diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 78909e666..5f48df0f1 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -87,7 +87,7 @@ class Anvil extends Fallable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $this->facing = Bearing::toFacing(Bearing::rotate($player->getDirection(), 1)); + $this->facing = Facing::rotate($player->getHorizontalFacing(), Facing::AXIS_Y, true); } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index fcbcbe202..829196704 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -185,7 +185,7 @@ class Bed extends Transparent{ $this->color = $item->getDamage(); //TODO: replace this with a proper colour getter $down = $this->getSide(Facing::DOWN); if(!$down->isTransparent()){ - $this->facing = $player !== null ? Bearing::toFacing($player->getDirection()) : Facing::NORTH; + $this->facing = $player !== null ? $player->getHorizontalFacing() : Facing::NORTH; $next = $this->getSide($this->getOtherHalfSide()); if($next->canBeReplaced() and !$next->getSide(Facing::DOWN)->isTransparent()){ diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 8b4fea601..c83ef3eac 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -25,7 +25,6 @@ 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; @@ -75,12 +74,12 @@ class Chest extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ $chest = null; if($player !== null){ - $this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } foreach([ - Bearing::toFacing(Bearing::rotate($player->getDirection(), -1)), - Bearing::toFacing(Bearing::rotate($player->getDirection(), 1)) + Facing::rotate($player->getHorizontalFacing(), Facing::AXIS_Y, false), + Facing::rotate($player->getHorizontalFacing(), Facing::AXIS_Y, true) ] as $side){ $c = $this->getSide($side); if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){ diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 76a67c7fa..fcf9573e6 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -110,7 +110,7 @@ abstract class Door extends Transparent{ } if($player !== null){ - $this->facing = Bearing::toFacing($player->getDirection()); + $this->facing = $player->getHorizontalFacing(); } $next = $this->getSide(Facing::rotate($this->facing, Facing::AXIS_Y, false)); diff --git a/src/pocketmine/block/EndPortalFrame.php b/src/pocketmine/block/EndPortalFrame.php index 438d0a2c2..d981ae913 100644 --- a/src/pocketmine/block/EndPortalFrame.php +++ b/src/pocketmine/block/EndPortalFrame.php @@ -82,7 +82,7 @@ class EndPortalFrame extends Solid{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index eab6beaff..f58ce88b0 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -26,7 +26,6 @@ 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; @@ -63,7 +62,7 @@ class EnderChest extends Chest{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ //same as normal chest - TODO: clean up inheritance here - $this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } if(Block::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 5dcb60ded..fdf1a060e 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -69,7 +69,7 @@ class FenceGate extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $this->facing = Bearing::toFacing($player->getDirection()); + $this->facing = $player->getHorizontalFacing(); } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -78,7 +78,7 @@ class FenceGate extends Transparent{ public function onActivate(Item $item, Player $player = null) : bool{ $this->open = !$this->open; if($this->open and $player !== null){ - $playerFacing = Bearing::toFacing($player->getDirection()); + $playerFacing = $player->getHorizontalFacing(); if($playerFacing === Facing::opposite($this->facing)){ $this->facing = $playerFacing; } diff --git a/src/pocketmine/block/Furnace.php b/src/pocketmine/block/Furnace.php index 06473a53a..38e8d91b1 100644 --- a/src/pocketmine/block/Furnace.php +++ b/src/pocketmine/block/Furnace.php @@ -25,7 +25,6 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\TieredTool; -use pocketmine\math\Bearing; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -97,7 +96,7 @@ class Furnace extends Solid{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ Tile::createTile(Tile::FURNACE, $this->getLevel(), TileFurnace::createNBT($this, $item)); diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index f3b5e72c5..940ee3824 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -26,7 +26,6 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\TieredTool; -use pocketmine\math\Bearing; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -62,7 +61,7 @@ class GlazedTerracotta extends Solid{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 410ef6ff9..f813a7831 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -24,7 +24,6 @@ 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\network\mcpe\protocol\LevelSoundEventPacket; @@ -94,7 +93,7 @@ class Lever extends Flowable{ if(Facing::axis($face) === Facing::AXIS_Y){ if($player !== null){ - $this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } $this->position = $face === Facing::DOWN ? self::BOTTOM : self::TOP; }else{ diff --git a/src/pocketmine/block/RedstoneRepeater.php b/src/pocketmine/block/RedstoneRepeater.php index 43f8b0b9a..d64fe598f 100644 --- a/src/pocketmine/block/RedstoneRepeater.php +++ b/src/pocketmine/block/RedstoneRepeater.php @@ -87,7 +87,7 @@ class RedstoneRepeater extends Flowable{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if(!$blockReplace->getSide(Facing::DOWN)->isTransparent()){ if($player !== null){ - $this->facing = Facing::opposite(Bearing::toFacing($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index 2b2403130..4a26c4ca2 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -25,7 +25,6 @@ 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; @@ -108,7 +107,7 @@ abstract class Stair extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $this->facing = Bearing::toFacing($player->getDirection()); + $this->facing = $player->getHorizontalFacing(); } $this->upsideDown = (($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN); diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 625824409..9466ebeff 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -26,7 +26,6 @@ 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; @@ -78,7 +77,7 @@ class Trapdoor extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ - $this->facing = Bearing::toFacing(Bearing::opposite($player->getDirection())); + $this->facing = Facing::opposite($player->getHorizontalFacing()); } if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){ $this->top = true; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 6085f4ae1..f5239bf36 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1289,6 +1289,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ return Bearing::fromAngle($this->yaw); } + public function getHorizontalFacing() : int{ + return Bearing::toFacing($this->getDirection()); + } + /** * @return Vector3 */