diff --git a/resources/changelog/1.18.2-1.17.0.txt b/resources/changelog/1.18.2-1.17.0.txt new file mode 100644 index 00000000000..e834a4e617e --- /dev/null +++ b/resources/changelog/1.18.2-1.17.0.txt @@ -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 + diff --git a/resources/changelog/1.19.2-1.20.0.txt b/resources/changelog/1.19.2-1.20.0.txt new file mode 100644 index 00000000000..c698dcb91ff --- /dev/null +++ b/resources/changelog/1.19.2-1.20.0.txt @@ -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 + diff --git a/src/main/java/org/cyclops/integrateddynamics/api/ingredient/IIngredientComponentStorageObservable.java b/src/main/java/org/cyclops/integrateddynamics/api/ingredient/IIngredientComponentStorageObservable.java index 054c8e344c1..e9c09b81aa9 100644 --- a/src/main/java/org/cyclops/integrateddynamics/api/ingredient/IIngredientComponentStorageObservable.java +++ b/src/main/java/org/cyclops/integrateddynamics/api/ingredient/IIngredientComponentStorageObservable.java @@ -107,14 +107,23 @@ public static class StorageChangeEvent { private final Change changeType; private final boolean completeChange; private final IIngredientCollection instances; + private final boolean initialChange; + @Deprecated // TODO: remove in next major MC version public StorageChangeEvent(int channel, PrioritizedPartPos pos, Change changeType, boolean completeChange, IIngredientCollection instances) { + this(channel, pos, changeType, completeChange, instances, false); + } + + public StorageChangeEvent(int channel, PrioritizedPartPos pos, + Change changeType, boolean completeChange, IIngredientCollection instances, + boolean initialChange) { this.channel = channel; this.pos = pos; this.changeType = changeType; this.completeChange = completeChange; this.instances = instances; + this.initialChange = initialChange; } public int getChannel() { @@ -148,6 +157,13 @@ public IIngredientCollection 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()); diff --git a/src/main/java/org/cyclops/integrateddynamics/core/network/IngredientObserver.java b/src/main/java/org/cyclops/integrateddynamics/core/network/IngredientObserver.java index 5149d208ac1..3806e8168b5 100644 --- a/src/main/java/org/cyclops/integrateddynamics/core/network/IngredientObserver.java +++ b/src/main/java/org/cyclops/integrateddynamics/core/network/IngredientObserver.java @@ -62,6 +62,7 @@ public class IngredientObserver { private final Map lastInventoryStates; private Future lastObserverBarrier; private boolean runningObserverSync; + private boolean initialObservation; public IngredientObserver(IPositionedAddonsNetworkIngredients network) { this.network = network; @@ -76,6 +77,7 @@ public IngredientObserver(IPositionedAddonsNetworkIngredients network) { this.lastObserverBarrier = null; this.runningObserverSync = false; + this.initialObservation = true; } public IPositionedAddonsNetworkIngredients getNetwork() { @@ -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! @@ -200,6 +203,7 @@ protected boolean observe(boolean forceSync) { observe(channel, true); } this.runningObserverSync = false; + this.initialObservation = false; } } return true; @@ -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 @@ -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); } } }