|
@@ -1,51 +1,71 @@
|
|
|
package me.km.world;
|
|
|
|
|
|
-import java.util.Random;
|
|
|
import me.km.blocks.ModBlocks;
|
|
|
-import net.minecraft.block.BlockState;
|
|
|
-import net.minecraft.util.math.BlockPos;
|
|
|
-import net.minecraft.world.World;
|
|
|
-import net.minecraft.world.chunk.AbstractChunkProvider;
|
|
|
-import net.minecraft.world.dimension.DimensionType;
|
|
|
-import net.minecraft.world.gen.ChunkGenerator;
|
|
|
-import net.minecraft.world.gen.feature.OreFeature;
|
|
|
+import net.minecraft.block.Blocks;
|
|
|
+import net.minecraft.world.biome.Biome;
|
|
|
+import net.minecraft.world.gen.GenerationStage;
|
|
|
+import net.minecraft.world.gen.feature.ConfiguredFeature;
|
|
|
+import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
|
|
|
+import net.minecraft.world.gen.feature.Feature;
|
|
|
import net.minecraft.world.gen.feature.OreFeatureConfig;
|
|
|
-import net.minecraftforge.fml.common.IWorldGenerator;
|
|
|
+import net.minecraft.world.gen.placement.CountRangeConfig;
|
|
|
+import net.minecraft.world.gen.placement.Placement;
|
|
|
+import net.minecraftforge.registries.ForgeRegistries;
|
|
|
|
|
|
-public class ModWorldGeneration implements IWorldGenerator
|
|
|
+public class ModWorldGeneration
|
|
|
{
|
|
|
- @Override
|
|
|
- public void generate(Random r, int cX, int cZ, World w, ChunkGenerator cg, AbstractChunkProvider cp)
|
|
|
+ public static void register()
|
|
|
{
|
|
|
- DimensionType type = w.getDimension().getType();
|
|
|
- if(type != DimensionType.NETHER && type != DimensionType.THE_END)
|
|
|
+ // search for all biomes which generate ore
|
|
|
+ for(Biome biome : ForgeRegistries.BIOMES.getValues())
|
|
|
{
|
|
|
- generateOverworld(r, cX, cZ, w, cg, cp);
|
|
|
- }
|
|
|
+ for(ConfiguredFeature f : biome.getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES))
|
|
|
+ {
|
|
|
+ if(!(f.config instanceof DecoratedFeatureConfig))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ DecoratedFeatureConfig conf = (DecoratedFeatureConfig) f.config;
|
|
|
+ if(!(conf.feature.config instanceof OreFeatureConfig))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ OreFeatureConfig ore = (OreFeatureConfig) conf.feature.config;
|
|
|
+ if(ore.state == Blocks.IRON_ORE.getDefaultState())
|
|
|
+ {
|
|
|
+ addFeatures(biome);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- private void generateOverworld(Random r, int chunkX, int chunkZ, World w, ChunkGenerator cg, AbstractChunkProvider cp)
|
|
|
- {
|
|
|
- generateOre(cg, ModBlocks.copperOre.getDefaultState(), w, r,
|
|
|
- chunkX << 4, chunkZ << 4, 0, 128, 9, 25);
|
|
|
- generateOre(cg, ModBlocks.tinOre.getDefaultState(), w, r,
|
|
|
- chunkX << 4, chunkZ << 4, 0, 96, 8, 12);
|
|
|
- generateOre(cg, ModBlocks.silverOre.getDefaultState(), w, r,
|
|
|
- chunkX << 4, chunkZ << 4, 0, 64, 8, 3);
|
|
|
- }
|
|
|
|
|
|
- private void generateOre(ChunkGenerator cg, BlockState ore, World w, Random r, int x, int z,
|
|
|
- int minY, int maxY, int size, int chances)
|
|
|
+ private static void addFeatures(Biome biome)
|
|
|
{
|
|
|
- int deltaY = maxY - minY;
|
|
|
- BlockPos pos;
|
|
|
- OreFeatureConfig config = new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, ore, size);
|
|
|
- OreFeature generator = new OreFeature(OreFeatureConfig::deserialize);
|
|
|
- for(int i = 0; i < chances; i++)
|
|
|
- {
|
|
|
- // generates position in chunk
|
|
|
- pos = new BlockPos(x + r.nextInt(16), minY + r.nextInt(deltaY), z + r.nextInt(16));
|
|
|
- generator.place(w, cg, r, pos, config);
|
|
|
- }
|
|
|
+ // | max | bottom | top | max | spawn |
|
|
|
+ // name | size | offset | offset | high | tries |
|
|
|
+ // ---------------------------------------------------
|
|
|
+ // coal | 17 | 0 | 0 | 128 | 20 |
|
|
|
+ // iron | 9 | 0 | 0 | 64 | 20 |
|
|
|
+ // gold | 9 | 0 | 0 | 32 | 2 |
|
|
|
+ // redstone | 8 | 0 | 0 | 16 | 8 |
|
|
|
+ // diamond | 8 | 0 | 0 | 16 | 1 |
|
|
|
+ // lapis | 7 | - | - | - | - |
|
|
|
+ // copper | 9 | 0 | 0 | 128 | 25 |
|
|
|
+ // tin | 6 | 0 | 0 | 96 | 12 |
|
|
|
+ // silver | 9 | 0 | 0 | 64 | 3 |
|
|
|
+
|
|
|
+ biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(
|
|
|
+ Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,
|
|
|
+ ModBlocks.copperOre.getDefaultState(), 9), Placement.COUNT_RANGE,
|
|
|
+ new CountRangeConfig(25, 0, 0, 128)));
|
|
|
+ biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(
|
|
|
+ Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,
|
|
|
+ ModBlocks.tinOre.getDefaultState(), 6), Placement.COUNT_RANGE,
|
|
|
+ new CountRangeConfig(12, 0, 0, 96)));
|
|
|
+ biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(
|
|
|
+ Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,
|
|
|
+ ModBlocks.silverOre.getDefaultState(), 9), Placement.COUNT_RANGE,
|
|
|
+ new CountRangeConfig(3, 0, 0, 64)));
|
|
|
}
|
|
|
}
|