mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Entity: add getHorizontalFacing(), clean up some boilerplate code
This commit is contained in:
parent
f60d13548e
commit
39e383a175
@ -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);
|
||||
}
|
||||
|
@ -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()){
|
||||
|
@ -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){
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)){
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user