From b7193fc3142a6fc0cafe74f64a3e38a1938b40e0 Mon Sep 17 00:00:00 2001 From: Andrew Gazelka Date: Tue, 12 Nov 2024 16:54:29 -0800 Subject: [PATCH] feat(ranks): Add Excavator rank and refine mining mechanics - Add new Excavator rank with custom skin and inventory loadout - Refactor inventory slot management to use variables instead of constants - Update ore distribution weights to include coal and rebalance percentages - Enhance Miner rank with torch and upgraded pickaxe - Add PartialEq, Eq traits to Rank enum --- crates/hyperion-rank-tree/src/inventory.rs | 59 ++++++++++++++----- crates/hyperion-rank-tree/src/lib.rs | 4 +- crates/hyperion-rank-tree/src/skin.rs | 2 + .../src/skin/excavator.toml | 5 ++ .../proof-of-concept/src/command/replace.rs | 17 +++--- 5 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 crates/hyperion-rank-tree/src/skin/excavator.toml diff --git a/crates/hyperion-rank-tree/src/inventory.rs b/crates/hyperion-rank-tree/src/inventory.rs index 9b533be5..4282d0d9 100644 --- a/crates/hyperion-rank-tree/src/inventory.rs +++ b/crates/hyperion-rank-tree/src/inventory.rs @@ -20,16 +20,22 @@ impl Team { impl Rank { pub fn apply_inventory(self, team: Team, inventory: &mut PlayerInventory) { - const PICKAXE_SLOT: u16 = 1; - const BUILD_SLOT: u16 = 2; - const ARROW_SLOT: u16 = 7; - const GUI_SLOT: u16 = 8; + let mut pickaxe_slot: u16 = 1; + + if self == Rank::Miner { + pickaxe_slot = 1; + } + + let main_slot: u16 = 0; + let build_slot: u16 = 2; + let arrow_slot: u16 = 7; + let gui_slot: u16 = 8; let default_pickaxe = ItemBuilder::new(ItemKind::WoodenPickaxe).build(); - inventory.set_hotbar(PICKAXE_SLOT, default_pickaxe); + inventory.set_hotbar(pickaxe_slot, default_pickaxe); let default_build_item = team.build_item().count(16).build(); - inventory.set_hotbar(BUILD_SLOT, default_build_item); + inventory.set_hotbar(build_slot, default_build_item); match self { Self::Stick => { @@ -39,17 +45,17 @@ impl Rank { .add_attribute(AttackDamage(3.0)) .build(); - inventory.set_hotbar(0, stick); + inventory.set_hotbar(main_slot, stick); } Self::Archer => { let bow = ItemBuilder::new(ItemKind::Bow).build(); - inventory.set_hotbar(0, bow); + inventory.set_hotbar(main_slot, bow); let arrow = ItemBuilder::new(ItemKind::Arrow).count(64).build(); - inventory.set_hotbar(ARROW_SLOT, arrow); + inventory.set_hotbar(arrow_slot, arrow); } Self::Sword => { let sword = ItemBuilder::new(ItemKind::StoneSword) @@ -57,15 +63,23 @@ impl Rank { .add_attribute(AttackDamage(3.0)) .build(); - inventory.set_hotbar(0, sword); + inventory.set_hotbar(main_slot, sword); } Self::Miner => { - let pickaxe = ItemBuilder::new(ItemKind::WoodenPickaxe) + let torch = ItemBuilder::new(ItemKind::Torch) + .name("§3§lTORCH") + .glowing() + .add_attribute(AttackDamage(3.0)) + .build(); + + inventory.set_hotbar(main_slot, torch); + + let pickaxe = ItemBuilder::new(ItemKind::StonePickaxe) .add_attribute(AttackDamage(2.0)) .build(); - inventory.set_hotbar(0, pickaxe); + inventory.set_hotbar(pickaxe_slot, pickaxe); } Self::Mage => { @@ -74,7 +88,7 @@ impl Rank { .add_attribute(AttackDamage(2.0)) .build(); - inventory.set_hotbar(0, wand); + inventory.set_hotbar(main_slot, wand); } Self::Knight => { let knight_sword = ItemBuilder::new(ItemKind::IronSword) @@ -83,14 +97,27 @@ impl Rank { .add_attribute(AttackDamage(4.0)) .build(); - inventory.set_hotbar(0, knight_sword); + inventory.set_hotbar(main_slot, knight_sword); } Self::Builder => { let builder_tool = ItemBuilder::new(ItemKind::GoldenPickaxe) .add_attribute(AttackDamage(5.0)) .build(); - inventory.set_hotbar(0, builder_tool); + inventory.set_hotbar(main_slot, builder_tool); + } + Rank::Excavator => { + let pickaxe = ItemBuilder::new(ItemKind::IronPickaxe).build(); + + inventory.set_hotbar(pickaxe_slot, pickaxe); + + let minecart = ItemBuilder::new(ItemKind::Minecart) + .name("§3§lMINECART") + .glowing() + .add_attribute(AttackDamage(3.0)) + .build(); + + inventory.set_hotbar(main_slot, minecart); } } @@ -98,6 +125,6 @@ impl Rank { .name("Upgrades") .build(); - inventory.set_hotbar(GUI_SLOT, upgrade_item); + inventory.set_hotbar(gui_slot, upgrade_item); } } diff --git a/crates/hyperion-rank-tree/src/lib.rs b/crates/hyperion-rank-tree/src/lib.rs index 7713f0e6..6f643d68 100644 --- a/crates/hyperion-rank-tree/src/lib.rs +++ b/crates/hyperion-rank-tree/src/lib.rs @@ -5,7 +5,7 @@ pub mod skin; mod util; -#[derive(Copy, Clone, Debug, ValueEnum)] +#[derive(Copy, Clone, Debug, ValueEnum, PartialEq, Eq)] #[repr(C)] pub enum Rank { /// ![Widget Example](https://i.imgur.com/pW7v0Xn.png) @@ -17,6 +17,8 @@ pub enum Rank { Sword, Miner, + Excavator, + Mage, Knight, Builder, diff --git a/crates/hyperion-rank-tree/src/skin.rs b/crates/hyperion-rank-tree/src/skin.rs index 1af19bda..ab88cab9 100644 --- a/crates/hyperion-rank-tree/src/skin.rs +++ b/crates/hyperion-rank-tree/src/skin.rs @@ -20,6 +20,7 @@ define_skin!(ARCHER_SKIN, "skin/archer.toml"); define_skin!(MAGE_SKIN, "skin/mage.toml"); define_skin!(BUILDER_SKIN, "skin/builder.toml"); define_skin!(MINER_SKIN, "skin/miner.toml"); +define_skin!(EXCAVATOR_SKIN, "skin/excavator.toml"); impl Rank { #[must_use] @@ -32,6 +33,7 @@ impl Rank { Self::Mage => &MAGE_SKIN, Self::Builder => &BUILDER_SKIN, Self::Miner => &MINER_SKIN, + Rank::Excavator => &EXCAVATOR_SKIN, } } } diff --git a/crates/hyperion-rank-tree/src/skin/excavator.toml b/crates/hyperion-rank-tree/src/skin/excavator.toml new file mode 100644 index 00000000..8d7915c6 --- /dev/null +++ b/crates/hyperion-rank-tree/src/skin/excavator.toml @@ -0,0 +1,5 @@ +# https://mineskin.org/ +# https://namemc.com/skin/bef08f02f7e42ed9 +textures = """ewogICJ0aW1lc3RhbXAiIDogMTcxNTE5Njk3MTg4MCwKICAicHJvZ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Ak80bsjaE1EcZxyTkBMC1opQxwEQh/b19VbLTA=""" diff --git a/events/proof-of-concept/src/command/replace.rs b/events/proof-of-concept/src/command/replace.rs index 38738583..c983b502 100644 --- a/events/proof-of-concept/src/command/replace.rs +++ b/events/proof-of-concept/src/command/replace.rs @@ -15,20 +15,21 @@ pub struct ReplaceCommand; /// Weights are roughly based on real Minecraft ore distribution fn pick_ore() -> BlockState { // Total weight is 100 for easy percentage calculation - const WEIGHTS: [(BlockState, u32); 5] = [ - (BlockState::COBBLESTONE, 40), // 40% - (BlockState::COPPER_ORE, 35), // 35% - (BlockState::IRON_ORE, 15), // 15% - (BlockState::GOLD_ORE, 8), // 8% - (BlockState::EMERALD_ORE, 2), // 2% + const WEIGHTS: &[(BlockState, u32)] = &[ + (BlockState::COBBLESTONE, 35), + (BlockState::COAL_ORE, 35), + (BlockState::COPPER_ORE, 25), + (BlockState::IRON_ORE, 15), + (BlockState::GOLD_ORE, 8), + (BlockState::EMERALD_ORE, 2), ]; let total_weight: u32 = WEIGHTS.iter().map(|(_, w)| w).sum(); let mut roll = fastrand::u32(0..total_weight); for (block, weight) in WEIGHTS { - if roll < weight { - return block; + if roll < *weight { + return *block; } roll -= weight; }