diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-10-23 14:59:42 +0200 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-10-23 14:59:42 +0200 |
commit | 72bb299a4a4f74840c3b368c6669ddc3d32006ee (patch) | |
tree | 748fee756010b1f36aa95162f762e21ee0d19c0a /src/Blocks/BlockTallGrass.h | |
parent | Merge branch 'master' into ChunkLoader (diff) | |
parent | Fixed a crash in redstone simulator. (diff) | |
download | cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.gz cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.bz2 cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.lz cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.xz cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.tar.zst cuberite-72bb299a4a4f74840c3b368c6669ddc3d32006ee.zip |
Diffstat (limited to 'src/Blocks/BlockTallGrass.h')
-rw-r--r-- | src/Blocks/BlockTallGrass.h | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index f520414a7..8e821b899 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -2,6 +2,7 @@ #pragma once #include "BlockHandler.h" +#include "ChunkInterface.h" @@ -10,6 +11,7 @@ class cBlockTallGrassHandler : public cBlockHandler { + typedef cBlockHandler super; public: cBlockTallGrassHandler(BLOCKTYPE a_BlockType) : cBlockHandler(a_BlockType) @@ -26,32 +28,58 @@ public: virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { // Drop seeds, sometimes - MTRand r1; - if (r1.randInt(10) == 5) + cFastRandom Random; + if (Random.NextInt(8) == 0) { a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0)); } } - virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override + virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop) override { - NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - - if ((!a_Player->IsGameModeCreative()) && (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SHEARS)) + if (a_CanDrop && (a_Digger != NULL) && (a_Digger->GetEquippedWeapon().m_ItemType == E_ITEM_SHEARS)) { - cItems Pickups; - Pickups.Add(E_BLOCK_TALL_GRASS, 1, Meta); - a_WorldInterface.SpawnItemPickups(Pickups, a_BlockX, a_BlockY, a_BlockZ); - - a_Player->UseEquippedItem(); + NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); + cItems Drops; + Drops.Add(m_BlockType, 1, Meta); + + // Allow plugins to modify the pickups: + a_BlockPluginInterface.CallHookBlockToPickups(a_Digger, a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta, Drops); + + // Spawn the pickups: + if (!Drops.empty()) + { + MTRand r1; + + // Mid-block position first + double MicroX, MicroY, MicroZ; + MicroX = a_BlockX + 0.5; + MicroY = a_BlockY + 0.5; + MicroZ = a_BlockZ + 0.5; + + // Add random offset second + MicroX += r1.rand(1) - 0.5; + MicroZ += r1.rand(1) - 0.5; + + a_WorldInterface.SpawnItemPickups(Drops, MicroX, MicroY, MicroZ); + } + return; } + + super::DropBlock(a_ChunkInterface, a_WorldInterface, a_BlockPluginInterface, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_CanDrop); } virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR)); + if (a_RelY <= 0) + { + return false; + } + + BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ); + return IsBlockTypeOfDirt(BelowBlock); } } ; |