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/08/19 19:36] – [Adding ores to a biome] Enhancements jamieswhiteshirttutorial:ores [2020/08/26 11:25] – Update to 1.16.2 siglong
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 and biomes added by other mods. There are 2 steps that are required to add ores to biomes. 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+  * Make a ConfiguredFeatures. This defines how your ore block is spawned
-  * Use the RegistryEntryAddedCallback to ensure your ore gets added into any biomes added by mods.+  * Use mixin to inject feature registration into DefaultBiomeFeature
  
 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.
  
-==== Adding ores to biome ====+==== Making ConfiguredFeatures ==== 
 +First we need to create a ConfiguredFeatures. Make sure to register your ConfiguredFeature at ''onInitialize''. Feel free to change the values to suit your mod.
  
-First we need to create a method to process a biomechecking if it is a valid biome then adding the ore.+<code java [enable_line_numbers="true"]> 
 +public class ExampleMod implements ModInitializer { 
 +  public static ConfiguredFeature<??> ORE_QUARTZ_OVERWORLD = Feature.ORE 
 +      .configure(new OreFeatureConfig( 
 +        OreFeatureConfig.Rules.BASE_STONE_OVERWORLD,  
 +        Blocks.NETHER_QUARTZ_ORE.getDefaultState(), 
 +        9)) // vein size 
 +      .decorate(Decorator.RANGE.configure(new RangeDecoratorConfig( 
 +        0, // bottom offset 
 +        0, // min y level 
 +        64))) // max y level 
 +      .spreadHorizontally() 
 +      .repeat(20); // number of veins per chunk
  
-<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) { +    Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("tutorial""ore_quartz_overworld"), ORE_QUARTZ_OVERWORLD); 
- biome.addFeature( +  }
-            GenerationStep.Feature.UNDERGROUND_ORES, +
-            Biome.configureFeature( +
-                Feature.ORE, +
-        new OreFeatureConfig( +
-        OreFeatureConfig.Target.NATURAL_STONE, +
-        Blocks.NETHER_QUARTZ_ORE.getDefaultState(), +
-                8 //Ore vein size +
-        ), +
-                Decorator.COUNT_RANGE, +
-        new RangeDecoratorConfig( +
-        8, //Number of veins per chunk +
-        0, //Bottom Offset +
-        0, //Min y level +
-        64 //Max y level +
-        ))); +
- }+
 } }
 </code> </code>
  
-This method adds your ore to the overworld, with the provided spawn settings. Feel free to change the values to suit your mod. +==== Injecting into DefaultBiomeFeature ==== 
- +This adds your ore to the overworld biomes. 
-==== 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.+
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-@Override +@Mixin(DefaultBiomeFeatures.class) 
-public void onInitialize() { +public class DefaultBiomeFeaturesMixin 
- //Loop over existing biomes +  @Inject(method = "addDefaultOres(Lnet/minecraft/world/biome/GenerationSettings$Builder;)V", at = @At("TAIL")
- Registry.BIOME.forEach(this::handleBiome); +  private static void addDefaultOres(GenerationSettings.Builder builder, CallbackInfo ci
- +    builder.feature(GenerationStep.Feature.UNDERGROUND_ORESExampleMod.ORE_QUARTZ_OVERWORLD); 
- //Listen for other biomes being registered +  }
- RegistryEntryAddedCallback.event(Registry.BIOME).register((iidentifier, biome) -> handleBiome(biome));+
 } }
 </code> </code>
  
 ==== Conclusion ==== ==== Conclusion ====
-You should see quartz ore spawning in the overworld: +You should see quartz ore spawning in the overworld. You can use fill command to remove stone blocks surrounding you like this''/fill ~-4 0 ~-4 ~4 ~ ~4 minecraft:air replace minecraft:stone''.
- +
-{{https://i.imgur.com/UemsMaI.png|Quartz Ores}}+
  
 +{{tutorial:ores.png}}
  
tutorial/ores.txt · Last modified: 2023/12/18 01:03 by solidblock