-
Notifications
You must be signed in to change notification settings - Fork 20
Creating a block
mineLdiver edited this page Jul 26, 2023
·
4 revisions
Similar to creating an item, we can use BlockRegistryEvent
and Template*
classes to register our modded blocks.
public class MyBlocks {
@Entrypoint.ModID
final ModID modId = Null.get();
public static BlockBase myBlock;
@EventListener
void registerBlocks(BlockRegistryEvent event) {
myBlock = new TemplateBlockBase(modId.id("my_block"), Material.STONE);
}
}
And, again, similar to items, we can set custom block properties, like so:
myBlock = new TemplateBlockBase(modId.id("my_block"), Material.STONE).setHardness(1.5F).setTranslationKey(modId, "myBlock");
Translation keys for blocks are defined like this:
en_US.lang
tile.myBlock.name=My Block
Minecraft doesn't automatically handle all registered blocks as items that you can keep in your inventory, drop on ground, etc.
But it does automatically register a block item for blocks registered at a very specific point in code, and BlockRegistryEvent
is dispatched right in time for this, so you don't need to do anything.
However, if you wish to disable this behavior, you can call .disableAutomaticBlockItemRegistration()
on your block, similar to other properties above.