Block
Constants
INTERNAL_STATE_DATA_BITS
public const INTERNAL_STATE_DATA_BITS = 11INTERNAL_STATE_DATA_MASK
public const INTERNAL_STATE_DATA_MASK = ~(~0 << self::INTERNAL_STATE_DATA_BITS)Properties
$collisionBoxes protected
protected ?array $collisionBoxes$fallbackName protected
protected string $fallbackName$idInfo protected
protected \pocketmine\block\BlockIdentifier $idInfo$position protected
protected \pocketmine\world\Position $position$typeInfo protected
protected \pocketmine\block\BlockTypeInfo $typeInfoMethods
__clone()
public function __clone()__construct()
public function __construct(\pocketmine\block\BlockIdentifier $idInfo, string $name, \pocketmine\block\BlockTypeInfo $typeInfo)__toString()
public function __toString()addVelocityToEntity()
public function addVelocityToEntity(\pocketmine\entity\Entity $entity) : ?\pocketmine\math\Vector3Returns a direction vector describing which way an entity intersecting this block should be pushed. This is used by liquids to push entities in liquid currents.
The returned vector is summed with vectors from every other block the entity is intersecting, and normalized to produce a final direction vector.
WARNING: This will not be called if Block::hasEntityCollision() does not return true!
asItem()
public function asItem() : \pocketmine\item\ItemReturns the block as an item. Block-only state such as facing, powered/unpowered, open/closed, etc., is discarded. Block-item state such as colour, wood type, etc. is preserved. Complex state properties stored in the tile data (e.g. inventory) are discarded.
blocksDirectSkyLight()
public function blocksDirectSkyLight() : boolReturns whether this block blocks direct sky light from passing through it. This is independent from the light filter value, which is used during propagation.
In most cases, this is the same as isTransparent(); however, some special cases exist such as leaves and cobwebs, which don't have any additional effect on light propagation, but don't allow direct sky light to pass through.
burnsForever()
public function burnsForever() : boolReturns whether fire lit on this block will burn indefinitely.
calculateIntercept()
public function calculateIntercept(\pocketmine\math\Vector3 $pos1, \pocketmine\math\Vector3 $pos2) : ?\pocketmine\math\RayTraceResultPerforms a ray trace along the line between the two positions using the block's collision boxes. Returns the intersection point closest to pos1, or null if no intersection occurred.
canBeFlowedInto()
public function canBeFlowedInto() : boolReturns whether this block can be destroyed by liquid flowing into its cell.
canBePlaced()
public function canBePlaced() : boolReturns whether this block can be placed when obtained as an item.
canBePlacedAt()
public function canBePlacedAt(\pocketmine\block\Block $blockReplace, \pocketmine\math\Vector3 $clickVector, int $face, bool $isClickedBlock) : boolReturns whether this block can replace the given block in the given placement conditions. This is used to allow slabs of the same type to combine into double slabs.
canBeReplaced()
public function canBeReplaced() : boolReturns whether this block can be replaced by another block placed in the same position.
canClimb()
public function canClimb() : boolReturns whether entities can climb up this block.
collidesWithBB()
public function collidesWithBB(\pocketmine\math\AxisAlignedBB $bb) : boolReturns whether any of the block's collision boxes intersect with the given AxisAlignedBB.
connectsToRedstoneWire() 5.46.0
public function connectsToRedstoneWire(int $face) : boolReturns whether redstone wire on the given side of this block points into this block.
describeBlockItemState()
public function describeBlockItemState(\pocketmine\data\runtime\RuntimeDataDescriber $w) : voidDescribes properties of this block which apply to both the block and item form of the block. Examples of suitable properties include colour, skull type, and any other information which IS kept when the block is mined or block-picked.
The method implementation must NOT use conditional logic to determine which properties are written. It must always write the same properties in the same order, regardless of the current state of the block.
describeBlockOnlyState() protected
protected function describeBlockOnlyState(\pocketmine\data\runtime\RuntimeDataDescriber $w) : voidDescribes properties of this block which apply only to the block form of the block. Examples of suitable properties include facing, open/closed, powered/unpowered, on/off, and any other information which IS NOT kept when the block is mined or block-picked.
The method implementation must NOT use conditional logic to determine which properties are written. It must always write the same properties in the same order, regardless of the current state of the block.
generateStatePermutations()
public function generateStatePermutations() : \GeneratorGenerates copies of this Block in all possible state permutations. Every possible combination of known properties (e.g. facing, open/closed, powered/unpowered, on/off) will be generated.
getAdjacentSupportType() protected
protected function getAdjacentSupportType(int $facing) : \pocketmine\block\utils\SupportTypegetAffectedBlocks()
public function getAffectedBlocks() : arrayReturns a list of blocks that this block is part of. In most cases, only contains the block itself, but in cases such as double plants, beds and doors, will contain both halves.
getAllSides()
public function getAllSides() : \GeneratorReturns the six blocks around this block.
getBreakInfo()
public function getBreakInfo() : \pocketmine\block\BlockBreakInfoReturns an object containing information about the destruction requirements of this block.
getCollisionBoxes()
final public function getCollisionBoxes() : arrayReturns an array of collision bounding boxes for this block. These are used for:
- entity movement collision checks (to ensure entities can't clip through blocks)
- projectile flight paths
- block placement (to ensure the player can't place blocks inside itself or another entity)
- anti-cheat checks in plugins
getCompostabilityChance() 5.46.0
public function getCompostabilityChance() : intReturns the chance that this block will fill one layer of a composter.
getCreativeDrops() 5.46.0
public function getCreativeDrops() : arrayReturn items dropped by the block when it is broken by a player in gamemode creative
getDrops()
public function getDrops(\pocketmine\item\Item $item) : arrayReturns an array of Item objects to be dropped
getDropsForCompatibleTool()
public function getDropsForCompatibleTool(\pocketmine\item\Item $item) : arrayReturns an array of Items to be dropped when the block is broken using the correct tool type.
getDropsForIncompatibleTool()
public function getDropsForIncompatibleTool(\pocketmine\item\Item $item) : arrayReturns the items dropped by this block when broken with an incorrect tool type (or tool with a too-low tier).
getEnchantmentTags()
public function getEnchantmentTags() : arrayReturns tags that represent the type of item being enchanted and are used to determine what enchantments can be applied to the item of this block during in-game enchanting (enchanting table, anvil, fishing, etc.).
getFlameEncouragement()
public function getFlameEncouragement() : intReturns the chance that the block will catch fire from nearby fire sources. Higher values lead to faster catching fire.
getFlammability()
public function getFlammability() : intReturns the base flammability of this block. Higher values lead to the block burning away more quickly.
getFrictionFactor()
public function getFrictionFactor() : floatReturns a multiplier applied to the velocity of entities moving on top of this block. A higher value will make the block more slippery (like ice).
getFuelTime()
public function getFuelTime() : intReturns the time in ticks which the block will fuel a furnace for.
getHorizontalSides()
public function getHorizontalSides() : \GeneratorReturns the 4 blocks on the horizontal axes around the block (north, south, east, west)
getIdInfo()
public function getIdInfo() : \pocketmine\block\BlockIdentifierReturns an object containing information about how to identify and store this block type, such as type ID and tile type (if any).
getLightFilter()
public function getLightFilter() : intReturns the amount of light this block will filter out when light passes through this block. This value is used in light spread calculation.
getLightLevel()
public function getLightLevel() : intReturns the amount of light emitted by this block.
getMaxStackSize()
public function getMaxStackSize() : intReturns the maximum number of this block that can fit into a single item stack.
getModelPositionOffset()
public function getModelPositionOffset() : ?\pocketmine\math\Vector3Returns an additional fractional vector to shift the block model's position by based on the current position. Used to randomize position of things like bamboo canes and tall grass.
getName()
public function getName() : stringReturns the printable English name of the block.
getPickedItem()
public function getPickedItem(bool $addUserData = false) : \pocketmine\item\ItemReturns the item that players will equip when middle-clicking on this block. If addUserData is true, additional data may be added, such as banner patterns, chest contents, etc.
getPistonPushReaction() 5.46.0
public function getPistonPushReaction() : \pocketmine\block\utils\PistonPushReactionReturns how this block reacts to being moved by a piston.
getPosition()
final public function getPosition() : \pocketmine\world\PositiongetSide()
public function getSide(int $side, int $step = 1)Returns the Block on the side $side, works like Vector3::getSide()
getSilkTouchDrops()
public function getSilkTouchDrops(\pocketmine\item\Item $item) : arrayReturns an array of Items to be dropped when the block is broken using a compatible Silk Touch-enchanted tool.
getStrongPower() 5.46.0
public function getStrongPower(int $face) : intReturns the redstone power (0-15) that this block strongly delivers into the block on the given side. A redstone conductor (see Block::isRedstoneConductor()) receiving strong power acts as a power source for all of its own neighbours.
getSupportType()
public function getSupportType(int $facing) : \pocketmine\block\utils\SupportTypeReturns the type of support that the block can provide on the given face. This is used to determine whether blocks placed on the given face can be supported by this block.
getTypeId()
public function getTypeId() : intReturns a type ID that identifies this type of block. This allows comparing basic block types, e.g. wool, stone, glass, etc. Type ID will not change for a given block type.
Information such as colour, powered, open/closed, etc. is not included in this ID. If you want to get a state ID that includes this information, use Block::getStateId() instead.
getTypeTags()
public function getTypeTags() : arraygetWeakPower() 5.46.0
public function getWeakPower(int $face) : intReturns the redstone power (0-15) that this block emits out of the given face, into the block on that side.
Weak power activates redstone components directly on that side (lamps, doors, wire...), but does not make a solid block on that side powered for its own neighbours.
getXpDropAmount() protected
protected function getXpDropAmount() : intReturns how much XP this block will drop when broken with an appropriate tool.
getXpDropForTool()
public function getXpDropForTool(\pocketmine\item\Item $item) : intReturns how much XP will be dropped by breaking this block with the given item.
hasEntityCollision()
public function hasEntityCollision() : boolReturns whether the block has actions to be executed when an entity enters its cell (full cube space).
hasSameTypeId()
public function hasSameTypeId(\pocketmine\block\Block $other) : boolReturns whether the given block has the same type ID as this one.
hasTypeTag()
public function hasTypeTag(string $tag) : boolReturns whether this block type has the given type tag. Type tags are used as a dynamic way to tag blocks as having certain properties, allowing type checks which are more dynamic than hardcoding a bunch of IDs or a bunch of instanceof checks.
For example, grass blocks, dirt, farmland, podzol and mycelium are all dirt-like blocks, and support the placement of blocks like flowers, so they have a common tag which allows them to be identified as such.
isAffectedBySilkTouch()
public function isAffectedBySilkTouch() : boolReturns whether Silk Touch enchanted tools will cause this block to drop as itself.
isCompostable() 5.46.0
public function isCompostable() : boolReturns whether this block can be used in a composter.
isFireProofAsItem()
public function isFireProofAsItem() : boolisFlammable()
public function isFlammable() : boolReturns whether this block can catch fire.
isFullCube()
public function isFullCube() : boolisPlacementObstructedByEntities() 5.46.0
public function isPlacementObstructedByEntities() : boolReturns whether entities in the way stop the block from being placed, which is the case when its collision boxes would intersect them. Blocks that entities can stand inside, like scaffolding, return false.
isRedstoneConductor() 5.46.0
public function isRedstoneConductor() : boolReturns whether this block relays strong power to its neighbours (like stone or planks). Transparent and non-full blocks (glass, slabs, leaves...) do not.
isRedstoneSource() 5.46.0
public function isRedstoneSource() : boolReturns whether this block can emit redstone power at all, regardless of its current state. Redstone wire connects to blocks that are power sources (see also Block::connectsToRedstoneWire()).
isSameState()
public function isSameState(\pocketmine\block\Block $other) : boolReturns whether the given block has the same type and properties as this block.
Note: Tile data (e.g. sign text, chest contents) are not compared here.
isSolid()
public function isSolid() : boolDeprecated
TL;DR: Don't use this function. Its results are confusing and inconsistent.
No one is sure what the meaning of this property actually is. It's borrowed from Minecraft Java Edition, and is used by various blocks for support checks.
Things like signs and banners are considered "solid" despite having no collision box, and things like skulls and flower pots are considered non-solid despite obviously being "solid" in the conventional, real-world sense.
isTransparent()
public function isTransparent() : boolReturns whether this block allows any light to pass through it.
onAttack()
public function onAttack(\pocketmine\item\Item $item, int $face, ?\pocketmine\player\Player $player = null) : boolCalled when this block is attacked (left-clicked) by a player attempting to start breaking it in survival.
onBreak()
public function onBreak(\pocketmine\item\Item $item, ?\pocketmine\player\Player $player = null, array &$returnedItems = []) : boolDo the actions needed so the block is broken with the Item
onEntityInside()
public function onEntityInside(\pocketmine\entity\Entity $entity) : boolCalled when an entity's bounding box clips inside this block's cell. Note that the entity may not be intersecting with the collision box or bounding box.
WARNING: This will not be called if Block::hasEntityCollision() returns false.
onEntityLand()
public function onEntityLand(\pocketmine\entity\Entity $entity) : ?floatCalled when an entity lands on this block (usually due to falling).
onIncinerate()
public function onIncinerate() : voidCalled when this block is burned away by being on fire.
onInteract()
public function onInteract(\pocketmine\item\Item $item, int $face, \pocketmine\math\Vector3 $clickVector, ?\pocketmine\player\Player $player = null, array &$returnedItems = []) : boolDo actions when interacted by Item. Returns if it has done anything
onNearbyBlockChange()
public function onNearbyBlockChange() : voidCalled when this block or a block immediately adjacent to it changes state.
onPostPlace()
public function onPostPlace() : voidCalled immediately after the block has been placed in the world. Since placement uses a block transaction, some things may not be possible until after the transaction has been executed.
onPrecipitation() 5.46.0
public function onPrecipitation(\pocketmine\world\weather\Precipitation $precipitation) : voidCalled now and then while rain or snow falls on this block (it is the top block of its column). Used by cauldrons to fill up. Like random ticks, this follows the chunk ticking budget.
onProjectileHit()
public function onProjectileHit(\pocketmine\entity\projectile\Projectile $projectile, \pocketmine\math\RayTraceResult $hitResult) : voidCalled when a projectile collides with one of this block's collision boxes.
onRandomTick()
public function onRandomTick() : voidCalled when this block is randomly updated due to chunk ticking. WARNING: This will not be called if Block::ticksRandomly() does not return true!
onScheduledUpdate()
public function onScheduledUpdate() : voidCalled when this block is updated by the delayed blockupdate scheduler in the world.
pausesScheduledUpdatesOutsideTickingChunks() 5.46.0
public function pausesScheduledUpdatesOutsideTickingChunks() : boolWhether a due scheduled update of this block waits while its chunk is not ticked (outside the chunk ticking radius of every player), like vanilla block ticks, instead of running in any loaded chunk. It runs as soon as the chunk is ticked again; it is dropped if the chunk unloads first (scheduled updates are not saved).
place()
public function place(\pocketmine\world\BlockTransaction $tx, \pocketmine\item\Item $item, \pocketmine\block\Block $blockReplace, \pocketmine\block\Block $blockClicked, int $face, \pocketmine\math\Vector3 $clickVector, ?\pocketmine\player\Player $player = null) : boolGenerates a block transaction to set all blocks affected by placing this block. Usually this is just the block itself, but may be multiple blocks in some cases (such as doors).
readStateFromWorld()
public function readStateFromWorld() : \pocketmine\block\BlockCalled when this block is created, set, or has a neighbouring block update, to re-detect dynamic properties which are not saved in the blockstate ID. If any such properties are updated, don't forget to clear things like AABB caches if necessary.
A replacement block may be returned. This is useful if the block type changed due to reading of world data (e.g. data from a block entity).
recalculateCollisionBoxes() protected
protected function recalculateCollisionBoxes() : arrayticksRandomly()
public function ticksRandomly() : boolReturns whether random block updates will be done on this block.
writeStateToWorld()
public function writeStateToWorld() : voidWrites information about the block into the world. This writes the blockstate ID into the chunk, and creates and/or removes tiles as necessary.
Note: Do not call this directly. Pass the block to World::setBlock() instead.
