Skip to content

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).

  1. Create class ModRegistriesInit.java (in package registry)
    • 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 RegistryHelper
    public static final RegistryHelper REGISTRY_HELPER = new RegistryHelper("your_mod_id");
    // declare init method
    public static void init() {
    // we will be putting stuff here...
    }
    // and register method
    public static void register(IEventBus bus) {
    REGISTRY_HELPER.register(bus); // IMPORTANT!
    }
    }
  2. 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 IEventBus
    IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
    // IMPORTANT!
    ModRegistriesInit.register(eventBus); // register the registries
    // ...
    }
    }
  3. 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”
IRegistryHelper.java
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);
}
  1. Create class ModItems.java
    • Directorylibs/
      • …
    • 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 CoreTabs
    import dev.tauri.jsgcore.common.registry.helper.builder.item.ItemRegistryHelperGeneric;
    import dev.tauri.jsgcore.common.registry.helper.RegistryObjectWrapper;
    public class ModItems {
    // create item registry helper
    public static final ItemRegistryHelperGeneric ITEM_HELPER = new ItemRegistryHelperGeneric(ModRegistriesInit.REGISTRY_HELPER::item);
    // register your item
    public 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 tooltip
    public static final RegistryObjectWrapper<JSGItem> ITEM_WITHOUT_TOOLTIP = ITEM_HELPER.builder("item_without_tooltip").clearTooltip().buildGeneric();
    // item inside core tab
    public 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.java
    public static void init() {}
    }
  2. Update your ModRegistriesInit.java
    • Directorylibs/
      • …
    • 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
    }
    // ...
    }
  1. Create class ModBlocks.java
    • Directorylibs/
      • …
    • 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 CoreTabs
    import 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 helper
    public static final BlockRegistryHelperGeneric BLOCK_HELPER = new BlockRegistryHelperGeneric(ModRegistriesInit.REGISTRY_HELPER::block);
    // register your block
    public static final RegistryObjectWrapper<Block> MY_AWESOME_BLOCK = BLOCK_HELPER.builder("my_awesome_block").buildGeneric();
    // this method will be called from the init() in ModRegistriesInit.java
    public static void init() {}
    }
  2. Update your ModRegistriesInit.java
    • Directorylibs/
      • …
    • 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
    }
    // ...
    }