Advertisement
TechOFreak

Ore Generation Tutorial

Nov 5th, 2020
5,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.32 KB | None | 0 0
  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.item.Items;
  6. import net.minecraft.util.registry.Registry;
  7. import net.minecraft.util.registry.WorldGenRegistries;
  8. import net.minecraft.world.biome.Biome;
  9. import net.minecraft.world.gen.GenerationStage;
  10. import net.minecraft.world.gen.feature.ConfiguredFeature;
  11. import net.minecraft.world.gen.feature.Feature;
  12. import net.minecraft.world.gen.feature.IFeatureConfig;
  13. import net.minecraft.world.gen.feature.OreFeatureConfig;
  14. import net.minecraft.world.gen.feature.template.BlockMatchRuleTest;
  15. import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
  16. import net.minecraftforge.event.world.BiomeLoadingEvent;
  17. import net.minecraftforge.eventbus.api.EventPriority;
  18. import net.minecraftforge.eventbus.api.SubscribeEvent;
  19. import net.minecraftforge.fml.common.Mod;
  20. import java.util.ArrayList;
  21.  
  22. /**
  23.  * Ore generation
  24.  * @author TechOFreak
  25.  *
  26.  */
  27.  
  28. @Mod.EventBusSubscriber
  29. public class OreGeneration {
  30.  
  31.     private static final ArrayList<ConfiguredFeature<?, ?>> overworldOres = new ArrayList<ConfiguredFeature<?, ?>>();
  32.     private static final ArrayList<ConfiguredFeature<?, ?>> netherOres = new ArrayList<ConfiguredFeature<?, ?>>();
  33.     private static final ArrayList<ConfiguredFeature<?, ?>> endOres = new ArrayList<ConfiguredFeature<?, ?>>();
  34.  
  35.     public static void registerOres(){
  36.         //BASE_STONE_OVERWORLD is for generating in stone, granite, diorite, and andesite
  37.         //NETHERRACK is for generating in netherrack
  38.         //BASE_STONE_NETHER is for generating in netherrack, basalt and blackstone
  39.  
  40.         //Overworld Ore Register
  41.         overworldOres.add(register("neutralis_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  42.                 OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, RegistryHandlerBlocks.NEUTRALIS_ORE.get().getDefaultState(), 4)) //Vein Size
  43.                 .range(64).square() //Spawn height start
  44.                 .func_242731_b(64))); //Chunk spawn frequency
  45.         overworldOres.add(register("earthy_deposit", Feature.ORE.withConfiguration(new OreFeatureConfig(
  46.                 new BlockMatchRuleTest(Blocks.DIRT), RegistryHandlerBlocks.EARTHY_DEPOSIT.get().getDefaultState(), 4)) //Vein Size
  47.                 .range(128).square() //Spawn height start
  48.                 .func_242731_b(64))); //Chunk spawn frequency
  49.  
  50.         //Nether Ore Register
  51.         netherOres.add(register("flame_crystal_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  52.                 OreFeatureConfig.FillerBlockType.NETHERRACK, RegistryHandlerBlocks.FLAME_CRYSTAL_ORE.get().getDefaultState(), 4))
  53.                 .range(48).square()
  54.                 .func_242731_b(64)));
  55.  
  56.         //The End Ore Register
  57.         endOres.add(register("air_block", Feature.ORE.withConfiguration(new OreFeatureConfig(
  58.                 new BlockMatchRuleTest(Blocks.END_STONE), RegistryHandlerBlocks.AIR_CRYSTAL_BLOCK.get().getDefaultState(), 4)) //Vein Size
  59.                 .range(128).square() //Spawn height start
  60.                 .func_242731_b(64))); //Chunk spawn frequency
  61.     }
  62.  
  63.     @SubscribeEvent(priority = EventPriority.HIGHEST)
  64.     public static void gen(BiomeLoadingEvent event) {
  65.         BiomeGenerationSettingsBuilder generation = event.getGeneration();
  66.         if(event.getCategory().equals(Biome.Category.NETHER)){
  67.             for(ConfiguredFeature<?, ?> ore : netherOres){
  68.                 if (ore != null) generation.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  69.             }
  70.         }
  71.         if(event.getCategory().equals(Biome.Category.THEEND)){
  72.             for(ConfiguredFeature<?, ?> ore : endOres){
  73.                 if (ore != null) generation.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  74.             }
  75.         }
  76.         for(ConfiguredFeature<?, ?> ore : overworldOres){
  77.             if (ore != null) generation.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  78.         }
  79.     }
  80.  
  81.     private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String name, ConfiguredFeature<FC, ?> configuredFeature) {
  82.         return Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, Elementa.MOD_ID + ":" + name, configuredFeature);
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement