In order to create a <code>BlockEntity</code> you need to extend the <code>BlockEntity</code> class. To register it, listen for the appropriate registry event and create a <code>BlockEntityType</code>:
−
<syntaxhighlight lang="java">
−
@SubscribeEvent
−
public static void registerTE(RegistryEvent.Register<BlockEntityType<?>> evt) {
−
BlockEntityType<?> type = BlockEntityType.Builder.of(supplier, validBlocks).build(null);
−
type.setRegistryName("examplemod", "mybe");
−
evt.getRegistry().register(type);
−
}
−
</syntaxhighlight>
You can also use a <code>DeferredRegister</code> instead.
You can also use a <code>DeferredRegister</code> instead.