From 024d5025a63288ecc6f97825155471e428f446e9 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 12 Jul 2013 09:27:12 +1000 Subject: [PATCH] Made metadata get checked when decided whether a plant can generate in a position. Fixes #11 --- .../biomes/BiomeDecoratorBOP.java | 6 +-- .../biomesoplenty/biomes/BiomeGenPasture.java | 4 +- .../biomes/BiomeGenPastureMeadow.java | 3 +- .../biomes/BiomeGenPastureThin.java | 3 +- .../biomesoplenty/blocks/BlockBOPPlant.java | 5 ++ .../worldgen/WorldGenBOPBush.java | 40 ++++++++++++++ .../worldgen/WorldGenBOPTallGrass.java | 52 +++++++++++++++++++ 7 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 src/minecraft/biomesoplenty/worldgen/WorldGenBOPBush.java create mode 100644 src/minecraft/biomesoplenty/worldgen/WorldGenBOPTallGrass.java diff --git a/src/minecraft/biomesoplenty/biomes/BiomeDecoratorBOP.java b/src/minecraft/biomesoplenty/biomes/BiomeDecoratorBOP.java index 3663d21ad..a7b8d92d7 100644 --- a/src/minecraft/biomesoplenty/biomes/BiomeDecoratorBOP.java +++ b/src/minecraft/biomesoplenty/biomes/BiomeDecoratorBOP.java @@ -54,7 +54,7 @@ import biomesoplenty.worldgen.WorldGenBadlands4; import biomesoplenty.worldgen.WorldGenBoneSpine; import biomesoplenty.worldgen.WorldGenBoneSpine2; import biomesoplenty.worldgen.WorldGenBoulder; -import biomesoplenty.worldgen.WorldGenBush; +import biomesoplenty.worldgen.WorldGenBOPBush; import biomesoplenty.worldgen.WorldGenCanyon; import biomesoplenty.worldgen.WorldGenCanyonGrass; import biomesoplenty.worldgen.WorldGenCattail; @@ -418,7 +418,7 @@ public class BiomeDecoratorBOP extends BiomeDecorator plantDeadGen = new WorldGenBOPFlowers(Blocks.plants.get().blockID, 0); plantDesertGen = new WorldGenBOPFlowers(Blocks.plants.get().blockID, 1); thornGen = new WorldGenBOPFlowers(Blocks.plants.get().blockID, 5); - bushGen = new WorldGenBush(Blocks.foliage.get().blockID, 4); + bushGen = new WorldGenBOPBush(Blocks.foliage.get().blockID, 4); berryBushGen = new WorldGenBOPFlowers(Blocks.foliage.get().blockID, 8); tinyCactusGen = new WorldGenBOPFlowers(Blocks.flowers.get().blockID, 11); aloeGen = new WorldGenBOPFlowers(Blocks.flowers.get().blockID, 12); @@ -429,7 +429,7 @@ public class BiomeDecoratorBOP extends BiomeDecorator duneGrassGen = new WorldGenBOPFlowers(Blocks.plants.get().blockID, 3); holyTallGrassGen = new WorldGenBOPFlowers(Blocks.plants.get().blockID, 4); desertSproutsGen = new WorldGenBOPFlowers(Blocks.plants.get().blockID, 2); - poisonIvyGen = new WorldGenBush(Blocks.foliage.get().blockID, 7); + poisonIvyGen = new WorldGenBOPBush(Blocks.foliage.get().blockID, 7); sunflowerGen = new WorldGenSunflower(Blocks.flowers.get().blockID, 13); promisedWillowGen = new WorldGenPromisedWillow(); netherVineGen = new WorldGenNetherVines(); diff --git a/src/minecraft/biomesoplenty/biomes/BiomeGenPasture.java b/src/minecraft/biomesoplenty/biomes/BiomeGenPasture.java index 617bb9c81..83c35ed81 100644 --- a/src/minecraft/biomesoplenty/biomes/BiomeGenPasture.java +++ b/src/minecraft/biomesoplenty/biomes/BiomeGenPasture.java @@ -5,9 +5,9 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.gen.feature.WorldGenTallGrass; import net.minecraft.world.gen.feature.WorldGenerator; import biomesoplenty.api.Blocks; +import biomesoplenty.worldgen.WorldGenBOPTallGrass; public class BiomeGenPasture extends BiomeGenBase { @@ -50,7 +50,7 @@ public class BiomeGenPasture extends BiomeGenBase @Override public WorldGenerator getRandomWorldGenForGrass(Random par1Random) { - return new WorldGenTallGrass(Blocks.plants.get().blockID, 6); + return new WorldGenBOPTallGrass(Blocks.plants.get().blockID, 6); } /** diff --git a/src/minecraft/biomesoplenty/biomes/BiomeGenPastureMeadow.java b/src/minecraft/biomesoplenty/biomes/BiomeGenPastureMeadow.java index 6243db936..496f73a1f 100644 --- a/src/minecraft/biomesoplenty/biomes/BiomeGenPastureMeadow.java +++ b/src/minecraft/biomesoplenty/biomes/BiomeGenPastureMeadow.java @@ -8,6 +8,7 @@ import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.feature.WorldGenTallGrass; import net.minecraft.world.gen.feature.WorldGenerator; import biomesoplenty.api.Blocks; +import biomesoplenty.worldgen.WorldGenBOPTallGrass; public class BiomeGenPastureMeadow extends BiomeGenBase { @@ -51,7 +52,7 @@ public class BiomeGenPastureMeadow extends BiomeGenBase @Override public WorldGenerator getRandomWorldGenForGrass(Random par1Random) { - return par1Random.nextInt(8) == 0 ? new WorldGenTallGrass(Blocks.plants.get().blockID, 6) : new WorldGenTallGrass(Block.tallGrass.blockID, 1); + return par1Random.nextInt(8) == 0 ? new WorldGenTallGrass(Blocks.plants.get().blockID, 6) : new WorldGenBOPTallGrass(Block.tallGrass.blockID, 1); } /** diff --git a/src/minecraft/biomesoplenty/biomes/BiomeGenPastureThin.java b/src/minecraft/biomesoplenty/biomes/BiomeGenPastureThin.java index ceac35f13..6467d65ed 100644 --- a/src/minecraft/biomesoplenty/biomes/BiomeGenPastureThin.java +++ b/src/minecraft/biomesoplenty/biomes/BiomeGenPastureThin.java @@ -8,6 +8,7 @@ import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.feature.WorldGenTallGrass; import net.minecraft.world.gen.feature.WorldGenerator; import biomesoplenty.api.Blocks; +import biomesoplenty.worldgen.WorldGenBOPTallGrass; public class BiomeGenPastureThin extends BiomeGenBase { @@ -50,7 +51,7 @@ public class BiomeGenPastureThin extends BiomeGenBase @Override public WorldGenerator getRandomWorldGenForGrass(Random par1Random) { - return par1Random.nextInt(3) == 0 ? new WorldGenTallGrass(Block.tallGrass.blockID, 1) : new WorldGenTallGrass(Blocks.plants.get().blockID, 6); + return par1Random.nextInt(3) == 0 ? new WorldGenTallGrass(Block.tallGrass.blockID, 1) : new WorldGenBOPTallGrass(Blocks.plants.get().blockID, 6); } /** diff --git a/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java b/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java index d1aae168d..ab1b7e2a3 100644 --- a/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java +++ b/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java @@ -109,6 +109,8 @@ public class BlockBOPPlant extends BlockFlower implements IShearable return blockID == Blocks.holyGrass.get().blockID; else if (metadata == 5) return blockID == Block.grass.blockID || blockID == Block.dirt.blockID || blockID == Block.slowSand.blockID; + else if (metadata == 6) + return blockID == Block.grass.blockID || blockID == Block.dirt.blockID; else if (metadata == 7) return blockID == Block.grass.blockID; else if (metadata == 8) @@ -150,6 +152,9 @@ public class BlockBOPPlant extends BlockFlower implements IShearable case 5: // Thorns return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.slowSand.blockID; + + case 6: // Barley + return id == Block.grass.blockID || id == Block.dirt.blockID; case 7: // Cattail return id != Block.grass.blockID ? false : (world.getBlockMaterial(x - 1, y - 1, z) == Material.water ? true : (world.getBlockMaterial(x + 1, y - 1, z) == Material.water ? true : (world.getBlockMaterial(x, y - 1, z - 1) == Material.water ? true : world.getBlockMaterial(x, y - 1, z + 1) == Material.water))); diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenBOPBush.java b/src/minecraft/biomesoplenty/worldgen/WorldGenBOPBush.java new file mode 100644 index 000000000..8637ba0d6 --- /dev/null +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenBOPBush.java @@ -0,0 +1,40 @@ +package biomesoplenty.worldgen; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class WorldGenBOPBush extends WorldGenerator +{ + /** The ID of the plant block used in this plant generator. */ + private int plantBlockId; + private int plantBlockMeta; + + public WorldGenBOPBush(int par1, int meta) + { + plantBlockId = par1; + plantBlockMeta = meta; + } + + @Override + public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) + { + for (int var6 = 0; var6 < 64; ++var6) + { + int x = par3 + par2Random.nextInt(8) - par2Random.nextInt(8); + int y = par4 + par2Random.nextInt(4) - par2Random.nextInt(4); + int z = par5 + par2Random.nextInt(8) - par2Random.nextInt(8); + + if (par1World.isAirBlock(x, y, z) && !par1World.provider.hasNoSky && Block.blocksList[plantBlockId].canPlaceBlockOnSide(par1World, x, y, z, 1, new ItemStack(plantBlockId, 1, plantBlockMeta))) + { + par1World.setBlock(x, y, z, plantBlockId, plantBlockMeta, 2); + } + } + + return true; + } +} + diff --git a/src/minecraft/biomesoplenty/worldgen/WorldGenBOPTallGrass.java b/src/minecraft/biomesoplenty/worldgen/WorldGenBOPTallGrass.java new file mode 100644 index 000000000..8e36013d7 --- /dev/null +++ b/src/minecraft/biomesoplenty/worldgen/WorldGenBOPTallGrass.java @@ -0,0 +1,52 @@ +package biomesoplenty.worldgen; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class WorldGenBOPTallGrass extends WorldGenerator +{ + /** Stores ID for WorldGenTallGrass */ + private int tallGrassID; + private int tallGrassMetadata; + + public WorldGenBOPTallGrass(int par1, int par2) + { + this.tallGrassID = par1; + this.tallGrassMetadata = par2; + } + + @Override + public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) + { + int l; + + Block block = null; + do + { + block = Block.blocksList[par1World.getBlockId(par3, par4, par5)]; + if (block != null && !block.isLeaves(par1World, par3, par4, par5)) + { + break; + } + par4--; + } while (par4 > 0); + + for (int i1 = 0; i1 < 128; ++i1) + { + int j1 = par3 + par2Random.nextInt(8) - par2Random.nextInt(8); + int k1 = par4 + par2Random.nextInt(4) - par2Random.nextInt(4); + int l1 = par5 + par2Random.nextInt(8) - par2Random.nextInt(8); + + if (par1World.isAirBlock(j1, k1, l1) && Block.blocksList[tallGrassID].canPlaceBlockOnSide(par1World, j1, k1, l1, 1, new ItemStack(tallGrassID, 1, tallGrassMetadata))) + { + par1World.setBlock(j1, k1, l1, this.tallGrassID, this.tallGrassMetadata, 2); + } + } + + return true; + } +}