Revert "Fixed crafting task stalling when there's not enough space in the inventory. Fixes #2051"

This reverts commit b2ecc5c06d.
This commit is contained in:
raoulvdberge
2018-11-21 08:39:23 +01:00
parent 60ada318d4
commit 23ec0c797c
2 changed files with 27 additions and 79 deletions

View File

@@ -719,10 +719,7 @@ public class CraftingTask implements ICraftingTask {
} }
if (p.getState() == ProcessingState.READY && hasAll) { if (p.getState() == ProcessingState.READY && hasAll) {
boolean insertedAll = true; boolean abort = false;
List<ItemStack> put = new ArrayList<>();
List<FluidStack> putFluids = new ArrayList<>();
for (int i = 0; i < p.getItemsToPut().size(); ++i) { for (int i = 0; i < p.getItemsToPut().size(); ++i) {
ItemStack need = p.getItemsToPut().get(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); ItemStack remainder = ItemHandlerHelper.insertItem(p.getPattern().getContainer().getConnectedInventory(), result, false);
if (!remainder.isEmpty()) { 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); this.internalStorage.insert(remainder, remainder.getCount(), Action.PERFORM);
p.getItemsToPut().set(i, remainder); p.getItemsToPut().set(i, remainder);
insertedAll = false; abort = true;
} else {
put.add(need); break;
} }
} }
if (abort) {
continue;
}
for (int i = 0; i < p.getFluidsToPut().size(); ++i) { for (int i = 0; i < p.getFluidsToPut().size(); ++i) {
FluidStack need = p.getFluidsToPut().get(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); int filled = p.getPattern().getContainer().getConnectedFluidInventory().fill(result, true);
if (filled != result.amount) { 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); this.internalFluidStorage.insert(result, result.amount - filled, Action.PERFORM);
p.getFluidsToPut().set(i, StackUtils.copy(result, result.amount - filled)); p.getFluidsToPut().set(i, StackUtils.copy(result, result.amount - filled));
insertedAll = false; abort = true;
} else {
putFluids.add(need); break;
} }
} }
put.forEach(p::markItemAsPut); if (abort) {
putFluids.forEach(p::markFluidAsPut); continue;
if (insertedAll) {
p.setState(ProcessingState.EXTRACTED_ALL);
p.getPattern().getContainer().onUsedForProcessing();
} }
p.setState(ProcessingState.EXTRACTED_ALL);
p.getPattern().getContainer().onUsedForProcessing();
} }
} }
@@ -1020,10 +1024,10 @@ public class CraftingTask implements ICraftingTask {
} }
if (processing.getState() == ProcessingState.EXTRACTED_ALL) { 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)); 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()) { for (ItemStack receive : processing.getItemsToReceive().getStacks()) {
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(receive, 0, 0, 0, receive.getCount(), 0); 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) { 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)); 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()) { for (FluidStack receive : processing.getFluidsToReceive().getStacks()) {
ICraftingMonitorElement element = new CraftingMonitorElementFluidRender(receive, 0, 0, 0, receive.amount, 0); 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"); element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.machine_does_not_accept_fluid");
} else if (processing.getState() == ProcessingState.MACHINE_NONE) { } else if (processing.getState() == ProcessingState.MACHINE_NONE) {
element = new CraftingMonitorElementError(element, "gui.refinedstorage:crafting_monitor.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); elements.add(element);

View File

@@ -20,8 +20,6 @@ class Processing {
private static final String NBT_FLUIDS_TO_RECEIVE = "FluidsToReceive"; private static final String NBT_FLUIDS_TO_RECEIVE = "FluidsToReceive";
private static final String NBT_ITEMS_TO_PUT = "ItemsToPut"; private static final String NBT_ITEMS_TO_PUT = "ItemsToPut";
private static final String NBT_FLUIDS_TO_PUT = "FluidsToPut"; 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_STATE = "State";
private static final String NBT_ROOT = "Root"; private static final String NBT_ROOT = "Root";
@@ -30,8 +28,6 @@ class Processing {
private IStackList<FluidStack> fluidsToReceive; private IStackList<FluidStack> fluidsToReceive;
private ArrayList<ItemStack> itemsToPut; private ArrayList<ItemStack> itemsToPut;
private ArrayList<FluidStack> fluidsToPut; private ArrayList<FluidStack> fluidsToPut;
private ArrayList<ItemStack> itemsPut = new ArrayList<>();
private ArrayList<FluidStack> fluidsPut = new ArrayList<>();
private ProcessingState state = ProcessingState.READY; private ProcessingState state = ProcessingState.READY;
private boolean root; private boolean root;
@@ -63,17 +59,6 @@ class Processing {
itemsToPut.add(stack); 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<>(); this.fluidsToPut = new ArrayList<>();
NBTTagList fluidsToPutList = tag.getTagList(NBT_FLUIDS_TO_PUT, Constants.NBT.TAG_COMPOUND); NBTTagList fluidsToPutList = tag.getTagList(NBT_FLUIDS_TO_PUT, Constants.NBT.TAG_COMPOUND);
@@ -87,17 +72,6 @@ class Processing {
fluidsToPut.add(stack); 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)]; this.state = ProcessingState.values()[tag.getInteger(NBT_STATE)];
} }
@@ -121,28 +95,10 @@ class Processing {
return fluidsToPut; return fluidsToPut;
} }
public ArrayList<ItemStack> getItemsPut() {
return itemsPut;
}
public ArrayList<FluidStack> getFluidsPut() {
return fluidsPut;
}
public void setState(ProcessingState state) { public void setState(ProcessingState state) {
this.state = 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() { public ProcessingState getState() {
return state; return state;
} }
@@ -163,25 +119,15 @@ class Processing {
for (ItemStack stack : this.itemsToPut) { for (ItemStack stack : this.itemsToPut) {
itemsToPutList.appendTag(StackUtils.serializeStackToNbt(stack)); itemsToPutList.appendTag(StackUtils.serializeStackToNbt(stack));
} }
tag.setTag(NBT_ITEMS_TO_PUT, itemsToPutList);
NBTTagList itemsPutList = new NBTTagList(); tag.setTag(NBT_ITEMS_TO_PUT, itemsToPutList);
for (ItemStack stack : this.itemsPut) {
itemsPutList.appendTag(StackUtils.serializeStackToNbt(stack));
}
tag.setTag(NBT_ITEMS_PUT, itemsPutList);
NBTTagList fluidsToPutList = new NBTTagList(); NBTTagList fluidsToPutList = new NBTTagList();
for (FluidStack stack : this.fluidsToPut) { for (FluidStack stack : this.fluidsToPut) {
fluidsToPutList.appendTag(stack.writeToNBT(new NBTTagCompound())); fluidsToPutList.appendTag(stack.writeToNBT(new NBTTagCompound()));
} }
tag.setTag(NBT_FLUIDS_TO_PUT, fluidsToPutList);
NBTTagList fluidsPutList = new NBTTagList(); tag.setTag(NBT_FLUIDS_TO_PUT, fluidsToPutList);
for (FluidStack stack : this.fluidsPut) {
fluidsPutList.appendTag(stack.writeToNBT(new NBTTagCompound()));
}
tag.setTag(NBT_FLUIDS_PUT, fluidsPutList);
tag.setInteger(NBT_STATE, state.ordinal()); tag.setInteger(NBT_STATE, state.ordinal());