From 672bb0457012612ef59502b33717ee789c4d6bfe Mon Sep 17 00:00:00 2001 From: 0ddlyoko Date: Fri, 6 Nov 2020 17:54:01 +0100 Subject: Add correct implementation of crops (#4802) * [FIX] Add correct implementation of seed drops. > Official percentage of drops has been implemented * Fix C++ conventions * Change "Vals" variable to "m_Vals" * [FIX] Add correct implementation of Carrots, Potatoes, Wheat & Beetroots seed * Add Fortune support with crops Add fortune support with Wheat, Carrots, Potatoes & Beetroots seeds * [FIX] Right-clicking on a grown Beetroot in survival consume 2 bone meals Fix #4805 * Add documentation for "cWorld::IsFullGrownPlantAt" method * Fix dispenser that full grown a plant > Change methods cItemDyeHandler::FertilizePlant & cItemDyeHandler::growPlantsAround to static * Display particle even if tree doesn't grow * When right-clicking on a full grown melon / pumpkin seed, no longer produce a melon / pumpkin Before this commit, when you right-click on a melon or a pumpkin seed, a melon / pumpkin block spawned. With this commit, it no longer spawns * [FIX] Do not create melon / pumpkin block when right-clicking with a bone meal This fix will prevent the creation of a melon / pumpkin block when you right-click with a bone meal on a melon / pumpkin plant - It just detect if the plant is full grown. if yes, the method "Grow" is not called - Remove IsFullGrownPlant Co-authored-by: 12xx12 <12xx12100@gmail.com> Co-authored-by: Tiger Wang --- src/Items/ItemDye.h | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'src/Items/ItemDye.h') diff --git a/src/Items/ItemDye.h b/src/Items/ItemDye.h index da657007f..631e28e7d 100644 --- a/src/Items/ItemDye.h +++ b/src/Items/ItemDye.h @@ -102,13 +102,13 @@ public: fertilization success is reported even in the case when the chance fails (bonemeal still needs to be consumed). */ static bool FertilizePlant(cWorld & a_World, Vector3i a_BlockPos) { - BLOCKTYPE blockType; - NIBBLETYPE blockMeta; - if (!a_World.GetBlockTypeMeta(a_BlockPos, blockType, blockMeta)) + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + if (!a_World.GetBlockTypeMeta(a_BlockPos, BlockType, BlockMeta)) { return false; } - switch (blockType) + switch (BlockType) { case E_BLOCK_WHEAT: case E_BLOCK_CARROTS: @@ -117,8 +117,8 @@ public: case E_BLOCK_PUMPKIN_STEM: { // Grow by 2 - 5 stages: - auto numStages = GetRandomProvider().RandInt(2, 5); - if (a_World.GrowPlantAt(a_BlockPos, numStages) <= 0) + auto NumStages = GetRandomProvider().RandInt(2, 5); + if (a_World.GrowPlantAt(a_BlockPos, NumStages) <= 0) { return false; } @@ -128,14 +128,21 @@ public: case E_BLOCK_BEETROOTS: { + if (a_World.GrowPlantAt(a_BlockPos, 1) <= 0) + { + // Fix GH #4805 (bonemeal should only advance growth, not spawn produce): + return false; + } + + a_World.BroadcastSoundParticleEffect(EffectID::PARTICLE_HAPPY_VILLAGER, a_BlockPos, 0); + // 75% chance of 1-stage growth: - if (GetRandomProvider().RandBool(0.75)) + if (!GetRandomProvider().RandBool(0.75)) { - if (a_World.GrowPlantAt(a_BlockPos, 1) > 0) - { - a_World.BroadcastSoundParticleEffect(EffectID::PARTICLE_HAPPY_VILLAGER, a_BlockPos, 0); - } + // Hit the 25%, rollback: + a_World.GrowPlantAt(a_BlockPos, -1); } + return true; } // case beetroots @@ -144,27 +151,25 @@ public: // 45% chance of growing to the next stage / full tree: if (GetRandomProvider().RandBool(0.45)) { - if (a_World.GrowPlantAt(a_BlockPos, 1) > 0) - { - a_World.BroadcastSoundParticleEffect(EffectID::PARTICLE_HAPPY_VILLAGER, a_BlockPos, 0); - } + a_World.GrowPlantAt(a_BlockPos, 1); } + a_World.BroadcastSoundParticleEffect(EffectID::PARTICLE_HAPPY_VILLAGER, a_BlockPos, 0); return true; - } + } // case sapling case E_BLOCK_BIG_FLOWER: { // Drop the corresponding flower item without destroying the block: - cItems pickups; - switch (blockMeta) + cItems Pickups; + switch (BlockMeta) { - case E_META_BIG_FLOWER_SUNFLOWER: pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_SUNFLOWER); break; - case E_META_BIG_FLOWER_LILAC: pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_LILAC); break; - case E_META_BIG_FLOWER_ROSE_BUSH: pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_ROSE_BUSH); break; - case E_META_BIG_FLOWER_PEONY: pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_PEONY); break; + case E_META_BIG_FLOWER_SUNFLOWER: Pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_SUNFLOWER); break; + case E_META_BIG_FLOWER_LILAC: Pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_LILAC); break; + case E_META_BIG_FLOWER_ROSE_BUSH: Pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_ROSE_BUSH); break; + case E_META_BIG_FLOWER_PEONY: Pickups.Add(E_BLOCK_BIG_FLOWER, 1, E_META_BIG_FLOWER_PEONY); break; } // TODO: Should we call any hook for this? - a_World.SpawnItemPickups(pickups, a_BlockPos); + a_World.SpawnItemPickups(Pickups, a_BlockPos); return true; } // big flower -- cgit v1.2.3