Implement more error handling and fix rendering of some stuff.
This commit is contained in:
@@ -61,31 +61,31 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
|
||||
int yy = y + 7;
|
||||
|
||||
if (stored > 0) {
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.stored", stored));
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.stored", API.instance().getQuantityFormatter().formatInBucketForm(stored)));
|
||||
|
||||
yy += 7;
|
||||
}
|
||||
|
||||
if (missing > 0) {
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.missing", missing));
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.missing", API.instance().getQuantityFormatter().formatInBucketForm(missing)));
|
||||
|
||||
yy += 7;
|
||||
}
|
||||
|
||||
if (processing > 0) {
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.processing", processing));
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.processing", API.instance().getQuantityFormatter().formatInBucketForm(processing)));
|
||||
|
||||
yy += 7;
|
||||
}
|
||||
|
||||
if (scheduled > 0) {
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.scheduled", scheduled));
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.scheduled", API.instance().getQuantityFormatter().formatInBucketForm(scheduled)));
|
||||
|
||||
yy += 7;
|
||||
}
|
||||
|
||||
if (crafting > 0) {
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.crafting", crafting));
|
||||
drawers.getStringDrawer().draw(RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy, scale), I18n.format("gui.refinedstorage:crafting_monitor.crafting", API.instance().getQuantityFormatter().formatInBucketForm(crafting)));
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternChainLis
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementList;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskErrorType;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingRequestInfo;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTaskError;
|
||||
@@ -31,16 +32,18 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
// TODO: Calculation time.
|
||||
// TODO: Progressive outputs?
|
||||
public class CraftingTask implements ICraftingTask {
|
||||
private static final long CALCULATION_TIMEOUT_MS = 5000;
|
||||
|
||||
private INetwork network;
|
||||
private ICraftingRequestInfo requested;
|
||||
private int quantity;
|
||||
private ICraftingPattern pattern;
|
||||
private UUID id = UUID.randomUUID();
|
||||
private int ticks;
|
||||
private long calculationStarted = -1;
|
||||
private long executionStarted = -1;
|
||||
private Set<ICraftingPattern> patternsUsed = new HashSet<>();
|
||||
|
||||
private IStorage<ItemStack> internalStorage;
|
||||
private IStorage<FluidStack> internalFluidStorage;
|
||||
@@ -73,6 +76,16 @@ public class CraftingTask implements ICraftingTask {
|
||||
@Override
|
||||
@Nullable
|
||||
public ICraftingTaskError calculate() {
|
||||
if (calculationStarted != -1) {
|
||||
throw new IllegalStateException("Task already calculated!");
|
||||
}
|
||||
|
||||
if (executionStarted != -1) {
|
||||
throw new IllegalStateException("Task already started!");
|
||||
}
|
||||
|
||||
this.calculationStarted = System.currentTimeMillis();
|
||||
|
||||
int qty = this.quantity;
|
||||
int qtyPerCraft = getQuantityPerCraft();
|
||||
int crafted = 0;
|
||||
@@ -119,6 +132,14 @@ public class CraftingTask implements ICraftingTask {
|
||||
ICraftingPatternChainList patternChainList,
|
||||
ICraftingPattern pattern) {
|
||||
|
||||
if (System.currentTimeMillis() - calculationStarted > CALCULATION_TIMEOUT_MS) {
|
||||
return new CraftingTaskError(CraftingTaskErrorType.TOO_COMPLEX);
|
||||
}
|
||||
|
||||
if (!patternsUsed.add(pattern)) {
|
||||
return new CraftingTaskError(CraftingTaskErrorType.RECURSIVE, pattern);
|
||||
}
|
||||
|
||||
IStackList<ItemStack> itemsToExtract = API.instance().createItemStackList();
|
||||
IStackList<FluidStack> fluidsToExtract = API.instance().createFluidStackList();
|
||||
|
||||
@@ -297,6 +318,8 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
}
|
||||
|
||||
patternsUsed.remove(pattern);
|
||||
|
||||
if (pattern.isProcessing()) {
|
||||
IStackList<ItemStack> itemsToReceive = API.instance().createItemStackList();
|
||||
IStackList<FluidStack> fluidsToReceive = API.instance().createFluidStackList();
|
||||
|
@@ -97,6 +97,8 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
@Override
|
||||
public void drawIcon(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer) {
|
||||
if (requested.getItem() != null) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
itemDrawer.draw(x, y, requested.getItem());
|
||||
} else {
|
||||
fluidDrawer.draw(x, y, requested.getFluid());
|
||||
|
Reference in New Issue
Block a user