From f750b9d4453cd3e98b6691a21029ef452ef07d22 Mon Sep 17 00:00:00 2001 From: Matt Caughey Date: Thu, 19 Sep 2013 22:45:21 -0400 Subject: [PATCH] Added a way to grow tiny cacti and cattails with bonemeal --- .../handlers/BonemealHandler.java | 28 ++++++++++ .../worldgen/WorldGenCattailBonemeal.java | 54 +++++++++++++++++++ .../worldgen/WorldGenDesertCactus.java | 54 +++++++------------ 3 files changed, 100 insertions(+), 36 deletions(-) create mode 100644 common/biomesoplenty/worldgen/WorldGenCattailBonemeal.java diff --git a/common/biomesoplenty/handlers/BonemealHandler.java b/common/biomesoplenty/handlers/BonemealHandler.java index 0e837e493..c3357cc55 100644 --- a/common/biomesoplenty/handlers/BonemealHandler.java +++ b/common/biomesoplenty/handlers/BonemealHandler.java @@ -7,8 +7,10 @@ import net.minecraftforge.event.entity.player.BonemealEvent; import biomesoplenty.api.Blocks; import biomesoplenty.blocks.BlockBOPColorizedSapling; import biomesoplenty.blocks.BlockBOPSapling; +import biomesoplenty.worldgen.WorldGenDesertCactus; import biomesoplenty.worldgen.WorldGenGiantFlowerRed; import biomesoplenty.worldgen.WorldGenGiantFlowerYellow; +import biomesoplenty.worldgen.WorldGenCattailBonemeal; import biomesoplenty.worldgen.WorldGenKelp; public class BonemealHandler @@ -79,6 +81,32 @@ public class BonemealHandler } } } + else if (event.ID == Blocks.plants.get().blockID && event.world.getBlockMetadata(event.X, event.Y, event.Z) == 12) + { + event.setResult(Result.ALLOW); + + if (!event.world.isRemote) + { + if (event.world.rand.nextFloat() < 0.45D) + { + WorldGenDesertCactus worldgendesertcactus = new WorldGenDesertCactus(); + worldgendesertcactus.generate(event.world, event.world.rand, event.X, event.Y, event.Z); + } + } + } + else if (event.ID == Blocks.plants.get().blockID && event.world.getBlockMetadata(event.X, event.Y, event.Z) == 7) + { + event.setResult(Result.ALLOW); + + if (!event.world.isRemote) + { + if (event.world.rand.nextFloat() < 0.45D) + { + WorldGenCattailBonemeal worldgencattailbonemeal = new WorldGenCattailBonemeal(Blocks.plants.get().blockID, 9); + worldgencattailbonemeal.generate(event.world, event.world.rand, event.X, event.Y, event.Z); + } + } + } else if (event.ID == Block.plantRed.blockID) { event.setResult(Result.ALLOW); diff --git a/common/biomesoplenty/worldgen/WorldGenCattailBonemeal.java b/common/biomesoplenty/worldgen/WorldGenCattailBonemeal.java new file mode 100644 index 000000000..e7a7b1916 --- /dev/null +++ b/common/biomesoplenty/worldgen/WorldGenCattailBonemeal.java @@ -0,0 +1,54 @@ +package biomesoplenty.worldgen; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; +import biomesoplenty.api.Blocks; + +public class WorldGenCattailBonemeal extends WorldGenerator +{ + /** Stores ID for WorldGenHighCattail */ + private int highCattailID; + private int highCattailMetadata; + + public WorldGenCattailBonemeal(int par1, int par2) + { + highCattailID = par1; + highCattailMetadata = par2; + } + + @Override + public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) + { + int var11; + + for (boolean var6 = false; ((var11 = par1World.getBlockId(par3, par4, par5)) == 0 || var11 == Block.leaves.blockID) && par4 > 0; --par4) + { + ; + } + + for (int var7 = 0; var7 < 128; ++var7) + { + int var8 = par3; + int var9 = par4; + int var10 = par5; + + int var999 = par1World.getBlockId(par3, par4, par5); + int var998 = par1World.getBlockMetadata(par3, par4, par5); + + if (var999 == Blocks.plants.get().blockID && var998 == 7 && Block.blocksList[highCattailID].canBlockStay(par1World, var8, var9, var10)) + { + if (par1World.getBlockMaterial(var8 - 1, var9 - 1, var10) == Material.water ? true : (par1World.getBlockMaterial(var8 + 1, var9 - 1, var10) == Material.water ? true : (par1World.getBlockMaterial(var8, var9 - 1, var10 - 1) == Material.water ? true : par1World.getBlockMaterial(var8, var9 - 1, var10 + 1) == Material.water))) + { + par1World.setBlock(var8, var9, var10, Blocks.plants.get().blockID, 10, 2); + par1World.setBlock(var8, var9 + 1, var10, Blocks.plants.get().blockID, 9, 2); + } + } + } + + return true; + } +} diff --git a/common/biomesoplenty/worldgen/WorldGenDesertCactus.java b/common/biomesoplenty/worldgen/WorldGenDesertCactus.java index 344d616eb..c4ed86d09 100644 --- a/common/biomesoplenty/worldgen/WorldGenDesertCactus.java +++ b/common/biomesoplenty/worldgen/WorldGenDesertCactus.java @@ -2,49 +2,31 @@ package biomesoplenty.worldgen; import java.util.Random; +import biomesoplenty.api.Blocks; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; -import biomesoplenty.api.Blocks; public class WorldGenDesertCactus extends WorldGenerator { - @Override - public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) - { - for (int var6 = 0; var6 < 10; ++var6) - { - int var7 = par3 + par2Random.nextInt(8) - par2Random.nextInt(8); - int var8 = par4 + par2Random.nextInt(4) - par2Random.nextInt(4); - int var9 = par5 + par2Random.nextInt(8) - par2Random.nextInt(8); + public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) + { + int var999 = par1World.getBlockId(par3, par4, par5); + int var998 = par1World.getBlockMetadata(par3, par4, par5); - if (par1World.isAirBlock(var7, var8, var9)) - { - if (!par1World.isAirBlock(var7 - 1, var8 - 1, var9)) - { - if (!par1World.isAirBlock(var7 + 1, var8 - 1, var9)) - { - if (!par1World.isAirBlock(var7, var8 - 1, var9 - 1)) - { - if (!par1World.isAirBlock(var7, var8 - 1, var9 + 1)) - { - int var10 = 2 + par2Random.nextInt(par2Random.nextInt(2) + 2); + if (var999 == Blocks.plants.get().blockID && var998 == 12) + { + int l1 = 1 + par2Random.nextInt(par2Random.nextInt(3) + 1); - for (int var11 = 0; var11 < var10; ++var11) - { - if (Blocks.plants.get().canBlockStay(par1World, var7, var8 + var11, var9)) - { - par1World.setBlock(var7, var8 - 1, var9, Block.sand.blockID); - par1World.setBlock(var7, var8 + var11, var9, Block.cactus.blockID); - } - } - } - } - } - } - } - } + for (int i2 = 0; i2 < l1; ++i2) + { + if (Block.cactus.canBlockStay(par1World, par3, par4 + i2, par5)) + { + par1World.setBlock(par3, par4 + i2, par5, Block.cactus.blockID, 0, 2); + } + } + } - return true; - } + return true; + } }