tutorial:chunkgenerator
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tutorial:chunkgenerator [2022/09/07 04:20] – created draft version, github repo coming soon miir | tutorial:chunkgenerator [2025/02/08 20:28] (current) – adds note to use Registries.CHUNK_GENERATOR on 1.19.3 and above 3xpl0173d | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Custom Chunk Generators | + | ===== Custom Chunk Generators ===== |
| '' | '' | ||
| Line 14: | Line 14: | ||
| <code java> | <code java> | ||
| public class ExampleChunkGenerator extends ChunkGenerator { | public class ExampleChunkGenerator extends ChunkGenerator { | ||
| - | /* this is a very important field, we will come back to the codec later | + | /* this is a very important field, we will come back to the codec later */ |
| public static final Codec< | public static final Codec< | ||
| Line 52: | Line 52: | ||
| /* this method builds the shape of the terrain. it places stone everywhere, which will later be overwritten with grass, terracotta, snow, sand, etc | /* this method builds the shape of the terrain. it places stone everywhere, which will later be overwritten with grass, terracotta, snow, sand, etc | ||
| - | by the buildSurface method. it also is responsible for putting the water in oceans. */ | + | by the buildSurface method. it also is responsible for putting the water in oceans. it returns a CompletableFuture-- you'll likely want this to be delegated to worker threads. */ |
| @Override | @Override | ||
| public CompletableFuture< | public CompletableFuture< | ||
| Line 97: | Line 97: | ||
| ==== Registering and Codecs ==== | ==== Registering and Codecs ==== | ||
| - | Like other features in the game, '' | + | Like other features in the game, '' |
| + | <code java> | ||
| + | public static final Codec< | ||
| + | instance.group( | ||
| + | BiomeSource.CODEC.fieldOf(" | ||
| + | Codec.INT.fieldOf(" | ||
| + | Codec.INT.fieldOf(" | ||
| + | Identifier.fieldOf(" | ||
| + | ).apply(instance, | ||
| + | </ | ||
| + | Each line in the codec corresponds to a different field in your chunk generator that should be configurable. In this example, I pass a '' | ||
| + | |||
| + | To use the fields properly, you have to add them, along with getters, into your class: | ||
| + | |||
| + | <code java> | ||
| + | private final BiomeSource biomeSource; | ||
| + | public BiomeSource getBiomeSource() { | ||
| + | return this.biomeSource; | ||
| + | } | ||
| + | private final int seaLevel; | ||
| + | public int getSeaLevel() { | ||
| + | return this.seaLevel; | ||
| + | } | ||
| + | // and the same for the other fields | ||
| + | </ | ||
| + | |||
| + | and then, create a constructor for your generator that uses each of those fields **in the same order that you listed them in the codec**: | ||
| + | <code java> | ||
| + | public ExampleChunkGenerator(BiomeSource biomeSource, | ||
| + | super(biomeSource); | ||
| + | this.seaLevel = seaLevel; | ||
| + | this.worldHeight = worldHeight; | ||
| + | this.customBlock = Registries.BLOCK.getOrThrow(RegistryKey.of(RegistryKeys.BLOCK, | ||
| + | this.customBlockID = customBlockID; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | Then, all that's left is to register your chunk generator. Put the following line into your mod initializer '' | ||
| <code java> | <code java> | ||
| Registry.register(Registry.CHUNK_GENERATOR, | Registry.register(Registry.CHUNK_GENERATOR, | ||
| + | </ | ||
| + | //* For Minecraft Versions 1.19.3 and above, use '' | ||
| + | // | ||
| + | |||
| + | Now, you can create json files to use your new chunk generator: | ||
| + | <code json> | ||
| + | // resources/ | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| </ | </ | ||
| And you're done! If you want to use your new generator, it might be helpful to wrap it with a [[tutorial: | And you're done! If you want to use your new generator, it might be helpful to wrap it with a [[tutorial: | ||
tutorial/chunkgenerator.1662524423.txt.gz · Last modified: 2022/09/07 04:20 by miir