Interface BlockState


public interface BlockState
A block state is a block and all its properties when placed in a world. This implementation of block states is rather simple and abstract, in order to remain as independent as possible from any actual implementation.

A block state is an immutable object that contains the identifier of the base block, as well as its properties and their values.

  • Method Details

    • getBlock

      Identifier getBlock()
      Returns:
      the identifier of the base block of that state
    • getProperty

      BlockPropertyValue getProperty(String property)
      Gets the value of a given property of this state.
      Parameters:
      property - the name of the property to get
      Returns:
      the property's value, or null if it doesn't have the given property
    • hasProperty

      boolean hasProperty(String property)
      Tests whether this state has a given property set.
      Parameters:
      property - the property name
      Returns:
      true if the state has the given property set, false otherwise
    • withProperty

      BlockState withProperty(String property, String value)
      Gets a copy of this block state, with the given property applied.
      Parameters:
      property - the name of the property to add or change
      value - the value for the property
      Returns:
      the resulting block state
    • withProperty

      BlockState withProperty(String property, int value)
      Gets a copy of this block state, with the given property applied.
      Parameters:
      property - the name of the property to add or change
      value - the value for the property
      Returns:
      the resulting block state
    • withProperty

      BlockState withProperty(String property, boolean value)
      Gets a copy of this block state, with the given property applied.
      Parameters:
      property - the name of the property to add or change
      value - the value for the property
      Returns:
      the resulting block state
    • getProperties

      Map<String,BlockPropertyValue> getProperties()
      Gets the properties of this state as a read only map.
      Returns:
      the map of properties names and values for this state
    • getPreviewColor

      default int getPreviewColor()
      Returns:
      a color that describes this state, to use when rendering a mpa, for example
    • parse

      static BlockState parse(@NotNull @NotNull String string)
      Parses a serialized BlockState from a String.
      Parameters:
      string - a serialized BlockState as it would be used in Minecraft commands
      Returns:
      the parsed BlockState
      Throws:
      IllegalArgumentException - if the supplied String is not a valid serialied BlockState