Skip to content

Commit

Permalink
Use slot.getMaxStackSize(stack)
Browse files Browse the repository at this point in the history
Improves compatibility with NetherChested.

See #127
  • Loading branch information
YaLTeR committed May 12, 2024
1 parent d2c46aa commit 4d78297
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/yalter/mousetweaks/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private static void rmbTweakMaybeClickSlot(Slot slot, ItemStack stackOnMouse) {
return;

// Return if we cannot put any more items into the slot.
if (selectedSlotStack.getCount() == selectedSlotStack.getMaxStackSize())
if (selectedSlotStack.getCount() == slot.getMaxStackSize(selectedSlotStack))
return;
}

Expand Down Expand Up @@ -383,7 +383,7 @@ public static boolean onMouseScrolled(Screen screen, double x, double y, double
handler.clickSlot(slot, MouseButton.LEFT, false);
} else {
// Otherwise right click the needed number of times.
int clickTimes = slot.getItem().getMaxStackSize() - slot.getItem().getCount();
int clickTimes = slot.getMaxStackSize(slot.getItem()) - slot.getItem().getCount();
while (clickTimes-- > 0)
handler.clickSlot(slot, MouseButton.RIGHT, false);
}
Expand Down Expand Up @@ -428,7 +428,7 @@ public static boolean onMouseScrolled(Screen screen, double x, double y, double
//
// Can't do the last slot left click optimization, because we usually want to move less items (1) than
// the whole available stack.
int clickTimes = slot.getItem().getMaxStackSize() - slot.getItem().getCount();
int clickTimes = slot.getMaxStackSize(slot.getItem()) - slot.getItem().getCount();
clickTimes = Math.min(clickTimes, numItemsToMove);
numItemsToMove -= clickTimes;

Expand All @@ -446,7 +446,7 @@ public static boolean onMouseScrolled(Screen screen, double x, double y, double

// Handle pulling items.
// Clip the number of items to move by the maximum item count that would fit in the slot.
int maxItemsToMove = selectedSlotStack.getMaxStackSize() - selectedSlotStack.getCount();
int maxItemsToMove = selectedSlot.getMaxStackSize(selectedSlotStack) - selectedSlotStack.getCount();
numItemsToMove = Math.min(numItemsToMove, maxItemsToMove);

while (numItemsToMove > 0) {
Expand Down Expand Up @@ -648,9 +648,9 @@ private static List<Slot> findPushSlots(List<Slot> slots, Slot selectedSlot, int
}
} else {
// Non-empty slots should have a compatible stack, not maxed out.
if (areStacksCompatible(selectedSlotStack, stack) && stack.getCount() < stack.getMaxStackSize()) {
if (areStacksCompatible(selectedSlotStack, stack) && stack.getCount() < slot.getMaxStackSize(stack)) {
rv.add(slot);
itemCount -= Math.min(itemCount, stack.getMaxStackSize() - stack.getCount());
itemCount -= Math.min(itemCount, slot.getMaxStackSize(stack) - stack.getCount());
}
}
}
Expand All @@ -659,7 +659,7 @@ private static List<Slot> findPushSlots(List<Slot> slots, Slot selectedSlot, int
for (int i = 0; i != goodEmptySlots.size() && itemCount > 0; i++) {
Slot slot = goodEmptySlots.get(i);
rv.add(slot);
itemCount -= Math.min(itemCount, slot.getItem().getMaxStackSize() - slot.getItem().getCount());
itemCount -= Math.min(itemCount, slot.getMaxStackSize());
}

// If we were unable to distribute all items as requested, return null.
Expand Down

0 comments on commit 4d78297

Please sign in to comment.