protocol 27, added player spawn events after death from new protocol, added EntityEvent constants

This commit is contained in:
Shoghi Cervantes
2015-05-28 14:19:00 +02:00
parent 51062940c5
commit 9a2170d296
5 changed files with 34 additions and 6 deletions

View File

@ -62,6 +62,17 @@ abstract class Living extends Entity implements Damageable{
$this->setHealth($this->namedtag["Health"]);
}
public function setHealth($amount){
$wasAlive = $this->isAlive();
parent::setHealth($amount);
if($this->isAlive() and !$wasAlive){
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::RESPAWN;
Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
}
}
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Health = new Short("Health", $this->getHealth());
@ -117,7 +128,7 @@ abstract class Living extends Entity implements Damageable{
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = $this->getHealth() <= 0 ? 3 : 2; //Ouch!
$pk->event = $this->getHealth() <= 0 ? EntityEventPacket::DEATH_ANIMATION : EntityEventPacket::HURT_ANIMATION; //Ouch!
Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
$this->attackTime = 10; //0.5 seconds cooldown