257 lines
11 KiB
Java
Executable file
257 lines
11 KiB
Java
Executable file
package game.worldgen.tree;
|
|
|
|
import game.block.Block;
|
|
import game.block.BlockCocoa;
|
|
import game.block.BlockLeaves;
|
|
import game.block.BlockVine;
|
|
import game.init.Blocks;
|
|
import game.material.Material;
|
|
import game.properties.PropertyBool;
|
|
import game.rng.Random;
|
|
import game.world.BlockPos;
|
|
import game.world.Facing;
|
|
import game.world.State;
|
|
import game.world.WorldServer;
|
|
|
|
public class WorldGenBaseTree extends WorldGenTree
|
|
{
|
|
private static final State defLog = Blocks.oak_log.getState(); // .withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.OAK);
|
|
private static final State defLeaves = Blocks.oak_leaves.getState(); // .withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK);
|
|
|
|
private final int minTreeHeight;
|
|
private final boolean vinesGrow;
|
|
private final State metaWood;
|
|
private final State metaLeaves;
|
|
|
|
public WorldGenBaseTree(boolean notify)
|
|
{
|
|
this(notify, 4, defLog, defLeaves, false);
|
|
}
|
|
|
|
public WorldGenBaseTree(boolean notify, State log, State leaves)
|
|
{
|
|
this(notify, 4, log, leaves, false);
|
|
}
|
|
|
|
public WorldGenBaseTree(boolean notify, int minHeight, State log, State leaves, boolean vines)
|
|
{
|
|
super(notify);
|
|
this.minTreeHeight = minHeight;
|
|
this.metaWood = log;
|
|
this.metaLeaves = leaves.withProperty(BlockLeaves.DECAY, Boolean.valueOf(false));
|
|
this.vinesGrow = vines;
|
|
}
|
|
|
|
public boolean generate(WorldServer worldIn, Random rand, BlockPos position)
|
|
{
|
|
int i = rand.zrange(3) + this.minTreeHeight;
|
|
boolean flag = true;
|
|
|
|
if (position.getY() >= 1 && position.getY() + i + 1 <= 512)
|
|
{
|
|
for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
|
|
{
|
|
int k = 1;
|
|
|
|
if (j == position.getY())
|
|
{
|
|
k = 0;
|
|
}
|
|
|
|
if (j >= position.getY() + 1 + i - 2)
|
|
{
|
|
k = 2;
|
|
}
|
|
|
|
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
|
|
|
for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
|
|
{
|
|
for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
|
|
{
|
|
if (j >= 0 && j < 512)
|
|
{
|
|
if (!this.canBeReplaced(worldIn.getState(blockpos$mutableblockpos.set(l, j, i1)).getBlock()))
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
flag = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!flag)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
Block block1 = worldIn.getState(position.down()).getBlock();
|
|
|
|
if ((block1 == Blocks.grass || block1 == Blocks.dirt || block1 == Blocks.farmland || block1 == Blocks.tian_soil) && position.getY() < 512 - i - 1)
|
|
{
|
|
this.setBaseBlock(worldIn, position.down());
|
|
int k2 = 3;
|
|
int l2 = 0;
|
|
|
|
for (int i3 = position.getY() - k2 + i; i3 <= position.getY() + i; ++i3)
|
|
{
|
|
int i4 = i3 - (position.getY() + i);
|
|
int j1 = l2 + 1 - i4 / 2;
|
|
|
|
for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1)
|
|
{
|
|
int l1 = k1 - position.getX();
|
|
|
|
for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2)
|
|
{
|
|
int j2 = i2 - position.getZ();
|
|
|
|
if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.zrange(2) != 0 && i4 != 0)
|
|
{
|
|
BlockPos blockpos = new BlockPos(k1, i3, i2);
|
|
Block block = worldIn.getState(blockpos).getBlock();
|
|
|
|
if (block.getMaterial() == Material.air || block.getMaterial() == Material.leaves || block.getMaterial() == Material.vine)
|
|
{
|
|
this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves.withProperty(BlockLeaves.TYPE, worldIn.getLeavesGen(blockpos)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int j3 = 0; j3 < i; ++j3)
|
|
{
|
|
Block block2 = worldIn.getState(position.up(j3)).getBlock();
|
|
|
|
if (block2.getMaterial() == Material.air || block2.getMaterial() == Material.leaves || block2.getMaterial() == Material.vine)
|
|
{
|
|
this.setBlockAndNotifyAdequately(worldIn, position.up(j3), this.metaWood);
|
|
|
|
if (this.vinesGrow && j3 > 0)
|
|
{
|
|
if (rand.zrange(3) > 0 && worldIn.isAirBlock(position.add(-1, j3, 0)))
|
|
{
|
|
this.func_181651_a(worldIn, position.add(-1, j3, 0), BlockVine.EAST);
|
|
}
|
|
|
|
if (rand.zrange(3) > 0 && worldIn.isAirBlock(position.add(1, j3, 0)))
|
|
{
|
|
this.func_181651_a(worldIn, position.add(1, j3, 0), BlockVine.WEST);
|
|
}
|
|
|
|
if (rand.zrange(3) > 0 && worldIn.isAirBlock(position.add(0, j3, -1)))
|
|
{
|
|
this.func_181651_a(worldIn, position.add(0, j3, -1), BlockVine.SOUTH);
|
|
}
|
|
|
|
if (rand.zrange(3) > 0 && worldIn.isAirBlock(position.add(0, j3, 1)))
|
|
{
|
|
this.func_181651_a(worldIn, position.add(0, j3, 1), BlockVine.NORTH);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (this.vinesGrow)
|
|
{
|
|
for (int k3 = position.getY() - 3 + i; k3 <= position.getY() + i; ++k3)
|
|
{
|
|
int j4 = k3 - (position.getY() + i);
|
|
int k4 = 2 - j4 / 2;
|
|
BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos();
|
|
|
|
for (int l4 = position.getX() - k4; l4 <= position.getX() + k4; ++l4)
|
|
{
|
|
for (int i5 = position.getZ() - k4; i5 <= position.getZ() + k4; ++i5)
|
|
{
|
|
blockpos$mutableblockpos1.set(l4, k3, i5);
|
|
|
|
if (worldIn.getState(blockpos$mutableblockpos1).getBlock().getMaterial() == Material.leaves)
|
|
{
|
|
BlockPos blockpos2 = blockpos$mutableblockpos1.west();
|
|
BlockPos blockpos3 = blockpos$mutableblockpos1.east();
|
|
BlockPos blockpos4 = blockpos$mutableblockpos1.north();
|
|
BlockPos blockpos1 = blockpos$mutableblockpos1.south();
|
|
|
|
if (rand.zrange(4) == 0 && worldIn.getState(blockpos2).getBlock().getMaterial() == Material.air)
|
|
{
|
|
this.func_181650_b(worldIn, blockpos2, BlockVine.EAST);
|
|
}
|
|
|
|
if (rand.zrange(4) == 0 && worldIn.getState(blockpos3).getBlock().getMaterial() == Material.air)
|
|
{
|
|
this.func_181650_b(worldIn, blockpos3, BlockVine.WEST);
|
|
}
|
|
|
|
if (rand.zrange(4) == 0 && worldIn.getState(blockpos4).getBlock().getMaterial() == Material.air)
|
|
{
|
|
this.func_181650_b(worldIn, blockpos4, BlockVine.SOUTH);
|
|
}
|
|
|
|
if (rand.zrange(4) == 0 && worldIn.getState(blockpos1).getBlock().getMaterial() == Material.air)
|
|
{
|
|
this.func_181650_b(worldIn, blockpos1, BlockVine.NORTH);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (rand.zrange(5) == 0 && i > 5)
|
|
{
|
|
for (int l3 = 0; l3 < 2; ++l3)
|
|
{
|
|
for (Facing enumfacing : Facing.Plane.HORIZONTAL)
|
|
{
|
|
if (rand.zrange(4 - l3) == 0)
|
|
{
|
|
Facing enumfacing1 = enumfacing.getOpposite();
|
|
this.func_181652_a(worldIn, rand.zrange(3), position.add(enumfacing1.getFrontOffsetX(), i - 5 + l3, enumfacing1.getFrontOffsetZ()), enumfacing);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void func_181652_a(WorldServer p_181652_1_, int p_181652_2_, BlockPos p_181652_3_, Facing p_181652_4_)
|
|
{
|
|
this.setBlockAndNotifyAdequately(p_181652_1_, p_181652_3_, Blocks.cocoa.getState().withProperty(BlockCocoa.AGE, p_181652_2_).withProperty(BlockCocoa.FACING, p_181652_4_));
|
|
}
|
|
|
|
private void func_181651_a(WorldServer p_181651_1_, BlockPos p_181651_2_, PropertyBool p_181651_3_)
|
|
{
|
|
this.setBlockAndNotifyAdequately(p_181651_1_, p_181651_2_, Blocks.vine.getState().withProperty(p_181651_3_, Boolean.valueOf(true)));
|
|
}
|
|
|
|
private void func_181650_b(WorldServer p_181650_1_, BlockPos p_181650_2_, PropertyBool p_181650_3_)
|
|
{
|
|
this.func_181651_a(p_181650_1_, p_181650_2_, p_181650_3_);
|
|
int i = 4;
|
|
|
|
for (p_181650_2_ = p_181650_2_.down(); p_181650_1_.getState(p_181650_2_).getBlock().getMaterial() == Material.air && i > 0; --i)
|
|
{
|
|
this.func_181651_a(p_181650_1_, p_181650_2_, p_181650_3_);
|
|
p_181650_2_ = p_181650_2_.down();
|
|
}
|
|
}
|
|
}
|