I'm currently updating my mod from 1.18, which previously allowed players to define the spawn weight of my custom entity for any biome via .TOML config files. This was done by subscribing to BiomeLoadingEvent and adding to the spawn list. That event has now been removed in favor of the new data-driven system, which I am still trying to fully grasp.
My current idea is to hook into GatherDataEvent and iterate through the list of user-defined biomes from the config, but the issue is that the configs aren't loaded at this stage, and runData crashes because the ForgeConfigSpec isn't initialized yet.
Here's what I currently have:
@SubscribeEvent
public static void gatherData(GatherDataEvent event)
{
DataGenerator generator = event.getGenerator();
ExistingFileHelper helper = event.getExistingFileHelper();
RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, RegistryAccess.builtinCopy());
<...>
EntityType<ChameleonEntity> chameleon = EntityInit.CHAMELEON.get();
ConfigSettings.CHAMELEON_BIOMES.get().forEach((biomeID, weight) ->
{
ForgeRegistries.BIOMES.getHolder(biomeID).ifPresent(biomeHolder ->
{
modifiers.put(new ResourceLocation(ColdSweat.MOD_ID, "chameleon_spawns_" + biomeID.getNamespace() + "_" + biomeID.getPath()),
ForgeBiomeModifiers.AddSpawnsBiomeModifier.singleSpawn(HolderSet.direct(biomeHolder), new MobSpawnSettings.SpawnerData(chameleon, weight, 1, 1)));
});
});
JsonCodecProvider<BiomeModifier> jsonCodecProvider = JsonCodecProvider.forDatapackRegistry(generator, helper, ColdSweat.MOD_ID, registryOps, ForgeRegistries.Keys.BIOME_MODIFIERS, modifiers);
generator.addProvider(event.includeServer(), jsonCodecProvider);
}
And here's the code on GitHub: https://github.com/Momo-Studios/Cold-Sweat/blob/1.19.x-FG/src/main/java/dev/momostudios/coldsweat/data/ColdSweatData.java
Is there a way to access the configs at this stage, or should I be using another way? I'd highly prefer using the configs since they're simpler to edit for users.