Interface FabricBlock


public interface FabricBlock
General-purpose Fabric-provided extensions for Block subclasses.

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

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Fabric-provided extensions for BlockBehaviour.Properties.
  • Method Summary

    Modifier and Type
    Method
    Description
    default net.minecraft.world.level.block.state.BlockState
    getAppearance(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.BlockAndLightGetter blockAndLightGetter, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, @Nullable net.minecraft.world.level.block.state.BlockState sourceState, @Nullable net.minecraft.core.BlockPos sourcePos)
    Return the current appearance of the block, i.e.
  • Method Details

    • getAppearance

      default net.minecraft.world.level.block.state.BlockState getAppearance(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.BlockAndLightGetter blockAndLightGetter, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, @Nullable net.minecraft.world.level.block.state.BlockState sourceState, @Nullable net.minecraft.core.BlockPos sourcePos)
      Return the current appearance of the block, i.e. which block state this block reports to look like on a given side.

      Common implementors are covers and facades, or any other mimic blocks that proxy another block's model. These will want to override this method. In that case, make sure to carefully read the implementation guidelines below.

      Common consumers are models with connected textures that wish to seamlessly connect to mimic blocks. These will want to check the apparent block state using FabricBlockState.getAppearance(BlockAndLightGetter, BlockPos, Direction, BlockState, BlockPos).

      Generally, the appearance will be queried from a nearby block, identified by the optional sourcePos and sourceState parameters.

      When a block changes appearance, it should trigger a chunk remesh for itself and the adjacent blocks, for example by calling Level.sendBlockUpdated(BlockPos, BlockState, BlockState, int).

      Note: Overriding this method for a block does not change how it renders. It's up to modded models to check for the appearance of nearby blocks and adjust accordingly.

      Implementation guidelines

      This can be called on the server, where block entity data can be safely accessed, and on the client, possibly in a meshing thread, where block entity data is not safe to access! Here is an example of how data from a block entity can be handled safely. The block entity should override RenderDataBlockEntity#getBlockEntityRenderData to return the necessary data. Refer to the documentation of RenderDataBlockEntity for more information.

      @Override
      public BlockState getAppearance(BlockState state, BlockAndTintGetter blockAndTintGetter, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) {
          if (blockAndTintGetter instanceof ServerLevel serverLevel) {
              // Server side; ok to use block entity directly!
              BlockEntity blockEntity = serverLevel.getBlockEntity(pos);
      
              if (blockEntity instanceof ...) {
                  // Get data from block entity
                  return ...;
              }
          } else {
              // Client side; need to use the block entity render data!
              Object data = blockAndTintGetter.getBlockEntityRenderData(pos);
      
              // Check if data is not null and of the correct type, and use that to determine the appearance
              if (data instanceof ...) {
                  // get appearance for side ...
                  return ...;
              }
          }
      
          // Example of varying the appearance based on the source pos
          if (sourcePos != null) {
              // get appearance for side ...
              return ...;
          }
      
          // If there is no other appearance, just return the original block state
          return state;
      });
      
      Parameters:
      state - state of this block, whose appearance is being queried
      blockAndLightGetter - the level this block is in
      pos - position of this block, whose appearance is being queried
      side - the side for which the appearance is being queried
      sourceState - (optional) state of the block that is querying the appearance, or null if unknown
      sourcePos - (optional) position of the block that is querying the appearance, or null if unknown
      Returns:
      the appearance of the block on the given side; the original state can be returned if there is no better option