mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Fix #893 Shift-Removing items from a machine prefers the hotbar
This commit is contained in:
1 parent
614c13b4f3
commit
099e6f47e8
1 file changed
+60
-36
@@ -104,11 +104,7 @@ public abstract class SlotUtil {
|
||||
return shiftToHotbar(inventorySlots, stackInSlot);
|
||||
}
|
||||
} else {
|
||||
boolean shifted = shiftToHotbar(inventorySlots, stackInSlot);
|
||||
if (!shifted) {
|
||||
shifted = shiftToPlayerInventoryNoHotbar(inventorySlots, stackInSlot);
|
||||
}
|
||||
return shifted;
|
||||
return shiftToPlayerInventory(inventorySlots, stackInSlot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,38 +154,31 @@ public abstract class SlotUtil {
|
||||
}
|
||||
|
||||
private static boolean shiftItemStackToRange(List inventorySlots, ItemStack stackToShift, int start, int count) {
|
||||
boolean changed = false;
|
||||
if (stackToShift.isStackable()) {
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot != null && ItemStackUtil.isIdenticalItem(stackInSlot, stackToShift)) {
|
||||
int resultingStackSize = stackInSlot.stackSize + stackToShift.stackSize;
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (resultingStackSize <= max) {
|
||||
stackToShift.stackSize = 0;
|
||||
stackInSlot.stackSize = resultingStackSize;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
} else if (stackInSlot.stackSize < max) {
|
||||
stackToShift.stackSize -= max - stackInSlot.stackSize;
|
||||
stackInSlot.stackSize = max;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean changed = shiftItemStackToRangeMerge(inventorySlots, stackToShift, start, count);
|
||||
changed |= shiftItemStackToRangeOpenSlots(inventorySlots, stackToShift, start, count);
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static boolean shiftItemStackToRangeMerge(List inventorySlots, ItemStack stackToShift, int start, int count) {
|
||||
if (stackToShift == null || !stackToShift.isStackable() || stackToShift.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (stackToShift.stackSize > 0) {
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot == null) {
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
stackInSlot = stackToShift.copy();
|
||||
stackInSlot.stackSize = Math.min(stackToShift.stackSize, max);
|
||||
stackToShift.stackSize -= stackInSlot.stackSize;
|
||||
slot.putStack(stackInSlot);
|
||||
|
||||
boolean changed = false;
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot != null && ItemStackUtil.isIdenticalItem(stackInSlot, stackToShift)) {
|
||||
int resultingStackSize = stackInSlot.stackSize + stackToShift.stackSize;
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (resultingStackSize <= max) {
|
||||
stackToShift.stackSize = 0;
|
||||
stackInSlot.stackSize = resultingStackSize;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
} else if (stackInSlot.stackSize < max) {
|
||||
stackToShift.stackSize -= max - stackInSlot.stackSize;
|
||||
stackInSlot.stackSize = max;
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
}
|
||||
@@ -198,6 +187,28 @@ public abstract class SlotUtil {
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static boolean shiftItemStackToRangeOpenSlots(List inventorySlots, ItemStack stackToShift, int start, int count) {
|
||||
if (stackToShift == null || stackToShift.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < start + count; slotIndex++) {
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
if (stackInSlot == null) {
|
||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
stackInSlot = stackToShift.copy();
|
||||
stackInSlot.stackSize = Math.min(stackToShift.stackSize, max);
|
||||
stackToShift.stackSize -= stackInSlot.stackSize;
|
||||
slot.putStack(stackInSlot);
|
||||
slot.onSlotChanged();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static final int playerInventorySize = 9 * 4;
|
||||
private static final int playerHotbarSize = 9;
|
||||
|
||||
@@ -209,6 +220,19 @@ public abstract class SlotUtil {
|
||||
return SlotUtil.isSlotInRange(slotIndex, playerInventorySize - playerHotbarSize, playerInventorySize);
|
||||
}
|
||||
|
||||
private static boolean shiftToPlayerInventory(List inventorySlots, ItemStack stackInSlot) {
|
||||
int playerHotbarStart = playerInventorySize - playerHotbarSize;
|
||||
|
||||
// try to merge with existing stacks, hotbar first
|
||||
boolean shifted = shiftItemStackToRangeMerge(inventorySlots, stackInSlot, playerHotbarStart, playerHotbarSize);
|
||||
shifted |= shiftItemStackToRangeMerge(inventorySlots, stackInSlot, 0, playerHotbarStart);
|
||||
|
||||
// shift to open slots, hotbar first
|
||||
shifted |= shiftItemStackToRangeOpenSlots(inventorySlots, stackInSlot, playerHotbarStart, playerHotbarSize);
|
||||
shifted |= shiftItemStackToRangeOpenSlots(inventorySlots, stackInSlot, 0, playerHotbarStart);
|
||||
return shifted;
|
||||
}
|
||||
|
||||
private static boolean shiftToPlayerInventoryNoHotbar(List inventorySlots, ItemStack stackInSlot) {
|
||||
int playerHotbarStart = playerInventorySize - playerHotbarSize;
|
||||
return shiftItemStackToRange(inventorySlots, stackInSlot, 0, playerHotbarStart);
|
||||
|
||||
Reference in new issue
Block a user