2020-10-11 11:27:41 -04:00
|
|
|
|
|
|
|
// BlockInfested.h
|
|
|
|
|
2020-12-19 21:13:34 -05:00
|
|
|
// Declares the cBlockInfestedHandler class representing the handler for Silverfish blocks (Mojang calls them Monster Eggs)
|
|
|
|
|
2020-10-11 11:27:41 -04:00
|
|
|
#include "../Entities/Player.h"
|
|
|
|
|
2020-12-19 21:13:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-11 11:27:41 -04:00
|
|
|
|
|
|
|
class cBlockInfestedHandler final:
|
|
|
|
public cBlockHandler
|
|
|
|
{
|
|
|
|
using Super = cBlockHandler;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
using Super::Super;
|
|
|
|
|
2020-12-19 21:13:34 -05:00
|
|
|
private:
|
|
|
|
|
2020-10-11 11:27:41 -04:00
|
|
|
static void SpawnSilverfish(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos)
|
|
|
|
{
|
|
|
|
// TODO: only display animation if the difficulty allows mob spawns - Add when difficulty is implemented
|
2020-12-19 21:13:34 -05:00
|
|
|
|
|
|
|
const auto Position = Vector3f(a_BlockPos.x + 0.5f, a_BlockPos.y, a_BlockPos.z + 0.5f);
|
|
|
|
a_WorldInterface.SpawnMob(Position.x, Position.y, Position.z, mtSilverfish, false);
|
|
|
|
a_WorldInterface.GetBroadcastManager().BroadcastParticleEffect("explode", Position, Vector3f(), 0.1f, 50);
|
2020-10-11 11:27:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-28 09:41:34 -04:00
|
|
|
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
|
2020-10-11 11:27:41 -04:00
|
|
|
{
|
|
|
|
switch (a_BlockMeta)
|
|
|
|
{
|
|
|
|
case E_META_SILVERFISH_EGG_STONE:
|
|
|
|
{
|
|
|
|
if (ToolHasSilkTouch(a_Tool))
|
|
|
|
{
|
2020-12-19 21:13:34 -05:00
|
|
|
return { E_BLOCK_STONE };
|
2020-10-11 11:27:41 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-19 21:13:34 -05:00
|
|
|
return { E_BLOCK_COBBLESTONE };
|
2020-10-11 11:27:41 -04:00
|
|
|
}
|
|
|
|
}
|
2020-12-19 21:13:34 -05:00
|
|
|
case E_META_SILVERFISH_EGG_COBBLESTONE: return { E_BLOCK_COBBLESTONE };
|
|
|
|
case E_META_SILVERFISH_EGG_STONE_BRICK: return { E_BLOCK_STONE_BRICKS };
|
2020-10-11 11:27:41 -04:00
|
|
|
case E_META_SILVERFISH_EGG_MOSSY_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS, 1, E_META_STONE_BRICK_MOSSY);
|
|
|
|
case E_META_SILVERFISH_EGG_CRACKED_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS, 1, E_META_STONE_BRICK_CRACKED);
|
|
|
|
case E_META_SILVERFISH_EGG_CHISELED_STONE_BRICK: return cItem(E_BLOCK_STONE_BRICKS, 1, E_META_STONE_BRICK_ORNAMENT);
|
|
|
|
}
|
2020-12-19 21:13:34 -05:00
|
|
|
|
2020-10-11 11:27:41 -04:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnBroken(
|
2020-12-19 21:13:34 -05:00
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
|
|
|
Vector3i a_BlockPos,
|
|
|
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
|
|
|
|
const cEntity * a_Digger
|
2020-10-11 11:27:41 -04:00
|
|
|
) const override
|
|
|
|
{
|
|
|
|
if (a_Digger != nullptr)
|
|
|
|
{
|
|
|
|
if (a_Digger->IsPlayer())
|
|
|
|
{
|
|
|
|
const auto Player = static_cast<const cPlayer *>(a_Digger);
|
|
|
|
if (Player->IsGameModeCreative())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (a_Digger->IsMob())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SpawnSilverfish(a_WorldInterface, a_BlockPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
|
|
|
{
|
|
|
|
return 11;
|
|
|
|
}
|
|
|
|
} ;
|