summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockHandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Blocks/BlockHandler.h')
-rw-r--r--src/Blocks/BlockHandler.h94
1 files changed, 67 insertions, 27 deletions
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index d077442c9..c0a11186e 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -50,30 +50,62 @@ public:
);
/** Called by cWorld::SetBlock() after the block has been set */
- virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
+ virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
/** Called by cPlayer::PlaceBlocks() for each block after it has been set to the world. Called after OnPlaced(). */
virtual void OnPlacedByPlayer(
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, const sSetBlock & a_BlockChange
);
- /** Called before the player has destroyed a block */
- virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ);
-
- /** Called before a block gets destroyed / replaced with air */
- virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ);
+ /** Called just before the player breaks the block.
+ The block is still valid in the world.
+ By default does nothing special; descendants may provide further behavior. */
+ virtual void OnPlayerBreakingBlock(
+ cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
+ cPlayer & a_Player,
+ Vector3i a_BlockPos
+ ) {}
+
+ /** Called just after the player breaks the block.
+ The block is already dug up in the world, the original block type and meta is passed in a_OldBlockType and a_OldBlockMeta.
+ By default does nothing special, descendants may provide further behavior. */
+ virtual void OnPlayerBrokeBlock(
+ cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
+ cPlayer & a_Player,
+ Vector3i a_BlockPos,
+ BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
+ ) {}
+
+ /** Called before a block gets broken (replaced with air), either by player or by natural means.
+ If by player, it is called after the OnPlayerBreakingBlock() callback.
+ By default does nothing. */
+ virtual void OnBreaking(
+ cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
+ Vector3i a_BlockPos
+ ) {}
+
+ /** Called after a block gets broken (replaced with air), either by player or by natural means.
+ If by player, it is called before the OnPlayerBrokeBlock() callback.
+ The block is already dug up in the world, the original block type and meta is passed in a_OldBlockType and a_OldBlockMeta.
+ By default notifies all direct neighbors via their OnNeighborChanged() callbacks. */
+ virtual void OnBroken(
+ cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
+ Vector3i a_BlockPos,
+ BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
+ );
- /** Called when a direct neighbor of this block has been changed (The position is the block's own position, not the changing neighbor's position)
+ /** Called when a direct neighbor of this block has been changed.
+ The position is the block's own position, NOT the changed neighbor's position.
a_WhichNeighbor indicates which neighbor has changed. For example, BLOCK_FACE_YP meant the neighbor above has changed.
BLOCK_FACE_NONE means that it is a neighbor not directly adjacent (diagonal, etc.) */
- virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_WhichNeighbor) {}
+ virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) {}
/** Notifies the specified neighbor that the current block has changed.
- a_NeighborXYZ coords are the coords of the neighbor
- a_WhichNeighbor specifies which neighbor (relative to a_NeighborXYZ) has changed.
+ a_NeighborPos are the coords of the neighbor to be notified
+ a_WhichNeighbor specifies which neighbor (relative to a_NeighborPos) has changed.
For example BLOCK_FACE_YP means that the block at {a_NeighborX, a_NeighborY + 1, a_NeighborZ} has changed.
BLOCK_FACE_NONE means that it is a neighbor not directly adjacent (diagonal, etc.) */
- static void NeighborChanged(cChunkInterface & a_ChunkInterface, int a_NeighborX, int a_NeighborY, int a_NeighborZ, eBlockFace a_WhichNeighbor);
+ static void NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_NeighborPos, eBlockFace a_WhichNeighbor);
/** Called when the player starts digging the block. */
virtual void OnDigging(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) {}
@@ -86,19 +118,18 @@ public:
It forces the server to send the real state of a block to the client to prevent client assuming the operation is successfull */
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 the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents */
- virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta);
-
- /** Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents.
- Overloaded method with coords and world interface for blocks that needs to access the block entity, e.g. a bed. */
- virtual void ConvertToPickups(cWorldInterface & a_WorldInterface, cItems & a_Pickups, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ) {}
-
- /** Handles the dropping, but not destruction, of a block based on what ConvertTo(Verbatim)Pickups() returns, including the spawning of pickups and alertion of plugins
- @param a_Digger The entity causing the drop; it may be nullptr
- @param a_CanDrop Informs the handler whether the block should be dropped at all. One example when this is false is when stone is destroyed by hand
- @param a_DropVerbatim Calls ConvertToVerbatimPickups() instead of its counterpart, meaning the block itself is dropped by default (due to a speical tool or enchantment)
- */
- 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 = true);
+ /** Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
+ Doesn't do any actual block change / mining, only calculates the pickups.
+ a_BlockEntity is the block entity present at the block, if any, nullptr if none.
+ a_Digger is the entity that caused the conversion, usually the player digging.
+ a_Tool is the tool used for the digging.
+ The default implementation drops a single item created from m_BlockType and the current meta. */
+ virtual cItems ConvertToPickups(
+ NIBBLETYPE a_BlockMeta,
+ cBlockEntity * a_BlockEntity,
+ const cEntity * a_Digger = nullptr,
+ const cItem * a_Tool = nullptr
+ );
/** Checks if the block can stay at the specified relative coords in the chunk */
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk);
@@ -138,9 +169,13 @@ public:
virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta);
/** Called when one of the neighbors gets set; equivalent to MC block update.
- By default drops if position no more suitable (CanBeAt(), DoesDropOnUnsuitable(), Drop()),
- and wakes up all simulators on the block. */
- virtual void Check(cChunkInterface & ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk);
+ By default drops (DropBlockAsPickup() / SetBlock()) if the position is no longer suitable (CanBeAt(), DoesDropOnUnsuitable()),
+ otherwise wakes up all simulators on the block. */
+ virtual void Check(
+ cChunkInterface & ChunkInterface, cBlockPluginInterface & a_PluginInterface,
+ Vector3i a_RelPos,
+ cChunk & a_Chunk
+ );
/** Returns the base colour ID of the block, as will be represented on a map, as per documentation: https://minecraft.gamepedia.com/Map_item_format */
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta);
@@ -165,6 +200,11 @@ public:
Returns block meta following rotation */
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; }
+ /** Returns true if the specified tool is valid and has a non-zero silk-touch enchantment.
+ Helper used in many ConvertToPickups() implementations. */
+ static bool ToolHasSilkTouch(const cItem * a_Tool);
+
+
protected:
BLOCKTYPE m_BlockType;