Skip to content

Commit

Permalink
Clean up the Saguaro Generator + fix it not generating correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbegt committed Jan 10, 2018
1 parent fc026c2 commit 3f74ed0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
Expand Up @@ -69,7 +69,7 @@ public OverworldTreesGenerator()

this.redwoodTreeGen = new RedwoodTreeGenerator(redwoodLog.withProperty(BlockRedwoodLog.TYPE, BlockRedwoodLog.RedwoodType.BARK), redwoodLog.withProperty(BlockRedwoodLog.TYPE, BlockRedwoodLog.RedwoodType.HEART), redwoodLog.withProperty(BlockRedwoodLog.TYPE, BlockRedwoodLog.RedwoodType.ROOT), redwoodLeaves.withProperty(BlockRedwoodLeaves.TYPE, BlockRedwoodLeaves.RedwoodType.NORMAL), false, false);

this.saguaroGen = new SaguaroGenerator(NaturaOverworld.saguaro.getDefaultState(), false, false);
this.saguaroGen = new SaguaroGenerator(NaturaOverworld.saguaro.getDefaultState(), true, false);
}

@Override
Expand Down Expand Up @@ -270,7 +270,7 @@ public void generateOverworld(Random random, int chunkX, int chunkZ, World world
if (Config.generateSaguaro && random.nextInt(Config.saguaroSpawnRarity) == 0)
{
xSpawn = xPos + random.nextInt(16);
ySpawn = random.nextInt(Config.seaLevel) + 16;
ySpawn = Config.seaLevel + random.nextInt(16);
zSpawn = zPos + random.nextInt(16);
position = new BlockPos(xSpawn, ySpawn, zSpawn);

Expand Down
Expand Up @@ -49,17 +49,16 @@ public void generateSaguaro(Random random, World worldIn, BlockPos position)
if (this.findGround)
{
this.basePos = this.findGround(worldIn, position);
while (position.getY() > 1 && worldIn.isAirBlock(position) || worldIn.getBlockState(position).getBlock().isLeaves(worldIn.getBlockState(position), worldIn, position))

if (position.getY() < 0)
{
this.basePos = position.down();
return;
}

if (!(blocksMatch(worldIn, position)))
if (!blocksMatch(worldIn, position))
{
return;
}

this.basePos = this.basePos.up();
}
else
{
Expand All @@ -81,9 +80,9 @@ public void generateSaguaro(Random random, World worldIn, BlockPos position)

private boolean blocksMatch(World world, BlockPos pos)
{
Block underBlock = world.getBlockState(pos).getBlock();
Block underBlock = world.getBlockState(pos.down()).getBlock();

if (!(underBlock == Blocks.SAND))
if (underBlock == Blocks.SAND)
{
return true;
}
Expand Down Expand Up @@ -241,48 +240,49 @@ void setBlock(BlockPos pos)

BlockPos findGround(World world, BlockPos pos)
{
if (world.getWorldType() == WorldType.FLAT && this.isBaby)
{
boolean foundGround = false;
int returnHeight = 0;

int height = Config.flatSeaLevel + 64;
int height = pos.getY();

if (world.getWorldType() == WorldType.FLAT && this.isBaby)
{
do
{
height--;
BlockPos position = new BlockPos(pos.getX(), height, pos.getZ());
Block underBlock = world.getBlockState(position).getBlock();

if (underBlock == Blocks.SAND || height < Config.flatSeaLevel)
Block block = world.getBlockState(position).getBlock();

if (block == Blocks.SAND && !world.getBlockState(position.up()).isFullBlock())
{
foundGround = true;
returnHeight = height + 1;
break;
}

height--;
}
while (!foundGround);
while (height > Config.flatSeaLevel);

return new BlockPos(pos.getX(), height + 1, pos.getZ());
return new BlockPos(pos.getX(), returnHeight, pos.getZ());
}
else
{
boolean foundGround = false;

int height = Config.seaLevel + 64;

do
{
height--;
BlockPos position = new BlockPos(pos.getX(), height, pos.getZ());
Block underBlock = world.getBlockState(position).getBlock();

if (underBlock == Blocks.SAND || height < Config.seaLevel)
Block block = world.getBlockState(position).getBlock();

if (block == Blocks.SAND && !world.getBlockState(position.up()).isFullBlock())
{
foundGround = true;
returnHeight = height + 1;
break;
}

height--;
}
while (!foundGround);
while (height > Config.seaLevel);

return new BlockPos(pos.getX(), height + 1, pos.getZ());
return new BlockPos(pos.getX(), returnHeight, pos.getZ());
}
}

}

0 comments on commit 3f74ed0

Please sign in to comment.