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";
68 return array_slice(array_pad(explode(
"\n", $blob, limit: 5), 4,
""), 0, 4);
72 private bool $waxed =
false;
74 protected ?
int $editorEntityRuntimeId =
null;
78 parent::__construct($world, $pos);
81 private function readTextTag(
CompoundTag $nbt,
bool $lightingBugResolved) : void{
82 $baseColor = new
Color(0, 0, 0);
84 if(($baseColorTag = $nbt->
getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){
85 $baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue()));
87 if($lightingBugResolved && ($glowingTextTag = $nbt->
getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag){
90 $glowingText = $glowingTextTag->getValue() !== 0;
92 $this->text =
SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB),
'UTF-8'), $baseColor, $glowingText);
95 public function readSaveData(
CompoundTag $nbt) : void{
96 $frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT);
98 $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->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 $this->waxed = $nbt->getByte(self::TAG_WAXED, 0) !== 0;
119 $nbt->setTag(self::TAG_FRONT_TEXT,
CompoundTag::create()
120 ->setString(self::TAG_TEXT_BLOB, implode(
"\n", $this->text->getLines()))
121 ->setInt(self::TAG_TEXT_COLOR,
Binary::signInt($this->text->getBaseColor()->toARGB()))
122 ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0)
123 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
125 $nbt->
setTag(self::TAG_BACK_TEXT, CompoundTag::create()
126 ->setString(self::TAG_TEXT_BLOB,
"")
127 ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00))
128 ->setByte(self::TAG_GLOWING_TEXT, 0)
129 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
132 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
135 public function getText() :
SignText{
139 public function setText(
SignText $text) : void{
143 public function isWaxed() : bool{ return $this->waxed; }
145 public function setWaxed(
bool $waxed) : void{ $this->waxed = $waxed; }
159 public function setEditorEntityRuntimeId(?
int $editorEntityRuntimeId) : void{
160 $this->editorEntityRuntimeId = $editorEntityRuntimeId;
164 $nbt->setTag(self::TAG_FRONT_TEXT,
CompoundTag::create()
165 ->setString(self::TAG_TEXT_BLOB, implode(
"\n", $this->text->getLines()))
166 ->setInt(self::TAG_TEXT_COLOR,
Binary::signInt($this->text->getBaseColor()->toARGB()))
167 ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0)
168 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
171 $nbt->
setTag(self::TAG_BACK_TEXT, CompoundTag::create()
172 ->setString(self::TAG_TEXT_BLOB,
"")
173 ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00))
174 ->setByte(self::TAG_GLOWING_TEXT, 0)
175 ->setByte(self::TAG_PERSIST_FORMATTING, 1)
177 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
178 $nbt->
setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1);
static fromBlob(string $blob, ?Color $baseColor=null, bool $glowing=false)