Skip to content

Commit

Permalink
fix item duplication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Leclowndu93150 committed Jan 18, 2025
1 parent 88e80df commit 697bd40
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod_name=Stick It!
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.0.0
mod_version=1.0.1
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,38 @@ public BoxCollection getContentsBoxes() {
* @return the remaining items if successful, or the original stack if not
*/
public ItemStack insertStack(ItemStack stack, int renderType) {
ItemUtils.InsertStackResult result = ItemUtils.insertStackAdv(this, stack);
if (result.remainder != stack) {
for (int slot : result.slots) {
contentsMeta[slot] = contentsMeta[slot].withRenderType(renderType);
if (stack.isEmpty()) return stack;

ItemStack remainder = stack.copy();
int slotsAvailable = 0;

for (int i = 0; i < getContainerSize(); i++) {
if (contents.get(i).isEmpty()) slotsAvailable++;
}

if (slotsAvailable == 0) return stack;

int totalItems = remainder.getCount();
int itemsPerSlot = (int) Math.ceil((double) totalItems / slotsAvailable);

for (int i = 0; i < getContainerSize() && !remainder.isEmpty(); i++) {
if (contents.get(i).isEmpty()) {
ItemStack toInsert = remainder.copy();
int insertAmount = Math.min(itemsPerSlot, remainder.getCount());
toInsert.setCount(insertAmount);
contents.set(i, toInsert);
contentsMeta[i] = contentsMeta[i].withRenderType(renderType);
remainder.shrink(insertAmount);
}
}
return result.remainder;

if (!remainder.isEmpty()) {
return remainder;
}

needsCleaning = true;
this.setChanged();
return ItemStack.EMPTY;
}

public static final class ItemMeta {
Expand Down

0 comments on commit 697bd40

Please sign in to comment.