From 0cdc04f9b519d04cac3bdc3b7f395f9e58ba0fb8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 26 Jun 2021 18:56:11 +0100 Subject: [PATCH] Player: Fixed so-called 'pot lag' this occurred because of transactions arriving before MobEquipmentPacket updating the player's own held item slot. This was only a problem while rapidly changing hotbar slots and simultaneously using items, like projectiles. closes #4168 --- src/pocketmine/Player.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7c1cdf838..5582645b0 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2529,6 +2529,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $blockVector = $packet->trData->getBlockPos(); $face = $packet->trData->getFace(); + if($this->inventory->getHeldItemIndex() !== $packet->trData->getHotbarSlot()){ + $this->inventory->equipItem($packet->trData->getHotbarSlot()); + } + switch($packet->trData->getActionType()){ case UseItemTransactionData::ACTION_CLICK_BLOCK: //TODO: start hack for client spam bug @@ -2687,6 +2691,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return false; } + if($this->inventory->getHeldItemIndex() !== $packet->trData->getHotbarSlot()){ + $this->inventory->equipItem($packet->trData->getHotbarSlot()); + } + switch($packet->trData->getActionType()){ case UseItemOnEntityTransactionData::ACTION_INTERACT: break; //TODO @@ -2778,6 +2786,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->inventory->sendContents($this); return false; }elseif($packet->trData instanceof ReleaseItemTransactionData){ + if($this->inventory->getHeldItemIndex() !== $packet->trData->getHotbarSlot()){ + $this->inventory->equipItem($packet->trData->getHotbarSlot()); + } + try{ switch($packet->trData->getActionType()){ case ReleaseItemTransactionData::ACTION_RELEASE: