Posted May 7, 20223 yr 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
May 7, 20223 yr 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
May 7, 20223 yr 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 May 7, 20223 yr by BLT typo
May 7, 20223 yr then debug your code is every thing called how it should which TagKey did you use and which Items are in this Tag? Edited May 7, 20223 yr by Luis_ST
May 7, 20223 yr 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.