add CSetContainerSlot packet
This commit is contained in:
parent
b8d350f32d
commit
4c572eca2d
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_player_remove;
|
||||||
mod c_remove_entities;
|
mod c_remove_entities;
|
||||||
mod c_set_container_content;
|
mod c_set_container_content;
|
||||||
|
mod c_set_container_slot;
|
||||||
mod c_set_held_item;
|
mod c_set_held_item;
|
||||||
mod c_set_title;
|
mod c_set_title;
|
||||||
mod c_spawn_player;
|
mod c_spawn_player;
|
||||||
@ -60,6 +61,7 @@ pub use c_player_info_update::*;
|
|||||||
pub use c_player_remove::*;
|
pub use c_player_remove::*;
|
||||||
pub use c_remove_entities::*;
|
pub use c_remove_entities::*;
|
||||||
pub use c_set_container_content::*;
|
pub use c_set_container_content::*;
|
||||||
|
pub use c_set_container_slot::*;
|
||||||
pub use c_set_held_item::*;
|
pub use c_set_held_item::*;
|
||||||
pub use c_set_title::*;
|
pub use c_set_title::*;
|
||||||
pub use c_spawn_player::*;
|
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_core::text::TextComponent;
|
||||||
use pumpkin_inventory::WindowType;
|
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_protocol::slot::Slot;
|
||||||
use pumpkin_world::item::Item;
|
use pumpkin_world::item::Item;
|
||||||
|
|
||||||
@ -68,4 +68,18 @@ impl super::Client {
|
|||||||
CSetContainerContent::new(window_type as u8 + 1, 0.into(), &slots, &carried_item);
|
CSetContainerContent::new(window_type as u8 + 1, 0.into(), &slots, &carried_item);
|
||||||
self.send_packet(&packet);
|
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,
|
config::CConfigDisconnect,
|
||||||
login::CLoginDisconnect,
|
login::CLoginDisconnect,
|
||||||
play::{
|
play::{
|
||||||
CGameEvent, CPlayDisconnect, CSetContainerContent, CSyncPlayerPostion,
|
CGameEvent, CPlayDisconnect, CSyncPlayerPostion,
|
||||||
CSystemChatMessge,
|
CSystemChatMessge,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -41,10 +41,6 @@ use pumpkin_protocol::{
|
|||||||
ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket,
|
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 std::io::Read;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user