From ebc65f6df54005d9ab169372b4e675e064275d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Kr=C3=BCger?= <46863600+itisluiz@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:00:31 -0300 Subject: [PATCH] fix: Resolve issue with book & quills on lectern contraptions Resolves #7253. Where an attempt to parse JSON out of a writable book (not a written book), which has raw string data for the pages array caused a game crash. --- .../simibubi/create/foundation/utility/NBTProcessors.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java index d23f57e89..42c88fbef 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java @@ -47,6 +47,11 @@ public final class NBTProcessors { return data; CompoundTag tag = book.getCompound("tag"); + // Check for book & quill, which does not have json pages and + // therefore can't have click events. Written books have an "author" tag. + if (!tag.contains("author", Tag.TAG_LIST)) + return data; + if (!tag.contains("pages", Tag.TAG_LIST)) return data; ListTag pages = tag.getList("pages", Tag.TAG_STRING); @@ -67,7 +72,7 @@ public final class NBTProcessors { if (!book.contains("tag", Tag.TAG_COMPOUND)) return data; CompoundTag itemData = book.getCompound("tag"); - + for (List entries : NBTHelper.readCompoundList(itemData.getList("Pages", Tag.TAG_COMPOUND), pageTag -> NBTHelper.readCompoundList(pageTag.getList("Entries", Tag.TAG_COMPOUND), tag -> tag.getString("Text")))) {