diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/CraftingTask.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/CraftingTask.java index 4a9c30ecc..051e07941 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/CraftingTask.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/CraftingTask.java @@ -719,10 +719,7 @@ public class CraftingTask implements ICraftingTask { } if (p.getState() == ProcessingState.READY && hasAll) { - boolean insertedAll = true; - - List put = new ArrayList<>(); - List putFluids = new ArrayList<>(); + boolean abort = false; for (int i = 0; i < p.getItemsToPut().size(); ++i) { ItemStack need = p.getItemsToPut().get(i); @@ -734,16 +731,22 @@ public class CraftingTask implements ICraftingTask { ItemStack remainder = ItemHandlerHelper.insertItem(p.getPattern().getContainer().getConnectedInventory(), result, false); if (!remainder.isEmpty()) { + LOGGER.warn("In a simulation, " + p.getPattern().getContainer().getConnectedInventory() + " reported that we could insert " + result + " but we got " + remainder + " as a remainder"); + this.internalStorage.insert(remainder, remainder.getCount(), Action.PERFORM); p.getItemsToPut().set(i, remainder); - insertedAll = false; - } else { - put.add(need); + abort = true; + + break; } } + if (abort) { + continue; + } + for (int i = 0; i < p.getFluidsToPut().size(); ++i) { FluidStack need = p.getFluidsToPut().get(i); @@ -754,24 +757,25 @@ public class CraftingTask implements ICraftingTask { int filled = p.getPattern().getContainer().getConnectedFluidInventory().fill(result, true); if (filled != result.amount) { + LOGGER.warn("In a simulation, " + p.getPattern().getContainer().getConnectedFluidInventory() + " reported that we could fill " + result + " but we only filled " + filled); + this.internalFluidStorage.insert(result, result.amount - filled, Action.PERFORM); p.getFluidsToPut().set(i, StackUtils.copy(result, result.amount - filled)); - insertedAll = false; - } else { - putFluids.add(need); + abort = true; + + break; } } - put.forEach(p::markItemAsPut); - putFluids.forEach(p::markFluidAsPut); - - if (insertedAll) { - p.setState(ProcessingState.EXTRACTED_ALL); - - p.getPattern().getContainer().onUsedForProcessing(); + if (abort) { + continue; } + + p.setState(ProcessingState.EXTRACTED_ALL); + + p.getPattern().getContainer().onUsedForProcessing(); } } @@ -1020,10 +1024,10 @@ public class CraftingTask implements ICraftingTask { } if (processing.getState() == ProcessingState.EXTRACTED_ALL) { - for (ItemStack put : processing.getItemsPut()) { + for (ItemStack put : processing.getItemsToPut()) { elements.add(new CraftingMonitorElementItemRender(put, 0, 0, put.getCount(), 0, 0)); } - } else { + } else if (processing.getState() == ProcessingState.READY || processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT || processing.getState() == ProcessingState.MACHINE_NONE || processing.getState() == ProcessingState.LOCKED) { for (ItemStack receive : processing.getItemsToReceive().getStacks()) { ICraftingMonitorElement element = new CraftingMonitorElementItemRender(receive, 0, 0, 0, receive.getCount(), 0); @@ -1056,10 +1060,10 @@ public class CraftingTask implements ICraftingTask { } if (processing.getState() == ProcessingState.EXTRACTED_ALL) { - for (FluidStack put : processing.getFluidsPut()) { + for (FluidStack put : processing.getFluidsToPut()) { elements.add(new CraftingMonitorElementFluidRender(put, 0, 0, put.amount, 0, 0)); } - } else { + } else if (processing.getState() == ProcessingState.READY || processing.getState() == ProcessingState.MACHINE_DOES_NOT_ACCEPT || processing.getState() == ProcessingState.MACHINE_NONE) { for (FluidStack receive : processing.getFluidsToReceive().getStacks()) { ICraftingMonitorElement element = new CraftingMonitorElementFluidRender(receive, 0, 0, 0, receive.amount, 0); @@ -1067,8 +1071,6 @@ public class CraftingTask implements ICraftingTask { element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept_fluid"); } else if (processing.getState() == ProcessingState.MACHINE_NONE) { element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_none"); - } else if (processing.getState() == ProcessingState.LOCKED) { - element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.crafter_is_locked"); } elements.add(element); diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/Processing.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/Processing.java index 6a6ce4080..8fcf2c04b 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/Processing.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/autocrafting/task/Processing.java @@ -20,8 +20,6 @@ class Processing { private static final String NBT_FLUIDS_TO_RECEIVE = "FluidsToReceive"; private static final String NBT_ITEMS_TO_PUT = "ItemsToPut"; private static final String NBT_FLUIDS_TO_PUT = "FluidsToPut"; - private static final String NBT_ITEMS_PUT = "ItemsPut"; - private static final String NBT_FLUIDS_PUT = "FluidsPut"; private static final String NBT_STATE = "State"; private static final String NBT_ROOT = "Root"; @@ -30,8 +28,6 @@ class Processing { private IStackList fluidsToReceive; private ArrayList itemsToPut; private ArrayList fluidsToPut; - private ArrayList itemsPut = new ArrayList<>(); - private ArrayList fluidsPut = new ArrayList<>(); private ProcessingState state = ProcessingState.READY; private boolean root; @@ -63,17 +59,6 @@ class Processing { itemsToPut.add(stack); } - NBTTagList itemsPutList = tag.getTagList(NBT_ITEMS_PUT, Constants.NBT.TAG_COMPOUND); - for (int i = 0; i < itemsPutList.tagCount(); ++i) { - ItemStack stack = StackUtils.deserializeStackFromNbt(itemsPutList.getCompoundTagAt(i)); - - if (stack.isEmpty()) { - throw new CraftingTaskReadException("Stack is empty!"); - } - - itemsPut.add(stack); - } - this.fluidsToPut = new ArrayList<>(); NBTTagList fluidsToPutList = tag.getTagList(NBT_FLUIDS_TO_PUT, Constants.NBT.TAG_COMPOUND); @@ -87,17 +72,6 @@ class Processing { fluidsToPut.add(stack); } - NBTTagList fluidsPutList = tag.getTagList(NBT_FLUIDS_PUT, Constants.NBT.TAG_COMPOUND); - for (int i = 0; i < fluidsPutList.tagCount(); ++i) { - FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidsPutList.getCompoundTagAt(i)); - - if (stack == null) { - throw new CraftingTaskReadException("Stack is empty!"); - } - - fluidsPut.add(stack); - } - this.state = ProcessingState.values()[tag.getInteger(NBT_STATE)]; } @@ -121,28 +95,10 @@ class Processing { return fluidsToPut; } - public ArrayList getItemsPut() { - return itemsPut; - } - - public ArrayList getFluidsPut() { - return fluidsPut; - } - public void setState(ProcessingState state) { this.state = state; } - public void markItemAsPut(ItemStack stack) { - itemsToPut.remove(stack); - itemsPut.add(stack); - } - - public void markFluidAsPut(FluidStack stack) { - fluidsToPut.remove(stack); - fluidsPut.add(stack); - } - public ProcessingState getState() { return state; } @@ -163,25 +119,15 @@ class Processing { for (ItemStack stack : this.itemsToPut) { itemsToPutList.appendTag(StackUtils.serializeStackToNbt(stack)); } - tag.setTag(NBT_ITEMS_TO_PUT, itemsToPutList); - NBTTagList itemsPutList = new NBTTagList(); - for (ItemStack stack : this.itemsPut) { - itemsPutList.appendTag(StackUtils.serializeStackToNbt(stack)); - } - tag.setTag(NBT_ITEMS_PUT, itemsPutList); + tag.setTag(NBT_ITEMS_TO_PUT, itemsToPutList); NBTTagList fluidsToPutList = new NBTTagList(); for (FluidStack stack : this.fluidsToPut) { fluidsToPutList.appendTag(stack.writeToNBT(new NBTTagCompound())); } - tag.setTag(NBT_FLUIDS_TO_PUT, fluidsToPutList); - NBTTagList fluidsPutList = new NBTTagList(); - for (FluidStack stack : this.fluidsPut) { - fluidsPutList.appendTag(stack.writeToNBT(new NBTTagCompound())); - } - tag.setTag(NBT_FLUIDS_PUT, fluidsPutList); + tag.setTag(NBT_FLUIDS_TO_PUT, fluidsToPutList); tag.setInteger(NBT_STATE, state.ordinal());