Package org.moddingx.libx.mod
Class ModXRegistration
java.lang.Object
org.moddingx.libx.mod.ModX
org.moddingx.libx.mod.ModXRegistration
You need to extend this instead of
ModX if you want to use the LibX registration system.
This works like this:
You define your objects for registration in classes like ModItems. Create some static methods
there that register all the items. To register something you need to call
register(ResourceKey, String, Object).
Then in the constructor of your mod class, you call addRegistrationHandler(Runnable) for every
registration method with a method reference to it. (Example: addRegistrationHandler(ModItems::init).
The handlers will get called in the order you added them.
This system has several advantages over the one recommended by neoforge:
- An object can have dependencies that are automatically registered with it. This is done with
the
Registerableinterface. For exampleBlockBEregisters ablock, anitemfor the block and ablock entity type. You could even go further with it and automatically register slabs, stairs, walls and doors for all of your decorative blocks. - You don't need the
.get()when you want to access a registration object
holders. However, this will only work for vanilla registries
that support holder creation prior to registering the item.-
Field Summary
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSubclasses should provide a public no-arg constructor that calls this with the values needed. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddRegistrationHandler(Runnable handler) Adds a registration handler that runs during the registry phase.protected voidinitRegistration(RegistrationBuilder builder) Initialises the registration system.final <T> voidregister(net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registry, String id, T value) Registers an object to a given registry using a given name as the path part of the objects id.Methods inherited from class org.moddingx.libx.mod.ModX
clientSetup, resource, setup
-
Constructor Details
-
ModXRegistration
protected ModXRegistration()Subclasses should provide a public no-arg constructor that calls this with the values needed.
-
-
Method Details
-
initRegistration
Initialises the registration system. SeeRegistrationBuilderfor more information. -
addRegistrationHandler
Adds a registration handler that runs during the registry phase. -
register
public final <T> void register(@Nullable net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<T>> registry, String id, T value) Registers an object to a given registry using a given name as the path part of the objects id. Theregistryparameter may benullto allow registeringregisterablesthat shouldn't go into any specific registry.
-