if (!(blockID instanceof BlockAir) && this.getDistanceFromServer(x, y, z) < bubbleSizeSq)
{
if (doGrass && blockID instanceof ITerraformableBlock && ((ITerraformableBlock) blockID).isTerraformable(this.worldObj, x, y, z))
{
this.terraformableBlocksList.add(new BlockVec3(x, y, z));
}
else if (doTrees)
{
Block blockIDAbove = this.worldObj.getBlock(x, y + 1, z);
if (blockID == Blocks.grass && blockIDAbove instanceof BlockAir)
{
this.grassBlockList.add(new BlockVec3(x, y, z));
}
}
}
}
}
}
}
}
if (!this.worldObj.isRemote && this.terraformableBlocksList.size() > 0 && this.ticks % 15 == 0)
{
ArrayList<BlockVec3> terraformableBlocks2 = new ArrayList<BlockVec3>(this.terraformableBlocksList);
int randomIndex = this.worldObj.rand.nextInt(this.terraformableBlocksList.size());
BlockVec3 vec = terraformableBlocks2.get(randomIndex);
if (vec.getBlock(this.worldObj) instanceof ITerraformableBlock)
{
Block id;
switch (this.worldObj.rand.nextInt(40))
{
case 0:
if (this.worldObj.func_147469_q(vec.x - 1, vec.y, vec.z) && this.worldObj.func_147469_q(vec.x + 1, vec.y, vec.z) && this.worldObj.func_147469_q(vec.x, vec.y, vec.z - 1) && this.worldObj.func_147469_q(vec.x, vec.y, vec.z + 1))
{
id = Blocks.flowing_water;
}
else
{
id = Blocks.grass;
}
break;
default:
id = Blocks.grass;
break;
}
this.worldObj.setBlock(vec.x, vec.y, vec.z, id);
if (id == Blocks.grass)
{
this.useCount[0]++;
this.waterTank.drain(1, true);
this.checkUsage(1);
}
else if (id == Blocks.flowing_water)
{
this.checkUsage(2);
}
}
this.terraformableBlocksList.remove(randomIndex);
}
if (!this.worldObj.isRemote && !this.treesDisabled && this.grassBlockList.size() > 0 && this.ticks % 50 == 0)
{
int randomIndex = this.worldObj.rand.nextInt(this.grassBlockList.size());
BlockVec3 vecGrass = grassBlockList.get(randomIndex);
if (vecGrass.getBlock(this.worldObj) == Blocks.grass)
{
BlockVec3 vecSapling = vecGrass.translate(0, 1, 0);
ItemStack sapling = this.getFirstSaplingStack();
boolean flag = false;
//Attempt to prevent placement too close to other trees
for (BlockVec3 testVec : this.grownTreesList)
{
if (testVec.distanceSquared(vecSapling) < 9)
{
flag = true;
break;
}
}
if (!flag && sapling != null)
{
Block b = Block.getBlockFromItem(sapling.getItem());
this.worldObj.setBlock(vecSapling.x, vecSapling.y, vecSapling.z, b, sapling.getItemDamage(), 3);
if (b instanceof BlockSapling)
{
if (this.worldObj.getBlockLightValue(vecSapling.x, vecSapling.y, vecSapling.z) >= 9)
{
((BlockSapling)b).func_149878_d(this.worldObj, vecSapling.x, vecSapling.y, vecSapling.z, this.worldObj.rand);
this.grownTreesList.add(vecSapling.clone());
}
}
else if (b instanceof BlockBush)
{
if (this.worldObj.getBlockLightValue(vecSapling.x, vecSapling.y, vecSapling.z) >= 5)
//Hammer the update tick a few times to try to get it to grow - it won't always
for (int j = 0; j < 12; j++)
{
if (this.worldObj.getBlock(vecSapling.x, vecSapling.y, vecSapling.z) == b)
((BlockBush)b).updateTick(this.worldObj, vecSapling.x, vecSapling.y, vecSapling.z, this.worldObj.rand);
else
{
this.grownTreesList.add(vecSapling.clone());
break;
}
}
}