fix inconsitencies with crafting and fluids, fixes #670
This commit is contained in:
		| @@ -69,7 +69,6 @@ public class CraftingTaskFactory implements ICraftingTaskFactory { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             IFluidStackList toTakeFluids = RSUtils.readFluidStackList(tag.getTagList(CraftingTask.NBT_TO_TAKE_FLUIDS, Constants.NBT.TAG_COMPOUND)); |             IFluidStackList toTakeFluids = RSUtils.readFluidStackList(tag.getTagList(CraftingTask.NBT_TO_TAKE_FLUIDS, Constants.NBT.TAG_COMPOUND)); | ||||||
|             IFluidStackList tookFluids = RSUtils.readFluidStackList(tag.getTagList(CraftingTask.NBT_TOOK_FLUIDS, Constants.NBT.TAG_COMPOUND)); |  | ||||||
|  |  | ||||||
|             NBTTagList toInsertFluidsList = tag.getTagList(CraftingTask.NBT_TO_INSERT_FLUIDS, Constants.NBT.TAG_COMPOUND); |             NBTTagList toInsertFluidsList = tag.getTagList(CraftingTask.NBT_TO_INSERT_FLUIDS, Constants.NBT.TAG_COMPOUND); | ||||||
|  |  | ||||||
| @@ -83,7 +82,7 @@ public class CraftingTaskFactory implements ICraftingTaskFactory { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return new CraftingTask(network, stack, pattern, quantity, steps, toInsert, toTakeFluids, tookFluids, toInsertFluids); |             return new CraftingTask(network, stack, pattern, quantity, steps, toInsert, toTakeFluids, toInsertFluids); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return new CraftingTask(network, stack, pattern, quantity); |         return new CraftingTask(network, stack, pattern, quantity); | ||||||
|   | |||||||
| @@ -33,7 +33,6 @@ public class CraftingTask implements ICraftingTask { | |||||||
|     public static final String NBT_TO_TAKE_FLUIDS = "ToTakeFluids"; |     public static final String NBT_TO_TAKE_FLUIDS = "ToTakeFluids"; | ||||||
|     public static final String NBT_TO_INSERT_ITEMS = "ToInsertItems"; |     public static final String NBT_TO_INSERT_ITEMS = "ToInsertItems"; | ||||||
|     public static final String NBT_TO_INSERT_FLUIDS = "ToInsertFluids"; |     public static final String NBT_TO_INSERT_FLUIDS = "ToInsertFluids"; | ||||||
|     public static final String NBT_TOOK_FLUIDS = "TookFluids"; |  | ||||||
|  |  | ||||||
|     private INetworkMaster network; |     private INetworkMaster network; | ||||||
|     @Nullable |     @Nullable | ||||||
| @@ -49,7 +48,6 @@ public class CraftingTask implements ICraftingTask { | |||||||
|     private Deque<ItemStack> toInsertItems = new ArrayDeque<>(); |     private Deque<ItemStack> toInsertItems = new ArrayDeque<>(); | ||||||
|     private Deque<FluidStack> toInsertFluids = new ArrayDeque<>(); |     private Deque<FluidStack> toInsertFluids = new ArrayDeque<>(); | ||||||
|     private IFluidStackList toTakeFluids = API.instance().createFluidStackList(); |     private IFluidStackList toTakeFluids = API.instance().createFluidStackList(); | ||||||
|     private IFluidStackList tookFluids = API.instance().createFluidStackList(); |  | ||||||
|  |  | ||||||
|     public CraftingTask(INetworkMaster network, @Nullable ItemStack requested, ICraftingPattern pattern, int quantity) { |     public CraftingTask(INetworkMaster network, @Nullable ItemStack requested, ICraftingPattern pattern, int quantity) { | ||||||
|         this.network = network; |         this.network = network; | ||||||
| @@ -58,12 +56,11 @@ public class CraftingTask implements ICraftingTask { | |||||||
|         this.quantity = quantity; |         this.quantity = quantity; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public CraftingTask(INetworkMaster network, @Nullable ItemStack requested, ICraftingPattern pattern, int quantity, List<ICraftingStep> steps, Deque<ItemStack> toInsertItems, IFluidStackList toTakeFluids, IFluidStackList tookFluids, Deque<FluidStack> toInsertFluids) { |     public CraftingTask(INetworkMaster network, @Nullable ItemStack requested, ICraftingPattern pattern, int quantity, List<ICraftingStep> steps, Deque<ItemStack> toInsertItems, IFluidStackList toTakeFluids, Deque<FluidStack> toInsertFluids) { | ||||||
|         this(network, requested, pattern, quantity); |         this(network, requested, pattern, quantity); | ||||||
|         this.steps = steps; |         this.steps = steps; | ||||||
|         this.toInsertItems = toInsertItems; |         this.toInsertItems = toInsertItems; | ||||||
|         this.toTakeFluids = toTakeFluids; |         this.toTakeFluids = toTakeFluids; | ||||||
|         this.tookFluids = tookFluids; |  | ||||||
|         this.toInsertFluids = toInsertFluids; |         this.toInsertFluids = toInsertFluids; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -302,10 +299,6 @@ public class CraftingTask implements ICraftingTask { | |||||||
|             network.insertItem(stack, stack.stackSize, false); |             network.insertItem(stack, stack.stackSize, false); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         for (FluidStack stack : tookFluids.getStacks()) { |  | ||||||
|             network.insertFluid(stack, stack.amount, false); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         network.markCraftingMonitorForUpdate(); |         network.markCraftingMonitorForUpdate(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -324,6 +317,7 @@ public class CraftingTask implements ICraftingTask { | |||||||
|     @Override |     @Override | ||||||
|     public boolean update(Map<ICraftingPatternContainer, Integer> usedContainers) { |     public boolean update(Map<ICraftingPatternContainer, Integer> usedContainers) { | ||||||
|         IItemStackList oreDictPrepped = network.getItemStorageCache().getList().getOredicted(); |         IItemStackList oreDictPrepped = network.getItemStorageCache().getList().getOredicted(); | ||||||
|  |         IFluidStackList networkFluids = network.getFluidStorageCache().getList(); | ||||||
|  |  | ||||||
|         if (!missing.isEmpty()) { |         if (!missing.isEmpty()) { | ||||||
|             for (ItemStack missing : this.missing.getStacks()) { |             for (ItemStack missing : this.missing.getStacks()) { | ||||||
| @@ -337,18 +331,6 @@ public class CraftingTask implements ICraftingTask { | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|         for (FluidStack stack : toTakeFluids.getStacks()) { |  | ||||||
|             FluidStack stackExtracted = network.extractFluid(stack, stack.amount, false); |  | ||||||
|             if (stackExtracted != null) { |  | ||||||
|                 toTakeFluids.remove(stack, stack.amount, false); |  | ||||||
|                 tookFluids.add(stackExtracted); |  | ||||||
|                 network.markCraftingMonitorForUpdate(); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         toTakeFluids.clean(); |  | ||||||
|  |  | ||||||
|         for (ICraftingStep step : steps) { |         for (ICraftingStep step : steps) { | ||||||
|             ICraftingPatternContainer container = step.getPattern().getContainer(); |             ICraftingPatternContainer container = step.getPattern().getContainer(); | ||||||
|             Integer timesUsed = usedContainers.get(container); |             Integer timesUsed = usedContainers.get(container); | ||||||
| @@ -358,7 +340,7 @@ public class CraftingTask implements ICraftingTask { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (timesUsed++ <= container.getSpeedUpdateCount()) { |             if (timesUsed++ <= container.getSpeedUpdateCount()) { | ||||||
|                 if (!step.hasStartedProcessing() && step.canStartProcessing(oreDictPrepped, tookFluids)) { |                 if (!step.hasStartedProcessing() && step.canStartProcessing(oreDictPrepped, networkFluids)) { | ||||||
|                     step.setStartedProcessing(); |                     step.setStartedProcessing(); | ||||||
|                     step.execute(toInsertItems, toInsertFluids); |                     step.execute(toInsertItems, toInsertFluids); | ||||||
|                     usedContainers.put(container, timesUsed); |                     usedContainers.put(container, timesUsed); | ||||||
| @@ -451,8 +433,6 @@ public class CraftingTask implements ICraftingTask { | |||||||
|  |  | ||||||
|         tag.setTag(NBT_TO_INSERT_FLUIDS, toInsertFluidsList); |         tag.setTag(NBT_TO_INSERT_FLUIDS, toInsertFluidsList); | ||||||
|  |  | ||||||
|         tag.setTag(NBT_TOOK_FLUIDS, RSUtils.serializeFluidStackList(tookFluids)); |  | ||||||
|  |  | ||||||
|         return tag; |         return tag; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -502,6 +482,7 @@ public class CraftingTask implements ICraftingTask { | |||||||
|                 elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_crafting", 16)); |                 elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_crafting", 16)); | ||||||
|  |  | ||||||
|                 IItemStackList oreDictPrepped = network.getItemStorageCache().getList().getOredicted(); |                 IItemStackList oreDictPrepped = network.getItemStorageCache().getList().getOredicted(); | ||||||
|  |                 IFluidStackList networkFluids = network.getFluidStorageCache().getList(); | ||||||
|  |  | ||||||
|                 for (ICraftingStep step : steps.stream().filter(s -> !s.getPattern().isProcessing()).collect(Collectors.toList())) { |                 for (ICraftingStep step : steps.stream().filter(s -> !s.getPattern().isProcessing()).collect(Collectors.toList())) { | ||||||
|                     for (int i = 0; i < step.getPattern().getOutputs().size(); ++i) { |                     for (int i = 0; i < step.getPattern().getOutputs().size(); ++i) { | ||||||
| @@ -512,7 +493,7 @@ public class CraftingTask implements ICraftingTask { | |||||||
|                             32 |                             32 | ||||||
|                         ); |                         ); | ||||||
|  |  | ||||||
|                         if (!step.hasStartedProcessing() && !step.canStartProcessing(oreDictPrepped, tookFluids)) { |                         if (!step.hasStartedProcessing() && !step.canStartProcessing(oreDictPrepped, networkFluids)) { | ||||||
|                             element = new CraftingMonitorElementInfo(element, "gui.refinedstorage:crafting_monitor.waiting_for_items"); |                             element = new CraftingMonitorElementInfo(element, "gui.refinedstorage:crafting_monitor.waiting_for_items"); | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
| @@ -547,19 +528,6 @@ public class CraftingTask implements ICraftingTask { | |||||||
|  |  | ||||||
|                 elements.commit(); |                 elements.commit(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!toTakeFluids.isEmpty()) { |  | ||||||
|                 elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.fluids_taking", 16)); |  | ||||||
|  |  | ||||||
|                 toTakeFluids.getStacks().stream() |  | ||||||
|                     .map(stack -> new CraftingMonitorElementFluidRender( |  | ||||||
|                         -1, |  | ||||||
|                         stack, |  | ||||||
|                         32 |  | ||||||
|                     )).forEach(elements::add); |  | ||||||
|  |  | ||||||
|                 elements.commit(); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return elements.getElements(); |         return elements.getElements(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 way2muchnoise
					way2muchnoise