Fixed desynchronization of hunger when cancelling food-related events (#4691)

This commit is contained in:
Covered123 2022-01-03 16:11:32 -03:00 committed by GitHub
parent f62cfe8ae3
commit bcc0f1e733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,7 @@ use pocketmine\block\BaseSign;
use pocketmine\block\ItemFrame; use pocketmine\block\ItemFrame;
use pocketmine\block\utils\SignText; use pocketmine\block\utils\SignText;
use pocketmine\entity\animation\ConsumingItemAnimation; use pocketmine\entity\animation\ConsumingItemAnimation;
use pocketmine\entity\Attribute;
use pocketmine\entity\InvalidSkinException; use pocketmine\entity\InvalidSkinException;
use pocketmine\event\player\PlayerEditBookEvent; use pocketmine\event\player\PlayerEditBookEvent;
use pocketmine\inventory\transaction\action\InventoryAction; use pocketmine\inventory\transaction\action\InventoryAction;
@ -371,6 +372,8 @@ class InGamePacketHandler extends PacketHandler{
case UseItemTransactionData::ACTION_CLICK_AIR: case UseItemTransactionData::ACTION_CLICK_AIR:
if($this->player->isUsingItem()){ if($this->player->isUsingItem()){
if(!$this->player->consumeHeldItem()){ if(!$this->player->consumeHeldItem()){
$hungerAttr = $this->player->getAttributeMap()->get(Attribute::HUNGER) ?? throw new AssumptionFailedError();
$hungerAttr->markSynchronized(false);
$this->inventoryManager->syncSlot($this->player->getInventory(), $this->player->getInventory()->getHeldItemIndex()); $this->inventoryManager->syncSlot($this->player->getInventory(), $this->player->getInventory()->getHeldItemIndex());
} }
return true; return true;