Add inventory support

This commit is contained in:
Snowiiii 2024-08-09 22:38:00 +02:00
parent 76106ded18
commit 50dcbfeb6d
12 changed files with 106 additions and 5 deletions

9
Cargo.lock generated
View File

@ -1163,6 +1163,7 @@ dependencies = [
"num-derive",
"num-traits",
"pumpkin-entity",
"pumpkin-inventory",
"pumpkin-protocol",
"pumpkin-registry",
"pumpkin-text",
@ -1189,6 +1190,14 @@ dependencies = [
"num-traits",
]
[[package]]
name = "pumpkin-inventory"
version = "0.1.0"
dependencies = [
"num-derive",
"num-traits",
]
[[package]]
name = "pumpkin-macros"
version = "0.1.0"

View File

@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = [ "pumpkin-entity", "pumpkin-macros/", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-text", "pumpkin-world", "pumpkin/" ]
members = [ "pumpkin-entity", "pumpkin-inventory", "pumpkin-macros/", "pumpkin-protocol/", "pumpkin-registry/", "pumpkin-world", "pumpkin/" ]
[workspace.package]
version = "0.1.0"

View File

@ -57,6 +57,7 @@ Pumpkin is currently under heavy development.
- [ ] Player Inventory
- [ ] Player Attack
- Server
- [x] Inventories
- [x] Chat
- [x] Commands

View File

@ -0,0 +1,8 @@
[package]
name = "pumpkin-inventory"
version.workspace = true
edition.workspace = true
[dependencies]
num-traits = "0.2"
num-derive = "0.4"

View File

@ -0,0 +1,41 @@
use num_derive::ToPrimitive;
/// https://wiki.vg/Inventory
#[derive(Debug, ToPrimitive)]
pub enum WindowType {
// not used
Generic9x1,
// not used
Generic9x2,
// General-purpose 3-row inventory. Used by Chest, minecart with chest, ender chest, and barrel
Generic9x3,
// not used
Generic9x4,
// not used
Generic9x5,
// Used by large chests
Generic9x6,
// General-purpose 3-by-3 square inventory, used by Dispenser and Dropper
Generic3x3,
// General-purpose 3-by-3 square inventory, used by the Crafter
Craft3x3,
Anvil,
Beacon,
BlastFurance,
BrewingStand,
CraftingTable,
EnchantmentTable,
Furnace,
Grindstone,
// Hopper or minecart with hopper
Hopper,
Lectern,
Loom,
// Villager, Wandering Trader
Merchant,
ShulkerBox,
SmithingTable,
Smoker,
CartographyTable,
Stonecutter,
}

View File

@ -0,0 +1,23 @@
use pumpkin_macros::packet;
use pumpkin_text::TextComponent;
use serde::Serialize;
use crate::VarInt;
#[derive(Serialize, Clone)]
#[packet(0x33)]
pub struct COpenScreen {
window_id: VarInt,
window_type: VarInt,
window_title: TextComponent,
}
impl COpenScreen {
pub fn new(window_id: VarInt, window_type: VarInt, window_title: TextComponent) -> Self {
Self {
window_id,
window_type,
window_title,
}
}
}

View File

@ -6,6 +6,7 @@ mod c_entity_metadata;
mod c_game_event;
mod c_head_rot;
mod c_login;
mod c_open_screen;
mod c_play_disconnect;
mod c_player_abilities;
mod c_player_chat_message;
@ -28,6 +29,7 @@ pub use c_entity_metadata::*;
pub use c_game_event::*;
pub use c_head_rot::*;
pub use c_login::*;
pub use c_open_screen::*;
pub use c_play_disconnect::*;
pub use c_player_abilities::*;
pub use c_player_chat_message::*;

View File

@ -1 +1,7 @@
pub struct ChatType {}
pub struct Decoration {
translation_key: String,
// style: Option,
parameters: Vec<String>,
}

View File

@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
pumpkin-text = { path = "../pumpkin-text" }
pumpkin-inventory = { path = "../pumpkin-inventory"}
pumpkin-world = { path = "../pumpkin-world"}
pumpkin-entity = { path = "../pumpkin-entity"}
pumpkin-protocol = { path = "../pumpkin-protocol"}

View File

@ -134,6 +134,7 @@ impl Client {
}
}
for ele in self.gameprofile.as_ref().unwrap().properties.clone() {
// todo, use this
unpack_textures(ele, &server.advanced_config.authentication.textures);
}

View File

@ -1,14 +1,15 @@
use num_traits::FromPrimitive;
use pumpkin_inventory::WindowType;
use pumpkin_protocol::{
client::play::{
Animation, CEntityAnimation, CHeadRot, CSystemChatMessge, CUpdateEntityPos,
Animation, CEntityAnimation, CHeadRot, COpenScreen, CSystemChatMessge, CUpdateEntityPos,
CUpdateEntityPosRot, CUpdateEntityRot,
},
server::play::{
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
SPlayerPositionRotation, SPlayerRotation, SSwingArm,
},
};
}, VarInt,
};
use pumpkin_text::TextComponent;
use crate::{
@ -189,6 +190,14 @@ impl Client {
pub fn handle_chat_message(&mut self, server: &mut Server, chat_message: SChatMessage) {
let message = chat_message.message;
server.broadcast_packet(
self,
COpenScreen::new(
VarInt(0),
VarInt(WindowType::CraftingTable as i32),
TextComponent::from("Test Crafter"),
),
);
// TODO: filter message & validation
let gameprofile = self.gameprofile.as_ref().unwrap();
dbg!("got message");