From cfbfdd77b4a400ef3bace378ff413aa2ff3bf57c Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 8 Jan 2024 00:12:54 -0600 Subject: fix ping packet, explosion packet, and panic less --- .../src/packets/game/clientbound_explode_packet.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'azalea-protocol/src/packets/game/clientbound_explode_packet.rs') 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(()) } -- cgit v1.2.3