Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockHandler.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../Defines.h"
5 
6 #include "../BoundingBox.h"
7 
8 
9 
10 
11 
12 // fwd:
13 class cPlayer;
14 class cChunk;
16 class cChunkInterface;
17 class cWorldInterface;
18 class cItems;
19 class BlockTypeRegistry;
20 
21 
22 
23 
24 
26 {
27 public:
28  cBlockHandler(BLOCKTYPE a_BlockType);
29 
30  virtual ~cBlockHandler() {}
31 
34  virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ);
35 
40 
45  virtual bool GetPlacementBlockTypeMeta(
46  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
47  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
48  int a_CursorX, int a_CursorY, int a_CursorZ,
49  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
50  );
51 
53  virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
54 
56  virtual void OnPlacedByPlayer(
57  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, const sSetBlock & a_BlockChange
58  );
59 
63  virtual void OnPlayerBreakingBlock(
64  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
65  cPlayer & a_Player,
66  Vector3i a_BlockPos
67  ) {}
68 
72  virtual void OnPlayerBrokeBlock(
73  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
74  cPlayer & a_Player,
75  Vector3i a_BlockPos,
76  BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
77  ) {}
78 
82  virtual void OnBreaking(
83  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
84  Vector3i a_BlockPos
85  ) {}
86 
91  virtual void OnBroken(
92  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
93  Vector3i a_BlockPos,
94  BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
95  );
96 
101  virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) {}
102 
108  static void NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_NeighborPos, eBlockFace a_WhichNeighbor);
109 
111  virtual void OnDigging(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) {}
112 
115  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) { return false; }
116 
119  virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) {}
120 
127  virtual cItems ConvertToPickups(
128  NIBBLETYPE a_BlockMeta,
129  cBlockEntity * a_BlockEntity,
130  const cEntity * a_Digger = nullptr,
131  const cItem * a_Tool = nullptr
132  );
133 
135  virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk);
136 
138  virtual bool CanSustainPlant(BLOCKTYPE a_Plant) { return false; }
139 
144  // virtual bool CanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir);
145 
148  virtual bool IsUseable(void);
149 
153  virtual bool IsClickedThrough(void);
154 
161  virtual bool DoesIgnoreBuildCollision(cChunkInterface & ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta);
162 
165  virtual bool DoesDropOnUnsuitable(void);
166 
169  virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta);
170 
174  virtual void Check(
175  cChunkInterface & ChunkInterface, cBlockPluginInterface & a_PluginInterface,
176  Vector3i a_RelPos,
177  cChunk & a_Chunk
178  );
179 
181  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta);
182 
185  virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) { return a_Meta; }
186 
189  virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) { return a_Meta; }
190 
193  virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) { return a_Meta; }
194 
197  virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) { return a_Meta; }
198 
201  virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; }
202 
205  virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) { return 0; }
206 
209  static bool ToolHasSilkTouch(const cItem * a_Tool);
210 
211 
212 protected:
214 
215  // Creates a new blockhandler for the given block type. For internal use only, use ::GetBlockHandler() instead.
216  static cBlockHandler * CreateBlockHandler(BLOCKTYPE a_BlockType);
217 
218  friend class cBlockInfo;
219 };
220 
221 
222 
223 
224 namespace Temporary
225 {
229 };
virtual void OnNeighborChanged(cChunkInterface &a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor)
Called when a direct neighbor of this block has been changed.
Definition: BlockHandler.h:101
Stores information on all known block types.
virtual void Check(cChunkInterface &ChunkInterface, cBlockPluginInterface &a_PluginInterface, Vector3i a_RelPos, cChunk &a_Chunk)
Called when one of the neighbors gets set; equivalent to MC block update.
virtual void OnBroken(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta)
Called after a block gets broken (replaced with air), either by player or by natural means...
virtual bool DoesIgnoreBuildCollision(cChunkInterface &ChunkInterface, Vector3i a_Pos, cPlayer &a_Player, NIBBLETYPE a_Meta)
Checks if the player can build "inside" this block.
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta)
Rotates a given block meta counter-clockwise.
Definition: BlockHandler.h:185
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta)
Mirrors a given block meta around the XY plane.
Definition: BlockHandler.h:193
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta)
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: Player.h:27
cBlockHandler(BLOCKTYPE a_BlockType)
virtual void OnPlacedByPlayer(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const sSetBlock &a_BlockChange)
Called by cPlayer::PlaceBlocks() for each block after it has been set to the world.
static void NeighborChanged(cChunkInterface &a_ChunkInterface, Vector3i a_NeighborPos, eBlockFace a_WhichNeighbor)
Notifies the specified neighbor that the current block has changed.
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
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)
Called if the user right clicks the block and the block is useable returns true if the use was succes...
Definition: BlockHandler.h:115
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta)
Mirros a given block meta around the YZ plane.
Definition: BlockHandler.h:201
virtual bool GetPlacementBlockTypeMeta(cChunkInterface &a_ChunkInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Called before a block is placed into a world.
virtual void OnDigging(cChunkInterface &cChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
Called when the player starts digging the block.
Definition: BlockHandler.h:111
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
Represents two sets of coords, minimum and maximum for each direction.
Definition: BoundingBox.h:23
static bool ToolHasSilkTouch(const cItem *a_Tool)
Returns true if the specified tool is valid and has a non-zero silk-touch enchantment.
Definition: Chunk.h:49
void RegisterAllBlockHandlers(BlockTypeRegistry &aRegistry)
Registers all the BlockHandler descendants in the specified registry.
virtual ~cBlockHandler()
Definition: BlockHandler.h:30
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld...
virtual void OnUpdate(cChunkInterface &cChunkInterface, cWorldInterface &a_WorldInterface, cBlockPluginInterface &a_BlockPluginInterface, cChunk &a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
Called when the block gets ticked either by a random tick or by a queued tick.
virtual bool IsClickedThrough(void)
Indicates whether the client will click through this block.
virtual int Grow(cChunk &a_Chunk, Vector3i a_RelPos, int a_NumStages=1)
Grows this block, if it supports growing, by the specified amount of stages (at most).
Definition: BlockHandler.h:205
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta)
Rotates a given block meta clockwise.
Definition: BlockHandler.h:189
virtual void OnPlayerBrokeBlock(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta)
Called just after the player breaks the block.
Definition: BlockHandler.h:72
virtual cBoundingBox GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP)
Returns the relative bounding box that must be entity-free in order for the block to be placed...
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta)
Mirros a given block meta around the XZ plane.
Definition: BlockHandler.h:197
static cBlockHandler * CreateBlockHandler(BLOCKTYPE a_BlockType)
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
virtual bool IsUseable(void)
Checks if the block can be placed at this point.
virtual bool DoesDropOnUnsuitable(void)
Returns if this block drops if it gets destroyed by an unsuitable situation.
Byte ColourID
Definition: Globals.h:118
Definition: Entity.h:73
virtual void OnBreaking(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos)
Called before a block gets broken (replaced with air), either by player or by natural means...
Definition: BlockHandler.h:82
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity *a_BlockEntity, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
virtual void OnCancelRightClick(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Called when a right click to this block is cancelled.
Definition: BlockHandler.h:119
virtual void OnPlaced(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Called by cWorld::SetBlock() after the block has been set.
virtual void OnPlayerBreakingBlock(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, Vector3i a_BlockPos)
Called just before the player breaks the block.
Definition: BlockHandler.h:63
virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta)
Tests if a_Position is inside the block where a_Position is relative to the origin of the block Note ...
Definition: Item.h:36
virtual bool CanSustainPlant(BLOCKTYPE a_Plant)
Checks whether the block has an effect on growing the plant.
Definition: BlockHandler.h:138
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234
virtual bool CanBeAt(cChunkInterface &a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk &a_Chunk)
Checks if the block can stay at the specified relative coords in the chunk.