Skip to content

Block ​

class · pocketmine\block\Block · source

Constants ​

INTERNAL_STATE_DATA_BITS ​

php
public const INTERNAL_STATE_DATA_BITS = 11

INTERNAL_STATE_DATA_MASK ​

php
public const INTERNAL_STATE_DATA_MASK = ~(~0 << self::INTERNAL_STATE_DATA_BITS)

Properties ​

$collisionBoxes protected ​

php
protected ?array $collisionBoxes

$fallbackName protected ​

php
protected string $fallbackName

$idInfo protected ​

php
protected \pocketmine\block\BlockIdentifier $idInfo

$position protected ​

php
protected \pocketmine\world\Position $position

$typeInfo protected ​

php
protected \pocketmine\block\BlockTypeInfo $typeInfo

Methods ​

__clone() ​

php
public function __clone()

__construct() ​

php
public function __construct(\pocketmine\block\BlockIdentifier $idInfo, string $name, \pocketmine\block\BlockTypeInfo $typeInfo)

__toString() ​

php
public function __toString()

addVelocityToEntity() ​

php
public function addVelocityToEntity(\pocketmine\entity\Entity $entity) : ?\pocketmine\math\Vector3

Returns 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() ​

php
public function asItem() : \pocketmine\item\Item

Returns 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() ​

php
public function blocksDirectSkyLight() : bool

Returns 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() ​

php
public function burnsForever() : bool

Returns whether fire lit on this block will burn indefinitely.

calculateIntercept() ​

php
public function calculateIntercept(\pocketmine\math\Vector3 $pos1, \pocketmine\math\Vector3 $pos2) : ?\pocketmine\math\RayTraceResult

Performs 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() ​

php
public function canBeFlowedInto() : bool

Returns whether this block can be destroyed by liquid flowing into its cell.

canBePlaced() ​

php
public function canBePlaced() : bool

Returns whether this block can be placed when obtained as an item.

canBePlacedAt() ​

php
public function canBePlacedAt(\pocketmine\block\Block $blockReplace, \pocketmine\math\Vector3 $clickVector, int $face, bool $isClickedBlock) : bool

Returns 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() ​

php
public function canBeReplaced() : bool

Returns whether this block can be replaced by another block placed in the same position.

canClimb() ​

php
public function canClimb() : bool

Returns whether entities can climb up this block.

collidesWithBB() ​

php
public function collidesWithBB(\pocketmine\math\AxisAlignedBB $bb) : bool

Returns whether any of the block's collision boxes intersect with the given AxisAlignedBB.

connectsToRedstoneWire() 5.46.0 ​

php
public function connectsToRedstoneWire(int $face) : bool

Returns whether redstone wire on the given side of this block points into this block.

describeBlockItemState() ​

php
public function describeBlockItemState(\pocketmine\data\runtime\RuntimeDataDescriber $w) : void

Describes 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 ​

php
protected function describeBlockOnlyState(\pocketmine\data\runtime\RuntimeDataDescriber $w) : void

Describes 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() ​

php
public function generateStatePermutations() : \Generator

Generates 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 ​

php
protected function getAdjacentSupportType(int $facing) : \pocketmine\block\utils\SupportType

getAffectedBlocks() ​

php
public function getAffectedBlocks() : array

Returns 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() ​

php
public function getAllSides() : \Generator

Returns the six blocks around this block.

getBreakInfo() ​

php
public function getBreakInfo() : \pocketmine\block\BlockBreakInfo

Returns an object containing information about the destruction requirements of this block.

getCollisionBoxes() ​

php
final public function getCollisionBoxes() : array

Returns 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 ​

php
public function getCompostabilityChance() : int

Returns the chance that this block will fill one layer of a composter.

getCreativeDrops() 5.46.0 ​

php
public function getCreativeDrops() : array

Return items dropped by the block when it is broken by a player in gamemode creative

getDrops() ​

php
public function getDrops(\pocketmine\item\Item $item) : array

Returns an array of Item objects to be dropped

getDropsForCompatibleTool() ​

php
public function getDropsForCompatibleTool(\pocketmine\item\Item $item) : array

Returns an array of Items to be dropped when the block is broken using the correct tool type.

getDropsForIncompatibleTool() ​

php
public function getDropsForIncompatibleTool(\pocketmine\item\Item $item) : array

Returns the items dropped by this block when broken with an incorrect tool type (or tool with a too-low tier).

getEnchantmentTags() ​

php
public function getEnchantmentTags() : array

Returns 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() ​

php
public function getFlameEncouragement() : int

Returns the chance that the block will catch fire from nearby fire sources. Higher values lead to faster catching fire.

getFlammability() ​

php
public function getFlammability() : int

Returns the base flammability of this block. Higher values lead to the block burning away more quickly.

getFrictionFactor() ​

php
public function getFrictionFactor() : float

Returns 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() ​

php
public function getFuelTime() : int

Returns the time in ticks which the block will fuel a furnace for.

getHorizontalSides() ​

php
public function getHorizontalSides() : \Generator

Returns the 4 blocks on the horizontal axes around the block (north, south, east, west)

getIdInfo() ​

php
public function getIdInfo() : \pocketmine\block\BlockIdentifier

Returns an object containing information about how to identify and store this block type, such as type ID and tile type (if any).

getLightFilter() ​

php
public function getLightFilter() : int

Returns the amount of light this block will filter out when light passes through this block. This value is used in light spread calculation.

getLightLevel() ​

php
public function getLightLevel() : int

Returns the amount of light emitted by this block.

getMaxStackSize() ​

php
public function getMaxStackSize() : int

Returns the maximum number of this block that can fit into a single item stack.

getModelPositionOffset() ​

php
public function getModelPositionOffset() : ?\pocketmine\math\Vector3

Returns 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() ​

php
public function getName() : string

Returns the printable English name of the block.

getPickedItem() ​

php
public function getPickedItem(bool $addUserData = false) : \pocketmine\item\Item

Returns 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 ​

php
public function getPistonPushReaction() : \pocketmine\block\utils\PistonPushReaction

Returns how this block reacts to being moved by a piston.

getPosition() ​

php
final public function getPosition() : \pocketmine\world\Position

getSide() ​

php
public function getSide(int $side, int $step = 1)

Returns the Block on the side $side, works like Vector3::getSide()

getSilkTouchDrops() ​

php
public function getSilkTouchDrops(\pocketmine\item\Item $item) : array

Returns an array of Items to be dropped when the block is broken using a compatible Silk Touch-enchanted tool.

getStrongPower() 5.46.0 ​

php
public function getStrongPower(int $face) : int

Returns 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() ​

php
public function getSupportType(int $facing) : \pocketmine\block\utils\SupportType

Returns 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() ​

php
public function getTypeId() : int

Returns 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() ​

php
public function getTypeTags() : array

getWeakPower() 5.46.0 ​

php
public function getWeakPower(int $face) : int

Returns 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 ​

php
protected function getXpDropAmount() : int

Returns how much XP this block will drop when broken with an appropriate tool.

getXpDropForTool() ​

php
public function getXpDropForTool(\pocketmine\item\Item $item) : int

Returns how much XP will be dropped by breaking this block with the given item.

hasEntityCollision() ​

php
public function hasEntityCollision() : bool

Returns whether the block has actions to be executed when an entity enters its cell (full cube space).

hasSameTypeId() ​

php
public function hasSameTypeId(\pocketmine\block\Block $other) : bool

Returns whether the given block has the same type ID as this one.

hasTypeTag() ​

php
public function hasTypeTag(string $tag) : bool

Returns 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() ​

php
public function isAffectedBySilkTouch() : bool

Returns whether Silk Touch enchanted tools will cause this block to drop as itself.

isCompostable() 5.46.0 ​

php
public function isCompostable() : bool

Returns whether this block can be used in a composter.

isFireProofAsItem() ​

php
public function isFireProofAsItem() : bool

isFlammable() ​

php
public function isFlammable() : bool

Returns whether this block can catch fire.

isFullCube() ​

php
public function isFullCube() : bool

isPlacementObstructedByEntities() 5.46.0 ​

php
public function isPlacementObstructedByEntities() : bool

Returns 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 ​

php
public function isRedstoneConductor() : bool

Returns 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 ​

php
public function isRedstoneSource() : bool

Returns 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() ​

php
public function isSameState(\pocketmine\block\Block $other) : bool

Returns 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() ​

php
public function isSolid() : bool

Deprecated

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() ​

php
public function isTransparent() : bool

Returns whether this block allows any light to pass through it.

onAttack() ​

php
public function onAttack(\pocketmine\item\Item $item, int $face, ?\pocketmine\player\Player $player = null) : bool

Called when this block is attacked (left-clicked) by a player attempting to start breaking it in survival.

onBreak() ​

php
public function onBreak(\pocketmine\item\Item $item, ?\pocketmine\player\Player $player = null, array &$returnedItems = []) : bool

Do the actions needed so the block is broken with the Item

onEntityInside() ​

php
public function onEntityInside(\pocketmine\entity\Entity $entity) : bool

Called 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() ​

php
public function onEntityLand(\pocketmine\entity\Entity $entity) : ?float

Called when an entity lands on this block (usually due to falling).

onIncinerate() ​

php
public function onIncinerate() : void

Called when this block is burned away by being on fire.

onInteract() ​

php
public function onInteract(\pocketmine\item\Item $item, int $face, \pocketmine\math\Vector3 $clickVector, ?\pocketmine\player\Player $player = null, array &$returnedItems = []) : bool

Do actions when interacted by Item. Returns if it has done anything

onNearbyBlockChange() ​

php
public function onNearbyBlockChange() : void

Called when this block or a block immediately adjacent to it changes state.

onPostPlace() ​

php
public function onPostPlace() : void

Called 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 ​

php
public function onPrecipitation(\pocketmine\world\weather\Precipitation $precipitation) : void

Called 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() ​

php
public function onProjectileHit(\pocketmine\entity\projectile\Projectile $projectile, \pocketmine\math\RayTraceResult $hitResult) : void

Called when a projectile collides with one of this block's collision boxes.

onRandomTick() ​

php
public function onRandomTick() : void

Called when this block is randomly updated due to chunk ticking. WARNING: This will not be called if Block::ticksRandomly() does not return true!

onScheduledUpdate() ​

php
public function onScheduledUpdate() : void

Called when this block is updated by the delayed blockupdate scheduler in the world.

pausesScheduledUpdatesOutsideTickingChunks() 5.46.0 ​

php
public function pausesScheduledUpdatesOutsideTickingChunks() : bool

Whether 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() ​

php
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) : bool

Generates 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() ​

php
public function readStateFromWorld() : \pocketmine\block\Block

Called 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 ​

php
protected function recalculateCollisionBoxes() : array

ticksRandomly() ​

php
public function ticksRandomly() : bool

Returns whether random block updates will be done on this block.

writeStateToWorld() ​

php
public function writeStateToWorld() : void

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

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.