Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cBlockHandler Class Reference

#include <BlockHandler.h>

Inheritance diagram for cBlockHandler:
Inheritance graph
[legend]

Public Member Functions

virtual bool CanBeAt (const cChunk &a_Chunk, Vector3i a_Position, NIBBLETYPE a_Meta) const
 Checks if the block can stay at the specified relative coords in the chunk. More...
 
virtual bool CanSustainPlant (BLOCKTYPE a_Plant) const
 Checks whether the block has an effect on growing the plant. More...
 
constexpr cBlockHandler (BLOCKTYPE a_BlockType)
 
void Check (cChunkInterface &ChunkInterface, cBlockPluginInterface &a_PluginInterface, Vector3i a_RelPos, cChunk &a_Chunk) const
 Called when one of the neighbors gets set; equivalent to MC block update. More...
 
virtual cItems ConvertToPickups (NIBBLETYPE a_BlockMeta, const cItem *a_Tool=nullptr) const
 Returns the pickups that would result if the block was mined by a_Digger using a_Tool. More...
 
virtual bool DoesIgnoreBuildCollision (const cWorld &a_World, const cItem &a_HeldItem, Vector3i a_Position, NIBBLETYPE a_Meta, eBlockFace a_ClickedBlockFace, bool a_ClickedDirectly) const
 Checks if the player can build "inside" this block. More...
 
virtual ColourID GetMapBaseColourID (NIBBLETYPE a_Meta) const
 Returns the base colour ID of the block, as will be represented on a map, as per documentation: https://minecraft.wiki/w/Map_item_format. More...
 
virtual cBoundingBox GetPlacementCollisionBox (BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const
 Returns the relative bounding box that must be entity-free in order for the block to be placed. More...
 
virtual int Grow (cChunk &a_Chunk, Vector3i a_RelPos, int a_NumStages=1) const
 Grows this block, if it supports growing, by the specified amount of stages (at most). More...
 
virtual bool IsInsideBlock (const Vector3d a_RelPosition, const NIBBLETYPE a_BlockMeta) const
 Tests if a_RelPosition is inside the block, where a_RelPosition is relative to the origin of the block. More...
 
virtual bool IsUseable (void) const
 Called to check whether this block supports a rclk action. More...
 
virtual NIBBLETYPE MetaMirrorXY (NIBBLETYPE a_Meta) const
 Mirrors a given block meta around the XY plane. More...
 
virtual NIBBLETYPE MetaMirrorXZ (NIBBLETYPE a_Meta) const
 Mirros a given block meta around the XZ plane. More...
 
virtual NIBBLETYPE MetaMirrorYZ (NIBBLETYPE a_Meta) const
 Mirros a given block meta around the YZ plane. More...
 
virtual NIBBLETYPE MetaRotateCCW (NIBBLETYPE a_Meta) const
 Rotates a given block meta counter-clockwise. More...
 
virtual NIBBLETYPE MetaRotateCW (NIBBLETYPE a_Meta) const
 Rotates a given block meta clockwise. More...
 
virtual void OnBroken (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, const cEntity *a_Digger) const
 Called after a block gets broken (replaced with air), by natural means. More...
 
virtual void OnCancelRightClick (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const
 Called when a right click to this block is cancelled. More...
 
virtual void OnDigging (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos) const
 Called when the player starts digging the block. More...
 
virtual void OnNeighborChanged (cChunkInterface &a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const
 Called when a direct neighbor of this block has been changed. More...
 
virtual void OnPlaced (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) const
 Called by cWorld::SetBlock() after the block has been set. More...
 
virtual void OnUpdate (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cBlockPluginInterface &a_BlockPluginInterface, cChunk &a_Chunk, const Vector3i a_RelPos) const
 Called when the block gets ticked either by a random tick or by a queued tick. More...
 
virtual bool OnUse (cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const
 Called when the user right clicks the block and the block is useable. More...
 

Static Public Member Functions

static const cBlockHandlerFor (BLOCKTYPE a_BlockType)
 
static char FortuneDiscreteRandom (char a_MinDrop, char a_DefaultMax, unsigned char a_BonusMax, char a_DropCap=25)
 Returns a random number of drops taking into account fortune. More...
 
static void NeighborChanged (cChunkInterface &a_ChunkInterface, Vector3i a_NeighborPos, eBlockFace a_WhichNeighbor)
 Notifies the specified neighbor that the current block has changed. More...
 
static unsigned char ToolFortuneLevel (const cItem *a_Tool)
 Returns the fortune level of a tool, if it is a valid tool. More...
 
static bool ToolHasSilkTouch (const cItem *a_Tool)
 Returns true if the specified tool is valid and has a non-zero silk-touch enchantment. More...
 

Protected Member Functions

 ~cBlockHandler ()=default
 

Protected Attributes

const BLOCKTYPE m_BlockType
 

Detailed Description

Definition at line 25 of file BlockHandler.h.

Constructor & Destructor Documentation

◆ cBlockHandler()

constexpr cBlockHandler::cBlockHandler ( BLOCKTYPE  a_BlockType)
inlineconstexpr

Definition at line 29 of file BlockHandler.h.

◆ ~cBlockHandler()

cBlockHandler::~cBlockHandler ( )
protecteddefault

Member Function Documentation

◆ CanBeAt()

bool cBlockHandler::CanBeAt ( const cChunk a_Chunk,
Vector3i  a_Position,
NIBBLETYPE  a_Meta 
) const
virtual

◆ CanSustainPlant()

virtual bool cBlockHandler::CanSustainPlant ( BLOCKTYPE  a_Plant) const
inlinevirtual

Checks whether the block has an effect on growing the plant.

Reimplemented in cBlockNetherrack, cBlockWaterHandler, cBlockLavaHandler, and cBlockFarmlandHandler.

Definition at line 128 of file BlockHandler.h.

◆ Check()

void cBlockHandler::Check ( cChunkInterface ChunkInterface,
cBlockPluginInterface a_PluginInterface,
Vector3i  a_RelPos,
cChunk a_Chunk 
) 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()), otherwise wakes up all simulators on the block.

Definition at line 564 of file BlockHandler.cpp.

◆ ConvertToPickups()

cItems cBlockHandler::ConvertToPickups ( NIBBLETYPE  a_BlockMeta,
const cItem a_Tool = nullptr 
) const
virtual

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_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.

Reimplemented in cBlockPistonHeadHandler, cClearMetaOnDrop< cBlockPlant< false > >, cClearMetaOnDrop< cBlockHandler >, cClearMetaOnDrop< cBlockEntityHandler >, cClearMetaOnDrop< cBlockTorchBaseHandler >, cBlockWallSignHandler, cBlockVinesHandler, cBlockTripwireHandler, cBlockRedstoneTorchHandler, cBlockTallGrassHandler, cBlockSugarCaneHandler, cBlockStoneHandler, cBlockStemsHandler< ProduceBlockType, StemPickupType >, cBlockSnowHandler, cBlockDoubleSlabHandler, cBlockSlabHandler, cBlockSignPostHandler, cBlockSidewaysHandler, cBlockSeaLanternHandler, cBlockSaplingHandler, cBlockRedstoneWireHandler, cBlockRedstoneLampHandler, cBlockPortalHandler, cBlockPackedIceHandler, cBlockOreHandler, cBlockNetherWartHandler, cBlockMyceliumHandler, cBlockMobSpawnerHandler, cBlockMobHeadHandler, cBlockMelonHandler, cBlockLeverHandler, cBlockLeavesHandler, cBlockInfestedHandler, cBlockIceHandler, cBlockHugeMushroomHandler, cBlockGravelHandler, cBlockGrassHandler, cBlockGlowstoneHandler, cBlockGlassHandler, cBlockFluidHandler, cBlockFlowerPotHandler, cBlockFlowerHandler, cBlockFireHandler, cBlockFarmlandHandler, cBlockEnchantingTableHandler, cBlockDirtHandler, cBlockDeadBushHandler, cBlockDaylightSensorHandler, cBlockCropsHandler< RipeMeta >, cBlockCommandBlockHandler, cBlockCocoaPodHandler, cBlockCobWebHandler, cBlockCauldronHandler, cBlockCakeHandler, cBlockBrewingStandHandler, cBlockBookShelfHandler, cBlockBigFlowerHandler, cBlockBannerHandler, and cBlockAirHandler.

Definition at line 501 of file BlockHandler.cpp.

◆ DoesIgnoreBuildCollision()

bool cBlockHandler::DoesIgnoreBuildCollision ( const cWorld a_World,
const cItem a_HeldItem,
Vector3i  a_Position,
NIBBLETYPE  a_Meta,
eBlockFace  a_ClickedBlockFace,
bool  a_ClickedDirectly 
) const
virtual

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

Parameters
a_PosPosition of the block
a_PlayerPlayer trying to build on the block
a_MetaMeta value of the block currently at a_Pos

Reimplemented in cBlockBigFlowerHandler, cBlockVinesHandler, cBlockTallGrassHandler, cBlockSnowHandler, cBlockSlabHandler, cBlockFluidHandler, cBlockFireHandler, and cBlockDeadBushHandler.

Definition at line 531 of file BlockHandler.cpp.

◆ For()

const cBlockHandler & cBlockHandler::For ( BLOCKTYPE  a_BlockType)
static

Definition at line 631 of file BlockHandler.cpp.

◆ FortuneDiscreteRandom()

char cBlockHandler::FortuneDiscreteRandom ( char  a_MinDrop,
char  a_DefaultMax,
unsigned char  a_BonusMax,
char  a_DropCap = 25 
)
static

Returns a random number of drops taking into account fortune.

Only applies to drops following clamped discrete random distribution. a_DefaultMax is the maximum items from one block without fortune. a_BonusMax is the amount to increase the max of randInt by, usually the fortune level (but not always) a_DropCap is the maximum items from one block with fortune, if unspecified set to 25 to prevent lag or crash with high level tools. Similar to uniform_bonus_count at https://minecraft.wiki/w/Loot_table#Functions

Definition at line 618 of file BlockHandler.cpp.

◆ GetMapBaseColourID()

ColourID cBlockHandler::GetMapBaseColourID ( NIBBLETYPE  a_Meta) const
virtual

Returns the base colour ID of the block, as will be represented on a map, as per documentation: https://minecraft.wiki/w/Map_item_format.

Reimplemented in cBlockWorkbenchHandler, cBlockWallSignHandler, cBlockVinesHandler, cBlockTripwireHookHandler, cBlockTripwireHandler, cBlockRedstoneTorchHandler, cBlockTorchBaseHandler, cBlockTNTHandler, cBlockTallGrassHandler, cBlockSugarCaneHandler, cBlockStoneHandler, cBlockStemsHandler< ProduceBlockType, StemPickupType >, cBlockSpongeHandler, cBlockSnowHandler, cBlockSlimeHandler, cBlockDoubleSlabHandler, cBlockSlabHandler, cBlockSignPostHandler, cBlockSaplingHandler, cBlockSandHandler, cBlockRedstoneWireHandler, cBlockRedstoneLampHandler, cBlockRailHandler, cBlockQuartzHandler, cBlockPressurePlateHandler, cBlockPortalHandler, cBlockPlanksHandler, cBlockPackedIceHandler, cBlockNetherWartHandler, cBlockMyceliumHandler, cBlockMushroomHandler, cBlockMobHeadHandler, cBlockMelonHandler, cBlockLilypadHandler, cBlockLeverHandler, cBlockLeavesHandler, cBlockJukeboxHandler, cBlockInfestedHandler, cBlockIceHandler, cBlockHugeMushroomHandler, cBlockGravelHandler, cBlockGrassHandler, cBlockGlowstoneHandler, cBlockGlassHandler, cBlockWaterHandler, cBlockLavaHandler, cBlockFlowerPotHandler, cBlockFlowerHandler, cBlockFireHandler, cBlockEnchantingTableHandler, cBlockDirtHandler, cBlockDeadBushHandler, cBlockCropsHandler< RipeMeta >, cBlockConcretePowderHandler, cBlockCommandBlockHandler, cBlockCocoaPodHandler, cBlockCobWebHandler, cBlockClothHandler, cBlockCauldronHandler, cBlockCarpetHandler, cBlockCakeHandler, cBlockCactusHandler, cBlockBrewingStandHandler, cBlockBigFlowerHandler, and cBlockBannerHandler.

Definition at line 583 of file BlockHandler.cpp.

◆ GetPlacementCollisionBox()

cBoundingBox cBlockHandler::GetPlacementCollisionBox ( BLOCKTYPE  a_XM,
BLOCKTYPE  a_XP,
BLOCKTYPE  a_YM,
BLOCKTYPE  a_YP,
BLOCKTYPE  a_ZM,
BLOCKTYPE  a_ZP 
) const
virtual

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.

Reimplemented in cBlockFenceHandler.

Definition at line 550 of file BlockHandler.cpp.

◆ Grow()

virtual int cBlockHandler::Grow ( cChunk a_Chunk,
Vector3i  a_RelPos,
int  a_NumStages = 1 
) const
inlinevirtual

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).

Reimplemented in cBlockTallGrassHandler, cBlockSugarCaneHandler, cBlockStemsHandler< ProduceBlockType, StemPickupType >, cBlockSaplingHandler, cBlockNetherWartHandler, cBlockCropsHandler< RipeMeta >, cBlockCocoaPodHandler, and cBlockCactusHandler.

Definition at line 179 of file BlockHandler.h.

◆ IsInsideBlock()

bool cBlockHandler::IsInsideBlock ( const Vector3d  a_RelPosition,
const NIBBLETYPE  a_BlockMeta 
) const
virtual

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.

Reimplemented in cBlockSlabHandler, and cBlockSnowHandler.

Definition at line 540 of file BlockHandler.cpp.

◆ IsUseable()

bool cBlockHandler::IsUseable ( void  ) const
virtual

Called to check whether this block supports a rclk action.

If it returns true, OnUse() is called

Reimplemented in cBlockWorkbenchHandler, cBlockLeverHandler, cBlockFenceHandler, cBlockEnchantingTableHandler, cBlockDaylightSensorHandler, cBlockCakeHandler, cBlockRedstoneOreHandler, cBlockMobSpawnerHandler, cBlockEntityHandler, and cBlockCauldronHandler.

Definition at line 522 of file BlockHandler.cpp.

◆ MetaMirrorXY()

virtual NIBBLETYPE cBlockHandler::MetaMirrorXY ( NIBBLETYPE  a_Meta) const
inlinevirtual

◆ MetaMirrorXZ()

virtual NIBBLETYPE cBlockHandler::MetaMirrorXZ ( NIBBLETYPE  a_Meta) const
inlinevirtual

Mirros a given block meta around the XZ plane.

Default: no change Returns block meta following rotation

Reimplemented in cBlockSlabHandler.

Definition at line 171 of file BlockHandler.h.

◆ MetaMirrorYZ()

virtual NIBBLETYPE cBlockHandler::MetaMirrorYZ ( NIBBLETYPE  a_Meta) const
inlinevirtual

◆ MetaRotateCCW()

virtual NIBBLETYPE cBlockHandler::MetaRotateCCW ( NIBBLETYPE  a_Meta) const
inlinevirtual

◆ MetaRotateCW()

virtual NIBBLETYPE cBlockHandler::MetaRotateCW ( NIBBLETYPE  a_Meta) const
inlinevirtual

◆ NeighborChanged()

void cBlockHandler::NeighborChanged ( cChunkInterface a_ChunkInterface,
Vector3i  a_NeighborPos,
eBlockFace  a_WhichNeighbor 
)
static

Notifies the specified neighbor that the current block 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.)

Definition at line 487 of file BlockHandler.cpp.

◆ OnBroken()

virtual void cBlockHandler::OnBroken ( cChunkInterface a_ChunkInterface,
cWorldInterface a_WorldInterface,
Vector3i  a_BlockPos,
BLOCKTYPE  a_OldBlockType,
NIBBLETYPE  a_OldBlockMeta,
const cEntity a_Digger 
) const
inlinevirtual

Called after a block gets broken (replaced with air), by natural means.

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. You can determine what kind of entity broke the block (e.g. player) by checking a_Digger!

Reimplemented in cBlockRailHandler, cBlockPistonHeadHandler, cBlockOreHandler, cBlockMobSpawnerHandler, cBlockInfestedHandler, cBlockIceHandler, cBlockFenceHandler, and cBlockBigFlowerHandler.

Definition at line 60 of file BlockHandler.h.

◆ OnCancelRightClick()

virtual void cBlockHandler::OnCancelRightClick ( cChunkInterface a_ChunkInterface,
cWorldInterface a_WorldInterface,
cPlayer a_Player,
const Vector3i  a_BlockPos,
eBlockFace  a_BlockFace 
) const
inlinevirtual

Called when a right click to this block is cancelled.

Descendants should force the server to send the real state of a block to the client to prevent client assuming the operation was successfull.

Reimplemented in cBlockTNTHandler, cBlockSlabHandler, and cBlockFenceHandler.

Definition at line 107 of file BlockHandler.h.

◆ OnDigging()

virtual void cBlockHandler::OnDigging ( cChunkInterface a_ChunkInterface,
cWorldInterface a_WorldInterface,
cPlayer a_Player,
const Vector3i  a_BlockPos 
) const
inlinevirtual

Called when the player starts digging the block.

Reimplemented in cBlockRedstoneOreHandler, and cBlockNoteBlockHandler.

Definition at line 81 of file BlockHandler.h.

◆ OnNeighborChanged()

void cBlockHandler::OnNeighborChanged ( cChunkInterface a_ChunkInterface,
Vector3i  a_BlockPos,
eBlockFace  a_WhichNeighbor 
) const
virtual

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.)

Reimplemented in cBlockVinesHandler, cBlockSpongeHandler, cBlockRailHandler, cBlockLeavesHandler, cBlockFarmlandHandler, and cBlockConcretePowderHandler.

Definition at line 473 of file BlockHandler.cpp.

◆ OnPlaced()

virtual void cBlockHandler::OnPlaced ( cChunkInterface a_ChunkInterface,
cWorldInterface a_WorldInterface,
Vector3i  a_BlockPos,
BLOCKTYPE  a_BlockType,
NIBBLETYPE  a_BlockMeta 
) const
inlinevirtual

Called by cWorld::SetBlock() after the block has been set.

Reimplemented in cBlockSpongeHandler, cBlockRailHandler, cBlockFireHandler, and cBlockConcretePowderHandler.

Definition at line 50 of file BlockHandler.h.

◆ OnUpdate()

void cBlockHandler::OnUpdate ( cChunkInterface a_ChunkInterface,
cWorldInterface a_WorldInterface,
cBlockPluginInterface a_BlockPluginInterface,
cChunk a_Chunk,
const Vector3i  a_RelPos 
) const
virtual

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!

Reimplemented in cBlockVinesHandler, cBlockSaplingHandler, cBlockPortalHandler, cBlockPlant< NeedsLightToGrow >, cBlockPlant< false >, cBlockPlant< true >, cBlockLeavesHandler, cBlockIceHandler, cBlockGrassHandler, cBlockLavaHandler, cBlockFarmlandHandler, cBlockCocoaPodHandler, cBlockCauldronHandler, and cBlockGlowingRedstoneOreHandler.

Definition at line 459 of file BlockHandler.cpp.

◆ OnUse()

virtual bool cBlockHandler::OnUse ( cChunkInterface a_ChunkInterface,
cWorldInterface a_WorldInterface,
cPlayer a_Player,
const Vector3i  a_BlockPos,
eBlockFace  a_BlockFace,
const Vector3i  a_CursorPos 
) const
inlinevirtual

Called when the user right clicks the block and the block is useable.

a_CursorPos is the cursor position within the clicked block face. Returns true if the use was successful, return false to use the block as a "normal" block

Reimplemented in cBlockWorkbenchHandler, cBlockRedstoneOreHandler, cBlockMobSpawnerHandler, cBlockLeverHandler, cBlockFenceHandler, cBlockEntityHandler, cBlockEnchantingTableHandler, cBlockDaylightSensorHandler, cBlockCauldronHandler, and cBlockCakeHandler.

Definition at line 93 of file BlockHandler.h.

◆ ToolFortuneLevel()

unsigned char cBlockHandler::ToolFortuneLevel ( const cItem a_Tool)
static

Returns the fortune level of a tool, if it is a valid tool.

Can be used in ConvertToPickups() implementations.

Definition at line 602 of file BlockHandler.cpp.

◆ ToolHasSilkTouch()

bool cBlockHandler::ToolHasSilkTouch ( const cItem a_Tool)
static

Returns true if the specified tool is valid and has a non-zero silk-touch enchantment.

Helper used in many ConvertToPickups() implementations.

Definition at line 593 of file BlockHandler.cpp.

Member Data Documentation

◆ m_BlockType

const BLOCKTYPE cBlockHandler::m_BlockType
protected

Definition at line 205 of file BlockHandler.h.


The documentation for this class was generated from the following files: