ModWorldGeneration.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package me.km.world;
  2. import java.util.Map;
  3. import me.km.blocks.ModBlocks;
  4. import me.km.utils.ReflectionUtils;
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.Blocks;
  7. import net.minecraft.world.biome.Biome;
  8. import net.minecraft.world.biome.NetherBiome;
  9. import net.minecraft.world.gen.GenerationStage;
  10. import net.minecraft.world.gen.feature.ConfiguredFeature;
  11. import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
  12. import net.minecraft.world.gen.feature.Feature;
  13. import net.minecraft.world.gen.feature.IFeatureConfig;
  14. import net.minecraft.world.gen.feature.NoFeatureConfig;
  15. import net.minecraft.world.gen.feature.OreFeatureConfig;
  16. import net.minecraft.world.gen.feature.structure.StrongholdStructure;
  17. import net.minecraft.world.gen.feature.structure.Structure;
  18. import net.minecraft.world.gen.placement.CountRangeConfig;
  19. import net.minecraft.world.gen.placement.Placement;
  20. import net.minecraftforge.registries.ForgeRegistries;
  21. public class ModWorldGeneration {
  22. public static void register() {
  23. // search for all biomes which generate ore
  24. StrongholdStructure patch = new StrongholdStructure(NoFeatureConfig::deserialize);
  25. for(Biome biome : ForgeRegistries.BIOMES.getValues()) {
  26. if(!(biome instanceof NetherBiome)) {
  27. biome.getCarvers(GenerationStage.Carving.AIR).clear();
  28. biome.getCarvers(GenerationStage.Carving.LIQUID).clear();
  29. }
  30. Map<Structure<?>, IFeatureConfig> map = ReflectionUtils.getBiomeStructures(biome);
  31. if(map.remove(Feature.STRONGHOLD) != null) {
  32. System.out.println("removing stronghold from " + biome.getTranslationKey());
  33. }
  34. for(ConfiguredFeature f : biome.getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES)) {
  35. if(!(f.config instanceof DecoratedFeatureConfig)) {
  36. continue;
  37. }
  38. DecoratedFeatureConfig conf = (DecoratedFeatureConfig) f.config;
  39. if(!(conf.feature.config instanceof OreFeatureConfig)) {
  40. continue;
  41. }
  42. OreFeatureConfig ore = (OreFeatureConfig) conf.feature.config;
  43. if(ore.state == Blocks.IRON_ORE.getDefaultState()) {
  44. addFeatures(biome);
  45. break;
  46. }
  47. }
  48. }
  49. }
  50. private static void addOre(Biome b, Block ore, int maxCount, int spawnTries, int maxHeight) {
  51. b.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES,
  52. Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,
  53. ore.getDefaultState(), maxCount)
  54. ).withPlacement(Placement.COUNT_RANGE.configure(new CountRangeConfig(spawnTries, 0, 0, maxHeight))));
  55. }
  56. private static void addFeatures(Biome biome) {
  57. // | max | bottom | top | max | spawn |
  58. // name | size | offset | offset | high | tries |
  59. // ---------------------------------------------------
  60. // coal | 17 | 0 | 0 | 128 | 20 |
  61. // iron | 9 | 0 | 0 | 64 | 20 |
  62. // gold | 9 | 0 | 0 | 32 | 2 |
  63. // redstone | 8 | 0 | 0 | 16 | 8 |
  64. // diamond | 8 | 0 | 0 | 16 | 1 |
  65. // lapis | 7 | - | - | - | - |
  66. // copper | 9 | 0 | 0 | 128 | 25 |
  67. // tin | 6 | 0 | 0 | 96 | 12 |
  68. // silver | 9 | 0 | 0 | 64 | 3 |
  69. addOre(biome, ModBlocks.copperOre, 9, 25, 128);
  70. addOre(biome, ModBlocks.tinOre, 6, 12, 96);
  71. addOre(biome, ModBlocks.silverOre, 9, 3, 64);
  72. }
  73. }