Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockInfested.h
Go to the documentation of this file.
1 
2 // BlockInfested.h
3 
4 // Declares the cBlockInfestedHandler class representing the handler for Silverfish blocks (Mojang calls them Monster Eggs)
5 
6 #include "../Entities/Player.h"
7 
8 
9 
10 
11 
13  public cBlockHandler
14 {
16 
17 public:
18 
19  using Super::Super;
20 
21 private:
22 
23  static void SpawnSilverfish(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos)
24  {
25  // TODO: only display animation if the difficulty allows mob spawns - Add when difficulty is implemented
26 
27  const auto Position = Vector3f(a_BlockPos.x + 0.5f, static_cast<float>(a_BlockPos.y), a_BlockPos.z + 0.5f);
28  a_WorldInterface.SpawnMob(Position.x, Position.y, Position.z, mtSilverfish, false);
29  a_WorldInterface.GetBroadcastManager().BroadcastParticleEffect("explode", Position, Vector3f(), 0.1f, 50);
30  }
31 
32 
33  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
34  {
35  switch (a_BlockMeta)
36  {
38  {
39  if (ToolHasSilkTouch(a_Tool))
40  {
41  return { E_BLOCK_STONE };
42  }
43  else
44  {
45  return { E_BLOCK_COBBLESTONE };
46  }
47  }
53  }
54 
55  return {};
56  }
57 
58 
59  virtual void OnBroken(
60  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
61  Vector3i a_BlockPos,
62  BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
63  const cEntity * a_Digger
64  ) const override
65  {
66  if (a_Digger != nullptr)
67  {
68  if (a_Digger->IsPlayer())
69  {
70  const auto Player = static_cast<const cPlayer *>(a_Digger);
71  if (Player->IsGameModeCreative())
72  {
73  return;
74  }
75  }
76  if (a_Digger->IsMob() || a_Digger->IsTNT())
77  {
78  return;
79  }
80  }
81  SpawnSilverfish(a_WorldInterface, a_BlockPos);
82  }
83 
84 
85  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
86  {
87  return 11;
88  }
89 } ;
@ E_META_STONE_BRICK_MOSSY
Definition: BlockType.h:925
@ E_META_SILVERFISH_EGG_STONE_BRICK
Definition: BlockType.h:824
@ E_META_SILVERFISH_EGG_MOSSY_STONE_BRICK
Definition: BlockType.h:825
@ E_META_STONE_BRICK_ORNAMENT
Definition: BlockType.h:927
@ E_META_SILVERFISH_EGG_CHISELED_STONE_BRICK
Definition: BlockType.h:827
@ E_META_SILVERFISH_EGG_COBBLESTONE
Definition: BlockType.h:823
@ E_META_SILVERFISH_EGG_STONE
Definition: BlockType.h:822
@ E_META_SILVERFISH_EGG_CRACKED_STONE_BRICK
Definition: BlockType.h:826
@ E_META_STONE_BRICK_CRACKED
Definition: BlockType.h:926
@ E_BLOCK_STONE_BRICKS
Definition: BlockType.h:113
@ E_BLOCK_STONE
Definition: BlockType.h:11
@ E_BLOCK_COBBLESTONE
Definition: BlockType.h:14
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
Byte ColourID
Definition: Globals.h:162
@ mtSilverfish
Definition: MonsterTypes.h:58
Vector3< float > Vector3f
Definition: Vector3.h:486
static bool ToolHasSilkTouch(const cItem *a_Tool)
Returns true if the specified tool is valid and has a non-zero silk-touch enchantment.
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockInfested.h:85
static void SpawnSilverfish(cWorldInterface &a_WorldInterface, Vector3i a_BlockPos)
Definition: BlockInfested.h:23
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem *const a_Tool) const override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
Definition: BlockInfested.h:33
virtual void OnBroken(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, const cEntity *a_Digger) const override
Called after a block gets broken (replaced with air), by natural means.
Definition: BlockInfested.h:59
virtual void BroadcastParticleEffect(const AString &a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, const cClientHandle *a_Exclude=nullptr)=0
virtual cBroadcastInterface & GetBroadcastManager()=0
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby)=0
Spawns a mob of the specified type.
Definition: Entity.h:76
bool IsPlayer(void) const
Definition: Entity.h:160
bool IsTNT(void) const
Definition: Entity.h:167
bool IsMob(void) const
Definition: Entity.h:162
Definition: Player.h:29
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17