mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Refactored entity metadata handling into its own class, with type-safe methods (#1876)
This includes several other changes, including: - SLOT data properties now accept items directly - POS data properties now accept floored Vector3s (in future this will be block positions) or null for 0,0,0 - VECTOR3F data properties now accept Vector3s or null for 0,0,0
This commit is contained in:
@ -153,23 +153,17 @@ class NetworkBinaryStream extends BinaryStream{
|
||||
$value = $this->getString();
|
||||
break;
|
||||
case Entity::DATA_TYPE_SLOT:
|
||||
//TODO: use objects directly
|
||||
$value = [];
|
||||
$item = $this->getSlot();
|
||||
$value[0] = $item->getId();
|
||||
$value[1] = $item->getCount();
|
||||
$value[2] = $item->getDamage();
|
||||
$value = $this->getSlot();
|
||||
break;
|
||||
case Entity::DATA_TYPE_POS:
|
||||
$value = [0, 0, 0];
|
||||
$this->getSignedBlockPosition(...$value);
|
||||
$value = new Vector3();
|
||||
$this->getSignedBlockPosition($value->x, $value->y, $value->z);
|
||||
break;
|
||||
case Entity::DATA_TYPE_LONG:
|
||||
$value = $this->getVarLong();
|
||||
break;
|
||||
case Entity::DATA_TYPE_VECTOR3F:
|
||||
$value = [0.0, 0.0, 0.0];
|
||||
$this->getVector3f(...$value);
|
||||
$value = $this->getVector3Obj();
|
||||
break;
|
||||
default:
|
||||
$value = [];
|
||||
@ -211,19 +205,21 @@ class NetworkBinaryStream extends BinaryStream{
|
||||
$this->putString($d[1]);
|
||||
break;
|
||||
case Entity::DATA_TYPE_SLOT:
|
||||
//TODO: change this implementation (use objects)
|
||||
$this->putSlot(ItemFactory::get($d[1][0], $d[1][2], $d[1][1])); //ID, damage, count
|
||||
$this->putSlot($d[1]);
|
||||
break;
|
||||
case Entity::DATA_TYPE_POS:
|
||||
//TODO: change this implementation (use objects)
|
||||
$this->putSignedBlockPosition(...$d[1]);
|
||||
$v = $d[1];
|
||||
if($v !== null){
|
||||
$this->putSignedBlockPosition($v->x, $v->y, $v->z);
|
||||
}else{
|
||||
$this->putSignedBlockPosition(0, 0, 0);
|
||||
}
|
||||
break;
|
||||
case Entity::DATA_TYPE_LONG:
|
||||
$this->putVarLong($d[1]);
|
||||
break;
|
||||
case Entity::DATA_TYPE_VECTOR3F:
|
||||
//TODO: change this implementation (use objects)
|
||||
$this->putVector3f(...$d[1]); //x, y, z
|
||||
$this->putVector3ObjNullable($d[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ use pocketmine\network\mcpe\NetworkBinaryStream;
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\utils\Utils;
|
||||
|
||||
|
||||
abstract class DataPacket extends NetworkBinaryStream{
|
||||
|
||||
public const NETWORK_ID = 0;
|
||||
|
Reference in New Issue
Block a user