TechOFreak

OreGeneration.java

Oct 27th, 2020
1,609
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.techofreak.elementa.world.gen;
  2. import com.techofreak.elementa.Elementa;
  3. import com.techofreak.elementa.util.RegistryHandlerBlocks;
  4. import net.minecraft.block.Blocks;
  5. import net.minecraft.util.registry.Registry;
  6. import net.minecraft.util.registry.WorldGenRegistries;
  7. import net.minecraft.world.biome.Biome;
  8. import net.minecraft.world.gen.GenerationStage;
  9. import net.minecraft.world.gen.feature.ConfiguredFeature;
  10. import net.minecraft.world.gen.feature.Feature;
  11. import net.minecraft.world.gen.feature.IFeatureConfig;
  12. import net.minecraft.world.gen.feature.OreFeatureConfig;
  13. import net.minecraft.world.gen.feature.template.BlockMatchRuleTest;
  14. import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
  15. import net.minecraftforge.event.world.BiomeLoadingEvent;
  16. import net.minecraftforge.eventbus.api.EventPriority;
  17. import net.minecraftforge.eventbus.api.SubscribeEvent;
  18. import net.minecraftforge.fml.common.Mod;
  19. import java.util.ArrayList;
  20.  
  21. /**
  22.  * Ore generation
  23.  * @author TechOFreak
  24.  *
  25.  */
  26.  
  27. @Mod.EventBusSubscriber
  28. public class OreGeneration {
  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("neutralis_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  41.                 OreFeatureConfig.FillerBlockType.field_241882_a, RegistryHandlerBlocks.NEUTRALIS_ORE.get().getDefaultState(), 4)) //Vein Size
  42.                 .func_242733_d(64).func_242728_a() //Spawn height start
  43.                 .func_242731_b(16))); //Chunk spawn frequency
  44.  
  45.         //Nether Ore Register
  46.         /*
  47.         netherOres.add(register("neutralis_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  48.                 OreFeatureConfig.FillerBlockType.field_241883_b, RegistryHandlerBlocks.FLAME_CRYSTAL_BLOCK.get().getDefaultState(), 4))
  49.                 .func_242733_d(64).func_242728_a()
  50.                 .func_242731_b(64)));
  51.          */
  52.  
  53.         /*
  54.         //The End Ore Register
  55.         endOres.add(register("neutralis_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  56.                 new BlockMatchRuleTest(Blocks.END_STONE), RegistryHandlerBlocks.AIR_CRYSTAL_BLOCK.get().getDefaultState(), 4)) //Vein Size
  57.                 .func_242733_d(128).func_242728_a() //Spawn height start
  58.                 .func_242731_b(64))); //Chunk spawn frequency
  59.          */
  60.     }
  61.  
  62.     @SubscribeEvent(priority = EventPriority.HIGHEST)
  63.     public static void gen(BiomeLoadingEvent event) {
  64.         BiomeGenerationSettingsBuilder generation = event.getGeneration();
  65.         if(event.getCategory().equals(Biome.Category.NETHER)){
  66.             for(ConfiguredFeature<?, ?> ore : netherOres){
  67.                 if (ore != null) generation.func_242513_a(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  68.             }
  69.         }
  70.         if(event.getCategory().equals(Biome.Category.THEEND)){
  71.             for(ConfiguredFeature<?, ?> ore : endOres){
  72.                 if (ore != null) generation.func_242513_a(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  73.             }
  74.         }
  75.         for(ConfiguredFeature<?, ?> ore : overworldOres){
  76.             if (ore != null) generation.func_242513_a(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  77.         }
  78.     }
  79.  
  80.     private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String name, ConfiguredFeature<FC, ?> configuredFeature) {
  81.         return Registry.register(WorldGenRegistries.field_243653_e, Elementa.MOD_ID + ":" + name, configuredFeature);
  82.     }
  83.  
  84. }
RAW Paste Data