Skip to content

Commit

Permalink
Add inventory support
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 9, 2024
1 parent 76106de commit 50dcbfe
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Pumpkin is currently under heavy development.
- [ ] Player Inventory
- [ ] Player Attack
- Server
- [x] Inventories
- [x] Chat
- [x] Commands

Expand Down
8 changes: 8 additions & 0 deletions pumpkin-inventory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "pumpkin-inventory"
version.workspace = true
edition.workspace = true

[dependencies]
num-traits = "0.2"
num-derive = "0.4"
41 changes: 41 additions & 0 deletions pumpkin-inventory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
}
23 changes: 23 additions & 0 deletions pumpkin-protocol/src/client/play/c_open_screen.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
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 @@ -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;
Expand All @@ -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::*;
Expand Down
6 changes: 6 additions & 0 deletions pumpkin-registry/src/chat_type.rs
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
pub struct ChatType {}

pub struct Decoration {
translation_key: String,
// style: Option,
parameters: Vec<String>,
}
2 changes: 1 addition & 1 deletion pumpkin-text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@ impl Default for TextContent {
fn default() -> Self {
Self::Text { text: "".into() }
}
}
}
1 change: 1 addition & 0 deletions pumpkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
1 change: 1 addition & 0 deletions pumpkin/src/client/client_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
15 changes: 12 additions & 3 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 50dcbfe

Please sign in to comment.