Posted April 1, 20214 yr Quote private NonNullList<ItemStack> bowlContents = NonNullList.withSize(12, ItemStack.EMPTY); public NonNullList<ItemStack> getBowlContents() { return bowlContents; } public void setBowlContents(NonNullList<ItemStack> bowlContents) { this.bowlContents = bowlContents; } public void addItemInventory(PlayerEntity playerIn, Hand handIn) { for (int i = 0; i < 9; i++) { if (bowlContents.get(i).equals(new ItemStack(Items.AIR))) { System.out.println("False"); continue; } bowlContents.set(i, new ItemStack(playerIn.getHeldItemMainhand().getItem())); playerIn.getHeldItemMainhand().shrink(1); break; } } Im not an expert in NonNullLists but im not sure why Quote bowlContents.set(i, new ItemStack(playerIn.getHeldItemMainhand().getItem())); doesnt work. Any help is appriciated
April 1, 20214 yr 1: your List holds 12 Item Stacks, why are you only checking from 0 to 9 in the for loop? intentional? 2: don't use System.out, use a Logger, the example mod already comes with one in the ExampleMod class 3: the following will always return false bowlContents.get(i).equals(new ItemStack(Items.AIR) It must be the 4th time I have to explain this: an Item Stack (and any other class for that matter) is only ever equal to itself, any other instance of an ItemStack (even if it has the same item and count!) is not going to be equals, since it is a DIFFERENT object. however, minecraft ever only has one instance of an Item, so what you want is to check if the items are the same. basic knowledge of OOP would help 4: you have a NonNullList of ItemStack: private NonNullList<ItemStack> bowlContents and then try adding an Item to it: bowlContents.set(i, new ItemStack(playerIn.getHeldItemMainhand().getItem())); Items and ItemStack are not the same thing, again: basic knowledge of OOP would help In recommend just watching a video on Java OOP, it shouldn't take more than a couple hours, and would avoid simple mistakes
April 1, 20214 yr Author It is intentinal that its only 0-9. System.out is just for testing purposes. Ill watch some videos on OOP. Thanks
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.