diff --git a/pumpkin-protocol/src/client/play/c_block_update.rs b/pumpkin-protocol/src/client/play/c_block_update.rs index 53548585d..c6e9aae82 100644 --- a/pumpkin-protocol/src/client/play/c_block_update.rs +++ b/pumpkin-protocol/src/client/play/c_block_update.rs @@ -9,3 +9,9 @@ pub struct CBlockUpdate { location: WorldPosition, block_id: VarInt, } + +impl CBlockUpdate { + pub fn new(location: WorldPosition, block_id: VarInt) -> Self { + Self { location, block_id } + } +} diff --git a/pumpkin-protocol/src/position.rs b/pumpkin-protocol/src/position.rs index 976c1267d..63180f215 100644 --- a/pumpkin-protocol/src/position.rs +++ b/pumpkin-protocol/src/position.rs @@ -1,9 +1,9 @@ use serde::{Deserialize, Serialize}; pub struct WorldPosition { - x: i32, - y: i32, - z: i32, + pub x: i32, + pub y: i32, + pub z: i32, } impl Serialize for WorldPosition { diff --git a/pumpkin-protocol/src/server/play/mod.rs b/pumpkin-protocol/src/server/play/mod.rs index 82ede8352..23842e3ca 100644 --- a/pumpkin-protocol/src/server/play/mod.rs +++ b/pumpkin-protocol/src/server/play/mod.rs @@ -9,6 +9,7 @@ mod s_player_position; mod s_player_position_rotation; mod s_player_rotation; mod s_swing_arm; +mod s_use_item_on; pub use c_client_information::*; pub use c_interact::*; @@ -21,3 +22,4 @@ pub use s_player_position::*; pub use s_player_position_rotation::*; pub use s_player_rotation::*; pub use s_swing_arm::*; +pub use s_use_item_on::*; diff --git a/pumpkin-protocol/src/server/play/s_use_item_on.rs b/pumpkin-protocol/src/server/play/s_use_item_on.rs new file mode 100644 index 000000000..b69227442 --- /dev/null +++ b/pumpkin-protocol/src/server/play/s_use_item_on.rs @@ -0,0 +1,17 @@ +use pumpkin_macros::packet; +use serde::Deserialize; + +use crate::{position::WorldPosition, VarInt}; + +#[derive(Deserialize)] +#[packet(0x38)] +pub struct SUseItemOn { + pub hand: VarInt, + pub location: WorldPosition, + pub face: VarInt, + pub cursor_pos_x: f32, + pub cursor_pos_y: f32, + pub cursor_pos_z: f32, + pub inside_block: bool, + pub sequene: VarInt, +} diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index 1c30f0ea7..af4c1c8d5 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -29,7 +29,7 @@ use pumpkin_protocol::{ play::{ SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, - SPlayerRotation, SSwingArm, + SPlayerRotation, SSwingArm, SUseItemOn, }, status::{SPingRequest, SStatusRequest}, }, @@ -298,6 +298,9 @@ impl Client { SPlayerAction::PACKET_ID => { self.handle_player_action(server, SPlayerAction::read(bytebuf).unwrap()) } + SUseItemOn::PACKET_ID => { + self.handle_use_item_on(server, SUseItemOn::read(bytebuf).unwrap()) + } _ => log::error!("Failed to handle player packet id {}", packet.id.0), } } diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index ca3b50898..ffd1dea29 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -2,13 +2,13 @@ use num_traits::FromPrimitive; use pumpkin_entity::EntityId; use pumpkin_protocol::{ client::play::{ - Animation, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, CSystemChatMessge, - CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, + Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, + CSystemChatMessge, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, }, server::play::{ Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, - SSwingArm, + SSwingArm, SUseItemOn, }, }; use pumpkin_text::TextComponent; @@ -314,4 +314,10 @@ impl Client { } } pub fn handle_player_action(&mut self, _server: &mut Server, player_action: SPlayerAction) {} + + pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) { + let mut location = use_item_on.location; + location.y += 2; + server.broadcast_packet(self, &CBlockUpdate::new(location, 11.into())); + } }