Player: fixed being able to eat cake in creative

closes #2070
This commit is contained in:
Dylan K. Taylor 2018-03-13 18:32:08 +00:00
parent 86eee429bb
commit ddc9dca8b4
2 changed files with 14 additions and 1 deletions

View File

@ -1754,6 +1754,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return 0.0;
}
public function isHungry() : bool{
return $this->isSurvival() and parent::isHungry();
}
public function canBreathe() : bool{
return $this->isCreative() or parent::canBreathe();
}

View File

@ -208,6 +208,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->setFood($amount);
}
/**
* Returns whether this Human may consume objects requiring hunger.
*
* @return bool
*/
public function isHungry() : bool{
return $this->getFood() < $this->getMaxFood();
}
public function getSaturation() : float{
return $this->attributeMap->getAttribute(Attribute::SATURATION)->getValue();
}
@ -282,7 +291,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function consumeObject(Consumable $consumable) : bool{
if($consumable instanceof FoodSource){
if($consumable->requiresHunger() and $this->getFood() >= $this->getMaxFood()){
if($consumable->requiresHunger() and !$this->isHungry()){
return false;
}