Jump to content

Recommended Posts

Posted
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

 

 

Posted

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

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.