Skip to content

Commit

Permalink
Inventory Types
Browse files Browse the repository at this point in the history
  • Loading branch information
Outspending committed Jan 5, 2025
1 parent 2ff5a83 commit 4a59780
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/lib/derive_macros/src/inventory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ pub fn create(input: TokenStream) -> TokenStream {
}

// Generate the `new` method
let new_method = if let Some(expr) = inventory_type_expr {
Some(quote! {
let new_method = inventory_type_expr.map(|expr| quote! {
pub fn new(id: u8) -> Self {
Self {
inventory: #net_crate::builder::InventoryBuilder::new(id)
Expand All @@ -116,10 +115,7 @@ pub fn create(input: TokenStream) -> TokenStream {
#(#default_statements)*
}
}
})
} else {
None
};
});

// Generate the complete implementation block
// Wacky ass code because rust is retarded
Expand Down
2 changes: 1 addition & 1 deletion src/lib/inventory/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Inventory {

let slot = self
.get_slot(36 + (carried_item as i16))
.unwrap_or_else(|| Slot::empty());
.unwrap_or_else(Slot::empty);

self.carried_item = slot;
}
Expand Down
14 changes: 14 additions & 0 deletions src/lib/inventory/src/types/anvil.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::inventory::Inventory;
use ferrumc_macros::{Inventory, inventory_type};

#[derive(Inventory, Debug)]
#[inventory_type(value = Anvil)]
pub struct EnchantingInventory {
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,
}
2 changes: 1 addition & 1 deletion src/lib/inventory/src/types/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ferrumc_macros::{Inventory, inventory_type};

use crate::inventory::Inventory;

#[derive(Inventory)]
#[derive(Inventory, Debug)]
#[inventory_type(value = Beacon)]
pub struct BeaconInventory {
inventory: Inventory,
Expand Down
14 changes: 14 additions & 0 deletions src/lib/inventory/src/types/cartography.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::inventory::Inventory;
use ferrumc_macros::{Inventory, inventory_type};

#[derive(Inventory, Debug)]
#[inventory_type(value = 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,
}
2 changes: 1 addition & 1 deletion src/lib/inventory/src/types/enchanting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ferrumc_macros::{Inventory, inventory_type};

use crate::inventory::Inventory;

#[derive(Inventory)]
#[derive(Inventory, Debug)]
#[inventory_type(value = EnchantmentTable)]
pub struct EnchantingInventory {
inventory: Inventory,
Expand Down
38 changes: 38 additions & 0 deletions src/lib/inventory/src/types/furnace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::inventory::Inventory;
use ferrumc_macros::{Inventory, inventory_type};

#[derive(Inventory, Debug)]
#[inventory_type(value = 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)]
#[inventory_type(value = 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)]
#[inventory_type(value = 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,
}
14 changes: 14 additions & 0 deletions src/lib/inventory/src/types/grindstone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::inventory::Inventory;
use ferrumc_macros::{Inventory, inventory_type};

#[derive(Inventory, Debug)]
#[inventory_type(value = 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,
}
16 changes: 16 additions & 0 deletions src/lib/inventory/src/types/loom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::inventory::Inventory;
use ferrumc_macros::{Inventory, inventory_type};

#[derive(Inventory, Debug)]
#[inventory_type(value = 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,
}
7 changes: 7 additions & 0 deletions src/lib/inventory/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
mod anvil;
pub mod beacon;
mod cartography;
pub mod enchanting;
mod furnace;
mod grindstone;
mod loom;
pub mod player;
mod smithing_table;
mod stonecutter;
16 changes: 16 additions & 0 deletions src/lib/inventory/src/types/smithing_table.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::inventory::Inventory;
use ferrumc_macros::{Inventory, inventory_type};

#[derive(Inventory, Debug)]
#[inventory_type(value = 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,
}
12 changes: 12 additions & 0 deletions src/lib/inventory/src/types/stonecutter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::inventory::Inventory;
use ferrumc_macros::{Inventory, inventory_type};

#[derive(Inventory, Debug)]
#[inventory_type(value = Stonecutter)]
pub struct StoneCutterInventory {
inventory: Inventory,
#[slot(id = 0, default_value = 0)]
pub input: i32,
#[slot(id = 1, default_value = 0)]
pub result: i32,
}

0 comments on commit 4a59780

Please sign in to comment.