Introduce a "block write-batch" concept (#2555)

Make use of writebatch to generate trees, doors and double plants safely

- Fixes #2441 
- Fixes #2548 
- Closes #2498
This commit is contained in:
Dylan T
2018-12-29 12:00:14 +00:00
committed by GitHub
parent aaaddd1fd6
commit ac87319aed
5 changed files with 175 additions and 23 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\block\utils\BlockDataValidator;
use pocketmine\item\Item;
use pocketmine\level\BlockWriteBatch;
use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
@ -124,9 +125,10 @@ abstract class Door extends Transparent{
$topHalf = clone $this;
$topHalf->top = true;
parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
$this->level->setBlock($blockUp, $topHalf); //Top
return true;
$write = new BlockWriteBatch();
$write->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf);
return $write->apply($this->level);
}
return false;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\BlockWriteBatch;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\Player;
@ -49,12 +50,12 @@ class DoublePlant extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$id = $blockReplace->getSide(Facing::DOWN)->getId();
if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Facing::UP)->canBeReplaced()){
$this->getLevel()->setBlock($blockReplace, $this, false);
$top = clone $this;
$top->top = true;
$this->getLevel()->setBlock($blockReplace->getSide(Facing::UP), $top, false);
return true;
$write = new BlockWriteBatch();
$write->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top);
return $write->apply($this->level);
}
return false;