Content Guides

Block Entities

Registering Block Entities

Block entities can be registered using a BalmBlockEntityTypeRegistrar.

public class ModBlockEntities {

    public static Holder<BlockEntityType<YourBlockEntity>> yourBlockEntity;

    public static void initialize(BalmBlockEntityTypeRegistrar blockEntities) {
        yourBlockEntity = blockEntities.register("your_block_entity", YourBlockEntity::new, ModBlocks.yourBlock).asHolder();
    }
}

You can obtain a BalmBlockEntityTypeRegistrar through the BalmRegistrars instance passed to your mod initializer, or by registering your mod as a BalmModule.

Using an Initializer

public class YourMod {

    public static void initialize(BalmRegistrars registrars) {
        registrars.blockEntityTypes(ModBlockEntities::initialize);
    }

}

Using BalmModule

public class YourMod implements BalmModule {

    @Override
    public void registerBlockEntityTypes(BalmBlockEntityTypeRegistrar blockEntities) {
        ModBlockEntities.initialize(blockEntities);
    }

}

Using the Block Entity

We're storing Holder<BlockEntityType<?>> instead of BlockEntityType<?> to account for delayed registration on some mod loaders.

You can resolve the block entity type using ModBlockEntities.yourBlockEntity.value().

Do not try to store BlockEntityType<?> instances in your ModBlockEntities class by using asHolder().value() in your registration code, as that is too early to access the resolved block entity type on NeoForge and Forge.Store a Holder<BlockEntityType<?>> instance instead and only resolve it once you truly need a BlockEntityType<?> instance.