Should fix #1666
This commit is contained in:
parent
094f2fc050
commit
c4fff1bf56
1 changed files with 30 additions and 26 deletions
|
@ -211,38 +211,42 @@ public class TileRollingMachine extends TilePowerAcceptor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalItems = possibleSlots.stream()
|
if(!possibleSlots.isEmpty()){
|
||||||
.mapToInt(value -> inventory.getStackInSlot(value).getCount()).sum();
|
int totalItems = possibleSlots.stream()
|
||||||
int slots = possibleSlots.size();
|
.mapToInt(value -> inventory.getStackInSlot(value).getCount()).sum();
|
||||||
|
int slots = possibleSlots.size();
|
||||||
|
|
||||||
//This makes an array of ints with the best possible slot distribution
|
//This makes an array of ints with the best possible slot distribution
|
||||||
int[] split = new int[slots];
|
int[] split = new int[slots];
|
||||||
int remainder = totalItems % slots;
|
int remainder = totalItems % slots;
|
||||||
Arrays.fill(split, totalItems / slots);
|
Arrays.fill(split, totalItems / slots);
|
||||||
while (remainder > 0){
|
while (remainder > 0){
|
||||||
for (int i = 0; i < split.length; i++) {
|
for (int i = 0; i < split.length; i++) {
|
||||||
if(remainder > 0){
|
if(remainder > 0){
|
||||||
split[i] +=1;
|
split[i] +=1;
|
||||||
remainder --;
|
remainder --;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
List<Integer> slotDistrubution = possibleSlots.stream()
|
List<Integer> slotDistrubution = possibleSlots.stream()
|
||||||
.mapToInt(value -> inventory.getStackInSlot(value).getCount())
|
.mapToInt(value -> inventory.getStackInSlot(value).getCount())
|
||||||
.boxed().collect(Collectors.toList());
|
.boxed().collect(Collectors.toList());
|
||||||
|
|
||||||
boolean needsBalance = false;
|
boolean needsBalance = false;
|
||||||
for (int i = 0; i < split.length; i++) {
|
for (int i = 0; i < split.length; i++) {
|
||||||
int required = split[i];
|
int required = split[i];
|
||||||
if(slotDistrubution.contains(required)){
|
if(slotDistrubution.contains(required)){
|
||||||
//We need to remove the int, not at the int, this seems to work around that
|
//We need to remove the int, not at the int, this seems to work around that
|
||||||
slotDistrubution.remove(new Integer(required));
|
slotDistrubution.remove(new Integer(required));
|
||||||
} else {
|
} else {
|
||||||
needsBalance = true;
|
needsBalance = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!needsBalance) {
|
||||||
if (!needsBalance) {
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue