diff --git a/src/entity/Human.php b/src/entity/Human.php index f2c4c7a740..767f1534d5 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -169,6 +169,10 @@ public function sendSkin(?array $targets = null) : void{ ]); } + public function allowForceEating() : bool{ + return false; + } + public function jump() : void{ parent::jump(); if($this->isSprinting()){ @@ -190,7 +194,7 @@ public function getHungerManager() : HungerManager{ } public function consumeObject(Consumable $consumable) : bool{ - if($consumable instanceof FoodSource && $consumable->requiresHunger() && !$this->hungerManager->isHungry()){ + if($consumable instanceof FoodSource && (!$this->allowForceEating() && $consumable->requiresHunger() && !$this->getHungerManager()->isHungry())){ return false; } diff --git a/src/item/Food.php b/src/item/Food.php index 1950c4b14a..94b746879c 100644 --- a/src/item/Food.php +++ b/src/item/Food.php @@ -44,6 +44,6 @@ public function onConsume(Living $consumer) : void{ } public function canStartUsingItem(Player $player) : bool{ - return !$this->requiresHunger() || $player->getHungerManager()->isHungry(); + return $player->allowForceEating() || !$this->requiresHunger() || $player->getHungerManager()->isHungry(); } } diff --git a/src/player/Player.php b/src/player/Player.php index 8ae206e1a4..7eb2231d56 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -688,6 +688,10 @@ public function setUsingItem(bool $value) : void{ $this->networkPropertiesDirty = true; } + public function allowForceEating() : bool{ + return $this->isCreative() || $this->getWorld()->getDifficulty() === World::DIFFICULTY_PEACEFUL; + } + /** * Returns how long the player has been using their currently-held item for. Used for determining arrow shoot force * for bows.