Skip to content

Commit

Permalink
Add Serverbound Use Item On
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 17, 2024
1 parent 4562570 commit 9d3ee1d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pumpkin-protocol/src/client/play/c_block_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/position.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pumpkin-protocol/src/server/play/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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::*;
17 changes: 17 additions & 0 deletions pumpkin-protocol/src/server/play/s_use_item_on.rs
Original file line number Diff line number Diff line change
@@ -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,
}
5 changes: 4 additions & 1 deletion pumpkin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down Expand Up @@ -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),
}
}
Expand Down
12 changes: 9 additions & 3 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

0 comments on commit 9d3ee1d

Please sign in to comment.