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.
This commit is contained in:
Dylan K. Taylor 2021-11-08 23:51:25 +00:00
parent 5be429a8c4
commit c7beb0a702
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 6 additions and 8 deletions

View File

@ -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;
}

View File

@ -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;