Refactored entity IDs in packets for consistency and to clarify on types

This commit is contained in:
Dylan K. Taylor 2017-06-05 15:41:27 +01:00
parent 51d510aa4f
commit 54453d0b0a
21 changed files with 58 additions and 58 deletions

View File

@ -1195,7 +1195,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->level->sleepTicks = 0;
$pk = new AnimatePacket();
$pk->eid = $this->id;
$pk->entityRuntimeId = $this->id;
$pk->action = 3; //Wake up
$this->dataPacket($pk);
}
@ -1638,7 +1638,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$entries = $sendAll ? $this->attributeMap->getAll() : $this->attributeMap->needSend();
if(count($entries) > 0){
$pk = new UpdateAttributesPacket();
$pk->entityId = $this->id;
$pk->entityRuntimeId = $this->id;
$pk->entries = $entries;
$this->dataPacket($pk);
foreach($entries as $entry){
@ -2573,7 +2573,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
$packet->eid = $this->id;
$packet->entityRuntimeId = $this->id;
$pos = new Vector3($packet->x, $packet->y, $packet->z);
switch($packet->action){
@ -2684,7 +2684,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->entityRuntimeId = $this->getId();
$pk->event = EntityEventPacket::USE_ITEM;
$this->dataPacket($pk);
$this->server->broadcastPacket($this->getViewers(), $pk);
@ -2840,7 +2840,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->entityRuntimeId = $this->getId();
$pk->action = $ev->getAnimationType();
$this->server->broadcastPacket($this->getViewers(), $pk);
@ -3936,7 +3936,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return;
}elseif($this->getLastDamageCause() === $source and $this->spawned){
$pk = new EntityEventPacket();
$pk->eid = $this->id;
$pk->entityRuntimeId = $this->id;
$pk->event = EntityEventPacket::HURT_ANIMATION;
$this->dataPacket($pk);
@ -3951,7 +3951,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$pitch = $pitch === null ? $this->pitch : $pitch;
$pk = new MovePlayerPacket();
$pk->eid = $this->getId();
$pk->entityRuntimeId = $this->getId();
$pk->x = $pos->x;
$pk->y = $pos->y + $this->getEyeHeight();
$pk->z = $pos->z;

View File

@ -396,7 +396,7 @@ class Effect{
}
if($entity instanceof Player){
$pk = new MobEffectPacket();
$pk->eid = $entity->getId();
$pk->entityRuntimeId = $entity->getId();
$pk->effectId = $this->getId();
$pk->amplifier = $this->getAmplifier();
$pk->particles = $this->isVisible();
@ -468,7 +468,7 @@ class Effect{
}
if($entity instanceof Player){
$pk = new MobEffectPacket();
$pk->eid = $entity->getId();
$pk->entityRuntimeId = $entity->getId();
$pk->eventId = MobEffectPacket::EVENT_REMOVE;
$pk->effectId = $this->getId();

View File

@ -834,7 +834,7 @@ abstract class Entity extends Location implements Metadatable{
public function sendPotionEffects(Player $player){
foreach($this->effects as $effect){
$pk = new MobEffectPacket();
$pk->eid = $this->id;
$pk->entityRuntimeId = $this->id;
$pk->effectId = $effect->getId();
$pk->amplifier = $effect->getAmplifier();
$pk->particles = $effect->isVisible();
@ -855,7 +855,7 @@ abstract class Entity extends Location implements Metadatable{
}
$pk = new SetEntityDataPacket();
$pk->eid = $this->getId();
$pk->entityRuntimeId = $this->getId();
$pk->metadata = $data === null ? $this->dataProperties : $data;
foreach($player as $p){
@ -878,7 +878,7 @@ abstract class Entity extends Location implements Metadatable{
if(isset($this->hasSpawned[$player->getLoaderId()])){
if($send){
$pk = new RemoveEntityPacket();
$pk->eid = $this->id;
$pk->entityUniqueId = $this->id;
$player->dataPacket($pk);
}
unset($this->hasSpawned[$player->getLoaderId()]);

View File

@ -73,7 +73,7 @@ abstract class Living extends Entity implements Damageable{
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth(), true);
if($this->isAlive() and !$wasAlive){
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->entityRuntimeId = $this->getId();
$pk->event = EntityEventPacket::RESPAWN;
$this->server->broadcastPacket($this->hasSpawned, $pk);
}
@ -166,7 +166,7 @@ abstract class Living extends Entity implements Damageable{
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->entityRuntimeId = $this->getId();
$pk->event = $this->getHealth() <= 0 ? EntityEventPacket::DEATH_ANIMATION : EntityEventPacket::HURT_ANIMATION; //Ouch!
$this->server->broadcastPacket($this->hasSpawned, $pk);

View File

@ -65,7 +65,7 @@ class Squid extends WaterAnimal implements Ageable{
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->entityRuntimeId = $this->getId();
$pk->event = EntityEventPacket::SQUID_INK_CLOUD;
$this->server->broadcastPacket($this->hasSpawned, $pk);
}

View File

@ -232,7 +232,7 @@ class PlayerInventory extends BaseInventory{
$item = $this->getItemInHand();
$pk = new MobEquipmentPacket();
$pk->eid = $this->getHolder()->getId();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->item = $item;
$pk->inventorySlot = $this->getHeldItemSlot();
$pk->hotbarSlot = $this->getHeldItemIndex();
@ -413,7 +413,7 @@ class PlayerInventory extends BaseInventory{
$armor = $this->getArmorContents();
$pk = new MobArmorEquipmentPacket();
$pk->eid = $this->getHolder()->getId();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->slots = $armor;
$pk->encode();
$pk->isEncoded = true;
@ -461,7 +461,7 @@ class PlayerInventory extends BaseInventory{
$armor = $this->getArmorContents();
$pk = new MobArmorEquipmentPacket();
$pk->eid = $this->getHolder()->getId();
$pk->entityRuntimeId = $this->getHolder()->getId();
$pk->slots = $armor;
$pk->encode();
$pk->isEncoded = true;

View File

@ -52,7 +52,7 @@ abstract class Food extends Item implements FoodSource{
public function onConsume(Entity $human){
$pk = new EntityEventPacket();
$pk->eid = $human->getId();
$pk->entityRuntimeId = $human->getId();
$pk->event = EntityEventPacket::USE_ITEM;
if($human instanceof Player){
$human->dataPacket($pk);

View File

@ -2904,7 +2904,7 @@ class Level implements ChunkManager, Metadatable{
public function addEntityMotion(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z){
$pk = new SetEntityMotionPacket();
$pk->eid = $entityId;
$pk->entityRuntimeId = $entityId;
$pk->motionX = $x;
$pk->motionY = $y;
$pk->motionZ = $z;
@ -2913,7 +2913,7 @@ class Level implements ChunkManager, Metadatable{
public function addEntityMovement(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z, float $yaw, float $pitch, $headYaw = null){
$pk = new MoveEntityPacket();
$pk->eid = $entityId;
$pk->entityRuntimeId = $entityId;
$pk->x = $x;
$pk->y = $y;
$pk->z = $z;

View File

@ -69,7 +69,7 @@ class FloatingTextParticle extends Particle{
$this->entityId = (int) bcadd("1095216660480", mt_rand(0, 0x7fffffff)); //No conflict with other things
}else{
$pk0 = new RemoveEntityPacket();
$pk0->eid = $this->entityId;
$pk0->entityUniqueId = $this->entityId;
$p[] = $pk0;
}

View File

@ -30,12 +30,12 @@ class AnimatePacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET;
public $action;
public $eid;
public $entityRuntimeId;
public $float; //TODO (Boat rowing time?)
public function decode(){
$this->action = $this->getVarInt();
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
if($this->action & 0x80){
$this->float = $this->getLFloat();
}
@ -44,7 +44,7 @@ class AnimatePacket extends DataPacket{
public function encode(){
$this->reset();
$this->putVarInt($this->action);
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
if($this->action & 0x80){
$this->putLFloat($this->float);
}

View File

@ -48,19 +48,19 @@ class EntityEventPacket extends DataPacket{
//TODO: add more events
public $eid;
public $entityRuntimeId;
public $event;
public $data = 0;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->event = $this->getByte();
$this->data = $this->getVarInt();
}
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putByte($this->event);
$this->putVarInt($this->data);
}

View File

@ -30,12 +30,12 @@ use pocketmine\network\mcpe\NetworkSession;
class MobArmorEquipmentPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET;
public $eid;
public $entityRuntimeId;
/** @var Item[] */
public $slots = [];
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->slots[0] = $this->getSlot();
$this->slots[1] = $this->getSlot();
$this->slots[2] = $this->getSlot();
@ -44,7 +44,7 @@ class MobArmorEquipmentPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putSlot($this->slots[0]);
$this->putSlot($this->slots[1]);
$this->putSlot($this->slots[2]);

View File

@ -33,7 +33,7 @@ class MobEffectPacket extends DataPacket{
const EVENT_MODIFY = 2;
const EVENT_REMOVE = 3;
public $eid;
public $entityRuntimeId;
public $eventId;
public $effectId;
public $amplifier = 0;
@ -41,7 +41,7 @@ class MobEffectPacket extends DataPacket{
public $duration = 0;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->eventId = $this->getByte();
$this->effectId = $this->getVarInt();
$this->amplifier = $this->getVarInt();
@ -51,7 +51,7 @@ class MobEffectPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putByte($this->eventId);
$this->putVarInt($this->effectId);
$this->putVarInt($this->amplifier);

View File

@ -29,14 +29,14 @@ use pocketmine\network\mcpe\NetworkSession;
class MobEquipmentPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::MOB_EQUIPMENT_PACKET;
public $eid;
public $entityRuntimeId;
public $item;
public $inventorySlot;
public $hotbarSlot;
public $unknownByte = 0;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->item = $this->getSlot();
$this->inventorySlot = $this->getByte();
$this->hotbarSlot = $this->getByte();
@ -45,7 +45,7 @@ class MobEquipmentPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putSlot($this->item);
$this->putByte($this->inventorySlot);
$this->putByte($this->hotbarSlot);

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\NetworkSession;
class MoveEntityPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_PACKET;
public $eid;
public $entityRuntimeId;
public $x;
public $y;
public $z;
@ -40,7 +40,7 @@ class MoveEntityPacket extends DataPacket{
public $teleported;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->getVector3f($this->x, $this->y, $this->z);
$this->pitch = $this->getByteRotation();
$this->headYaw = $this->getByteRotation();
@ -51,7 +51,7 @@ class MoveEntityPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putVector3f($this->x, $this->y, $this->z);
$this->putByteRotation($this->pitch);
$this->putByteRotation($this->headYaw);

View File

@ -34,7 +34,7 @@ class MovePlayerPacket extends DataPacket{
const MODE_TELEPORT = 2;
const MODE_PITCH = 3; //facepalm Mojang
public $eid;
public $entityRuntimeId;
public $x;
public $y;
public $z;
@ -48,7 +48,7 @@ class MovePlayerPacket extends DataPacket{
public $int2 = 0;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->getVector3f($this->x, $this->y, $this->z);
$this->pitch = $this->getLFloat();
$this->yaw = $this->getLFloat();
@ -64,7 +64,7 @@ class MovePlayerPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putVector3f($this->x, $this->y, $this->z);
$this->putLFloat($this->pitch);
$this->putLFloat($this->yaw);

View File

@ -49,7 +49,7 @@ class PlayerActionPacket extends DataPacket{
const ACTION_CONTINUE_BREAK = 18;
public $eid;
public $entityRuntimeId;
public $action;
public $x;
public $y;
@ -57,7 +57,7 @@ class PlayerActionPacket extends DataPacket{
public $face;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->action = $this->getVarInt();
$this->getBlockPosition($this->x, $this->y, $this->z);
$this->face = $this->getVarInt();
@ -65,7 +65,7 @@ class PlayerActionPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putVarInt($this->action);
$this->putBlockPosition($this->x, $this->y, $this->z);
$this->putVarInt($this->face);

View File

@ -29,15 +29,15 @@ use pocketmine\network\mcpe\NetworkSession;
class RemoveEntityPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::REMOVE_ENTITY_PACKET;
public $eid;
public $entityUniqueId;
public function decode(){
$this->eid = $this->getEntityUniqueId();
$this->entityUniqueId = $this->getEntityUniqueId();
}
public function encode(){
$this->reset();
$this->putEntityUniqueId($this->eid);
$this->putEntityUniqueId($this->entityUniqueId);
}
public function handle(NetworkSession $session) : bool{

View File

@ -29,17 +29,17 @@ use pocketmine\network\mcpe\NetworkSession;
class SetEntityDataPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::SET_ENTITY_DATA_PACKET;
public $eid;
public $entityRuntimeId;
public $metadata;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->metadata = $this->getEntityMetadata();
}
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putEntityMetadata($this->metadata);
}

View File

@ -29,19 +29,19 @@ use pocketmine\network\mcpe\NetworkSession;
class SetEntityMotionPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::SET_ENTITY_MOTION_PACKET;
public $eid;
public $entityRuntimeId;
public $motionX;
public $motionY;
public $motionZ;
public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->getVector3f($this->motionX, $this->motionY, $this->motionZ);
}
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->eid);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putVector3f($this->motionX, $this->motionY, $this->motionZ);
}

View File

@ -30,18 +30,18 @@ use pocketmine\network\mcpe\NetworkSession;
class UpdateAttributesPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::UPDATE_ATTRIBUTES_PACKET;
public $entityId;
public $entityRuntimeId;
/** @var Attribute[] */
public $entries = [];
public function decode(){
$this->entityId = $this->getEntityRuntimeId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->entries = $this->getAttributeList();
}
public function encode(){
$this->reset();
$this->putEntityRuntimeId($this->entityId);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putAttributeList(...$this->entries);
}