diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemCollector.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemCollector.java index c39494e8..8ad85ca7 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemCollector.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemCollector.java @@ -73,7 +73,7 @@ public class ItemCollector { items.addTo(def, stack.getCount()); } }); - iterator.afterPopulate(count.get()); + iterator.afterPopulate(container, count.get()); if (mergedResult != null && !iterator.isFinished()) { updateCollectingProgress(mergedResult.getFirst()); return mergedResult; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemIterator.java b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemIterator.java index 4d65e9a8..08ebca52 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemIterator.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/protocol/jade/util/ItemIterator.java @@ -15,6 +15,7 @@ public abstract class ItemIterator { protected final int fromIndex; protected boolean finished; protected int currentIndex; + protected float progress; protected ItemIterator(Function containerFinder, int fromIndex) { this.containerFinder = containerFinder; @@ -35,16 +36,19 @@ public abstract class ItemIterator { public abstract Stream populate(T container); + protected abstract int getSlotCount(T container); + public void reset() { currentIndex = fromIndex; finished = false; } - public void afterPopulate(int count) { + public void afterPopulate(T container, int count) { currentIndex += count; if (count == 0 || currentIndex >= 10000) { finished = true; } + progress = (float) (currentIndex - fromIndex) / (getSlotCount(container) - fromIndex); } public float getCollectingProgress() { @@ -52,14 +56,11 @@ public abstract class ItemIterator { } public static abstract class SlottedItemIterator extends ItemIterator { - protected float progress; public SlottedItemIterator(Function containerFinder, int fromIndex) { super(containerFinder, fromIndex); } - protected abstract int getSlotCount(T container); - protected abstract ItemStack getItemInSlot(T container, int slot); @Override @@ -70,7 +71,6 @@ public abstract class ItemIterator { toIndex = slotCount; finished = true; } - progress = (float) (currentIndex - fromIndex) / (slotCount - fromIndex); return IntStream.range(currentIndex, toIndex).mapToObj(slot -> getItemInSlot(container, slot)); }