format
This commit is contained in:
parent
2e00110d5d
commit
816215c698
@ -45,7 +45,7 @@ pub enum WindowType {
|
||||
impl WindowType {
|
||||
pub const fn default_title(&self) -> &'static str {
|
||||
match self {
|
||||
_ => "WINDOW TITLE"
|
||||
_ => "WINDOW TITLE",
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
use crate::slot::Slot;
|
||||
use crate::VarInt;
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[packet(0x13)]
|
||||
@ -10,10 +10,9 @@ pub struct CSetContainerContent<'a> {
|
||||
state_id: VarInt,
|
||||
count: VarInt,
|
||||
slot_data: &'a [Slot],
|
||||
carried_item: &'a Slot
|
||||
carried_item: &'a Slot,
|
||||
}
|
||||
|
||||
|
||||
impl<'a> CSetContainerContent<'a> {
|
||||
pub fn new(window_id: u8, state_id: VarInt, slots: &'a [Slot], carried_item: &'a Slot) -> Self {
|
||||
Self {
|
||||
@ -21,7 +20,7 @@ impl<'a> CSetContainerContent<'a> {
|
||||
state_id,
|
||||
count: slots.len().try_into().unwrap(),
|
||||
slot_data: slots,
|
||||
carried_item
|
||||
carried_item,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ mod c_player_chat_message;
|
||||
mod c_player_info_update;
|
||||
mod c_player_remove;
|
||||
mod c_remove_entities;
|
||||
mod c_set_container_content;
|
||||
mod c_set_held_item;
|
||||
mod c_set_title;
|
||||
mod c_spawn_player;
|
||||
@ -33,7 +34,6 @@ mod c_update_entity_pos;
|
||||
mod c_update_entity_rot;
|
||||
mod c_worldevent;
|
||||
mod player_action;
|
||||
mod c_set_container_content;
|
||||
|
||||
pub use c_acknowledge_block::*;
|
||||
pub use c_actionbar::*;
|
||||
@ -59,6 +59,7 @@ pub use c_player_chat_message::*;
|
||||
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_held_item::*;
|
||||
pub use c_set_title::*;
|
||||
pub use c_spawn_player::*;
|
||||
@ -70,4 +71,3 @@ pub use c_update_entity_pos::*;
|
||||
pub use c_update_entity_rot::*;
|
||||
pub use c_worldevent::*;
|
||||
pub use player_action::*;
|
||||
pub use c_set_container_content::*;
|
||||
@ -1,7 +1,10 @@
|
||||
use crate::VarInt;
|
||||
use pumpkin_world::item::Item;
|
||||
use serde::{de::{self, SeqAccess, Visitor}, Deserialize, Serialize, Serializer};
|
||||
use serde::ser::SerializeSeq;
|
||||
use serde::{
|
||||
de::{self, SeqAccess, Visitor},
|
||||
Deserialize, Serialize, Serializer,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(dead_code)]
|
||||
@ -122,7 +125,6 @@ impl Serialize for Slot {
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,10 @@ use pumpkin_protocol::{
|
||||
client::{
|
||||
config::CConfigDisconnect,
|
||||
login::CLoginDisconnect,
|
||||
play::{CGameEvent, CPlayDisconnect, CSyncPlayerPostion, CSystemChatMessge, CSetContainerContent},
|
||||
play::{
|
||||
CGameEvent, CPlayDisconnect, CSetContainerContent, CSyncPlayerPostion,
|
||||
CSystemChatMessge,
|
||||
},
|
||||
},
|
||||
packet_decoder::PacketDecoder,
|
||||
packet_encoder::PacketEncoder,
|
||||
@ -38,13 +41,13 @@ use pumpkin_protocol::{
|
||||
};
|
||||
use pumpkin_text::TextComponent;
|
||||
|
||||
use std::io::Read;
|
||||
use thiserror::Error;
|
||||
use pumpkin_inventory::WindowType;
|
||||
use pumpkin_protocol::bytebuf::ByteBuffer;
|
||||
use pumpkin_protocol::client::play::COpenScreen;
|
||||
use pumpkin_protocol::slot::Slot;
|
||||
use pumpkin_world::item::Item;
|
||||
use std::io::Read;
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod authentication;
|
||||
mod client_packet;
|
||||
@ -180,29 +183,57 @@ impl Client {
|
||||
self.send_packet(&CGameEvent::new(3, gamemode.to_f32().unwrap()));
|
||||
}
|
||||
|
||||
pub fn open_container(&mut self, window_type: WindowType, minecraft_menu_id: &str,window_title: Option<&str>, items: Option<Vec<Option<&Item>>>, carried_item: Option<&Item>) {
|
||||
let menu_protocol_id = (*pumpkin_world::global_registry::REGISTRY.get("minecraft:menu").unwrap().entries.get(minecraft_menu_id).expect("Should be a valid menu id").get("protocol_id").unwrap()).into();
|
||||
pub fn open_container(
|
||||
&mut self,
|
||||
window_type: WindowType,
|
||||
minecraft_menu_id: &str,
|
||||
window_title: Option<&str>,
|
||||
items: Option<Vec<Option<&Item>>>,
|
||||
carried_item: Option<&Item>,
|
||||
) {
|
||||
let menu_protocol_id = (*pumpkin_world::global_registry::REGISTRY
|
||||
.get("minecraft:menu")
|
||||
.unwrap()
|
||||
.entries
|
||||
.get(minecraft_menu_id)
|
||||
.expect("Should be a valid menu id")
|
||||
.get("protocol_id")
|
||||
.unwrap())
|
||||
.into();
|
||||
let title = TextComponent::text(window_title.unwrap_or(window_type.default_title()));
|
||||
self.send_packet(&COpenScreen::new((window_type.clone() as u8 +1).into(),menu_protocol_id, title));
|
||||
self.send_packet(&COpenScreen::new(
|
||||
(window_type.clone() as u8 + 1).into(),
|
||||
menu_protocol_id,
|
||||
title,
|
||||
));
|
||||
self.set_container_content(window_type, items, carried_item);
|
||||
}
|
||||
|
||||
pub fn set_container_content<'a>(&mut self, window_type: WindowType, items: Option<Vec<Option<&'a Item>>>, carried_item: Option<&'a Item>) {
|
||||
pub fn set_container_content<'a>(
|
||||
&mut self,
|
||||
window_type: WindowType,
|
||||
items: Option<Vec<Option<&'a Item>>>,
|
||||
carried_item: Option<&'a Item>,
|
||||
) {
|
||||
let player = self.player.as_ref().unwrap();
|
||||
|
||||
let slots: Vec<Slot> = {if let Some(mut items) = items {
|
||||
let slots: Vec<Slot> = {
|
||||
if let Some(mut items) = items {
|
||||
items.extend(player.inventory.slots());
|
||||
items
|
||||
} else {
|
||||
player.inventory.slots()
|
||||
}.into_iter()
|
||||
}
|
||||
.into_iter()
|
||||
.map(|item| {
|
||||
if let Some(item) = item {
|
||||
Slot::from(item)
|
||||
} else {
|
||||
Slot::empty()
|
||||
}
|
||||
}).collect()};
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
|
||||
let carried_item = {
|
||||
if let Some(item) = carried_item {
|
||||
@ -211,7 +242,12 @@ impl Client {
|
||||
Slot::empty()
|
||||
}
|
||||
};
|
||||
self.send_packet(&CSetContainerContent::new(window_type as u8+1, 0.into(), &slots, &carried_item));
|
||||
self.send_packet(&CSetContainerContent::new(
|
||||
window_type as u8 + 1,
|
||||
0.into(),
|
||||
&slots,
|
||||
&carried_item,
|
||||
));
|
||||
}
|
||||
|
||||
pub async fn process_packets(&mut self, server: &mut Server) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user