Registry helper
Registry helper is a class that is responsible of holding registries and helping developer handle some of the registrations (Menu types for example).
- Create class
ModRegistriesInit.java(in packageregistry)Directorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModRegistriesInit.java
- ExampleMod.java
- …
ModRegistriesInit.java import dev.tauri.jsgcore.common.registry.helper.RegistryHelper;import net.minecraftforge.eventbus.api.IEventBus;public class ModRegistriesInit {// create a constant object of the RegistryHelperpublic static final RegistryHelper REGISTRY_HELPER = new RegistryHelper("your_mod_id");// declare init methodpublic static void init() {// we will be putting stuff here...}// and register methodpublic static void register(IEventBus bus) {REGISTRY_HELPER.register(bus); // IMPORTANT!}} - Inside your main class update the constructor:
Directorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModRegistriesInit.java
- ExampleMod.java
- …
ExampleMod.java @Mod("your_mod_id")public class ExampleMod implements JSGAddon {public ExampleMod(){// ...ModRegistriesInit.init(); // inicialize the registries (load all constants etc.)// ...some other registrations and stuff// if you don't have already one, get the IEventBusIEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();// IMPORTANT!ModRegistriesInit.register(eventBus); // register the registries// ...}} - Now you have set up a registry helper for your mod!
- Create class
ModRegistriesInit.java(in packageregistry)Directorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModRegistriesInit.java
- ExampleMod.java
- …
ModRegistriesInit.java import dev.tauri.jsgcore.common.registry.helper.RegistryHelper;import net.neoforged.bus.api.IEventBus;public class ModRegistriesInit {// create a constant object of the RegistryHelperpublic static final RegistryHelper REGISTRY_HELPER = new RegistryHelper("your_mod_id");// declare init methodpublic static void init() {// we will be putting stuff here...}// and register methodpublic static void register(IEventBus bus) {REGISTRY_HELPER.register(bus); // IMPORTANT!}} - Inside your main class update the constructor:
Directorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModRegistriesInit.java
- ExampleMod.java
- …
ExampleMod.java @Mod("your_mod_id")public class ExampleMod implements JSGAddon {public ExampleMod(IEventBus eventBus){// ...ModRegistriesInit.init(); // inicialize the registries (load all constants etc.)// ...some other registrations and stuff// IMPORTANT!ModRegistriesInit.register(eventBus); // register the registries// ...}} - Now you have set up a registry helper for your mod!
List of methods inside the RegistryHelper class
Section titled “List of methods inside the RegistryHelper class”package dev.tauri.jsgcore.common.registry.helper;
/** * Helper class that helps creating and registering deferred registers */public interface IRegistryHelper { /** * Registers all created deferred registers to the mod event bus * @param eventBus the mod's event bus */ void register(IEventBus eventBus);
/** * Append the deferredRegister to the list of registers that will be registered to the bus * @param deferredRegister the register to register */ void toRegister(DeferredRegisterWrapper<?> deferredRegister);
/** * Runnable that will run when binding menus to GUIs * @param runnable the runnable to run * @return self */ RegistryHelper guiRegister(Runnable runnable);
/** * Runnable that will run when binding entities with their renderers * @param runnable the runnable to run * @return self */ RegistryHelper entityRendererRegister(Runnable runnable);
/** * Runnable that will run when binding block entities with their renderers * @param supplier list of bind BE to renderer * @return self */ RegistryHelper beRenderers(Supplier<List<RegistryHelper.BlockEntityRendererPair<?>>> supplier);
/** * Creates a new DeferredRegister object of type FluidType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<FluidType> fluidType();
/** * Creates a new DeferredRegister object of type Fluid, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<Fluid> fluid();
/** * Creates a new DeferredRegister object of type PoiType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<PoiType> poi();
/** * Creates a new DeferredRegister object of type VillagerType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<VillagerType> villagerType();
/** * Creates a new DeferredRegister object of type VillagerProfession, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<VillagerProfession> villagerProfession();
/** * Creates a new DeferredRegister object of type EntityType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<EntityType<?>> entity();
/** * Creates a new DeferredRegister object of type StructureType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<StructureType<?>> structureType();
/** * Creates a new DeferredRegister object of type Feature, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<Feature<?>> feature();
/** * Creates a new DeferredRegister object of type MenuType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<MenuType<?>> menu();
/** * Creates a new DeferredRegister object of type StateType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<StateType> state();
/** * Creates a new DeferredRegister object of type SymbolUsage, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<SymbolUsage> symbolUsage();
/** * Creates a new DeferredRegister object of type SymbolType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<SymbolType<?>> symbolType();
/** * Creates a new DeferredRegister object of type SoundEvent, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<SoundEvent> sound();
/** * Creates a new DeferredRegister object of type CreativeModeTab, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<CreativeModeTab> tab();
/** * Creates a new DeferredRegister object of type BlockEntityType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<BlockEntityType<?>> be();
/** * Creates a new DeferredRegister object of type Block, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<Block> block();
/** * Creates a new DeferredRegister object of type Item, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<Item> item();
/** * Creates a new DeferredRegister object of type ScheduledTaskType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<ScheduledTaskType> scheduledTask();
/** * Creates a new DeferredRegister object of type BiomeOverlayInstance, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<BiomeOverlayInstance> biomeOverlay();
/** * Creates a new DeferredRegister object of type NotebookPageType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<NotebookPageType<?>> notebookPage();
/** * Creates a new DeferredRegister object of type IPointOfOriginType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<IPointOfOriginType> pooType();
/** * Creates a new DeferredRegister object of type Raycaster, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<Raycaster> raycaster();
/** * Creates a new DeferredRegister object of type RecipeType, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<RecipeType<?>> recipeType();
/** * Creates a new DeferredRegister object of type RecipeSerializer, if not created already. * @return the created/already present register */ DeferredRegisterWrapper<RecipeSerializer<?>> recipeSerializer();
/** * Creates a new DeferredRegister object of type you like, if not created already. * @return the created/already present register */ <B> DeferredRegisterWrapper<B> other(IForgeRegistry<B> registry);}Registering an item
Section titled “Registering an item”- Create class
ModItems.javaDirectorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModItems.java
- ModRegistriesInit.java
- ExampleMod.java
- …
ModItems.java import dev.tauri.jsgcore.common.item.JSGItem;import dev.tauri.jsgcore.common.registry.CoreTabs; // only needed when using CoreTabsimport dev.tauri.jsgcore.common.registry.helper.builder.item.ItemRegistryHelperGeneric;import dev.tauri.jsgcore.common.registry.helper.RegistryObjectWrapper;public class ModItems {// create item registry helperpublic static final ItemRegistryHelperGeneric ITEM_HELPER = new ItemRegistryHelperGeneric(ModRegistriesInit.REGISTRY_HELPER::item);// register your itempublic static final RegistryObjectWrapper<JSGItem> MY_AWESOME_ITEM = ITEM_HELPER.builder("my_awesome_item").buildGeneric();// register more items...public static final RegistryObjectWrapper<JSGItem> ANOTHER_COOL_ITEM = ITEM_HELPER.builder("another_cool_item").buildGeneric();// item without generic tooltippublic static final RegistryObjectWrapper<JSGItem> ITEM_WITHOUT_TOOLTIP = ITEM_HELPER.builder("item_without_tooltip").clearTooltip().buildGeneric();// item inside core tabpublic static final RegistryObjectWrapper<JSGItem> ITEM_IN_TAB = ITEM_HELPER.builder("item_in_tab").setInTabs(List.of(CoreTabs.TAB_RESOURCES)).buildGeneric();// this method will be called from the init() in ModRegistriesInit.javapublic static void init() {}} - Update your
ModRegistriesInit.javaDirectorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModItems.java
- ModRegistriesInit.java
- ExampleMod.java
- …
ModRegistriesInit.java public class ModRegistriesInit {// ...public static void init() {// ...ModItems.init(); // init the mod items}// ...}
Registering a block
Section titled “Registering a block”- Create class
ModBlocks.javaDirectorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModBlocks.java
- ModRegistriesInit.java
- ExampleMod.java
- …
ModBlocks.java import dev.tauri.jsgcore.common.registry.CoreTabs; // only needed when using CoreTabsimport dev.tauri.jsgcore.common.registry.helper.builder.block.BlockRegistryHelperGeneric;import dev.tauri.jsgcore.common.registry.helper.RegistryObjectWrapper;import net.minecraft.world.level.block.Block;public class ModBlocks {// create block registry helperpublic static final BlockRegistryHelperGeneric BLOCK_HELPER = new BlockRegistryHelperGeneric(ModRegistriesInit.REGISTRY_HELPER::block);// register your blockpublic static final RegistryObjectWrapper<Block> MY_AWESOME_BLOCK = BLOCK_HELPER.builder("my_awesome_block").buildGeneric();// this method will be called from the init() in ModRegistriesInit.javapublic static void init() {}} - Update your
ModRegistriesInit.javaDirectorylibs/
- …
Directorysrc/main/java/your/namespace/yourmodid/
Directorycommon/
Directoryregistry/
- ModBlocks.java
- ModRegistriesInit.java
- ExampleMod.java
- …
ModRegistriesInit.java public class ModRegistriesInit {// ...public static void init() {// ...ModBlocks.init(); // init the mod blocks}// ...}