mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Fixed the half-done hunger implementation, fixed lots of bugs related to hunger
- Fixed starvation doesn't deal any damage at all (Human->getFood() returns a float, not an int, === 0 won't work so great) - Added exhaustion for sprinting, walking, jumping and sprint-jumping as per MCPE (these use MCPE values, and yes MCPE does walking exhaustion!) - Fixed attributes don't get reset after player death - Added food and hunger regeneration in peaceful difficulty - Added API methods Living->jump() (motion isn't updated yet, so this won't actually do much if plugins try to use it) and Living->getJumpVelocity() TODO: implement exhaustion for swimming
This commit is contained in:
@ -99,6 +99,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
$this->skinId = $skinId;
|
||||
}
|
||||
|
||||
public function jump(){
|
||||
parent::jump();
|
||||
if($this->isSprinting()){
|
||||
$this->exhaust(0.8, PlayerExhaustEvent::CAUSE_SPRINT_JUMPING);
|
||||
}else{
|
||||
$this->exhaust(0.2, PlayerExhaustEvent::CAUSE_JUMPING);
|
||||
}
|
||||
}
|
||||
|
||||
public function getFood() : float{
|
||||
return $this->attributeMap->getAttribute(Attribute::HUNGER)->getValue();
|
||||
}
|
||||
@ -355,31 +364,35 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
if($this->isAlive()){
|
||||
$food = $this->getFood();
|
||||
$health = $this->getHealth();
|
||||
if($food >= 18){
|
||||
$this->foodTickTimer++;
|
||||
if($this->foodTickTimer >= 80 and $health < $this->getMaxHealth()){
|
||||
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
|
||||
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
|
||||
$this->foodTickTimer = 0;
|
||||
$difficulty = $this->server->getDifficulty();
|
||||
|
||||
$this->foodTickTimer++;
|
||||
if($this->foodTickTimer >= 80){
|
||||
$this->foodTickTimer = 0;
|
||||
}
|
||||
|
||||
if($difficulty === 0 and $this->foodTickTimer % 10 === 0){ //Peaceful
|
||||
if($food < 20){
|
||||
$this->addFood(1.0);
|
||||
}
|
||||
}elseif($food === 0){
|
||||
$this->foodTickTimer++;
|
||||
if($this->foodTickTimer >= 80){
|
||||
$diff = $this->server->getDifficulty();
|
||||
$can = false;
|
||||
if($diff === 1){
|
||||
$can = $health > 10;
|
||||
}elseif($diff === 2){
|
||||
$can = $health > 1;
|
||||
}elseif($diff === 3){
|
||||
$can = true;
|
||||
if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){
|
||||
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
|
||||
}
|
||||
}
|
||||
|
||||
if($this->foodTickTimer === 0){
|
||||
if($food >= 18){
|
||||
if($health < $this->getMaxHealth()){
|
||||
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
|
||||
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
|
||||
}
|
||||
if($can){
|
||||
}elseif($food <= 0){
|
||||
if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){
|
||||
$this->attack(1, new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($food <= 6){
|
||||
if($this->isSprinting()){
|
||||
$this->setSprinting(false);
|
||||
|
Reference in New Issue
Block a user