diff --git a/src/main/java/crazypants/enderio/machine/gui/AbstractMachineContainer.java b/src/main/java/crazypants/enderio/machine/gui/AbstractMachineContainer.java index 5c38259f..9726fbb1 100644 --- a/src/main/java/crazypants/enderio/machine/gui/AbstractMachineContainer.java +++ b/src/main/java/crazypants/enderio/machine/gui/AbstractMachineContainer.java @@ -158,39 +158,47 @@ public abstract class AbstractMachineContainer extends Container { return new SlotRange(startHotBarSlot, endHotBarSlot, false); } + protected void addInventorySlotRange(List res, int start, int end) { + for (int i = start; i < end; i++) { + int slotNumber = getSlotFromInventory(tileEntity, i).slotNumber; + res.add(new SlotRange(slotNumber, slotNumber + 1, false)); + } + } + protected void addInputSlotRanges(List res) { SlotDefinition slotDef = tileEntity.getSlotDefinition(); if(slotDef.getNumInputSlots() > 0) { - res.add(new SlotRange(slotDef.getMinInputSlot(), slotDef.getMaxInputSlot() + 1, false)); + addInventorySlotRange(res, slotDef.getMinInputSlot(), slotDef.getMaxInputSlot() + 1); } } protected void addUpgradeSlotRanges(List res) { SlotDefinition slotDef = tileEntity.getSlotDefinition(); if(slotDef.getNumUpgradeSlots() > 0) { - res.add(new SlotRange(slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1, false)); + addInventorySlotRange(res, slotDef.getMinUpgradeSlot(), slotDef.getMaxUpgradeSlot() + 1); } } protected void addPlayerSlotRanges(List res, int slotIndex) { - if(slotIndex <= endPlayerSlot) { + if (slotIndex < endPlayerSlot) { res.add(getPlayerHotbarSlotRange()); } - if(slotIndex >= startHotBarSlot && slotIndex <= endHotBarSlot) { + if (slotIndex >= startHotBarSlot && slotIndex < endHotBarSlot) { res.add(getPlayerInventoryWithoutHotbarSlotRange()); } } protected List getTargetSlotsForTransfer(int slotIndex, Slot slot) { - SlotDefinition slotDef = tileEntity.getSlotDefinition(); - if(slotDef.isInputSlot(slotIndex) || slotDef.isUpgradeSlot(slotIndex)) { - return Collections.singletonList(getPlayerInventorySlotRange(false)); - } - if(slotDef.isOutputSlot(slotIndex)) { - return Collections.singletonList(getPlayerInventorySlotRange(true)); - } - if(slotIndex >= startPlayerSlot) { - ArrayList res = new ArrayList(); + if (slot.inventory == tileEntity) { + SlotDefinition slotDef = tileEntity.getSlotDefinition(); + if (slotDef.isInputSlot(slot.slotNumber) || slotDef.isUpgradeSlot(slot.slotNumber)) { + return Collections.singletonList(getPlayerInventorySlotRange(false)); + } + if (slotDef.isOutputSlot(slot.slotNumber)) { + return Collections.singletonList(getPlayerInventorySlotRange(true)); + } + } else if (slotIndex >= startPlayerSlot) { + List res = new ArrayList(); addInputSlotRanges(res); addUpgradeSlotRanges(res); addPlayerSlotRanges(res, slotIndex); @@ -221,10 +229,10 @@ public abstract class AbstractMachineContainer extends Container { slot = (Slot) this.inventorySlots.get(checkIndex); itemstack1 = slot.getStack(); - if(itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() + if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) - && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1) - && slot.isItemValid(par1ItemStack)) { + && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1) && slot.isItemValid(par1ItemStack) + && par1ItemStack != itemstack1) { int mergedSize = itemstack1.stackSize + par1ItemStack.stackSize; int maxStackSize = Math.min(par1ItemStack.getMaxStackSize(), slot.getSlotStackLimit());