diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-09-20 15:50:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-20 15:50:52 +0200 |
commit | 68cced73afe546328cf94ed07c57deee47bfadec (patch) | |
tree | 88be88e3fd4a208b9849e526f1877caa44058ab5 /src/Blocks/BlockHandler.h | |
parent | Added armor and shulker box cleaning (#4875) (diff) | |
download | cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.gz cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.bz2 cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.lz cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.xz cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.zst cuberite-68cced73afe546328cf94ed07c57deee47bfadec.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Blocks/BlockHandler.h | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 96e251f49..447fc7dc6 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -25,9 +25,11 @@ class BlockTypeRegistry; class cBlockHandler { public: - cBlockHandler(BLOCKTYPE a_BlockType); - virtual ~cBlockHandler() {} + constexpr cBlockHandler(BLOCKTYPE a_BlockType) : + m_BlockType(a_BlockType) + { + } /** Called when the block gets ticked either by a random tick or by a queued tick. Note that the coords in a_RelPos are chunk-relative! */ @@ -37,12 +39,12 @@ public: cBlockPluginInterface & a_BlockPluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos - ); + ) const; /** Returns the relative bounding box that must be entity-free in order for the block to be placed. a_XM, a_XP, etc. stand for the blocktype of the minus-X neighbor, the positive-X neighbor, etc. */ - virtual cBoundingBox GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP); + virtual cBoundingBox GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const; /** Called before a block is placed into a world by player, by cItemHandler::GetPlacementBlockTypeMeta(). The handler should return true to allow placement, false to refuse. @@ -58,19 +60,19 @@ public: eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta - ); + ) const; /** Called by cWorld::SetBlock() after the block has been set */ virtual void OnPlaced( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta - ) {}; + ) const {}; /** 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 - ) {}; + ) const {}; /** 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. @@ -80,7 +82,7 @@ public: cPlayer & a_Player, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta - ) {} + ) const {} /** 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. @@ -90,13 +92,13 @@ public: cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta - ) {}; + ) const {}; /** 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, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor); + virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const; /** Notifies the specified neighbor that the current block has changed. a_NeighborPos are the coords of the neighbor to be notified @@ -111,7 +113,7 @@ public: cWorldInterface & a_WorldInterface, cPlayer & a_Player, const Vector3i a_BlockPos - ) + ) const { } @@ -125,7 +127,7 @@ public: const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos - ) + ) const { return false; } @@ -138,7 +140,7 @@ public: cPlayer & a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace - ) + ) const { } @@ -153,40 +155,40 @@ public: cBlockEntity * a_BlockEntity, const cEntity * a_Digger = nullptr, const cItem * a_Tool = nullptr - ); + ) const; /** Checks if the block can stay at the specified relative coords in the chunk */ virtual bool CanBeAt( cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk - ); + ) const; /** Checks whether the block has an effect on growing the plant */ - virtual bool CanSustainPlant(BLOCKTYPE a_Plant) { return false; } + virtual bool CanSustainPlant(BLOCKTYPE a_Plant) const { return false; } /** Called to check whether this block supports a rclk action. If it returns true, OnUse() is called */ - virtual bool IsUseable(void); + virtual bool IsUseable(void) const; /** Indicates whether the client will click through this block. For example digging a fire will hit the block below the fire so fire is clicked through. */ - virtual bool IsClickedThrough(void); + virtual bool IsClickedThrough(void) const; /** Checks if the player can build "inside" this block. For example blocks placed "on" snow will be placed at the same position. So: Snow ignores Build collision @param a_Pos Position of the block @param a_Player Player trying to build on the block @param a_Meta Meta value of the block currently at a_Pos */ - virtual bool DoesIgnoreBuildCollision(cChunkInterface & ChunkInterface, const Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta); + virtual bool DoesIgnoreBuildCollision(cChunkInterface & ChunkInterface, const Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) const; /** Returns if this block drops if it gets destroyed by an unsuitable situation. Default: true */ - virtual bool DoesDropOnUnsuitable(void); + virtual bool DoesDropOnUnsuitable(void) const; /** Tests if a_RelPosition is inside the block, where a_RelPosition is relative to the origin of the block. Coords in a_RelPosition are guaranteed to be in the [0..1] range. */ - virtual bool IsInsideBlock(const Vector3d a_RelPosition, const NIBBLETYPE a_BlockMeta); + virtual bool IsInsideBlock(const Vector3d a_RelPosition, const NIBBLETYPE a_BlockMeta) const; /** Called when one of the neighbors gets set; equivalent to MC block update. By default drops (DropBlockAsPickup() / SetBlock()) if the position is no longer suitable (CanBeAt(), DoesDropOnUnsuitable()), @@ -195,47 +197,45 @@ public: cChunkInterface & ChunkInterface, cBlockPluginInterface & a_PluginInterface, Vector3i a_RelPos, cChunk & a_Chunk - ); + ) const; /** 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); + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const; /** Rotates a given block meta counter-clockwise. Default: no change Returns block meta following rotation */ - virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) { return a_Meta; } + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) const { return a_Meta; } /** Rotates a given block meta clockwise. Default: no change Returns block meta following rotation */ - virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) { return a_Meta; } + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) const { return a_Meta; } /** Mirrors a given block meta around the XY plane. Default: no change Returns block meta following rotation */ - virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) { return a_Meta; } + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) const { return a_Meta; } /** Mirros a given block meta around the XZ plane. Default: no change Returns block meta following rotation */ - virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) { return a_Meta; } + virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) const { return a_Meta; } /** Mirros a given block meta around the YZ plane. Default: no change Returns block meta following rotation */ - virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; } + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) const { return a_Meta; } /** Grows this block, if it supports growing, by the specified amount of stages (at most). Returns the number of stages actually grown, zero if not supported (default). */ - virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) { return 0; } + virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) const { return 0; } /** 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); // Gets the blockhandler for the given block type. - static cBlockHandler & GetBlockHandler(BLOCKTYPE a_BlockType); + static const cBlockHandler & For(BLOCKTYPE a_BlockType); protected: BLOCKTYPE m_BlockType; - - friend class cBlockInfo; }; |