fix: Resolve issue with book & quills on lectern contraptions (#7276)

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.
This commit is contained in:
Luiz Krüger 2025-02-14 07:18:51 -03:00 committed by GitHub
parent d95515a405
commit 773fd257b9
Failed to generate hash of commit

View file

@ -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,6 +46,11 @@ 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");