From 2caf0c0517a2d206318c01dc8240057021dedc3d Mon Sep 17 00:00:00 2001 From: Kran <56488228+kran27@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:53:38 -0700 Subject: [PATCH 1/2] fence gate fix fence gate should change direction based on player input --- src/material/block/nonfull/FenceGateBlock.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/material/block/nonfull/FenceGateBlock.php b/src/material/block/nonfull/FenceGateBlock.php index 0f66fdf5..ddd41ff8 100644 --- a/src/material/block/nonfull/FenceGateBlock.php +++ b/src/material/block/nonfull/FenceGateBlock.php @@ -31,7 +31,19 @@ class FenceGateBlock extends TransparentBlock{ ); } public function onActivate(Item $item, Player $player){ - $this->meta ^= 0x04; + $faces = array( + 0 => 2, + 1 => 3, + 2 => 0, + 3 => 1, + ); + $playerDirection = $faces[$player->entity->getDirection()] & 0x03; + $gateDirection = $this->meta & 0x03; + if ($playerDirection === $gateDirection) { + $this->meta ^= 0x04; + } else if (($playerDirection + 2) % 4 === $gateDirection) { + $this->meta = ($this->meta & 0x04) | $playerDirection; + } $this->level->setBlock($this, $this, true, false, true); $players = ServerAPI::request()->api->player->getAll($this->level); unset($players[$player->CID]); @@ -43,5 +55,5 @@ class FenceGateBlock extends TransparentBlock{ $pk->data = 0; ServerAPI::request()->api->player->broadcastPacket($players, $pk); return true; - } + } } From 46326707d0dac79e9b59cb976234f2f43af6ce63 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 26 Mar 2024 23:03:00 +0300 Subject: [PATCH 2/2] ported from vanilla --- src/material/block/nonfull/FenceGateBlock.php | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/material/block/nonfull/FenceGateBlock.php b/src/material/block/nonfull/FenceGateBlock.php index ddd41ff8..e1b0cb90 100644 --- a/src/material/block/nonfull/FenceGateBlock.php +++ b/src/material/block/nonfull/FenceGateBlock.php @@ -31,21 +31,23 @@ class FenceGateBlock extends TransparentBlock{ ); } public function onActivate(Item $item, Player $player){ - $faces = array( - 0 => 2, - 1 => 3, - 2 => 0, - 3 => 1, - ); - $playerDirection = $faces[$player->entity->getDirection()] & 0x03; - $gateDirection = $this->meta & 0x03; - if ($playerDirection === $gateDirection) { - $this->meta ^= 0x04; - } else if (($playerDirection + 2) % 4 === $gateDirection) { - $this->meta = ($this->meta & 0x04) | $playerDirection; + + $meta = $this->meta; + if(($meta & 4) != 0){ + $meta ^= 4; + }else{ + $direction = ($player->entity->yaw * 4 / 360) + 0.5; + $blockDirection = (int)$direction; + if($direction < $blockDirection) --$blockDirection; + $blockDirection &= 3; + if(($meta & 3) == (($blockDirection + 2) & 3)){ + $meta = $blockDirection; + } + $meta |= 4; } - $this->level->setBlock($this, $this, true, false, true); - $players = ServerAPI::request()->api->player->getAll($this->level); + + $this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->id, $meta); + $players = $this->level->players; unset($players[$player->CID]); $pk = new LevelEventPacket; $pk->x = $this->x;