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:
Dylan K. Taylor
2017-04-03 13:12:33 +01:00
parent 00a226921c
commit 2204942338
6 changed files with 101 additions and 31 deletions

View File

@ -34,19 +34,21 @@ class PlayerExhaustEvent extends PlayerEvent implements Cancellable{
const CAUSE_HEALTH_REGEN = 4;
const CAUSE_POTION = 5;
const CAUSE_WALKING = 6;
const CAUSE_SNEAKING = 7;
const CAUSE_SPRINTING = 7;
const CAUSE_SWIMMING = 8;
const CAUSE_JUMPING = 10;
const CAUSE_JUMPING = 9;
const CAUSE_SPRINT_JUMPING = 10;
const CAUSE_CUSTOM = 11;
const CAUSE_FLAG_SPRINT = 0x10000;
/** @var float */
private $amount;
/** @var int */
private $cause;
public function __construct(Human $human, float $amount, int $cause){
$this->player = $human;
$this->amount = $amount;
$this->cause = $cause;
}
/**
@ -63,4 +65,12 @@ class PlayerExhaustEvent extends PlayerEvent implements Cancellable{
public function setAmount(float $amount){
$this->amount = $amount;
}
/**
* Returns an int cause of the exhaustion - one of the constants at the top of this class.
* @return int
*/
public function getCause() : int{
return $this->cause;
}
}