Toying with biome decoration, *hopefully* fixed errors with iPosition

This commit is contained in:
Adubbz 2013-12-30 10:35:41 +11:00
parent 2280ffbb8e
commit 793a680f31
11 changed files with 232 additions and 5 deletions

View file

@ -0,0 +1,6 @@
package biomesoplenty.api;
public class BOPBiomeHelper
{
}

View file

@ -1,5 +1,7 @@
package biomesoplenty.common.core;
import biomesoplenty.common.world.ForcedDecorators;
import biomesoplenty.common.world.WorldGenFieldAssociation;
import biomesoplenty.common.world.WorldTypeBOP;
public class BOPBiomes
@ -9,6 +11,8 @@ public class BOPBiomes
public static void init()
{
initializeBiomes();
WorldGenFieldAssociation.init();
ForcedDecorators.init();
}
private static void initializeBiomes()

View file

@ -1,7 +1,7 @@
package biomesoplenty.common.entities.projectiles.dispenser;
import net.minecraft.dispenser.BehaviorProjectileDispense;
import net.minecraft.dispenser.iPosition;
import net.minecraft.dispenser.IPosition;
import net.minecraft.entity.IProjectile;
import net.minecraft.world.World;
import biomesoplenty.common.entities.projectiles.EntityDart;
@ -9,7 +9,7 @@ import biomesoplenty.common.entities.projectiles.EntityDart;
public class DispenserBehaviourDart extends BehaviorProjectileDispense
{
@Override
protected IProjectile getProjectileEntity(World world, iPosition iPosition)
protected IProjectile getProjectileEntity(World world, IPosition iPosition)
{
return new EntityDart(world, iPosition.getX(), iPosition.getY(), iPosition.getZ());
}

View file

@ -1,7 +1,7 @@
package biomesoplenty.common.entities.projectiles.dispenser;
import net.minecraft.dispenser.BehaviorProjectileDispense;
import net.minecraft.dispenser.iPosition;
import net.minecraft.dispenser.IPosition;
import net.minecraft.entity.IProjectile;
import net.minecraft.world.World;
import biomesoplenty.common.entities.projectiles.EntityMudball;
@ -9,8 +9,8 @@ import biomesoplenty.common.entities.projectiles.EntityMudball;
public class DispenserBehaviourMudball extends BehaviorProjectileDispense
{
@Override
protected IProjectile getProjectileEntity(World world, iPosition par2IPosition)
protected IProjectile getProjectileEntity(World world, IPosition iPosition)
{
return new EntityMudball(world, par2IPosition.getX(), par2IPosition.getY(), par2IPosition.getZ());
return new EntityMudball(world, iPosition.getX(), iPosition.getY(), iPosition.getZ());
}
}

View file

@ -7,16 +7,23 @@ import biomesoplenty.common.eventhandler.entity.TemptEventHandler;
import biomesoplenty.common.eventhandler.misc.CapeEventHandler;
import biomesoplenty.common.eventhandler.potions.PotionParalysisEventHandler;
import biomesoplenty.common.eventhandler.potions.PotionPossessionEventHandler;
import biomesoplenty.common.eventhandler.world.DecorateBiomeEventHandler;
public class BOPCommonEventHandlers
{
public static void init()
{
registerWorldEventHandlers();
registerEntityEventHandlers();
registerPotionEventHandlers();
registerMiscEventHandlers();
}
private static void registerWorldEventHandlers()
{
MinecraftForge.EVENT_BUS.register(new DecorateBiomeEventHandler());
}
private static void registerEntityEventHandlers()
{
MinecraftForge.EVENT_BUS.register(new DyeEventHandler());

View file

@ -0,0 +1,57 @@
package biomesoplenty.common.eventhandler.world;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
import biomesoplenty.common.world.ForcedDecorators;
import biomesoplenty.common.world.IBOPDecoration;
import biomesoplenty.common.world.WorldGenFieldAssociation;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class DecorateBiomeEventHandler
{
@SubscribeEvent
public void onBiomeDecorate(DecorateBiomeEvent.Pre event)
{
World world = event.world;
int chunkX = event.chunkX;
int chunkZ = event.chunkZ;
Random random = event.rand;
BiomeGenBase biome = world.getBiomeGenForCoordsBody(chunkX / 16, chunkZ / 16);
IBOPDecoration bopDecoration = null;
if (biome instanceof IBOPDecoration)
{
bopDecoration = (IBOPDecoration)biome;
}
else if (ForcedDecorators.biomeHasForcedDecorator(biome))
{
bopDecoration = ForcedDecorators.getForcedDecorator(biome.biomeID);
}
if (bopDecoration != null)
{
for (String worldGeneratorField : WorldGenFieldAssociation.getDeclaredFields())
{
int worldGenPerChunk = bopDecoration.getWorldGenPerChunk(worldGeneratorField);
for (int i = 0; i < worldGenPerChunk; i++)
{
int x = chunkX + random.nextInt(16) + 8;
int z = chunkZ + random.nextInt(16) + 8;
WorldGenerator worldGenerator = WorldGenFieldAssociation.getAssociatedWorldGenerator(worldGeneratorField);
worldGenerator.generate(world, random, x, world.getTopSolidOrLiquidBlock(x, z), z);
}
}
}
}
}

View file

@ -0,0 +1,36 @@
package biomesoplenty.common.world;
import java.util.HashMap;
import net.minecraft.world.biome.BiomeGenBase;
import biomesoplenty.common.world.forceddecorators.SwampForcedDecorator;
public class ForcedDecorators
{
public static HashMap<Integer, IBOPDecoration> forcedDecoratorMap = new HashMap();
public static void init()
{
addForcedDecorators();
}
private static void addForcedDecorators()
{
addForcedDecorator(BiomeGenBase.swampland.biomeID, new SwampForcedDecorator());
}
public static void addForcedDecorator(int biomeID, IBOPDecoration decorator)
{
forcedDecoratorMap.put(biomeID, decorator);
}
public static IBOPDecoration getForcedDecorator(int biomeID)
{
return forcedDecoratorMap.get(biomeID);
}
public static boolean biomeHasForcedDecorator(BiomeGenBase biome)
{
return forcedDecoratorMap.containsKey(biome.biomeID);
}
}

View file

@ -0,0 +1,6 @@
package biomesoplenty.common.world;
public interface IBOPDecoration
{
public int getWorldGenPerChunk(String fieldName);
}

View file

@ -0,0 +1,37 @@
package biomesoplenty.common.world;
import java.util.HashMap;
import java.util.Set;
import net.minecraft.world.gen.feature.WorldGenerator;
import biomesoplenty.common.world.generators.WorldGenMud;
public class WorldGenFieldAssociation
{
public static HashMap<String, WorldGenerator> worldGeneratorMap = new HashMap();
public static void init()
{
associateFieldsWithGenerators();
}
private static void associateFieldsWithGenerators()
{
associateField("mudPerChunk", new WorldGenMud(7));
}
public static void associateField(String fieldName, WorldGenerator generator)
{
worldGeneratorMap.put(fieldName, generator);
}
public static WorldGenerator getAssociatedWorldGenerator(String fieldName)
{
return worldGeneratorMap.get(fieldName);
}
public static Set<String> getDeclaredFields()
{
return worldGeneratorMap.keySet();
}
}

View file

@ -0,0 +1,14 @@
package biomesoplenty.common.world.forceddecorators;
import biomesoplenty.common.world.IBOPDecoration;
public class SwampForcedDecorator implements IBOPDecoration
{
@Override
public int getWorldGenPerChunk(String fieldName)
{
if (fieldName.equals("mudPerChunk")) return 9;
return 0;
}
}

View file

@ -0,0 +1,60 @@
package biomesoplenty.common.world.generators;
import java.util.Random;
import biomesoplenty.api.BOPBlockHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
public class WorldGenMud extends WorldGenerator
{
/** The maximum radius used when generating a patch of blocks. */
private int radius;
public WorldGenMud(int radius)
{
this.radius = radius;
}
@Override
public boolean generate(World world, Random random, int x, int y, int z)
{
//TODO: getBlock() getMaterial() water
if (world.func_147439_a(x, y, z).func_149688_o() != Material.field_151586_h)
return false;
else
{
int var6 = random.nextInt(radius - 2) + 2;
byte var7 = 2;
for (int var8 = x - var6; var8 <= x + var6; ++var8)
{
for (int var9 = z - var6; var9 <= z + var6; ++var9)
{
int var10 = var8 - x;
int var11 = var9 - z;
if (var10 * var10 + var11 * var11 <= var6 * var6)
{
for (int var12 = y - var7; var12 <= y + var7; ++var12)
{
//TODO: getBlock()
Block block = world.func_147439_a(var8, var12, var9);
if (block == Blocks.dirt || block == Blocks.grass)
{
//TODO: setBlock()
world.func_147449_b(var8, var12, var9, BOPBlockHelper.get("mud"));
}
}
}
}
}
return true;
}
}
}