Skip to content

Commit

Permalink
All Inventory Types + Better Macro Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Outspending committed Jan 5, 2025
1 parent 70f9cde commit 6c3a8ba
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 180 deletions.
6 changes: 3 additions & 3 deletions src/lib/derive_macros/src/inventory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Into<Slot> + Copy>(&mut self, #field_name: S) {
self.#field_name = #field_name.into();
self.set_slot(#id, #field_name);
}
});
}
Expand Down
4 changes: 0 additions & 4 deletions src/lib/inventory/src/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
14 changes: 0 additions & 14 deletions src/lib/inventory/src/types/anvil.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/lib/inventory/src/types/beacon.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/lib/inventory/src/types/cartography.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/lib/inventory/src/types/enchanting.rs

This file was deleted.

40 changes: 0 additions & 40 deletions src/lib/inventory/src/types/furnace.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/lib/inventory/src/types/grindstone.rs

This file was deleted.

18 changes: 0 additions & 18 deletions src/lib/inventory/src/types/loom.rs

This file was deleted.

177 changes: 167 additions & 10 deletions src/lib/inventory/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -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<S: Into<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<S: Into<Slot> + 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,
}
18 changes: 0 additions & 18 deletions src/lib/inventory/src/types/smithing_table.rs

This file was deleted.

14 changes: 0 additions & 14 deletions src/lib/inventory/src/types/stonecutter.rs

This file was deleted.

0 comments on commit 6c3a8ba

Please sign in to comment.