This is the 1.15+ version of this tutorial. For the 1.14 version, see Manipulating a Block's appearance (1.14).
You may have noticed that even if your block's texture is transparent or translucent, it still looks opaque. To fix this, you need to set your block's render layer to cutout or transparent.
In a client-sided mod initializer:
@Environment(EnvType.CLIENT) public class ExampleModClient implements ClientModInitializer() { public void onInitializeClient() { // To make some parts of the block transparent (like glass, saplings and doors): BlockRenderLayerMap.INSTANCE.putBlock(TutorialBlocks.MY_BLOCK, RenderLayer.getCutout()); // To make some parts of the block translucent (like ice, stained glass and portal) BlockRenderLayerMap.INSTANCE.putBlock(TutorialBlocks.MY_BLOCK, RenderLayer.getTranslucent()); } }
You probably also want to make your block non-opaque. To do that, use the nonOpaque
method on your block settings. This will also make sides render inside.
public static final Block MY_BLOCK = new Block(AbstractBlock.Settings.create().nonOpaque());
If you do not mark your block as non-opaque like this, then block faces behind the block will not render and you will be able to see through the world.
Be sure to add your client entrypoint to fabric.mod.json. You can do this like so:
{ [...] "entrypoints": { "main": [ "net.fabricmc.example.ExampleMod" ], "client": [ "net.fabricmc.example.ExampleModClient" ] }, [...] }
Note: For non-transparent blocks that are not full, you may have to override the getOutlineShape
method to return a non-full shape to avoid seeing through the world.
First we need to make the block appear invisible. To do this, we override getRenderType
in our block class and return BlockRenderType.INVISIBLE
:
@Override public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.INVISIBLE; }
We may also need to make our block unselectable by making its outline shape be non-existent. So override getOutlineShape
and return an empty VoxelShape
:
@Override public VoxelShape getOutlineShape(BlockState state, BlockView blockView, BlockPos pos, ShapeContext context) { return VoxelShapes.empty(); }