Jump to content

[1.18.2] How can I refer to a datapack biome during Mod init?


NamelessDev

Recommended Posts

Using ForgeRegistries.Biomes, after adding a TOML dependency to load AFTER Terralith, I realized it is (according to the author) "a datapack wrapped as a mod."

I am guessing datapacks are only enabled at the start of a world as Terraliths biomes are not registered in the main menu at all.

My mod needs to clone and modify all biomes in a level. 

How can this be done?

Edited by NamelessDev
Link to comment
Share on other sites

This description is going to be very high level and gloss over many details:

Worlds (see WorldStem) are made up of dimensions/levels (see LevelStem).

Within the LevelStem is a ChunkGenerator that has BiomeSource. this is what determines which biomes are in a dimension.

If you look inside Terralith you will see it has a data/minecraft/dimension_type/overworld.json that is the configuration override for the vanilla overworld defined in the builtin registry.

See https://minecraft.fandom.com/wiki/Custom_dimension for the format.

It then defines a bunch of biomes jsons that are referenced in that overworld.json which will in turn reference other world gen components in the datapack. NOTE: This also includes tags to reference groups of biomes. See other pages on the same wiki for the formats.

 

As you have determined this data is not loaded until the world creation screen (or first server load). The process is to load copies of the builtin registries then override these objects with the datapacks. The worldgen data is then stored in the world's save folder. This datapack data for worldgen are not referenced again on subsequent loads. It is fixed at world creation.

 

I am not sure what you mean by "clone and modify" a biome.

You can modify a Biome using the BiomeLoadingEvent, but this won't make a new one. To do that you need to provide a new resource from a datapack.

 

One thing you are going to need to do is override terralith's overworld definition if you want new biomes in the overworld. This will likely involve you using the AddPackFindersEvent to add a new RepositorySource. This will define a pack at the "TOP" of the datapacks list (as seen from the create new world screen's datapacks button) which contains the new definition. It's a bit of a rabbit hole the way this works. 🙂

 

You might find a simpler solution is to just write your own datapack? Forge mods are datapacks so its an easy way to install them.

  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

15 hours ago, warjort said:

This description is going to be very high level and gloss over many details:

Worlds (see WorldStem) are made up of dimensions/levels (see LevelStem).

Within the LevelStem is a ChunkGenerator that has BiomeSource. this is what determines which biomes are in a dimension.

If you look inside Terralith you will see it has a data/minecraft/dimension_type/overworld.json that is the configuration override for the vanilla overworld defined in the builtin registry.

See https://minecraft.fandom.com/wiki/Custom_dimension for the format.

It then defines a bunch of biomes jsons that are referenced in that overworld.json which will in turn reference other world gen components in the datapack. NOTE: This also includes tags to reference groups of biomes. See other pages on the same wiki for the formats.

 

As you have determined this data is not loaded until the world creation screen (or first server load). The process is to load copies of the builtin registries then override these objects with the datapacks. The worldgen data is then stored in the world's save folder. This datapack data for worldgen are not referenced again on subsequent loads. It is fixed at world creation.

 

I am not sure what you mean by "clone and modify" a biome.

You can modify a Biome using the BiomeLoadingEvent, but this won't make a new one. To do that you need to provide a new resource from a datapack.

 

One thing you are going to need to do is override terralith's overworld definition if you want new biomes in the overworld. This will likely involve you using the AddPackFindersEvent to add a new RepositorySource. This will define a pack at the "TOP" of the datapacks list (as seen from the create new world screen's datapacks button) which contains the new definition. It's a bit of a rabbit hole the way this works. 🙂

 

You might find a simpler solution is to just write your own datapack? Forge mods are datapacks so its an easy way to install them.

This was an excellent answer. Thank you. 

I actually have a BiomeSource and ChunkGenerator. My mod is supposed to clone the overworld to another dimension. With vanilla, by listening for all available biomes at the start, I just get them, use BiomeBuilder to replace some of their settings, and register them as mine. During run time for world gen, I relay chunk generation to my cloned version of the vanilla ChunkGenerator which leads to an exact replica of the overworld, with a little bit of spooky environment added in.

The problem here of course is datapack biomes aren't registered the same way. Ideally, my mod would always clone your (the users) overworld. For my personal purposes, copy-pasting terralith is fine but... it leaves something to be desired from the mod itself.

Is there anyway I can get the datapack biomes on world creation and perform my cloning operation on them and then save them in the world as you mentioned?

Additionally, here is my working code:

 

 @Override
    public Holder<Biome> getNoiseBiome(int x, int y, int z, Climate.Sampler sampler) {
        var overworld = TUDChunkGenerator.GET_OVERWORLD_CHUNK_GEN().getBiomeSource().getNoiseBiome(x, y, z, sampler);

        var tud = Registration.TUD_BIOME_KEYS.get(overworld.value().getRegistryName().getPath());
        if(tud != null)
            return getBiomeRegistry().getHolderOrThrow(tud);
        else
            return overworld;
    }

While this works, as you can see, if it found a cloned biome, it uses the clone. If it did not (either because another mod loaded after it, or a datapack adds in data), it simply relays the overworld ChunkGenerator. This is not ideal and does not clone as well as it does when I have the biomes registered before hand.

I am open to alternative solutions, if needed.

Edited by NamelessDev
Link to comment
Share on other sites

The biomes and other worldgen can be found in MinecraftServer.registryAccess().

You can't add to these registries after loading, they are frozen. I don't know why you want to?

The objects are already clones of the builtin registry objects or made from "whole cloth" and are specific to that world save.

Like I said above, there is a way to modify biomes during loading - BiomeLoadingEvent.

 

If you have your own ChunkGenerator then you can make your own BiomeSource to choose which biomes to use.

  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.