mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
better(?) way to handle eid translation, local eid 0 is not used now, some additional fixes
This commit is contained in:
parent
62819f8b12
commit
21f8796e89
32 changed files with 345 additions and 56 deletions
|
|
@ -96,7 +96,8 @@ abstract class ProtocolInfo{
|
|||
self::ADD_ENTITY_PACKET => true,
|
||||
self::REMOVE_BLOCK_PACKET => true,
|
||||
self::MOVE_PLAYER_PACKET => true,
|
||||
self::DROP_ITEM_PACKET => true
|
||||
self::DROP_ITEM_PACKET => true,
|
||||
self::SET_ENTITY_LINK_PACKET => true
|
||||
];
|
||||
}
|
||||
/*Unused:
|
||||
|
|
|
|||
|
|
@ -33,5 +33,14 @@ class AddEntityPacket extends RakNetDataPacket{
|
|||
$this->putShort((int)($this->speedZ * 8000));
|
||||
}
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,5 +29,12 @@ class AddItemEntityPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->pitch);
|
||||
$this->putByte($this->roll);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,5 +29,13 @@ class AddMobPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->pitch);
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,5 +25,13 @@ class AddPaintingPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->direction);
|
||||
$this->putString($this->title);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,5 +46,13 @@ class AddPlayerPacket extends RakNetDataPacket{
|
|||
$this->putShort($this->itemAuxValue); //Example: bow shooting power
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -22,4 +22,21 @@ class AnimatePacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,5 +18,13 @@ class DropItemPacket extends RakNetDataPacket{
|
|||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -31,5 +31,21 @@ class EntityEventPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
$this->putByte($this->event);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,24 @@ class InteractPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
$this->putInt($this->target);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
$this->target = $p->global2localEID[$this->target] ?? false;
|
||||
if($this->eid === false || $this->target === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
$this->target = $p->local2GlobalEID[$this->target] ?? false;
|
||||
if($this->eid === false || $this->target === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,4 +32,20 @@ class MoveEntityPacket_PosRot extends RakNetDataPacket{
|
|||
$this->putFloat($this->pitch);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -34,4 +34,20 @@ class MovePlayerPacket extends RakNetDataPacket{
|
|||
$this->putFloat($this->bodyYaw);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,13 @@ class PlayerActionPacket extends RakNetDataPacket{
|
|||
public function encode(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,22 @@ class PlayerArmorEquipmentPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->slots[2]);
|
||||
$this->putByte($this->slots[3]);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,22 @@ class PlayerEquipmentPacket extends RakNetDataPacket{
|
|||
$this->putShort($this->meta);
|
||||
$this->putByte($this->slot);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,4 +21,12 @@ class RemoveBlockPacket extends RakNetDataPacket{
|
|||
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,5 +15,13 @@ class RemoveEntityPacket extends RakNetDataPacket{
|
|||
$this->reset();
|
||||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,4 +18,12 @@ class RemovePlayerPacket extends RakNetDataPacket{
|
|||
$this->putLong($this->clientID);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,5 +24,12 @@ class RespawnPacket extends RakNetDataPacket{
|
|||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -26,4 +26,21 @@ class RotateHeadPacket extends RakNetDataPacket{
|
|||
$this->putByte($this->rawYaw ? $this->yaw : ($this->yaw / 360 / 0.0039062)); //wraps 360 angle to 0xff
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,5 +38,23 @@ class SendInventoryPacket extends RakNetDataPacket{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,5 +17,13 @@ class SetEntityDataPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
$this->put(Utils::writeMetadata($this->metadata));
|
||||
}
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,4 +28,23 @@ class SetEntityLinkPacket extends RakNetDataPacket{
|
|||
return ProtocolInfo::SET_ENTITY_LINK_PACKET;
|
||||
}
|
||||
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->rider = $p->local2GlobalEID[$this->rider] ?? false;
|
||||
$this->riding = $p->local2GlobalEID[$this->riding] ?? false;
|
||||
if($this->rider === false || $this->riding === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->rider = $p->global2localEID[$this->rider] ?? false;
|
||||
$this->riding = $p->global2localEID[$this->riding] ?? false;
|
||||
if($this->rider === false || $this->riding === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,5 +21,12 @@ class SetEntityMotionPacket extends RakNetDataPacket{
|
|||
$this->putShort((int) ($this->speedY * 8000));
|
||||
$this->putShort((int) ($this->speedZ * 8000));
|
||||
}
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,5 +27,13 @@ class StartGamePacket extends RakNetDataPacket{
|
|||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
}
|
||||
|
||||
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,4 +18,14 @@ class TakeItemEntityPacket extends RakNetDataPacket{
|
|||
$this->putInt($this->eid);
|
||||
}
|
||||
|
||||
//TODO convert
|
||||
public function eidsToLocal(Player $p){
|
||||
if(!$this->localEids){
|
||||
$this->localEids = true;
|
||||
$this->eid = $p->global2localEID[$this->eid] ?? false;
|
||||
$this->target = $p->global2localEID[$this->eid] ?? false;
|
||||
if($this->eid === false || $this->target === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,5 +38,13 @@ class UseItemPacket extends RakNetDataPacket{
|
|||
public function encode(){
|
||||
|
||||
}
|
||||
public function eidsToGlobal(Player $p){
|
||||
if($this->localEids){
|
||||
$this->localEids = false;
|
||||
$this->eid = $p->local2GlobalEID[$this->eid] ?? false;
|
||||
if($this->eid === false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue