From 6a4ae4cb94232bf7dbd3896f42a689bfae691191 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 24 Aug 2019 17:19:27 +0100 Subject: [PATCH] remove position parameters from BlockFactory::get() and BlockFactory::fromFullBlock() --- src/block/BlockFactory.php | 16 +++++----------- src/entity/projectile/Projectile.php | 6 +++--- src/world/Explosion.php | 17 +++++++++-------- src/world/World.php | 7 ++----- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php index 847c8b844..065f34eac 100644 --- a/src/block/BlockFactory.php +++ b/src/block/BlockFactory.php @@ -51,7 +51,6 @@ use pocketmine\block\utils\TreeType; use pocketmine\item\Item; use pocketmine\item\ItemIds; use pocketmine\item\ToolTier; -use pocketmine\world\Position; use function array_fill; use function array_filter; use function get_class; @@ -830,13 +829,12 @@ class BlockFactory{ /** * Returns a new Block instance with the specified ID, meta and position. * - * @param int $id - * @param int $meta - * @param Position $pos + * @param int $id + * @param int $meta * * @return Block */ - public static function get(int $id, int $meta = 0, ?Position $pos = null) : Block{ + public static function get(int $id, int $meta = 0) : Block{ if($meta < 0 or $meta > 0xf){ throw new \InvalidArgumentException("Block meta value $meta is out of bounds"); } @@ -856,15 +854,11 @@ class BlockFactory{ $block = new UnknownBlock(new BID($id, $meta)); } - if($pos !== null){ - $block->position($pos->getWorld(), $pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()); - } - return $block; } - public static function fromFullBlock(int $fullState, ?Position $pos = null) : Block{ - return self::get($fullState >> 4, $fullState & 0xf, $pos); + public static function fromFullBlock(int $fullState) : Block{ + return self::get($fullState >> 4, $fullState & 0xf); } /** diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index 52376fbc1..62b00af9c 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -41,7 +41,6 @@ use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\timings\Timings; -use pocketmine\world\Position; use pocketmine\world\World; use function assert; use function atan2; @@ -84,7 +83,7 @@ abstract class Projectile extends Entity{ $blockData = null; if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){ - $blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->getWorld()); + $blockPos = new Vector3($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ")); }else{ break; } @@ -101,7 +100,8 @@ abstract class Projectile extends Entity{ break; } - $this->blockHit = BlockFactory::get($blockId, $blockData, $blockPos); + $this->blockHit = BlockFactory::get($blockId, $blockData); + $this->blockHit->position($this->getWorld(), $blockPos->getFloorX(), $blockPos->getFloorY(), $blockPos->getFloorZ()); }while(false); } diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 8a9f57ba9..5805c6d46 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -95,7 +95,6 @@ class Explosion{ } $vector = new Vector3(0, 0, 0); - $vBlock = new Position(0, 0, 0, $this->world); $currentChunk = null; $currentSubChunk = null; @@ -115,21 +114,23 @@ class Explosion{ $x = (int) $pointerX; $y = (int) $pointerY; $z = (int) $pointerZ; - $vBlock->x = $pointerX >= $x ? $x : $x - 1; - $vBlock->y = $pointerY >= $y ? $y : $y - 1; - $vBlock->z = $pointerZ >= $z ? $z : $z - 1; + $vBlockX = $pointerX >= $x ? $x : $x - 1; + $vBlockY = $pointerY >= $y ? $y : $y - 1; + $vBlockZ = $pointerZ >= $z ? $z : $z - 1; - if(!$this->subChunkHandler->moveTo($vBlock->x, $vBlock->y, $vBlock->z, false)){ + if(!$this->subChunkHandler->moveTo($vBlockX, $vBlockY, $vBlockZ, false)){ continue; } - $state = $this->subChunkHandler->currentSubChunk->getFullBlock($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f); + $state = $this->subChunkHandler->currentSubChunk->getFullBlock($vBlockX & 0x0f, $vBlockY & 0x0f, $vBlockZ & 0x0f); if($state !== 0){ $blastForce -= (BlockFactory::$blastResistance[$state] / 5 + 0.3) * $this->stepLen; if($blastForce > 0){ - if(!isset($this->affectedBlocks[$index = World::blockHash($vBlock->x, $vBlock->y, $vBlock->z)])){ - $this->affectedBlocks[$index] = BlockFactory::fromFullBlock($state, $vBlock); + if(!isset($this->affectedBlocks[$index = World::blockHash($vBlockX, $vBlockY, $vBlockZ)])){ + $_block = BlockFactory::fromFullBlock($state); + $_block->position($this->world, $vBlockX, $vBlockY, $vBlockZ); + $this->affectedBlocks[$index] = $_block; } } } diff --git a/src/world/World.php b/src/world/World.php index 91455bf5c..27c29472b 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -996,11 +996,8 @@ class World implements ChunkManager{ if(isset($this->randomTickBlocks[$state])){ /** @var Block $block */ - $block = BlockFactory::fromFullBlock($state, $this->temporalPosition->setComponents( - $chunkX * 16 + $x, - ($Y << 4) + $y, - $chunkZ * 16 + $z - )); + $block = BlockFactory::fromFullBlock($state); + $block->position($this, $chunkX * 16 + $x, ($Y << 4) + $y, $chunkZ * 16 + $z); $block->onRandomTick(); } }