TechOFreak

OreGenerationExample.java

Oct 27th, 2020 (edited)
1,586
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.techofreak.elementa.world.gen;
  2.  
  3. import net.minecraft.block.Blocks;
  4. import net.minecraft.util.registry.Registry;
  5. import net.minecraft.util.registry.WorldGenRegistries;
  6. import net.minecraft.world.biome.Biome;
  7. import net.minecraft.world.gen.GenerationStage;
  8. import net.minecraft.world.gen.feature.ConfiguredFeature;
  9. import net.minecraft.world.gen.feature.Feature;
  10. import net.minecraft.world.gen.feature.IFeatureConfig;
  11. import net.minecraft.world.gen.feature.OreFeatureConfig;
  12. import net.minecraft.world.gen.feature.template.BlockMatchRuleTest;
  13. import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
  14. import net.minecraftforge.event.world.BiomeLoadingEvent;
  15. import net.minecraftforge.eventbus.api.EventPriority;
  16. import net.minecraftforge.eventbus.api.SubscribeEvent;
  17. import net.minecraftforge.fml.common.Mod;
  18.  
  19. import java.util.ArrayList;
  20.  
  21. /**
  22.  * Ore generation
  23.  * @author TechOFreak
  24.  * Add OreGenerationExample.registerOres(); to your main class's setup method
  25.  */
  26.  
  27. @Mod.EventBusSubscriber
  28. public class OreGenerationExample {
  29.  
  30.     private static final ArrayList<ConfiguredFeature<?, ?>> overworldOres = new ArrayList<ConfiguredFeature<?, ?>>();
  31.     private static final ArrayList<ConfiguredFeature<?, ?>> netherOres = new ArrayList<ConfiguredFeature<?, ?>>();
  32.     private static final ArrayList<ConfiguredFeature<?, ?>> endOres = new ArrayList<ConfiguredFeature<?, ?>>();
  33.  
  34.     public static void registerOres(){
  35.         //field_241882_a is for generating in stone, granite, diorite, and andesite
  36.         //field_241883_b is for generating in netherrack
  37.         //field_241884_c is for generating in netherrack, basalt and blackstone
  38.  
  39.         //Overworld Ore Register
  40.         overworldOres.add(register("example_overworld_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  41.                 OreFeatureConfig.FillerBlockType.field_241882_a, YOUR_ORE_BLOCK.getDefaultState(), 4)) //Vein Size
  42.                 .func_242733_d(64).func_242728_a() //Spawn height start
  43.                 .func_242731_b(64))); //Chunk spawn frequency
  44.  
  45.         //Nether Ore Register
  46.         netherOres.add(register("example_nether_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  47.                 OreFeatureConfig.FillerBlockType.field_241883_b, YOUR_ORE_BLOCK.getDefaultState(), 4)) //Vein Size
  48.                 .func_242733_d(64).func_242728_a() //Spawn height start
  49.                 .func_242731_b(64))); //Chunk spawn frequency
  50.  
  51.         //The End Ore Register
  52.         endOres.add(register("example_end_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  53.                 new BlockMatchRuleTest(Blocks.END_STONE), YOUR_ORE_BLOCK.getDefaultState(), 4)) //Vein Size
  54.                 .func_242733_d(128).func_242728_a() //Spawn height start
  55.                 .func_242731_b(64))); //Chunk spawn frequency
  56.     }
  57.  
  58.     @SubscribeEvent(priority = EventPriority.HIGHEST)
  59.     public static void gen(BiomeLoadingEvent event) {
  60.         BiomeGenerationSettingsBuilder generation = event.getGeneration();
  61.         if(event.getCategory().equals(Biome.Category.NETHER)){
  62.             for(ConfiguredFeature<?, ?> ore : netherOres){
  63.                 if (ore != null) generation.func_242513_a(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  64.             }
  65.         }
  66.         if(event.getCategory().equals(Biome.Category.THEEND)){
  67.             for(ConfiguredFeature<?, ?> ore : endOres){
  68.                 if (ore != null) generation.func_242513_a(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  69.             }
  70.         }
  71.         for(ConfiguredFeature<?, ?> ore : overworldOres){
  72.             if (ore != null) generation.func_242513_a(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  73.         }
  74.     }
  75.  
  76.     private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String name, ConfiguredFeature<FC, ?> configuredFeature) {
  77.         return Registry.register(WorldGenRegistries.field_243653_e, YOUR_MOD_ID + ":" + name, configuredFeature);
  78.     }
  79.  
  80. }
RAW Paste Data