some performance enhancement to loop checks in the preview
This commit is contained in:
@@ -15,7 +15,6 @@ import java.util.HashMap;
|
|||||||
public class CraftingPreviewData {
|
public class CraftingPreviewData {
|
||||||
private HashMap<Integer, CraftingPreviewStack> data = new HashMap<>();
|
private HashMap<Integer, CraftingPreviewStack> data = new HashMap<>();
|
||||||
private INetworkMaster network;
|
private INetworkMaster network;
|
||||||
private int depth = 0;
|
|
||||||
private boolean depthCheck = false;
|
private boolean depthCheck = false;
|
||||||
|
|
||||||
public CraftingPreviewData(INetworkMaster network) {
|
public CraftingPreviewData(INetworkMaster network) {
|
||||||
@@ -23,34 +22,34 @@ public class CraftingPreviewData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void calculate(ItemStack stack, int quantity) {
|
public void calculate(ItemStack stack, int quantity) {
|
||||||
calculate(stack, quantity, true);
|
calculate(stack, quantity, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculate(ItemStack stack, int quantity, boolean baseStack) {
|
private void calculate(ItemStack stack, int quantity, boolean baseStack, int depth) {
|
||||||
quantity = -add(stack, quantity, baseStack);
|
if (!this.depthCheck) {
|
||||||
|
quantity = -add(stack, quantity, baseStack);
|
||||||
|
|
||||||
if (quantity > 0 && !get(stack).cantCraft()) {
|
if (quantity > 0 && !get(stack).cantCraft()) {
|
||||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
|
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
|
||||||
|
|
||||||
if (pattern != null && depth < CraftingTask.MAX_DEPTH) {
|
if (pattern != null && depth < CraftingTask.MAX_DEPTH) {
|
||||||
int quantityPerRequest = pattern.getQuantityPerRequest(stack);
|
int quantityPerRequest = pattern.getQuantityPerRequest(stack);
|
||||||
|
|
||||||
while (quantity > 0) {
|
while (quantity > 0) {
|
||||||
for (ItemStack ingredient : pattern.getInputs()) {
|
for (ItemStack ingredient : pattern.getInputs()) {
|
||||||
depth++;
|
calculate(ingredient, ingredient.stackSize, false, depth + 1);
|
||||||
calculate(ingredient, ingredient.stackSize, false);
|
}
|
||||||
depth--;
|
|
||||||
|
get(stack).addExtras(quantityPerRequest);
|
||||||
|
|
||||||
|
quantity -= quantityPerRequest;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
get(stack).addExtras(quantityPerRequest);
|
if (depth >= CraftingTask.MAX_DEPTH) {
|
||||||
|
this.depthCheck = true;
|
||||||
quantity -= quantityPerRequest;
|
}
|
||||||
|
get(stack).setCantCraft(true);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (depth >= CraftingTask.MAX_DEPTH) {
|
|
||||||
this.depthCheck = true;
|
|
||||||
}
|
|
||||||
get(stack).setCantCraft(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user