How to generate ore in the world (Minecraft mod)
On 1.18 and newer, ore generation is two data files plus one hook. The configured feature (type minecraft:ore) says which block replaces which blocks and how big a vein is. The placed feature says how many veins per chunk and between which heights. The hook adds the placed feature to biomes: a biome modifier file of type neoforge:add_features (forge:add_features on Forge) on NeoForge and Forge, BiomeModifications.addFeature on Fabric. On 1.16.5 and 1.12.2 it is done in code instead. New ore only appears in chunks made after the mod is added.
Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.18 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.
- Write the configured feature with your block and the vein size.
- Write the placed feature with the count per chunk and the height range.
- Add it to biomes: JSON on NeoForge and Forge, one call on Fabric.
- Create a new world and fly through the caves.
What you can change
Section titled “What you can change”The example uses these values. Change them in the code.
| Setting | In the example | What it does |
|---|---|---|
| block | minecraft:emerald_ore |
The block the vein is made of (it must exist). |
| size | 6 |
Blocks per vein (iron is 9, diamond 4). |
| veins | 8 |
Veins per chunk. |
| miny | -60 |
Lowest height. |
| maxy | 60 |
Highest height. |
For each loader and version
Section titled “For each loader and version”The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.
Fabric 1.19.3 to 1.20.6
Section titled “Fabric 1.19.3 to 1.20.6”Uses:
BiomeModifications.addFeatureGenerationStep.Decoration.UNDERGROUND_ORESRegistries.PLACED_FEATUREminecraft:ore
src/main/resources/data/examplemod/worldgen/configured_feature/ruby_ore.json
{ "type": "minecraft:ore", "config": { "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": { "Name": "minecraft:emerald_ore" }, "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ] }}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/java/com/example/examplemod/world/RubyOreGen.java
package com.example.examplemod.world;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceKey;import net.minecraft.resources.ResourceLocation;import net.minecraft.world.level.levelgen.GenerationStep;import net.minecraft.world.level.levelgen.placement.PlacedFeature;
// Adds the placed feature examplemod:ruby_ore (the ore veins) to every overworld biome, in the underground ores step.public final class RubyOreGen { private RubyOreGen() { }
// Called from the mod's onInitialize. public static void register() { ResourceKey<PlacedFeature> feature = ResourceKey.create(Registries.PLACED_FEATURE, new ResourceLocation("examplemod", "ruby_ore")); BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Decoration.UNDERGROUND_ORES, feature); }}In your main mod class, inside onInitialize:
RubyOreGen.register();Fabric 1.21 to 1.21.1
Section titled “Fabric 1.21 to 1.21.1”Uses:
BiomeModifications.addFeatureGenerationStep.Decoration.UNDERGROUND_ORESRegistries.PLACED_FEATUREminecraft:ore
src/main/resources/data/examplemod/worldgen/configured_feature/ruby_ore.json
{ "type": "minecraft:ore", "config": { "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": { "Name": "minecraft:emerald_ore" }, "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ] }}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/java/com/example/examplemod/world/RubyOreGen.java
package com.example.examplemod.world;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceKey;import net.minecraft.resources.ResourceLocation;import net.minecraft.world.level.levelgen.GenerationStep;import net.minecraft.world.level.levelgen.placement.PlacedFeature;
// Adds the placed feature examplemod:ruby_ore (the ore veins) to every overworld biome, in the underground ores step.public final class RubyOreGen { private RubyOreGen() { }
// Called from the mod's onInitialize. public static void register() { ResourceKey<PlacedFeature> feature = ResourceKey.create(Registries.PLACED_FEATURE, ResourceLocation.fromNamespaceAndPath("examplemod", "ruby_ore")); BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Decoration.UNDERGROUND_ORES, feature); }}In your main mod class, inside onInitialize:
RubyOreGen.register();NeoForge 1.20.1 to 1.21.1, NeoForge 1.21.2 to 26.2
Section titled “NeoForge 1.20.1 to 1.21.1, NeoForge 1.21.2 to 26.2”Uses:
neoforge:add_featuresminecraft:oreminecraft:height_range
src/main/resources/data/examplemod/worldgen/configured_feature/ruby_ore.json
{ "type": "minecraft:ore", "config": { "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": { "Name": "minecraft:emerald_ore" }, "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ] }}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/resources/data/examplemod/neoforge/biome_modifier/ruby_ore.json
{ "type": "neoforge:add_features", "biomes": "#minecraft:is_overworld", "features": "examplemod:ruby_ore", "step": "underground_ores"}Fabric 1.21.2 to 1.21.10
Section titled “Fabric 1.21.2 to 1.21.10”Uses:
BiomeModifications.addFeatureGenerationStep.Decoration.UNDERGROUND_ORESRegistries.PLACED_FEATUREminecraft:ore
src/main/resources/data/examplemod/worldgen/configured_feature/ruby_ore.json
{ "type": "minecraft:ore", "config": { "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": { "Name": "minecraft:emerald_ore" }, "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ] }}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/java/com/example/examplemod/world/RubyOreGen.java
package com.example.examplemod.world;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceKey;import net.minecraft.resources.ResourceLocation;import net.minecraft.world.level.levelgen.GenerationStep;import net.minecraft.world.level.levelgen.placement.PlacedFeature;
// Adds the placed feature examplemod:ruby_ore (the ore veins) to every overworld biome, in the underground ores step.public final class RubyOreGen { private RubyOreGen() { }
// Called from the mod's onInitialize. public static void register() { ResourceKey<PlacedFeature> feature = ResourceKey.create(Registries.PLACED_FEATURE, ResourceLocation.fromNamespaceAndPath("examplemod", "ruby_ore")); BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Decoration.UNDERGROUND_ORES, feature); }}In your main mod class, inside onInitialize:
RubyOreGen.register();NeoForge 26.3
Section titled “NeoForge 26.3”Uses:
neoforge:add_featuresminecraft:oreminecraft:height_range
From 26.3 the configured feature file goes in data/<mod id>/worldgen/feature/ (it was worldgen/configured_feature/ before), and its fields sit at the top level with no “config” object; a target state is written as the block id.
src/main/resources/data/examplemod/worldgen/feature/ruby_ore.json
{ "type": "minecraft:ore", "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": "minecraft:emerald_ore", "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ]}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/resources/data/examplemod/neoforge/biome_modifier/ruby_ore.json
{ "type": "neoforge:add_features", "biomes": "#minecraft:is_overworld", "features": "examplemod:ruby_ore", "step": "underground_ores"}Fabric 1.21.11 to 26.2
Section titled “Fabric 1.21.11 to 26.2”Uses:
BiomeModifications.addFeatureGenerationStep.Decoration.UNDERGROUND_ORESRegistries.PLACED_FEATUREminecraft:ore
src/main/resources/data/examplemod/worldgen/configured_feature/ruby_ore.json
{ "type": "minecraft:ore", "config": { "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": { "Name": "minecraft:emerald_ore" }, "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ] }}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/java/com/example/examplemod/world/RubyOreGen.java
package com.example.examplemod.world;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceKey;import net.minecraft.resources.Identifier;import net.minecraft.world.level.levelgen.GenerationStep;import net.minecraft.world.level.levelgen.placement.PlacedFeature;
// Adds the placed feature examplemod:ruby_ore (the ore veins) to every overworld biome, in the underground ores step.public final class RubyOreGen { private RubyOreGen() { }
// Called from the mod's onInitialize. public static void register() { ResourceKey<PlacedFeature> feature = ResourceKey.create(Registries.PLACED_FEATURE, Identifier.fromNamespaceAndPath("examplemod", "ruby_ore")); BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Decoration.UNDERGROUND_ORES, feature); }}In your main mod class, inside onInitialize:
RubyOreGen.register();Fabric 26.3
Section titled “Fabric 26.3”Uses:
BiomeModifications.addFeatureGenerationStep.Decoration.UNDERGROUND_ORESRegistries.PLACED_FEATUREminecraft:ore
From 26.3 the configured feature file goes in data/<mod id>/worldgen/feature/ (it was worldgen/configured_feature/ before), and its fields sit at the top level with no “config” object; a target state is written as the block id.
src/main/resources/data/examplemod/worldgen/feature/ruby_ore.json
{ "type": "minecraft:ore", "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": "minecraft:emerald_ore", "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ]}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/java/com/example/examplemod/world/RubyOreGen.java
package com.example.examplemod.world;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceKey;import net.minecraft.resources.Identifier;import net.minecraft.world.level.levelgen.GenerationStep;import net.minecraft.world.level.levelgen.placement.PlacedFeature;
// Adds the placed feature examplemod:ruby_ore (the ore veins) to every overworld biome, in the underground ores step.public final class RubyOreGen { private RubyOreGen() { }
// Called from the mod's onInitialize. public static void register() { ResourceKey<PlacedFeature> feature = ResourceKey.create(Registries.PLACED_FEATURE, Identifier.fromNamespaceAndPath("examplemod", "ruby_ore")); BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Decoration.UNDERGROUND_ORES, feature); }}In your main mod class, inside onInitialize:
RubyOreGen.register();Forge 1.17.1 to 1.20.1
Section titled “Forge 1.17.1 to 1.20.1”Uses:
neoforge:add_featuresminecraft:oreminecraft:height_range
src/main/resources/data/examplemod/worldgen/configured_feature/ruby_ore.json
{ "type": "minecraft:ore", "config": { "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": { "Name": "minecraft:emerald_ore" }, "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ] }}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/resources/data/examplemod/forge/biome_modifier/ruby_ore.json
{ "type": "forge:add_features", "biomes": "#minecraft:is_overworld", "features": "examplemod:ruby_ore", "step": "underground_ores"}Fabric 1.18 to 1.19.2
Section titled “Fabric 1.18 to 1.19.2”Uses:
BiomeModifications.addFeatureGenerationStep.Decoration.UNDERGROUND_ORESRegistries.PLACED_FEATUREminecraft:ore
src/main/resources/data/examplemod/worldgen/configured_feature/ruby_ore.json
{ "type": "minecraft:ore", "config": { "discard_chance_on_air_exposure": 0.0, "size": 6, "targets": [ { "state": { "Name": "minecraft:emerald_ore" }, "target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" } } ] }}src/main/resources/data/examplemod/worldgen/placed_feature/ruby_ore.json
{ "feature": "examplemod:ruby_ore", "placement": [ { "type": "minecraft:count", "count": 8 }, { "type": "minecraft:in_square" }, { "type": "minecraft:height_range", "height": { "type": "minecraft:uniform", "min_inclusive": { "absolute": -60 }, "max_inclusive": { "absolute": 60 } } }, { "type": "minecraft:biome" } ]}src/main/java/com/example/examplemod/world/RubyOreGen.java
package com.example.examplemod.world;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;import net.minecraft.core.Registry;import net.minecraft.resources.ResourceKey;import net.minecraft.resources.ResourceLocation;import net.minecraft.world.level.levelgen.GenerationStep;import net.minecraft.world.level.levelgen.placement.PlacedFeature;
// Adds the placed feature examplemod:ruby_ore (the ore veins) to every overworld biome, in the underground ores step.public final class RubyOreGen { private RubyOreGen() { }
// Called from the mod's onInitialize. public static void register() { ResourceKey<PlacedFeature> feature = ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, new ResourceLocation("examplemod", "ruby_ore")); BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Decoration.UNDERGROUND_ORES, feature); }}In your main mod class, inside onInitialize:
RubyOreGen.register();Forge 1.16.5
Section titled “Forge 1.16.5”Uses:
BiomeLoadingEvent.getGenerationFeature.OREOreFeatureConfigPlacement.RANGEWorldGenRegistries.CONFIGURED_FEATURE
1.16.5 has no placed features or biome modifier files: the ore is a ConfiguredFeature built in code (heights are 0 to 255 here).
src/main/java/com/example/examplemod/worldgen/RubyOreOreGen.java
package com.example.examplemod.worldgen;
import com.example.examplemod.ExampleMod;import net.minecraft.util.ResourceLocation;import net.minecraft.util.registry.Registry;import net.minecraft.world.biome.Biome;import net.minecraft.world.gen.GenerationStage;import net.minecraft.world.gen.feature.ConfiguredFeature;import net.minecraft.world.gen.feature.Feature;import net.minecraft.world.gen.feature.OreFeatureConfig;import net.minecraft.world.gen.placement.Placement;import net.minecraft.world.gen.placement.TopSolidRangeConfig;import net.minecraft.util.registry.WorldGenRegistries;import net.minecraftforge.common.MinecraftForge;import net.minecraftforge.event.world.BiomeLoadingEvent;import net.minecraftforge.eventbus.api.EventPriority;import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;import net.minecraftforge.registries.ForgeRegistries;
// Ruby Ore: veins of minecraft:emerald_ore, 6 blocks each, 8 per chunk between y -60 and 60. 1.16.5 has no world generation data files: the feature is built in code and added to every overworld biome as it loads.public final class RubyOreOreGen { private static ConfiguredFeature<?, ?> feature;
private RubyOreOreGen() { }
// Called from the mod's constructor. public static void register() { FMLJavaModLoadingContext.get().getModEventBus().addListener(RubyOreOreGen::onCommonSetup); MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, RubyOreOreGen::onBiomeLoading); }
// A feature has to be in the configured feature registry too, or the world cannot save it. private static void onCommonSetup(FMLCommonSetupEvent event) { event.enqueueWork(() -> { feature = Feature.ORE.configured(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, ForgeRegistries.BLOCKS.getValue(new ResourceLocation("minecraft:emerald_ore")).defaultBlockState(), 6)) .decorated(Placement.RANGE.configured(new TopSolidRangeConfig(Math.max(0, -60), 0, Math.min(255, 60)))) .squared().count(8); Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, new ResourceLocation(ExampleMod.MOD_ID, "ruby_ore"), feature); }); }
private static void onBiomeLoading(BiomeLoadingEvent event) { if (feature != null && event.getCategory() != Biome.Category.NETHER && event.getCategory() != Biome.Category.THEEND) { event.getGeneration().addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, feature); } }}In your main mod class, inside <init>:
RubyOreOreGen.register();Forge 1.12.2
Section titled “Forge 1.12.2”Uses:
BiomeLoadingEvent.getGenerationFeature.OREOreFeatureConfigPlacement.RANGEWorldGenRegistries.CONFIGURED_FEATURE
1.12.2 has no world generation data files: an IWorldGenerator registered with GameRegistry.registerWorldGenerator adds veins to every new chunk (the example uses WorldGenMinable).
src/main/java/com/example/examplemod/worldgen/RubyOreOreGen.java
package com.example.examplemod.worldgen;
import java.util.Random;import net.minecraft.block.Block;import net.minecraft.util.ResourceLocation;import net.minecraft.util.math.BlockPos;import net.minecraft.world.World;import net.minecraft.world.chunk.IChunkProvider;import net.minecraft.world.gen.IChunkGenerator;import net.minecraft.world.gen.feature.WorldGenMinable;import net.minecraftforge.fml.common.IWorldGenerator;import net.minecraftforge.fml.common.registry.ForgeRegistries;import net.minecraftforge.fml.common.registry.GameRegistry;
// Ruby Ore: veins of minecraft:emerald_ore, 6 blocks each, 8 per chunk between y -60 and 60. 1.12.2 has no world generation data files: an IWorldGenerator runs for every new chunk.public final class RubyOreOreGen implements IWorldGenerator { // Called from preInit. public static void register() { GameRegistry.registerWorldGenerator(new RubyOreOreGen(), 0); }
@Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator generator, IChunkProvider provider) { if (world.provider.getDimension() != 0) { return; } Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("minecraft:emerald_ore")); WorldGenMinable vein = new WorldGenMinable(block.getDefaultState(), 6); int low = Math.max(1, -60); int high = Math.min(255, 60); for (int i = 0; i < 8; i++) { vein.generate(world, random, new BlockPos(chunkX * 16 + random.nextInt(16), low + random.nextInt(Math.max(1, high - low)), chunkZ * 16 + random.nextInt(16))); } }}In your main mod class, inside preInit:
RubyOreOreGen.register();Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/events
- https://docs.neoforged.net/docs/1.21.1/worldgen/biomemodifier
- https://docs.neoforged.net/docs/1.21.1/worldgen/
- https://maven.fabricmc.net/docs/fabric-api-0.116.17+1.21.1/net/fabricmc/fabric/api/biome/v1/BiomeModifications.html
Related how-tos
Section titled “Related how-tos”- A new dimension
- Define a new biome
- Make a mob spawn in the world
- A new enchantment
- Add an advancement
In Linen
Section titled “In Linen”Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.