From 8eca58a1c9d3ea928b301de1ad772a46164372e1 Mon Sep 17 00:00:00 2001 From: KingCol13 <48412633+KingCol13@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:41:49 +0100 Subject: Fortune Drops (#4932) + Implemented and standardized all clamped discrete random drops. + Changed cItems Add from push_back to emplace_back. Implement fortune for crops. + Enabled hoes to be enchanted with efficiency, silk touch and fortune. Made leaves, gravel and crops affected by fortune. Co-authored-by: Tiger Wang --- src/Blocks/BlockCrops.h | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src/Blocks/BlockCrops.h') diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 1d612e685..827b26881 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -21,6 +21,17 @@ public: private: + /** Calculate the number of seeds to drop when the crop is broken. */ + static char CalculateSeedCount(char a_Min, char a_BaseRolls, char a_FortuneLevel) + { + std::binomial_distribution Binomial(a_BaseRolls + a_FortuneLevel, 0.57); + return a_Min + Binomial(GetRandomProvider().Engine()); + } + + + + + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { auto & rand = GetRandomProvider(); @@ -30,11 +41,12 @@ private: { switch (m_BlockType) { - case E_BLOCK_BEETROOTS: return cItem(E_ITEM_BEETROOT_SEEDS, 1, 0); break; - case E_BLOCK_CROPS: return cItem(E_ITEM_SEEDS, 1, 0); break; - case E_BLOCK_CARROTS: return cItem(E_ITEM_CARROT, 1, 0); break; - case E_BLOCK_POTATOES: return cItem(E_ITEM_POTATO, 1, 0); break; + case E_BLOCK_BEETROOTS: return cItem(E_ITEM_BEETROOT_SEEDS); + case E_BLOCK_CROPS: return cItem(E_ITEM_SEEDS); + case E_BLOCK_CARROTS: return cItem(E_ITEM_CARROT); + case E_BLOCK_POTATOES: return cItem(E_ITEM_POTATO); } + ASSERT(!"Unhandled block type"); return {}; } @@ -45,30 +57,32 @@ private: { case E_BLOCK_BEETROOTS: { - char SeedCount = 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2); // [1 .. 3] with high preference of 2 - res.Add(E_ITEM_BEETROOT_SEEDS, SeedCount, 0); - char BeetrootCount = 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2); // [1 .. 3] with high preference of 2 - res.Add(E_ITEM_BEETROOT, BeetrootCount, 0); + const auto SeedCount = CalculateSeedCount(0, 3, ToolFortuneLevel(a_Tool)); + res.Add(E_ITEM_BEETROOT_SEEDS, SeedCount); + res.Add(E_ITEM_BEETROOT); break; } case E_BLOCK_CROPS: { - res.Add(E_ITEM_WHEAT, 1, 0); - res.Add(E_ITEM_SEEDS, 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2), 0); // [1 .. 3] with high preference of 2 + res.Add(E_ITEM_WHEAT); + const auto SeedCount = CalculateSeedCount(1, 3, ToolFortuneLevel(a_Tool)); + res.Add(E_ITEM_SEEDS, SeedCount); break; } case E_BLOCK_CARROTS: { - res.Add(E_ITEM_CARROT, 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2), 0); // [1 .. 3] with high preference of 2 + const auto CarrotCount = CalculateSeedCount(1, 4, ToolFortuneLevel(a_Tool)); + res.Add(E_ITEM_CARROT, CarrotCount); break; } case E_BLOCK_POTATOES: { - res.Add(E_ITEM_POTATO, 1 + ((rand.RandInt(2) + rand.RandInt(2)) / 2), 0); // [1 .. 3] with high preference of 2 - if (rand.RandBool(0.05)) + const auto PotatoCount = CalculateSeedCount(2, 3, ToolFortuneLevel(a_Tool)); + res.Add(E_ITEM_POTATO, PotatoCount); + if (rand.RandBool(0.02)) { - // With a 5% chance, drop a poisonous potato as well - res.emplace_back(E_ITEM_POISONOUS_POTATO, 1, 0); + // With a 2% chance, drop a poisonous potato as well + res.Add(E_ITEM_POISONOUS_POTATO); } break; } -- cgit v1.2.3