Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryntet committed Aug 23, 2024
1 parent 4523900 commit 98fcd41
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 52 deletions.
46 changes: 19 additions & 27 deletions pumpkin-inventory/src/window_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@ pub trait WindowPropertyTrait: Sized {

pub struct WindowProperty<T: WindowPropertyTrait> {
window_property: T,
value: i16
value: i16,
}

impl<T: WindowPropertyTrait> WindowProperty<T> {
pub fn new(window_property: T,value: i16) -> Self {
pub fn new(window_property: T, value: i16) -> Self {
Self {
window_property,
value
value,
}
}
pub fn into_packet(self) -> (i16,i16) {

pub fn into_packet(self) -> (i16, i16) {
(self.window_property.to_id(), self.value)
}
}


pub enum Furnace {
FireIcon,
MaximumFuelBurnTime,
ProgressArrow,
MaximumProgress
MaximumProgress,
}

impl WindowPropertyTrait for Furnace {
Expand All @@ -36,36 +35,30 @@ impl WindowPropertyTrait for Furnace {
}
}



pub enum EnchantmentTable {
LevelRequirement{
slot:u8
},
LevelRequirement { slot: u8 },
EnchantmentSeed,
EnchantmentId{
slot:u8
},
EnchantmentLevel{slot:u8},
EnchantmentId { slot: u8 },
EnchantmentLevel { slot: u8 },
}

impl WindowPropertyTrait for EnchantmentTable {
fn to_id(self) -> i16 {
use EnchantmentTable::*;

(match self {
LevelRequirement{slot} => slot,
LevelRequirement { slot } => slot,
EnchantmentSeed => 3,
EnchantmentId{slot} => 4+slot,
EnchantmentLevel{slot} => 7+slot,
EnchantmentId { slot } => 4 + slot,
EnchantmentLevel { slot } => 7 + slot,
}) as i16
}
}

pub enum Beacon {
PowerLevel,
FirstPotionEffect,
SecondPotionEffect
SecondPotionEffect,
}

impl WindowPropertyTrait for Beacon {
Expand All @@ -75,14 +68,14 @@ impl WindowPropertyTrait for Beacon {
}

pub enum Anvil {
RepairCost
RepairCost,
}

impl WindowPropertyTrait for Anvil {}

pub enum BrewingStand{
pub enum BrewingStand {
BrewTime,
FuelTime
FuelTime,
}

impl WindowPropertyTrait for BrewingStand {
Expand All @@ -92,20 +85,19 @@ impl WindowPropertyTrait for BrewingStand {
}

pub enum Stonecutter {
SelectedRecipe
SelectedRecipe,
}

impl WindowPropertyTrait for Stonecutter {}

pub enum Loom {
SelectedPattern
SelectedPattern,
}

impl WindowPropertyTrait for Loom {}

pub enum Lectern {
PageNumber
PageNumber,
}

impl WindowPropertyTrait for Lectern {}

10 changes: 4 additions & 6 deletions pumpkin-protocol/src/client/play/c_close_container.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use serde::Serialize;
use pumpkin_macros::packet;
use serde::Serialize;

#[derive(Serialize)]
#[packet(0x12)]
pub struct CCloseContainer {
window_id: u8
window_id: u8,
}

impl CCloseContainer {
pub const fn new(window_id: u8) -> Self {
Self {
window_id
}
Self { window_id }
}
}
}
8 changes: 4 additions & 4 deletions pumpkin-protocol/src/client/play/c_set_container_property.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use serde::Serialize;
use pumpkin_macros::packet;
use serde::Serialize;
#[derive(Serialize)]
#[packet(0x14)]
pub struct CSetContainerProperty {
window_id: u8,
property: i16,
value: i16
value: i16,
}

impl CSetContainerProperty {
pub const fn new(window_id: u8, property: i16, value:i16) -> Self {
pub const fn new(window_id: u8, property: i16, value: i16) -> Self {
Self {
window_id,
property,
value
value,
}
}
}
8 changes: 4 additions & 4 deletions pumpkin-protocol/src/client/play/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod c_block_update;
mod c_center_chunk;
mod c_change_difficulty;
mod c_chunk_data;
mod c_close_container;
mod c_disguised_chat_message;
mod c_entity_animation;
mod c_entity_metadata;
Expand All @@ -23,6 +24,7 @@ mod c_player_info_update;
mod c_player_remove;
mod c_remove_entities;
mod c_set_container_content;
mod c_set_container_property;
mod c_set_container_slot;
mod c_set_held_item;
mod c_set_title;
Expand All @@ -36,8 +38,6 @@ mod c_update_entity_pos;
mod c_update_entity_rot;
mod c_worldevent;
mod player_action;
mod c_close_container;
mod c_set_container_property;

pub use c_acknowledge_block::*;
pub use c_actionbar::*;
Expand All @@ -46,6 +46,7 @@ pub use c_block_update::*;
pub use c_center_chunk::*;
pub use c_change_difficulty::*;
pub use c_chunk_data::*;
pub use c_close_container::*;
pub use c_disguised_chat_message::*;
pub use c_entity_animation::*;
pub use c_entity_metadata::*;
Expand All @@ -64,6 +65,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_property::*;
pub use c_set_container_slot::*;
pub use c_set_held_item::*;
pub use c_set_title::*;
Expand All @@ -77,5 +79,3 @@ pub use c_update_entity_pos::*;
pub use c_update_entity_rot::*;
pub use c_worldevent::*;
pub use player_action::*;
pub use c_close_container::*;
pub use c_set_container_property::*;
25 changes: 14 additions & 11 deletions pumpkin/src/client/container.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use pumpkin_core::text::TextComponent;
use pumpkin_inventory::window_property::{WindowProperty, WindowPropertyTrait};
use pumpkin_inventory::WindowType;
use pumpkin_protocol::client::play::{CCloseContainer, COpenScreen, CSetContainerContent, CSetContainerProperty, CSetContainerSlot};
use pumpkin_protocol::client::play::{
CCloseContainer, COpenScreen, CSetContainerContent, CSetContainerProperty, CSetContainerSlot,
};
use pumpkin_protocol::slot::Slot;
use pumpkin_world::item::Item;

Expand Down Expand Up @@ -83,17 +85,18 @@ impl super::Client {
&item.into(),
))
}

/// The official Minecraft client is weird, and will always just close *any* window that is opened when this gets sent
pub fn close_container(
&mut self,
window_type: WindowType
) {

/// The official Minecraft client is weird, and will always just close *any* window that is opened when this gets sent
pub fn close_container(&mut self, window_type: WindowType) {
self.send_packet(&CCloseContainer::new(window_type as u8))
}

pub fn set_container_property<T: WindowPropertyTrait>(&mut self, window_type: WindowType, window_property: WindowProperty<T>) {
let (id,value) = window_property.into_packet();
self.send_packet(&CSetContainerProperty::new(window_type as u8,id,value));

pub fn set_container_property<T: WindowPropertyTrait>(
&mut self,
window_type: WindowType,
window_property: WindowProperty<T>,
) {
let (id, value) = window_property.into_packet();
self.send_packet(&CSetContainerProperty::new(window_type as u8, id, value));
}
}

0 comments on commit 98fcd41

Please sign in to comment.