Jump to content

[1.10.2] Inserter glitch


Egietje

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.