47 public const TAG_TEXT_BLOB =
"Text";
48 public const TAG_TEXT_LINE =
"Text%d";
49 public const TAG_TEXT_COLOR =
"SignTextColor";
50 public const TAG_GLOWING_TEXT =
"IgnoreLighting";
51 public const TAG_PERSIST_FORMATTING =
"PersistFormatting";
58 public const TAG_FRONT_TEXT =
"FrontText";
59 public const TAG_BACK_TEXT =
"BackText";
60 public const TAG_WAXED =
"IsWaxed";
61 public const TAG_LOCKED_FOR_EDITING_BY =
"LockedForEditingBy";
67 return array_slice(array_pad(explode(
"\n", $blob), 4,
""), 0, 4);
71 private bool $waxed =
false;
73 protected ?
int $editorEntityRuntimeId =
null;
77 parent::__construct($world, $pos);
80 private function readTextTag(
CompoundTag $nbt,
bool $lightingBugResolved) : void{
81 $baseColor = new
Color(0, 0, 0);
83 if(($baseColorTag = $nbt->
getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){
84 $baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue()));
86 if($lightingBugResolved && ($glowingTextTag = $nbt->
getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag){
89 $glowingText = $glowingTextTag->getValue() !== 0;
91 $this->text =
SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB),
'UTF-8'), $baseColor, $glowingText);
94 public function readSaveData(
CompoundTag $nbt) : void{
95 $frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT);
97 $this->readTextTag($frontTextTag,
true);
98 }elseif($nbt->
getTag(self::TAG_TEXT_BLOB) instanceof StringTag){
99 $lightingBugResolved =
false;
100 if(($lightingBugResolvedTag = $nbt->
getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag){
101 $lightingBugResolved = $lightingBugResolvedTag->getValue() !== 0;
103 $this->readTextTag($nbt, $lightingBugResolved);
106 for($i = 0; $i < SignText::LINE_COUNT; ++$i){
107 $textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
108 if(($lineTag = $nbt->
getTag($textKey)) instanceof StringTag){
109 $text[$i] = mb_scrub($lineTag->getValue(),
'UTF-8');
112 $this->text =
new SignText($text);
114 $this->waxed = $nbt->getByte(self::TAG_WAXED, 0) !== 0;
118 $nbt->setTag(self::TAG_FRONT_TEXT,
CompoundTag::create()
119 ->setString(self::TAG_TEXT_BLOB, implode(
"\n", $this->text->getLines()))
120 ->setInt(self::TAG_TEXT_COLOR,
Binary::signInt($this->text->getBaseColor()->toARGB()))
121 ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0)
122 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
124 $nbt->
setTag(self::TAG_BACK_TEXT, CompoundTag::create()
125 ->setString(self::TAG_TEXT_BLOB,
"")
126 ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00))
127 ->setByte(self::TAG_GLOWING_TEXT, 0)
128 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
131 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
134 public function getText() :
SignText{
138 public function setText(
SignText $text) : void{
142 public function isWaxed() : bool{ return $this->waxed; }
144 public function setWaxed(
bool $waxed) : void{ $this->waxed = $waxed; }
158 public function setEditorEntityRuntimeId(?
int $editorEntityRuntimeId) : void{
159 $this->editorEntityRuntimeId = $editorEntityRuntimeId;
163 $nbt->setTag(self::TAG_FRONT_TEXT,
CompoundTag::create()
164 ->setString(self::TAG_TEXT_BLOB, implode(
"\n", $this->text->getLines()))
165 ->setInt(self::TAG_TEXT_COLOR,
Binary::signInt($this->text->getBaseColor()->toARGB()))
166 ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0)
167 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
170 $nbt->
setTag(self::TAG_BACK_TEXT, CompoundTag::create()
171 ->setString(self::TAG_TEXT_BLOB,
"")
172 ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00))
173 ->setByte(self::TAG_GLOWING_TEXT, 0)
174 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
176 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
177 $nbt->
setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1);
static fromBlob(string $blob, ?Color $baseColor=null, bool $glowing=false)