User Tools

Site Tools


tutorial:ores

This is an old revision of the document!


Adding Ores to the World

A lot of mods add their own ores, and you'll need a way to place them in existing biomes for players to find. In this tutorial, we'll look at adding ores to existing biomes and biomes added by other mods. There are 2 steps that are required to add ores to biomes.

  • Iterate over the biome registry to add your ores to existing biomes.
  • Use the RegistryEntryAddedCallback to ensure your ore gets added into any biomes added by mods.

We'll assume you've already created your own ore block at this point. Quartz Ore will serve as our replacement, and our goal will be spawning it in overworld biomes. Replace references to Quartz Ore with your ore when appropriate.

Adding ores to a biome

First we need to create a method to process a biome, checking if it is a valid biome then adding the ore.

  1. private void handleBiome(Biome biome) {
  2. if(biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND) {
  3. biome.addFeature(
  4. GenerationStep.Feature.UNDERGROUND_ORES,
  5. Biome.configureFeature(
  6. Feature.ORE,
  7. new OreFeatureConfig(
  8. OreFeatureConfig.Target.NATURAL_STONE,
  9. Blocks.NETHER_QUARTZ_ORE.getDefaultState(),
  10. 8 //Ore vein size
  11. ),
  12. Decorator.COUNT_RANGE,
  13. new RangeDecoratorConfig(
  14. 8, //Number of veins per chunk
  15. 0, //Bottom Offset
  16. 0, //Min y level
  17. 64 //Max y level
  18. )));
  19. }
  20. }

This method adds your ore to the overworld, with the provided spawn settings. Feel free to change the values to suit your mod.

Iterating Biome Registry

What we need to do next is process all biomes that have been registered as well as all biomes that will be registered in the future (as added by other mods). We first iterate over the current registry, then register a listener that will be called for future additions.

  1. @Override
  2. public void onInitialize() {
  3. //Loop over existing biomes
  4. Registry.BIOME.forEach(this::handleBiome);
  5.  
  6. //Listen for other biomes being registered
  7. RegistryEntryAddedCallback.event(Registry.BIOME).register((i, identifier, biome) -> handleBiome(biome));
  8. }

Conclusion

You should see quartz ore spawning in the overworld:

Quartz Ores

tutorial/ores.1566243397.txt.gz · Last modified: 2019/08/19 19:36 by jamieswhiteshirt