mrh0 / buildersaddition

Builders Addition Minecraft Forge Mod by MRH0
MIT License
6 stars 12 forks source link

Suggestion: Allow Bookshelf to accept items tagged "forge:books" #36

Closed ghost closed 3 years ago

ghost commented 3 years ago

Currently the bookshelf accepts standard books and items with registry names that match certain patterns. I think it would be useful to accept items tagged as "forge:books" to allow more books to work. For example, some of the new books in Tinker's Construct don't fit the current rules, but they are tagged as "forge:books".

Current Behavior:

https://user-images.githubusercontent.com/83793683/125315584-e6fe6600-e2fc-11eb-969f-68737fc76aec.mp4

I tweaked class Util to accept book items by tag:

diff --git a/src/main/java/com/mrh0/buildersaddition/util/Util.java b/src/main/java/com/mrh0/buildersaddition/util/Util.java
index 6e70438..80f2566 100644
--- a/src/main/java/com/mrh0/buildersaddition/util/Util.java
+++ b/src/main/java/com/mrh0/buildersaddition/util/Util.java
@@ -9,12 +9,16 @@ import net.minecraft.item.Item;
 import net.minecraft.item.ItemStack;
 import net.minecraft.item.Items;
 import net.minecraft.item.KnowledgeBookItem;
+import net.minecraft.tags.ItemTags;
+import net.minecraft.tags.ITag;
 import net.minecraft.util.Direction;
+import net.minecraft.util.ResourceLocation;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.world.IBlockReader;
 import net.minecraft.world.World;

 public class Util {
+    private static final ITag<Item> FORGE_BOOK_TAG = ItemTags.makeWrapperTag(new ResourceLocation("forge", "books").toString());
    public static boolean isBook(ItemStack stack) {
        Item i = stack.getItem();
        String n = i.getRegistryName().getPath();
@@ -22,7 +26,8 @@ public class Util {
        return (i instanceof EnchantedBookItem) || (i instanceof KnowledgeBookItem) || i == Items.BOOK || i == Items.WRITABLE_BOOK || i == Items.WRITTEN_BOOK 
                || n.endsWith("book") || n.endsWith("manual") || n.endsWith("journal") || n.endsWith("tome")  || n.startsWith("tome") || n.endsWith("lexicon")  || n.endsWith("codex")
                || n.endsWith("guide") || n.startsWith("guide") || n.startsWith("handbook") || n.endsWith("chronicle") || n.endsWith("companion") || n.endsWith("binder") || n.endsWith("nomicon")
-               || n.endsWith("dictionary") || n.startsWith("dictionary") || n.endsWith("materials_and_you") || n.endsWith("binder") || n.startsWith("binder");
+               || n.endsWith("dictionary") || n.startsWith("dictionary") || n.endsWith("materials_and_you") || n.endsWith("binder") || n.startsWith("binder")
+                || i.isIn(FORGE_BOOK_TAG);
    }

    public static BlockState crackedState(BlockState cur) {

New Behavior:

https://user-images.githubusercontent.com/83793683/125315629-efef3780-e2fc-11eb-9491-a32d79655561.mp4

Let me know what you think.

mrh0 commented 3 years ago

Yes!

mrh0 commented 3 years ago

Fixed in 20210730b, however only on 1.17.1 atm.

mrh0 commented 3 years ago

in 1.16.5 20210807a