Skip to content

Commit

Permalink
Don't try to parse writeable book contents as text component
Browse files Browse the repository at this point in the history
Fixes #97
  • Loading branch information
RaphiMC committed Jan 5, 2025
1 parent 881f3c1 commit ed88d8b
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.mcstructs.text.ATextComponent;
import com.viaversion.viaversion.libs.mcstructs.text.components.StringComponent;
import com.viaversion.viaversion.libs.mcstructs.text.serializer.TextComponentSerializer;
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
Expand Down Expand Up @@ -104,7 +105,7 @@ public Item handleItemToClient(final UserConnection user, final Item item) {

gameProfileFetcher.getMojangUUIDAsync(skullOwnerName).thenAccept(gameProfileFetcher::getGameProfile);
}
} else if ((item.identifier() == ItemList1_6.writtenBook.itemId() || item.identifier() == ItemList1_6.writableBook.itemId()) && item.tag() != null) {
} else if (item.identifier() == ItemList1_6.writtenBook.itemId() && item.tag() != null) {
final ListTag<StringTag> pages = item.tag().getListTag("pages", StringTag.class);
if (pages == null) return item;

Expand All @@ -127,13 +128,18 @@ public Item handleItemToServer(final UserConnection user, final Item item) {
if (item.tag().get("1_7_SkullOwner") instanceof StringTag) {
item.tag().put("SkullOwner", item.tag().remove("1_7_SkullOwner"));
}
} else if ((item.identifier() == ItemList1_6.writtenBook.itemId() || item.identifier() == ItemList1_6.writableBook.itemId()) && item.tag() != null) {
} else if (item.identifier() == ItemList1_6.writtenBook.itemId() && item.tag() != null) {
final ListTag<StringTag> pages = item.tag().getListTag("pages", StringTag.class);
if (pages == null) break NOT_VALID;

for (int i = 0; i < pages.size(); i++) {
final String text = pages.get(i).getValue();
pages.set(i, new StringTag(TextComponentSerializer.V1_8.deserialize(text).asLegacyFormatString()));
final ATextComponent textComponent = TextComponentSerializer.V1_8.deserialize(text);
if (textComponent instanceof StringComponent stringComponent) {
pages.set(i, new StringTag(stringComponent.getText()));
} else {
pages.set(i, new StringTag(textComponent.asLegacyFormatString()));
}
}
}

Expand Down

0 comments on commit ed88d8b

Please sign in to comment.