TechOFreak

Ore Generation Tutorial with Desert Gen

Nov 12th, 2020
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.10 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.     //Added for desert generation
  35.     private static final ArrayList<ConfiguredFeature<?, ?>> desertOres = new ArrayList<ConfiguredFeature<?, ?>>();
  36.  
  37.     public static void registerOres(){
  38.         //BASE_STONE_OVERWORLD is for generating in stone, granite, diorite, and andesite
  39.         //NETHERRACK is for generating in netherrack
  40.         //BASE_STONE_NETHER is for generating in netherrack, basalt and blackstone
  41.  
  42.         //Overworld Ore Register
  43.         overworldOres.add(register("neutralis_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  44.                 OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, RegistryHandlerBlocks.NEUTRALIS_ORE.get().getDefaultState(), 4)) //Vein Size
  45.                 .range(64).square() //Spawn height start
  46.                 .func_242731_b(64))); //Chunk spawn frequency
  47.         overworldOres.add(register("earthy_deposit", Feature.ORE.withConfiguration(new OreFeatureConfig(
  48.                 new BlockMatchRuleTest(Blocks.DIRT), RegistryHandlerBlocks.EARTHY_DEPOSIT.get().getDefaultState(), 4)) //Vein Size
  49.                 .range(128).square() //Spawn height start
  50.                 .func_242731_b(64))); //Chunk spawn frequency
  51.  
  52.         //Nether Ore Register
  53.         netherOres.add(register("flame_crystal_ore", Feature.ORE.withConfiguration(new OreFeatureConfig(
  54.                 OreFeatureConfig.FillerBlockType.NETHERRACK, RegistryHandlerBlocks.FLAME_CRYSTAL_ORE.get().getDefaultState(), 4))
  55.                 .range(48).square()
  56.                 .func_242731_b(64)));
  57.  
  58.         //The End Ore Register
  59.         endOres.add(register("air_block", Feature.ORE.withConfiguration(new OreFeatureConfig(
  60.                 new BlockMatchRuleTest(Blocks.END_STONE), RegistryHandlerBlocks.AIR_CRYSTAL_BLOCK.get().getDefaultState(), 4)) //Vein Size
  61.                 .range(128).square() //Spawn height start
  62.                 .func_242731_b(64))); //Chunk spawn frequency
  63.  
  64.     //Desert Ore Register
  65.         desertOres.add(register("your_ore_block_name", Feature.ORE.withConfiguration(new OreFeatureConfig(
  66.                 new BlockMatchRuleTest(Blocks.SAND), YOUR_ORE_BLOCK.getDefaultState(), 4)) //Vein Size
  67.                 .range(128).square() //Spawn height start
  68.                 .func_242731_b(64))); //Chunk spawn frequency
  69.     }
  70.  
  71.     @SubscribeEvent(priority = EventPriority.HIGHEST)
  72.     public static void gen(BiomeLoadingEvent event) {
  73.         BiomeGenerationSettingsBuilder generation = event.getGeneration();
  74.         if(event.getCategory().equals(Biome.Category.NETHER)){
  75.             for(ConfiguredFeature<?, ?> ore : netherOres){
  76.                 if (ore != null) generation.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  77.             }
  78.         }
  79.         if(event.getCategory().equals(Biome.Category.THEEND)){
  80.             for(ConfiguredFeature<?, ?> ore : endOres){
  81.                 if (ore != null) generation.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  82.             }
  83.         }
  84.     //Added for desert generation
  85.     if(event.getCategory().equals(Biome.Category.DESERT)){
  86.             for(ConfiguredFeature<?, ?> ore : desertOres){
  87.                 if (ore != null) generation.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  88.             }
  89.         }
  90.         for(ConfiguredFeature<?, ?> ore : overworldOres){
  91.             if (ore != null) generation.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ore);
  92.         }
  93.     }
  94.  
  95.     private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String name, ConfiguredFeature<FC, ?> configuredFeature) {
  96.         return Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, Elementa.MOD_ID + ":" + name, configuredFeature);
  97.     }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment