aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-12-28 21:54:12 -0600
committerGitHub <noreply@github.com>2025-12-28 21:54:12 -0600
commit39488a6585ce969af93f43ece1ffb1174dc95e1d (patch)
tree49b63b2321b974a7c6425e53b8602a0b4500f092 /azalea/examples
parent25e441944412038da2be4e64854e59169d58305b (diff)
downloadazalea-drasl-39488a6585ce969af93f43ece1ffb1174dc95e1d.tar.xz
Implement `EntityRef` (#299)
* start implementing EntityRef struct * use EntityRef and impl more functions for it * fix doctests * typo * slightly reword some docs * update changelog
Diffstat (limited to 'azalea/examples')
-rw-r--r--azalea/examples/testbot/commands.rs5
-rw-r--r--azalea/examples/testbot/commands/debug.rs12
-rw-r--r--azalea/examples/testbot/commands/movement.rs20
-rw-r--r--azalea/examples/testbot/killaura.rs2
-rw-r--r--azalea/examples/todo/README.md2
-rw-r--r--azalea/examples/todo/pvp.rs2
6 files changed, 14 insertions, 29 deletions
diff --git a/azalea/examples/testbot/commands.rs b/azalea/examples/testbot/commands.rs
index 9d9d9b8a..beb87510 100644
--- a/azalea/examples/testbot/commands.rs
+++ b/azalea/examples/testbot/commands.rs
@@ -3,9 +3,10 @@ pub mod debug;
pub mod movement;
use azalea::{
- Client, brigadier::prelude::*, chat::ChatPacket, ecs::prelude::*, entity::metadata::Player,
+ Client, brigadier::prelude::*, chat::ChatPacket, entity::metadata::Player,
player::GameProfileComponent,
};
+use bevy_ecs::query::With;
use parking_lot::Mutex;
use crate::State;
@@ -29,7 +30,7 @@ impl CommandSource {
}
}
- pub fn entity(&mut self) -> Option<Entity> {
+ pub fn entity(&mut self) -> Option<azalea::EntityRef> {
let username = self.chat.sender()?;
self.bot
.any_entity_by::<&GameProfileComponent, With<Player>>(
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs
index f11ced45..36c699a4 100644
--- a/azalea/examples/testbot/commands/debug.rs
+++ b/azalea/examples/testbot/commands/debug.rs
@@ -6,13 +6,11 @@ use azalea::{
BlockPos,
brigadier::prelude::*,
chunks::ReceiveChunkEvent,
- entity::Position,
packet::game,
pathfinder::{ExecutingPath, Pathfinder},
- world::MinecraftEntityId,
};
use azalea_core::hit_result::HitResult;
-use azalea_entity::{EntityKindComponent, EntityUuid, metadata};
+use azalea_entity::{EntityKindComponent, metadata};
use azalea_inventory::components::MaxStackSize;
use azalea_world::InstanceContainer;
use bevy_app::AppExit;
@@ -40,7 +38,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
source.reply("You aren't in render distance!");
return 0;
};
- let position = source.bot.entity_component::<Position>(entity);
+ let position = entity.position();
source.reply(format!(
"You are at {}, {}, {}",
position.x, position.y, position.z
@@ -54,7 +52,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
source.reply("You aren't in render distance!");
return 0;
};
- let entity_id = source.bot.entity_component::<MinecraftEntityId>(entity);
+ let entity_id = entity.minecraft_id();
source.reply(format!(
"Your Minecraft ID is {} and your ECS ID is {entity:?}",
*entity_id
@@ -219,10 +217,10 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
.nearest_entities_by::<(), With<metadata::Player>>(|_: ()| true);
let tab_list = source.bot.tab_list();
for player_entity in player_entities {
- let uuid = source.bot.entity_component::<EntityUuid>(player_entity);
+ let uuid = player_entity.uuid();
source.reply(format!(
"{} - {} ({:?})",
- player_entity,
+ player_entity.id(),
tab_list.get(&uuid).map_or("?", |p| p.profile.name.as_str()),
uuid
));
diff --git a/azalea/examples/testbot/commands/movement.rs b/azalea/examples/testbot/commands/movement.rs
index 6f43a021..c1af4143 100644
--- a/azalea/examples/testbot/commands/movement.rs
+++ b/azalea/examples/testbot/commands/movement.rs
@@ -3,11 +3,9 @@ use std::time::Duration;
use azalea::{
BlockPos, SprintDirection, WalkDirection,
brigadier::prelude::*,
- entity::Position,
pathfinder::goals::{BlockPosGoal, RadiusGoal, XZGoal},
prelude::*,
};
-use azalea_entity::dimensions::EntityDimensions;
use parking_lot::Mutex;
use super::{CommandSource, Ctx};
@@ -24,11 +22,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
source.reply("I can't see you!");
return 0;
};
- let Some(position) = source.bot.get_entity_component::<Position>(entity) else {
- source.reply("I can't see you!");
- return 0;
- };
- let position = position.clone();
+ let position = entity.position();
source.reply("ok");
source
.bot
@@ -99,16 +93,8 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
source.reply("I can't see you!");
return 0;
};
- let Some(position) = source.bot.get_entity_component::<Position>(entity) else {
- source.reply("I can't see you!");
- return 0;
- };
- let eye_height = source
- .bot
- .get_entity_component::<EntityDimensions>(entity)
- .map(|h| h.eye_height)
- .unwrap_or_default();
- source.bot.look_at(position.up(eye_height as f64));
+ let eye_position = entity.eye_position();
+ source.bot.look_at(eye_position);
1
})
.then(argument("x", integer()).then(argument("y", integer()).then(
diff --git a/azalea/examples/testbot/killaura.rs b/azalea/examples/testbot/killaura.rs
index e6eb40ba..4f29a0f2 100644
--- a/azalea/examples/testbot/killaura.rs
+++ b/azalea/examples/testbot/killaura.rs
@@ -26,7 +26,7 @@ pub fn tick(bot: Client, state: State) -> anyhow::Result<()> {
if let Some(nearest_entity) = nearest_entity {
println!("attacking {nearest_entity:?}");
- bot.attack(nearest_entity);
+ nearest_entity.attack();
}
Ok(())
diff --git a/azalea/examples/todo/README.md b/azalea/examples/todo/README.md
index ab31cf22..9655617e 100644
--- a/azalea/examples/todo/README.md
+++ b/azalea/examples/todo/README.md
@@ -1 +1 @@
-These examples don't work yet and were only written to help design APIs. They will work in the future (probably with minor changes).
+These examples don't work yet and were only written to help design APIs. They will work in the future (with some changes).
diff --git a/azalea/examples/todo/pvp.rs b/azalea/examples/todo/pvp.rs
index 3c86778f..8da55f3a 100644
--- a/azalea/examples/todo/pvp.rs
+++ b/azalea/examples/todo/pvp.rs
@@ -47,7 +47,7 @@ async fn swarm_handle(swarm: Swarm, event: SwarmEvent, state: SwarmState) -> any
for (bot, bot_state) in swarm {
bot.tick_goto_goal(pathfinder::Goals::Reach(target_bounding_box));
// if target.bounding_box.distance(bot.eyes) < bot.reach_distance() {
- if azalea::entities::can_reach(bot.entity(), target_bounding_box) {
+ if bot.can_reach(target_bounding_box) {
bot.swing();
}
if !bot.using_held_item() && bot.hunger() <= 17 {