From a95ecb3ff9581b94784645fd09eae30f1bf6b3cb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 18 Feb 2019 19:00:58 +0000 Subject: [PATCH] FenceGate: implement in-wall checks --- src/pocketmine/block/FenceGate.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 0914d202d..c378a4ac3 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -37,18 +37,21 @@ class FenceGate extends Transparent{ protected $open = false; /** @var int */ protected $facing = Facing::NORTH; + /** @var bool */ + protected $inWall = false; protected function writeStateToMeta() : int{ - return Bearing::fromFacing($this->facing) | ($this->open ? 0x04 : 0); + return Bearing::fromFacing($this->facing) | ($this->open ? 0x04 : 0) | ($this->inWall ? 0x08 : 0); } public function readStateFromMeta(int $meta) : void{ $this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03); $this->open = ($meta & 0x04) !== 0; + $this->inWall = ($meta & 0x08) !== 0; } public function getStateBitmask() : int{ - return 0b111; + return 0b1111; } public function getHardness() : float{ @@ -68,14 +71,31 @@ class FenceGate extends Transparent{ return AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16); } + private function checkInWall() : bool{ + return ( + $this->getSide(Facing::rotateY($this->facing, false)) instanceof CobblestoneWall or + $this->getSide(Facing::rotateY($this->facing, true)) instanceof CobblestoneWall + ); + } + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ $this->facing = $player->getHorizontalFacing(); } + $this->inWall = $this->checkInWall(); + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } + public function onNearbyBlockChange() : void{ + $inWall = $this->checkInWall(); + if($inWall !== $this->inWall){ + $this->inWall = $inWall; + $this->level->setBlock($this, $this); + } + } + public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; if($this->open and $player !== null){