diff --git a/src/packet.rs b/src/packet.rs index 7e49e95..1aaf556 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -85,6 +85,11 @@ impl PacketWriter { self.write_u8(b as u8) } + /// writes a bool to the packet + fn write_bool(self, b: bool) -> Self { + self.write_u8(if b { 1 } else { 0 }) + } + /// writes a u16 to the packet fn write_u16(self, sh: u16) -> Self { let mut s = self; @@ -191,6 +196,11 @@ impl ExtBitmask { fn info(self) -> Option { // TODO: add entries as extensions are supported Some(match self { + // this isn't actually used by the server at all, but it technically sort of implements it + Self::HeldBlock => ExtInfo::new("HeldBlock".to_string(), 1, Self::HeldBlock), + Self::EmoteFix => ExtInfo::new("EmoteFix".to_string(), 1, Self::EmoteFix), + // TODO: render CP437 properly in server output + Self::FullCP437 => ExtInfo::new("FullCP437".to_string(), 1, Self::FullCP437), Self::EnvWeatherType => { ExtInfo::new("EnvWeatherType".to_string(), 1, Self::EnvWeatherType) } diff --git a/src/packet/client.rs b/src/packet/client.rs index 618438a..47b0d79 100644 --- a/src/packet/client.rs +++ b/src/packet/client.rs @@ -27,8 +27,8 @@ pub enum ClientPacket { }, /// sent to update the player's current position and orientation with the server PositionOrientation { - /// should always be 0xff (-1), referring to the player who sent it - _player_id: i8, + /// if the HeldBlock extension is supported, this should contain the block the player is currently holding + _player_id_or_held_block: i8, x: f16, y: f16, z: f16, @@ -78,7 +78,7 @@ impl ClientPacket { block_type: buf.try_get_u8().ok()?, }, 0x08 => Self::PositionOrientation { - _player_id: buf.try_get_i8().ok()?, + _player_id_or_held_block: buf.try_get_i8().ok()?, x: buf.try_get_f16().ok()?, y: buf.try_get_f16().ok()?, z: buf.try_get_f16().ok()?, diff --git a/src/packet/server.rs b/src/packet/server.rs index f24b719..d4d6e24 100644 --- a/src/packet/server.rs +++ b/src/packet/server.rs @@ -99,6 +99,8 @@ pub enum ServerPacket { ExtInfo {}, /// packet to send info about an extension on the server ExtEntry { ext_name: String, version: i32 }, + /// packet to set a player's currently held block + HoldThis { block: u8, prevent_change: bool }, /// informs the client that it should update the current weather EnvWeatherType { weather_type: WeatherType }, } @@ -125,6 +127,7 @@ impl ServerPacket { Self::ExtInfo {} => 0x10, Self::ExtEntry { .. } => 0x11, + Self::HoldThis { .. } => 0x14, Self::EnvWeatherType { .. } => 0x1f, } } @@ -242,6 +245,10 @@ impl ServerPacket { Self::ExtEntry { ext_name, version } => { writer.write_string(ext_name).write_i32(*version) } + Self::HoldThis { + block, + prevent_change, + } => writer.write_u8(*block).write_bool(*prevent_change), Self::EnvWeatherType { weather_type } => writer.write_u8(weather_type.into()), } } diff --git a/src/server/network.rs b/src/server/network.rs index 40728b4..fd51055 100644 --- a/src/server/network.rs +++ b/src/server/network.rs @@ -328,7 +328,7 @@ async fn handle_stream_inner( } } ClientPacket::PositionOrientation { - _player_id: _, + _player_id_or_held_block: _, x, y, z,