mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
parent
93a9007f3c
commit
12214792b3
@ -34,6 +34,7 @@ interface FoodSource extends Consumable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether a Human eating this FoodSource must have a non-full hunger bar.
|
* Returns whether a Human eating this FoodSource must have a non-full hunger bar.
|
||||||
|
* This is ignored in creative mode and in peaceful difficulty.
|
||||||
*/
|
*/
|
||||||
public function requiresHunger() : bool;
|
public function requiresHunger() : bool;
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
|||||||
use pocketmine\network\mcpe\protocol\UpdateAbilitiesPacket;
|
use pocketmine\network\mcpe\protocol\UpdateAbilitiesPacket;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\sound\TotemUseSound;
|
use pocketmine\world\sound\TotemUseSound;
|
||||||
|
use pocketmine\world\World;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Ramsey\Uuid\UuidInterface;
|
use Ramsey\Uuid\UuidInterface;
|
||||||
use function array_fill;
|
use function array_fill;
|
||||||
@ -189,8 +190,16 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
|||||||
return $this->hungerManager;
|
return $this->hungerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the Human can eat food. This may return a different result than {@link HungerManager::isHungry()},
|
||||||
|
* as HungerManager only handles the hunger bar.
|
||||||
|
*/
|
||||||
|
public function canEat() : bool{
|
||||||
|
return $this->hungerManager->isHungry() || $this->getWorld()->getDifficulty() === World::DIFFICULTY_PEACEFUL;
|
||||||
|
}
|
||||||
|
|
||||||
public function consumeObject(Consumable $consumable) : bool{
|
public function consumeObject(Consumable $consumable) : bool{
|
||||||
if($consumable instanceof FoodSource && $consumable->requiresHunger() && !$this->hungerManager->isHungry()){
|
if($consumable instanceof FoodSource && $consumable->requiresHunger() && !$this->canEat()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,8 @@ class HungerManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this Human may consume objects requiring hunger.
|
* Returns whether the food level is below the maximum.
|
||||||
|
* This doesn't decide if the entity can eat food. Use {@link Human::canEat()} for that.
|
||||||
*/
|
*/
|
||||||
public function isHungry() : bool{
|
public function isHungry() : bool{
|
||||||
return $this->getFood() < $this->getMaxFood();
|
return $this->getFood() < $this->getMaxFood();
|
||||||
|
@ -44,6 +44,6 @@ abstract class Food extends Item implements FoodSourceItem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function canStartUsingItem(Player $player) : bool{
|
public function canStartUsingItem(Player $player) : bool{
|
||||||
return !$this->requiresHunger() || $player->getHungerManager()->isHungry();
|
return !$this->requiresHunger() || $player->canEat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1471,6 +1471,10 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canEat() : bool{
|
||||||
|
return $this->isCreative() || parent::canEat();
|
||||||
|
}
|
||||||
|
|
||||||
public function canBreathe() : bool{
|
public function canBreathe() : bool{
|
||||||
return $this->isCreative() || parent::canBreathe();
|
return $this->isCreative() || parent::canBreathe();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user