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

So I've made an inserter but it acts weird, it adds 1 new stack and adds 1 item to an already existing one, the code responsible for this:

	public void addItemToChest(BlockPos pos, World worldIn, Entity entityIn) {
	if (!worldIn.isRemote) {
		IBlockState state = worldIn.getBlockState(pos);
		Block block = state.getBlock();
		EntityItem entityItem = (EntityItem) entityIn;
		if(block.equals(Blocks.CHEST)) {
			BlockChest chest = (BlockChest) block;
    		ILockableContainer container = chest.getContainer(worldIn, pos, false);
			for (int i = 0;i < container.getSizeInventory();i++) {
				if (container.getStackInSlot(i) != null) {
					if (container.getStackInSlot(i).getItem().equals(entityItem.getEntityItem().getItem())) {
        				if (container.getStackInSlot(i).stackSize < 64) {
        					container.getStackInSlot(i).stackSize++;
        					entityItem.setDead();
        				}
        			}
    			} else {
    				container.setInventorySlotContents(i, entityItem.getEntityItem());
    				entityItem.setDead();
    				break;
    			}
			}
		}
	}
}

So when I drop 1 item on top of the inserter it adds it to all the stacks of that item and makes a new stack of the item

it worked before so...

You're a freaking idiot. Seriously.

 

if (container.getStackInSlot(i).stackSize < 64) {
container.getStackInSlot(i).stackSize++;
entityItem.setDead();
}

 

Seriously.  What the hell.  All of your problems are here.

 

And why are you not using Capabilities for item storage?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Oh wait, would it work like this:

public void addItemToChest(BlockPos pos, World worldIn, Entity entityIn) {
	if (!worldIn.isRemote) {
		IBlockState state = worldIn.getBlockState(pos);
		Block block = state.getBlock();
		EntityItem entityItem = (EntityItem) entityIn;
		ItemStack stack = entityItem.getEntityItem();
		Item item = stack.getItem();
		if(block.equals(Blocks.CHEST)) {
			BlockChest chest = (BlockChest) block;
    		TileEntityChest tile = (TileEntityChest) worldIn.getTileEntity(pos);
    		IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, (EnumFacing) state.getValue(FACING));
			for (int i = 0;i < handler.getSlots();i++) {
				if (handler.getStackInSlot(i) != null) {
					if (handler.getStackInSlot(i).getItem().equals(item)) {
        				if (handler.getStackInSlot(i).stackSize < stack.getMaxStackSize()) {
        					handler.getStackInSlot(i).stackSize++;
        					entityItem.setDead();
        				}
        			}
    			} else {
    				handler.insertItem(i, stack, false);
    				entityItem.setDead();
    				break;
    			}
			}
		}
	}
}

Run it and see.

 

No.

 

Because you didn't fix the issue I point out in the code I actually copied.  You changed a line I didn't copy.

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Look at the chunk of code and manually step through it. Use the debugger if you have to.

 

The error it obvious.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Guest
This topic is now closed to further replies.

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.