BrainFace Posted January 24, 2018 Posted January 24, 2018 I'm having the following problem, i'm trying to create a Witchery like cauldron and i need to check wether multiple Items (saved in a list) are contained in another list. List<ItemStack> items = new ArrayList<ItemStack>(); for (int i = 0; i < tile.getInventory().getSlots(); i++){ if (tile.getItem().getStackInSlot(i) != new ItemStack(Items.AIR)){ items.add(tile.getItem().getStackInSlot(i)); } } if (items.containsAll(recipe.catalysator)) { // TODO } The recipe.catalysator is a list that contains one item and the same item is also in the inventory. Quote
loordgek Posted January 24, 2018 Posted January 24, 2018 use itemstack.isEmpty not != new ItemStack(Items.AIR) Quote
Differentiation Posted January 24, 2018 Posted January 24, 2018 9 minutes ago, BrainFace said: List<ItemStack> items = new ArrayList<ItemStack>(); for (int i = 0; i < tile.getInventory().getSlots(); i++){ if (tile.getItem().getStackInSlot(i) != new ItemStack(Items.AIR)){ items.add(tile.getItem().getStackInSlot(i)); } } if (items.containsAll(recipe.catalysator)) { // TODO } List<ItemStack> items = new ArrayList<ItemStack>(); for (int i = 0; i < tile.getInventory().getSlots(); i++){ if (!tile.getItem().getStackInSlot(i).isEmpty()){ items.add(tile.getItem().getStackInSlot(i)); } } if (items.containsAll(recipe.catalysator)) { // TODO } Quote
loordgek Posted January 24, 2018 Posted January 24, 2018 @Differentiation that code block is a bit hard to read Quote
Differentiation Posted January 24, 2018 Posted January 24, 2018 (edited) 14 minutes ago, BrainFace said: I'm having the following problem, i'm trying to create a Witchery like cauldron and i need to check wether multiple Items (saved in a list) are contained in another list. List<ItemStack> items = new ArrayList<ItemStack>(); for (int i = 0; i < tile.getInventory().getSlots(); i++){ if (tile.getItem().getStackInSlot(i) != new ItemStack(Items.AIR)){ items.add(tile.getItem().getStackInSlot(i)); } } if (items.containsAll(recipe.catalysator)) { // TODO } The recipe.catalysator is a list that contains one item and the same item is also in the inventory. List<ItemStack> items = new ArrayList<ItemStack>(); for (int i = 0; i < tile.getInventory().getSlots(); ++i) { if (!tile.getItem().getStackInSlot(i).isEmpty()) { items.add(tile.getItem().getStackInSlot(i)); } } if (items.containsAll(recipe.catalysator)) { } Edited January 24, 2018 by Differentiation Quote
Differentiation Posted January 24, 2018 Posted January 24, 2018 1 minute ago, loordgek said: @Differentiation that code block is a bit hard to read Purge the page (reload) 1 Quote
BrainFace Posted January 24, 2018 Author Posted January 24, 2018 So i tried this change and my inventory list doesnt contain air anymore but it still doesnt work. Quote
loordgek Posted January 24, 2018 Posted January 24, 2018 can you put all your code on https://github.com/ so we can have a look Quote
Recommended Posts
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.