BiomesOPlenty/common/biomesoplenty/worldgen/tree/WorldGenPineTree.java

127 lines
3.8 KiB
Java
Raw Normal View History

2013-09-14 10:16:39 +00:00
package biomesoplenty.worldgen.tree;
2013-05-25 21:31:11 +00:00
import java.util.Random;
import net.minecraft.block.Block;
2013-09-29 09:16:32 +00:00
import net.minecraft.block.material.Material;
2013-05-25 21:31:11 +00:00
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import biomesoplenty.api.Blocks;
2013-05-25 21:31:11 +00:00
public class WorldGenPineTree extends WorldGenerator
{
2013-05-31 10:34:02 +00:00
@Override
public boolean generate(World var1, Random var2, int var3, int var4, int var5)
{
while (var1.isAirBlock(var3, var4, var5) && var4 > 2)
{
--var4;
}
int var6 = var1.getBlockId(var3, var4, var5);
if (var6 != Block.grass.blockID && var6 != Blocks.hardDirt.get().blockID && var6 != Block.stone.blockID && var6 != Block.dirt.blockID)
2013-09-29 09:16:32 +00:00
{
2013-05-31 10:34:02 +00:00
return false;
2013-09-29 09:16:32 +00:00
}
2013-05-31 10:34:02 +00:00
else
{
for (int var7 = -2; var7 <= 2; ++var7)
{
for (int var8 = -2; var8 <= 2; ++var8)
{
if (var1.isAirBlock(var3 + var7, var4 - 1, var5 + var8) && var1.isAirBlock(var3 + var7, var4 - 2, var5 + var8) && !var1.isAirBlock(var3 + var7, var4, var5 + var8))
2013-09-29 09:16:32 +00:00
{
2013-05-31 10:34:02 +00:00
return false;
2013-09-29 09:16:32 +00:00
}
2013-05-31 10:34:02 +00:00
}
}
2013-09-29 09:16:32 +00:00
//settings========
int baselength = 4 + var2.nextInt(4);
int branches = 1 + var2.nextInt(3);
//================
int h = 1;
buildBlock(var1, var3, var4, var5, Block.dirt.blockID, 0);
for(int b = 0; b < baselength; b++)
2013-05-25 21:31:11 +00:00
{
2013-09-29 09:16:32 +00:00
buildBlock(var1, var3, var4 + h, var5, Blocks.logs4.get().blockID, 0);
h++;
2013-05-25 21:31:11 +00:00
}
2013-09-29 09:16:32 +00:00
int c = 1;
for(int r = 0; r < branches; r++)
2013-05-25 21:31:11 +00:00
{
2013-09-29 09:16:32 +00:00
generateBranch(var1, var2, var3, var4 + h, var5, c);
c++;
h+=2;
2013-05-25 21:31:11 +00:00
}
2013-09-29 09:16:32 +00:00
generateTop(var1, var3, var4 + h, var5);
2013-05-25 21:31:11 +00:00
return true;
2013-05-31 10:34:02 +00:00
}
}
2013-09-29 09:16:32 +00:00
public void generateTop(World world, int x, int y, int z)
{
for(int i = -1; i < 2; i++)
{
for(int j = -1; j < 2; j++)
{
buildBlock(world, x + i, y, z + j, Blocks.leavesColorized.get().blockID, 5);
}
}
buildBlock(world, x, y, z, Blocks.logs4.get().blockID, 0);
buildBlock(world, x + 1, y + 1, z, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x, y + 1, z - 1, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x, y + 1, z + 1, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x - 1, y + 1, z, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x, y + 2, z, Blocks.leavesColorized.get().blockID, 5);
}
public void generateBranch(World world, Random rand, int x, int y, int z, int n)
{
for(int i = -1; i < 2; i++)
{
for(int j = -1; j < 2; j++)
{
buildBlock(world, x + i, y, z + j, Blocks.leavesColorized.get().blockID, 5);
}
}
if(n % 2 == 0)
{
buildBlock(world, x + 1, y, z - 2, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x + 2, y, z - 2, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x + 2, y, z - 1, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x - 2, y, z + 1, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x - 2, y, z + 2, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x - 1, y, z + 2, Blocks.leavesColorized.get().blockID, 5);
}
else
{
buildBlock(world, x + 2, y, z + 1, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x + 2, y, z + 2, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x + 1, y, z + 2, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x - 1, y, z - 2, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x - 2, y, z - 2, Blocks.leavesColorized.get().blockID, 5);
buildBlock(world, x - 2, y, z - 1, Blocks.leavesColorized.get().blockID, 5);
}
buildBlock(world, x, y, z, Blocks.logs4.get().blockID, 0);
buildBlock(world, x, y + 1, z, Blocks.logs4.get().blockID, 0);
}
public void buildBlock(World world, int x, int y, int z, int id, int meta)
{
Material m = world.getBlockMaterial(x, y, z);
if(m == Material.air || m == Material.leaves)
{
world.setBlock(x, y, z, id, meta, 2);
}
}
2013-05-25 21:31:11 +00:00
}