diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 027a91417..2e4df8214 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1433,6 +1433,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ 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){ if(!$this->onGround or $movY != 0){ $bb = clone $this->boundingBox; diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 30aa735e3..5c968b2f0 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -510,7 +510,9 @@ abstract class Living extends Entity implements Damageable{ $this->deadTicks += $tickDiff; if($this->deadTicks >= $this->maxDeadTicks){ $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 []; } + /** + * Returns the amount of XP this mob will drop on death. + * @return int + */ + public function getXpDropAmount() : int{ + return 0; + } + /** * @param int $maxDistance * @param int $maxLength diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index 94b0a9d18..715f912a0 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -57,4 +57,9 @@ class Zombie extends Monster{ return $drops; } + + public function getXpDropAmount() : int{ + //TODO: check for equipment and whether it's a baby + return 5; + } }