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

Hi guys, I have a TileEntity with only 1 slot and it can contain only 1 item, but those item's max stack size is 4 and when I try to shift-click it transfer all stack. I tried to use overrided mergeItemStack function, but minecraft chrashes. In the console lot of this 2 strings:

2013-08-28 23:40:26 [iNFO] [sTDOUT] 	at net.minecraft.inventory.Container.retrySlotClick(Container.java:520)
2013-08-28 23:40:26 [iNFO] [sTDOUT] 	at net.minecraft.inventory.Container.slotClick(Container.java:291)

[spoiler=mergeItemStack]

@Override
    public boolean mergeItemStack(ItemStack stack, int begin, int end, boolean backwards)
{
	System.out.println("enter");
	int i = backwards ? end-1 : begin, increment = backwards ? -1 : 1;
	boolean flag = false;
	while(stack.stackSize > 0 && i >= begin && i < end)
	{
		System.out.println(i);
		Slot slot = this.getSlot(i);
		ItemStack slotStack = slot.getStack();
		int slotStacklimit = i < te.getSizeInventory() ? te.getInventoryStackLimit() : 64;
		int totalLimit = slotStacklimit < stack.getMaxStackSize() ? slotStacklimit : stack.getMaxStackSize();
		System.out.println("Slot Stack Limit: " + slotStacklimit);
		System.out.println("Total limit: " + totalLimit);
		if(slotStack == null)
		{
			System.out.println("Empty Stack");
			int transfer = totalLimit < stack.stackSize ? totalLimit : stack.stackSize;
			ItemStack stackToPut = stack.copy();
			stackToPut.stackSize = transfer;
			slot.putStack(stackToPut);
			slot.onSlotChanged();
			stack.stackSize -= transfer;
			flag = true;
        }
        else if(slotStack.itemID == stack.itemID && (!stack.getHasSubtypes() || stack.getItemDamage() == slotStack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, slotStack))
        {
        	System.out.println("Add to stack");
        	int maxTransfer = totalLimit - slotStack.stackSize;
        	int transfer = maxTransfer > stack.stackSize ? stack.stackSize : maxTransfer;
        	slotStack.stackSize += transfer;
        	slot.onSlotChanged();
        	stack.stackSize -= transfer;
        	flag = true;
        }
        i += increment;
	}
	System.out.println("exit");
	return flag;
    }

 

[spoiler=transferStackInSlot]

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
{
	ItemStack itemstack = null;
	Slot slot = (Slot)this.inventorySlots.get(slotID);
	if (slot != null && slot.getHasStack())
	{
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();
		if (slotID < NumVars.CMFTEslotsCount)
		{
			if (!this.mergeItemStack(itemstack1, NumVars.CMFTEslotsCount, this.inventorySlots.size(), true))
				return null;
		}
		else
		{
			if (itemstack1.getItem() instanceof AnimusSpall)
			{
				if (!this.mergeItemStack(itemstack1, 0, NumVars.CMFTEslotsCount, false))
					return null;
			}
			else
				return null;
		}
		if (itemstack1.stackSize == 0)
			slot.putStack((ItemStack)null);
		else
			slot.onSlotChanged();
	}
	return itemstack;
}

 

  • 10 months later...

Did you ever figure this out?

I am trying to do the same thing with Forge Gradle in 1.7.2

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.