AddEntityPacket's attributes encoding is still non-standard -_-

I thought they fixed this...
This commit is contained in:
Dylan K. Taylor 2017-06-11 18:09:58 +01:00
parent 789df942b6
commit 4341fb8347
2 changed files with 29 additions and 2 deletions

View File

@ -64,6 +64,7 @@ class Attribute{
self::addAttribute(self::EXPERIENCE_LEVEL, "minecraft:player.level", 0.00, 24791.00, 0.00);
self::addAttribute(self::EXPERIENCE, "minecraft:player.experience", 0.00, 1.00, 0.00);
//TODO: minecraft:luck (for fishing?)
//TODO: minecraft:fall_damage
}
/**

View File

@ -55,7 +55,25 @@ class AddEntityPacket extends DataPacket{
$this->getVector3f($this->speedX, $this->speedY, $this->speedZ);
$this->pitch = $this->getLFloat();
$this->yaw = $this->getLFloat();
$this->attributes = $this->getAttributeList();
$attrCount = $this->getUnsignedVarInt();
for($i = 0; $i < $attrCount; ++$i){
$name = $this->getString();
$min = $this->getLFloat();
$current = $this->getLFloat();
$max = $this->getLFloat();
$attr = Attribute::getAttributeByName($name);
if($attr !== null){
$attr->setMinValue($min);
$attr->setMaxValue($max);
$attr->setValue($current);
$this->attributes[] = $attr;
}else{
throw new \UnexpectedValueException("Unknown attribute type \"$name\"");
}
}
$this->metadata = $this->getEntityMetadata();
$linkCount = $this->getUnsignedVarInt();
for($i = 0; $i < $linkCount; ++$i){
@ -74,7 +92,15 @@ class AddEntityPacket extends DataPacket{
$this->putVector3f($this->speedX, $this->speedY, $this->speedZ);
$this->putLFloat($this->pitch);
$this->putLFloat($this->yaw);
$this->putAttributeList(...$this->attributes);
$this->putUnsignedVarInt(count($this->attributes));
foreach($this->attributes as $attribute){
$this->putString($attribute->getName());
$this->putLFloat($attribute->getMinValue());
$this->putLFloat($attribute->getValue());
$this->putLFloat($attribute->getMaxValue());
}
$this->putEntityMetadata($this->metadata);
$this->putUnsignedVarInt(count($this->links));
foreach($this->links as $link){