improves preview when there is loops in the crafting task
This commit is contained in:
@@ -2,16 +2,21 @@ package refinedstorage.apiimpl.autocrafting.preview;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.network.NetworkUtils;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
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) {
|
||||
this.network = network;
|
||||
@@ -24,15 +29,17 @@ public class CraftingPreviewData {
|
||||
private void calculate(ItemStack stack, int quantity, boolean baseStack) {
|
||||
quantity = -add(stack, quantity, baseStack);
|
||||
|
||||
if (quantity > 0) {
|
||||
if (quantity > 0 && !get(stack).cantCraft()) {
|
||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
|
||||
|
||||
if (pattern != null) {
|
||||
if (pattern != null && depth < CraftingTask.MAX_DEPTH) {
|
||||
int quantityPerRequest = pattern.getQuantityPerRequest(stack);
|
||||
|
||||
while (quantity > 0) {
|
||||
for (ItemStack ingredient : pattern.getInputs()) {
|
||||
depth++;
|
||||
calculate(ingredient, ingredient.stackSize, false);
|
||||
depth--;
|
||||
}
|
||||
|
||||
get(stack).addExtras(quantityPerRequest);
|
||||
@@ -40,6 +47,9 @@ public class CraftingPreviewData {
|
||||
quantity -= quantityPerRequest;
|
||||
}
|
||||
} else {
|
||||
if (depth >= CraftingTask.MAX_DEPTH) {
|
||||
this.depthCheck = true;
|
||||
}
|
||||
get(stack).setCantCraft(true);
|
||||
}
|
||||
}
|
||||
@@ -68,6 +78,6 @@ public class CraftingPreviewData {
|
||||
}
|
||||
|
||||
public Collection<CraftingPreviewStack> values() {
|
||||
return this.data.values();
|
||||
return this.depthCheck ? Collections.emptyList() : this.data.values();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
cancelButton = addButton(x + 16, y + 144, 50, 20, t("gui.cancel"));
|
||||
startButton = addButton(x + 85, y + 144, 50, 20, t("misc.refinedstorage:start"));
|
||||
|
||||
startButton.enabled = stacks.stream().filter(CraftingPreviewStack::cantCraft).count() == 0;
|
||||
startButton.enabled = !stacks.isEmpty() && stacks.stream().filter(CraftingPreviewStack::cantCraft).count() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,6 +68,10 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
|
||||
drawTexture(x, y, 0, 0, width, height);
|
||||
|
||||
if (stacks.isEmpty()) {
|
||||
drawRect(x + 7, y + 20, x + 142, y + 139, 0xFFDBDBDB);
|
||||
}
|
||||
else {
|
||||
x += 7;
|
||||
y += 20;
|
||||
|
||||
@@ -92,6 +96,7 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
@@ -99,6 +104,17 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
|
||||
int x = 12;
|
||||
int y = 22;
|
||||
float scale = 0.5f;
|
||||
|
||||
if (stacks.isEmpty()) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
drawString(calculateOffsetOnScale(x + 34, scale), calculateOffsetOnScale(y + 50, scale), t("gui.refinedstorage:crafting_preview.circular"));
|
||||
drawString(calculateOffsetOnScale(x + 35, scale), calculateOffsetOnScale(y + 57, scale), t("gui.refinedstorage:crafting_preview.loop"));
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
} else {
|
||||
|
||||
int slot = scrollbar.getOffset() * 2;
|
||||
|
||||
@@ -112,8 +128,6 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
|
||||
drawItem(x, y + 5, stack.getStack());
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
@@ -151,6 +165,7 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
drawTooltip(mouseX, mouseY, hoveringStack.getTooltip(Minecraft.getMinecraft().thePlayer, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char character, int keyCode) throws IOException {
|
||||
|
||||
@@ -45,6 +45,8 @@ gui.refinedstorage:crafting_preview=Crafting Preview
|
||||
gui.refinedstorage:crafting_preview.to_craft=To craft: %d
|
||||
gui.refinedstorage:crafting_preview.available=Available: %d
|
||||
gui.refinedstorage:crafting_preview.missing=Missing: %d
|
||||
gui.refinedstorage:crafting_preview.circular=Circular dependency!
|
||||
gui.refinedstorage:crafting_preview.loop=loop in processing...
|
||||
|
||||
misc.refinedstorage:energy_stored=%d / %d RS
|
||||
misc.refinedstorage:energy_usage=Usage: %d RS/t
|
||||
|
||||
Reference in New Issue
Block a user