Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

11 minutes ago, BLT said:
Registry.ITEM.getHolderOrThrow(Registry.ITEM.getResourceKey(a.getItem()).get()).is(tagKey)

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

  • Author
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

then debug your code is every thing called how it should

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

Edited by Luis_ST

  • Author
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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.