diff options
author | KingCol13 <48412633+KingCol13@users.noreply.github.com> | 2020-09-28 14:41:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-28 14:41:49 +0200 |
commit | 8eca58a1c9d3ea928b301de1ad772a46164372e1 (patch) | |
tree | 9627cfb9c43ed9b332a493c474e7ebe119543b89 /src/Blocks/BlockCrops.h | |
parent | Enchanting consumes lapis, removes correct number of levels (#4934) (diff) | |
download | cuberite-8eca58a1c9d3ea928b301de1ad772a46164372e1.tar cuberite-8eca58a1c9d3ea928b301de1ad772a46164372e1.tar.gz cuberite-8eca58a1c9d3ea928b301de1ad772a46164372e1.tar.bz2 cuberite-8eca58a1c9d3ea928b301de1ad772a46164372e1.tar.lz cuberite-8eca58a1c9d3ea928b301de1ad772a46164372e1.tar.xz cuberite-8eca58a1c9d3ea928b301de1ad772a46164372e1.tar.zst cuberite-8eca58a1c9d3ea928b301de1ad772a46164372e1.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Blocks/BlockCrops.h | 44 |
1 files changed, 29 insertions, 15 deletions
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<char>(2) + rand.RandInt<char>(2)) / 2); // [1 .. 3] with high preference of 2 - res.Add(E_ITEM_BEETROOT_SEEDS, SeedCount, 0); - char BeetrootCount = 1 + ((rand.RandInt<char>(2) + rand.RandInt<char>(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<char>(2) + rand.RandInt<char>(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<char>(2) + rand.RandInt<char>(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<char>(2) + rand.RandInt<char>(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; } |