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);
74 private bool $waxed =
false;
76 protected ?
int $editorEntityRuntimeId =
null;
81 parent::__construct($world, $pos);
85 $baseColor = new
Color(0, 0, 0);
87 if(($baseColorTag = $nbt->
getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){
88 $baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue()));
90 if($lightingBugResolved && ($glowingTextTag = $nbt->
getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag){
93 $glowingText = $glowingTextTag->getValue() !== 0;
95 return SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB),
'UTF-8'), $baseColor, $glowingText);
98 private function writeTextTag(SignText $text) :
CompoundTag{
100 ->setString(self::TAG_TEXT_BLOB, rtrim(implode(
"\n", $text->getLines()),
"\n"))
101 ->setInt(self::TAG_TEXT_COLOR, Binary::signInt($text->getBaseColor()->toARGB()))
102 ->setByte(self::TAG_GLOWING_TEXT, $text->isGlowing() ? 1 : 0)
103 ->setByte(self::TAG_PERSIST_FORMATTING, 1);
106 public function readSaveData(CompoundTag $nbt) : void{
107 $frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT);
108 if($frontTextTag instanceof CompoundTag){
109 $this->text = $this->readTextTag($frontTextTag,
true);
110 }elseif($nbt->getTag(self::TAG_TEXT_BLOB) instanceof StringTag){
111 $lightingBugResolved =
false;
112 if(($lightingBugResolvedTag = $nbt->getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag){
113 $lightingBugResolved = $lightingBugResolvedTag->getValue() !== 0;
115 $this->text = $this->readTextTag($nbt, $lightingBugResolved);
118 for($i = 0; $i < SignText::LINE_COUNT; ++$i){
119 $textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
120 if(($lineTag = $nbt->getTag($textKey)) instanceof StringTag){
121 $text[$i] = mb_scrub($lineTag->getValue(),
'UTF-8');
124 $this->text =
new SignText($text);
126 $backTextTag = $nbt->getTag(self::TAG_BACK_TEXT);
127 $this->backText = $backTextTag instanceof CompoundTag ? $this->readTextTag($backTextTag,
true) : new SignText();
128 $this->waxed = $nbt->getByte(self::TAG_WAXED, 0) !== 0;
132 $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->text));
133 $nbt->
setTag(self::TAG_BACK_TEXT, $this->writeTextTag($this->backText));
135 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
138 public function getText() :
SignText{
142 public function setText(
SignText $text) : void{
146 public function getBackText() : SignText{ return $this->backText; }
148 public function setBackText(SignText $backText) : void{ $this->backText = $backText; }
150 public function isWaxed() : bool{ return $this->waxed; }
152 public function setWaxed(
bool $waxed) : void{ $this->waxed = $waxed; }
166 public function setEditorEntityRuntimeId(?
int $editorEntityRuntimeId) : void{
167 $this->editorEntityRuntimeId = $editorEntityRuntimeId;
171 $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->text));
172 $nbt->
setTag(self::TAG_BACK_TEXT, $this->writeTextTag($this->backText));
173 $nbt->
setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
174 $nbt->
setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1);
static fromBlob(string $blob, ?Color $baseColor=null, bool $glowing=false)