diff options
| -rw-r--r-- | azalea-client/src/plugins.rs | 10 | ||||
| -rwxr-xr-x | azalea-physics/src/lib.rs | 11 | ||||
| -rw-r--r-- | azalea-world/src/entity/attributes.rs | 5 | ||||
| -rw-r--r-- | azalea-world/src/entity/mod.rs | 9 | ||||
| -rwxr-xr-x | azalea/src/bot.rs | 8 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mtdstarlite.rs | 2 | ||||
| -rwxr-xr-x | bot/src/main.rs | 5 |
9 files changed, 30 insertions, 24 deletions
diff --git a/azalea-client/src/plugins.rs b/azalea-client/src/plugins.rs index 1a3aa049..150d5960 100644 --- a/azalea-client/src/plugins.rs +++ b/azalea-client/src/plugins.rs @@ -7,19 +7,21 @@ use std::{ hash::BuildHasherDefault, }; +type U64Hasher = BuildHasherDefault<NoHashHasher<u64>>; + // kind of based on https://docs.rs/http/latest/src/http/extensions.rs.html /// A map of plugin ids to Plugin trait objects. The client stores this so we /// can keep the state for our plugins. /// /// If you're using azalea, you should generate this from the `plugins!` macro. -#[derive(Clone)] +#[derive(Clone, Default)] pub struct Plugins { - map: Option<HashMap<TypeId, Box<dyn Plugin>, BuildHasherDefault<NoHashHasher<u64>>>>, + map: Option<HashMap<TypeId, Box<dyn Plugin>, U64Hasher>>, } impl Plugins { pub fn new() -> Self { - Self { map: None } + Self::default() } pub fn add<T: Plugin>(&mut self, plugin: T) { @@ -46,7 +48,7 @@ impl IntoIterator for Plugins { fn into_iter(self) -> Self::IntoIter { self.map - .map(|map| map.into_iter().map(|(_, v)| v).collect::<Vec<_>>()) + .map(|map| map.into_values().collect::<Vec<_>>()) .unwrap_or_default() .into_iter() } diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index 635a36bc..852874b8 100755 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -122,12 +122,11 @@ impl<D: DerefMut<Target = Dimension>> HasPhysics for Entity<'_, D> { }; if self.metadata.sprinting { let y_rot = self.y_rot * 0.017453292; - self.delta = self.delta - + Vec3 { - x: (-f32::sin(y_rot) * 0.2) as f64, - y: 0., - z: (f32::cos(y_rot) * 0.2) as f64, - }; + self.delta += Vec3 { + x: (-f32::sin(y_rot) * 0.2) as f64, + y: 0., + z: (f32::cos(y_rot) * 0.2) as f64, + }; } self.has_impulse = true; diff --git a/azalea-world/src/entity/attributes.rs b/azalea-world/src/entity/attributes.rs index 1050615c..f7e9682e 100644 --- a/azalea-world/src/entity/attributes.rs +++ b/azalea-world/src/entity/attributes.rs @@ -40,9 +40,8 @@ impl AttributeInstance { AttributeModifierOperation::MultiplyBase => total += self.base * modifier.amount, _ => {} } - match modifier.operation { - AttributeModifierOperation::MultiplyTotal => total *= 1.0 + modifier.amount, - _ => {} + if let AttributeModifierOperation::MultiplyTotal = modifier.operation { + total *= 1.0 + modifier.amount } } total diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs index 63147ced..540bfeed 100644 --- a/azalea-world/src/entity/mod.rs +++ b/azalea-world/src/entity/mod.rs @@ -270,10 +270,19 @@ impl EntityData { &self.pos } + /// Convert this &mut self into a (mutable) pointer. + /// + /// # Safety + /// The entity MUST exist while this pointer exists. pub unsafe fn as_ptr(&mut self) -> NonNull<EntityData> { NonNull::new_unchecked(self as *mut EntityData) } + /// Convert this &self into a (mutable) pointer. + /// + /// # Safety + /// The entity MUST exist while this pointer exists. You also must not + /// modify the data inside the pointer. pub unsafe fn as_const_ptr(&self) -> NonNull<EntityData> { // this is cursed NonNull::new_unchecked(self as *const EntityData as *mut EntityData) diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 961f093d..0becaa62 100755 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -38,11 +38,9 @@ impl BotTrait for azalea_client::Client { impl crate::Plugin for Plugin { async fn handle(self: Box<Self>, event: Event, mut bot: Client) { if let Event::Tick = event { - if *self.state.jumping_once.lock() { - if bot.jumping() { - *self.state.jumping_once.lock() = false; - bot.set_jumping(false); - } + if *self.state.jumping_once.lock() && bot.jumping() { + *self.state.jumping_once.lock() = false; + bot.set_jumping(false); } } } diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index d62b3e05..9fd9fe90 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -77,7 +77,7 @@ impl Trait for azalea_client::Client { let dimension = self.dimension.read(); for possible_move in possible_moves.iter() { edges.push(Edge { - target: possible_move.next_node(&node), + target: possible_move.next_node(node), cost: possible_move.cost(&dimension, node), }); } diff --git a/azalea/src/pathfinder/moves.rs b/azalea/src/pathfinder/moves.rs index ed98b70d..a08d4b80 100644 --- a/azalea/src/pathfinder/moves.rs +++ b/azalea/src/pathfinder/moves.rs @@ -29,7 +29,7 @@ fn is_passable(pos: &BlockPos, dim: &Dimension) -> bool { /// Whether we can stand in this position. Checks if the block below is solid, /// and that the two blocks above that are passable. fn is_standable(pos: &BlockPos, dim: &Dimension) -> bool { - is_block_solid(&pos.down(1), dim) && is_passable(&pos, dim) + is_block_solid(&pos.down(1), dim) && is_passable(pos, dim) } const JUMP_COST: f32 = 0.5; diff --git a/azalea/src/pathfinder/mtdstarlite.rs b/azalea/src/pathfinder/mtdstarlite.rs index 8a40ec37..ff0fe4cc 100644 --- a/azalea/src/pathfinder/mtdstarlite.rs +++ b/azalea/src/pathfinder/mtdstarlite.rs @@ -105,7 +105,7 @@ impl< for n in &known_nodes { *pf.state_mut(n) = NodeState::default(); } - (*pf.state_mut(&start)).rhs = W::default(); + pf.state_mut(&start).rhs = W::default(); pf.open.push(start, pf.calculate_key(&start)); pf diff --git a/bot/src/main.rs b/bot/src/main.rs index f1398062..ce627651 100755 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -58,13 +58,12 @@ async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> Event::Chat(m) => { println!("{}", m.message().to_ansi(None)); if m.message().to_string() == "<py5> goto" { - let target_pos_vec3 = bot + let target_pos_vec3 = *(bot .dimension .read() .entity_by_uuid(&uuid::uuid!("6536bfed869548fd83a1ecd24cf2a0fd")) .unwrap() - .pos() - .clone(); + .pos()); let target_pos: BlockPos = (&target_pos_vec3).into(); // bot.look_at(&target_pos_vec3); bot.goto(BlockPosGoal::from(target_pos)); |
