Skip to content

Commit

Permalink
Basic handling of Set creative mod slot packet
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas0008 committed Aug 17, 2024
1 parent 9a10ea4 commit 7b9b35e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 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 @@ -8,6 +8,7 @@ mod s_player_command;
mod s_player_position;
mod s_player_position_rotation;
mod s_player_rotation;
mod s_set_creative_slot;
mod s_set_held_item;
mod s_swing_arm;
mod s_use_item_on;
Expand All @@ -22,6 +23,7 @@ pub use s_player_command::*;
pub use s_player_position::*;
pub use s_player_position_rotation::*;
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_on::*;
10 changes: 10 additions & 0 deletions pumpkin-protocol/src/server/play/s_set_creative_slot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use pumpkin_macros::packet;

use crate::slot::Slot;

#[derive(serde::Deserialize, Debug)]
#[packet(0x32)]
pub struct SSetCreativeSlot {
slot: i16,
clicked_item: Slot,
}
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, SSetHeldItem, SSwingArm, SUseItemOn,
SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn,
},
status::{SPingRequest, SStatusRequest},
},
Expand Down Expand Up @@ -304,6 +304,9 @@ impl Client {
SSetHeldItem::PACKET_ID => {
self.handle_set_held_item(server, SSetHeldItem::read(bytebuf).unwrap())
}
SSetCreativeSlot::PACKET_ID => {
self.handle_set_creative_slot(server, SSetCreativeSlot::read(bytebuf).unwrap())
}
_ => log::error!("Failed to handle player packet id {}", packet.id.0),
}
}
Expand Down
15 changes: 11 additions & 4 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use pumpkin_protocol::{
client::play::{
Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
CSystemChatMessge, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot,
}, position::WorldPosition, server::play::{
},
position::WorldPosition,
server::play::{
Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
SSetHeldItem, SSwingArm, SUseItemOn,
}
SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn,
},
};
use pumpkin_text::TextComponent;
use pumpkin_world::block::BlockFace;
Expand Down Expand Up @@ -316,7 +318,7 @@ 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;
let location = use_item_on.location;
let face = BlockFace::from_i32(use_item_on.face.0).unwrap();
let location = WorldPosition(location.0 + face.to_offset());
server.broadcast_packet(self, &CBlockUpdate::new(location, 11.into()));
Expand All @@ -330,4 +332,9 @@ impl Client {
let player = self.player.as_mut().unwrap();
player.inventory.set_selected(slot);
}

pub fn handle_set_creative_slot(&mut self, _server: &mut Server, packet: SSetCreativeSlot) {
// TODO: handle this
dbg!(&packet);
}
}

0 comments on commit 7b9b35e

Please sign in to comment.