-
Notifications
You must be signed in to change notification settings - Fork 7
Registrar
The registrar allows you to manually add and edit datapack registries before Minecraft loads them.
To get started, find your quilt.mod.json and add the following to your entrypoints block:
"entrypoints": {
"limlib:registrar": "net.myname.modid.MyRegistrar"
}
Of course, replace the entry with the actual path to your class.
At that class, it should look something like this:
public class MyRegistrar implements LimlibRegistrar {
@Override
public void registerHooks() {
}
}
Register hooks?! What's a hook?! Good question hypothetical audience member. In this method, you can add a 'hook' to modify a registry. For example, if you had some biomes you wanted to register outside of using json, heres what that might look like.
public class MyRegistrar implements LimlibRegistrar {
@Override
public void registerHooks() {
LimlibRegistryHooks.hook(RegistryKeys.BIOME, (infoLookup, registryKey, registry) -> {
HolderProvider<PlacedFeature> features = infoLookup.lookup(RegistryKeys.PLACED_FEATURE).get().getter();
HolderProvider<ConfiguredCarver<?>> carvers = infoLookup.lookup(RegistryKeys.CONFIGURED_CARVER).get().getter();
registry.register(MyBiomes.MY_BIOME, MyBiome.create(features, carvers), Lifecycle.stable());
});
}
}
This LimlibRegistryHooks#hook
method takes in two parameters: The registry key of the registry you want to modify; then The actual hook. This hook has three parameters: first The registry lookup of everything vanilla's registered in code; The registry key you're hooking into; and The actual registry itself. Note that this is called after that registry is filled up.
Now say you want to be a little mischievous? And edit a registry as its being read! Well, look no further!~ You can use a different kind of hook to change a jsonElement as its being read from the loaded datapacks. Here's an example for changing every biomes' sky color to be red.
LimlibRegistryHooks.hook(RegistryKeys.BIOME, (infoLookup, registryKey, registryOps, jsonElement) -> {
if (jsonElement.getAsJsonObject().has("effects")) {
JsonObject effects = jsonElement.getAsJsonObject().get("effects").getAsJsonObject();
effects.addProperty("sky_color", 16711684);
}
});
This hook has four parameters: first The registry lookup of everything vanilla's registered in code; The registry key you're hooking into; the registryOps (useful for messing with codec); and the actual jsonElement you wish to modify.