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

@ -251,20 +251,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
* @param Player $player
*/
public function spawnTo(Player $player){
if($this->spawned === true and $this->dead !== true and $this !== $player and $player->getLevel() === $this->level and $player->canSee($this)){
if($this->spawned === true and $this->dead !== true and $player->dead !== true and $player->getLevel() === $this->level and $player->canSee($this)){
parent::spawnTo($player);
}
}
/**
* @param Player $player
*/
public function despawnFrom(Player $player){
if($this->spawned === true and $this->dead !== true){
parent::despawnFrom($player);
}
}
/**
* @return Server
*/
@ -1198,8 +1189,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
}
public function onUpdate($currentTick){
if($this->dead === true){
return true;
if($this->dead === true and $this->spawned){
++$this->deadTicks;
if($this->deadTicks >= 10){
$this->despawnFromAll();
}
return $this->deadTicks < 10;
}
$this->timings->startTiming();
@ -2001,11 +1996,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn()));
$this->teleport($ev->getRespawnPosition());
$this->fireTicks = 0;
$this->airTicks = 300;
$this->deadTicks = 0;
$this->setHealth(20);
$this->dead = false;
$this->sendMetadata($this->getViewers());
$this->sendMetadata($this);
@ -2013,9 +2011,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->inventory->sendContents($this);
$this->inventory->sendArmorContents($this);
$this->spawnToAll();
$this->blocked = false;
$this->spawnToAll();
$this->scheduleUpdate();
break;
case ProtocolInfo::SET_HEALTH_PACKET: //Not used
break;
@ -2565,9 +2564,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
if($ev->getDeathMessage() != ""){
$this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
}
$this->despawnFromAll();
}
public function setHealth($amount){

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
}

View File

@ -27,6 +27,10 @@ use pocketmine\nbt\NBT;
class Compound extends NamedTag implements \ArrayAccess{
/**
* @param string $name
* @param NamedTag[] $value
*/
public function __construct($name = "", $value = []){
$this->name = $name;
foreach($value as $tag){