====== Manipulating a Block's appearance ======
//This is the 1.15+ version of this tutorial. For the 1.14 version, see [[tutorial:1.14:blockappearance|Manipulating a Block's appearance (1.14)]].//
===== Making a block transparent or translucent =====
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 [[documentation:entrypoint|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, class_1921.method_23581());
// To make some parts of the block translucent (like ice, stained glass and portal)
BlockRenderLayerMap.INSTANCE.putBlock(TutorialBlocks.MY_BLOCK, class_1921.method_23583());
}
}
You probably also want to make your block non-opaque. To do that, use the '''' method on your block settings. This will also make sides render inside.
public static final Block MY_BLOCK = new Block(AbstractBlock.Settings.create().method_22488());
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 [[documentation:fabric_mod_json|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 '''' method to return a non-full shape to avoid seeing through the world.
===== Making a block invisible =====
First we need to make the block appear invisible. To do this, we override '''' in our block class and return ''.'':
@Override
public class_2464 method_9604(class_2680 state) {
return class_2464.field_11455;
}
We may also need to make our block unselectable by making its outline shape be non-existent. So override '''' and return an empty '''':
@Override
public class_265 method_9530(class_2680 state, class_1922 blockView, class_2338 pos, class_3726 context) {
return class_259.method_1073();
}