From 308d2d72d2c230f41b3e904025af8f32d9a45422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Kr=C3=BCger?= <46863600+itisluiz@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:37:18 -0300 Subject: [PATCH] feat: More robust writable book check Instead of checking if the book has an author, check if it specifically is a writable book by id --- .../create/foundation/utility/NBTProcessors.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 42c88fbef..62cd194ad 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java @@ -15,13 +15,16 @@ import net.minecraft.nbt.ListTag; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.world.item.EnchantedBookItem; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.SpawnerBlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.registries.ForgeRegistries; public final class NBTProcessors { @@ -43,15 +46,15 @@ public final class NBTProcessors { return data; CompoundTag book = data.getCompound("Book"); + // Writable books can't have click events, so they're safe to keep + ResourceLocation writableBookResource = ForgeRegistries.ITEMS.getKey(Items.WRITABLE_BOOK); + if (writableBookResource != null && book.getString("id").equals(writableBookResource.toString())) + return data; + if (!book.contains("tag", Tag.TAG_COMPOUND)) 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);