Skip to content

Commit

Permalink
fix: Resolve issue with book & quills on lectern contraptions (#7276)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
itisluiz authored Feb 14, 2025
1 parent d95515a commit 773fd25
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
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 {

Expand All @@ -43,6 +46,11 @@ public static synchronized void addSurvivalProcessor(BlockEntityType<?> type,
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");
Expand All @@ -67,7 +75,7 @@ public static synchronized void addSurvivalProcessor(BlockEntityType<?> type,
if (!book.contains("tag", Tag.TAG_COMPOUND))
return data;
CompoundTag itemData = book.getCompound("tag");

for (List<String> entries : NBTHelper.readCompoundList(itemData.getList("Pages", Tag.TAG_COMPOUND),
pageTag -> NBTHelper.readCompoundList(pageTag.getList("Entries", Tag.TAG_COMPOUND),
tag -> tag.getString("Text")))) {
Expand Down

0 comments on commit 773fd25

Please sign in to comment.