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
tutorial:ores [2023/03/01 18:44] – Added 1.19.3 section explaining the process of adding custom ores vextintutorial:ores [2023/12/18 01:03] (current) solidblock
Line 1: Line 1:
-FIXME: If you are looking for 1.19.3, ores should be done completely in jsons. A helpful tool to know is: [[https://misode.github.io/worldgen/feature/|Configured Features]] and [[https://misode.github.io/worldgen/placed-feature/|Placed Features]]+If you are looking for 1.19.3, ores should be done completely in jsons. A helpful tool to know is: [[https://misode.github.io/worldgen/feature/|Configured Features]] and [[https://misode.github.io/worldgen/placed-feature/|Placed Features]]
  
 ====== Generating Custom Ores [1.19.3+] ====== ====== Generating Custom Ores [1.19.3+] ======
Line 6: Line 6:
   * Use [[https://github.com/FabricMC/fabric/pull/1097|Biome Modification API in Fabric API]] to add your feature to biomes.   * Use [[https://github.com/FabricMC/fabric/pull/1097|Biome Modification API in Fabric API]] to add your feature to biomes.
  
- +To simplify, we use vanilla end rod as ore, because it can be easily found and seen underground in spectator mode.
-This tutorial assumes that you have already created your ore blockand that it appears correctly in-game (via the ''/give'' command)+
  
 ==== Adding to the overworld biomes ==== ==== Adding to the overworld biomes ====
Line 14: Line 13:
 First, create two new JSON files in your mod's data directory: First, create two new JSON files in your mod's data directory:
  
-<code JavaScript src\main\resources\data\examplemod\worldgen\configured_feature\ore_custom.json>+<code JavaScript src\main\resources\data\tutorial\worldgen\configured_feature\ore_custom.json>
 { {
   "type": "minecraft:ore",   "type": "minecraft:ore",
Line 23: Line 22:
       {       {
         "state": {         "state": {
-          "Name": "examplemod:custom_ore"+          "Name": "minecraft:end_rod"
         },         },
         "target": {         "target": {
Line 32: Line 31:
       {       {
         "state": {         "state": {
-          "Name": "examplemod:deepslate_custom_ore"+          "Name": "minecraft:end_rod"
         },         },
         "target": {         "target": {
Line 44: Line 43:
 </code> </code>
  
-This Configured Feature tells the game the size of the ore veins, what fraction of the ore blocks should be removed due to air exposure, and, importantly, which blocks the ore block should be allowed to replace. Notice how there are two ''target'' objects in the ''targets'' array: one for stone ore, and one for deepslate oreIf you have not yet made a deepslate ore blockdo that now, or simply replace ''"examplemod:deepslate_custom_ore"'' with ''"examplemod:custom_ore"'' to use the stone version of your ore block.+This Configured Feature tells the game the size of the ore veins, what fraction of the ore blocks should be removed due to air exposure, and, importantly, which blocks the ore block should be allowed to replace. Notice how there are two ''target'' objects in the ''targets'' array: one for ore in stone, and another is the ore in deepslate. To simplify itboth we use end rod in vanilla games.
  
-<code JavaScript src\main\resources\data\examplemod\worldgen\placed_feature\ore_custom.json>+<code JavaScript src\main\resources\data\tutorial\worldgen\placed_feature\ore_custom.json>
 { {
-  "feature": "examplemod:ore_custom",+  "feature": "tutorial:ore_custom",
   "placement": [   "placement": [
     {     {
Line 78: Line 77:
 This Placed Feature tells the game how many ore veins to place in a chunk, what shape the ore veins are placed in, and at what y-levels the ore veins are placed in. Note that the first line of the Placed Feature references the Configured Feature that was created a moment ago.  This Placed Feature tells the game how many ore veins to place in a chunk, what shape the ore veins are placed in, and at what y-levels the ore veins are placed in. Note that the first line of the Placed Feature references the Configured Feature that was created a moment ago. 
    
-Writing these JSON files by hand is strenuous and inefficient. Note that the bulk of the work can be skipped by using tools like this [[https://misode.github.io/worldgen/feature/|Configured Features generator]] and this [[https://misode.github.io/worldgen/placed-feature/|Placed Features generator]]. Alternatively, use 7Zip or WinRar to open your vanilla Minecraft ''.jar'' and use the vanilla files as a reference. +Writing these JSON files by hand is strenuous and inefficient. Note that the bulk of the work can be skipped by using tools like this [[https://misode.github.io/worldgen/feature/|Configured Features generator]] and this [[https://misode.github.io/worldgen/placed-feature/|Placed Features generator]]. Alternatively, use compressed file tools to open your vanilla Minecraft ''.jar'' and use the vanilla files as a reference. 
  
 Now that our data is created, it's time for code! Thanks to the changes in Minecraft 1.19.3, adding ore to world generation requires much less Java code. All we need to do is register the feature, then use the Fabric Biome Modification API to tell Minecraft which dimension to generate the ore in (and during which stage of world generation to generate the ore). Now that our data is created, it's time for code! Thanks to the changes in Minecraft 1.19.3, adding ore to world generation requires much less Java code. All we need to do is register the feature, then use the Fabric Biome Modification API to tell Minecraft which dimension to generate the ore in (and during which stage of world generation to generate the ore).
Line 84: Line 83:
 First, at the class level, let's create a new ''RegistryKey'' at the class-level to store our ore.  First, at the class level, let's create a new ''RegistryKey'' at the class-level to store our ore. 
  
-<code Java src/main/java/net/fabricmc/examplemod/ExampleMod.java> +<code Java src/main/java/net/fabricmc/example/ExampleMod.java>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
   
- //public static final Logger LOGGER... + public static final RegistryKey<PlacedFeature> CUSTOM_ORE_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("tutorial","ore_custom"));
- public static final RegistryKey<PlacedFeature> CUSTOM_ORE_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("examplemod","ore_custom"));+
  
  @Override  @Override
Line 106: Line 103:
 Now to add the Feature to a biome: Now to add the Feature to a biome:
  
-<code Java src/main/java/net/fabricmc/examplemod/ExampleMod.java>+<code Java src/main/java/net/fabricmc/example/ExampleMod.java>
  
 @Override @Override
-public void onInitialize() { + public void onInitialize() { 
- +  
- //Your other code here... + //Your other code here... 
- BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Feature.UNDERGROUND_ORES, CUSTOM_ORE_PLACED_KEY); + BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Feature.UNDERGROUND_ORES, CUSTOM_ORE_PLACED_KEY); 
- + }
-}+
  
 </code> </code>
Line 120: Line 116:
 ==== Testing ==== ==== Testing ====
  
-To test your new ore, generate a new world. Use the following command to remove the stone in an area around you: +To test your new ore, generate a new world. You can also open existing world but have to go to new chunks. In this example of end rod, the ores can be directly seen underground in spectator mode.
-<code> +
-/fill ~-8 0 ~-8 ~8 ~-16 ~8 minecraft:air replace minecraft:stone +
-</code> +
  
 ==== Adding to the Nether or End ==== ==== Adding to the Nether or End ====
Line 132: Line 124:
 As with the Overworld, we begin with the JSON files. Using vanilla's nether gold ore as an example, our Placed Feature will look something like this: As with the Overworld, we begin with the JSON files. Using vanilla's nether gold ore as an example, our Placed Feature will look something like this:
  
-<code JavaScript src/main/resources/data/examplemod/worldgen/placed_feature/ore_custom_nether.json>+<code JavaScript src/main/resources/data/tutorial/worldgen/placed_feature/ore_custom_nether.json>
 { {
-  "feature": "examplemod:ore_nether_custom",+  "feature": "tutorial:ore_nether_custom",
   "placement": [   "placement": [
     {     {
Line 166: Line 158:
 As before, we add a Configured Feature as well. As before, we add a Configured Feature as well.
  
-<code JavaScript src/main/resources/data/examplemod/worldgen/configured_feature/ore_nether_custom.json>+<code JavaScript src/main/resources/data/tutorial/worldgen/configured_feature/ore_nether_custom.json>
 { {
   "type": "minecraft:ore",   "type": "minecraft:ore",
Line 175: Line 167:
       {       {
         "state": {         "state": {
-          "Name": "minecraft:nether_custom_ore"+          "Name": "minecraft:end_rod"
         },         },
         "target": {         "target": {
Line 191: Line 183:
 Finally, back in our Java code, right after our other BiomeModification line, Finally, back in our Java code, right after our other BiomeModification line,
  
-<code Java src/main/java/net/fabricmc/examplemod/ExampleMod.java> +<code Java src/main/java/net/fabricmc/example/ExampleMod.java> 
-BiomeModifications.addFeature(BiomeSelectors.foundInNether(), GenerationStep.Feature.UNDERGROUND_ORES, CUSTOM_ORE_PLACED_KEY);+ BiomeModifications.addFeature(BiomeSelectors.foundInNether(), GenerationStep.Feature.UNDERGROUND_ORES, CUSTOM_ORE_PLACED_KEY);
 </code> </code>
  
tutorial/ores.1677696297.txt.gz · Last modified: 2023/03/01 18:44 by vextin