2013-07-29 12:13:03 +01:00
#pragma once
#include "../Defines.h"
#include "../Item.h"
2014-01-25 11:14:14 -08:00
#include "WorldInterface.h"
2014-01-26 06:20:39 -08:00
#include "ChunkInterface.h"
2014-02-02 06:49:37 -08:00
#include "BlockPluginInterface.h"
2013-07-29 12:13:03 +01:00
// fwd:
class cPlayer ;
2014-02-01 06:01:13 -08:00
class cChunk ;
2013-07-29 12:13:03 +01:00
class cBlockHandler
{
public :
cBlockHandler ( BLOCKTYPE a_BlockType );
2014-03-08 08:33:38 -08:00
virtual ~ cBlockHandler () {}
2013-07-29 12:13:03 +01:00
2013-11-30 15:58:27 +01:00
/// Called when the block gets ticked either by a random tick or by a queued tick.
/// Note that the coords are chunk-relative!
2014-02-02 06:49:37 -08:00
virtual void OnUpdate ( cChunkInterface & cChunkInterface , cWorldInterface & a_WorldInterface , cBlockPluginInterface & a_BlockPluginInterface , cChunk & a_Chunk , int a_RelX , int a_RelY , int a_RelZ );
2013-07-29 12:13:03 +01:00
2014-07-17 22:50:58 +02:00
/** Called before a block is placed into a world.
2013-07-29 12:13:03 +01:00
The handler should return true to allow placement, false to refuse.
Also, the handler should set a_BlockType and a_BlockMeta to correct values for the newly placed block.
Called by cItemHandler::GetPlacementBlockTypeMeta() if the item is a block
*/
virtual bool GetPlacementBlockTypeMeta (
2014-02-01 05:06:32 -08:00
cChunkInterface & a_ChunkInterface , cPlayer * a_Player ,
2014-07-17 22:50:58 +02:00
int a_BlockX , int a_BlockY , int a_BlockZ , eBlockFace a_BlockFace ,
2013-07-29 12:13:03 +01:00
int a_CursorX , int a_CursorY , int a_CursorZ ,
BLOCKTYPE & a_BlockType , NIBBLETYPE & a_BlockMeta
);
/// Called by cWorld::SetBlock() after the block has been set
2014-02-01 05:06:32 -08:00
virtual void OnPlaced ( cChunkInterface & a_ChunkInterface , cWorldInterface & a_WorldInterface , int a_BlockX , int a_BlockY , int a_BlockZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta );
2013-07-29 12:13:03 +01:00
/// Called by cClientHandle::HandlePlaceBlock() after the player has placed a new block. Called after OnPlaced().
virtual void OnPlacedByPlayer (
2014-07-17 22:50:58 +02:00
cChunkInterface & a_ChunkInterface , cWorldInterface & a_WorldInterface , cPlayer * a_Player ,
int a_BlockX , int a_BlockY , int a_BlockZ , eBlockFace a_BlockFace ,
2013-07-29 12:13:03 +01:00
int a_CursorX , int a_CursorY , int a_CursorZ ,
BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta
);
/// Called before the player has destroyed a block
2014-02-01 06:01:13 -08:00
virtual void OnDestroyedByPlayer ( cChunkInterface & a_ChunkInterface , cWorldInterface & a_WorldInterface , cPlayer * a_Player , int a_BlockX , int a_BlockY , int a_BlockZ );
2013-07-29 12:13:03 +01:00
/// Called before a block gets destroyed / replaced with air
2014-02-01 05:06:32 -08:00
virtual void OnDestroyed ( cChunkInterface & a_ChunkInterface , cWorldInterface & a_WorldInterface , int a_BlockX , int a_BlockY , int a_BlockZ );
2013-07-29 12:13:03 +01:00
/// Called when a direct neighbor of this block has been changed (The position is the own position, not the neighbor position)
2014-07-17 22:26:53 +01:00
virtual void OnNeighborChanged ( cChunkInterface & a_ChunkInterface , int a_BlockX , int a_BlockY , int a_BlockZ ) {};
2013-07-29 12:13:03 +01:00
/// Notifies all neighbors of the given block about a change
2014-02-01 05:06:32 -08:00
static void NeighborChanged ( cChunkInterface & a_ChunkInterface , int a_BlockX , int a_BlockY , int a_BlockZ );
2013-07-29 12:13:03 +01:00
/// Called while the player diggs the block.
2014-07-17 22:26:53 +01:00
virtual void OnDigging ( cChunkInterface & cChunkInterface , cWorldInterface & a_WorldInterface , cPlayer * a_Player , int a_BlockX , int a_BlockY , int a_BlockZ ) {};
2013-07-29 12:13:03 +01:00
/// Called if the user right clicks the block and the block is useable
2014-07-17 22:26:53 +01:00
virtual void 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 ) {};
2013-07-29 12:13:03 +01:00
2014-07-20 12:00:20 +01:00
/** Called when a right click to this block is cancelled */
2014-07-17 22:26:53 +01:00
virtual void OnCancelRightClick ( cChunkInterface & a_ChunkInterface , cWorldInterface & a_WorldInterface , cPlayer * a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , eBlockFace a_BlockFace ) {};
2014-03-05 15:10:20 +01:00
2013-11-30 15:58:27 +01:00
/// <summary>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</summary>
2013-07-29 12:13:03 +01:00
virtual void ConvertToPickups ( cItems & a_Pickups , NIBBLETYPE a_BlockMeta );
2014-07-20 12:00:20 +01:00
/** 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 NULL
@param a_DropVerbatim Calls ConvertToVerbatimPickups() instead of its counterpart, meaning the block itself is dropped by default (due to a speical tool or enchantment)
*/
2014-07-17 22:26:53 +01:00
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_DropVerbatim = false );
2013-07-29 12:13:03 +01:00
/// Returns step sound name of block
virtual const char * GetStepSound ( void );
/// Checks if the block can stay at the specified relative coords in the chunk
2014-02-01 05:06:32 -08:00
virtual bool CanBeAt ( cChunkInterface & a_ChunkInterface , int a_RelX , int a_RelY , int a_RelZ , const cChunk & a_Chunk );
2014-04-06 21:41:01 +02:00
2014-05-07 12:59:48 +02:00
/** Can the dirt under this block grow to grass? */
virtual bool CanDirtGrowGrass ( NIBBLETYPE a_Meta );
2014-03-05 19:33:43 +01:00
2013-07-29 12:13:03 +01:00
/** Checks if the block can be placed at this point.
2014-07-17 22:50:58 +02:00
Default: CanBeAt(...)
2013-07-29 12:13:03 +01:00
NOTE: This call doesn't actually place the block
*/
// virtual bool CanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir);
2013-09-15 12:18:14 +01:00
2013-07-29 12:13:03 +01:00
/// Called to check whether this block supports a rclk action. If it returns true, OnUse() is called
virtual bool IsUseable ( void );
2014-07-17 22:50:58 +02:00
/** Indicates whether the client will click through this block.
2013-07-29 12:13:03 +01:00
For example digging a fire will hit the block below the fire so fire is clicked through
*/
virtual bool IsClickedThrough ( void );
2014-07-17 22:50:58 +02:00
/** Checks if the player can build "inside" this block.
2013-07-29 12:13:03 +01:00
For example blocks placed "on" snow will be placed at the same position. So: Snow ignores Build collision
*/
virtual bool DoesIgnoreBuildCollision ( void );
2013-11-30 00:31:21 +00:00
/// <summary>Similar to DoesIgnoreBuildCollision(void), but is used for cases where block meta/player item-in-hand is needed to determine collision (thin snow)</summary>
2014-07-17 22:50:58 +02:00
virtual bool DoesIgnoreBuildCollision ( cPlayer * , NIBBLETYPE a_Meta )
{
2013-12-22 13:46:55 +00:00
UNUSED ( a_Meta );
2014-07-17 22:50:58 +02:00
return DoesIgnoreBuildCollision ();
2013-12-22 13:46:55 +00:00
}
2013-11-30 00:31:21 +00:00
/// <summary>Returns if this block drops if it gets destroyed by an unsuitable situation. Default: true</summary>
2013-07-29 12:13:03 +01:00
virtual bool DoesDropOnUnsuitable ( void );
2014-07-17 22:50:58 +02:00
/** Called when one of the neighbors gets set; equivalent to MC block update.
2013-07-29 12:13:03 +01:00
By default drops if position no more suitable (CanBeAt(), DoesDropOnUnsuitable(), Drop()),
and wakes up all simulators on the block.
*/
2014-02-02 06:49:37 -08:00
virtual void Check ( cChunkInterface & ChunkInterface , cBlockPluginInterface & a_PluginInterface , int a_RelX , int a_RelY , int a_RelZ , cChunk & a_Chunk );
2013-07-29 12:13:03 +01:00
2013-11-30 00:31:21 +00:00
/// <summary>Rotates a given block meta counter-clockwise. Default: no change</summary>
/// <returns>Block meta following rotation</returns>
2013-07-29 12:13:03 +01:00
virtual NIBBLETYPE MetaRotateCCW ( NIBBLETYPE a_Meta ) { return a_Meta ; }
2013-11-30 00:31:21 +00:00
/// <summary>Rotates a given block meta clockwise. Default: no change</summary>
/// <returns>Block meta following rotation</returns>
2013-07-29 12:13:03 +01:00
virtual NIBBLETYPE MetaRotateCW ( NIBBLETYPE a_Meta ) { return a_Meta ; }
2013-11-30 00:31:21 +00:00
/// <summary>Mirros a given block meta around the XY plane. Default: no change</summary>
/// <returns>Block meta following mirroring</returns>
2013-07-29 12:13:03 +01:00
virtual NIBBLETYPE MetaMirrorXY ( NIBBLETYPE a_Meta ) { return a_Meta ; }
2013-11-30 00:31:21 +00:00
/// <summary>Mirros a given block meta around the XZ plane. Default: no change</summary>
/// <returns>Block meta following mirroring</returns>
2013-07-29 12:13:03 +01:00
virtual NIBBLETYPE MetaMirrorXZ ( NIBBLETYPE a_Meta ) { return a_Meta ; }
2013-11-30 00:31:21 +00:00
/// <summary>Mirros a given block meta around the YZ plane. Default: no change</summary>
/// <returns>Block meta following mirroring</returns>
2013-07-29 12:13:03 +01:00
virtual NIBBLETYPE MetaMirrorYZ ( NIBBLETYPE a_Meta ) { return a_Meta ; }
2013-11-30 00:31:21 +00:00
2013-07-29 12:13:03 +01:00
protected :
BLOCKTYPE m_BlockType ;
// Creates a new blockhandler for the given block type. For internal use only, use ::GetBlockHandler() instead.
2014-03-02 21:25:05 +02:00
static cBlockHandler * CreateBlockHandler ( BLOCKTYPE a_BlockType );
2013-07-29 12:13:03 +01:00
2014-03-02 21:25:05 +02:00
friend class cBlockInfo ;
};
2013-07-29 12:13:03 +01:00