Entity spawn packets

This commit is contained in:
Shoghi Cervantes 2014-02-07 17:24:50 +01:00
parent 083bfcc83c
commit 84638098d0

View File

@ -572,24 +572,24 @@ class Entity extends Position{
$players = $this->server->api->player->getAll($this->level); $players = $this->server->api->player->getAll($this->level);
if($this->player instanceof Player){ if($this->player instanceof Player){
unset($players[$this->player->CID]); unset($players[$this->player->CID]);
$this->server->api->player->broadcastPacket($players, ProtocolInfo::MOVE_PLAYER_PACKET, array( $pk = new MovePlayerPacket;
"eid" => $this->eid, $pk->eid = $this->eid;
"x" => $this->x, $pk->x = $this->x;
"y" => $this->y, $pk->y = $this->y;
"z" => $this->z, $pk->z = $this->z;
"yaw" => $this->yaw, $pk->yaw = $this->yaw;
"pitch" => $this->pitch, $pk->pitch = $this->pitch;
"bodyYaw" => $this->yaw, $pk->bodyYaw = $this->yaw;
)); $this->server->api->player->broadcastPacket($players, $pk);
}else{ }else{
$this->server->api->player->broadcastPacket($players, ProtocolInfo::MOVE_ENTITY_POSROT_PACKET, array( $pk = new MoveEntityPacket_PosRot;
"eid" => $this->eid, $pk->eid = $this->eid;
"x" => $this->x, $pk->x = $this->x;
"y" => $this->y, $pk->y = $this->y;
"z" => $this->z, $pk->z = $this->z;
"yaw" => $this->yaw, $pk->yaw = $this->yaw;
"pitch" => $this->pitch, $pk->pitch = $this->pitch;
)); $this->server->api->player->broadcastPacket($players, $pk);
} }
} }
}else{ }else{
@ -661,116 +661,135 @@ class Entity extends Position{
if($this->player->connected !== true or $this->player->spawned === false){ if($this->player->connected !== true or $this->player->spawned === false){
return false; return false;
} }
$player->dataPacket(ProtocolInfo::ADD_PLAYER_PACKET, array(
"clientID" => 0,/*$this->player->clientID,*/ $pk = new AddPlayerPacket;
"username" => $this->player->username, $pk->clientID = 0; //$this->player->clientID;
"eid" => $this->eid, $pk->username = $this->player->username;
"x" => $this->x, $pk->eid = $this->eid;
"y" => $this->y, $pk->x = $this->x;
"z" => $this->z, $pk->y = $this->y;
"yaw" => 0, $pk->z = $this->z;
"pitch" => 0, $pk->yaw = 0;
"unknown1" => 0, $pk->pitch = 0;
"unknown2" => 0, $pk->unknown1 = 0;
"metadata" => $this->getMetadata(), $pk->unknown2 = 0;
)); $pk->metadata = $this->getMetadata();
$player->dataPacket(ProtocolInfo::PLAYER_EQUIPMENT_PACKET, array( $player->dataPacket($pk);
"eid" => $this->eid,
"block" => $this->player->getSlot($this->player->slot)->getID(), $pk = new SetEntityMotionPacket;
"meta" => $this->player->getSlot($this->player->slot)->getMetadata(), $pk->eid = $this->eid;
"slot" => 0, $pk->speedX = $this->speedX;
)); $pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
$pk = new PlayerEquipmentPacket;
$pk->eid = $this->eid;
$pk->item = $this->player->getSlot($this->player->slot)->getID();
$pk->meta = $this->player->getSlot($this->player->slot)->getMetadata();
$pk->slot = 0;
$player->dataPacket($pk);
$this->player->sendArmor($player); $this->player->sendArmor($player);
break; break;
case ENTITY_ITEM: case ENTITY_ITEM:
$player->dataPacket(ProtocolInfo::ADD_ITEM_ENTITY_PACKET, array( $pk = new AddItemEntityPacket;
"eid" => $this->eid, $pk->eid = $this->eid;
"x" => $this->x, $pk->x = $this->x;
"y" => $this->y, $pk->y = $this->y;
"z" => $this->z, $pk->z = $this->z;
"yaw" => $this->yaw, $pk->yaw = $this->yaw;
"pitch" => $this->pitch, $pk->pitch = $this->pitch;
"roll" => 0, $pk->roll = 0;
"block" => $this->type, $pk->item = BlockAPI::getItem($this->type, $this->meta, $this->stack);
"meta" => $this->meta, $pk->metadata = $this->getMetadata();
"stack" => $this->stack, $player->dataPacket($pk);
));
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array( $pk = new SetEntityMotionPacket;
"eid" => $this->eid, $pk->eid = $this->eid;
"speedX" => (int) ($this->speedX * 400), $pk->speedX = $this->speedX;
"speedY" => (int) ($this->speedY * 400), $pk->speedY = $this->speedY;
"speedZ" => (int) ($this->speedZ * 400), $pk->speedZ = $this->speedZ;
)); $player->dataPacket($pk);
break; break;
case ENTITY_MOB: case ENTITY_MOB:
$player->dataPacket(ProtocolInfo::ADD_MOB_PACKET, array( $pk = new AddMobPacket;
"type" => $this->type, $pk->eid = $this->eid;
"eid" => $this->eid, $pk->type = $this->type;
"x" => $this->x, $pk->x = $this->x;
"y" => $this->y, $pk->y = $this->y;
"z" => $this->z, $pk->z = $this->z;
"yaw" => 0, $pk->yaw = $this->yaw;
"pitch" => 0, $pk->pitch = $this->pitch;
"metadata" => $this->getMetadata(), $pk->metadata = $this->getMetadata();
)); $player->dataPacket($pk);
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array(
"eid" => $this->eid, $pk = new SetEntityMotionPacket;
"speedX" => (int) ($this->speedX * 400), $pk->eid = $this->eid;
"speedY" => (int) ($this->speedY * 400), $pk->speedX = $this->speedX;
"speedZ" => (int) ($this->speedZ * 400), $pk->speedY = $this->speedY;
)); $pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
break; break;
case ENTITY_OBJECT: case ENTITY_OBJECT:
if($this->type === OBJECT_PAINTING){ if($this->type === OBJECT_PAINTING){
$player->dataPacket(ProtocolInfo::ADD_PAINTING_PACKET, array( $pk = new AddPaintingPacket;
"eid" => $this->eid, $pk->eid = $this->eid;
"x" => (int) $this->x, $pk->x = (int) $this->x;
"y" => (int) $this->y, $pk->y = (int) $this->y;
"z" => (int) $this->z, $pk->z = (int) $this->z;
"direction" => $this->getDirection(), $pk->direction = $this->getDirection();
"title" => $this->data["Motive"], $pk->title = $this->data["Motive"];
)); $player->dataPacket($pk);
}elseif($this->type === OBJECT_PRIMEDTNT){ }elseif($this->type === OBJECT_PRIMEDTNT){
$player->dataPacket(ProtocolInfo::ADD_ENTITY_PACKET, array( $pk = new AddEntityPacket;
"eid" => $this->eid, $pk->eid = $this->eid;
"type" => $this->type, $pk->type = $this->type;
"x" => $this->x, $pk->x = $this->x;
"y" => $this->y, $pk->y = $this->y;
"z" => $this->z, $pk->z = $this->z;
"did" => 0, $pk->did = 0;
)); $player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk->eid = $this->eid;
$pk->speedX = $this->speedX;
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
}elseif($this->type === OBJECT_ARROW){ }elseif($this->type === OBJECT_ARROW){
$player->dataPacket(ProtocolInfo::ADD_ENTITY_PACKET, array( $pk = new AddEntityPacket;
"eid" => $this->eid, $pk->eid = $this->eid;
"type" => $this->type, $pk->type = $this->type;
"x" => $this->x, $pk->x = $this->x;
"y" => $this->y, $pk->y = $this->y;
"z" => $this->z, $pk->z = $this->z;
"did" => 0, $pk->did = 0;
)); $player->dataPacket($pk);
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array(
"eid" => $this->eid, $pk = new SetEntityMotionPacket;
"speedX" => (int) ($this->speedX * 400), $pk->eid = $this->eid;
"speedY" => (int) ($this->speedY * 400), $pk->speedX = $this->speedX;
"speedZ" => (int) ($this->speedZ * 400), $pk->speedY = $this->speedY;
)); $pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
} }
break; break;
case ENTITY_FALLING: case ENTITY_FALLING:
$player->dataPacket(ProtocolInfo::ADD_ENTITY_PACKET, array( $pk = new AddEntityPacket;
"eid" => $this->eid, $pk->eid = $this->eid;
"type" => $this->type, $pk->type = $this->type;
"x" => $this->x, $pk->x = $this->x;
"y" => $this->y, $pk->y = $this->y;
"z" => $this->z, $pk->z = $this->z;
"did" => -$this->data["Tile"], $pk->did = -$this->data["Tile"];
)); $player->dataPacket($pk);
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array(
"eid" => $this->eid, $pk = new SetEntityMotionPacket;
"speedX" => (int) ($this->speedX * 400), $pk->eid = $this->eid;
"speedY" => (int) ($this->speedY * 400), $pk->speedX = $this->speedX;
"speedZ" => (int) ($this->speedZ * 400), $pk->speedY = $this->speedY;
)); $pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
break; break;
} }
} }
@ -995,14 +1014,14 @@ class Entity extends Position{
$this->updateMetadata(); $this->updateMetadata();
$this->dead = true; $this->dead = true;
if($this->player instanceof Player){ if($this->player instanceof Player){
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), ProtocolInfo::MOVE_ENTITY_POSROT_PACKET, array( $pk = new MoveEntityPacket_PosRot;
"eid" => $this->eid, $pk->eid = $this->eid;
"x" => -256, $pk->x = -256;
"y" => 128, $pk->y = 128;
"z" => -256, $pk->z = -256;
"yaw" => 0, $pk->yaw = 0;
"pitch" => 0, $pk->pitch = 0;
)); $this->server->api->player->broadcastPacket($this->level->players, $pk);
}else{ }else{
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead $this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead
} }