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

this code isn't working (as in it crashes with NullPointerException):

 

@Override
public void updateTick(World world,int x,int y,int z,Random rand){
	CrucibleTileEntity te = (CrucibleTileEntity)world.getTileEntity(x, y, z);

	List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x+0D, y+1D, z+0D, x+1D, y+2D, z+1D));

	ItemStack item=null;

	if(items.size()>0){


		item = items.get(items.size()-1).getEntityItem();
		if(CrucibleRecipeHandler.alloweds.contains(item.getItem())){

			int Counter=0;

			for(ItemStack i : inventory){
				Counter++;
				if(i.isItemEqual(item))
					if(i.isItemEqual(inventory.get(Counter-1))){
						inventory.add(new ItemStack(i.getItem(),i.stackSize+inventory.get(Counter-1).stackSize));
						inventory.remove(Counter-1);
					break;
					}
			}
			Counter=0;


			inventory.add(item);
			items.get(items.size()-1).setDead();
			item = null;
		}

 

inventory is an ArrayList stored outside the function. Yes I  realize I have to use a tileentity etc, this is just for testing purposes.

The proud(ish) developer of Ancients

  • Author

I changed it to:

item = items.get(items.size()-1).getEntityItem();
		if(CrucibleRecipeHandler.alloweds.contains(item.getItem())){

			int Counter=0;

			for(ItemStack i : inventory){
				Counter++;
				if(i.isItemEqual(item))
					if(inventory.get(Counter)!=null)
					if(i.isItemEqual(inventory.get(Counter-1))){
						inventory.add(new ItemStack(i.getItem(),i.stackSize+inventory.get(Counter-1).stackSize));
					break;
					}
			}
			if(inventory.get(Counter-1)!=null)
			inventory.remove(Counter-1);
			Counter=0;


			inventory.add(item);
			items.get(items.size()-1).setDead();
			item = null;
		}

it still doesn't work, keep getting crashes on my null check... "if(inventory.get(Counter-1)!=null)"

The proud(ish) developer of Ancients

Is your inventory ArrayList ever empty for any reason?

 

If so, then it will crash on that line since you're checking the index position of Counter-1, which will be -1 if the counter is not incremented. Now, the counter is only incremented within your augmented for-loop, which won't execute if there are no elements in the inventory ArrayList.

  • Author

Should I still try and use an ArrayList? or should I just use an ItemStack[]?

The proud(ish) developer of Ancients

I'd say you could do a if(inventory != null) check before that get() call.

 

I also see that you do not have brackets for the if-statements, which only works for one-line statements after the if()

--Remember to "Thank you" posts that actually helped you, and if a person seems nice, why not give them an applaud while you're at it--

  • Author

first, wouldn't the ArrayList = a new ArrayList?  Wouldn't it not be null then? or is that how "new" works.

 

also They're nested if statements, I didn't need the brackets.

The proud(ish) developer of Ancients

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.