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 with 2 different methods. The best options for this are:

  • Iterate over the biome registry
  • Mixin into DefaultBiomeFeatures#addDefaultOres
  • Use a library that provides utilities for adding ores, such as Cotton, which won't be covered here

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.

Iterating Biome Registry

All we do here is iterate over the biome registry and add our ore to each biome sometime during the initialization phase. We can filter the biome to make sure our ore is placed in appropriate areas:

  1. @Override
  2. public void onInitialize()
  3. {
  4. Registry.BIOME.stream()
  5. .filter(biome -> biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND)
  6. .forEach(biome ->
  7. biome.addFeature(
  8. GenerationStep.Feature.UNDERGROUND_ORES,
  9. Biome.configureFeature(
  10. Feature.ORE,
  11. new OreFeatureConfig(
  12. OreFeatureConfig.Target.NATURAL_STONE,
  13. Blocks.NETHER_QUARTZ_ORE.getDefaultState(),
  14. 8
  15. ),
  16. Decorator.COUNT_RANGE,
  17. new RangeDecoratorConfig(
  18. 8,
  19. 0,
  20. 0,
  21. 64
  22. )
  23. )
  24. ));
  25. }

We're forcing the ore on each biome that the filter finds.

Mixin into DefaultBiomeFeatures

Create a mixin class in your mixin folder, and register it to your mixins.json file. We'll be injecting into the head of addDefaultOres, and copying the existing implementation to add our custom ore:

  1. @Mixin(DefaultBiomeFeatures.class)
  2. public class OreMixin
  3. {
  4. @Inject(at = @At("HEAD"), method = "addDefaultOres")
  5. private static void addDefaultOres(final Biome biome, final CallbackInfo info)
  6. {
  7. biome.addFeature(
  8. GenerationStep.Feature.UNDERGROUND_ORES,
  9. Biome.configureFeature(
  10. Feature.ORE,
  11. new OreFeatureConfig(
  12. OreFeatureConfig.Target.NATURAL_STONE,
  13. Blocks.NETHER_QUARTZ_ORE.getDefaultState(),
  14. 8
  15. ),
  16. Decorator.COUNT_RANGE,
  17. new RangeDecoratorConfig(
  18. 8,
  19. 0,
  20. 0,
  21. 64
  22. )
  23. )
  24. );
  25. }
  26. }

In this mixin, we add an ore feature to each biome that calls the method. The vein is up to 8 blocks large, spawns up to 8 times per chunk, and spawns under y64. It overrides all natural stone types and uses the default decorator to decide where ores should go.

Conclusion

Regardless of which method you use, you should see quartz ore spawning in the overworld:

Quartz Ores

tutorial/ores.1562186223.txt.gz · Last modified: 2019/07/03 20:37 by draylar