diff options
author | Mattes D <github@xoft.cz> | 2019-10-16 10:06:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-16 10:06:34 +0200 |
commit | 221cc4ec5cb6301743e947eaabed3fecedba796f (patch) | |
tree | 4e44c8bb7523e5d1d04468fc906ae24674c10abc /src/Blocks/BlockCrops.h | |
parent | Fixed crash in hopper while pulling items from blockentity above itself (#4412) (diff) | |
download | cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.gz cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.bz2 cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.lz cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.xz cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.zst cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.zip |
Diffstat (limited to 'src/Blocks/BlockCrops.h')
-rw-r--r-- | src/Blocks/BlockCrops.h | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 378505430..0d6296a33 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -10,71 +10,70 @@ /** Common class that takes care of beetroots, carrots, potatoes and wheat */ template <NIBBLETYPE RipeMeta> -class cBlockCropsHandler : - public cBlockPlant +class cBlockCropsHandler: + public cBlockPlant<true> { - typedef cBlockPlant Super; + using super = cBlockPlant<true>; public: cBlockCropsHandler(BLOCKTYPE a_BlockType): - Super(a_BlockType, true) + super(a_BlockType) { } - virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override + + + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override { auto & rand = GetRandomProvider(); // If not fully grown, drop the "seed" of whatever is growing: - if (a_Meta < RipeMeta) + if (a_BlockMeta < RipeMeta) { switch (m_BlockType) { - case E_BLOCK_BEETROOTS: a_Pickups.push_back(cItem(E_ITEM_BEETROOT_SEEDS, 1, 0)); break; - case E_BLOCK_CROPS: a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0)); break; - case E_BLOCK_CARROTS: a_Pickups.push_back(cItem(E_ITEM_CARROT, 1, 0)); break; - case E_BLOCK_POTATOES: a_Pickups.push_back(cItem(E_ITEM_POTATO, 1, 0)); break; - default: - { - ASSERT(!"Unhandled block type"); - break; - } + 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; } - return; + ASSERT(!"Unhandled block type"); + return {}; } // Fully grown, drop the crop's produce: + cItems res; switch (m_BlockType) { case E_BLOCK_BEETROOTS: { char SeedCount = 1 + ((rand.RandInt<char>(2) + rand.RandInt<char>(2)) / 2); // [1 .. 3] with high preference of 2 - a_Pickups.emplace_back(E_ITEM_BEETROOT_SEEDS, SeedCount, 0); + 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 - a_Pickups.emplace_back(E_ITEM_BEETROOT, BeetrootCount, 0); + res.Add(E_ITEM_BEETROOT, BeetrootCount, 0); break; } case E_BLOCK_CROPS: { - a_Pickups.emplace_back(E_ITEM_WHEAT, 1, 0); - a_Pickups.emplace_back(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, 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 break; } case E_BLOCK_CARROTS: { - a_Pickups.emplace_back(E_ITEM_CARROT, 1 + ((rand.RandInt<char>(2) + rand.RandInt<char>(2)) / 2), 0); // [1 .. 3] with high preference of 2 + res.Add(E_ITEM_CARROT, 1 + ((rand.RandInt<char>(2) + rand.RandInt<char>(2)) / 2), 0); // [1 .. 3] with high preference of 2 break; } case E_BLOCK_POTATOES: { - a_Pickups.emplace_back(E_ITEM_POTATO, 1 + ((rand.RandInt<char>(2) + rand.RandInt<char>(2)) / 2), 0); // [1 .. 3] with high preference of 2 + 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)) { // With a 5% chance, drop a poisonous potato as well - a_Pickups.emplace_back(E_ITEM_POISONOUS_POTATO, 1, 0); + res.emplace_back(E_ITEM_POISONOUS_POTATO, 1, 0); } break; } @@ -84,10 +83,13 @@ public: break; } } // switch (m_BlockType) + return res; } + + virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); |