some performance enhancement to loop checks in the preview

This commit is contained in:
way2muchnoise
2016-09-25 17:27:03 +02:00
parent 67075b38e0
commit e016683c19

View File

@@ -15,7 +15,6 @@ import java.util.HashMap;
public class CraftingPreviewData {
private HashMap<Integer, CraftingPreviewStack> data = new HashMap<>();
private INetworkMaster network;
private int depth = 0;
private boolean depthCheck = false;
public CraftingPreviewData(INetworkMaster network) {
@@ -23,10 +22,11 @@ public class CraftingPreviewData {
}
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) {
if (!this.depthCheck) {
quantity = -add(stack, quantity, baseStack);
if (quantity > 0 && !get(stack).cantCraft()) {
@@ -37,9 +37,7 @@ public class CraftingPreviewData {
while (quantity > 0) {
for (ItemStack ingredient : pattern.getInputs()) {
depth++;
calculate(ingredient, ingredient.stackSize, false);
depth--;
calculate(ingredient, ingredient.stackSize, false, depth + 1);
}
get(stack).addExtras(quantityPerRequest);
@@ -54,6 +52,7 @@ public class CraftingPreviewData {
}
}
}
}
public int add(ItemStack stack, int quantity, boolean baseStack) {
int hash = NetworkUtils.getItemStackHashCode(stack);