Skip to content

Commit

Permalink
Fixed dupe bug.
Browse files Browse the repository at this point in the history
Closes #29.
Closes #30.
  • Loading branch information
Flanks255 committed Aug 4, 2024
1 parent 8647e56 commit f3c39c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx6G
org.gradle.daemon=false
mod_version=1.2.0
mod_version=1.2.1
minecraft_version=1.21
neo_version=21.0.146
neogradle.subsystems.parchment.minecraftVersion=1.21
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/flanks255/psu/gui/PSUContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ public boolean stillValid(Player playerIn) {
return true;
}

@Nonnull
@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
Slot slot = this.slots.get(index);

if (slot != null && slot.hasItem()) {
return handler.insertItemSlotless(slot.getItem(), true, true);
ItemStack remainder = handler.insertItemSlotless(slot.getItem(), true, true);
if (!remainder.isEmpty())
slot.set(remainder);
else
slot.set(ItemStack.EMPTY);
}
return ItemStack.EMPTY;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/flanks255/psu/inventory/PSUItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public List<PSUSlot> getMatchingSlots(@Nonnull ItemStack stack) {
return slots.stream().filter(s -> ItemStack.isSameItemSameComponents(s.getStack(), stack)).toList();
}

// Inserts an item into the first slot that matches the item.
// Returns the remainder of the stack if it could not be fully inserted.
public ItemStack insertItemSlotless(@Nonnull ItemStack stack, boolean allowEmpty, boolean allowVoid) {
if (stack.isEmpty() || !isItemValid(0, stack))
return ItemStack.EMPTY;
Expand Down Expand Up @@ -113,9 +115,7 @@ public ItemStack insertItemSlotless(@Nonnull ItemStack stack, boolean allowEmpty
if (slots.get(n).isEmpty()) {
slots.set(n, new PSUSlot(stack));
onContentsChanged();
ItemStack tmpstack = stack.copy();
stack.setCount(0);
return tmpstack;
return ItemStack.EMPTY;
}
}
}
Expand Down

0 comments on commit f3c39c8

Please sign in to comment.