mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-27 13:28:00 +01:00
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
This commit is contained in:
parent
ebc65f6df5
commit
308d2d72d2
1 changed files with 8 additions and 5 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue