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 net.minecraft.item.ItemStack;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
|
import refinedstorage.api.autocrafting.task.CraftingTask;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
import refinedstorage.api.network.NetworkUtils;
|
import refinedstorage.api.network.NetworkUtils;
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
|
import refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
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;
|
||||||
|
|
||||||
public CraftingPreviewData(INetworkMaster network) {
|
public CraftingPreviewData(INetworkMaster network) {
|
||||||
this.network = network;
|
this.network = network;
|
||||||
@@ -24,15 +29,17 @@ public class CraftingPreviewData {
|
|||||||
private void calculate(ItemStack stack, int quantity, boolean baseStack) {
|
private void calculate(ItemStack stack, int quantity, boolean baseStack) {
|
||||||
quantity = -add(stack, quantity, baseStack);
|
quantity = -add(stack, quantity, baseStack);
|
||||||
|
|
||||||
if (quantity > 0) {
|
if (quantity > 0 && !get(stack).cantCraft()) {
|
||||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
|
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
|
||||||
|
|
||||||
if (pattern != null) {
|
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);
|
calculate(ingredient, ingredient.stackSize, false);
|
||||||
|
depth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
get(stack).addExtras(quantityPerRequest);
|
get(stack).addExtras(quantityPerRequest);
|
||||||
@@ -40,6 +47,9 @@ public class CraftingPreviewData {
|
|||||||
quantity -= quantityPerRequest;
|
quantity -= quantityPerRequest;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (depth >= CraftingTask.MAX_DEPTH) {
|
||||||
|
this.depthCheck = true;
|
||||||
|
}
|
||||||
get(stack).setCantCraft(true);
|
get(stack).setCantCraft(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,6 +78,6 @@ public class CraftingPreviewData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<CraftingPreviewStack> values() {
|
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"));
|
cancelButton = addButton(x + 16, y + 144, 50, 20, t("gui.cancel"));
|
||||||
startButton = addButton(x + 85, y + 144, 50, 20, t("misc.refinedstorage:start"));
|
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
|
@Override
|
||||||
@@ -68,28 +68,33 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
|
|
||||||
drawTexture(x, y, 0, 0, width, height);
|
drawTexture(x, y, 0, 0, width, height);
|
||||||
|
|
||||||
x += 7;
|
if (stacks.isEmpty()) {
|
||||||
y += 20;
|
drawRect(x + 7, y + 20, x + 142, y + 139, 0xFFDBDBDB);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x += 7;
|
||||||
|
y += 20;
|
||||||
|
|
||||||
int slot = scrollbar.getOffset() * 2;
|
int slot = scrollbar.getOffset() * 2;
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
if (slot < stacks.size()) {
|
if (slot < stacks.size()) {
|
||||||
CraftingPreviewStack stack = stacks.get(slot);
|
CraftingPreviewStack stack = stacks.get(slot);
|
||||||
|
|
||||||
if (stack.cantCraft()) {
|
if (stack.cantCraft()) {
|
||||||
drawTexture(x, y, 189, 0, 67, 29);
|
drawTexture(x, y, 189, 0, 67, 29);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (i % 2 == 1) {
|
if (i % 2 == 1) {
|
||||||
x -= 68;
|
x -= 68;
|
||||||
y += 30;
|
y += 30;
|
||||||
} else {
|
} else {
|
||||||
x += 68;
|
x += 68;
|
||||||
}
|
}
|
||||||
|
|
||||||
slot++;
|
slot++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,56 +104,66 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
|
|
||||||
int x = 12;
|
int x = 12;
|
||||||
int y = 22;
|
int y = 22;
|
||||||
|
float scale = 0.5f;
|
||||||
|
|
||||||
int slot = scrollbar.getOffset() * 2;
|
if (stacks.isEmpty()) {
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.scale(scale, scale, 1);
|
||||||
|
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
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"));
|
||||||
|
|
||||||
ItemStack hoveringStack = null;
|
GlStateManager.popMatrix();
|
||||||
|
} else {
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i) {
|
int slot = scrollbar.getOffset() * 2;
|
||||||
if (slot < stacks.size()) {
|
|
||||||
CraftingPreviewStack stack = stacks.get(slot);
|
|
||||||
|
|
||||||
drawItem(x, y + 5, stack.getStack());
|
RenderHelper.enableGUIStandardItemLighting();
|
||||||
|
|
||||||
float scale = 0.5f;
|
ItemStack hoveringStack = null;
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
for (int i = 0; i < 8; ++i) {
|
||||||
GlStateManager.scale(scale, scale, 1);
|
if (slot < stacks.size()) {
|
||||||
|
CraftingPreviewStack stack = stacks.get(slot);
|
||||||
|
|
||||||
int yy = y + 8;
|
drawItem(x, y + 5, stack.getStack());
|
||||||
|
|
||||||
if (stack.needsCrafting()) {
|
GlStateManager.pushMatrix();
|
||||||
String format = stack.cantCraft() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
|
GlStateManager.scale(scale, scale, 1);
|
||||||
drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t(format, stack.getToCraft()));
|
|
||||||
|
|
||||||
yy += 7;
|
int yy = y + 8;
|
||||||
|
|
||||||
|
if (stack.needsCrafting()) {
|
||||||
|
String format = stack.cantCraft() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
|
||||||
|
drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t(format, stack.getToCraft()));
|
||||||
|
|
||||||
|
yy += 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.getStock() > 0) {
|
||||||
|
drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t("gui.refinedstorage:crafting_preview.available", stack.getStock()));
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
|
||||||
|
if (inBounds(x, y, 16, 16, mouseX, mouseY)) {
|
||||||
|
hoveringStack = stack.getStack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getStock() > 0) {
|
if (i % 2 == 1) {
|
||||||
drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t("gui.refinedstorage:crafting_preview.available", stack.getStock()));
|
x -= 68;
|
||||||
|
y += 30;
|
||||||
|
} else {
|
||||||
|
x += 68;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
slot++;
|
||||||
|
|
||||||
if (inBounds(x, y, 16, 16, mouseX, mouseY)) {
|
|
||||||
hoveringStack = stack.getStack();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i % 2 == 1) {
|
if (hoveringStack != null) {
|
||||||
x -= 68;
|
drawTooltip(mouseX, mouseY, hoveringStack.getTooltip(Minecraft.getMinecraft().thePlayer, false));
|
||||||
y += 30;
|
|
||||||
} else {
|
|
||||||
x += 68;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
slot++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hoveringStack != null) {
|
|
||||||
drawTooltip(mouseX, mouseY, hoveringStack.getTooltip(Minecraft.getMinecraft().thePlayer, false));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ gui.refinedstorage:crafting_preview=Crafting Preview
|
|||||||
gui.refinedstorage:crafting_preview.to_craft=To craft: %d
|
gui.refinedstorage:crafting_preview.to_craft=To craft: %d
|
||||||
gui.refinedstorage:crafting_preview.available=Available: %d
|
gui.refinedstorage:crafting_preview.available=Available: %d
|
||||||
gui.refinedstorage:crafting_preview.missing=Missing: %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_stored=%d / %d RS
|
||||||
misc.refinedstorage:energy_usage=Usage: %d RS/t
|
misc.refinedstorage:energy_usage=Usage: %d RS/t
|
||||||
|
|||||||
Reference in New Issue
Block a user