Drop experience on death

This commit is contained in:
Dylan K. Taylor 2017-11-23 14:43:26 +00:00
parent 0f30467f62
commit 0410df77aa
3 changed files with 24 additions and 1 deletions

View File

@ -1433,6 +1433,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return []; return [];
} }
public function getXpDropAmount() : int{
if(!$this->isCreative()){
return min(100, $this->getCurrentTotalXp());
}
return 0;
}
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){ protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){
if(!$this->onGround or $movY != 0){ if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox; $bb = clone $this->boundingBox;

View File

@ -510,7 +510,9 @@ abstract class Living extends Entity implements Damageable{
$this->deadTicks += $tickDiff; $this->deadTicks += $tickDiff;
if($this->deadTicks >= $this->maxDeadTicks){ if($this->deadTicks >= $this->maxDeadTicks){
$this->endDeathAnimation(); $this->endDeathAnimation();
//TODO: spawn experience orbs here
//TODO: check death conditions (must have been damaged by player < 5 seconds from death)
$this->level->dropExperience($this, $this->getXpDropAmount());
} }
} }
@ -660,6 +662,14 @@ abstract class Living extends Entity implements Damageable{
return []; return [];
} }
/**
* Returns the amount of XP this mob will drop on death.
* @return int
*/
public function getXpDropAmount() : int{
return 0;
}
/** /**
* @param int $maxDistance * @param int $maxDistance
* @param int $maxLength * @param int $maxLength

View File

@ -57,4 +57,9 @@ class Zombie extends Monster{
return $drops; return $drops;
} }
public function getXpDropAmount() : int{
//TODO: check for equipment and whether it's a baby
return 5;
}
} }