diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index f44b46a33..086c8aacc 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -300,17 +300,20 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($consumable instanceof MaybeConsumable and !$consumable->canBeConsumed()){ return false; } + if($consumable instanceof FoodSource && $consumable->requiresHunger() and !$this->isHungry()){ + return false; + } + return parent::consumeObject($consumable); + } + + protected function applyConsumptionResults(Consumable $consumable) : void{ if($consumable instanceof FoodSource){ - if($consumable->requiresHunger() and !$this->isHungry()){ - return false; - } - $this->addFood($consumable->getFoodRestore()); $this->addSaturation($consumable->getSaturationRestore()); } - return parent::consumeObject($consumable); + parent::applyConsumptionResults($consumable); } /** diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index bc38bd1c9..0d952cca3 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -363,13 +363,20 @@ abstract class Living extends Entity implements Damageable{ return false; } + $this->applyConsumptionResults($consumable); + return true; + } + + /** + * Applies effects from consuming the object. This shouldn't do any can-consume checks (those are expected to be + * handled by the caller). + */ + protected function applyConsumptionResults(Consumable $consumable) : void{ foreach($consumable->getAdditionalEffects() as $effect){ $this->addEffect($effect); } $consumable->onConsume($this); - - return true; } /**