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,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);
|
||||||
|
|||||||
Reference in New Issue
Block a user