Interface FabricBlock
Block
subclasses.
Note: This interface is automatically implemented on all blocks via Mixin and interface injection.
-
Method Summary
Modifier and TypeMethodDescriptiondefault net.minecraft.block.BlockState
getAppearance
(net.minecraft.block.BlockState state, net.minecraft.world.BlockRenderView renderView, net.minecraft.util.math.BlockPos pos, net.minecraft.util.math.Direction side, @Nullable net.minecraft.block.BlockState sourceState, @Nullable net.minecraft.util.math.BlockPos sourcePos) Return the current appearance of the block, i.e.
-
Method Details
-
getAppearance
default net.minecraft.block.BlockState getAppearance(net.minecraft.block.BlockState state, net.minecraft.world.BlockRenderView renderView, net.minecraft.util.math.BlockPos pos, net.minecraft.util.math.Direction side, @Nullable @Nullable net.minecraft.block.BlockState sourceState, @Nullable @Nullable net.minecraft.util.math.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(net.minecraft.world.BlockRenderView, net.minecraft.util.math.BlockPos, net.minecraft.util.math.Direction, net.minecraft.block.BlockState, net.minecraft.util.math.BlockPos)
.Generally, the appearance will be queried from a nearby block, identified by the optional
sourcePos
andsourceState
parameters.When a block changes appearance, it should trigger a chunk remesh for itself and the adjacent blocks, for example by calling
World.updateListeners(net.minecraft.util.math.BlockPos, net.minecraft.block.BlockState, net.minecraft.block.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 needs to implement
RenderAttachmentBlockEntity
for this to work.@Override public BlockState getAppearance(BlockState state, BlockRenderView renderView, BlockPos pos, Direction side, @Nullable BlockState sourceState, @Nullable BlockPos sourcePos) { if (renderView instanceof ServerWorld serverWorld) { // Server side, ok to use block entity directly! BlockEntity blockEntity = serverWorld.getBlockEntity(pos); if (blockEntity instanceof ...) { // Get data from block entity return ...; } } else { // Client side, need to use the render attachment! RenderAttachedBlockView attachmentView = (RenderAttachedBlockView) renderView; Object data = attachmentView.getBlockEntityRenderAttachment(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 queriedrenderView
- the world this block is inpos
- position of this block, whose appearance is being queriedside
- the side for which the appearance is being queriedsourceState
- (optional) state of the block that is querying the appearance, or null if unknownsourcePos
- (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
-