Jump to content

Comparing tags not working.


BLT

Recommended Posts

I have a function that gets a list of items in an Inventory, and then makes a list of all the items that have the a specific TagKey<Item>. The function is below:
 

protected NonNullList<ItemStack> getAllOfType(TagKey<Item> tagKey, Inventory pInv) {
        NonNullList<ItemStack> items = null;
        String invEmptyCheck = pInv.isEmpty() ? "Empty" : "not Empty";
        CustomBows.LOGGER.debug("pInv is " + invEmptyCheck);
        if(!pInv.isEmpty()) {
            for (ItemStack a : pInv.items) {
                if (Registry.ITEM.getHolderOrThrow(Registry.ITEM.getResourceKey(a.getItem()).get()).is(tagKey)); {
                    items.add(a);
                }
            }
        }
        return items;
    }

However, it keeps returning a null list. The log in this function returns "pInv is not Empty", but in its use case the debug says the list is empty. So I believe that the problem is with the following:
if(Registry.ITEM.getHolderOrThrow(Registry.ITEM.getResourceKey(a.getItem()).get()).is(tagKey))
Or with my tag json, which you can find in my GitHub repo: https://www.github.com/bltstudios/custom_bows

Link to comment
Share on other sites

2 minutes ago, Luis_ST said:

why on earth did you use this complicated code?
you can achieve the same thing with ItemStack#is

I tried that, but since its giving me the same null list I assumed it doesnt work.

Edited by BLT
typo
Link to comment
Share on other sites

1 minute ago, Luis_ST said:

then debug your code is every thing called how it should

which TagKey did you use and which Items are in this Tag?

As i showed, code has been debug, all code runs as it should
Here is ModTags class: https://github.com/bltstudios/custom_bows/blob/master/src/main/java/com/btstudios/custombows/init/ModTags.java

And my acceptable_heads.json file: https://github.com/bltstudios/custom_bows/blob/master/src/main/resources/data/custombows/tags/items/acceptable_heads.json

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.