Repository navigation
Registries
Neoloxal edited this page Sep 5, 2026
·
8 revisions
This library adds two basic registries.
- Create a new child class of
ItemRegistrar.
public class ModItems extends ItemRegistrar {
// You can replace mod with your modid.
public ModItems(String modid) {
super(modid);
}
@Override
protected void registerItems() {
// register your items here.
}
}- Create your items class.
@Mod(PaintPaletteExampleMod.MODID)
public class PaintPaletteExampleMod {
public static final String MODID = "paint_palette_example_mod";
private static final Logger LOGGER = LogUtils.getLogger();
private static final ItemRegistrar MOD_ITEMS = new ModItems(MODID);and then in your mod constructor:
public PaintPaletteExampleMod(IEventBus modEventBus, ModContainer modContainer) {
MOD_ITEMS.register(modEventBus);
}You can place these methods in your registerItems() method.
| Method | Function |
|---|---|
basicItem(name, supplier) |
Returns a DeferredItem<T extends Item>
|
funnyStick(name, supplier) |
Returns a <DeferredItem<T extends FunnyStick>>
|
conditionalItem(run, supplier) |
Returns an Optional<DeferredItem<T extends Item>> if run is true. |
To access your registered item call, getItem(name) where the name is the name you registered the item with.
- Create a new child class of
BlockRegistrar.
public class ModBlocks extends BlockRegistrar {
public ModBlocks(String modid, ItemRegistrar itemRegistrar) {
// You can replace these with your existing values.
super(modid, itemRegistrar);
}
@Override
protected void registerBlocks() {
// Register your blocks here.
}
}- Create your blocks class.
@Mod(PaintPaletteExampleMod.MODID)
public class PaintPaletteExampleMod {
public static final String MODID = "paint_palette_example_mod";
private static final Logger LOGGER = LogUtils.getLogger();
private static final ItemRegistrar MOD_ITEMS = new ModItems(MODID);
private static final BlockRegistrar MOD_BLOCKS = new ModBlocks(MODID, MOD_ITEMS);and then in your mod constructor:
public PaintPaletteExampleMod(IEventBus modEventBus, ModContainer modContainer) {
MOD_ITEMS.register(modEventBus);
MOD_BLOCKS.register(modEventBus);
}You can place the following methods in your registerBlocks() method.
| Method | Function |
|---|---|
basicBlock(name, supplier, registerItem = true) |
Returns a DeferredBlock<T extends Block> with an item if register item is true. |
conditionalBlock(run, supplier) |
Returns an Optional<DeferredBlock<T extends Block>>, the optional will be empty if run is false. |
To access your registered block, call getBlock(name) where the name is the name you registered the item with.