Interface BlockBehaviour


public interface BlockBehaviour
The server-side logic of a block type: how it is placed, used and removed, and how it interacts with light.
Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    keepsBlockEntity(BlockData state, BlockData replacement)
    Tells whether the block entity of the block survives it turning into another block type, as a copper chest keeps what it holds when it takes the oxidation of the chest it joins.
    key()
    Returns the key of the block type this behaviour drives.
    default int
    Returns the light level the state emits, from 0 to 15.
    default int
    Returns how much light the state absorbs, from 0 (transparent) to 15 (opaque).
    Returns the color terrain maps draw the state with.
    default void
    onRemove(World world, BlockPosition position, BlockData data)
    Called when the block is about to be replaced by another block type: broken, blown up, or overwritten by a plugin.
    Chooses the state a player places, for instance facing the player.
    Returns the block type this behaviour drives.
    default boolean
    use(Player player, BlockPosition position, BlockData data)
    Called when a player uses the block, a right click, unless they sneak with an item in hand.
  • Method Details

    • type

      BlockType type()
      Returns the block type this behaviour drives.
      Returns:
      the block type this behaviour drives
      Since:
      0.1.0
    • key

      default TypedKey<BlockType> key()
      Returns the key of the block type this behaviour drives.
      Returns:
      the key of the block type this behaviour drives
      Since:
      0.1.0
    • placementState

      default @Nullable BlockData placementState(BlockPlaceContext context)
      Chooses the state a player places, for instance facing the player.
      Parameters:
      context - where and how the block is being placed
      Returns:
      the state to place, or null to refuse the placement
      Since:
      0.1.0
    • use

      default boolean use(Player player, BlockPosition position, BlockData data)
      Called when a player uses the block, a right click, unless they sneak with an item in hand. Opening a crafting table or an ender chest happens here.

      Runs on the thread of the region owning the block.

      Parameters:
      player - the player using the block
      position - where the block is, in the player's world
      data - the state of the block
      Returns:
      true when the use is handled: the held item is then neither used nor placed
      Since:
      0.1.0
    • onRemove

      default void onRemove(World world, BlockPosition position, BlockData data)
      Called when the block is about to be replaced by another block type: broken, blown up, or overwritten by a plugin. The block and its block entity are still in place, so that what it holds can be read.

      Runs on the thread of the region owning the block.

      Parameters:
      world - the world of the block
      position - where the block is
      data - the state being removed
      Since:
      0.1.0
    • keepsBlockEntity

      default boolean keepsBlockEntity(BlockData state, BlockData replacement)
      Tells whether the block entity of the block survives it turning into another block type, as a copper chest keeps what it holds when it takes the oxidation of the chest it joins. When it does, onRemove(World, BlockPosition, BlockData) is not called and the data of the block entity is handed over as it is; the replacement must have a block entity of the same type.

      Runs on the thread of the region owning the block.

      Parameters:
      state - the state being replaced
      replacement - the state of another block type taking its place
      Returns:
      true to keep the block entity; false, the default, to remove it
      Since:
      0.1.0
    • lightEmission

      default int lightEmission(BlockData data)
      Returns the light level the state emits, from 0 to 15.
      Parameters:
      data - the state
      Returns:
      the light level the state emits, from 0 to 15
      Since:
      0.1.0
    • lightOpacity

      default int lightOpacity(BlockData data)
      Returns how much light the state absorbs, from 0 (transparent) to 15 (opaque).
      Parameters:
      data - the state
      Returns:
      how much light the state absorbs, from 0 (transparent) to 15 (opaque)
      Since:
      0.1.0
    • mapColor

      default @Nullable MapColor mapColor(BlockData data)
      Returns the color terrain maps draw the state with.
      Parameters:
      data - the state
      Returns:
      the color, MapColor.NONE for a block maps look through, or null (the default) to keep the vanilla color of the block
      Since:
      0.1.0
      See Also: