diff --git a/src/pocketmine/level/BlockWriteBatch.php b/src/pocketmine/level/BlockWriteBatch.php index 8638930fd..11faaa2bc 100644 --- a/src/pocketmine/level/BlockWriteBatch.php +++ b/src/pocketmine/level/BlockWriteBatch.php @@ -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. diff --git a/src/pocketmine/level/generator/object/Tree.php b/src/pocketmine/level/generator/object/Tree.php index aa6993017..7a795e20a 100644 --- a/src/pocketmine/level/generator/object/Tree.php +++ b/src/pocketmine/level/generator/object/Tree.php @@ -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); } }