From f2188683381671e803e580ce7770c8c01c1371b4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 5 Sep 2018 19:56:14 +0100 Subject: [PATCH] Separate facing/bearing handling from Vector3, deobfusticate a ton of @shoghicp old code --- composer.json | 2 +- composer.lock | 17 +++--- src/pocketmine/block/Anvil.php | 3 +- src/pocketmine/block/Bed.php | 29 +++------- src/pocketmine/block/Block.php | 13 ++--- src/pocketmine/block/BurningFurnace.php | 11 ++-- src/pocketmine/block/Cactus.php | 15 +++--- src/pocketmine/block/Cake.php | 5 +- src/pocketmine/block/Carpet.php | 5 +- src/pocketmine/block/Chest.php | 27 ++++------ src/pocketmine/block/CobblestoneWall.php | 12 ++--- src/pocketmine/block/Crops.php | 5 +- src/pocketmine/block/Dandelion.php | 5 +- src/pocketmine/block/DeadBush.php | 5 +- src/pocketmine/block/Door.php | 41 +++++++------- src/pocketmine/block/DoublePlant.php | 15 +++--- src/pocketmine/block/EndRod.php | 11 ++-- src/pocketmine/block/EnderChest.php | 15 +++--- src/pocketmine/block/Fallable.php | 4 +- src/pocketmine/block/Farmland.php | 4 +- src/pocketmine/block/Fence.php | 18 +++---- src/pocketmine/block/FenceGate.php | 7 ++- src/pocketmine/block/Fire.php | 10 ++-- src/pocketmine/block/Flower.php | 5 +- src/pocketmine/block/FlowerPot.php | 5 +- src/pocketmine/block/GlazedTerracotta.php | 10 +--- src/pocketmine/block/Grass.php | 4 +- src/pocketmine/block/GrassPath.php | 4 +- src/pocketmine/block/ItemFrame.php | 19 +++---- src/pocketmine/block/Leaves.php | 27 +++++----- src/pocketmine/block/Lever.php | 29 +++++----- src/pocketmine/block/MelonStem.php | 4 +- src/pocketmine/block/Mycelium.php | 4 +- src/pocketmine/block/NetherWartPlant.php | 5 +- src/pocketmine/block/Pumpkin.php | 13 ----- src/pocketmine/block/PumpkinStem.php | 4 +- src/pocketmine/block/Rail.php | 5 +- src/pocketmine/block/RedMushroom.php | 5 +- src/pocketmine/block/Sapling.php | 5 +- src/pocketmine/block/SignPost.php | 7 +-- src/pocketmine/block/Skull.php | 3 +- src/pocketmine/block/Slab.php | 9 ++-- src/pocketmine/block/SnowLayer.php | 5 +- src/pocketmine/block/Stair.php | 18 ++++--- src/pocketmine/block/StandingBanner.php | 7 +-- src/pocketmine/block/Sugarcane.php | 17 +++--- src/pocketmine/block/TallGrass.php | 5 +- src/pocketmine/block/Thin.php | 18 +++---- src/pocketmine/block/Torch.php | 35 ++++++------ src/pocketmine/block/Trapdoor.php | 16 +++--- src/pocketmine/block/Vine.php | 25 ++++----- src/pocketmine/block/WaterLily.php | 5 +- .../block/utils/PillarRotationHelper.php | 12 ++--- src/pocketmine/entity/Entity.php | 47 ++++++---------- src/pocketmine/entity/object/Painting.php | 54 +++++-------------- src/pocketmine/item/PaintingItem.php | 9 ++-- src/pocketmine/tile/Skull.php | 3 +- 57 files changed, 338 insertions(+), 384 deletions(-) diff --git a/composer.json b/composer.json index 86bf002ec..916c15bab 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "pocketmine/spl": "^0.3.0", "pocketmine/binaryutils": "^0.1.0", "pocketmine/nbt": "^0.2.1", - "pocketmine/math": "^0.2.0", + "pocketmine/math": "dev-master", "pocketmine/snooze": "^0.1.0" }, "autoload": { diff --git a/composer.lock b/composer.lock index a35c19934..6b30e4c31 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9ff16274822f181c2ed533797d2e22f7", + "content-hash": "cef68cbc2596130f6b20e6f2ecdfd58d", "packages": [ { "name": "fgrosse/phpasn1", @@ -183,16 +183,16 @@ }, { "name": "pocketmine/math", - "version": "0.2.1", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/pmmp/Math.git", - "reference": "ee299f5c9c444ca526c9c691b920f321458cf0b6" + "reference": "ec66eaa959b86ec3d3d22084a534ae466910aabe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/Math/zipball/ee299f5c9c444ca526c9c691b920f321458cf0b6", - "reference": "ee299f5c9c444ca526c9c691b920f321458cf0b6", + "url": "https://api.github.com/repos/pmmp/Math/zipball/ec66eaa959b86ec3d3d22084a534ae466910aabe", + "reference": "ec66eaa959b86ec3d3d22084a534ae466910aabe", "shasum": "" }, "require": { @@ -210,10 +210,10 @@ ], "description": "PHP library containing math related code used in PocketMine-MP", "support": { - "source": "https://github.com/pmmp/Math/tree/0.2.1", + "source": "https://github.com/pmmp/Math/tree/master", "issues": "https://github.com/pmmp/Math/issues" }, - "time": "2018-08-15T15:43:27+00:00" + "time": "2018-09-05T18:50:26+00:00" }, { "name": "pocketmine/nbt", @@ -367,7 +367,8 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "ext-pthreads": 20 + "ext-pthreads": 20, + "pocketmine/math": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 1f4ed8b7c..7279fc8c3 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -27,6 +27,7 @@ use pocketmine\inventory\AnvilInventory; use pocketmine\item\Item; use pocketmine\item\TieredTool; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -94,7 +95,7 @@ class Anvil extends Fallable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $direction = ($player !== null ? $player->getDirection() : 0) & 0x03; + $direction = $player !== null ? Bearing::rotate($player->getDirection(), -1) : 0; $this->meta = $this->getVariant() | $direction; return $this->getLevel()->setBlock($blockReplace, $this, true, true); } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index b4024b238..229fbedad 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -28,6 +28,8 @@ use pocketmine\item\ItemFactory; use pocketmine\lang\TranslationContainer; use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\Bed as TileBed; @@ -90,26 +92,9 @@ class Bed extends Transparent{ * @return int */ public static function getOtherHalfSide(int $meta, bool $isHead = false) : int{ - $rotation = $meta & 0x03; - $side = -1; - - switch($rotation){ - case 0x00: //South - $side = Vector3::SIDE_SOUTH; - break; - case 0x01: //West - $side = Vector3::SIDE_WEST; - break; - case 0x02: //North - $side = Vector3::SIDE_NORTH; - break; - case 0x03: //East - $side = Vector3::SIDE_EAST; - break; - } - + $side = Bearing::toFacing($meta & 0x03); if($isHead){ - $side = Vector3::getOppositeSide($side); + $side = Facing::opposite($side); } return $side; @@ -165,11 +150,11 @@ class Bed extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if(!$down->isTransparent()){ - $meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03; + $meta = $player instanceof Player ? Bearing::rotate($player->getDirection(), 2) : 0; //rotate 180 degrees $next = $this->getSide(self::getOtherHalfSide($meta)); - if($next->canBeReplaced() and !$next->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($next->canBeReplaced() and !$next->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true); $this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true); diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 74e1dd05f..777c9311a 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -32,6 +32,7 @@ use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\level\Position; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; use pocketmine\metadata\Metadatable; @@ -588,10 +589,10 @@ class Block extends Position implements BlockIds, Metadatable{ */ public function getHorizontalSides() : array{ return [ - $this->getSide(Vector3::SIDE_NORTH), - $this->getSide(Vector3::SIDE_SOUTH), - $this->getSide(Vector3::SIDE_WEST), - $this->getSide(Vector3::SIDE_EAST) + $this->getSide(Facing::NORTH), + $this->getSide(Facing::SOUTH), + $this->getSide(Facing::WEST), + $this->getSide(Facing::EAST) ]; } @@ -603,8 +604,8 @@ class Block extends Position implements BlockIds, Metadatable{ public function getAllSides() : array{ return array_merge( [ - $this->getSide(Vector3::SIDE_DOWN), - $this->getSide(Vector3::SIDE_UP) + $this->getSide(Facing::DOWN), + $this->getSide(Facing::UP) ], $this->getHorizontalSides() ); diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index 01bbd6779..98d0c135d 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\TieredTool; +use pocketmine\math\Bearing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\Furnace as TileFurnace; @@ -61,13 +62,9 @@ class BurningFurnace extends Solid{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $faces = [ - 0 => 4, - 1 => 2, - 2 => 5, - 3 => 3 - ]; - $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; + if($player !== null){ + $this->meta = Bearing::toFacing($player->getDirection()); + } $this->getLevel()->setBlock($blockReplace, $this, true, true); Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $face, $item, $player)); diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 105e2ab1c..8964cd248 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -29,6 +29,7 @@ use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; @@ -64,7 +65,7 @@ class Cactus extends Transparent{ } public function onNearbyBlockChange() : void{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){ $this->getLevel()->useBreakOn($this); }else{ @@ -83,7 +84,7 @@ class Cactus extends Transparent{ } public function onRandomTick() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::CACTUS){ + if($this->getSide(Facing::DOWN)->getId() !== self::CACTUS){ if($this->meta === 0x0f){ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); @@ -104,12 +105,12 @@ class Cactus extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === self::SAND or $down->getId() === self::CACTUS){ - $block0 = $this->getSide(Vector3::SIDE_NORTH); - $block1 = $this->getSide(Vector3::SIDE_SOUTH); - $block2 = $this->getSide(Vector3::SIDE_WEST); - $block3 = $this->getSide(Vector3::SIDE_EAST); + $block0 = $this->getSide(Facing::NORTH); + $block1 = $this->getSide(Facing::SOUTH); + $block2 = $this->getSide(Facing::WEST); + $block3 = $this->getSide(Facing::EAST); if(!$block0->isSolid() and !$block1->isSolid() and !$block2->isSolid() and !$block3->isSolid()){ $this->getLevel()->setBlock($this, $this, true); diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index d4c46d520..83d2b61c1 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -28,6 +28,7 @@ use pocketmine\entity\Living; use pocketmine\item\FoodSource; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -61,7 +62,7 @@ class Cake extends Transparent implements FoodSource{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() !== self::AIR){ $this->getLevel()->setBlock($blockReplace, $this, true, true); @@ -72,7 +73,7 @@ class Cake extends Transparent implements FoodSource{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method + if($this->getSide(Facing::DOWN)->getId() === self::AIR){ //Replace with common break method $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true); } } diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 6c0189a50..a3cbc8c55 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColorBlockMetaHelper; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -54,7 +55,7 @@ class Carpet extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() !== self::AIR){ $this->getLevel()->setBlock($blockReplace, $this, true, true); @@ -65,7 +66,7 @@ class Carpet extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ + if($this->getSide(Facing::DOWN)->getId() === self::AIR){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index a0b8d1a61..2e1f1e91b 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -25,6 +25,8 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\Chest as TileChest; @@ -56,22 +58,15 @@ class Chest extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $faces = [ - 0 => 4, - 1 => 2, - 2 => 5, - 3 => 3 - ]; - $chest = null; - $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; + if($player !== null){ + $this->meta = Bearing::toFacing($player->getDirection()); + } - for($side = 2; $side <= 5; ++$side){ - if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){ - continue; - }elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){ - continue; - } + foreach([ + Bearing::toFacing(Bearing::rotate($player->getDirection(), -1)), + Bearing::toFacing(Bearing::rotate($player->getDirection(), 1)) + ] as $side){ $c = $this->getSide($side); if($c->getId() === $this->id and $c->getDamage() === $this->meta){ $tile = $this->getLevel()->getTile($c); @@ -105,8 +100,8 @@ class Chest extends Transparent{ } if( - !$this->getSide(Vector3::SIDE_UP)->isTransparent() or - ($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Vector3::SIDE_UP)->isTransparent()) or + !$this->getSide(Facing::UP)->isTransparent() or + ($chest->isPaired() and !$chest->getPair()->getBlock()->getSide(Facing::UP)->isTransparent()) or !$chest->canOpenWith($item->getCustomName()) ){ return true; diff --git a/src/pocketmine/block/CobblestoneWall.php b/src/pocketmine/block/CobblestoneWall.php index 34bd9a8b1..86c2d977d 100644 --- a/src/pocketmine/block/CobblestoneWall.php +++ b/src/pocketmine/block/CobblestoneWall.php @@ -25,7 +25,7 @@ namespace pocketmine\block; use pocketmine\item\TieredTool; use pocketmine\math\AxisAlignedBB; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; class CobblestoneWall extends Transparent{ public const NONE_MOSSY_WALL = 0; @@ -60,14 +60,14 @@ class CobblestoneWall extends Transparent{ protected function recalculateBoundingBox() : ?AxisAlignedBB{ //walls don't have any special collision boxes like fences do - $north = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); - $south = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); - $west = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); - $east = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); + $north = $this->canConnect($this->getSide(Facing::NORTH)); + $south = $this->canConnect($this->getSide(Facing::SOUTH)); + $west = $this->canConnect($this->getSide(Facing::WEST)); + $east = $this->canConnect($this->getSide(Facing::EAST)); $inset = 0.25; if( - $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR and //if there is a block on top, it stays as a post + $this->getSide(Facing::UP)->getId() === Block::AIR and //if there is a block on top, it stays as a post ( ($north and $south and !$west and !$east) or (!$north and !$south and $west and $east) diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index 43be76732..476c8d5ce 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; @@ -32,7 +33,7 @@ use pocketmine\Server; abstract class Crops extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($blockReplace->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){ + if($blockReplace->getSide(Facing::DOWN)->getId() === Block::FARMLAND){ $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; @@ -65,7 +66,7 @@ abstract class Crops extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){ + if($this->getSide(Facing::DOWN)->getId() !== Block::FARMLAND){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index bf9f16b8e..443ba0811 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -41,7 +42,7 @@ class Dandelion extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ $this->getLevel()->setBlock($blockReplace, $this, true, true); @@ -52,7 +53,7 @@ class Dandelion extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/DeadBush.php b/src/pocketmine/block/DeadBush.php index 2ea91e6e2..8f3c5c354 100644 --- a/src/pocketmine/block/DeadBush.php +++ b/src/pocketmine/block/DeadBush.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -41,7 +42,7 @@ class DeadBush extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if(!$this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if(!$this->getSide(Facing::DOWN)->isTransparent()){ return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -49,7 +50,7 @@ class DeadBush extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 3b4f54af7..c95947725 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -26,6 +26,8 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -41,11 +43,11 @@ abstract class Door extends Transparent{ $isUp = ($damage & 0x08) > 0; if($isUp){ - $down = $this->getSide(Vector3::SIDE_DOWN)->getDamage(); + $down = $this->getSide(Facing::DOWN)->getDamage(); $up = $damage; }else{ $down = $damage; - $up = $this->getSide(Vector3::SIDE_UP)->getDamage(); + $up = $this->getSide(Facing::UP)->getDamage(); } $isRight = ($up & 0x01) > 0; @@ -109,36 +111,33 @@ abstract class Door extends Transparent{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method + if($this->getSide(Facing::DOWN)->getId() === self::AIR){ //Replace with common break method $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false); - if($this->getSide(Vector3::SIDE_UP) instanceof Door){ - $this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), BlockFactory::get(Block::AIR), false); + if($this->getSide(Facing::UP) instanceof Door){ + $this->getLevel()->setBlock($this->getSide(Facing::UP), BlockFactory::get(Block::AIR), false); } } } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($face === Vector3::SIDE_UP){ - $blockUp = $this->getSide(Vector3::SIDE_UP); - $blockDown = $this->getSide(Vector3::SIDE_DOWN); + if($face === Facing::UP){ + $blockUp = $this->getSide(Facing::UP); + $blockDown = $this->getSide(Facing::DOWN); if(!$blockUp->canBeReplaced() or $blockDown->isTransparent()){ return false; } - $direction = $player instanceof Player ? $player->getDirection() : 0; - $faces = [ - 0 => 3, - 1 => 4, - 2 => 2, - 3 => 5 - ]; - $next = $this->getSide($faces[($direction + 2) % 4]); - $next2 = $this->getSide($faces[$direction]); + + $ccw = Bearing::toFacing($player instanceof Player ? Bearing::rotate($player->getDirection(), -1) : Facing::EAST); + + $next = $this->getSide(Facing::opposite($ccw)); + $next2 = $this->getSide($ccw); + $metaUp = 0x08; if($next->getId() === $this->getId() or (!$next2->isTransparent() and $next->isTransparent())){ //Door hinge $metaUp |= 0x01; } - $this->setDamage($player->getDirection() & 0x03); + $this->setDamage(Bearing::rotate($player->getDirection(), -1)); $this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom $this->getLevel()->setBlock($blockUp, BlockFactory::get($this->getId(), $metaUp), true); //Top return true; @@ -149,7 +148,7 @@ abstract class Door extends Transparent{ public function onActivate(Item $item, Player $player = null) : bool{ if(($this->getDamage() & 0x08) === 0x08){ //Top - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === $this->getId()){ $meta = $down->getDamage() ^ 0x04; $this->level->setBlock($down, BlockFactory::get($this->getId(), $meta), true); @@ -185,12 +184,12 @@ abstract class Door extends Transparent{ public function getAffectedBlocks() : array{ if(($this->getDamage() & 0x08) === 0x08){ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === $this->getId()){ return [$this, $down]; } }else{ - $up = $this->getSide(Vector3::SIDE_UP); + $up = $this->getSide(Facing::UP); if($up->getId() === $this->getId()){ return [$this, $up]; } diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index b1d38fff1..f1d477675 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -54,10 +55,10 @@ class DoublePlant extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $id = $blockReplace->getSide(Vector3::SIDE_DOWN)->getId(); - if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Vector3::SIDE_UP)->canBeReplaced()){ + $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, false); - $this->getLevel()->setBlock($blockReplace->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false); + $this->getLevel()->setBlock($blockReplace->getSide(Facing::UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false); return true; } @@ -71,9 +72,9 @@ class DoublePlant extends Flowable{ */ public function isValidHalfPlant() : bool{ if($this->meta & self::BITFLAG_TOP){ - $other = $this->getSide(Vector3::SIDE_DOWN); + $other = $this->getSide(Facing::DOWN); }else{ - $other = $this->getSide(Vector3::SIDE_UP); + $other = $this->getSide(Facing::UP); } return ( @@ -84,7 +85,7 @@ class DoublePlant extends Flowable{ } public function onNearbyBlockChange() : void{ - if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $this->getSide(Vector3::SIDE_DOWN)->isTransparent())){ + if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $this->getSide(Facing::DOWN)->isTransparent())){ $this->getLevel()->useBreakOn($this); } } @@ -119,7 +120,7 @@ class DoublePlant extends Flowable{ public function getAffectedBlocks() : array{ if($this->isValidHalfPlant()){ - return [$this, $this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP)]; + return [$this, $this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Facing::DOWN : Facing::UP)]; } return parent::getAffectedBlocks(); diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index da64cc568..e65270740 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -41,7 +42,7 @@ class EndRod extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){ + if(Facing::axis($face) === Facing::AXIS_Y){ $this->meta = $face; }else{ $this->meta = $face ^ 0x01; @@ -62,11 +63,11 @@ class EndRod extends Flowable{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $m = $this->meta & ~0x01; + $m = $this->meta >> 1; //everything except up/down are inverted, but we can still use this for axis $width = 0.375; switch($m){ - case 0x00: //up/down + case Facing::AXIS_Y: return new AxisAlignedBB( $width, 0, @@ -75,7 +76,7 @@ class EndRod extends Flowable{ 1, 1 - $width ); - case 0x02: //north/south + case Facing::AXIS_Z: return new AxisAlignedBB( 0, $width, @@ -84,7 +85,7 @@ class EndRod extends Flowable{ 1 - $width, 1 - $width ); - case 0x04: //east/west + case Facing::AXIS_X: return new AxisAlignedBB( $width, $width, diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index ea5afb257..015f90948 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -26,6 +26,8 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\TieredTool; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\EnderChest as TileEnderChest; @@ -60,14 +62,9 @@ class EnderChest extends Chest{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $faces = [ - 0 => 4, - 1 => 2, - 2 => 5, - 3 => 3 - ]; - - $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; + if($player !== null){ + $this->meta = Bearing::toFacing($player->getDirection()); + } $this->getLevel()->setBlock($blockReplace, $this, true, true); Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this, $face, $item, $player)); @@ -86,7 +83,7 @@ class EnderChest extends Chest{ $enderChest = Tile::createTile(Tile::ENDER_CHEST, $this->getLevel(), TileEnderChest::createNBT($this)); } - if(!$this->getSide(Vector3::SIDE_UP)->isTransparent()){ + if(!$this->getSide(Facing::UP)->isTransparent()){ return true; } diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index d3fe4dec5..990a13ebe 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -24,12 +24,12 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\entity\Entity; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; abstract class Fallable extends Solid{ public function onNearbyBlockChange() : void{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === self::AIR or $down instanceof Liquid or $down instanceof Fire){ $this->level->setBlock($this, BlockFactory::get(Block::AIR), true); diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 9c473a512..b8a32a753 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -26,7 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\AxisAlignedBB; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; class Farmland extends Transparent{ @@ -53,7 +53,7 @@ class Farmland extends Transparent{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_UP)->isSolid()){ + if($this->getSide(Facing::UP)->isSolid()){ $this->level->setBlock($this, BlockFactory::get(Block::DIRT), true); } } diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index aa9cdd00f..f7981e207 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\math\AxisAlignedBB; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; abstract class Fence extends Transparent{ @@ -40,12 +40,12 @@ abstract class Fence extends Transparent{ $width = 0.5 - $this->getThickness() / 2; return new AxisAlignedBB( - ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), + ($this->canConnect($this->getSide(Facing::WEST)) ? 0 : $width), 0, - ($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), - 1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), + ($this->canConnect($this->getSide(Facing::NORTH)) ? 0 : $width), + 1 - ($this->canConnect($this->getSide(Facing::EAST)) ? 0 : $width), 1.5, - 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) + 1 - ($this->canConnect($this->getSide(Facing::SOUTH)) ? 0 : $width) ); } @@ -55,8 +55,8 @@ abstract class Fence extends Transparent{ /** @var AxisAlignedBB[] $bbs */ $bbs = []; - $connectWest = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); - $connectEast = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); + $connectWest = $this->canConnect($this->getSide(Facing::WEST)); + $connectEast = $this->canConnect($this->getSide(Facing::EAST)); if($connectWest or $connectEast){ //X axis (west/east) @@ -70,8 +70,8 @@ abstract class Fence extends Transparent{ ); } - $connectNorth = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); - $connectSouth = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); + $connectNorth = $this->canConnect($this->getSide(Facing::NORTH)); + $connectSouth = $this->canConnect($this->getSide(Facing::SOUTH)); if($connectNorth or $connectSouth){ //Z axis (north/south) diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 1d7a93b9c..1aacbbf84 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -68,7 +69,9 @@ class FenceGate extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $this->meta = ($player instanceof Player ? ($player->getDirection() - 1) & 0x03 : 0); + if($player !== null){ + $this->meta = Bearing::rotate($player->getDirection(), 2); + } $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; @@ -82,7 +85,7 @@ class FenceGate extends Transparent{ $this->meta = (($this->meta ^ 0x04) & ~0x02); if($player !== null){ - $this->meta |= (($player->getDirection() - 1) & 0x02); + $this->meta |= (Bearing::rotate($player->getDirection(), 2) & 0x02); //open towards the player, retaining axis } $this->getLevel()->setBlock($this, $this, true); diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index ace4a385d..33e971fd3 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -30,7 +30,7 @@ use pocketmine\event\entity\EntityCombustByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; use pocketmine\Server; class Fire extends Flowable{ @@ -80,7 +80,7 @@ class Fire extends Flowable{ } public function onNearbyBlockChange() : void{ - if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){ + if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){ $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true); }else{ $this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40)); @@ -92,7 +92,7 @@ class Fire extends Flowable{ } public function onRandomTick() : void{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); $result = null; if($this->meta < 15 and mt_rand(0, 2) === 0){ @@ -130,8 +130,8 @@ class Fire extends Flowable{ } //vanilla uses a 250 upper bound here, but I don't think they intended to increase the chance of incineration - $this->burnBlock($this->getSide(Vector3::SIDE_UP), 350); - $this->burnBlock($this->getSide(Vector3::SIDE_DOWN), 350); + $this->burnBlock($this->getSide(Facing::UP), 350); + $this->burnBlock($this->getSide(Facing::DOWN), 350); //TODO: fire spread } diff --git a/src/pocketmine/block/Flower.php b/src/pocketmine/block/Flower.php index 2946b3cbe..ac7a063a8 100644 --- a/src/pocketmine/block/Flower.php +++ b/src/pocketmine/block/Flower.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -60,7 +61,7 @@ class Flower extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ $this->getLevel()->setBlock($blockReplace, $this, true); @@ -71,7 +72,7 @@ class Flower extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 3f92b7cc0..8dd7f9db2 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\FlowerPot as TileFlowerPot; @@ -52,7 +53,7 @@ class FlowerPot extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ return false; } @@ -62,7 +63,7 @@ class FlowerPot extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index 336b51325..d4c3e3063 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\TieredTool; +use pocketmine\math\Bearing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -45,15 +46,8 @@ class GlazedTerracotta extends Solid{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $faces = [ - 0 => 4, - 1 => 3, - 2 => 5, - 3 => 2 - ]; - $this->meta = $faces[(~($player->getDirection() - 1)) & 0x03]; + $this->meta = Bearing::toFacing($player->getDirection()); } - return $this->getLevel()->setBlock($blockReplace, $this, true, true); } diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index a2887e0fd..43045355e 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -29,7 +29,7 @@ use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\Shovel; use pocketmine\level\generator\object\TallGrass as TallGrassObject; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; use pocketmine\Player; use pocketmine\utils\Random; @@ -105,7 +105,7 @@ class Grass extends Solid{ $this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND)); return true; - }elseif($item instanceof Shovel and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){ + }elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === Block::AIR){ $item->applyDamage(1); $this->getLevel()->setBlock($this, BlockFactory::get(Block::GRASS_PATH)); diff --git a/src/pocketmine/block/GrassPath.php b/src/pocketmine/block/GrassPath.php index e58c40224..dbe08ca78 100644 --- a/src/pocketmine/block/GrassPath.php +++ b/src/pocketmine/block/GrassPath.php @@ -26,7 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\AxisAlignedBB; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; class GrassPath extends Transparent{ @@ -53,7 +53,7 @@ class GrassPath extends Transparent{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_UP)->isSolid()){ + if($this->getSide(Facing::UP)->isSolid()){ $this->level->setBlock($this, BlockFactory::get(Block::DIRT), true); } } diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 9b44104e1..e01fcc938 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\ItemFrame as TileItemFrame; @@ -59,10 +60,10 @@ class ItemFrame extends Flowable{ public function onNearbyBlockChange() : void{ $sides = [ - 0 => Vector3::SIDE_WEST, - 1 => Vector3::SIDE_EAST, - 2 => Vector3::SIDE_NORTH, - 3 => Vector3::SIDE_SOUTH + 0 => Facing::WEST, + 1 => Facing::EAST, + 2 => Facing::NORTH, + 3 => Facing::SOUTH ]; if(!$this->getSide($sides[$this->meta])->isSolid()){ $this->level->useBreakOn($this); @@ -70,15 +71,15 @@ class ItemFrame extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($face === Vector3::SIDE_DOWN or $face === Vector3::SIDE_UP or !$blockClicked->isSolid()){ + if($face === Facing::DOWN or $face === Facing::UP or !$blockClicked->isSolid()){ return false; } $faces = [ - Vector3::SIDE_NORTH => 3, - Vector3::SIDE_SOUTH => 2, - Vector3::SIDE_WEST => 1, - Vector3::SIDE_EAST => 0 + Facing::NORTH => 3, + Facing::SOUTH => 2, + Facing::WEST => 1, + Facing::EAST => 0 ]; $this->meta = $faces[$face]; diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index 05ef8a882..212354682 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\event\block\LeavesDecayEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -76,7 +77,7 @@ class Leaves extends Transparent{ return true; }elseif($pos->getId() === $this->id and $distance < 3){ $visited[$index] = true; - $down = $pos->getSide(Vector3::SIDE_DOWN)->getId(); + $down = $pos->getSide(Facing::DOWN)->getId(); if($down === $this->woodType){ return true; } @@ -89,38 +90,38 @@ class Leaves extends Transparent{ }else{ //No more loops switch($fromSide){ case 2: - if($this->findLog($pos->getSide(Vector3::SIDE_NORTH), $visited, $distance + 1, $fromSide)){ + if($this->findLog($pos->getSide(Facing::NORTH), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_WEST), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::WEST), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_EAST), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::EAST), $visited, $distance + 1, $fromSide)){ return true; } break; case 3: - if($this->findLog($pos->getSide(Vector3::SIDE_SOUTH), $visited, $distance + 1, $fromSide)){ + if($this->findLog($pos->getSide(Facing::SOUTH), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_WEST), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::WEST), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_EAST), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::EAST), $visited, $distance + 1, $fromSide)){ return true; } break; case 4: - if($this->findLog($pos->getSide(Vector3::SIDE_NORTH), $visited, $distance + 1, $fromSide)){ + if($this->findLog($pos->getSide(Facing::NORTH), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_SOUTH), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::SOUTH), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_WEST), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::WEST), $visited, $distance + 1, $fromSide)){ return true; } break; case 5: - if($this->findLog($pos->getSide(Vector3::SIDE_NORTH), $visited, $distance + 1, $fromSide)){ + if($this->findLog($pos->getSide(Facing::NORTH), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_SOUTH), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::SOUTH), $visited, $distance + 1, $fromSide)){ return true; - }elseif($this->findLog($pos->getSide(Vector3::SIDE_EAST), $visited, $distance + 1, $fromSide)){ + }elseif($this->findLog($pos->getSide(Facing::EAST), $visited, $distance + 1, $fromSide)){ return true; } break; diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 10b6f3042..7b622af4a 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -24,6 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -52,19 +54,20 @@ class Lever extends Flowable{ return false; } - if($face === Vector3::SIDE_DOWN){ + if($face === Facing::DOWN){ $this->meta = 0; }else{ $this->meta = 6 - $face; } if($player !== null){ - if(($player->getDirection() & 0x01) === 0){ - if($face === Vector3::SIDE_UP){ + $bearing = $player->getDirection(); + if($bearing === Bearing::EAST or $bearing === Bearing::WEST){ + if($face === Facing::UP){ $this->meta = 6; } }else{ - if($face === Vector3::SIDE_DOWN){ + if($face === Facing::DOWN){ $this->meta = 7; } } @@ -74,15 +77,15 @@ class Lever extends Flowable{ } public function onNearbyBlockChange() : void{ - $faces = [ - 0 => Vector3::SIDE_UP, - 1 => Vector3::SIDE_WEST, - 2 => Vector3::SIDE_EAST, - 3 => Vector3::SIDE_NORTH, - 4 => Vector3::SIDE_SOUTH, - 5 => Vector3::SIDE_DOWN, - 6 => Vector3::SIDE_DOWN, - 7 => Vector3::SIDE_UP + static $faces = [ + 0 => Facing::UP, + 1 => Facing::WEST, + 2 => Facing::EAST, + 3 => Facing::NORTH, + 4 => Facing::SOUTH, + 5 => Facing::DOWN, + 6 => Facing::DOWN, + 7 => Facing::UP ]; if(!$this->getSide($faces[$this->meta & 0x07])->isSolid()){ $this->level->useBreakOn($this); diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index eb4c6d0ee..48e4f19ec 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -26,7 +26,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; use pocketmine\Server; class MelonStem extends Crops{ @@ -58,7 +58,7 @@ class MelonStem extends Crops{ } } $side = $this->getSide(mt_rand(2, 5)); - $d = $side->getSide(Vector3::SIDE_DOWN); + $d = $side->getSide(Facing::DOWN); if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::MELON_BLOCK))); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 36439e0e8..331d4ddc7 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -26,7 +26,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; use pocketmine\Server; class Mycelium extends Solid{ @@ -66,7 +66,7 @@ class Mycelium extends Solid{ $z = mt_rand($this->z - 1, $this->z + 1); $block = $this->getLevel()->getBlockAt($x, $y, $z); if($block->getId() === Block::DIRT){ - if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){ + if($block->getSide(Facing::UP) instanceof Transparent){ Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, BlockFactory::get(Block::MYCELIUM))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($block, $ev->getNewState()); diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index 14e82f548..9071ca29e 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -27,6 +27,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -44,7 +45,7 @@ class NetherWartPlant extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === Block::SOUL_SAND){ $this->getLevel()->setBlock($blockReplace, $this, false, true); @@ -55,7 +56,7 @@ class NetherWartPlant extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::SOUL_SAND){ + if($this->getSide(Facing::DOWN)->getId() !== Block::SOUL_SAND){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Pumpkin.php b/src/pocketmine/block/Pumpkin.php index 811dd06e5..3c63bae35 100644 --- a/src/pocketmine/block/Pumpkin.php +++ b/src/pocketmine/block/Pumpkin.php @@ -23,10 +23,6 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\item\Item; -use pocketmine\math\Vector3; -use pocketmine\Player; - class Pumpkin extends Solid{ protected $id = self::PUMPKIN; @@ -47,15 +43,6 @@ class Pumpkin extends Solid{ return "Pumpkin"; } - public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($player instanceof Player){ - $this->meta = ((int) $player->getDirection() + 1) % 4; - } - $this->getLevel()->setBlock($blockReplace, $this, true, true); - - return true; - } - public function getVariantBitmask() : int{ return 0; } diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index 33d83470f..7cc4da642 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -26,7 +26,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; use pocketmine\Server; class PumpkinStem extends Crops{ @@ -58,7 +58,7 @@ class PumpkinStem extends Crops{ } } $side = $this->getSide(mt_rand(2, 5)); - $d = $side->getSide(Vector3::SIDE_DOWN); + $d = $side->getSide(Facing::DOWN); if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::PUMPKIN))); if(!$ev->isCancelled()){ diff --git a/src/pocketmine/block/Rail.php b/src/pocketmine/block/Rail.php index 8ac173cd3..7e5e36f97 100644 --- a/src/pocketmine/block/Rail.php +++ b/src/pocketmine/block/Rail.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -55,7 +56,7 @@ class Rail extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if(!$blockReplace->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if(!$blockReplace->getSide(Facing::DOWN)->isTransparent()){ return $this->getLevel()->setBlock($blockReplace, $this, true, true); } @@ -63,7 +64,7 @@ class Rail extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); }else{ //TODO: Update rail connectivity diff --git a/src/pocketmine/block/RedMushroom.php b/src/pocketmine/block/RedMushroom.php index 5c4d5296b..d5f25a60b 100644 --- a/src/pocketmine/block/RedMushroom.php +++ b/src/pocketmine/block/RedMushroom.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -44,13 +45,13 @@ class RedMushroom extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); } } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if(!$down->isTransparent()){ $this->getLevel()->setBlock($blockReplace, $this, true, true); diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index a6c65bba9..5d6d51c0f 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\generator\object\Tree; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\utils\Random; @@ -56,7 +57,7 @@ class Sapling extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ $this->getLevel()->setBlock($blockReplace, $this, true, true); @@ -80,7 +81,7 @@ class Sapling extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + if($this->getSide(Facing::DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index fdd4a0e1a..c1b820f66 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\Sign as TileSign; @@ -58,9 +59,9 @@ class SignPost extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($face !== Vector3::SIDE_DOWN){ + if($face !== Facing::DOWN){ - if($face === Vector3::SIDE_UP){ + if($face === Facing::UP){ $this->meta = $player !== null ? (floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f) : 0; $this->getLevel()->setBlock($blockReplace, $this, true); }else{ @@ -77,7 +78,7 @@ class SignPost extends Transparent{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ + if($this->getSide(Facing::DOWN)->getId() === self::AIR){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index dc74b96eb..34c6077d7 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\Skull as TileSkull; @@ -54,7 +55,7 @@ class Skull extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($face === Vector3::SIDE_DOWN){ + if($face === Facing::DOWN){ return false; } diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 319d03998..66bb2940f 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -43,9 +44,9 @@ abstract class Slab extends Transparent{ if($blockReplace->getId() === $this->getId() and $blockReplace->getVariant() === $this->getVariant()){ if(($blockReplace->getDamage() & 0x08) !== 0){ //Trying to combine with top slab - return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_UP); + return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP); }else{ - return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Vector3::SIDE_DOWN); + return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Facing::DOWN); } } @@ -54,7 +55,7 @@ abstract class Slab extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $this->meta &= 0x07; - if($face === Vector3::SIDE_DOWN){ + if($face === Facing::DOWN){ if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and $blockClicked->getVariant() === $this->getVariant()){ $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true); @@ -66,7 +67,7 @@ abstract class Slab extends Transparent{ }else{ $this->meta |= 0x08; } - }elseif($face === Vector3::SIDE_UP){ + }elseif($face === Facing::UP){ if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and $blockClicked->getVariant() === $this->getVariant()){ $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->getDoubleSlabId(), $this->getVariant()), true); diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index ab8168e82..b7c730b9d 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\TieredTool; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -58,7 +59,7 @@ class SnowLayer extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($blockReplace->getSide(Vector3::SIDE_DOWN)->isSolid()){ + if($blockReplace->getSide(Facing::DOWN)->isSolid()){ //TODO: fix placement $this->getLevel()->setBlock($blockReplace, $this, true); @@ -69,7 +70,7 @@ class SnowLayer extends Flowable{ } public function onNearbyBlockChange() : void{ - if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid()){ + if(!$this->getSide(Facing::DOWN)->isSolid()){ $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false, false); } } diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index 27e66a24e..a7a7a425a 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -25,6 +25,8 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -69,14 +71,16 @@ abstract class Stair extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $faces = [ - 0 => 0, - 1 => 2, - 2 => 1, - 3 => 3 + static $faces = [ + Bearing::SOUTH => 3, //north + Bearing::WEST => 0, //east + Bearing::NORTH => 2, //south + Bearing::EAST => 1 //west ]; - $this->meta = $faces[$player->getDirection()] & 0x03; - if(($clickVector->y > 0.5 and $face !== Vector3::SIDE_UP) or $face === Vector3::SIDE_DOWN){ + if($player !== null){ + $this->meta = $faces[$player->getDirection()]; + } + if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){ $this->meta |= 0x04; //Upside-down stairs } $this->getLevel()->setBlock($blockReplace, $this, true, true); diff --git a/src/pocketmine/block/StandingBanner.php b/src/pocketmine/block/StandingBanner.php index 88520deb2..352bbd170 100644 --- a/src/pocketmine/block/StandingBanner.php +++ b/src/pocketmine/block/StandingBanner.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\Banner as TileBanner; @@ -58,8 +59,8 @@ class StandingBanner extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if($face !== Vector3::SIDE_DOWN){ - if($face === Vector3::SIDE_UP and $player !== null){ + if($face !== Facing::DOWN){ + if($face === Facing::UP and $player !== null){ $this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f; $this->getLevel()->setBlock($blockReplace, $this, true); }else{ @@ -75,7 +76,7 @@ class StandingBanner extends Transparent{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ + if($this->getSide(Facing::DOWN)->getId() === self::AIR){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index bddd9ec1c..f2ddab721 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; @@ -45,7 +46,7 @@ class Sugarcane extends Flowable{ public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal - if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){ + if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === self::AIR){ @@ -69,7 +70,7 @@ class Sugarcane extends Flowable{ } public function onNearbyBlockChange() : void{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->isTransparent() and $down->getId() !== self::SUGARCANE_BLOCK){ $this->getLevel()->useBreakOn($this); } @@ -80,7 +81,7 @@ class Sugarcane extends Flowable{ } public function onRandomTick() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){ + if($this->getSide(Facing::DOWN)->getId() !== self::SUGARCANE_BLOCK){ if($this->meta === 0x0F){ for($y = 1; $y < 3; ++$y){ $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); @@ -99,16 +100,16 @@ class Sugarcane extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === self::SUGARCANE_BLOCK){ $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); return true; }elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){ - $block0 = $down->getSide(Vector3::SIDE_NORTH); - $block1 = $down->getSide(Vector3::SIDE_SOUTH); - $block2 = $down->getSide(Vector3::SIDE_WEST); - $block3 = $down->getSide(Vector3::SIDE_EAST); + $block0 = $down->getSide(Facing::NORTH); + $block1 = $down->getSide(Facing::SOUTH); + $block2 = $down->getSide(Facing::WEST); + $block3 = $down->getSide(Facing::EAST); if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){ $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index fe3c133c4..310398f53 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -50,7 +51,7 @@ class TallGrass extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); + $down = $this->getSide(Facing::DOWN); if($down->getId() === self::GRASS){ $this->getLevel()->setBlock($blockReplace, $this, true); @@ -61,7 +62,7 @@ class TallGrass extends Flowable{ } public function onNearbyBlockChange() : void{ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ //Replace with common break method + if($this->getSide(Facing::DOWN)->isTransparent()){ //Replace with common break method $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); } } diff --git a/src/pocketmine/block/Thin.php b/src/pocketmine/block/Thin.php index fb6b5f91c..3c33da2cf 100644 --- a/src/pocketmine/block/Thin.php +++ b/src/pocketmine/block/Thin.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\math\AxisAlignedBB; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; abstract class Thin extends Transparent{ @@ -32,12 +32,12 @@ abstract class Thin extends Transparent{ $width = 0.5 - 0.125 / 2; return new AxisAlignedBB( - ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), + ($this->canConnect($this->getSide(Facing::WEST)) ? 0 : $width), 0, - ($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), - 1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), + ($this->canConnect($this->getSide(Facing::NORTH)) ? 0 : $width), + 1 - ($this->canConnect($this->getSide(Facing::EAST)) ? 0 : $width), 1, - 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) + 1 - ($this->canConnect($this->getSide(Facing::SOUTH)) ? 0 : $width) ); } @@ -47,8 +47,8 @@ abstract class Thin extends Transparent{ /** @var AxisAlignedBB[] $bbs */ $bbs = []; - $connectWest = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); - $connectEast = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); + $connectWest = $this->canConnect($this->getSide(Facing::WEST)); + $connectEast = $this->canConnect($this->getSide(Facing::EAST)); if($connectWest or $connectEast){ //X axis (west/east) @@ -62,8 +62,8 @@ abstract class Thin extends Transparent{ ); } - $connectNorth = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); - $connectSouth = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); + $connectNorth = $this->canConnect($this->getSide(Facing::NORTH)); + $connectSouth = $this->canConnect($this->getSide(Facing::SOUTH)); if($connectNorth or $connectSouth){ //Z axis (north/south) diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 3c310a68a..b553bfd8c 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -44,32 +45,32 @@ class Torch extends Flowable{ } public function onNearbyBlockChange() : void{ - $below = $this->getSide(Vector3::SIDE_DOWN); + $below = $this->getSide(Facing::DOWN); $side = $this->getDamage(); - $faces = [ - 0 => Vector3::SIDE_DOWN, - 1 => Vector3::SIDE_WEST, - 2 => Vector3::SIDE_EAST, - 3 => Vector3::SIDE_NORTH, - 4 => Vector3::SIDE_SOUTH, - 5 => Vector3::SIDE_DOWN + static $faces = [ + 0 => Facing::DOWN, + 1 => Facing::WEST, + 2 => Facing::EAST, + 3 => Facing::NORTH, + 4 => Facing::SOUTH, + 5 => Facing::DOWN ]; - if($this->getSide($faces[$side])->isTransparent() and !($side === Vector3::SIDE_DOWN and ($below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL))){ + if($this->getSide($faces[$side])->isTransparent() and !($side === Facing::DOWN and ($below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL))){ $this->getLevel()->useBreakOn($this); } } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $below = $this->getSide(Vector3::SIDE_DOWN); + $below = $this->getSide(Facing::DOWN); - if(!$blockClicked->isTransparent() and $face !== Vector3::SIDE_DOWN){ - $faces = [ - Vector3::SIDE_UP => 5, - Vector3::SIDE_NORTH => 4, - Vector3::SIDE_SOUTH => 3, - Vector3::SIDE_WEST => 2, - Vector3::SIDE_EAST => 1 + if(!$blockClicked->isTransparent() and $face !== Facing::DOWN){ + static $faces = [ + Facing::UP => 5, + Facing::NORTH => 4, + Facing::SOUTH => 3, + Facing::WEST => 2, + Facing::EAST => 1 ]; $this->meta = $faces[$face]; $this->getLevel()->setBlock($blockReplace, $this, true, true); diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 63277f66c..1d01dcd02 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -26,6 +26,8 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -81,16 +83,16 @@ class Trapdoor extends Transparent{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - $directions = [ - 0 => 1, - 1 => 3, - 2 => 0, - 3 => 2 + static $directions = [ + Bearing::SOUTH => 2, + Bearing::WEST => 1, + Bearing::NORTH => 3, + Bearing::EAST => 0 ]; if($player !== null){ - $this->meta = $directions[$player->getDirection() & 0x03]; + $this->meta = $directions[$player->getDirection()]; } - if(($clickVector->y > 0.5 and $face !== self::SIDE_UP) or $face === self::SIDE_DOWN){ + if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){ $this->meta |= self::MASK_UPPER; //top half of block } $this->getLevel()->setBlock($blockReplace, $this, true, true); diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index f9c27a65e..72bc36fc5 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\entity\Entity; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -111,7 +112,7 @@ class Vine extends Flowable{ //TODO: Missing NORTH check - if(!$flag and $this->getSide(Vector3::SIDE_UP)->isSolid()){ + if(!$flag and $this->getSide(Facing::UP)->isSolid()){ $minY = min($minY, 0.9375); $maxY = 1; $minX = 0; @@ -124,15 +125,15 @@ class Vine extends Flowable{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ - if(!$blockClicked->isSolid() or $face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){ + if(!$blockClicked->isSolid() or $face === Facing::UP or $face === Facing::DOWN){ return false; } - $faces = [ - Vector3::SIDE_NORTH => self::FLAG_SOUTH, - Vector3::SIDE_SOUTH => self::FLAG_NORTH, - Vector3::SIDE_WEST => self::FLAG_EAST, - Vector3::SIDE_EAST => self::FLAG_WEST + static $faces = [ + Facing::NORTH => self::FLAG_SOUTH, + Facing::SOUTH => self::FLAG_NORTH, + Facing::WEST => self::FLAG_EAST, + Facing::EAST => self::FLAG_WEST ]; $this->meta = $faces[$face] ?? 0; @@ -145,11 +146,11 @@ class Vine extends Flowable{ } public function onNearbyBlockChange() : void{ - $sides = [ - self::FLAG_SOUTH => Vector3::SIDE_SOUTH, - self::FLAG_WEST => Vector3::SIDE_WEST, - self::FLAG_NORTH => Vector3::SIDE_NORTH, - self::FLAG_EAST => Vector3::SIDE_EAST + static $sides = [ + self::FLAG_SOUTH => Facing::SOUTH, + self::FLAG_WEST => Facing::WEST, + self::FLAG_NORTH => Facing::NORTH, + self::FLAG_EAST => Facing::EAST ]; $meta = $this->meta; diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php index 78eb3cd33..59f999960 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -51,7 +52,7 @@ class WaterLily extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($blockClicked instanceof Water){ - $up = $blockClicked->getSide(Vector3::SIDE_UP); + $up = $blockClicked->getSide(Facing::UP); if($up->getId() === Block::AIR){ $this->getLevel()->setBlock($up, $this, true, true); return true; @@ -62,7 +63,7 @@ class WaterLily extends Flowable{ } public function onNearbyBlockChange() : void{ - if(!($this->getSide(Vector3::SIDE_DOWN) instanceof Water)){ + if(!($this->getSide(Facing::DOWN) instanceof Water)){ $this->getLevel()->useBreakOn($this); } } diff --git a/src/pocketmine/block/utils/PillarRotationHelper.php b/src/pocketmine/block/utils/PillarRotationHelper.php index 8a633c11f..8e64afd92 100644 --- a/src/pocketmine/block/utils/PillarRotationHelper.php +++ b/src/pocketmine/block/utils/PillarRotationHelper.php @@ -23,17 +23,17 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\math\Vector3; +use pocketmine\math\Facing; class PillarRotationHelper{ public static function getMetaFromFace(int $meta, int $face) : int{ - $faces = [ - Vector3::SIDE_DOWN => 0, - Vector3::SIDE_NORTH => 0x08, - Vector3::SIDE_WEST => 0x04 + static $bits = [ + Facing::AXIS_Y => 0, + Facing::AXIS_Z => 0x08, + Facing::AXIS_X => 0x04 ]; - return ($meta & 0x03) | $faces[$face & ~0x01]; + return ($meta & 0x03) | $bits[Facing::axis($face)]; } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index eb8aa1171..25f68b0c9 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -53,6 +53,8 @@ use pocketmine\level\Level; use pocketmine\level\Location; use pocketmine\level\Position; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector2; use pocketmine\math\Vector3; use pocketmine\metadata\Metadatable; @@ -1208,66 +1210,66 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ if($westNonSolid){ $limit = $diffX; - $direction = Vector3::SIDE_WEST; + $direction = Facing::WEST; } if($eastNonSolid and 1 - $diffX < $limit){ $limit = 1 - $diffX; - $direction = Vector3::SIDE_EAST; + $direction = Facing::EAST; } if($downNonSolid and $diffY < $limit){ $limit = $diffY; - $direction = Vector3::SIDE_DOWN; + $direction = Facing::DOWN; } if($upNonSolid and 1 - $diffY < $limit){ $limit = 1 - $diffY; - $direction = Vector3::SIDE_UP; + $direction = Facing::UP; } if($northNonSolid and $diffZ < $limit){ $limit = $diffZ; - $direction = Vector3::SIDE_NORTH; + $direction = Facing::NORTH; } if($southNonSolid and 1 - $diffZ < $limit){ - $direction = Vector3::SIDE_SOUTH; + $direction = Facing::SOUTH; } $force = lcg_value() * 0.2 + 0.1; - if($direction === Vector3::SIDE_WEST){ + if($direction === Facing::WEST){ $this->motion->x = -$force; return true; } - if($direction === Vector3::SIDE_EAST){ + if($direction === Facing::EAST){ $this->motion->x = $force; return true; } - if($direction === Vector3::SIDE_DOWN){ + if($direction === Facing::DOWN){ $this->motion->y = -$force; return true; } - if($direction === Vector3::SIDE_UP){ + if($direction === Facing::UP){ $this->motion->y = $force; return true; } - if($direction === Vector3::SIDE_NORTH){ + if($direction === Facing::NORTH){ $this->motion->z = -$force; return true; } - if($direction === Vector3::SIDE_SOUTH){ + if($direction === Facing::SOUTH){ $this->motion->z = $force; return true; @@ -1277,25 +1279,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ return false; } - /** - * @return int|null - */ - public function getDirection() : ?int{ - $rotation = ($this->yaw - 90) % 360; - if($rotation < 0){ - $rotation += 360.0; - } - if((0 <= $rotation and $rotation < 45) or (315 <= $rotation and $rotation < 360)){ - return 2; //North - }elseif(45 <= $rotation and $rotation < 135){ - return 3; //East - }elseif(135 <= $rotation and $rotation < 225){ - return 0; //South - }elseif(225 <= $rotation and $rotation < 315){ - return 1; //West - }else{ - return null; - } + public function getDirection() : int{ + return Bearing::fromAngle($this->yaw); } /** diff --git a/src/pocketmine/entity/object/Painting.php b/src/pocketmine/entity/object/Painting.php index 5b5db672d..7699db77a 100644 --- a/src/pocketmine/entity/object/Painting.php +++ b/src/pocketmine/entity/object/Painting.php @@ -32,6 +32,8 @@ use pocketmine\item\ItemFactory; use pocketmine\level\Level; use pocketmine\level\particle\DestroyBlockParticle; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Bearing; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; @@ -110,29 +112,14 @@ class Painting extends Entity{ } protected function recalculateBoundingBox() : void{ - static $directions = [ - 0 => Vector3::SIDE_SOUTH, - 1 => Vector3::SIDE_WEST, - 2 => Vector3::SIDE_NORTH, - 3 => Vector3::SIDE_EAST - ]; - - $facing = $directions[$this->direction]; - + $facing = Bearing::toFacing($this->direction); $this->boundingBox->setBB(self::getPaintingBB($this->blockIn->getSide($facing), $facing, $this->getMotive())); } public function onNearbyBlockChange() : void{ parent::onNearbyBlockChange(); - static $directions = [ - 0 => Vector3::SIDE_SOUTH, - 1 => Vector3::SIDE_WEST, - 2 => Vector3::SIDE_NORTH, - 3 => Vector3::SIDE_EAST - ]; - - $face = $directions[$this->direction]; + $face = Bearing::toFacing($this->direction); if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){ $this->kill(); } @@ -170,7 +157,7 @@ class Painting extends Entity{ return PaintingMotive::getMotiveByName($this->motive); } - public function getDirection() : ?int{ + public function getDirection() : int{ return $this->direction; } @@ -199,25 +186,25 @@ class Painting extends Entity{ $maxY = $minY + $height; switch($facing){ - case Vector3::SIDE_NORTH: + case Facing::NORTH: $minZ = 1 - $thickness; $maxZ = 1; $maxX = $horizontalStart + 1; $minX = $maxX - $width; break; - case Vector3::SIDE_SOUTH: + case Facing::SOUTH: $minZ = 0; $maxZ = $thickness; $minX = -$horizontalStart; $maxX = $minX + $width; break; - case Vector3::SIDE_WEST: + case Facing::WEST: $minX = 1 - $thickness; $maxX = 1; $minZ = -$horizontalStart; $maxZ = $minZ + $width; break; - case Vector3::SIDE_EAST: + case Facing::EAST: $minX = 0; $maxX = $thickness; $maxZ = $horizontalStart + 1; @@ -253,30 +240,15 @@ class Painting extends Entity{ $horizontalStart = (int) (ceil($width / 2) - 1); $verticalStart = (int) (ceil($height / 2) - 1); - switch($facing){ - case Vector3::SIDE_NORTH: - $rotatedFace = Vector3::SIDE_WEST; - break; - case Vector3::SIDE_WEST: - $rotatedFace = Vector3::SIDE_SOUTH; - break; - case Vector3::SIDE_SOUTH: - $rotatedFace = Vector3::SIDE_EAST; - break; - case Vector3::SIDE_EAST: - $rotatedFace = Vector3::SIDE_NORTH; - break; - default: - return false; - } + $rotatedFace = Bearing::toFacing(Bearing::rotate(Bearing::fromFacing($facing), -1)); - $oppositeSide = Vector3::getOppositeSide($facing); + $oppositeSide = Facing::opposite($facing); - $startPos = $blockIn->asVector3()->getSide(Vector3::getOppositeSide($rotatedFace), $horizontalStart)->getSide(Vector3::SIDE_DOWN, $verticalStart); + $startPos = $blockIn->asVector3()->getSide(Facing::opposite($rotatedFace), $horizontalStart)->getSide(Facing::DOWN, $verticalStart); for($w = 0; $w < $width; ++$w){ for($h = 0; $h < $height; ++$h){ - $pos = $startPos->getSide($rotatedFace, $w)->getSide(Vector3::SIDE_UP, $h); + $pos = $startPos->getSide($rotatedFace, $w)->getSide(Facing::UP, $h); $block = $level->getBlockAt($pos->x, $pos->y, $pos->z); if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){ diff --git a/src/pocketmine/item/PaintingItem.php b/src/pocketmine/item/PaintingItem.php index c342502a3..0ee2542fe 100644 --- a/src/pocketmine/item/PaintingItem.php +++ b/src/pocketmine/item/PaintingItem.php @@ -27,6 +27,7 @@ use pocketmine\block\Block; use pocketmine\entity\Entity; use pocketmine\entity\object\Painting; use pocketmine\entity\object\PaintingMotive; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\Player; @@ -71,10 +72,10 @@ class PaintingItem extends Item{ $motive = $motives[array_rand($motives)]; static $directions = [ - Vector3::SIDE_SOUTH => 0, - Vector3::SIDE_WEST => 1, - Vector3::SIDE_NORTH => 2, - Vector3::SIDE_EAST => 3 + Facing::SOUTH => 0, + Facing::WEST => 1, + Facing::NORTH => 2, + Facing::EAST => 3 ]; $direction = $directions[$face] ?? -1; diff --git a/src/pocketmine/tile/Skull.php b/src/pocketmine/tile/Skull.php index 4367991a6..bfe0df385 100644 --- a/src/pocketmine/tile/Skull.php +++ b/src/pocketmine/tile/Skull.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\tile; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\Player; @@ -74,7 +75,7 @@ class Skull extends Spawnable{ $nbt->setByte(self::TAG_SKULL_TYPE, $item !== null ? $item->getDamage() : self::TYPE_SKELETON); $rot = 0; - if($face === Vector3::SIDE_UP and $player !== null){ + if($face === Facing::UP and $player !== null){ $rot = floor(($player->yaw * 16 / 360) + 0.5) & 0x0F; } $nbt->setByte(self::TAG_ROT, $rot);