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

 

 

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

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.