Skip to content

Commit

Permalink
Fixes Maple and Tiger trees growing without their tops, and maybe fix…
Browse files Browse the repository at this point in the history
… the nether trees growing in the lava/on walls. (fixes #288)
  • Loading branch information
alexbegt committed Oct 8, 2016
1 parent 4bcf268 commit 699588c
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 50 deletions.
Expand Up @@ -55,7 +55,7 @@ BlockPos findGround(World world, BlockPos pos)
position = position.down();
Block underBlock = world.getBlockState(position).getBlock();

if (underBlock == Blocks.NETHERRACK || underBlock == Blocks.SOUL_SAND || underBlock == NaturaNether.netherTaintedSoil || height < 0)
if (underBlock == Blocks.NETHERRACK || underBlock == Blocks.SOUL_SAND || underBlock == NaturaNether.netherTaintedSoil || position.getY() < 0)
{
foundGround = true;
}
Expand Down Expand Up @@ -92,11 +92,16 @@ public void generateTree(Random random, World world, BlockPos pos)

if (yPos >= 1 && yPos + height + 1 <= 256)
{
if (!this.checkClear(world, pos.getX(), pos.getY(), pos.getY(), height))
{
return;
}

IBlockState state = world.getBlockState(pos.down());
Block soil = state.getBlock();
boolean isSoil = (soil != null && soil.canSustainPlant(state, world, pos.down(), EnumFacing.UP, NaturaNether.netherSapling) || soil == Blocks.NETHERRACK);

if (isSoil)
if (isSoil && yPos < 256 - height - 1)
{
soil.onPlantGrow(state, world, pos.down(), pos);

Expand All @@ -106,6 +111,50 @@ public void generateTree(Random random, World world, BlockPos pos)
}
}

boolean checkClear(World world, int xPos, int yPos, int zPos, int treeHeight)
{
boolean flag = true;

for (int y = yPos; y <= yPos + 1 + treeHeight; ++y)
{
int range = 1;

if (y == yPos)
{
range = 0;
}

if (y >= yPos + 1 + treeHeight - 2)
{
range = 2;
}

for (int x = xPos - range; x <= xPos + range && flag; ++x)
{
for (int z = zPos - range; z <= zPos + range && flag; ++z)
{
if (y >= 0 && y < 256)
{
BlockPos blockpos = new BlockPos(x, y, z);
IBlockState state = world.getBlockState(blockpos);
Block block = state.getBlock();

if (!block.isAir(state, world, blockpos) && !block.isLeaves(state, world, blockpos) && block != Blocks.NETHERRACK && block != Blocks.SOUL_SAND && block != NaturaNether.netherTaintedSoil && !block.isWood(world, blockpos))
{
flag = false;
}
}
else
{
flag = false;
}
}
}
}

return flag;
}

protected void placeCanopy(World world, Random random, BlockPos pos, int height)
{
for (int y = pos.getY() - 3 + height; y <= pos.getY() + height; ++y)
Expand All @@ -126,9 +175,9 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height)
BlockPos blockpos = new BlockPos(x, y, z);
IBlockState state = world.getBlockState(blockpos);

if (state.getBlock().isAir(state, world, blockpos) || state.getBlock().canBeReplacedByLeaves(state, world, blockpos))
if (state.getBlock() == null || state.getBlock().canBeReplacedByLeaves(state, world, blockpos))
{
this.setBlockAndMetadata(world, blockpos, this.getRandomizedLeaves(random));
world.setBlockState(blockpos, this.getRandomizedLeaves(random), 2);
}
}
}
Expand All @@ -138,28 +187,30 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height)

protected void placeTrunk(World world, BlockPos pos, int height)
{
while (height >= 0)
for (int localHeight = 0; localHeight < height; ++localHeight)
{
BlockPos blockpos = new BlockPos(pos.getX(), pos.getY() + localHeight, pos.getZ());
IBlockState state = world.getBlockState(blockpos);
Block block = state.getBlock();

if (block.isAir(state, world, blockpos) || block == null || block.isLeaves(state, world, blockpos))
{
world.setBlockState(blockpos, this.log, 2);
}
}

/*while (height >= 0)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || block.isReplaceable(world, pos) || block.isLeaves(state, world, pos))
{
this.setBlockAndMetadata(world, pos, this.log);
}

pos = pos.up();
height--;
}
}

protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || block.canPlaceBlockAt(world, pos) || world.getBlockState(pos) == this.leaves)
{
world.setBlockState(pos, stateNew, 2);
}
}*/
}

protected IBlockState getRandomizedLeaves(Random random)
Expand Down
Expand Up @@ -73,6 +73,7 @@ public void generateTree(Random random, World world, BlockPos pos)
{
height = 4;
}

if (this.seekHeight)
{
pos = this.findGround(world, pos);
Expand All @@ -86,11 +87,16 @@ public void generateTree(Random random, World world, BlockPos pos)

if (yPos >= 1 && yPos + height + 1 <= 256)
{
if (!this.checkClear(world, pos.getX(), yPos, pos.getY(), height))
{
return;
}

IBlockState state = world.getBlockState(pos.down());
Block soil = state.getBlock();
boolean isSoil = (soil != null && soil.canSustainPlant(state, world, pos.down(), EnumFacing.UP, NaturaNether.netherSapling) || soil == Blocks.NETHERRACK);

if (isSoil)
if (isSoil && yPos < 256 - height - 1)
{
soil.onPlantGrow(state, world, pos.down(), pos);

Expand All @@ -100,6 +106,49 @@ public void generateTree(Random random, World world, BlockPos pos)
}
}

boolean checkClear(World world, int xPos, int yPos, int zPos, int treeHeight)
{
boolean flag = true;

for (int y = yPos; y <= yPos + 1 + treeHeight; ++y)
{
int range = 1;

if (y == yPos)
{
range = 0;
}

if (y >= yPos + 1 + treeHeight - 2)
{
range = 2;
}

for (int x = xPos - range; x <= xPos + range && flag; ++x)
{
for (int z = zPos - range; z <= zPos + range && flag; ++z)
{
if (y >= 0 && y < 256)
{
BlockPos blockpos = new BlockPos(x, y, z);
IBlockState state = world.getBlockState(blockpos);
Block block = state.getBlock();

if (!block.isAir(state, world, blockpos) && !block.isLeaves(state, world, blockpos) && block != Blocks.NETHERRACK && block != Blocks.SOUL_SAND && block != NaturaNether.netherTaintedSoil && !block.isWood(world, blockpos))
{
flag = false;
}
}
else
{
flag = false;
}
}
}
}
return flag;
}

protected void placeCanopy(World world, Random random, BlockPos pos, int height)
{
for (int y = pos.getY() - 3 + height; y <= pos.getY() + height; ++y)
Expand All @@ -120,9 +169,9 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height)
BlockPos blockpos = new BlockPos(x, y, z);
IBlockState state = world.getBlockState(blockpos);

if (state.getBlock().isAir(state, world, blockpos) || state.getBlock().isLeaves(state, world, blockpos) || state.getBlock().canBeReplacedByLeaves(state, world, blockpos))
if (state.getBlock() == null || state.getBlock().canBeReplacedByLeaves(state, world, blockpos))
{
this.setBlockAndMetadata(world, blockpos, this.leaves);
world.setBlockState(blockpos, this.leaves, 2);
}
}
}
Expand All @@ -132,27 +181,29 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height)

protected void placeTrunk(World world, BlockPos pos, int height)
{
while (height >= 0)
for (int localHeight = 0; localHeight < height; ++localHeight)
{
BlockPos blockpos = new BlockPos(pos.getX(), pos.getY() + localHeight, pos.getZ());
IBlockState state = world.getBlockState(blockpos);
Block block = state.getBlock();

if (block.isAir(state, world, blockpos) || block == null || block.isLeaves(state, world, blockpos))
{
world.setBlockState(blockpos, this.log, 2);
}
}

/*while (height >= 0)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || block.isReplaceable(world, pos) || block.isLeaves(state, world, pos))
{
this.setBlockAndMetadata(world, pos, this.log);
}

pos = pos.up();
height--;
}
}

protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || block.canPlaceBlockAt(world, pos) || world.getBlockState(pos) == this.leaves)
{
world.setBlockState(pos, stateNew, 2);
}
}*/
}
}
Expand Up @@ -7,7 +7,6 @@
import com.progwml6.natura.world.worldgen.trees.BaseTreeGenerator;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -70,13 +69,50 @@ public void generateTree(Random random, World world, BlockPos pos)

if (isSoil)
{
if (!this.checkClear(world, pos.getX(), yPos, pos.getY(), height))
{
return;
}

soil.onPlantGrow(state, world, pos.down(), pos);
this.placeCanopy(world, random, pos, height);
this.placeTrunk(world, pos, height);
}
}
}

boolean checkClear(World world, int x, int y, int z, int treeHeight)
{
for (int yPos = 0; yPos < treeHeight + 1; yPos++)
{
int range = 1;

if (yPos == 0)
{
range = 0;
}
else if (yPos >= treeHeight - 1)
{
range = 2;
}

for (int xPos = range; xPos <= range; xPos++)
{
for (int zPos = range; zPos <= range; zPos++)
{
BlockPos blockpos = new BlockPos(x + xPos, y + yPos, z + zPos);
IBlockState state = world.getBlockState(blockpos);

if (state.getBlock() != null && state.getBlock() != NaturaOverworld.overworldSapling || !state.getBlock().isLeaves(state, world, blockpos))
{
return true;
}
}
}
}
return true;
}

BlockPos findGround(World world, BlockPos pos)
{
int returnHeight = 0;
Expand Down Expand Up @@ -122,10 +158,9 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height)
BlockPos blockpos = new BlockPos(x, y, z);
IBlockState state = world.getBlockState(blockpos);

if (state.getBlock().isAir(state, world, blockpos) || state.getBlock().isLeaves(state, world, blockpos)
|| state.getMaterial() == Material.VINE)
if (state.getBlock().isAir(state, world, blockpos) || state.getBlock().canBeReplacedByLeaves(state, world, blockpos))
{
this.setBlockAndMetadata(world, blockpos, this.leaves);
world.setBlockState(blockpos, this.leaves, 2);
}
}
}
Expand All @@ -135,27 +170,29 @@ protected void placeCanopy(World world, Random random, BlockPos pos, int height)

protected void placeTrunk(World world, BlockPos pos, int height)
{
while (height >= 0)
for (int localHeight = 0; localHeight < height; ++localHeight)
{
BlockPos blockpos = new BlockPos(pos.getX(), pos.getY() + localHeight, pos.getZ());
IBlockState state = world.getBlockState(blockpos);
Block block = state.getBlock();

if (block.isAir(state, world, blockpos) || block == null || block.isLeaves(state, world, blockpos))
{
world.setBlockState(blockpos, this.log, 2);
}
}

/*while (height >= 0)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || block.isReplaceable(world, pos) || block.isLeaves(state, world, pos))
{
this.setBlockAndMetadata(world, pos, this.log);
}

pos = pos.up();
height--;
}
}

protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || block.canPlaceBlockAt(world, pos) || world.getBlockState(pos) == this.leaves)
{
world.setBlockState(pos, stateNew, 2);
}
}*/
}
}

0 comments on commit 699588c

Please sign in to comment.