ModWorldGeneration.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package me.km.world;
  2. import me.km.blocks.ModBlocks;
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.Blocks;
  5. import net.minecraft.world.biome.Biome;
  6. import net.minecraft.world.gen.GenerationStage;
  7. import net.minecraft.world.gen.feature.ConfiguredFeature;
  8. import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
  9. import net.minecraft.world.gen.feature.Feature;
  10. import net.minecraft.world.gen.feature.OreFeatureConfig;
  11. import net.minecraft.world.gen.placement.CountRangeConfig;
  12. import net.minecraft.world.gen.placement.Placement;
  13. import net.minecraftforge.registries.ForgeRegistries;
  14. public class ModWorldGeneration
  15. {
  16. public static void register()
  17. {
  18. // search for all biomes which generate ore
  19. for(Biome biome : ForgeRegistries.BIOMES.getValues())
  20. {
  21. for(ConfiguredFeature f : biome.getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES))
  22. {
  23. if(!(f.config instanceof DecoratedFeatureConfig))
  24. {
  25. continue;
  26. }
  27. DecoratedFeatureConfig conf = (DecoratedFeatureConfig) f.config;
  28. if(!(conf.feature.config instanceof OreFeatureConfig))
  29. {
  30. continue;
  31. }
  32. OreFeatureConfig ore = (OreFeatureConfig) conf.feature.config;
  33. if(ore.state == Blocks.IRON_ORE.getDefaultState())
  34. {
  35. addFeatures(biome);
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. private static void addOre(Biome b, Block ore, int maxCount, int spawnTries, int maxHeight)
  42. {
  43. b.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES,
  44. Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,
  45. ore.getDefaultState(), maxCount)
  46. ).withPlacement(Placement.COUNT_RANGE.configure(new CountRangeConfig(spawnTries, 0, 0, maxHeight))));
  47. }
  48. private static void addFeatures(Biome biome)
  49. {
  50. // | max | bottom | top | max | spawn |
  51. // name | size | offset | offset | high | tries |
  52. // ---------------------------------------------------
  53. // coal | 17 | 0 | 0 | 128 | 20 |
  54. // iron | 9 | 0 | 0 | 64 | 20 |
  55. // gold | 9 | 0 | 0 | 32 | 2 |
  56. // redstone | 8 | 0 | 0 | 16 | 8 |
  57. // diamond | 8 | 0 | 0 | 16 | 1 |
  58. // lapis | 7 | - | - | - | - |
  59. // copper | 9 | 0 | 0 | 128 | 25 |
  60. // tin | 6 | 0 | 0 | 96 | 12 |
  61. // silver | 9 | 0 | 0 | 64 | 3 |
  62. addOre(biome, ModBlocks.copperOre, 9, 25, 128);
  63. addOre(biome, ModBlocks.tinOre, 6, 12, 96);
  64. addOre(biome, ModBlocks.silverOre, 9, 3, 64);
  65. }
  66. }