A powerful wrapper for creating and registering objects in your mod.
- Allows you to organize your mod content however you like, rather than having pieces of each object defined in scattered places
- Simple fluent API
- Open to extension, build and register custom objects and data
- Automatic data generation with sane defaults
- Shadeable, contains no mod, only code
First, create a Registrate
object which will be used across your entire project.
public static final Registrate REGISTRATE = Registrate.create(MOD_ID);
Using a constant field is not necessary, it can be passed around and thrown away after registration is setup.
If declared static in your @Mod
class, you must create the Registrate
object lazily so it is not created too early during loading. This can be done easily like so:
public static final NonNullSupplier<Registrate> REGISTRATE = NonNullSupplier.lazy(() -> Registrate.create(MOD_ID));
Next, begin adding objects.
If you have a block class such as
public class MyBlock extends Block {
public MyBlock(Block.Properties properties) {
super(properties);
}
...
}
then register it like so,
public static final RegistryEntry<MyBlock> MY_BLOCK = REGISTRATE.block("my_block", MyBlock::new).register();
Registrate will create a block, with a default simple blockstate, model, loot table, and lang entry. However, all of these facets can be configured easily to use whatever custom data you may want. Example:
public static final RegistryEntry<MyStairsBlock> MY_STAIRS = REGISTRATE.block("my_block", MyStairsBlock::new)
.defaultItem()
.tag(BlockTags.STAIRS)
.blockstate(ctx -> ctx.getProvider()
.stairsBlock(ctx.getEntry(), ctx.getProvider().modLoc(ctx.getName())))
.lang("Special Stairs")
.register();
This customized version will create a BlockItem (with its own default model and lang entry), add the block to a tag, configure the blockstate for stair properties, and add a custom localization.
To get an overview of the different APIs and methods, check out the Javadocs. For more advanced usage, read the wiki (WIP).
Registrate can be installed in the mods folder as a typical dependency, but since it does not have a mod, it can also be shaded. Shading is the recommended way to include Registrate (at least until Forge jar-in-jar is working again).
This is easiest with the Gradle Shadow plugin. Add the plugin to your buildscript like so:
plugins {
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
Note: Shadow 5.1+ requires Gradle 5.x. I recommend 5.6 as I know this version works with both Shadow and FG3.
Once you have the plugin, it needs to be configured. First add a shade configuration,
configurations {
shade
}
configure the shadowJar task use it, and repackage Registrate classes.
shadowJar {
configurations = [project.configurations.shade]
relocate 'com.tterrag.registrate', 'com.mymod.repack.registrate'
}
Then, make sure the shadow jar artifact is reobfuscated.
reobf {
shadowJar {}
}
Finally, the dependency itself must be added. First add my maven repository,
repositories {
maven { // Registrate
url "http://maven.tterrag.com/"
}
mavenLocal()
}
and then the Registrate dependency to the implementation and shade configurations.
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" // This should already be here
def registrate = "com.tterrag.registrate:Registrate:MC${minecraft_version}-${registrate_version}"
implementation fg.deobf(registrate)
shade registrate
}
To build the jar containing shaded dependencies, use the shadowJar
task, or configure the task to run automatically when using build
.
build.dependsOn shadowJar
build.dependsOn reobfShadowJar