From c394aea80325d9cf06aab4cee302e4be5a82e56b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 20 Aug 2017 10:43:48 +0100 Subject: [PATCH] Replaced more literal ints with Vector3 constants --- src/pocketmine/block/Door.php | 8 ++++---- src/pocketmine/block/ItemFrame.php | 10 +++++----- src/pocketmine/block/SignPost.php | 4 ++-- src/pocketmine/block/Skull.php | 4 ++-- src/pocketmine/block/Stair.php | 2 +- src/pocketmine/block/Torch.php | 12 ++++++------ src/pocketmine/block/Wood.php | 12 ++++++------ src/pocketmine/block/WoodenSlab.php | 4 ++-- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index d070c3a3a..d5adc3648 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -217,21 +217,21 @@ abstract class Door extends Transparent{ } public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($face === 1){ + if($face === Vector3::SIDE_UP){ $blockUp = $this->getSide(Vector3::SIDE_UP); $blockDown = $this->getSide(Vector3::SIDE_DOWN); if($blockUp->canBeReplaced() === false or $blockDown->isTransparent() === true){ return false; } $direction = $player instanceof Player ? $player->getDirection() : 0; - $face = [ + $faces = [ 0 => 3, 1 => 4, 2 => 2, 3 => 5, ]; - $next = $this->getSide($face[($direction + 2) % 4]); - $next2 = $this->getSide($face[$direction]); + $next = $this->getSide($faces[($direction + 2) % 4]); + $next2 = $this->getSide($faces[$direction]); $metaUp = 0x08; if($next->getId() === $this->getId() or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge $metaUp |= 0x01; diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index e6fcaa8bc..2399ac442 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -105,15 +105,15 @@ class ItemFrame extends Flowable{ } public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($face === 0 or $face === 1){ + if($face === Vector3::SIDE_DOWN or $face === Vector3::SIDE_UP){ return false; } $faces = [ - 2 => 3, - 3 => 2, - 4 => 1, - 5 => 0 + Vector3::SIDE_NORTH => 3, + Vector3::SIDE_SOUTH => 2, + Vector3::SIDE_WEST => 1, + Vector3::SIDE_EAST => 0 ]; $this->meta = $faces[$face]; diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index 757750c58..a453ccbd2 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -61,7 +61,7 @@ class SignPost extends Transparent{ public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($face !== 0){ + if($face !== Vector3::SIDE_DOWN){ $nbt = new CompoundTag("", [ new StringTag("id", Tile::SIGN), new IntTag("x", $block->x), @@ -83,7 +83,7 @@ class SignPost extends Transparent{ } } - if($face === 1){ + if($face === Vector3::SIDE_UP){ $this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f; $this->getLevel()->setBlock($block, $this, true); }else{ diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 5d2c79750..d088c888c 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -64,9 +64,9 @@ class Skull extends Flowable{ } public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($face !== 0){ + if($face !== Vector3::SIDE_DOWN){ $this->meta = $face; - if($face === 1){ + if($face === Vector3::SIDE_UP){ $rot = floor(($player->yaw * 16 / 360) + 0.5) & 0x0F; }else{ $rot = $face; diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index ef5277582..a17b17eca 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -138,7 +138,7 @@ abstract class Stair extends Transparent{ 3 => 3, ]; $this->meta = $faces[$player->getDirection()] & 0x03; - if(($facePos->y > 0.5 and $face !== 1) or $face === 0){ + if(($facePos->y > 0.5 and $face !== Vector3::SIDE_UP) or $face === Vector3::SIDE_DOWN){ $this->meta |= 0x04; //Upside-down stairs } $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 9b545cff4..44ca18a02 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -71,13 +71,13 @@ class Torch extends Flowable{ public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $below = $this->getSide(Vector3::SIDE_DOWN); - if($target->isTransparent() === false and $face !== 0){ + if($target->isTransparent() === false and $face !== Vector3::SIDE_DOWN){ $faces = [ - 1 => 5, - 2 => 4, - 3 => 3, - 4 => 2, - 5 => 1, + Vector3::SIDE_UP => 5, + Vector3::SIDE_NORTH => 4, + Vector3::SIDE_SOUTH => 3, + Vector3::SIDE_WEST => 2, + Vector3::SIDE_EAST => 1, ]; $this->meta = $faces[$face]; $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index 7236317fc..bf1933013 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -56,12 +56,12 @@ class Wood extends Solid{ public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ - 0 => 0, - 1 => 0, - 2 => 0b1000, - 3 => 0b1000, - 4 => 0b0100, - 5 => 0b0100, + Vector3::SIDE_DOWN => 0, + Vector3::SIDE_UP => 0, + Vector3::SIDE_NORTH => 0b1000, + Vector3::SIDE_SOUTH => 0b1000, + Vector3::SIDE_WEST => 0b0100, + Vector3::SIDE_EAST => 0b0100, ]; $this->meta = ($this->meta & 0x03) | $faces[$face]; diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index b01812376..320640944 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -80,7 +80,7 @@ class WoodenSlab extends Transparent{ public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->meta &= 0x07; - if($face === 0){ + if($face === Vector3::SIDE_DOWN){ if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === ($this->meta)){ $this->getLevel()->setBlock($target, Block::get($this->doubleId, $this->meta), true); @@ -92,7 +92,7 @@ class WoodenSlab extends Transparent{ }else{ $this->meta |= 0x08; } - }elseif($face === 1){ + }elseif($face === Vector3::SIDE_UP){ if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0 and ($target->getDamage() & 0x07) === $this->meta){ $this->getLevel()->setBlock($target, Block::get($this->doubleId, $this->meta), true);