Added Player death animations, improved spawning behavior to correct invisible players, fixed players getting stuck when dead, closes #2304

This commit is contained in:
Shoghi Cervantes
2014-12-09 01:36:46 +01:00
parent 5e5f8bf33d
commit 306f492fc0
4 changed files with 36 additions and 28 deletions

View File

@@ -111,6 +111,7 @@ abstract class Entity extends Location implements Metadatable{
public $positionChanged;
public $motionChanged;
public $dead;
public $deadTicks = 0;
protected $age = 0;
public $height;
@@ -527,12 +528,16 @@ abstract class Entity extends Location implements Metadatable{
$isPlayer = $this instanceof Player;
if($this->dead === true){
$this->despawnFromAll();
if(!$isPlayer){
$this->close();
++$this->deadTicks;
if($this->deadTicks >= 10){
$this->despawnFromAll();
if(!$isPlayer){
$this->close();
}
}
Timings::$tickEntityTimer->stopTiming();
return $isPlayer;
return $this->deadTicks < 10;
}
$hasUpdate = false;
@@ -1107,12 +1112,14 @@ abstract class Entity extends Location implements Metadatable{
$this->boundingBox->setBounds($pos->x - $radius, $pos->y + $this->ySize, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height + $this->ySize, $pos->z + $radius);
if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) and $this->chunk->getZ() !== ($this->z >> 4))){
if($this->chunk === null or ($this->chunkX !== ($this->x >> 4) and $this->chunkZ !== ($this->z >> 4))){
if($this->chunk instanceof FullChunk){
$this->chunk->removeEntity($this);
}
$this->level->loadChunk($this->x >> 4, $this->z >> 4);
$this->chunk = $this->level->getChunk($this->x >> 4, $this->z >> 4);
$this->chunkX = $this->chunk->getX();
$this->chunkZ = $this->chunk->getZ();
if(!$this->justCreated){
$newChunk = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
@@ -1221,8 +1228,8 @@ abstract class Entity extends Location implements Metadatable{
}
public function spawnToAll(){
foreach($this->level->getUsingChunk($this->x >> 4, $this->z >> 4) as $player){
if(isset($player->id) and $player->spawned === true){
foreach($this->level->getUsingChunk($this->chunkX, $this->chunkZ) as $player){
if($player->loggedIn === true){
$this->spawnTo($player);
}
}

View File

@@ -93,10 +93,6 @@ abstract class Living extends Entity implements Damageable{
}
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = 2; //Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);
$this->setLastDamageCause($source);
if($source instanceof EntityDamageByEntityEvent){
@@ -109,6 +105,11 @@ abstract class Living extends Entity implements Damageable{
$this->setHealth($this->getHealth() - $damage);
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = $this->getHealth() <= 0 ? 3 : 2; //Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);
$this->attackTime = 10; //0.5 seconds cooldown
}