Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockMobSpawner.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "../Items/ItemHandler.h"
6 
7 
8 
9 
10 
12  public cBlockHandler
13 {
14 public:
16  : cBlockHandler(a_BlockType)
17  {
18  }
19 
20 
21  virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
22  {
23  return a_ChunkInterface.UseBlockEntity(&a_Player, a_BlockX, a_BlockY, a_BlockZ);
24  }
25 
26 
27  virtual bool IsUseable() override
28  {
29  return true;
30  }
31 
32 
33 
34 
35 
36  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
37  {
38  // No pickups
39  return {};
40  }
41 
42 
43 
44 
45 
46  virtual void OnPlayerBrokeBlock(
47  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
48  cPlayer & a_Player,
49  Vector3i a_BlockPos,
50  BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
51  ) override
52  {
53  auto handler = a_Player.GetEquippedItem().GetHandler();
54  if (!a_Player.IsGameModeSurvival() || !handler->CanHarvestBlock(E_BLOCK_MOB_SPAWNER))
55  {
56  return;
57  }
58 
59  auto & random = GetRandomProvider();
60  int reward = 15 + random.RandInt(14) + random.RandInt(14);
61  a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, reward);
62  }
63 } ;
cItemHandler * GetHandler(void) const
Returns the cItemHandler responsible for this item type.
Definition: Item.cpp:137
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
MTRand & GetRandomProvider()
Returns the current thread's random number source.
Definition: FastRandom.cpp:20
const cItem & GetEquippedItem(void) const
Definition: Player.h:142
Definition: Player.h:27
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity *a_BlockEntity, const cEntity *a_Digger, const cItem *a_Tool) override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
cBlockMobSpawnerHandler(BLOCKTYPE a_BlockType)
Vector3< double > Vector3d
Definition: Vector3.h:445
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
virtual std::vector< UInt32 > SpawnSplitExperienceOrbs(Vector3d a_Pos, int a_Reward)=0
Spawns experience orbs of the specified total value at the given location.
bool IsGameModeSurvival(void) const
Returns true if the player is in Survival mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1269
virtual bool IsUseable() override
Checks if the block can be placed at this point.
bool UseBlockEntity(cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
Use block entity on coordinate.
virtual void OnPlayerBrokeBlock(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta) override
Called just after the player breaks the block.
Definition: Entity.h:73
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
Called if the user right clicks the block and the block is useable returns true if the use was succes...
Definition: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234