mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Fixed misuse of kill() and close() when deleting entities (#1490)
This commit is contained in:
@ -471,6 +471,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
|
||||
/** @var bool */
|
||||
protected $closed = false;
|
||||
/** @var bool */
|
||||
private $needsDespawn = false;
|
||||
|
||||
/** @var TimingsHandler */
|
||||
protected $timings;
|
||||
@ -1280,15 +1282,20 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
|
||||
$this->lastUpdate = $currentTick;
|
||||
|
||||
if($this->needsDespawn){
|
||||
$this->close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->isAlive()){
|
||||
$this->deadTicks += $tickDiff;
|
||||
if($this->deadTicks >= $this->maxDeadTicks){
|
||||
$this->despawnFromAll();
|
||||
if(!$this->isPlayer){
|
||||
$this->close();
|
||||
$this->flagForDespawn();
|
||||
}
|
||||
}
|
||||
return $this->deadTicks < $this->maxDeadTicks;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1930,6 +1937,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags the entity to be removed from the world on the next tick.
|
||||
*/
|
||||
public function flagForDespawn() : void{
|
||||
$this->needsDespawn = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity has been "closed".
|
||||
* @return bool
|
||||
|
@ -104,7 +104,7 @@ class FallingSand extends Entity{
|
||||
}
|
||||
|
||||
if($this->onGround or $blockTarget !== null){
|
||||
$this->kill();
|
||||
$this->flagForDespawn();
|
||||
|
||||
$block = $this->level->getBlock($pos);
|
||||
if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){
|
||||
|
@ -118,7 +118,7 @@ class Item extends Entity{
|
||||
if($ev->isCancelled()){
|
||||
$this->age = 0;
|
||||
}else{
|
||||
$this->kill();
|
||||
$this->flagForDespawn();
|
||||
$hasUpdate = true;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
$this->fuse -= $tickDiff;
|
||||
|
||||
if($this->fuse <= 0){
|
||||
$this->kill();
|
||||
$this->flagForDespawn();
|
||||
$this->explode();
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class Arrow extends Projectile{
|
||||
}
|
||||
|
||||
if($this->age > 1200){
|
||||
$this->close();
|
||||
$this->flagForDespawn();
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ abstract class Projectile extends Entity{
|
||||
}
|
||||
}
|
||||
|
||||
$this->close();
|
||||
$this->flagForDespawn();
|
||||
}
|
||||
|
||||
public function saveNBT(){
|
||||
|
@ -40,7 +40,7 @@ abstract class Throwable extends Projectile{
|
||||
|
||||
if($this->age > 1200 or $this->isCollided){
|
||||
//TODO: hit particles
|
||||
$this->kill();
|
||||
$this->flagForDespawn();
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user