Skip to main content

Block entities

danger

Some errors might be present in the code above due to some methods ore classes not existing yet! Don't worry, those errors will go away once we create those classes and methods.

I did not make ImplementedInventory.java, the proper credits are in the class itself.

Before we can create our block entity, we need to first make 2 'helper' classes, ModBlockEntities and a little helper class ImplementedInventory.

public class ModBlockEntities {

public static final BlockEntityType<ExampleBlockEntity> EXAMPLE_BLOCK_ENTITY =
Registry.register(Registries.BLOCK_ENTITY_TYPE, Identifier.of(ExampleMod.MOD_ID, "example_be"),
BlockEntityType.Builder.create(ExampleBlockEntity::new,
ModBlocks.EXAMPLE_BLOCK).build());

public static void registerBlockEntities() {
Main.LOGGER.info("Registering Block Entities for " + Main.MOD_ID);
}
}

Now we can make a block entity with 2, 3 or 4 possible outputs.