Posted November 12, 201410 yr 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
November 12, 201410 yr 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
November 13, 201410 yr 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.
November 13, 201410 yr Author So I have to redo it pretty much... The proud(ish) developer of Ancients
November 13, 201410 yr Author Should I still try and use an ArrayList? or should I just use an ItemStack[]? The proud(ish) developer of Ancients
November 13, 201410 yr 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--
November 13, 201410 yr 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.