From 1fcd033e637ebc7a1cb94139fe2a06f2f6faa1eb Mon Sep 17 00:00:00 2001 From: zelophed Date: Thu, 5 Dec 2019 15:54:11 +0100 Subject: [PATCH] added foundation for basic ore generation Signed-off-by: Zelophed --- src/main/java/com/simibubi/create/Create.java | 8 ++ .../foundation/world/OreGeneration.java | 102 ++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/main/java/com/simibubi/create/foundation/world/OreGeneration.java diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 8e571000c..7a620c158 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -1,5 +1,6 @@ package com.simibubi.create; +import com.simibubi.create.foundation.world.OreGeneration; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -51,6 +52,7 @@ public class Create { public Create() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(Create::init); + modEventBus.addListener(Create::preInit); modEventBus.addGenericListener(Block.class, Create::registerBlocks); modEventBus.addGenericListener(Item.class, Create::registerItems); modEventBus.addGenericListener(IRecipeSerializer.class, Create::registerRecipes); @@ -66,6 +68,12 @@ public class Create { ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CreateClientConfig.specification); } + public static void preInit(FMLCommonSetupEvent event) { + + OreGeneration.setupOreGeneration(); + + } + public static void init(final FMLCommonSetupEvent event) { schematicReceiver = new ServerSchematicLoader(); frequencyHandler = new FrequencyHandler(); diff --git a/src/main/java/com/simibubi/create/foundation/world/OreGeneration.java b/src/main/java/com/simibubi/create/foundation/world/OreGeneration.java new file mode 100644 index 000000000..645174f14 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/world/OreGeneration.java @@ -0,0 +1,102 @@ +package com.simibubi.create.foundation.world; + +import com.simibubi.create.AllBlocks; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biomes; +import net.minecraft.world.gen.GenerationStage; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.OreFeatureConfig; +import net.minecraft.world.gen.placement.CountRangeConfig; +import net.minecraft.world.gen.placement.Placement; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public enum OreGeneration { + + TEST_BLOB_1(new BasicOreGenConfig(Blocks.EMERALD_BLOCK, 25, 2, 128)), + TEST_BLOB_2(new BasicOreGenConfig(Blocks.QUARTZ_BLOCK, 41, 3, 25)), + TEST_BLOB_3(new OnlyInBiomes(new BasicOreGenConfig(Blocks.BLUE_GLAZED_TERRACOTTA, 5, 10, 30), Biome.Category.OCEAN)), + TEST_BLOB_4(new OnlyInBiomes(new BasicOreGenConfig(AllBlocks.GABBRO.get(), 31, 2, 128), Biomes.TAIGA, Biomes.TAIGA_HILLS, Biomes.TAIGA_MOUNTAINS)), + + ; + + IOreGenConfig config; + + OreGeneration(IOreGenConfig oreGenConfig) { + this.config = oreGenConfig; + } + + public static void setupOreGeneration() { + + for (Biome biome : + ForgeRegistries.BIOMES) { + + Arrays.stream(values()).forEach(oreGen -> oreGen.config.addFeature(biome)); + } + } + + private static class BasicOreGenConfig implements IOreGenConfig { + + Block block; + //im not 100% certain that these names are accurate but at least they seem that way + int clusterSize, clusterCount/*per chunk*/, maxHeight; + + private BasicOreGenConfig(Block block, int clusterSize, int clusterCount, int maxHeight) { + this.block = block; + this.clusterSize = clusterSize; + this.clusterCount = clusterCount; + this.maxHeight = maxHeight; + } + + @Override + public void addFeature(Biome biome) { + biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, + Biome.createDecoratedFeature(Feature.ORE, + new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, + block.getDefaultState(), clusterSize), + Placement.COUNT_RANGE, new CountRangeConfig(clusterCount, 0, 0, maxHeight))); + } + + } + + private static class OnlyInBiomes implements IOreGenConfig { + + //not sure if this is really needed but w/e + + IOreGenConfig config; + List biomes; + + private OnlyInBiomes(IOreGenConfig config, Biome... biomes) { + this.config = config; + this.biomes = Arrays.asList(biomes); + } + + private OnlyInBiomes(IOreGenConfig config, Biome.Category category){ + this.config = config; + this.biomes = new LinkedList<>(); + for (Biome biome: + ForgeRegistries.BIOMES) { + if (biome.getCategory() == category) + biomes.add(biome); + } + } + + @Override + public void addFeature(Biome biome) { + if (biomes.contains(biome)) { + config.addFeature(biome); + } + } + } + + private interface IOreGenConfig { + + void addFeature(Biome biome); + + } +}