Skip to content

Commit

Permalink
Fix minor slot merge/update regressions (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotMyWing authored Jan 16, 2024
1 parent 10f47a5 commit 7a6d494
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main/java/appeng/container/AEBaseContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -964,26 +964,34 @@ public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, @Not
if (!draggedStack.isEmpty()) {
if (appEngSlot.isItemValid(draggedStack)) {
if (slotStack.getItem() == draggedStack.getItem() && slotStack.getMetadata() == draggedStack.getMetadata() && ItemStack.areItemStackTagsEqual(slotStack, draggedStack)) {
var maxSize = Math.max(appEngSlot.getSlotStackLimit(), draggedStack.getMaxStackSize());
var maxInsertable = Math.min(draggedStack.getCount(), maxSize - appEngSlot.getStack().getCount());
var toInsert = Math.min(maxInsertable, dragType == 0 ? maxInsertable : 1);
// Slot size or stack size, whichever is smaller.
var maxSize = Math.min(appEngSlot.getSlotStackLimit(), draggedStack.getMaxStackSize());

draggedStack.shrink(toInsert);
slotStack.grow(toInsert);
// The maximum number of items that can be inserted into the slot, non-negative.
var maxInsertable = Math.min(draggedStack.getCount(),
Math.max(0, maxSize - appEngSlot.getStack().getCount()));

slot.onSlotChanged();
return ItemStack.EMPTY;
if (maxInsertable != 0) {
var toInsert = Math.min(maxInsertable, dragType == 0 ? maxInsertable : 1);

draggedStack.shrink(toInsert);
slotStack.grow(toInsert);

slot.putStack(slot.getStack());
return ItemStack.EMPTY;
}
}
}
}
// Fixes taking and halving issues from oversized slots.
else if (dragType == 0 || dragType == 1) {
if (slot.canTakeStack(player) && !slotStack.isEmpty()) {
var result = slotStack.copy();
var toTake = Math.min(slotStack.getCount(), slotStack.getMaxStackSize());
this.invPlayer.setItemStack(slot.decrStackSize(dragType == 0 ? toTake : (toTake + 1) / 2));

slot.onTake(player, invPlayer.getItemStack());
return ItemStack.EMPTY;
slot.putStack(slot.getStack());
return result;
}
}

Expand Down

0 comments on commit 7a6d494

Please sign in to comment.