Minecraft imports should only be in minecraft task implementations

This commit is contained in:
Brady
2018-10-30 20:05:35 -05:00
parent 91c6baead1
commit f76736a378
2 changed files with 17 additions and 7 deletions

View File

@@ -40,7 +40,7 @@ public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider,
allocation = null;
HashMap<IQuantizedChildTaskRelationship, Integer> tmp = new HashMap<>();
int amountToAllocate = getCurrentQuantityInInventory();
int[] newAmounts = ScarceParentPriorityAllocator.priorityAllocation(amountToAllocate, parents).getSecond();
int[] newAmounts = ScarceParentPriorityAllocator.priorityAllocation(amountToAllocate, parents).parentAllocationQuantity;
for (int i = 0; i < parents.size(); i++) {
tmp.put(parents.get(i), newAmounts[i]);
}
@@ -53,7 +53,7 @@ public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider,
@Override
public IQuantityRelationship priority() { // TODO cache
return x -> ScarceParentPriorityAllocator.priorityAllocation(x, parentTasks()).getFirst();
return x -> ScarceParentPriorityAllocator.priorityAllocation(x, parentTasks()).totalPriority;
}
@Override

View File

@@ -17,14 +17,13 @@
package tenor;
import net.minecraft.util.Tuple;
import java.util.List;
public class ScarceParentPriorityAllocator {
public static Tuple<Double, int[]> priorityAllocation(int quantity, List<IQuantizedChildTaskRelationship> parents) {
public static PriorityAllocation priorityAllocation(int quantity, List<IQuantizedChildTaskRelationship> parents) {
if (quantity == 0) {
return new Tuple<>(0D, new int[parents.size()]);
return new PriorityAllocation(new int[parents.size()], 0D);
}
double[][] priorities = new double[parents.size()][quantity];
for (int i = 0; i < parents.size(); i++) {
@@ -53,7 +52,7 @@ public class ScarceParentPriorityAllocator {
}
if (bestParent == -1 || bestRatio == 0) {
return new Tuple<>(totalPriority, taken);
return new PriorityAllocation(taken, totalPriority);
}
taken[bestParent] += bestQuantity;
filled += bestQuantity;
@@ -67,4 +66,15 @@ public class ScarceParentPriorityAllocator {
priorities[bestParent] = repl;
}
}
public static class PriorityAllocation {
public final int[] parentAllocationQuantity;
public final double totalPriority;
public PriorityAllocation(int[] parentAllocationQuantity, double totalPriority) {
this.parentAllocationQuantity = parentAllocationQuantity;
this.totalPriority = totalPriority;
}
}
}