Completed configurable cactus gen

This commit is contained in:
Adubbz 2015-02-01 10:47:40 +11:00
parent 8a5ef81dcd
commit c2ec7df86d
9 changed files with 116 additions and 28 deletions

2
Mixin

@ -1 +1 @@
Subproject commit 116ecb0458d31c055c43d10db2670f513b59b27c
Subproject commit 9defcd6245c783d3a685c7bc8530b59a31fc928f

View file

@ -10,11 +10,15 @@ package biomesoplenty.api.biome;
import java.util.Map;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
public interface IExtendedDecorator
{
public void addGenerator(String key, IGenerator<?> generator, Decorate.EventType nextFeature);
public void addGenerator(String key, IGenerator<?> generator);
public void configureGenerators(Map<String, IGenerator<?>> generatorMap);
public Map<String, IGenerator<?>> getGeneratorMap();
public Decorate.EventType getGeneratorStage(String key);
}

View file

@ -8,10 +8,17 @@
package biomesoplenty.api.biome;
import java.util.Random;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import com.google.gson.JsonElement;
public interface IGenerator<T>
{
public void generate(World world, Random random, BlockPos pos);
public JsonElement serialize(IGenerator<T> src);
public IGenerator<T> deserialize(JsonElement json);

View file

@ -15,6 +15,7 @@ import java.util.Map.Entry;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.gen.feature.WorldGenCactus;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
import org.apache.commons.io.FileUtils;
@ -140,7 +141,8 @@ public class BiomeConfigurationHandler
IExtendedCactusGen extendedCactusGen = (IExtendedCactusGen) cactusGen;
extendedCactusGen.setCactiPerChunk(biome.theBiomeDecorator.cactiPerChunk);
extendedDecorator.addGenerator("cactus", extendedCactusGen);
extendedDecorator.addGenerator("cactus", extendedCactusGen, Decorate.EventType.CACTUS);
biome.theBiomeDecorator.cactiPerChunk = 0;
}
}
}

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright 2014-2015, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.handler.decoration;
import java.util.Map.Entry;
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.fml.common.eventhandler.SubscribeEvent;
import biomesoplenty.api.biome.IExtendedDecorator;
import biomesoplenty.api.biome.IGenerator;
public class DecorateBiomeEventHandler
{
@SubscribeEvent
public void onBiomeDecorate(DecorateBiomeEvent.Decorate event)
{
World world = event.world;
BlockPos pos = event.pos.add(16, 0, 16);
BiomeGenBase biome = world.getBiomeGenForCoords(pos);
IExtendedDecorator extendedDecorator = (IExtendedDecorator)biome.theBiomeDecorator;
for (Entry<String, IGenerator<?>> entry : extendedDecorator.getGeneratorMap().entrySet())
{
String key = entry.getKey();
IGenerator<?> generator = entry.getValue();
if (extendedDecorator.getGeneratorStage(key) == event.type)
{
generator.generate(world, event.rand, event.pos);
}
}
}
}

View file

@ -8,14 +8,16 @@
package biomesoplenty.common.init;
import net.minecraftforge.common.MinecraftForge;
import biomesoplenty.common.handler.BlockModelRegisterEventHandler;
import biomesoplenty.common.handler.DrawScreenEventHandler;
import net.minecraftforge.common.MinecraftForge;
import biomesoplenty.common.handler.decoration.DecorateBiomeEventHandler;
public class ModHandlers
{
public static void init()
{
MinecraftForge.TERRAIN_GEN_BUS.register(new DecorateBiomeEventHandler());
MinecraftForge.EVENT_BUS.register(new BlockModelRegisterEventHandler());
MinecraftForge.EVENT_BUS.register(new DrawScreenEventHandler());
}

View file

@ -13,6 +13,7 @@ import java.util.HashMap;
import java.util.Map;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@ -25,18 +26,21 @@ import biomesoplenty.api.biome.IGenerator;
@Mixin(BiomeDecorator.class)
public class MixinBiomeDecorator implements IExtendedDecorator
{
private Map<String, IGenerator<?>> generatorMap;
private Map<String, IGenerator<?>> generatorMap = new HashMap();
//TODO: Come up with a better sequencing system
private Map<String, Decorate.EventType> generatorSequenceMap = new HashMap();
@Inject(method = "<init>", at = @At("RETURN"))
private void onConstructed(CallbackInfo callbackInfo)
@Override
public void addGenerator(String key, IGenerator<?> generator, Decorate.EventType nextFeature)
{
this.generatorMap = new HashMap();
this.generatorMap.put(key, generator);
this.generatorSequenceMap.put(key, nextFeature);
}
@Override
public void addGenerator(String key, IGenerator<?> generator)
{
this.generatorMap.put(key, generator);
this.addGenerator(key, generator, Decorate.EventType.CUSTOM);
}
@Override
@ -50,4 +54,10 @@ public class MixinBiomeDecorator implements IExtendedDecorator
{
return Collections.unmodifiableMap(this.generatorMap);
}
@Override
public Decorate.EventType getGeneratorStage(String key)
{
return generatorSequenceMap.get(key);
}
}

View file

@ -8,9 +8,11 @@
package biomesoplenty.common.mixin.biome;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraft.world.biome.BiomeGenBase;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -21,12 +23,16 @@ import biomesoplenty.api.biome.IExtendedBiome;
@Mixin(BiomeGenBase.class)
public abstract class MixinBiomeGenBase implements IExtendedBiome
{
private BiomeOwner biomeOwner;
@Shadow
public BiomeDecorator theBiomeDecorator;
private BiomeOwner biomeOwner = BiomeOwner.OTHER;
@Inject(method = "<init>(IZ)V", at = @At("RETURN"))
private void onConstructed(int biomeId, boolean register, CallbackInfo callbackInfo)
{
this.biomeOwner = BiomeOwner.OTHER;
//Prevents Forge from wiping all of our added data
this.theBiomeDecorator = new BiomeDecorator();
}
@Override

View file

@ -8,9 +8,15 @@
package biomesoplenty.common.mixin.decoration;
import java.util.Random;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenCactus;
import net.minecraft.world.gen.feature.WorldGenerator;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin;
import biomesoplenty.api.biome.IGenerator;
@ -20,24 +26,34 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@Mixin(WorldGenCactus.class)
public abstract class MixinWorldGenCactus extends WorldGenerator implements IExtendedCactusGen
@Implements(@Interface(iface = IExtendedCactusGen.class, prefix = "extendedCactus$"))
public abstract class MixinWorldGenCactus extends WorldGenerator //implements IExtendedCactusGen
{
private int cactiPerChunk;
@Override
public void setCactiPerChunk(int amount)
public void extendedCactus$generate(World world, Random random, BlockPos pos)
{
for (int i = 0; i < cactiPerChunk; i++)
{
int x = random.nextInt(16) + 8;
int z = random.nextInt(16) + 8;
int y = random.nextInt(world.getHorizon(pos.add(x, 0, z)).getY() * 2);
this.generate(world, random, pos.add(x, y, z));
}
}
public void extendedCactus$setCactiPerChunk(int amount)
{
this.cactiPerChunk = amount;
}
@Override
public int getCactiPerChunk()
public int extendedCactus$getCactiPerChunk()
{
return this.cactiPerChunk;
}
@Override
public JsonElement serialize(IGenerator<WorldGenCactus> src)
public JsonElement extendedCactus$serialize(IGenerator<WorldGenCactus> src)
{
JsonObject jsonCactusGen = new JsonObject();
@ -46,8 +62,7 @@ public abstract class MixinWorldGenCactus extends WorldGenerator implements IExt
return jsonCactusGen;
}
@Override
public IGenerator<WorldGenCactus> deserialize(JsonElement json)
public IGenerator<WorldGenCactus> extendedCactus$deserialize(JsonElement json)
{
JsonObject jsonCactusGen = json.getAsJsonObject();
WorldGenCactus cactusGen = new WorldGenCactus();
@ -55,6 +70,6 @@ public abstract class MixinWorldGenCactus extends WorldGenerator implements IExt
extendedCactusGen.setCactiPerChunk(jsonCactusGen.get("cacti_per_chunk").getAsInt());
return (IGenerator<WorldGenCactus>) new WorldGenCactus();
return extendedCactusGen;
}
}