Fixed paintings dropping multiple times, closes #2774

This commit is contained in:
Dylan K. Taylor 2019-03-21 19:46:43 +00:00
parent 9ad7f74501
commit 89c0836047
4 changed files with 22 additions and 20 deletions

View File

@ -2918,17 +2918,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$this->server->saveOfflinePlayerData($this->username, $nbt); $this->server->saveOfflinePlayerData($this->username, $nbt);
} }
public function kill() : void{ protected function onDeath() : void{
if(!$this->spawned){ if(!$this->spawned){ //TODO: drop this hack
return; return;
} }
parent::kill();
$this->networkSession->onDeath();
}
protected function onDeath() : void{
//Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the //Crafting grid must always be evacuated even if keep-inventory is true. This dumps the contents into the
//main inventory and drops the rest on the ground. //main inventory and drops the rest on the ground.
$this->doCloseInventory(); $this->doCloseInventory();
@ -2957,6 +2950,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
if($ev->getDeathMessage() != ""){ if($ev->getDeathMessage() != ""){
$this->server->broadcastMessage($ev->getDeathMessage()); $this->server->broadcastMessage($ev->getDeathMessage());
} }
$this->startDeathAnimation();
$this->networkSession->onDeath();
} }
protected function onDeathUpdate(int $tickDiff) : bool{ protected function onDeathUpdate(int $tickDiff) : bool{

View File

@ -806,8 +806,18 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
public function kill() : void{ public function kill() : void{
$this->health = 0; if($this->isAlive()){
$this->scheduleUpdate(); $this->health = 0;
$this->onDeath();
$this->scheduleUpdate();
}
}
/**
* Override this to do actions on death.
*/
protected function onDeath() : void{
} }
/** /**
@ -844,7 +854,6 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if($amount <= 0){ if($amount <= 0){
if($this->isAlive()){ if($this->isAlive()){
$this->health = 0;
$this->kill(); $this->kill();
} }
}elseif($amount <= $this->getMaxHealth() or $amount < $this->health){ }elseif($amount <= $this->getMaxHealth() or $amount < $this->health){

View File

@ -640,12 +640,6 @@ abstract class Living extends Entity implements Damageable{
} }
} }
public function kill() : void{
parent::kill();
$this->onDeath();
$this->startDeathAnimation();
}
protected function onDeath() : void{ protected function onDeath() : void{
$ev = new EntityDeathEvent($this, $this->getDrops()); $ev = new EntityDeathEvent($this, $this->getDrops());
$ev->call(); $ev->call();
@ -656,6 +650,8 @@ abstract class Living extends Entity implements Damageable{
//TODO: check death conditions (must have been damaged by player < 5 seconds from death) //TODO: check death conditions (must have been damaged by player < 5 seconds from death)
//TODO: allow this number to be manipulated during EntityDeathEvent //TODO: allow this number to be manipulated during EntityDeathEvent
$this->level->dropExperience($this, $this->getXpDropAmount()); $this->level->dropExperience($this, $this->getXpDropAmount());
$this->startDeathAnimation();
} }
protected function onDeathUpdate(int $tickDiff) : bool{ protected function onDeathUpdate(int $tickDiff) : bool{

View File

@ -93,8 +93,8 @@ class Painting extends Entity{
return $nbt; return $nbt;
} }
public function kill() : void{ protected function onDeath() : void{
parent::kill(); parent::onDeath();
$drops = true; $drops = true;