diff --git a/src/lib/derive_macros/src/inventory/mod.rs b/src/lib/derive_macros/src/inventory/mod.rs index 7ed5c8e3..c5722bbf 100644 --- a/src/lib/derive_macros/src/inventory/mod.rs +++ b/src/lib/derive_macros/src/inventory/mod.rs @@ -106,9 +106,9 @@ pub fn create(input: TokenStream) -> TokenStream { let setter_name = syn::Ident::new(&format!("set_{}", field_name), field_name.span()); field_statements.push(quote! { - pub fn #setter_name(&mut self, #field_name: #field_ty) { - self.#field_name = #field_name; - self.set_slot(#id, #net_crate::slot::Slot::with_item(#field_name)); + pub fn #setter_name + Copy>(&mut self, #field_name: S) { + self.#field_name = #field_name.into(); + self.set_slot(#id, #field_name); } }); } diff --git a/src/lib/inventory/src/contents.rs b/src/lib/inventory/src/contents.rs index 0fc385fd..a9333d4c 100644 --- a/src/lib/inventory/src/contents.rs +++ b/src/lib/inventory/src/contents.rs @@ -43,8 +43,4 @@ impl InventoryContents { LengthPrefixedVec::new(contents) } - - //to store in chunk metadata: TAG 44: byte - //to show: starts at slot 0 ALWAYS - > 26/53 smalll/large. - //other inventories are to be implemented after. } diff --git a/src/lib/inventory/src/types/anvil.rs b/src/lib/inventory/src/types/anvil.rs deleted file mode 100644 index b9641e18..00000000 --- a/src/lib/inventory/src/types/anvil.rs +++ /dev/null @@ -1,14 +0,0 @@ -use crate::inventory::Inventory; -use ferrumc_macros::{Inventory, inventory}; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = Anvil)] -pub struct AnvilInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub first: i32, - #[slot(id = 1, default_value = 0)] - pub second: i32, - #[slot(id = 2, default_value = 0)] - pub result: i32, -} diff --git a/src/lib/inventory/src/types/beacon.rs b/src/lib/inventory/src/types/beacon.rs deleted file mode 100644 index 2a01f655..00000000 --- a/src/lib/inventory/src/types/beacon.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![warn(dead_code)] - -use ferrumc_macros::{Inventory, inventory}; - -use crate::inventory::Inventory; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = Beacon)] -pub struct BeaconInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub powered_item: i32, -} diff --git a/src/lib/inventory/src/types/cartography.rs b/src/lib/inventory/src/types/cartography.rs deleted file mode 100644 index 71ee6c62..00000000 --- a/src/lib/inventory/src/types/cartography.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![warn(dead_code)] -use crate::inventory::Inventory; -use ferrumc_macros::{Inventory, inventory}; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = Cartography)] -pub struct EnchantingInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub map: i32, - #[slot(id = 1, default_value = 0)] - pub paper: i32, - #[slot(id = 2, default_value = 0)] - pub output: i32, -} diff --git a/src/lib/inventory/src/types/enchanting.rs b/src/lib/inventory/src/types/enchanting.rs deleted file mode 100644 index ad7cb6e4..00000000 --- a/src/lib/inventory/src/types/enchanting.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![warn(dead_code)] - -use ferrumc_macros::{Inventory, inventory}; - -use crate::inventory::Inventory; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = EnchantmentTable)] -pub struct EnchantingInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub item: i32, - #[slot(id = 1, default_value = 0)] - pub secondary: i32, -} diff --git a/src/lib/inventory/src/types/furnace.rs b/src/lib/inventory/src/types/furnace.rs deleted file mode 100644 index 3ef6ccfe..00000000 --- a/src/lib/inventory/src/types/furnace.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![warn(dead_code)] - -use crate::inventory::Inventory; -use ferrumc_macros::{Inventory, inventory}; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = Furnace)] -pub struct FurnaceInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub ingredient: i32, - #[slot(id = 1, default_value = 0)] - pub fuel: i32, - #[slot(id = 2, default_value = 0)] - pub output: i32, -} - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = BlastFurnace)] -pub struct BlastFurnaceInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub ingredient: i32, - #[slot(id = 1, default_value = 0)] - pub fuel: i32, - #[slot(id = 2, default_value = 0)] - pub output: i32, -} - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = Smoker)] -pub struct SmokerInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub ingredient: i32, - #[slot(id = 1, default_value = 0)] - pub fuel: i32, - #[slot(id = 2, default_value = 0)] - pub output: i32, -} diff --git a/src/lib/inventory/src/types/grindstone.rs b/src/lib/inventory/src/types/grindstone.rs deleted file mode 100644 index 5f7f527e..00000000 --- a/src/lib/inventory/src/types/grindstone.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![warn(dead_code)] - -use crate::inventory::Inventory; -use ferrumc_macros::{Inventory, inventory}; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = Grindstone)] -pub struct GrindstoneInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub first: i32, - #[slot(id = 1, default_value = 0)] - pub second: i32, - #[slot(id = 2, default_value = 0)] - pub result: i32, -} diff --git a/src/lib/inventory/src/types/loom.rs b/src/lib/inventory/src/types/loom.rs deleted file mode 100644 index 736ba320..00000000 --- a/src/lib/inventory/src/types/loom.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![warn(dead_code)] - -use crate::inventory::Inventory; -use ferrumc_macros::{Inventory, inventory}; - -#[derive(Inventory, Debug)] -#[inventory(inventory_type = Loom)] -pub struct LoomInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub banner: i32, - #[slot(id = 1, default_value = 0)] - pub dye: i32, - #[slot(id = 2, default_value = 0)] - pub pattern: i32, - #[slot(id = 3, default_value = 0)] - pub result: i32, -} diff --git a/src/lib/inventory/src/types/mod.rs b/src/lib/inventory/src/types/mod.rs index 6da5b7e2..372a21f8 100644 --- a/src/lib/inventory/src/types/mod.rs +++ b/src/lib/inventory/src/types/mod.rs @@ -1,10 +1,167 @@ -pub mod anvil; -pub mod beacon; -pub mod cartography; -pub mod enchanting; -pub mod furnace; -pub mod grindstone; -pub mod loom; -pub mod player; -pub mod smithing_table; -pub mod stonecutter; +use ferrumc_macros::{Inventory, inventory}; + +use crate::{inventory::Inventory, slot::Slot}; + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Anvil)] +pub struct AnvilInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub first: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub second: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub result: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Beacon)] +pub struct BeaconInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub powered_item: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Cartography)] +pub struct EnchantingInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub map: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub paper: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub output: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Furnace)] +pub struct FurnaceInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub ingredient: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub fuel: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub output: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = BlastFurnace)] +pub struct BlastFurnaceInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub ingredient: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub fuel: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub output: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Smoker)] +pub struct SmokerInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub ingredient: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub fuel: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub output: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Grindstone)] +pub struct GrindstoneInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub first: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub second: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub result: Slot, +} + +#[derive(Inventory, Debug)] +#[inventory(inventory_type = Loom)] +pub struct LoomInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub banner: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub dye: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub pattern: Slot, + #[slot(id = 3, default_value = Slot::empty())] + pub result: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = SmithingTable)] +pub struct SmithingTableInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub template: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub base: Slot, + #[slot(id = 2, default_value = Slot::empty())] + pub additional: Slot, + #[slot(id = 3, default_value = Slot::empty())] + pub result: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Stonecutter)] +pub struct StoneCutterInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub input: Slot, + #[slot(id = 1, default_value = Slot::empty())] + pub result: Slot, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = BrewingStand)] +pub struct BrewingStandInventory { + inventory: Inventory, + #[slot(id = 3, default_value = Slot::empty())] + pub potion_ingredient: Slot, + #[slot(id = 4, default_value = Slot::empty())] + pub blaze_powder: Slot, +} + +impl BrewingStandInventory { + pub fn set_potion_slot + Copy>(&mut self, index: i16, slot: S) { + if (0..=2).contains(&index) { + self.set_slot(index, slot); + } + } +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = CraftingTable)] +pub struct CraftingTableInventory { + inventory: Inventory, + #[slot(id = 0, default_value = Slot::empty())] + pub output: Slot, +} + +impl CraftingTableInventory { + pub fn set_crafting_input + Copy>(&mut self, index: i16, slot: S) { + if (0..=8).contains(&index) { + self.set_slot(1 + index, slot); + } + } +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = Hopper)] +pub struct HopperInventory { + inventory: Inventory, +} + +#[derive(Inventory, Debug, Clone)] +#[inventory(inventory_type = ShulkerBox)] +pub struct ShulkerBoxInventory { + inventory: Inventory, +} diff --git a/src/lib/inventory/src/types/smithing_table.rs b/src/lib/inventory/src/types/smithing_table.rs deleted file mode 100644 index 194d2cd3..00000000 --- a/src/lib/inventory/src/types/smithing_table.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![warn(dead_code)] - -use crate::inventory::Inventory; -use ferrumc_macros::{Inventory, inventory}; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = SmithingTable)] -pub struct SmithingTableInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub template: i32, - #[slot(id = 1, default_value = 0)] - pub base: i32, - #[slot(id = 2, default_value = 0)] - pub additional: i32, - #[slot(id = 3, default_value = 0)] - pub result: i32, -} diff --git a/src/lib/inventory/src/types/stonecutter.rs b/src/lib/inventory/src/types/stonecutter.rs deleted file mode 100644 index dd39d4ae..00000000 --- a/src/lib/inventory/src/types/stonecutter.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![warn(dead_code)] - -use crate::inventory::Inventory; -use ferrumc_macros::{Inventory, inventory}; - -#[derive(Inventory, Debug, Clone)] -#[inventory(inventory_type = Stonecutter)] -pub struct StoneCutterInventory { - inventory: Inventory, - #[slot(id = 0, default_value = 0)] - pub input: i32, - #[slot(id = 1, default_value = 0)] - pub result: i32, -}