Interface BlockPlaceContext


public interface BlockPlaceContext
Where and how a player is placing a block, handed to BlockBehaviour.placementState(BlockPlaceContext).

The server makes it; the default methods work out what most blocks need from the rest.

Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    Returns true when the block on that side can hold the placed block: it is loaded, and neither air nor a fluid.
    Returns the face of the neighbouring block the player clicked.
    float
    Returns the height of the click on the clicked face, from 0 to 1.
    default BlockFace
    Returns the horizontal direction the player looks towards.
    default boolean
    Returns true when the block replaces a water source, and should be waterlogged.
    default BlockFace
    Returns the direction the player looks towards, vertical ones included.
    Returns the location and orientation of the player.
    pos()
    Returns the position the block is placed at.
    Returns the state next to the placed block, or null if it is not loaded.
    Returns the state about to be replaced, or null if it is not loaded.
    boolean
    Returns true when the player sneaks while placing the block: a chest then stays alone, unless it is placed against the side of another chest, which it joins.
    default boolean
    Returns true when the block should go in the upper half, for slabs and stairs.
    Returns read access to the surrounding blocks.
  • Method Details

    • pos

      Returns the position the block is placed at.
      Returns:
      the position the block is placed at
      Since:
      0.1.0
    • clickedFace

      BlockFace clickedFace()
      Returns the face of the neighbouring block the player clicked.
      Returns:
      the face of the neighbouring block the player clicked
      Since:
      0.1.0
    • placer

      Location placer()
      Returns the location and orientation of the player.
      Returns:
      the location and orientation of the player
      Since:
      0.1.0
    • world

      BlockGetter world()
      Returns read access to the surrounding blocks.
      Returns:
      read access to the surrounding blocks
      Since:
      0.1.0
    • cursorY

      float cursorY()
      Returns the height of the click on the clicked face, from 0 to 1.
      Returns:
      the height of the click on the clicked face, from 0 to 1
      Since:
      0.1.0
    • sneaking

      boolean sneaking()
      Returns true when the player sneaks while placing the block: a chest then stays alone, unless it is placed against the side of another chest, which it joins.
      Returns:
      true when the player sneaks while placing the block: a chest then stays alone, unless it is placed against the side of another chest, which it joins
      Since:
      0.1.0
    • horizontalFacing

      default BlockFace horizontalFacing()
      Returns the horizontal direction the player looks towards.
      Returns:
      the horizontal direction the player looks towards
      Since:
      0.1.0
    • lookingDirection

      default BlockFace lookingDirection()
      Returns the direction the player looks towards, vertical ones included.
      Returns:
      the direction the player looks towards, vertical ones included
      Since:
      0.1.0
    • upperHalf

      default boolean upperHalf()
      Returns true when the block should go in the upper half, for slabs and stairs.
      Returns:
      true when the block should go in the upper half, for slabs and stairs
      Since:
      0.1.0
    • replaced

      default @Nullable BlockData replaced()
      Returns the state about to be replaced, or null if it is not loaded.
      Returns:
      the state about to be replaced, or null if it is not loaded
      Since:
      0.1.0
    • relative

      default @Nullable BlockData relative(BlockFace face)
      Returns the state next to the placed block, or null if it is not loaded.
      Parameters:
      face - the side to look at
      Returns:
      the state next to the placed block, or null if it is not loaded
      Since:
      0.1.0
    • canAttachTo

      default boolean canAttachTo(BlockFace side)
      Returns true when the block on that side can hold the placed block: it is loaded, and neither air nor a fluid.
      Parameters:
      side - the side the placed block would be attached to
      Returns:
      true when the block on that side can hold the placed block: it is loaded, and neither air nor a fluid
      Since:
      0.1.0
    • intoWater

      default boolean intoWater()
      Returns true when the block replaces a water source, and should be waterlogged.
      Returns:
      true when the block replaces a water source, and should be waterlogged
      Since:
      0.1.0