Record Class BlockPlaceContext

java.lang.Object
java.lang.Record
fr.fidorial.world.block.BlockPlaceContext
Record Components:
pos - the position the block is placed at
clickedFace - the face of the neighbouring block the player clicked
placer - the location and orientation of the player
world - read access to the surrounding blocks
cursorY - the height of the click on the clicked face, from 0 to 1

public record BlockPlaceContext(BlockPos pos, BlockFace clickedFace, Location placer, BlockGetter world, float cursorY) extends Record
Where and how a player is placing a block, handed to BlockBehaviour.placementState(BlockPlaceContext).
Since:
0.1.0
  • Constructor Details

    • BlockPlaceContext

      public BlockPlaceContext(BlockPos pos, BlockFace clickedFace, Location placer, BlockGetter world, float cursorY)
      Creates an instance of a BlockPlaceContext record class.
      Parameters:
      pos - the value for the pos record component
      clickedFace - the value for the clickedFace record component
      placer - the value for the placer record component
      world - the value for the world record component
      cursorY - the value for the cursorY record component
  • Method Details

    • horizontalFacing

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

      public 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

      public 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

      public @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

      public @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
    • intoWater

      public 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
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • pos

      public BlockPos pos()
      Returns the value of the pos record component.
      Returns:
      the value of the pos record component
    • clickedFace

      public BlockFace clickedFace()
      Returns the value of the clickedFace record component.
      Returns:
      the value of the clickedFace record component
    • placer

      public Location placer()
      Returns the value of the placer record component.
      Returns:
      the value of the placer record component
    • world

      public BlockGetter world()
      Returns the value of the world record component.
      Returns:
      the value of the world record component
    • cursorY

      public float cursorY()
      Returns the value of the cursorY record component.
      Returns:
      the value of the cursorY record component