Fixed tree trunk generation bug introduced by ac87319aed4d556d85a8aeba0ea6da6667a5408f

Blocks were being overwritten in the writebatch which hadn't yet been set, so reading them from the world yielded air blocks instead of trunk, allowing the generation to overwrite blocks which should have been logs.
This commit is contained in:
Dylan K. Taylor 2019-01-19 13:41:28 +00:00
parent 6b7710e62b
commit 179fb9c7cb
2 changed files with 29 additions and 2 deletions

View File

@ -67,6 +67,33 @@ class BlockWriteBatch{
return $this;
}
/**
* Reads a block from the given world, masked by the blocks in this writebatch. This can be useful if you want to
* add blocks to the batch that depend on previous blocks should they exist.
*
* @param ChunkManager $world
* @param Vector3 $pos
*
* @return Block
*/
public function fetchBlock(ChunkManager $world, Vector3 $pos) : Block{
return $this->fetchBlockAt($world, $pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ());
}
/**
* @see BlockWriteBatch::fetchBlock()
*
* @param ChunkManager $world
* @param int $x
* @param int $y
* @param int $z
*
* @return Block
*/
public function fetchBlockAt(ChunkManager $world, int $x, int $y, int $z) : Block{
return $this->blocks[$x][$y][$z] ?? $world->getBlockAt($x, $y, $z);
}
/**
* Validates and attempts to apply the batch to the given world. If any part of the batch fails to validate, no
* changes will be made to the world.

View File

@ -117,7 +117,7 @@ abstract class Tree{
$write->addBlockAt($x, $y - 1, $z, BlockFactory::get(Block::DIRT));
for($yy = 0; $yy < $trunkHeight; ++$yy){
if($this->canOverride($level->getBlockAt($x, $y + $yy, $z))){
if($this->canOverride($write->fetchBlockAt($level, $x, $y + $yy, $z))){
$write->addBlockAt($x, $y + $yy, $z, $this->trunkBlock);
}
}
@ -134,7 +134,7 @@ abstract class Tree{
if($xOff === $mid and $zOff === $mid and ($yOff === 0 or $random->nextBoundedInt(2) === 0)){
continue;
}
if(!$level->getBlockAt($xx, $yy, $zz)->isSolid()){
if(!$write->fetchBlockAt($level, $xx, $yy, $zz)->isSolid()){
$write->addBlockAt($xx, $yy, $zz, $this->leafBlock);
}
}