Drop useless numeric IDs for attributes, use strings instead

This commit is contained in:
Dylan K. Taylor
2018-10-19 13:43:01 +01:00
parent 20b87b7875
commit d88b32da91
5 changed files with 46 additions and 67 deletions

View File

@ -236,9 +236,9 @@ class NetworkBinaryStream extends BinaryStream{
$max = $this->getLFloat();
$current = $this->getLFloat();
$default = $this->getLFloat();
$name = $this->getString();
$id = $this->getString();
$attr = Attribute::getAttributeByName($name);
$attr = Attribute::getAttribute($id);
if($attr !== null){
$attr->setMinValue($min);
$attr->setMaxValue($max);
@ -247,7 +247,7 @@ class NetworkBinaryStream extends BinaryStream{
$list[] = $attr;
}else{
throw new \UnexpectedValueException("Unknown attribute type \"$name\"");
throw new \UnexpectedValueException("Unknown attribute type \"$id\"");
}
}
@ -266,7 +266,7 @@ class NetworkBinaryStream extends BinaryStream{
$this->putLFloat($attribute->getMaxValue());
$this->putLFloat($attribute->getValue());
$this->putLFloat($attribute->getDefaultValue());
$this->putString($attribute->getName());
$this->putString($attribute->getId());
}
}

View File

@ -69,11 +69,11 @@ class AddEntityPacket extends DataPacket{
$attrCount = $this->getUnsignedVarInt();
for($i = 0; $i < $attrCount; ++$i){
$name = $this->getString();
$id = $this->getString();
$min = $this->getLFloat();
$current = $this->getLFloat();
$max = $this->getLFloat();
$attr = Attribute::getAttributeByName($name);
$attr = Attribute::getAttribute($id);
if($attr !== null){
$attr->setMinValue($min);
@ -81,7 +81,7 @@ class AddEntityPacket extends DataPacket{
$attr->setValue($current);
$this->attributes[] = $attr;
}else{
throw new \UnexpectedValueException("Unknown attribute type \"$name\"");
throw new \UnexpectedValueException("Unknown attribute type \"$id\"");
}
}
@ -104,7 +104,7 @@ class AddEntityPacket extends DataPacket{
$this->putUnsignedVarInt(count($this->attributes));
foreach($this->attributes as $attribute){
$this->putString($attribute->getName());
$this->putString($attribute->getId());
$this->putLFloat($attribute->getMinValue());
$this->putLFloat($attribute->getValue());
$this->putLFloat($attribute->getMaxValue());

View File

@ -44,7 +44,7 @@ class UpdateAttributesPacket extends DataPacket{
protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putAttributeList(...$this->entries);
$this->putAttributeList(...array_values($this->entries));
}
public function handle(SessionHandler $handler) : bool{