From cfbfdd77b4a400ef3bace378ff413aa2ff3bf57c Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 8 Jan 2024 00:12:54 -0600 Subject: [PATCH] fix ping packet, explosion packet, and panic less --- azalea-physics/src/lib.rs | 6 +++--- .../game/clientbound_explode_packet.rs | 21 +++++++++++++++---- .../packets/game/clientbound_ping_packet.rs | 1 - azalea/examples/testbot/main.rs | 4 ++-- azalea/src/pathfinder/mod.rs | 8 ++++--- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/azalea-physics/src/lib.rs b/azalea-physics/src/lib.rs index a69c1bcf..55f54ccd 100644 --- a/azalea-physics/src/lib.rs +++ b/azalea-physics/src/lib.rs @@ -74,9 +74,9 @@ fn travel( jumping, ) in &mut query { - let world_lock = instance_container - .get(world_name) - .expect("All entities should be in a valid world"); + let Some(world_lock) = instance_container.get(world_name) else { + continue; + }; let world = world_lock.read(); // if !self.is_effective_ai() && !self.is_controlled_by_local_instance() { // // this.calculateEntityAnimation(this, this instanceof FlyingAnimal); diff --git a/azalea-protocol/src/packets/game/clientbound_explode_packet.rs b/azalea-protocol/src/packets/game/clientbound_explode_packet.rs index ae39135a..58e61e2e 100755 --- a/azalea-protocol/src/packets/game/clientbound_explode_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_explode_packet.rs @@ -1,9 +1,12 @@ -use std::io::{Cursor, Write}; +use std::{ + io::{Cursor, Write}, + str::FromStr, +}; use azalea_buf::{ BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, }; -use azalea_core::position::BlockPos; +use azalea_core::{position::BlockPos, resource_location::ResourceLocation}; use azalea_protocol_macros::ClientboundGamePacket; use azalea_registry::{ParticleKind, SoundEvent}; @@ -59,7 +62,14 @@ impl McBufReadable for ClientboundExplodePacket { let block_interaction = BlockInteraction::read_from(buf)?; let small_explosion_particles = ParticleKind::read_from(buf)?; let large_explosion_particles = ParticleKind::read_from(buf)?; - let explosion_sound = SoundEvent::read_from(buf)?; + + let sound_event_resource_location = ResourceLocation::read_from(buf)?.to_string(); + let explosion_sound = + SoundEvent::from_str(&sound_event_resource_location).map_err(|_| { + BufReadError::UnexpectedStringEnumVariant { + id: sound_event_resource_location, + } + })?; Ok(Self { x, @@ -108,7 +118,10 @@ impl McBufWritable for ClientboundExplodePacket { self.block_interaction.write_into(buf)?; self.small_explosion_particles.write_into(buf)?; self.large_explosion_particles.write_into(buf)?; - self.explosion_sound.write_into(buf)?; + + let sound_event_resource_location = + ResourceLocation::new(&self.explosion_sound.to_string()); + sound_event_resource_location.write_into(buf)?; Ok(()) } diff --git a/azalea-protocol/src/packets/game/clientbound_ping_packet.rs b/azalea-protocol/src/packets/game/clientbound_ping_packet.rs index 82de4fab..0bd2c8c3 100755 --- a/azalea-protocol/src/packets/game/clientbound_ping_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_ping_packet.rs @@ -3,6 +3,5 @@ use azalea_protocol_macros::ClientboundGamePacket; #[derive(Clone, Debug, McBuf, ClientboundGamePacket)] pub struct ClientboundPingPacket { - #[var] pub id: u32, } diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs index 9a3bd4f8..baa078d7 100644 --- a/azalea/examples/testbot/main.rs +++ b/azalea/examples/testbot/main.rs @@ -5,7 +5,7 @@ //! - Run `cargo r --example testbot` //! - Commands are prefixed with `!` in chat. You can send them either in public //! chat or as a /msg. -//! - Some commands to try are `!goto`, `!killaura`, `!down`. Check the +//! - Some commands to try are `!goto`, `!killaura true`, `!down`. Check the //! `commands` directory to see all of them. #![feature(async_closure)] @@ -31,7 +31,7 @@ const ADDRESS: &str = "localhost"; /// Whether the bot should run /particle a ton of times to show where it's /// pathfinding to. You should only have this on if the bot has operator /// permissions, otherwise it'll just spam the server console unnecessarily. -const PATHFINDER_DEBUG_PARTICLES: bool = true; +const PATHFINDER_DEBUG_PARTICLES: bool = false; #[tokio::main] async fn main() { diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 9fd769e6..360c4df5 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -208,9 +208,11 @@ fn goto_listener( let thread_pool = AsyncComputeTaskPool::get(); for event in events.read() { - let (mut pathfinder, executing_path, position, instance_name, inventory) = query - .get_mut(event.entity) - .expect("Called goto on an entity that's not in the world"); + let Ok((mut pathfinder, executing_path, position, instance_name, inventory)) = + query.get_mut(event.entity) + else { + continue; + }; if event.goal.success(BlockPos::from(position)) { // we're already at the goal, nothing to do