diff --git a/pumpkin-inventory/src/lib.rs b/pumpkin-inventory/src/lib.rs index 044980cc4..0230ac189 100644 --- a/pumpkin-inventory/src/lib.rs +++ b/pumpkin-inventory/src/lib.rs @@ -1,6 +1,7 @@ use num_derive::ToPrimitive; pub mod player; +pub mod window_property; /// https://wiki.vg/Inventory #[derive(Debug, ToPrimitive, Clone)] diff --git a/pumpkin-inventory/src/window_property.rs b/pumpkin-inventory/src/window_property.rs new file mode 100644 index 000000000..64e24d044 --- /dev/null +++ b/pumpkin-inventory/src/window_property.rs @@ -0,0 +1,111 @@ +pub trait WindowPropertyTrait: Sized { + fn to_id(self) -> i16 { + 0 + } +} + +pub struct WindowProperty { + window_property: T, + value: i16 +} + +impl WindowProperty { + pub fn new(window_property: T,value: i16) -> Self { + Self { + window_property, + value + } + } + + pub fn into_packet(self) -> (i16,i16) { + (self.window_property.to_id(), self.value) + } +} + + +pub enum Furnace { + FireIcon, + MaximumFuelBurnTime, + ProgressArrow, + MaximumProgress +} + +impl WindowPropertyTrait for Furnace { + fn to_id(self) -> i16 { + self as i16 + } +} + + + +pub enum EnchantmentTable { + LevelRequirement{ + slot:u8 + }, + EnchantmentSeed, + EnchantmentId{ + slot:u8 + }, + EnchantmentLevel{slot:u8}, +} + +impl WindowPropertyTrait for EnchantmentTable { + fn to_id(self) -> i16 { + use EnchantmentTable::*; + + (match self { + LevelRequirement{slot} => slot, + EnchantmentSeed => 3, + EnchantmentId{slot} => 4+slot, + EnchantmentLevel{slot} => 7+slot, + }) as i16 + } +} + +pub enum Beacon { + PowerLevel, + FirstPotionEffect, + SecondPotionEffect +} + +impl WindowPropertyTrait for Beacon { + fn to_id(self) -> i16 { + self as i16 + } +} + +pub enum Anvil { + RepairCost +} + +impl WindowPropertyTrait for Anvil {} + +pub enum BrewingStand{ + BrewTime, + FuelTime +} + +impl WindowPropertyTrait for BrewingStand { + fn to_id(self) -> i16 { + self as i16 + } +} + +pub enum Stonecutter { + SelectedRecipe +} + +impl WindowPropertyTrait for Stonecutter {} + +pub enum Loom { + SelectedPattern +} + +impl WindowPropertyTrait for Loom {} + +pub enum Lectern { + PageNumber +} + +impl WindowPropertyTrait for Lectern {} +