From b6b7fb1a6549ba0c92c5db141af6f6f9bc1d3038 Mon Sep 17 00:00:00 2001 From: KingCol13 <48412633+KingCol13@users.noreply.github.com> Date: Sun, 20 Sep 2020 19:06:28 +0100 Subject: Implement fortune for ores, glowstone and sea lanterns (#4897) * Implemented fortune for ores, glowstone and sea lanterns (but nothing organic or flint). * Cleanup printf * Stopped playing golf, gave the Camels a FirstHump and moved the FortuneDropMult comment. Thanks for the review :). * Got rid of FortuneDropMult and replaced with Peter's massive optimization/simplification. * Fixed default lapis max droprate (8 -> 9). * Clamp max drops for non-redstone ores to 10. * Comment justifying the clamp. --- src/Blocks/BlockOre.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/Blocks/BlockOre.h') diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h index e329a5781..6c01a6a27 100644 --- a/src/Blocks/BlockOre.h +++ b/src/Blocks/BlockOre.h @@ -3,10 +3,6 @@ #include "BlockHandler.h" - - - - class cBlockOreHandler: public cBlockHandler { @@ -31,17 +27,20 @@ private: } } - // TODO: Handle the Fortune enchantment here auto & random = GetRandomProvider(); + const unsigned int FortuneLevel = ToolFortuneLevel(a_Tool); + // Clamp to 10 to prevent server crash if thing are mined with extremely high level fortune pick + const unsigned int DropMult = std::clamp(FloorC(random.RandReal(FortuneLevel + 2.0)), 1, 10); + switch (m_BlockType) { - case E_BLOCK_LAPIS_ORE: return cItem(E_ITEM_DYE, random.RandInt(4, 8), 4); - case E_BLOCK_REDSTONE_ORE: return cItem(E_ITEM_REDSTONE_DUST, random.RandInt(4, 5), 0); - case E_BLOCK_REDSTONE_ORE_GLOWING: return cItem(E_ITEM_REDSTONE_DUST, random.RandInt(4, 5), 0); - case E_BLOCK_DIAMOND_ORE: return cItem(E_ITEM_DIAMOND); - case E_BLOCK_EMERALD_ORE: return cItem(E_ITEM_EMERALD); - case E_BLOCK_COAL_ORE: return cItem(E_ITEM_COAL); - case E_BLOCK_NETHER_QUARTZ_ORE: return cItem(E_ITEM_NETHER_QUARTZ); + case E_BLOCK_LAPIS_ORE: return cItem(E_ITEM_DYE, DropMult * random.RandInt(4, 9), 4); + case E_BLOCK_REDSTONE_ORE: // handled by next case (glowing redstone), no dropMult + case E_BLOCK_REDSTONE_ORE_GLOWING: return cItem(E_ITEM_REDSTONE_DUST, random.RandInt(4, 5 + FortuneLevel), 0); + case E_BLOCK_DIAMOND_ORE: return cItem(E_ITEM_DIAMOND, DropMult); + case E_BLOCK_EMERALD_ORE: return cItem(E_ITEM_EMERALD, DropMult); + case E_BLOCK_COAL_ORE: return cItem(E_ITEM_COAL, DropMult); + case E_BLOCK_NETHER_QUARTZ_ORE: return cItem(E_ITEM_NETHER_QUARTZ, DropMult); case E_BLOCK_CLAY: return cItem(E_ITEM_CLAY, 4); default: { -- cgit v1.2.3