From c7beb0a70258fdf5dbba6bf4f93b17cca2a88838 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 8 Nov 2021 23:51:25 +0000 Subject: [PATCH] Clean up inventory auto close mess from PM3 on PM3 there was no concept of 'current window', we had no idea which window the player was actually looking at. --- src/network/mcpe/handler/InGamePacketHandler.php | 4 +--- src/player/Player.php | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 5b63aa09d..e4553c49b 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -193,7 +193,7 @@ class InGamePacketHandler extends PacketHandler{ //TODO HACK: EATING_ITEM is sent back to the server when the server sends it for other players (1.14 bug, maybe earlier) return $packet->actorRuntimeId === ActorEvent::EATING_ITEM; } - $this->player->doCloseInventory(); + $this->player->removeCurrentWindow(); switch($packet->eventId){ case ActorEvent::EATING_ITEM: //TODO: ignore this and handle it server-side @@ -570,8 +570,6 @@ class InGamePacketHandler extends PacketHandler{ } public function handleContainerClose(ContainerClosePacket $packet) : bool{ - $this->player->doCloseInventory(); - $this->inventoryManager->onClientRemoveWindow($packet->windowId); return true; } diff --git a/src/player/Player.php b/src/player/Player.php index 308371af7..aab421014 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1316,7 +1316,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ * as a command. */ public function chat(string $message) : bool{ - $this->doCloseInventory(); + $this->removeCurrentWindow(); $message = TextFormat::clean($message, false); foreach(explode("\n", $message) as $messagePart){ @@ -1572,7 +1572,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ * @return bool if the block was successfully broken, false if a rollback needs to take place. */ public function breakBlock(Vector3 $pos) : bool{ - $this->doCloseInventory(); + $this->removeCurrentWindow(); if($this->canInteract($pos->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 7)){ $this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers()); @@ -1991,7 +1991,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ //prevent the player receiving their own disconnect message $this->server->unsubscribeFromAllBroadcastChannels($this); - $this->doCloseInventory(); + $this->removeCurrentWindow(); $ev = new PlayerQuitEvent($this, $quitMessage ?? $this->getLeaveMessage(), $reason); $ev->call(); @@ -2104,7 +2104,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ protected function onDeath() : void{ //Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the //main inventory and drops the rest on the ground. - $this->doCloseInventory(); + $this->removeCurrentWindow(); $ev = new PlayerDeathEvent($this, $this->getDrops(), $this->getXpDropAmount(), null); $ev->call(); @@ -2322,7 +2322,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ * @internal Called to clean up crafting grid and cursor inventory when it is detected that the player closed their * inventory. */ - public function doCloseInventory() : void{ + private function doCloseInventory() : void{ $inventories = [$this->craftingGrid, $this->cursorInventory]; if($this->currentWindow instanceof TemporaryInventory){ $inventories[] = $this->currentWindow;