48 public const TAG_TEXT_BLOB =
"Text";
49 public const TAG_TEXT_LINE =
"Text%d";
50 public const TAG_TEXT_COLOR =
"SignTextColor";
51 public const TAG_GLOWING_TEXT =
"IgnoreLighting";
52 public const TAG_PERSIST_FORMATTING =
"PersistFormatting";
59 public const TAG_FRONT_TEXT =
"FrontText";
60 public const TAG_BACK_TEXT =
"BackText";
61 public const TAG_WAXED =
"IsWaxed";
62 public const TAG_LOCKED_FOR_EDITING_BY =
"LockedForEditingBy";
69 return array_slice(array_pad(explode(
"\n", $blob, limit: 5), 4,
""), 0, 4);
73 private bool $waxed =
false;
75 protected ?
int $editorEntityRuntimeId =
null;
79 parent::__construct($world, $pos);
82 private function readTextTag(
CompoundTag $nbt,
bool $lightingBugResolved) : void{
83 $baseColor = new
Color(0, 0, 0);
85 if(($baseColorTag = $nbt->
getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){
86 $baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue()));
88 if($lightingBugResolved && ($glowingTextTag = $nbt->
getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag){
91 $glowingText = $glowingTextTag->getValue() !== 0;
93 $this->text =
SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB),
'UTF-8'), $baseColor, $glowingText);
96 public function readSaveData(
CompoundTag $nbt) : void{
97 $frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT);
99 $this->readTextTag($frontTextTag,
true);
100 }elseif($nbt->
getTag(self::TAG_TEXT_BLOB) instanceof StringTag){
101 $lightingBugResolved =
false;
102 if(($lightingBugResolvedTag = $nbt->
getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag){
103 $lightingBugResolved = $lightingBugResolvedTag->getValue() !== 0;
105 $this->readTextTag($nbt, $lightingBugResolved);
108 for($i = 0; $i < SignText::LINE_COUNT; ++$i){
109 $textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
110 if(($lineTag = $nbt->
getTag($textKey)) instanceof StringTag){
111 $text[$i] = mb_scrub($lineTag->getValue(),
'UTF-8');
114 $this->text =
new SignText($text);
116 $this->waxed = $nbt->getByte(self::TAG_WAXED, 0) !== 0;
120 $nbt->setTag(self::TAG_FRONT_TEXT,
CompoundTag::create()
121 ->setString(self::TAG_TEXT_BLOB, rtrim(implode(
"\n", $this->text->getLines()),
"\n"))
122 ->setInt(self::TAG_TEXT_COLOR,
Binary::signInt($this->text->getBaseColor()->toARGB()))
123 ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0)
124 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
126 $nbt->
setTag(self::TAG_BACK_TEXT, CompoundTag::create()
127 ->setString(self::TAG_TEXT_BLOB,
"")
128 ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00))
129 ->setByte(self::TAG_GLOWING_TEXT, 0)
130 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
133 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
136 public function getText() :
SignText{
140 public function setText(
SignText $text) : void{
144 public function isWaxed() : bool{ return $this->waxed; }
146 public function setWaxed(
bool $waxed) : void{ $this->waxed = $waxed; }
160 public function setEditorEntityRuntimeId(?
int $editorEntityRuntimeId) : void{
161 $this->editorEntityRuntimeId = $editorEntityRuntimeId;
165 $nbt->setTag(self::TAG_FRONT_TEXT,
CompoundTag::create()
166 ->setString(self::TAG_TEXT_BLOB, rtrim(implode(
"\n", $this->text->getLines()),
"\n"))
167 ->setInt(self::TAG_TEXT_COLOR,
Binary::signInt($this->text->getBaseColor()->toARGB()))
168 ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0)
169 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
172 $nbt->
setTag(self::TAG_BACK_TEXT, CompoundTag::create()
173 ->setString(self::TAG_TEXT_BLOB,
"")
174 ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00))
175 ->setByte(self::TAG_GLOWING_TEXT, 0)
176 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
178 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
179 $nbt->
setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1);
static fromBlob(string $blob, ?Color $baseColor=null, bool $glowing=false)