Skip to content

Commit

Permalink
always reset raw value when tag value is set, initialize tag values
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Mar 4, 2022
1 parent 5cfc1a4 commit 83e59f4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/Tag/DoubleTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public function generatePayload(NbtSerializer $serializer): string
*/
public function setValue(float $value): FloatValueTag
{
if($value !== $this->value) {
$this->resetRawValue();
}
$this->resetRawValue();
return parent::setValue($value);
}

Expand All @@ -48,4 +46,4 @@ protected function readPayload(Reader $reader): Tag
$this->value = $reader->getSerializer()->decodeDouble($this->rawValue);
return $this;
}
}
}
6 changes: 2 additions & 4 deletions src/Tag/FloatTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function generatePayload(NbtSerializer $serializer): string
*/
public function setValue(float $value): FloatValueTag
{
if($value !== $this->value) {
$this->resetRawValue();
}
$this->resetRawValue();
return parent::setValue($value);
}

Expand All @@ -46,4 +44,4 @@ protected function readPayload(Reader $reader): Tag
$this->value = $reader->getSerializer()->decodeFloat($this->rawValue);
return $this;
}
}
}
2 changes: 1 addition & 1 deletion src/Tag/FloatValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

abstract class FloatValueTag extends Tag
{
protected float $value;
protected float $value = 0;

/**
* @return float
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/IntValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

abstract class IntValueTag extends Tag
{
protected int $value;
protected int $value = 0;

/**
* @return int
Expand Down
6 changes: 2 additions & 4 deletions src/Tag/LongTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function generatePayload(NbtSerializer $serializer): string
*/
public function setValue(int $value): IntValueTag
{
if($value !== $this->value) {
$this->resetRawValue();
}
$this->resetRawValue();
return parent::setValue($value);
}

Expand All @@ -47,4 +45,4 @@ protected function readPayload(Reader $reader): Tag
$this->value = $result->getValue();
return $this;
}
}
}
2 changes: 1 addition & 1 deletion src/Tag/StringTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StringTag extends Tag
{
public const TYPE = TagType::TAG_String;

protected string $value;
protected string $value = "";

/**
* @return string
Expand Down

0 comments on commit 83e59f4

Please sign in to comment.