ModWorldGeneration.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package me.km.world;
  2. import java.util.function.Supplier;
  3. import me.km.blocks.ModBlocks;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.block.Blocks;
  6. import net.minecraft.world.biome.Biome;
  7. import net.minecraft.world.gen.GenerationStage;
  8. import net.minecraft.world.gen.feature.ConfiguredFeature;
  9. import net.minecraft.world.gen.feature.Feature;
  10. import net.minecraft.world.gen.feature.OreFeatureConfig;
  11. import net.minecraftforge.registries.ForgeRegistries;
  12. public class ModWorldGeneration {
  13. public static void register() {
  14. // search for all biomes which generate ore
  15. for(Biome biome : ForgeRegistries.BIOMES.getValues()) {
  16. biome.getGenerationSettings().getFeatures().forEach(list -> {
  17. for(Supplier<ConfiguredFeature<?, ?>> entry : list) {
  18. if(entry.get().config instanceof OreFeatureConfig) {
  19. OreFeatureConfig ore = (OreFeatureConfig) entry.get().config;
  20. if(ore.state == Blocks.IRON_ORE.getDefaultState()) {
  21. addFeatures(biome);
  22. break;
  23. }
  24. }
  25. }
  26. });
  27. }
  28. }
  29. private static void addOre(Biome b, Block ore, int maxCount, int spawnTries, int maxHeight) {
  30. b.getGenerationSettings().getFeatures().get(GenerationStage.Decoration.UNDERGROUND_ORES.ordinal()).add(() -> {
  31. return Feature.ORE.withConfiguration(
  32. new OreFeatureConfig(OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
  33. ore.getDefaultState(), maxCount)).range(maxHeight).square().func_242731_b(spawnTries);
  34. });
  35. }
  36. private static void addFeatures(Biome biome) {
  37. // | max | bottom | top | max | spawn |
  38. // name | size | offset | offset | high | tries |
  39. // ---------------------------------------------------
  40. // coal | 17 | 0 | 0 | 128 | 20 |
  41. // iron | 9 | 0 | 0 | 64 | 20 |
  42. // gold | 9 | 0 | 0 | 32 | 2 |
  43. // redstone | 8 | 0 | 0 | 16 | 8 |
  44. // diamond | 8 | 0 | 0 | 16 | 1 |
  45. // lapis | 7 | - | - | - | - |
  46. // copper | 9 | 0 | 0 | 128 | 25 |
  47. // tin | 6 | 0 | 0 | 96 | 12 |
  48. // silver | 9 | 0 | 0 | 64 | 3 |
  49. addOre(biome, ModBlocks.copperOre, 9, 25, 128);
  50. addOre(biome, ModBlocks.tinOre, 6, 12, 96);
  51. addOre(biome, ModBlocks.silverOre, 9, 3, 64);
  52. }
  53. }