Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master-1.16' into master-1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Apr 17, 2022
2 parents 1f8616f + e46c0b5 commit ee155b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
10 changes: 10 additions & 0 deletions resources/changelog/1.16.5-1.0.21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
As always, don't forget to backup your world before updating!
Requires CyclopsCore version 1.11.6 or higher.

Fixes:
* Flush crafting output buffer in same tick
This resolves cases where the crafting result may be missed
and get stuck in a pending state if it is extracted from the
target storage too quickly.
Closes #81

Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,7 @@ public void update(INetwork network, IPartNetwork partNetwork, PartTarget target
}

// Push any pending output ingredients into the network
ListIterator<IngredientInstanceWrapper<?, ?>> 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()) {
Expand Down Expand Up @@ -742,6 +733,11 @@ protected <C, T, M> C wrapStorageCapability(Capability<C> capability, Ingredient
@Override
public <T, M> void addResult(IngredientComponent<T, M> 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) {
Expand Down Expand Up @@ -785,5 +781,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<IngredientInstanceWrapper<?, ?>> 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());
}
}
}
}

0 comments on commit ee155b6

Please sign in to comment.