2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2014-10-21 12:06:44 -04:00
|
|
|
#include "ChunkInterface.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockTallGrassHandler :
|
|
|
|
public cBlockHandler
|
|
|
|
{
|
2014-10-21 12:06:44 -04:00
|
|
|
typedef cBlockHandler super;
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
|
|
|
cBlockTallGrassHandler(BLOCKTYPE a_BlockType)
|
|
|
|
: cBlockHandler(a_BlockType)
|
|
|
|
{
|
|
|
|
}
|
2014-03-28 18:14:58 -04:00
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual bool DoesIgnoreBuildCollision(void) override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-28 18:14:58 -04:00
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
|
|
|
{
|
|
|
|
// Drop seeds, sometimes
|
2014-10-07 12:21:39 -04:00
|
|
|
cFastRandom Random;
|
|
|
|
if (Random.NextInt(8) == 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-21 12:06:44 -04:00
|
|
|
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
|
|
|
|
{
|
2014-12-16 18:18:59 -05:00
|
|
|
if (a_CanDrop && (a_Digger != nullptr) && (a_Digger->GetEquippedWeapon().m_ItemType == E_ITEM_SHEARS))
|
2014-10-21 12:06:44 -04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 12:21:39 -04:00
|
|
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
2014-03-28 18:14:58 -04:00
|
|
|
{
|
2014-10-07 12:21:39 -04:00
|
|
|
if (a_RelY <= 0)
|
2014-03-28 18:14:58 -04:00
|
|
|
{
|
2014-10-07 12:21:39 -04:00
|
|
|
return false;
|
2014-03-28 18:14:58 -04:00
|
|
|
}
|
|
|
|
|
2014-10-07 12:21:39 -04:00
|
|
|
BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
|
|
|
|
return IsBlockTypeOfDirt(BelowBlock);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|