Hooked up generator stages with the appropriate events
This commit is contained in:
parent
7d5446375c
commit
7ace8f34f7
6 changed files with 93 additions and 32 deletions
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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<BiomeType, Integer> getWeightMap();
|
||||
public void clearWeights();
|
||||
|
|
|
@ -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<IGenerator<?>> getGeneratorsForStage(GeneratorStage stage)
|
||||
{
|
||||
return this.generatorTable.rowMap().get(stage).values();
|
||||
}
|
||||
|
||||
public Map<String, IGenerator<?>> createGeneratorMap()
|
||||
{
|
||||
Map<String, IGenerator<?>> result = new HashMap<String, IGenerator<?>>();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -8,24 +8,46 @@
|
|||
|
||||
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);
|
||||
|
||||
|
@ -33,16 +55,10 @@ public class DecorateBiomeEventHandler
|
|||
{
|
||||
GenerationManager generationManager = extendedBiome.getGenerationManager();
|
||||
|
||||
for (Entry<String, IGenerator<?>> 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);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue