Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master-1.19-lts' into master-1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 10, 2023
2 parents 91dc18c + b493158 commit 43852ce
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
7 changes: 7 additions & 0 deletions resources/changelog/1.18.2-1.17.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
As always, don't forget to backup your world before updating!
Requires CyclopsCore version 1.17.0 or higher.

Additions:
* Add initialChange flag to storage change events
This is required to fix CyclopsMC/IntegratedCrafting#99

7 changes: 7 additions & 0 deletions resources/changelog/1.19.2-1.20.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
As always, don't forget to backup your world before updating!
Requires CyclopsCore version 1.18.2 or higher.

Additions:
* Add initialChange flag to storage change events
This is required to fix CyclopsMC/IntegratedCrafting#99

Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,23 @@ public static class StorageChangeEvent<T, M> {
private final Change changeType;
private final boolean completeChange;
private final IIngredientCollection<T, M> instances;
private final boolean initialChange;

@Deprecated // TODO: remove in next major MC version
public StorageChangeEvent(int channel, PrioritizedPartPos pos,
Change changeType, boolean completeChange, IIngredientCollection<T, M> instances) {
this(channel, pos, changeType, completeChange, instances, false);
}

public StorageChangeEvent(int channel, PrioritizedPartPos pos,
Change changeType, boolean completeChange, IIngredientCollection<T, M> instances,
boolean initialChange) {
this.channel = channel;
this.pos = pos;
this.changeType = changeType;
this.completeChange = completeChange;
this.instances = instances;
this.initialChange = initialChange;
}

public int getChannel() {
Expand Down Expand Up @@ -148,6 +157,13 @@ public IIngredientCollection<T, M> getInstances() {
return instances;
}

/**
* @return If this change occurred during initialization of the observer.
*/
public boolean isInitialChange() {
return initialChange;
}

@Override
public String toString() {
return String.format("[%s at %s(%s): %s]", getChangeType().name(), getPos(), getChannel(), getInstances());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class IngredientObserver<T, M> {
private final Map<PartPos, Integer> lastInventoryStates;
private Future<?> lastObserverBarrier;
private boolean runningObserverSync;
private boolean initialObservation;

public IngredientObserver(IPositionedAddonsNetworkIngredients<T, M> network) {
this.network = network;
Expand All @@ -76,6 +77,7 @@ public IngredientObserver(IPositionedAddonsNetworkIngredients<T, M> network) {

this.lastObserverBarrier = null;
this.runningObserverSync = false;
this.initialObservation = true;
}

public IPositionedAddonsNetworkIngredients<T, M> getNetwork() {
Expand Down Expand Up @@ -185,6 +187,7 @@ protected boolean observe(boolean forceSync) {
for (int channel : getChannels()) {
observe(channel, false);
}
this.initialObservation = false;
});
} else {
// If we have an uncompleted sync observer, don't start a new one yet!
Expand All @@ -200,6 +203,7 @@ protected boolean observe(boolean forceSync) {
observe(channel, true);
}
this.runningObserverSync = false;
this.initialObservation = false;
}
}
return true;
Expand Down Expand Up @@ -296,12 +300,12 @@ protected void observe(int channel, boolean forceSync) {
if (diff.hasAdditions()) {
hasChanges = true;
this.emitEvent(new IIngredientComponentStorageObservable.StorageChangeEvent<>(channel, partPos,
IIngredientComponentStorageObservable.Change.ADDITION, false, diff.getAdditions()), forceSync);
IIngredientComponentStorageObservable.Change.ADDITION, false, diff.getAdditions(), this.initialObservation), forceSync);
}
if (diff.hasDeletions()) {
hasChanges = true;
this.emitEvent(new IIngredientComponentStorageObservable.StorageChangeEvent<>(channel, partPos,
IIngredientComponentStorageObservable.Change.DELETION, diff.isCompletelyEmpty(), diff.getDeletions()), forceSync);
IIngredientComponentStorageObservable.Change.DELETION, diff.isCompletelyEmpty(), diff.getDeletions(), this.initialObservation), forceSync);
}

// Update the next tick value
Expand Down Expand Up @@ -364,7 +368,7 @@ protected void observe(int channel, boolean forceSync) {
// No additions are possible
if (diff.hasDeletions()) {
this.emitEvent(new IIngredientComponentStorageObservable.StorageChangeEvent<>(channel, partPos,
IIngredientComponentStorageObservable.Change.DELETION, diff.isCompletelyEmpty(), diff.getDeletions()), forceSync);
IIngredientComponentStorageObservable.Change.DELETION, diff.isCompletelyEmpty(), diff.getDeletions(), this.initialObservation), forceSync);
}
}
}
Expand Down

0 comments on commit 43852ce

Please sign in to comment.