src/base/gcewing/sg/BaseContainer.java
// A better version of mergeItemStack that respects Slot.isItemValid() and Slot.getStackLimit().
A better version of mergeItemStack that respects Slot.isItemValid() and Slot.getStackLimit().
A better version of mergeItemStack that respects Slot . isItemValid () and Slot . getStackLimit () .
@Override
    protected boolean mergeItemStack(ItemStack stack, int startSlot, int endSlot, boolean reverse) {
        boolean result = false;
        int n = endSlot - startSlot;
        if (stack.isStackable()) {
            for (int i = 0; i < n && stack.stackSize > 0; i++) {
                int k = reverse ? endSlot - 1 - i : startSlot + i;
                Slot slot = (Slot)this.inventorySlots.get(k);
                ItemStack slotStack = slot.getStack();
                if (slotStack != null
                    && slotStack.isStackable()
                    && slotStack.getItem() == stack.getItem()
                    && (!stack.getHasSubtypes() || stack.getItemDamage() == slotStack.getItemDamage())
                    && ItemStack.areItemStackTagsEqual(stack, slotStack))
                {
                    if (transferToSlot(stack, slot))
                        result = true;
                }
            }
        }
        for (int i = 0; i < n && stack.stackSize > 0; i++) {
            int k = reverse ? endSlot - 1 - i : startSlot + i;
            Slot slot = (Slot)this.inventorySlots.get(k);
            if (!slot.getHasStack() && slot.isItemValid(stack)) {
                ItemStack newStack = stack.copy();
                newStack.stackSize = 0;
                slot.putStack(newStack);
                if (transferToSlot(stack, slot))
                    result = true;
            }
        }
        return result;
    }
@ Override protected boolean mergeItemStack ( ItemStack stack , int startSlot , int endSlot , boolean reverse ) { boolean result = false ; int n = endSlot - startSlot ; if ( stack . isStackable ( ) ) { for ( int i = 0 ; i < n && stack . stackSize > 0 ; i ++ ) { int k = reverse ? endSlot - 1 - i : startSlot + i ; Slot slot = ( Slot ) this . inventorySlots . get ( k ) ; ItemStack slotStack = slot . getStack ( ) ; if ( slotStack != null && slotStack . isStackable ( ) && slotStack . getItem ( ) == stack . getItem ( ) && ( ! stack . getHasSubtypes ( ) || stack . getItemDamage ( ) == slotStack . getItemDamage ( ) ) && ItemStack . areItemStackTagsEqual ( stack , slotStack ) ) { if ( transferToSlot ( stack , slot ) ) result = true ; } } } for ( int i = 0 ; i < n && stack . stackSize > 0 ; i ++ ) { int k = reverse ? endSlot - 1 - i : startSlot + i ; Slot slot = ( Slot ) this . inventorySlots . get ( k ) ; if ( ! slot . getHasStack ( ) && slot . isItemValid ( stack ) ) { ItemStack newStack = stack . copy ( ) ; newStack . stackSize = 0 ; slot . putStack ( newStack ) ; if ( transferToSlot ( stack , slot ) ) result = true ; } } return result ; }
A better version of mergeItemStack that respects Slot.isItemValid() and Slot.getStackLimit().
A better version of mergeItemStack that respects Slot . isItemValid () and Slot . getStackLimit () .