aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-12-28 04:31:29 -0600
committerGitHub <noreply@github.com>2025-12-28 04:31:29 -0600
commit20c7e27250148f62bab9e7b99e4f0cd6deb82325 (patch)
tree163b312ef4dc72c5c23be923f8ca17cdf2a7278c /azalea/examples
parent7ab3b8924f64f7eadb6b8928b6fae73cb06e4c2f (diff)
downloadazalea-drasl-20c7e27250148f62bab9e7b99e4f0cd6deb82325.tar.xz
Change Client::component to return a reference (#298)
* change Client::component to return a reference * write docs * merge main * remove unused parking_lot feature
Diffstat (limited to 'azalea/examples')
-rw-r--r--azalea/examples/testbot/commands/combat.rs8
-rw-r--r--azalea/examples/testbot/commands/debug.rs17
-rw-r--r--azalea/examples/testbot/commands/movement.rs1
-rw-r--r--azalea/examples/testbot/killaura.rs4
-rw-r--r--azalea/examples/testbot/main.rs2
5 files changed, 16 insertions, 16 deletions
diff --git a/azalea/examples/testbot/commands/combat.rs b/azalea/examples/testbot/commands/combat.rs
index b440b3ac..af147e96 100644
--- a/azalea/examples/testbot/commands/combat.rs
+++ b/azalea/examples/testbot/commands/combat.rs
@@ -2,6 +2,7 @@ use azalea::brigadier::prelude::*;
use parking_lot::Mutex;
use super::{CommandSource, Ctx};
+use crate::State;
pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
commands.register(
@@ -9,12 +10,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
let enabled = get_bool(ctx, "enabled").unwrap();
let source = ctx.source.lock();
let bot = source.bot.clone();
- {
- let mut ecs = bot.ecs.lock();
- let mut entity = ecs.entity_mut(bot.entity);
- let mut state = entity.get_mut::<crate::State>().unwrap();
- state.killaura = enabled
- }
+ bot.query_self::<&mut State, _>(|mut state| state.killaura = enabled);
source.reply(if enabled {
"Enabled killaura"
} else {
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs
index edadd697..711c3260 100644
--- a/azalea/examples/testbot/commands/debug.rs
+++ b/azalea/examples/testbot/commands/debug.rs
@@ -110,7 +110,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
let hit_result = source.bot.component::<HitResultComponent>();
- match &*hit_result {
+ match &**hit_result {
HitResult::Block(r) => {
if r.miss {
source.reply("I'm not looking at anything");
@@ -121,7 +121,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
source.reply(format!("I'm looking at {block:?} at {block_pos:?}"));
}
HitResult::Entity(r) => {
- let entity_kind = *source.bot.entity_component::<EntityKindComponent>(r.entity);
+ let entity_kind = **source.bot.entity_component::<EntityKindComponent>(r.entity);
source.reply(format!(
"I'm looking at {entity_kind} ({:?}) at {}",
r.entity, r.location
@@ -180,7 +180,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
"is_path_partial: {}, path.len: {}, queued_path.len: {}",
executing_path.is_path_partial,
executing_path.path.len(),
- if let Some(queued) = executing_path.queued_path {
+ if let Some(queued) = &executing_path.queued_path {
queued.len().to_string()
} else {
"n/a".to_owned()
@@ -261,9 +261,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
thread::sleep(Duration::from_secs(1));
// dump the ecs
- let mut ecs = ecs.lock();
-
-
+ let mut ecs = ecs.write();
let report_path = env::temp_dir().join("azalea-ecs-leak-report.txt");
let mut report = File::create(&report_path).unwrap();
@@ -357,7 +355,12 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
- source.lock().bot.ecs.lock().write_message(AppExit::Success);
+ source
+ .lock()
+ .bot
+ .ecs
+ .write()
+ .write_message(AppExit::Success);
});
1
diff --git a/azalea/examples/testbot/commands/movement.rs b/azalea/examples/testbot/commands/movement.rs
index a4ac787a..6f43a021 100644
--- a/azalea/examples/testbot/commands/movement.rs
+++ b/azalea/examples/testbot/commands/movement.rs
@@ -28,6 +28,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
source.reply("I can't see you!");
return 0;
};
+ let position = position.clone();
source.reply("ok");
source
.bot
diff --git a/azalea/examples/testbot/killaura.rs b/azalea/examples/testbot/killaura.rs
index 093495ea..e3d9091c 100644
--- a/azalea/examples/testbot/killaura.rs
+++ b/azalea/examples/testbot/killaura.rs
@@ -17,9 +17,9 @@ pub fn tick(bot: Client, state: State) -> anyhow::Result<()> {
let mut nearest_entity = None;
let mut nearest_distance = f64::INFINITY;
let bot_position = bot.eye_position();
- let bot_instance_name = bot.component::<InstanceName>();
+ let bot_instance_name = bot.component::<InstanceName>().clone();
{
- let mut ecs = bot.ecs.lock();
+ let mut ecs = bot.ecs.write();
let mut query = ecs
.query_filtered::<(Entity, &Position, &InstanceName), (
With<AbstractMonster>,
diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs
index aa4a7b99..9889e250 100644
--- a/azalea/examples/testbot/main.rs
+++ b/azalea/examples/testbot/main.rs
@@ -129,7 +129,7 @@ async fn handle(bot: Client, event: azalea::Event, state: State) -> anyhow::Resu
});
if swarm.args.pathfinder_debug_particles {
bot.ecs
- .lock()
+ .write()
.entity_mut(bot.entity)
.insert(PathfinderDebugParticles);
}