diff --git a/core/src/mindustry/world/modules/ItemModule.java b/core/src/mindustry/world/modules/ItemModule.java index 8fc338dcbd..cd30730d2d 100644 --- a/core/src/mindustry/world/modules/ItemModule.java +++ b/core/src/mindustry/world/modules/ItemModule.java @@ -12,6 +12,9 @@ public class ItemModule extends BlockModule{ private int[] items = new int[content.items().size]; private int total; + // Make the take() loop persistent so it does not return the same item twice in a row unless there is nothing else to return. + protected int takeRotation; + public void forEach(ItemConsumer cons){ for(int i = 0; i < items.length; i++){ if(items[i] > 0){ @@ -68,10 +71,13 @@ public class ItemModule extends BlockModule{ public Item take(){ for(int i = 0; i < items.length; i++){ - if(items[i] > 0){ - items[i]--; - total--; - return content.item(i); + int index = (i + takeRotation); + if(index >= items.length) index -= items.length; //conditional instead of mod + if(items[index] > 0){ + items[index] --; + total --; + takeRotation = index + 1; + return content.item(index % items.length); } } return null;