aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/s_interact.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2026-01-13 10:51:45 -0600
committerGitHub <noreply@github.com>2026-01-13 10:51:45 -0600
commitb21ac946cafaacc9ee2478ea48ed9e72554f79ed (patch)
tree4d05744b9801e94f5da6563d8fabddfb20d1c7b7 /azalea-protocol/src/packets/game/s_interact.rs
parentd5fa5e32b37754b3b5c136e58821e48cd3b7c2ff (diff)
downloadazalea-drasl-b21ac946cafaacc9ee2478ea48ed9e72554f79ed.tar.xz
Merge AzaleaRead and AzaleaWrite (#305)
Diffstat (limited to 'azalea-protocol/src/packets/game/s_interact.rs')
-rw-r--r--azalea-protocol/src/packets/game/s_interact.rs61
1 files changed, 27 insertions, 34 deletions
diff --git a/azalea-protocol/src/packets/game/s_interact.rs b/azalea-protocol/src/packets/game/s_interact.rs
index d368354f..bd04e09d 100644
--- a/azalea-protocol/src/packets/game/s_interact.rs
+++ b/azalea-protocol/src/packets/game/s_interact.rs
@@ -1,9 +1,11 @@
use std::io::{self, Cursor, Write};
-use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar};
-use azalea_core::position::Vec3;
+use azalea_buf::{AzBuf, AzBufVar};
+use azalea_core::{
+ entity_id::MinecraftEntityId,
+ position::{Vec3, Vec3f32},
+};
use azalea_protocol_macros::ServerboundGamePacket;
-use azalea_core::entity_id::MinecraftEntityId;
use crate::packets::BufReadError;
@@ -28,29 +30,7 @@ pub enum ActionType {
},
}
-impl AzaleaWrite for ActionType {
- fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
- match self {
- ActionType::Interact { hand } => {
- 0u32.azalea_write_var(buf)?;
- hand.azalea_write(buf)?;
- }
- ActionType::Attack => {
- 1u32.azalea_write_var(buf)?;
- }
- ActionType::InteractAt { location, hand } => {
- 2u32.azalea_write_var(buf)?;
- (location.x as f32).azalea_write(buf)?;
- (location.y as f32).azalea_write(buf)?;
- (location.z as f32).azalea_write(buf)?;
- hand.azalea_write(buf)?;
- }
- }
- Ok(())
- }
-}
-
-impl AzaleaRead for ActionType {
+impl AzBuf for ActionType {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let action_type = u32::azalea_read_var(buf)?;
match action_type {
@@ -60,16 +40,10 @@ impl AzaleaRead for ActionType {
}
1 => Ok(ActionType::Attack),
2 => {
- let x = f32::azalea_read(buf)?;
- let y = f32::azalea_read(buf)?;
- let z = f32::azalea_read(buf)?;
+ let pos = Vec3f32::azalea_read(buf)?;
let hand = InteractionHand::azalea_read(buf)?;
Ok(ActionType::InteractAt {
- location: Vec3 {
- x: f64::from(x),
- y: f64::from(y),
- z: f64::from(z),
- },
+ location: Vec3::from(pos),
hand,
})
}
@@ -78,6 +52,25 @@ impl AzaleaRead for ActionType {
}),
}
}
+ fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
+ match self {
+ ActionType::Interact { hand } => {
+ 0u32.azalea_write_var(buf)?;
+ hand.azalea_write(buf)?;
+ }
+ ActionType::Attack => {
+ 1u32.azalea_write_var(buf)?;
+ }
+ ActionType::InteractAt { location, hand } => {
+ 2u32.azalea_write_var(buf)?;
+ (location.x as f32).azalea_write(buf)?;
+ (location.y as f32).azalea_write(buf)?;
+ (location.z as f32).azalea_write(buf)?;
+ hand.azalea_write(buf)?;
+ }
+ }
+ Ok(())
+ }
}
#[derive(AzBuf, Clone, Copy, Debug, Default, PartialEq)]