Skip to content

Commit

Permalink
add CSetContainerSlot packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryntet committed Aug 22, 2024
1 parent b8d350f commit 4c572ec
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
23 changes: 23 additions & 0 deletions pumpkin-protocol/src/client/play/c_set_container_slot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::slot::Slot;
use crate::VarInt;
use pumpkin_macros::packet;
use serde::Serialize;
#[derive(Serialize)]
#[packet(0x15)]
pub struct CSetContainerSlot<'a> {
window_id: i8,
state_id: VarInt,
slot: i16,
slot_data: &'a Slot,
}

impl<'a> CSetContainerSlot<'a> {
pub fn new(window_id: i8, state_id: i32, slot: usize, slot_data: &'a Slot) -> Self {
Self {
window_id,
state_id: state_id.into(),
slot: slot.try_into().unwrap(),
slot_data,
}
}
}
2 changes: 2 additions & 0 deletions pumpkin-protocol/src/client/play/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod c_player_info_update;
mod c_player_remove;
mod c_remove_entities;
mod c_set_container_content;
mod c_set_container_slot;
mod c_set_held_item;
mod c_set_title;
mod c_spawn_player;
Expand Down Expand Up @@ -60,6 +61,7 @@ pub use c_player_info_update::*;
pub use c_player_remove::*;
pub use c_remove_entities::*;
pub use c_set_container_content::*;
pub use c_set_container_slot::*;
pub use c_set_held_item::*;
pub use c_set_title::*;
pub use c_spawn_player::*;
Expand Down
6 changes: 6 additions & 0 deletions pumpkin-protocol/src/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,9 @@ impl From<&Item> for Slot {
}
}
}

impl From<Option<&Item>> for Slot {
fn from(item: Option<&Item>) -> Self {
item.map(Slot::from).unwrap_or(Slot::empty())
}
}
16 changes: 15 additions & 1 deletion pumpkin/src/client/container.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pumpkin_core::text::TextComponent;
use pumpkin_inventory::WindowType;
use pumpkin_protocol::client::play::{COpenScreen, CSetContainerContent};
use pumpkin_protocol::client::play::{COpenScreen, CSetContainerContent, CSetContainerSlot};
use pumpkin_protocol::slot::Slot;
use pumpkin_world::item::Item;

Expand Down Expand Up @@ -68,4 +68,18 @@ impl super::Client {
CSetContainerContent::new(window_type as u8 + 1, 0.into(), &slots, &carried_item);
self.send_packet(&packet);
}

pub fn set_container_slot(
&mut self,
window_type: WindowType,
slot: usize,
item: Option<&Item>,
) {
self.send_packet(&CSetContainerSlot::new(
window_type as i8,
0,
slot,
&item.into(),
))
}
}
6 changes: 1 addition & 5 deletions pumpkin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use pumpkin_protocol::{
config::CConfigDisconnect,
login::CLoginDisconnect,
play::{
CGameEvent, CPlayDisconnect, CSetContainerContent, CSyncPlayerPostion,
CGameEvent, CPlayDisconnect, CSyncPlayerPostion,
CSystemChatMessge,
},
},
Expand All @@ -41,10 +41,6 @@ use pumpkin_protocol::{
ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket,
};

use pumpkin_inventory::WindowType;
use pumpkin_protocol::client::play::COpenScreen;
use pumpkin_protocol::slot::Slot;
use pumpkin_world::item::Item;
use std::io::Read;
use thiserror::Error;

Expand Down

0 comments on commit 4c572ec

Please sign in to comment.