45 public const TAG_TEXT_BLOB =
"Text";
46 public const TAG_TEXT_LINE =
"Text%d";
47 public const TAG_TEXT_COLOR =
"SignTextColor";
48 public const TAG_GLOWING_TEXT =
"IgnoreLighting";
49 public const TAG_PERSIST_FORMATTING =
"PersistFormatting";
56 public const TAG_FRONT_TEXT =
"FrontText";
57 public const TAG_BACK_TEXT =
"BackText";
58 public const TAG_WAXED =
"IsWaxed";
59 public const TAG_LOCKED_FOR_EDITING_BY =
"LockedForEditingBy";
63 private bool $waxed =
false;
65 protected ?
int $editorEntityRuntimeId =
null;
70 parent::__construct($world, $pos);
74 $baseColor = new
Color(0, 0, 0);
76 if(($baseColorTag = $nbt->
getTag(self::TAG_TEXT_COLOR)) instanceof
IntTag){
77 $baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue()));
79 if($lightingBugResolved && ($glowingTextTag = $nbt->
getTag(self::TAG_GLOWING_TEXT)) instanceof
ByteTag){
82 $glowingText = $glowingTextTag->getValue() !== 0;
84 return SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB),
'UTF-8'), $baseColor, $glowingText);
89 ->setString(self::TAG_TEXT_BLOB, rtrim(implode(
"\n", $text->getLines()),
"\n"))
90 ->setInt(self::TAG_TEXT_COLOR,
Binary::signInt($text->getBaseColor()->toARGB()))
91 ->setByte(self::TAG_GLOWING_TEXT, $text->isGlowing() ? 1 : 0)
92 ->setByte(self::TAG_PERSIST_FORMATTING, 1);
95 public function readSaveData(
CompoundTag $nbt) : void{
96 $frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT);
98 $this->text = $this->readTextTag($frontTextTag,
true);
99 }elseif($nbt->
getTag(self::TAG_TEXT_BLOB) instanceof StringTag){
100 $lightingBugResolved =
false;
101 if(($lightingBugResolvedTag = $nbt->
getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag){
102 $lightingBugResolved = $lightingBugResolvedTag->getValue() !== 0;
104 $this->text = $this->readTextTag($nbt, $lightingBugResolved);
107 for($i = 0; $i < SignText::LINE_COUNT; ++$i){
108 $textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
109 if(($lineTag = $nbt->
getTag($textKey)) instanceof StringTag){
110 $text[$i] = mb_scrub($lineTag->getValue(),
'UTF-8');
113 $this->text =
new SignText($text);
115 $backTextTag = $nbt->
getTag(self::TAG_BACK_TEXT);
116 $this->backText = $backTextTag instanceof CompoundTag ? $this->readTextTag($backTextTag,
true) : new SignText();
117 $this->waxed = $nbt->getByte(self::TAG_WAXED, 0) !== 0;
121 $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->text));
122 $nbt->
setTag(self::TAG_BACK_TEXT, $this->writeTextTag($this->backText));
124 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
127 public function getText() :
SignText{
131 public function setText(
SignText $text) : void{
135 public function getBackText() : SignText{ return $this->backText; }
137 public function setBackText(SignText $backText) : void{ $this->backText = $backText; }
139 public function isWaxed() : bool{ return $this->waxed; }
141 public function setWaxed(
bool $waxed) : void{ $this->waxed = $waxed; }
155 public function setEditorEntityRuntimeId(?
int $editorEntityRuntimeId) : void{
156 $this->editorEntityRuntimeId = $editorEntityRuntimeId;
160 $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->text));
161 $nbt->
setTag(self::TAG_BACK_TEXT, $this->writeTextTag($this->backText));
162 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
163 $nbt->
setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1);
static fromBlob(string $blob, ?Color $baseColor=null, bool $glowing=false)