Skip to content

Commit

Permalink
Merge pull request #61 from neeleshpoli/master
Browse files Browse the repository at this point in the history
Implement Use Item (packet id 0x39) packet
  • Loading branch information
Snowiiii authored Aug 25, 2024
2 parents 9d6c8dc + 983ede2 commit 52ffec0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
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 @@ -14,6 +14,7 @@ mod s_player_rotation;
mod s_set_creative_slot;
mod s_set_held_item;
mod s_swing_arm;
mod s_use_item;
mod s_use_item_on;

pub use s_chat_command::*;
Expand All @@ -32,4 +33,5 @@ pub use s_player_rotation::*;
pub use s_set_creative_slot::*;
pub use s_set_held_item::*;
pub use s_swing_arm::*;
pub use s_use_item::*;
pub use s_use_item_on::*;
14 changes: 14 additions & 0 deletions pumpkin-protocol/src/server/play/s_use_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use pumpkin_macros::packet;
use serde::Deserialize;

use crate::VarInt;

#[derive(Deserialize)]
#[packet(0x39)]
pub struct SUseItem {
// 0 for main hand, 1 for off hand
pub hand: VarInt,
pub sequence: VarInt,
pub yaw: f32,
pub pitch: f32,
}
7 changes: 6 additions & 1 deletion pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use num_traits::FromPrimitive;
use pumpkin_core::text::TextComponent;
use pumpkin_entity::EntityId;
use pumpkin_inventory::WindowType;
use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround};
use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround, SUseItem};
use pumpkin_protocol::{
client::play::{
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
Expand Down Expand Up @@ -423,6 +423,11 @@ impl Player {
.send_packet(&CAcknowledgeBlockChange::new(use_item_on.sequence));
}

pub fn handle_use_item(&mut self, _server: &mut Server, _use_item: SUseItem) {
// TODO: handle packet correctly
log::error!("An item was used(SUseItem), but the packet is not implemented yet");
}

pub fn handle_set_held_item(&mut self, _server: &mut Server, held: SSetHeldItem) {
let slot = held.slot;
if !(0..=8).contains(&slot) {
Expand Down
7 changes: 6 additions & 1 deletion pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use pumpkin_protocol::{
server::play::{
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation,
SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUseItemOn,
SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUseItem,
SUseItemOn,
},
ConnectionState, RawPacket, ServerPacket, VarInt,
};
Expand Down Expand Up @@ -256,6 +257,10 @@ impl Player {
self.handle_use_item_on(server, SUseItemOn::read(bytebuf)?);
Ok(())
}
SUseItem::PACKET_ID => {
self.handle_use_item(server, SUseItem::read(bytebuf)?);
Ok(())
}
SSetHeldItem::PACKET_ID => {
self.handle_set_held_item(server, SSetHeldItem::read(bytebuf)?);
Ok(())
Expand Down

0 comments on commit 52ffec0

Please sign in to comment.