tutorial:ores
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:ores [2019/07/03 20:37] – draylar | tutorial: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 | + | 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 |
- | * Iterate over the biome registry | + | * Iterate over the biome registry |
- | * Mixin into '' | + | * 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:// | + | |
We'll assume you've already created your own ore block at this point. Quartz Ore will serve as our replacement, | We'll assume you've already created your own ore block at this point. Quartz Ore will serve as our replacement, | ||
- | ==== 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 phase. We 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 | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | @Override | + | private |
- | public | + | if(biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND) |
- | { | + | biome.addFeature( |
- | Registry.BIOME.stream() | + | |
- | .filter(biome -> biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND) | + | |
- | | + | |
- | | + | new OreFeatureConfig( |
- | | + | OreFeatureConfig.Target.NATURAL_STONE, |
- | | + | Blocks.NETHER_QUARTZ_ORE.getDefaultState(), |
- | | + | |
- | new OreFeatureConfig( | + | ), |
- | OreFeatureConfig.Target.NATURAL_STONE, | + | |
- | Blocks.NETHER_QUARTZ_ORE.getDefaultState(), | + | new RangeDecoratorConfig( |
- | | + | 8, //Number of veins per chunk |
- | ), | + | 0, //Bottom Offset |
- | | + | 0, //Min y level |
- | new RangeDecoratorConfig( | + | 64 //Max y level |
- | | + | ))); |
- | | + | } |
- | | + | |
- | | + | |
- | ) | + | |
- | ) | + | |
- | | + | |
} | } | ||
</ | </ | ||
- | 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 | ||
- | ==== Mixin into DefaultBiomeFeatures ==== | ||
- | Create a mixin class in your mixin folder, and register it to your '' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | @Mixin(DefaultBiomeFeatures.class) | + | @Override |
- | public | + | public void onInitialize() { |
- | { | + | //Loop over existing biomes |
- | @Inject(at = @At(" | + | Registry.BIOME.forEach(this:: |
- | private static | + | |
- | | + | //Listen for other biomes being registered |
- | | + | RegistryEntryAddedCallback.event(Registry.BIOME).register((i, identifier, biome) -> handleBiome(biome)); |
- | | + | |
- | Biome.configureFeature( | + | |
- | | + | |
- | new OreFeatureConfig( | + | |
- | | + | |
- | Blocks.NETHER_QUARTZ_ORE.getDefaultState(), | + | |
- | 8 | + | |
- | ), | + | |
- | Decorator.COUNT_RANGE, | + | |
- | new RangeDecoratorConfig( | + | |
- | 8, | + | |
- | 0, | + | |
- | 0, | + | |
- | 64 | + | |
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
} | } | ||
</ | </ | ||
- | |||
- | 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:// | {{https:// | ||
tutorial/ores.txt · Last modified: 2023/12/18 01:03 by solidblock