User Tools

Site Tools


tutorial:ores

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:ores [2019/07/03 20:37] draylartutorial:ores [2019/08/19 19:36] – [Adding ores to a biome] Enhancements jamieswhiteshirt
Line 1: Line 1:
 ====== Adding Ores to the World ====== ====== 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 methodsThe best options for this are: +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 modsThere are 2 steps that are required to add ores to biomes. 
-  * Iterate over the biome registry  +  * Iterate over the biome registry to add your ores to existing biomes. 
-  * Mixin into ''DefaultBiomeFeatures#addDefaultOres''  +  * Use the RegistryEntryAddedCallback to ensure your ore gets added into any biomes added by mods.
-  * Use a library that provides utilities for adding ores, such as [[https://github.com/CottonMC/cotton|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. 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 ==== +==== Adding ores to a biome ==== 
-All we do here is iterate over the biome registry and add our ore to each biome sometime during the initialization phaseWe can filter the biome to make sure our ore is placed in appropriate areas:+ 
 +First we need to create a method to process a biome, checking if it is a valid biome then adding the ore.
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-@Override +private void handleBiome(Biome biome) { 
-public void onInitialize() + if(biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND) { 
-+ biome.addFeature( 
-Registry.BIOME.stream(+             GenerationStep.Feature.UNDERGROUND_ORES, 
-    .filter(biome -> biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND) +             Biome.configureFeature( 
-    .forEach(biome -> +                 Feature.ORE, 
-        biome.addFeature( +         new OreFeatureConfig( 
-     GenerationStep.Feature.UNDERGROUND_ORES, +         OreFeatureConfig.Target.NATURAL_STONE, 
-     Biome.configureFeature( +         Blocks.NETHER_QUARTZ_ORE.getDefaultState(), 
-         Feature.ORE, +                 //Ore vein size 
- new OreFeatureConfig( +         ), 
- OreFeatureConfig.Target.NATURAL_STONE, +                 Decorator.COUNT_RANGE, 
- Blocks.NETHER_QUARTZ_ORE.getDefaultState(), +         new RangeDecoratorConfig( 
-         +         8, //Number of veins per chunk 
- ), +         0, //Bottom Offset 
-         Decorator.COUNT_RANGE, +         0, //Min y level 
- new RangeDecoratorConfig( +         64 //Max y level 
-     8, +         ))); 
-     0, + }
-     0, +
-     64 +
- ) +
-     ) +
-    ));+
 } }
 </code> </code>
  
-We're forcing the ore on each biome that the filter finds+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.
  
-==== 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: 
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-@Mixin(DefaultBiomeFeatures.class) +@Override 
-public class OreMixin +public void onInitialize() { 
-+ //Loop over existing biomes 
-    @Inject(at = @At("HEAD"), method = "addDefaultOres"+ Registry.BIOME.forEach(this::handleBiome); 
-    private static void addDefaultOres(final Biome biome, final CallbackInfo info) + 
-    + //Listen for other biomes being registered 
-        biome.addFeature( + RegistryEntryAddedCallback.event(Registry.BIOME).register((iidentifierbiome-> handleBiome(biome));
-                GenerationStep.Feature.UNDERGROUND_ORES, +
-                Biome.configureFeature+
-                        Feature.ORE, +
-                        new OreFeatureConfig( +
-                                OreFeatureConfig.Target.NATURAL_STONE, +
-                                Blocks.NETHER_QUARTZ_ORE.getDefaultState()+
-                                8 +
-                        ), +
-                        Decorator.COUNT_RANGE, +
-                        new RangeDecoratorConfig( +
-                                8, +
-                                0, +
-                                0, +
-                                64 +
-                        ) +
-                ) +
-        ); +
-    }+
 } }
 </code> </code>
- 
-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 ==== ==== Conclusion ====
-Regardless of which method you use, you should see quartz ore spawning in the overworld:+You should see quartz ore spawning in the overworld:
  
 {{https://i.imgur.com/UemsMaI.png|Quartz Ores}} {{https://i.imgur.com/UemsMaI.png|Quartz Ores}}
  
  
tutorial/ores.txt · Last modified: 2023/12/18 01:03 by solidblock