From 179fb9c7cb19e7a3221492a156f0c25684121172 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 19 Jan 2019 13:41:28 +0000 Subject: [PATCH] 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. --- src/pocketmine/level/BlockWriteBatch.php | 27 +++++++++++++++++++ .../level/generator/object/Tree.php | 4 +-- 2 files changed, 29 insertions(+), 2 deletions(-) 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); } }