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
+2 -2
View File
@@ -40,7 +40,7 @@ public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider,
allocation = null; allocation = null;
HashMap<IQuantizedChildTaskRelationship, Integer> tmp = new HashMap<>(); HashMap<IQuantizedChildTaskRelationship, Integer> tmp = new HashMap<>();
int amountToAllocate = getCurrentQuantityInInventory(); 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++) { for (int i = 0; i < parents.size(); i++) {
tmp.put(parents.get(i), newAmounts[i]); tmp.put(parents.get(i), newAmounts[i]);
} }
@@ -53,7 +53,7 @@ public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider,
@Override @Override
public IQuantityRelationship priority() { // TODO cache public IQuantityRelationship priority() { // TODO cache
return x -> ScarceParentPriorityAllocator.priorityAllocation(x, parentTasks()).getFirst(); return x -> ScarceParentPriorityAllocator.priorityAllocation(x, parentTasks()).totalPriority;
} }
@Override @Override
@@ -17,14 +17,13 @@
package tenor; package tenor;
import net.minecraft.util.Tuple;
import java.util.List; import java.util.List;
public class ScarceParentPriorityAllocator { 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) { 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]; double[][] priorities = new double[parents.size()][quantity];
for (int i = 0; i < parents.size(); i++) { for (int i = 0; i < parents.size(); i++) {
@@ -53,7 +52,7 @@ public class ScarceParentPriorityAllocator {
} }
if (bestParent == -1 || bestRatio == 0) { if (bestParent == -1 || bestRatio == 0) {
return new Tuple<>(totalPriority, taken); return new PriorityAllocation(taken, totalPriority);
} }
taken[bestParent] += bestQuantity; taken[bestParent] += bestQuantity;
filled += bestQuantity; filled += bestQuantity;
@@ -67,4 +66,15 @@ public class ScarceParentPriorityAllocator {
priorities[bestParent] = repl; 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;
}
}
} }