mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-09 23:39:43 +00:00
Rename BlockWriteBatch -> BlockTransaction
This commit is contained in:
parent
b252be1c7a
commit
0794c94b4b
@ -25,7 +25,7 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\BlockDataValidator;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\BlockWriteBatch;
|
||||
use pocketmine\level\BlockTransaction;
|
||||
use pocketmine\level\sound\DoorSound;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Bearing;
|
||||
@ -125,10 +125,10 @@ abstract class Door extends Transparent{
|
||||
$topHalf = clone $this;
|
||||
$topHalf->top = true;
|
||||
|
||||
$write = new BlockWriteBatch();
|
||||
$write->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf);
|
||||
$transaction = new BlockTransaction();
|
||||
$transaction->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf);
|
||||
|
||||
return $write->apply($this->level);
|
||||
return $transaction->apply($this->level);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\BlockWriteBatch;
|
||||
use pocketmine\level\BlockTransaction;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
@ -53,9 +53,9 @@ class DoublePlant extends Flowable{
|
||||
$top = clone $this;
|
||||
$top->top = true;
|
||||
|
||||
$write = new BlockWriteBatch();
|
||||
$write->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top);
|
||||
return $write->apply($this->level);
|
||||
$transaction = new BlockTransaction();
|
||||
$transaction->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top);
|
||||
return $transaction->apply($this->level);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -27,7 +27,7 @@ use pocketmine\block\Block;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\utils\Utils;
|
||||
|
||||
class BlockWriteBatch{
|
||||
class BlockTransaction{
|
||||
/** @var Block[][][] */
|
||||
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 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
|
||||
* add blocks to the batch that depend on previous blocks should they exist.
|
||||
* 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 transaction that depend on previous blocks should they exist.
|
||||
*
|
||||
* @param ChunkManager $world
|
||||
* @param Vector3 $pos
|
||||
@ -81,7 +81,7 @@ class BlockWriteBatch{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BlockWriteBatch::fetchBlock()
|
||||
* @see BlockTransaction::fetchBlock()
|
||||
*
|
||||
* @param ChunkManager $world
|
||||
* @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
|
||||
* changes will be made to the world.
|
||||
* Validates and attempts to apply the transaction to the given world. If any part of the transaction fails to
|
||||
* validate, no changes will be made to the world.
|
||||
*
|
||||
* @param ChunkManager $world
|
||||
*
|
||||
@ -132,7 +132,7 @@ class BlockWriteBatch{
|
||||
/**
|
||||
* Add a validation predicate which will be used to validate every block.
|
||||
* The callable signature should be the same as the below dummy function.
|
||||
* @see BlockWriteBatch::dummyValidator()
|
||||
* @see BlockTransaction::dummyValidator()
|
||||
*
|
||||
* @param callable $validator
|
||||
*/
|
||||
@ -143,7 +143,7 @@ class BlockWriteBatch{
|
||||
|
||||
/**
|
||||
* Dummy function demonstrating the required closure signature for validators.
|
||||
* @see BlockWriteBatch::addValidator()
|
||||
* @see BlockTransaction::addValidator()
|
||||
*
|
||||
* @dummy
|
||||
*
|
@ -26,7 +26,7 @@ namespace pocketmine\level\generator\object;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\level\BlockWriteBatch;
|
||||
use pocketmine\level\BlockTransaction;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
use function abs;
|
||||
@ -46,7 +46,7 @@ class SpruceTree extends Tree{
|
||||
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));
|
||||
$lRadius = 2 + $random->nextBoundedInt(2);
|
||||
$radius = $random->nextBoundedInt(2);
|
||||
@ -65,7 +65,7 @@ class SpruceTree extends Tree{
|
||||
}
|
||||
|
||||
if(!$level->getBlockAt($xx, $yyy, $zz)->isSolid()){
|
||||
$write->addBlockAt($xx, $yyy, $zz, $this->leafBlock);
|
||||
$transaction->addBlockAt($xx, $yyy, $zz, $this->leafBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Leaves;
|
||||
use pocketmine\block\Sapling;
|
||||
use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\level\BlockWriteBatch;
|
||||
use pocketmine\level\BlockTransaction;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
use function abs;
|
||||
@ -107,29 +107,29 @@ abstract class Tree{
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{
|
||||
$write = new BlockWriteBatch();
|
||||
$this->placeTrunk($level, $x, $y, $z, $random, $this->generateChunkHeight($random), $write);
|
||||
$this->placeCanopy($level, $x, $y, $z, $random, $write);
|
||||
$transaction = new BlockTransaction();
|
||||
$this->placeTrunk($level, $x, $y, $z, $random, $this->generateChunkHeight($random), $transaction);
|
||||
$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{
|
||||
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
|
||||
$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){
|
||||
if($this->canOverride($write->fetchBlockAt($level, $x, $y + $yy, $z))){
|
||||
$write->addBlockAt($x, $y + $yy, $z, $this->trunkBlock);
|
||||
if($this->canOverride($transaction->fetchBlockAt($level, $x, $y + $yy, $z))){
|
||||
$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){
|
||||
$yOff = $yy - ($y + $this->treeHeight);
|
||||
$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)){
|
||||
continue;
|
||||
}
|
||||
if(!$write->fetchBlockAt($level, $xx, $yy, $zz)->isSolid()){
|
||||
$write->addBlockAt($xx, $yy, $zz, $this->leafBlock);
|
||||
if(!$transaction->fetchBlockAt($level, $xx, $yy, $zz)->isSolid()){
|
||||
$transaction->addBlockAt($xx, $yy, $zz, $this->leafBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user