User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:blockappearance

Manipulating a Block's appearance

This is the 1.15+ (1.16, 1.17, 1.18, and 1.19 work fine too) version of this tutorial. For the 1.14 version, see Manipulating a Block's appearance (1.14).

Making a block transparent

You may have noticed that even if your block's texture is transparent, 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:

public class ExampleModClient implements ClientModInitializer() {
    public void onInitializeClient() {
         BlockRenderLayerMap.INSTANCE.putBlock(ExampleMod.MY_BLOCK, RenderLayer.getCutout());
         // Replace `RenderLayer.getCutout()` with `RenderLayer.getTranslucent()` if you have a translucent texture.
    }
}

You probably also want to make your block transparent. To do that, use the nonOpaque method on your block settings.

     public static final Block MY_BLOCK = new Block(FabricBlockSettings.of(...).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": [
      "mod.fabricmc.examplemod.ExampleMod"
    ],
    "client": [
      "mod.fabricmc.examplemod.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.

Making a block invisible

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 then 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();
    }

tutorial/blockappearance.txt · Last modified: 2022/12/16 02:21 by solidblock