Rename BlockWriteBatch -> BlockTransaction

This commit is contained in:
Dylan K. Taylor 2019-02-16 19:53:15 +00:00
parent b252be1c7a
commit 0794c94b4b
5 changed files with 32 additions and 32 deletions

View File

@ -25,7 +25,7 @@ namespace pocketmine\block;
use pocketmine\block\utils\BlockDataValidator; use pocketmine\block\utils\BlockDataValidator;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\BlockWriteBatch; use pocketmine\level\BlockTransaction;
use pocketmine\level\sound\DoorSound; use pocketmine\level\sound\DoorSound;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing; use pocketmine\math\Bearing;
@ -125,10 +125,10 @@ abstract class Door extends Transparent{
$topHalf = clone $this; $topHalf = clone $this;
$topHalf->top = true; $topHalf->top = true;
$write = new BlockWriteBatch(); $transaction = new BlockTransaction();
$write->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf); $transaction->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf);
return $write->apply($this->level); return $transaction->apply($this->level);
} }
return false; return false;

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\BlockWriteBatch; use pocketmine\level\BlockTransaction;
use pocketmine\math\Facing; use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -53,9 +53,9 @@ class DoublePlant extends Flowable{
$top = clone $this; $top = clone $this;
$top->top = true; $top->top = true;
$write = new BlockWriteBatch(); $transaction = new BlockTransaction();
$write->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top); $transaction->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top);
return $write->apply($this->level); return $transaction->apply($this->level);
} }
return false; return false;

View File

@ -27,7 +27,7 @@ use pocketmine\block\Block;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
class BlockWriteBatch{ class BlockTransaction{
/** @var Block[][][] */ /** @var Block[][][] */
private $blocks = []; private $blocks = [];
@ -41,7 +41,7 @@ class BlockWriteBatch{
} }
/** /**
* Adds a block to the batch at the given position. * Adds a block to the transaction at the given position.
* *
* @param Vector3 $pos * @param Vector3 $pos
* @param Block $state * @param Block $state
@ -68,8 +68,8 @@ class BlockWriteBatch{
} }
/** /**
* Reads a block from the given world, masked by the blocks in this writebatch. This can be useful if you want to * Reads a block from the given world, masked by the blocks in this transaction. This can be useful if you want to
* add blocks to the batch that depend on previous blocks should they exist. * add blocks to the transaction that depend on previous blocks should they exist.
* *
* @param ChunkManager $world * @param ChunkManager $world
* @param Vector3 $pos * @param Vector3 $pos
@ -81,7 +81,7 @@ class BlockWriteBatch{
} }
/** /**
* @see BlockWriteBatch::fetchBlock() * @see BlockTransaction::fetchBlock()
* *
* @param ChunkManager $world * @param ChunkManager $world
* @param int $x * @param int $x
@ -95,8 +95,8 @@ class BlockWriteBatch{
} }
/** /**
* Validates and attempts to apply the batch to the given world. If any part of the batch fails to validate, no * Validates and attempts to apply the transaction to the given world. If any part of the transaction fails to
* changes will be made to the world. * validate, no changes will be made to the world.
* *
* @param ChunkManager $world * @param ChunkManager $world
* *
@ -132,7 +132,7 @@ class BlockWriteBatch{
/** /**
* Add a validation predicate which will be used to validate every block. * Add a validation predicate which will be used to validate every block.
* The callable signature should be the same as the below dummy function. * The callable signature should be the same as the below dummy function.
* @see BlockWriteBatch::dummyValidator() * @see BlockTransaction::dummyValidator()
* *
* @param callable $validator * @param callable $validator
*/ */
@ -143,7 +143,7 @@ class BlockWriteBatch{
/** /**
* Dummy function demonstrating the required closure signature for validators. * Dummy function demonstrating the required closure signature for validators.
* @see BlockWriteBatch::addValidator() * @see BlockTransaction::addValidator()
* *
* @dummy * @dummy
* *

View File

@ -26,7 +26,7 @@ namespace pocketmine\level\generator\object;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\BlockFactory;
use pocketmine\block\utils\TreeType; use pocketmine\block\utils\TreeType;
use pocketmine\level\BlockWriteBatch; use pocketmine\level\BlockTransaction;
use pocketmine\level\ChunkManager; use pocketmine\level\ChunkManager;
use pocketmine\utils\Random; use pocketmine\utils\Random;
use function abs; use function abs;
@ -46,7 +46,7 @@ class SpruceTree extends Tree{
parent::placeObject($level, $x, $y, $z, $random); parent::placeObject($level, $x, $y, $z, $random);
} }
protected function placeCanopy(ChunkManager $level, int $x, int $y, int $z, Random $random, BlockWriteBatch $write) : void{ protected function placeCanopy(ChunkManager $level, int $x, int $y, int $z, Random $random, BlockTransaction $transaction) : void{
$topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2)); $topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2));
$lRadius = 2 + $random->nextBoundedInt(2); $lRadius = 2 + $random->nextBoundedInt(2);
$radius = $random->nextBoundedInt(2); $radius = $random->nextBoundedInt(2);
@ -65,7 +65,7 @@ class SpruceTree extends Tree{
} }
if(!$level->getBlockAt($xx, $yyy, $zz)->isSolid()){ if(!$level->getBlockAt($xx, $yyy, $zz)->isSolid()){
$write->addBlockAt($xx, $yyy, $zz, $this->leafBlock); $transaction->addBlockAt($xx, $yyy, $zz, $this->leafBlock);
} }
} }
} }

View File

@ -28,7 +28,7 @@ use pocketmine\block\BlockFactory;
use pocketmine\block\Leaves; use pocketmine\block\Leaves;
use pocketmine\block\Sapling; use pocketmine\block\Sapling;
use pocketmine\block\utils\TreeType; use pocketmine\block\utils\TreeType;
use pocketmine\level\BlockWriteBatch; use pocketmine\level\BlockTransaction;
use pocketmine\level\ChunkManager; use pocketmine\level\ChunkManager;
use pocketmine\utils\Random; use pocketmine\utils\Random;
use function abs; use function abs;
@ -107,29 +107,29 @@ abstract class Tree{
} }
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{ public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{
$write = new BlockWriteBatch(); $transaction = new BlockTransaction();
$this->placeTrunk($level, $x, $y, $z, $random, $this->generateChunkHeight($random), $write); $this->placeTrunk($level, $x, $y, $z, $random, $this->generateChunkHeight($random), $transaction);
$this->placeCanopy($level, $x, $y, $z, $random, $write); $this->placeCanopy($level, $x, $y, $z, $random, $transaction);
$write->apply($level); //TODO: handle return value on failure $transaction->apply($level); //TODO: handle return value on failure
} }
protected function generateChunkHeight(Random $random) : int{ protected function generateChunkHeight(Random $random) : int{
return $this->treeHeight - 1; return $this->treeHeight - 1;
} }
protected function placeTrunk(ChunkManager $level, int $x, int $y, int $z, Random $random, int $trunkHeight, BlockWriteBatch $write) : void{ protected function placeTrunk(ChunkManager $level, int $x, int $y, int $z, Random $random, int $trunkHeight, BlockTransaction $transaction) : void{
// The base dirt block // The base dirt block
$write->addBlockAt($x, $y - 1, $z, BlockFactory::get(Block::DIRT)); $transaction->addBlockAt($x, $y - 1, $z, BlockFactory::get(Block::DIRT));
for($yy = 0; $yy < $trunkHeight; ++$yy){ for($yy = 0; $yy < $trunkHeight; ++$yy){
if($this->canOverride($write->fetchBlockAt($level, $x, $y + $yy, $z))){ if($this->canOverride($transaction->fetchBlockAt($level, $x, $y + $yy, $z))){
$write->addBlockAt($x, $y + $yy, $z, $this->trunkBlock); $transaction->addBlockAt($x, $y + $yy, $z, $this->trunkBlock);
} }
} }
} }
protected function placeCanopy(ChunkManager $level, int $x, int $y, int $z, Random $random, BlockWriteBatch $write) : void{ protected function placeCanopy(ChunkManager $level, int $x, int $y, int $z, Random $random, BlockTransaction $transaction) : void{
for($yy = $y - 3 + $this->treeHeight; $yy <= $y + $this->treeHeight; ++$yy){ for($yy = $y - 3 + $this->treeHeight; $yy <= $y + $this->treeHeight; ++$yy){
$yOff = $yy - ($y + $this->treeHeight); $yOff = $yy - ($y + $this->treeHeight);
$mid = (int) (1 - $yOff / 2); $mid = (int) (1 - $yOff / 2);
@ -140,8 +140,8 @@ abstract class Tree{
if($xOff === $mid and $zOff === $mid and ($yOff === 0 or $random->nextBoundedInt(2) === 0)){ if($xOff === $mid and $zOff === $mid and ($yOff === 0 or $random->nextBoundedInt(2) === 0)){
continue; continue;
} }
if(!$write->fetchBlockAt($level, $xx, $yy, $zz)->isSolid()){ if(!$transaction->fetchBlockAt($level, $xx, $yy, $zz)->isSolid()){
$write->addBlockAt($xx, $yy, $zz, $this->leafBlock); $transaction->addBlockAt($xx, $yy, $zz, $this->leafBlock);
} }
} }
} }