aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-12-05 06:30:47 +0000
committermat <git@matdoes.dev>2024-12-05 06:30:47 +0000
commit39f4d68e1ff1f0fa0d45663335d83299d5d37790 (patch)
treeac61d7bf437a1874c91d5c794b732dc599f86259 /azalea-protocol/src/packets
parent6379035b852f1b619565d27f5cee3b93042c2312 (diff)
downloadazalea-drasl-39f4d68e1ff1f0fa0d45663335d83299d5d37790.tar.xz
fix container_set_content, player_position, and recipe_book_remove packets
Diffstat (limited to 'azalea-protocol/src/packets')
-rwxr-xr-xazalea-protocol/src/packets/game/c_container_set_content.rs26
-rwxr-xr-xazalea-protocol/src/packets/game/c_player_position.rs53
-rwxr-xr-xazalea-protocol/src/packets/game/c_recipe_book_remove.rs6
-rwxr-xr-xazalea-protocol/src/packets/game/s_move_player_pos_rot.rs5
4 files changed, 64 insertions, 26 deletions
diff --git a/azalea-protocol/src/packets/game/c_container_set_content.rs b/azalea-protocol/src/packets/game/c_container_set_content.rs
index 852ce60f..d4bd9184 100755
--- a/azalea-protocol/src/packets/game/c_container_set_content.rs
+++ b/azalea-protocol/src/packets/game/c_container_set_content.rs
@@ -10,3 +10,29 @@ pub struct ClientboundContainerSetContent {
pub items: Vec<ItemStack>,
pub carried_item: ItemStack,
}
+
+#[cfg(test)]
+mod tests {
+ use std::io::Cursor;
+
+ use super::ClientboundContainerSetContent;
+ use crate::packets::ProtocolPacket;
+
+ #[test]
+ fn test_read_write_container_set_content() {
+ let contents = [
+ 1, 2, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 196, 6, 0, 0, 0,
+ ];
+ let mut buf = Cursor::new(contents.as_slice());
+ let packet = ClientboundContainerSetContent::read(&mut buf).unwrap();
+ println!("{:?}", packet);
+
+ assert_eq!(buf.position(), contents.len() as u64);
+
+ let mut buf = Vec::new();
+ packet.write(&mut buf).unwrap();
+ assert_eq!(buf, contents);
+ }
+}
diff --git a/azalea-protocol/src/packets/game/c_player_position.rs b/azalea-protocol/src/packets/game/c_player_position.rs
index aa030fc5..e742df22 100755
--- a/azalea-protocol/src/packets/game/c_player_position.rs
+++ b/azalea-protocol/src/packets/game/c_player_position.rs
@@ -8,11 +8,19 @@ use azalea_protocol_macros::ClientboundGamePacket;
pub struct ClientboundPlayerPosition {
#[var]
pub id: u32,
+ pub change: PositionMoveRotation,
+ pub relative: RelativeMovements,
+}
+
+/// These values are either absolute or relative, depending on the fields from
+/// the [`RelativeMovements`].
+#[derive(Clone, Debug, AzBuf)]
+pub struct PositionMoveRotation {
pub pos: Vec3,
- pub delta_movement: Vec3,
+ /// The updated delta movement (velocity).
+ pub delta: Vec3,
pub y_rot: f32,
pub x_rot: f32,
- pub relative_arguments: RelativeMovements,
}
#[derive(Debug, Clone)]
@@ -22,6 +30,10 @@ pub struct RelativeMovements {
pub z: bool,
pub y_rot: bool,
pub x_rot: bool,
+ pub delta_x: bool,
+ pub delta_y: bool,
+ pub delta_z: bool,
+ pub rotate_delta: bool,
}
impl AzaleaRead for RelativeMovements {
@@ -34,28 +46,33 @@ impl AzaleaRead for RelativeMovements {
z: set.index(2),
y_rot: set.index(3),
x_rot: set.index(4),
+ delta_x: set.index(5),
+ delta_y: set.index(6),
+ delta_z: set.index(7),
+ rotate_delta: set.index(8),
})
}
}
impl AzaleaWrite for RelativeMovements {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- let mut set = FixedBitSet::<5>::new();
- if self.x {
- set.set(0);
- }
- if self.y {
- set.set(1);
- }
- if self.z {
- set.set(2);
- }
- if self.y_rot {
- set.set(3);
- }
- if self.x_rot {
- set.set(4);
- }
+ let mut set = FixedBitSet::<32>::new();
+ let mut set_bit = |index: usize, value: bool| {
+ if value {
+ set.set(index);
+ }
+ };
+
+ set_bit(0, self.x);
+ set_bit(1, self.y);
+ set_bit(2, self.z);
+ set_bit(3, self.y_rot);
+ set_bit(4, self.x_rot);
+ set_bit(5, self.delta_x);
+ set_bit(6, self.delta_y);
+ set_bit(7, self.delta_z);
+ set_bit(8, self.rotate_delta);
+
set.azalea_write(buf)
}
}
diff --git a/azalea-protocol/src/packets/game/c_recipe_book_remove.rs b/azalea-protocol/src/packets/game/c_recipe_book_remove.rs
index aa5a09fe..983c5e12 100755
--- a/azalea-protocol/src/packets/game/c_recipe_book_remove.rs
+++ b/azalea-protocol/src/packets/game/c_recipe_book_remove.rs
@@ -1,12 +1,8 @@
use azalea_buf::AzBuf;
use azalea_protocol_macros::ClientboundGamePacket;
-use super::{c_entity_position_sync::PositionMoveRotation, c_player_position::RelativeMovements};
-
#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
pub struct ClientboundRecipeBookRemove {
#[var]
- pub id: u32,
- pub change: PositionMoveRotation,
- pub relatives: RelativeMovements,
+ pub recipes: Vec<u32>,
}
diff --git a/azalea-protocol/src/packets/game/s_move_player_pos_rot.rs b/azalea-protocol/src/packets/game/s_move_player_pos_rot.rs
index cb0e0633..2cf186da 100755
--- a/azalea-protocol/src/packets/game/s_move_player_pos_rot.rs
+++ b/azalea-protocol/src/packets/game/s_move_player_pos_rot.rs
@@ -1,11 +1,10 @@
use azalea_buf::AzBuf;
+use azalea_core::position::Vec3;
use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, AzBuf, ServerboundGamePacket)]
pub struct ServerboundMovePlayerPosRot {
- pub x: f64,
- pub y: f64,
- pub z: f64,
+ pub pos: Vec3,
pub y_rot: f32,
pub x_rot: f32,
pub on_ground: bool,