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 { 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,10 +22,11 @@ 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) {
if (!this.depthCheck) {
quantity = -add(stack, quantity, baseStack); quantity = -add(stack, quantity, baseStack);
if (quantity > 0 && !get(stack).cantCraft()) { if (quantity > 0 && !get(stack).cantCraft()) {
@@ -37,9 +37,7 @@ public class CraftingPreviewData {
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); get(stack).addExtras(quantityPerRequest);
@@ -54,6 +52,7 @@ public class CraftingPreviewData {
} }
} }
} }
}
public int add(ItemStack stack, int quantity, boolean baseStack) { public int add(ItemStack stack, int quantity, boolean baseStack) {
int hash = NetworkUtils.getItemStackHashCode(stack); int hash = NetworkUtils.getItemStackHashCode(stack);