Simply abstraction of property trait

This commit is contained in:
Edvin Bryntesson committed 2024-08-24 18:03:32 +02:00
1 parent ef21b3ae40
commit 52943f66c8
3 files changed
+19 -67

No files matched your search

+16 -30
View File
@@ -1,6 +1,13 @@
pub trait WindowPropertyTrait: Sized {
use num_derive::ToPrimitive;
use num_traits::ToPrimitive;
pub trait WindowPropertyTrait {
fn to_id(self) -> i16;
}
impl<T: ToPrimitive> WindowPropertyTrait for T {
fn to_id(self) -> i16 {
0
self.to_i16().unwrap()
}
}
@@ -21,7 +28,7 @@ impl<T: WindowPropertyTrait> WindowProperty<T> {
(self.window_property.to_id(), self.value)
}
}
#[derive(ToPrimitive)]
pub enum Furnace {
FireIcon,
MaximumFuelBurnTime,
@@ -29,12 +36,6 @@ pub enum Furnace {
MaximumProgress,
}
impl WindowPropertyTrait for Furnace {
fn to_id(self) -> i16 {
self as i16
}
}
pub enum EnchantmentTable {
LevelRequirement { slot: u8 },
EnchantmentSeed,
@@ -54,50 +55,35 @@ impl WindowPropertyTrait for EnchantmentTable {
}) as i16
}
}
#[derive(ToPrimitive)]
pub enum Beacon {
PowerLevel,
FirstPotionEffect,
SecondPotionEffect,
}
impl WindowPropertyTrait for Beacon {
fn to_id(self) -> i16 {
self as i16
}
}
#[derive(ToPrimitive)]
pub enum Anvil {
RepairCost,
}
impl WindowPropertyTrait for Anvil {}
#[derive(ToPrimitive)]
pub enum BrewingStand {
BrewTime,
FuelTime,
}
impl WindowPropertyTrait for BrewingStand {
fn to_id(self) -> i16 {
self as i16
}
}
#[derive(ToPrimitive)]
pub enum Stonecutter {
SelectedRecipe,
}
impl WindowPropertyTrait for Stonecutter {}
#[derive(ToPrimitive)]
pub enum Loom {
SelectedPattern,
}
impl WindowPropertyTrait for Loom {}
#[derive(ToPrimitive)]
pub enum Lectern {
PageNumber,
}
impl WindowPropertyTrait for Lectern {}