Skip to main content

World Gen

Since 1.16, the way minecraft handles world generation has been shifting towards being based on json files in data packs rather than making you write code. Eventually I'd like to write my own tutorials on this but for now I'll try to collect a list of resources made by people that understand it much better than me.

If you have questions specificlly about how world gen works, the Minecraft Worldgen Discord Server might have someone who can help.

MC Wiki​

Author: TelepathicGrunt​

  • Create a new structure that generates in the world. Uses jigsaw so you can make kinda dynamic structures built out of many parts like how villages work.
  • Add new buildings to villages. Adds new piece to a pool of a jigsaw structure so similar would work for bastions, woodland mansions and many modded structures. Note: You will still need to add a jigsaw block to your nbt structure piece so that it can connect to the other pieces and spawn. For example, adding to village's houses pool means you need a jigsaw block with "minecraft:building_entrance" in the Name field and the jigsaw block is facing outward towards the street on the bottom edge of the piece.
  • Add modded crop blocks to village farms. This method can stack with other people attempting to do the same. This works by adding a new processer to the structure piece that randomly replaces some wheat blocks. You could do other block replaces in other structures with the same technique.
  • Example of a surface builder class The way they work is their method is ran for every x/z position in the biome. The idea is that you simply loop from the top terrain height (startHeight) to y = 0 and replace the first few blocks of every surface you meet along the way. Of course, you may want to add noise or change the behavior of the surfacebuilder completely. Register the surfacebuilder to the surface builder registry to be able to either configured it with json files for json biomes. Or you could configure it in code, register it to WorldGenRegisteries.CONFIGURED_SURFACE_BUILDER, and then add it to your coded biome.
  • Ore generation
public static ConfiguredFeature<?,?> CONFIGURED_COAL_ORE;

// register to the Mod event bus
public static void commonSetup(FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
// the OreFeatureConfig.FillerBlockType tells it which types of blocks its allowed to replace
CONFIGURED_COAL_ORE = Feature.ORE.configured(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, Blocks.COAL_ORE.getDefaultState(), 17)).range(128).squared().count(20)

Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, new ResourceLocation(StructureTutorialMain.MODID, "coal_ore"), CONFIGURED_COAL_ORE);
}
}

// register to the Forge event bus
public void biomeModification(final BiomeLoadingEvent event) {
event.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES).add(() -> CONFIGURED_COAL_ORE);
}

Author: Commoble​

Author: gigaherz​

  • Brief example of how to make your entity spawn in certain biomes
@SubscribeEvent
public static void biomeLoading(final BiomeLoadingEvent event){
RegistryKey<Biome> biomeRegistryKey = RegistryKey.getOrCreateKey(Registry.BIOME_KEY, event.getName());
if (isBiomeAllowed(biomeRegistryKey)){
MobSpawnInfo.Spawners spawn = new MobSpawnInfo.Spawners(EntityInit.YOUR_ENTITY.get(), weight, minPackSize, maxPackSize);

event.getSpawns().withSpawner(CLASSIFICATION, spawn);
}
}