From 7ace8f34f7b06459379e10d015b343f25906aacf Mon Sep 17 00:00:00 2001 From: Adubbz Date: Mon, 6 Apr 2015 15:45:11 +1000 Subject: [PATCH] Hooked up generator stages with the appropriate events --- .../biomesoplenty/api/biome/BOPBiome.java | 8 +++ .../api/biome/IExtendedBiome.java | 3 ++ .../biome/generation/GenerationManager.java | 8 ++- .../api/biome/generation/GeneratorStage.java | 54 +++++++++++++------ .../common/biome/ExtendedBiomeRegistry.java | 8 +++ .../decoration/DecorateBiomeEventHandler.java | 44 ++++++++++----- 6 files changed, 93 insertions(+), 32 deletions(-) diff --git a/src/main/java/biomesoplenty/api/biome/BOPBiome.java b/src/main/java/biomesoplenty/api/biome/BOPBiome.java index ce0c2e9ff..4d3926f10 100644 --- a/src/main/java/biomesoplenty/api/biome/BOPBiome.java +++ b/src/main/java/biomesoplenty/api/biome/BOPBiome.java @@ -14,6 +14,8 @@ import java.util.Map; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.BiomeManager.BiomeType; import biomesoplenty.api.biome.generation.GenerationManager; +import biomesoplenty.api.biome.generation.GeneratorStage; +import biomesoplenty.api.biome.generation.IGenerator; public class BOPBiome extends BiomeGenBase implements IExtendedBiome { @@ -38,6 +40,12 @@ public class BOPBiome extends BiomeGenBase implements IExtendedBiome return BiomeOwner.BIOMESOPLENTY; } + @Override + public void addGenerator(String name, GeneratorStage stage, IGenerator generator) + { + this.generationManager.addGenerator(name, stage, generator); + } + @Override public GenerationManager getGenerationManager() { diff --git a/src/main/java/biomesoplenty/api/biome/IExtendedBiome.java b/src/main/java/biomesoplenty/api/biome/IExtendedBiome.java index 61d7df5cb..da3688182 100644 --- a/src/main/java/biomesoplenty/api/biome/IExtendedBiome.java +++ b/src/main/java/biomesoplenty/api/biome/IExtendedBiome.java @@ -11,11 +11,14 @@ package biomesoplenty.api.biome; import java.util.Map; import biomesoplenty.api.biome.generation.GenerationManager; +import biomesoplenty.api.biome.generation.GeneratorStage; +import biomesoplenty.api.biome.generation.IGenerator; import net.minecraftforge.common.BiomeManager.BiomeType; public interface IExtendedBiome { public BiomeOwner getBiomeOwner(); + public void addGenerator(String name, GeneratorStage stage, IGenerator generator); public GenerationManager getGenerationManager(); public Map getWeightMap(); public void clearWeights(); diff --git a/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java b/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java index fea64b552..9f43518d7 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GenerationManager.java @@ -8,6 +8,7 @@ package biomesoplenty.api.biome.generation; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -21,7 +22,7 @@ public class GenerationManager public void addGenerator(String name, GeneratorStage stage, IGenerator generator) { - if (!generatorTable.containsColumn(name)) + if (!this.generatorTable.containsColumn(name)) { generator.setName(name); generator.setStage(stage); @@ -34,6 +35,11 @@ public class GenerationManager } } + public Collection> getGeneratorsForStage(GeneratorStage stage) + { + return this.generatorTable.rowMap().get(stage).values(); + } + public Map> createGeneratorMap() { Map> result = new HashMap>(); diff --git a/src/main/java/biomesoplenty/api/biome/generation/GeneratorStage.java b/src/main/java/biomesoplenty/api/biome/generation/GeneratorStage.java index 77dfda1b4..c71fb697c 100644 --- a/src/main/java/biomesoplenty/api/biome/generation/GeneratorStage.java +++ b/src/main/java/biomesoplenty/api/biome/generation/GeneratorStage.java @@ -8,42 +8,62 @@ package biomesoplenty.api.biome.generation; +import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate; + import com.google.gson.annotations.SerializedName; public enum GeneratorStage { @SerializedName("pre") - PRE, + PRE(null), @SerializedName("big_shroom") - BIG_SHROOM, + BIG_SHROOM(Decorate.EventType.BIG_SHROOM), @SerializedName("cactus") - CACTUS, + CACTUS(Decorate.EventType.CACTUS), @SerializedName("clay") - CLAY, + CLAY(Decorate.EventType.CLAY), @SerializedName("dead_bush") - DEAD_BUSH, + DEAD_BUSH(Decorate.EventType.DEAD_BUSH), @SerializedName("lilypad") - LILYPAD, + LILYPAD(Decorate.EventType.LILYPAD), @SerializedName("flowers") - FLOWERS, + FLOWERS(Decorate.EventType.FLOWERS), @SerializedName("grass") - GRASS, + GRASS(Decorate.EventType.GRASS), @SerializedName("lake_water") - LAKE_WATER, + LAKE_WATER(Decorate.EventType.LAKE_WATER), @SerializedName("lake_lava") - LAKE_LAVA, + LAKE_LAVA(Decorate.EventType.LAKE_LAVA), @SerializedName("pumpkin") - PUMPKIN, + PUMPKIN(Decorate.EventType.PUMPKIN), @SerializedName("reed") - REED, + REED(Decorate.EventType.REED), @SerializedName("sand") - SAND, + SAND(Decorate.EventType.SAND), @SerializedName("sand_pass_2") - SAND_PASS2, + SAND_PASS2(Decorate.EventType.SAND_PASS2), @SerializedName("shroom") - SHROOM, + SHROOM(Decorate.EventType.SHROOM), @SerializedName("tree") - TREE, + TREE(Decorate.EventType.TREE), @SerializedName("post") - POST; + POST(null); + + private Decorate.EventType decorateType; + + private GeneratorStage(Decorate.EventType decorateType) + { + this.decorateType = decorateType; + } + + public Decorate.EventType getDecorateType() + { + return this.decorateType; + } + + public static GeneratorStage mapDecorateType(Decorate.EventType decorateType) + { + //Somewhat of a hack, requires the ordering of our enum to be the s + return decorateType != Decorate.EventType.CUSTOM ? GeneratorStage.values()[decorateType.ordinal() + 1] : null; + } } diff --git a/src/main/java/biomesoplenty/common/biome/ExtendedBiomeRegistry.java b/src/main/java/biomesoplenty/common/biome/ExtendedBiomeRegistry.java index 63df39a56..89ed9f3d2 100644 --- a/src/main/java/biomesoplenty/common/biome/ExtendedBiomeRegistry.java +++ b/src/main/java/biomesoplenty/common/biome/ExtendedBiomeRegistry.java @@ -16,6 +16,8 @@ import net.minecraftforge.common.BiomeManager.BiomeType; import biomesoplenty.api.biome.BiomeOwner; import biomesoplenty.api.biome.IExtendedBiome; import biomesoplenty.api.biome.generation.GenerationManager; +import biomesoplenty.api.biome.generation.GeneratorStage; +import biomesoplenty.api.biome.generation.IGenerator; public class ExtendedBiomeRegistry { @@ -62,6 +64,12 @@ public class ExtendedBiomeRegistry return BiomeOwner.OTHER; } + @Override + public void addGenerator(String name, GeneratorStage stage, IGenerator generator) + { + this.generationManager.addGenerator(name, stage, generator); + } + @Override public GenerationManager getGenerationManager() { diff --git a/src/main/java/biomesoplenty/common/handler/decoration/DecorateBiomeEventHandler.java b/src/main/java/biomesoplenty/common/handler/decoration/DecorateBiomeEventHandler.java index 89b5c51ff..0e95659be 100644 --- a/src/main/java/biomesoplenty/common/handler/decoration/DecorateBiomeEventHandler.java +++ b/src/main/java/biomesoplenty/common/handler/decoration/DecorateBiomeEventHandler.java @@ -8,41 +8,57 @@ package biomesoplenty.common.handler.decoration; -import java.util.Map.Entry; +import java.util.Random; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.event.terraingen.DecorateBiomeEvent; +import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import biomesoplenty.api.biome.IExtendedBiome; +import biomesoplenty.api.biome.generation.GenerationManager; +import biomesoplenty.api.biome.generation.GeneratorStage; import biomesoplenty.api.biome.generation.IGenerator; import biomesoplenty.common.biome.ExtendedBiomeRegistry; public class DecorateBiomeEventHandler { - /*TODO: @SubscribeEvent + @SubscribeEvent + public void onPreBiomeDecorate(DecorateBiomeEvent.Pre event) + { + runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.PRE); + } + + @SubscribeEvent public void onBiomeDecorate(DecorateBiomeEvent.Decorate event) { - World world = event.world; - BlockPos pos = event.pos.add(16, 0, 16); + if (event.type != Decorate.EventType.CUSTOM) + { + runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.mapDecorateType(event.type)); + } + } + + @SubscribeEvent + public void onPostBiomeDecorate(DecorateBiomeEvent.Pre event) + { + runGeneratorStage(event.world, event.rand, event.pos, GeneratorStage.POST); + } + + private static void runGeneratorStage(World world, Random random, BlockPos pos, GeneratorStage stage) + { + pos.add(16, 0, 16); BiomeGenBase biome = world.getBiomeGenForCoords(pos); IExtendedBiome extendedBiome = ExtendedBiomeRegistry.getExtension(biome); if (extendedBiome != null) { GenerationManager generationManager = extendedBiome.getGenerationManager(); - - for (Entry> entry : generationManager.getGeneratorMap().entrySet()) + + for (IGenerator generator : generationManager.getGeneratorsForStage(stage)) { - String key = entry.getKey(); - IGenerator generator = entry.getValue(); - - if (generationManager.getGeneratorStage(key) == event.type) - { - generator.generate(world, event.rand, event.pos); - } + generator.generate(world, random, pos); } } - }*/ + } }