Class AbstractBlock

java.lang.Object
net.minecraft.block.AbstractBlock
All Implemented Interfaces:
ToggleableFeature
Direct Known Subclasses:
Block

public abstract class AbstractBlock extends Object implements ToggleableFeature
An abstract class that defines some logic for blocks. This class should not be extended directly. Extend Block instead. Custom block behaviors are specified either through block settings or by overriding methods in this class.

Methods in this class may be executed during world generation if they take WorldAccess as a parameter. In this case, a ChunkRegion is passed to the parameter, which is not a subclass of World.

Deprecated methods in this class mean they should only be called from the corresponding method in AbstractBlock.AbstractBlockState or subclasses of this class. Overriding the methods is an expected usage and is not deprecated in any way.

API Note:
In vanilla subclasses, these methods are called either to do the default behavior (e.g. super.onUse(...)) or to delegate logic to other blocks (e.g. StairsBlock#randomTick calls randomTick of its base block).

Many methods of this class are called on both the logical client and logical server, so take caution when using those methods. The logical side can be checked using World.isClient.

Quick view

Notes: "Tall or wide block" refers to a block that has multiple parts, such as doors, sunflowers, or beds. "Neighboring block" refers to blocks adjacent to a block on all 6 sides (but not diagonally.)

Placement related methods

Block placement related methods (sorted by execution order)
Method Purpose Player/dispenser Falling block setBlockState call
oldState.canReplace Checking if the current block can be replaced Yes Yes No
newBlock.getPlacementState Getting the placed state Yes Yes No
newState.canPlaceAt Checking the block's placement restriction Yes Yes No
oldState.onStateReplaced Dropping inventory, updating redstone circuit, etc Yes Yes Yes
newState.onBlockAdded Activating redstone component, etc Yes Yes Yes
neighborState.neighborUpdate Activating neighboring redstone component, etc Yes Yes Yes
oldState.prepare Updating redstone wire connection Yes Yes Yes
neighborState.getStateForNeighborUpdate Checking the neighboring block's placement restriction, updating connection, etc Yes Yes Yes
newState.prepare Updating redstone wire connection Yes Yes Yes
newBlock.onPlaced Placing the other half of tall or wide block, setting block entity's custom name, etc Yes No No

Breaking related methods

Block breaking related methods (sorted by execution order)
Method Purpose Player mining Explosion setBlockState / removeBlock call breakBlock call
state.onBlockBreakStart Doing something when player starts breaking a block Yes No No No
state.calcBlockBreakingDelta Calculating the player's mining speed Yes No No No
block.onBreak Spawning particles, breaking the other half of tall or wide block, etc Yes No No No
state.onStateReplaced Dropping inventory, updating redstone circuit, etc Yes Yes Yes Yes
neighborState.neighborUpdate Activating neighboring redstone component, etc Yes Yes Yes Yes
state.prepare Updating redstone wire connection Yes Yes Yes Yes
neighborState.getStateForNeighborUpdate Checking the neighboring block's placement restriction, updating connection, etc Yes Yes Yes Yes
block.onBroken Unused in most cases Yes No No No
block.afterBreak Dropping stacks, replacing the broken block with another block, etc Yes No No No
state.getDroppedStacks Supplying information to loot context builder Yes Yes Yes Yes1
state.onStacksDropped Dropping experience orbs Yes Yes2 Yes Yes1

Notes:

  1. Called before onStateReplaced in this case.
  2. Called before getDroppedStacks in this case.
Mappings:
Namespace Name
official cys
intermediary net/minecraft/class_4970
named net/minecraft/block/AbstractBlock