Interface FabricBlockView


public interface FabricBlockView
General-purpose Fabric-provided extensions for BlockView subclasses.

These extensions were designed primarily for use by methods invoked during chunk building, but they can also be used in other contexts.

Note: This interface is automatically implemented on all BlockView instances via Mixin and interface injection.

  • Method Summary

    Modifier and Type
    Method
    Description
    default @UnknownNullability RegistryEntry<Biome>
    Retrieves the biome at the given position if biome retrieval is supported.
    default @Nullable Object
    Retrieves block entity render data for a given block position.
    default boolean
    Checks whether biome retrieval is supported.
  • Method Details

    • getBlockEntityRenderData

      @Nullable default @Nullable Object getBlockEntityRenderData(BlockPos pos)
      Retrieves block entity render data for a given block position.

      This method must be used instead of BlockView.getBlockEntity(BlockPos) in cases where the user knows that the current context may be multithreaded, such as chunk building, to ensure thread safety and data consistency. Using a BlockEntity directly may not be thread-safe since it may lead to non-atomic modification of the internal state of the BlockEntity (such as through lazy computation). Using a BlockEntity directly may not be consistent since the internal state of the BlockEntity may change on a different thread.

      As previously stated, a common environment to use this method in is chunk building. Methods that are invoked during chunk building and that thus should use this method include, but are not limited to, FabricBakedModel#emitBlockQuads (block models), BlockColorProvider#getColor (block color providers), and FabricBlock#getAppearance (block appearance computation).

      Users of this method are required to check the returned object before using it. Users must check if it is null and if it is of the correct type to avoid null pointer and class cast exceptions, as the returned data is not guaranteed to be what the user expects. A simple way to implement these checks is to use instanceof, since it always returns false if the object is null. If the instanceof returns false, a fallback path should be used.

      Parameters:
      pos - the position of the block entity
      Returns:
      the render data provided by the block entity, or null if there is no block entity at this position
      See Also:
    • hasBiomes

      default boolean hasBiomes()
      Checks whether biome retrieval is supported. The returned value will not change between multiple calls of this method. See getBiomeFabric(BlockPos) for more information.
      Returns:
      whether biome retrieval is supported
      See Also:
    • getBiomeFabric

      default @UnknownNullability RegistryEntry<Biome> getBiomeFabric(BlockPos pos)
      Retrieves the biome at the given position if biome retrieval is supported. If hasBiomes() returns true, this method will always return a non-null RegistryEntry whose value is non-null. If hasBiomes() returns false, this method will always return null.

      Prefer using WorldView.getBiome(BlockPos) instead of this method if this instance is known to implement WorldView.

      Parameters:
      pos - the position for which to retrieve the biome
      Returns:
      the biome, or null if biome retrieval is not supported
      See Also:
      Implementation Note:
      Implementations which do not return null are encouraged to use the plains biome as the default value, for example when the biome at the given position is unknown.