mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
add CSetContainerSlot packet
This commit is contained in:
23
pumpkin-protocol/src/client/play/c_set_container_slot.rs
Normal file
23
pumpkin-protocol/src/client/play/c_set_container_slot.rs
Normal file
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use pumpkin_protocol::{
|
||||
config::CConfigDisconnect,
|
||||
login::CLoginDisconnect,
|
||||
play::{
|
||||
CGameEvent, CPlayDisconnect, CSetContainerContent, CSyncPlayerPostion,
|
||||
CGameEvent, CPlayDisconnect, CSyncPlayerPostion,
|
||||
CSystemChatMessge,
|
||||
},
|
||||
},
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user