Adding World Presets [1.19.2 AND BELOW]
A WorldPreset
is a wrapper class around a ChunkGenerator
that allows you to create a world with a preconfigured chunk generator. The preset is shown on the “More World Options” screen, on the “World Type” button. The vanilla world presets are Default, Large Biomes, AMPLIFIED, Single Biome, Superflat, and Debug Mode.
In this tutorial, we will add a simple world preset which generates nothing in a world.
Creating a World Preset
A world preset requires a ChunkGenerator
. You can create your own1), but here, we will modify the FlatChunkGenerator
to create a void world.
In order to implement a preset, we first need access to the WorldPresets$Registrar
inner class. For that, we can use a simple access widener. This could be done without an access widener, but it is much simpler to use one in this case. Your access widener should look like this:
accessWidener v1 named accessible class net/minecraft/world/gen/WorldPresets$Registrar
Don't forget to add the neccessary entries to your fabric.mod.json and build.gradle files!
Once we have access to the Registrar
class, the preset can be implemented in one mixin:
// if you can't mixin here, make sure your access widener is set up correctly! @Mixin(WorldPresets.Registrar.class) public abstract class WorldPresetMixin { // defining our registry key. this key provides an Identifier for our preset, that we can use for our lang files and data elements. private static final RegistryKey<WorldPreset> VOID_WORLD = RegistryKey.of(Registry.WORLD_PRESET_KEY, new Identifier("wiki-example", "void_world")); @Shadow protected abstract RegistryEntry<WorldPreset> register(RegistryKey<WorldPreset> key, DimensionOptions dimensionOptions); @Shadow protected abstract DimensionOptions createOverworldOptions(ChunkGenerator chunkGenerator); @Inject(method = "initAndGetDefault", at = @At("RETURN")) private void addPresets(CallbackInfoReturnable<RegistryEntry<WorldPreset>> cir) { // the register() method is shadowed from the target class this.register(VOID_WORLD, this.createOverworldOptions( // a FlatChunkGenerator is the easiest way to get a void world, but you can replace this FlatChunkGenerator constructor with a NoiseChunkGenerator, or your own custom ChunkGenerator. new FlatChunkGenerator( // passing null will use the default structure set null, new FlatChunkGeneratorConfig( // we don't need to overwrite the structure set Optional.empty(), BuiltinRegistries.BIOME) ) ) ); } }
Don't forget to add the mixin to your mixins.json
file!
Our preset is registered, but if you load up the game, nothing will show up in the menu. This is because the presets that are actually displayed in the More World Options menu are controlled via tags.
In order for the preset to show up, we'll need to add it to the normal
WorldPreset tag. Create a new file in your resources directory, at src/main/resources/data/minecraft/tags/worldgen/world_preset
called normal.json
. Note that the tag is stored under the minecraft
namespace, not your mod's.
{ "replace": false, "values": [ "wiki-example:void_world" ] }
And, of course, you'll probably want a translation file. I'm using English, so my lang file will be at src/main/resources/assets/wiki-example/lang/en_us.json
:
{ "generator.wiki-example.void_world": "Nothing but Void" }
And you're done!