diff --git a/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java b/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java index f33ebb4c..32258d64 100644 --- a/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java +++ b/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCrafting.java @@ -238,16 +238,7 @@ public void update(INetwork network, IPartNetwork partNetwork, PartTarget target } // Push any pending output ingredients into the network - ListIterator> outputBufferIt = state.getInventoryOutputBuffer().listIterator(); - while (outputBufferIt.hasNext()) { - IngredientInstanceWrapper newWrapper = insertIntoNetwork(outputBufferIt.next(), - network, state.getChannelCrafting()); - if (newWrapper == null) { - outputBufferIt.remove(); - } else { - outputBufferIt.set(newWrapper); - } - } + state.flushInventoryOutputBuffer(network); // Block job ticking if there still are outputs in our crafting result buffer. if (state.getInventoryOutputBuffer().isEmpty()) { @@ -744,6 +735,11 @@ protected C wrapStorageCapability(Capability capability, Ingredient @Override public void addResult(IngredientComponent ingredientComponent, T instance) { this.getInventoryOutputBuffer().add(new IngredientInstanceWrapper<>(ingredientComponent, instance)); + + // Try to flush buffer immediately + if (this.network != null) { + this.flushInventoryOutputBuffer(this.network); + } } public void setIngredientComponentTargetSideOverride(IngredientComponent ingredientComponent, Direction side) { @@ -787,5 +783,29 @@ public void setDisableCraftingCheck(boolean disableCraftingCheck) { public boolean isDisableCraftingCheck() { return disableCraftingCheck; } + + public void flushInventoryOutputBuffer(INetwork network) { + // Try to insert each ingredient in the buffer into the network. + boolean changed = false; + ListIterator> outputBufferIt = this.getInventoryOutputBuffer().listIterator(); + while (outputBufferIt.hasNext()) { + IngredientInstanceWrapper oldWrapper = outputBufferIt.next(); + IngredientInstanceWrapper newWrapper = insertIntoNetwork(oldWrapper, + network, this.getChannelCrafting()); + if (newWrapper != oldWrapper) { + changed = true; + } + if (newWrapper == null) { + outputBufferIt.remove(); + } else { + outputBufferIt.set(newWrapper); + } + } + + // If at least one ingredient was inserted, force a sync observer update in the network. + if (changed) { + CraftingHelpers.beforeCalculateCraftingJobs(network, getChannelCrafting()); + } + } } }