diff --git a/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java b/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java index 748a3ef73..db9f007c5 100644 --- a/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java +++ b/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java @@ -211,38 +211,42 @@ public class TileRollingMachine extends TilePowerAcceptor } } - int totalItems = possibleSlots.stream() - .mapToInt(value -> inventory.getStackInSlot(value).getCount()).sum(); - int slots = possibleSlots.size(); + if(!possibleSlots.isEmpty()){ + int totalItems = possibleSlots.stream() + .mapToInt(value -> inventory.getStackInSlot(value).getCount()).sum(); + int slots = possibleSlots.size(); - //This makes an array of ints with the best possible slot distribution - int[] split = new int[slots]; - int remainder = totalItems % slots; - Arrays.fill(split, totalItems / slots); - while (remainder > 0){ - for (int i = 0; i < split.length; i++) { - if(remainder > 0){ - split[i] +=1; - remainder --; + //This makes an array of ints with the best possible slot distribution + int[] split = new int[slots]; + int remainder = totalItems % slots; + Arrays.fill(split, totalItems / slots); + while (remainder > 0){ + for (int i = 0; i < split.length; i++) { + if(remainder > 0){ + split[i] +=1; + remainder --; + } } } - } - List slotDistrubution = possibleSlots.stream() - .mapToInt(value -> inventory.getStackInSlot(value).getCount()) - .boxed().collect(Collectors.toList()); + List slotDistrubution = possibleSlots.stream() + .mapToInt(value -> inventory.getStackInSlot(value).getCount()) + .boxed().collect(Collectors.toList()); - boolean needsBalance = false; - for (int i = 0; i < split.length; i++) { - int required = split[i]; - if(slotDistrubution.contains(required)){ - //We need to remove the int, not at the int, this seems to work around that - slotDistrubution.remove(new Integer(required)); - } else { - needsBalance = true; + boolean needsBalance = false; + for (int i = 0; i < split.length; i++) { + int required = split[i]; + if(slotDistrubution.contains(required)){ + //We need to remove the int, not at the int, this seems to work around that + slotDistrubution.remove(new Integer(required)); + } else { + needsBalance = true; + } } - } - if (!needsBalance) { + if (!needsBalance) { + return Optional.empty(); + } + } else { return Optional.empty(); }