Skip to content

DM-Earth/DeferredRegistries

Repository files navigation

Deferred Registries

Deferred Registries

This Minecraft mod provides a way to register things that are not available at the time of registration, which is similar to how Minecraft Forge's DeferredRegister works.

Setup

repositories {
 // [...]
 maven {
  name = "Modrinth"
  url = "https://api.modrinth.com/maven"
  content {
   includeGroup "maven.modrinth"
  }
 }
}

dependencies {
 // [...]
 modImplementation include("maven.modrinth:deferred-registries:<version_id>")
}

Usage

First, create a DeferredRegistries object, here we use Item as example:

private static final DeferredRegistries<Item> ITEMS = DeferredRegistries.create(Registry.ITEM, "example_mod");

Then, register things to it:

public static final DeferredObject<Item> EXAMPLE_ITEM = ITEMS.register("example_item", () -> new Item(new Item.Settings()));
public static final DeferredObject<Item> SIMPLE_ITEM = ITEMS.register("simple_item", new Item(new Item.Settings()));

Finally, register the DeferredRegistries object when initializing your mod:

@Override
public void onInitialize() {
    ITEMS.register();
}