diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c15150ff..eb7a8fe0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Void excess mode to storages. + ### Fixed - Fixed losing disk when using Wrench dismantling on the Portable Grid. diff --git a/build.gradle b/build.gradle index 5a9f53ab1..54f67457f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,13 +5,13 @@ subprojects { ext { apis = [ - ':refinedstorage2-core-api', - ':refinedstorage2-resource-api', - ':refinedstorage2-storage-api', - ':refinedstorage2-network-api', - ':refinedstorage2-network', - ':refinedstorage2-grid-api', - ':refinedstorage2-query-parser' + ':refinedstorage2-core-api', + ':refinedstorage2-resource-api', + ':refinedstorage2-storage-api', + ':refinedstorage2-network-api', + ':refinedstorage2-network', + ':refinedstorage2-grid-api', + ':refinedstorage2-query-parser' ] compileApis = [':refinedstorage2-platform-api'] } @@ -22,7 +22,6 @@ enableSonarQube("refinedmods_refinedstorage2") sonarqube { properties { property "sonar.coverage.exclusions", "refinedstorage2-platform-forge/**/*,refinedstorage2-platform-fabric/**/*,refinedstorage2-platform-common/**/*,refinedstorage2-platform-api/**/*" - // TODO: REI code is duplicated as reusing it in a common module isn't possible/too difficult. Fix this. property "sonar.cpd.exclusions", "refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/recipemod/rei/*,refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/recipemod/rei/*" } } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java index 06f834d8d..e6093f416 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java index 7c77eebbe..7db29d3ee 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.controller.ControllerNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java index 6e1621904..c6f1830fb 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java index d796aecd2..1c1addc8c 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.exporter.ExporterNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java index ffec2a728..3827224d0 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.storage.tracked.InMemoryTrackedStorageRepository; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java index d51e1e4dd..48ae36153 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java index 6683c513c..8cd7444af 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java index 9f4cfb8b4..dca9012be 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java index 42b6aaf77..7543f8b51 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java index c5aea7fe9..ad1c8380f 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java index 491a18f4c..2c7cb7aca 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java index c1a666e45..7a2e3af67 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; public class SimpleNetworkNode extends AbstractNetworkNode { private long energyUsage; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java index 8ecf26f29..d3fd21a53 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java index 73dff0160..fb6d9c53c 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.detector; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java index 9db98bc38..9ae1f3962 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.exporter; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.Task; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExposedExternalStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExposedExternalStorage.java index 438534771..72d6860de 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExposedExternalStorage.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExposedExternalStorage.java @@ -1,11 +1,10 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage; -import com.refinedmods.refinedstorage2.api.network.node.AbstractConfiguredProxyStorage; -import com.refinedmods.refinedstorage2.api.network.node.StorageConfiguration; +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractConfiguredProxyStorage; +import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild; -import com.refinedmods.refinedstorage2.api.storage.composite.ConsumingStorage; import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorage; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageListener; @@ -21,7 +20,7 @@ import javax.annotation.Nullable; public class ExposedExternalStorage extends AbstractConfiguredProxyStorage - implements ConsumingStorage, CompositeAwareChild, TrackedStorage, ExternalStorageListener { + implements TrackedStorage, ExternalStorageListener { private final Set parents = new HashSet<>(); private final LongSupplier clock; @Nullable @@ -63,6 +62,24 @@ public void onRemovedFromComposite(final ParentComposite parentComposite) { } } + @Override + public Amount compositeInsert(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + final Amount inserted = super.compositeInsert(resource, amount, action, actor); + return inserted.withoutNotifyingList(); + } + + @Override + public Amount compositeExtract(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + final Amount extracted = super.compositeExtract(resource, amount, action, actor); + return extracted.withoutNotifyingList(); + } + @Override public void setDelegate(final ExternalStorage newDelegate) { super.setDelegate(newDelegate); diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java index 3b5298ffb..6d4d66bb2 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage; import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; -import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.externalstorage.ExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorage; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java index d57b19d42..255721c6c 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManagerImpl; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.storage.Actor; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java index 732a0b3cd..5ebb5580e 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java @@ -4,7 +4,7 @@ import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExposedExternalStorage; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.externalstorage.InterfaceExternalStorageProvider; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java index 2491e8296..537316c90 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.importer; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java index 76e1e2715..7823b4dc5 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java @@ -1,12 +1,11 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage; -import com.refinedmods.refinedstorage2.api.network.node.AbstractImmutableConfiguredProxyStorage; -import com.refinedmods.refinedstorage2.api.network.node.StorageConfiguration; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractImmutableConfiguredProxyStorage; +import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild; import com.refinedmods.refinedstorage2.api.storage.composite.CompositeStorage; import com.refinedmods.refinedstorage2.api.storage.composite.CompositeStorageImpl; import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite; @@ -16,7 +15,7 @@ import java.util.Optional; class ExposedMultiStorage extends AbstractImmutableConfiguredProxyStorage - implements CompositeStorage, CompositeAwareChild { + implements CompositeStorage { protected ExposedMultiStorage(final StorageConfiguration config) { super(config, new CompositeStorageImpl(new ResourceListImpl())); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java index 95704945c..667f40117 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage; import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; -import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode; import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.StorageState; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/ExposedStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/ExposedStorage.java index 1724bba1c..c4e7b035b 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/ExposedStorage.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/ExposedStorage.java @@ -1,11 +1,10 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.storage; -import com.refinedmods.refinedstorage2.api.network.node.AbstractConfiguredProxyStorage; -import com.refinedmods.refinedstorage2.api.network.node.StorageConfiguration; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractConfiguredProxyStorage; +import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild; import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorage; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; @@ -15,8 +14,7 @@ import java.util.Optional; import java.util.Set; -class ExposedStorage extends AbstractConfiguredProxyStorage - implements TrackedStorage, CompositeAwareChild { +class ExposedStorage extends AbstractConfiguredProxyStorage implements TrackedStorage { private final Set parents = new HashSet<>(); ExposedStorage(final StorageConfiguration config) { diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java index 659ae9106..6b0b57a45 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.storage; import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; -import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode; import com.refinedmods.refinedstorage2.api.storage.Storage; import javax.annotation.Nullable; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractConfiguredProxyStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractConfiguredProxyStorage.java similarity index 60% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractConfiguredProxyStorage.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractConfiguredProxyStorage.java index d40723398..0d15bff67 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractConfiguredProxyStorage.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractConfiguredProxyStorage.java @@ -1,12 +1,13 @@ -package com.refinedmods.refinedstorage2.api.network.node; +package com.refinedmods.refinedstorage2.api.network.impl.storage; import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.core.CoreValidations; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; +import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild; import com.refinedmods.refinedstorage2.api.storage.composite.Priority; import java.util.Collection; @@ -17,7 +18,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") -public abstract class AbstractConfiguredProxyStorage implements Storage, Priority { +public abstract class AbstractConfiguredProxyStorage implements CompositeAwareChild, Priority { @Nullable private S delegate; private final StorageConfiguration config; @@ -33,21 +34,39 @@ protected AbstractConfiguredProxyStorage(final StorageConfiguration config, fina @Override public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { - if (delegate == null || config.getAccessMode() == AccessMode.INSERT || !config.isActive()) { - return 0; - } - return delegate.extract(resource, amount, action, actor); + throw new UnsupportedOperationException("Immediate extract is not allowed"); } @Override public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { - if (delegate == null - || config.getAccessMode() == AccessMode.EXTRACT - || !config.isActive() - || !config.isAllowed(resource)) { - return 0; + throw new UnsupportedOperationException("Immediate insert is not allowed"); + } + + @Override + public Amount compositeInsert(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + if (delegate == null || config.isExtractOnly() || !config.isActive() || !config.isAllowed(resource)) { + return Amount.ZERO; + } + final long inserted = delegate.insert(resource, amount, action, actor); + if ((config.isVoidExcess() && config.getFilterMode() == FilterMode.ALLOW) && inserted < amount) { + return new Amount(amount, inserted); + } + return new Amount(inserted, inserted); + } + + @Override + public Amount compositeExtract(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + if (delegate == null || config.isInsertOnly() || !config.isActive()) { + return Amount.ZERO; } - return delegate.insert(resource, amount, action, actor); + final long extracted = delegate.extract(resource, amount, action, actor); + return new Amount(extracted, extracted); } @Override diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractImmutableConfiguredProxyStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractImmutableConfiguredProxyStorage.java similarity index 92% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractImmutableConfiguredProxyStorage.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractImmutableConfiguredProxyStorage.java index df1977a85..174e59b36 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractImmutableConfiguredProxyStorage.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractImmutableConfiguredProxyStorage.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.network.node; +package com.refinedmods.refinedstorage2.api.network.impl.storage; import com.refinedmods.refinedstorage2.api.storage.Storage; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java similarity index 89% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractNetworkNode.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java index c14f895ef..8a6955d77 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java @@ -1,7 +1,8 @@ -package com.refinedmods.refinedstorage2.api.network.node; +package com.refinedmods.refinedstorage2.api.network.impl.storage; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import javax.annotation.Nullable; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractStorageNetworkNode.java similarity index 86% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractStorageNetworkNode.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractStorageNetworkNode.java index 2fcb85df7..3712bbe59 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractStorageNetworkNode.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.network.node; +package com.refinedmods.refinedstorage2.api.network.impl.storage; import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; @@ -16,6 +16,7 @@ public abstract class AbstractStorageNetworkNode extends AbstractNetworkNode imp private final Filter filter = new Filter(); private int priority; private AccessMode accessMode = AccessMode.INSERT_EXTRACT; + private boolean voidExcess; @Override public int getPriority() { @@ -50,10 +51,19 @@ public void setFilterMode(final FilterMode mode) { @Override public void setPriority(final int priority) { this.priority = priority; - trySortSources(); } + @Override + public boolean isVoidExcess() { + return voidExcess; + } + + @Override + public void setVoidExcess(final boolean voidExcess) { + this.voidExcess = voidExcess; + } + private void trySortSources() { if (network == null) { return; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/StorageConfiguration.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageConfiguration.java similarity index 67% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/StorageConfiguration.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageConfiguration.java index 9647a18e8..518945726 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/StorageConfiguration.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageConfiguration.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.network.node; +package com.refinedmods.refinedstorage2.api.network.impl.storage; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; @@ -11,6 +11,18 @@ public interface StorageConfiguration extends Priority { AccessMode getAccessMode(); + default boolean isInsertOnly() { + return getAccessMode() == AccessMode.INSERT; + } + + default boolean isExtractOnly() { + return getAccessMode() == AccessMode.EXTRACT; + } + + boolean isVoidExcess(); + + void setVoidExcess(boolean voidExcess); + void setAccessMode(AccessMode accessMode); FilterMode getFilterMode(); diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/package-info.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/package-info.java new file mode 100644 index 000000000..d9d432727 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.api.network.impl.storage; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java index d01134c05..8d43fe645 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; public final class SpyingNetworkNode extends AbstractNetworkNode { private final long energyUsage; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java index f96e95348..fce1733f2 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java @@ -16,6 +16,7 @@ import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import java.util.Collection; import java.util.Set; import org.junit.jupiter.api.Nested; @@ -306,6 +307,98 @@ void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final Stor ); } + @Test + void shouldNotInsertWhenFull(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + // Arrange + final Storage storage = new LimitedStorageImpl(100); + storage.insert(A, 95, Action.EXECUTE, EmptyActor.INSTANCE); + activateStorage(storage); + + // Act + final long inserted1 = networkStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + final Collection stored1 = networkStorage.getAll(); + final long inserted2 = networkStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + final Collection stored2 = networkStorage.getAll(); + + // Assert + assertThat(inserted1).isEqualTo(5); + assertThat(stored1).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 100) + ); + + assertThat(inserted2).isZero(); + assertThat(stored2).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 100) + ); + } + + @Test + void shouldNotInsertWhenFullWhenStorageVoidsExcessButIsNotInAllowlistMode( + @InjectNetworkStorageChannel final StorageChannel networkStorage + ) { + // Arrange + final LimitedStorageImpl storage = new LimitedStorageImpl(100); + storage.insert(A, 95, Action.EXECUTE, EmptyActor.INSTANCE); + activateStorage(storage); + + sut.setVoidExcess(true); + + // Act + final long inserted = networkStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(5); + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 100) + ); + } + + @Test + void shouldNotInsertWhenStorageVoidsExcessAndInAllowlistModeWithoutConfiguredFilter( + @InjectNetworkStorageChannel final StorageChannel networkStorage + ) { + // Arrange + final LimitedStorageImpl storage = new LimitedStorageImpl(100); + activateStorage(storage); + + sut.setVoidExcess(true); + sut.setFilterMode(FilterMode.ALLOW); + + // Act + final long inserted = networkStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isZero(); + assertThat(storage.getAll()).isEmpty(); + } + + @Test + void shouldInsertWhenFullWhenStorageVoidsExcessAndIsInAllowlistMode( + @InjectNetworkStorageChannel final StorageChannel networkStorage + ) { + // Arrange + final LimitedStorageImpl storage = new LimitedStorageImpl(100); + storage.insert(A, 95, Action.EXECUTE, EmptyActor.INSTANCE); + activateStorage(storage); + + sut.setVoidExcess(true); + sut.setFilterMode(FilterMode.ALLOW); + sut.setFilters(Set.of(A)); + + // Act + final long inserted1 = networkStorage.insert(A, 3, Action.EXECUTE, EmptyActor.INSTANCE); + final long inserted2 = networkStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedOther = networkStorage.insert(B, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted1).isEqualTo(3); + assertThat(inserted2).isEqualTo(7); + assertThat(insertedOther).isZero(); + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 100) + ); + } + @Test void shouldTrackChanges(@InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/AbstractStorageContainerItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/AbstractStorageContainerItem.java index b36966d29..f82f05397 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/AbstractStorageContainerItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/AbstractStorageContainerItem.java @@ -18,8 +18,6 @@ import net.minecraft.world.level.Level; import org.apiguardian.api.API; -// TODO: Immunity for despawning -// TODO: Tags/ore dict in recipes @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public abstract class AbstractStorageContainerItem extends Item implements StorageContainerItem { protected final StorageContainerItemHelper helper; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceType.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceType.java index ea0b7fde8..a494eb278 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceType.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceType.java @@ -2,6 +2,7 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; import com.refinedmods.refinedstorage2.api.grid.view.GridResource; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; @@ -31,7 +32,7 @@ public interface ResourceType { double getDisplayAmount(long amount); - Optional toGridResource(PlatformResourceKey resource, long amount); + Optional toGridResource(ResourceAmount resourceAmount); boolean isGridResourceBelonging(GridResource gridResource); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java index c61da30ab..eb4bdaa99 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/configurationcard/ConfigurationCardItem.java @@ -32,7 +32,6 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; import static java.util.Objects.requireNonNull; -// TODO: textures public class ConfigurationCardItem extends Item { private static final Component EMPTY_HELP = createTranslation("item", "configuration_card.empty_help"); private static final Component CONFIGURED_HELP = createTranslation("item", "configuration_card.configured_help"); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorScreen.java index c2accdb21..898088838 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorScreen.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.constructordestructor; +import com.refinedmods.refinedstorage2.platform.common.storage.FilterModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.support.AbstractFilterScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; -import com.refinedmods.refinedstorage2.platform.common.support.widget.FilterModeSideButtonWidget; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/KeyMappings.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/KeyMappings.java index 4b102dd6c..4da7ced0e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/KeyMappings.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/KeyMappings.java @@ -28,7 +28,7 @@ public void setFocusSearchBar(final KeyMapping focusSearchBar) { this.focusSearchBar = focusSearchBar; } - @Nullable // TODO - implement on Fabric + @Nullable public KeyMapping getClearCraftingGridMatrixToNetwork() { return clearCraftingGridMatrixToNetwork; } @@ -37,7 +37,7 @@ public void setClearCraftingGridMatrixToNetwork(final KeyMapping clearCraftingGr this.clearCraftingGridMatrixToNetwork = clearCraftingGridMatrixToNetwork; } - @Nullable // TODO - implement on Fabric + @Nullable public KeyMapping getClearCraftingGridMatrixToInventory() { return clearCraftingGridMatrixToInventory; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/CompositeGridResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/CompositeGridResourceFactory.java index 566afc85a..aee3b67d5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/CompositeGridResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/CompositeGridResourceFactory.java @@ -4,7 +4,6 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; -import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import java.util.Optional; @@ -18,12 +17,9 @@ public CompositeGridResourceFactory(final PlatformRegistry resourc @Override public Optional apply(final ResourceAmount resourceAmount) { - if (!(resourceAmount.getResource() instanceof PlatformResourceKey platformResource)) { - return Optional.empty(); - } return resourceTypeRegistry.getAll() .stream() - .flatMap(type -> type.toGridResource(platformResource, resourceAmount.getAmount()).stream()) + .flatMap(type -> type.toGridResource(resourceAmount).stream()) .findFirst(); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterScreen.java index e77a4766b..442e12938 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterScreen.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.importer; +import com.refinedmods.refinedstorage2.platform.common.storage.FilterModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.support.AbstractFilterScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; -import com.refinedmods.refinedstorage2.platform.common.support.widget.FilterModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.support.widget.FuzzyModeSideButtonWidget; import net.minecraft.network.chat.Component; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkCardItem.java index 825ede85c..880c9702f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkCardItem.java @@ -30,7 +30,6 @@ import static com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverKey.getDimensionName; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -// TODO: better active texture. public class NetworkCardItem extends Item { private static final MutableComponent UNBOUND_HELP = createTranslation("item", "network_card.unbound_help"); private static final MutableComponent BOUND_HELP = createTranslation("item", "network_card.bound_help"); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java index 318f7281b..03adbb4bf 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java @@ -35,7 +35,6 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -// TODO: better error texture and better active texture with animation? Reuse controller textures? public class NetworkTransmitterBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity implements ExtendedMenuProvider, BlockEntityWithDrops { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractProgressStorageScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractProgressStorageScreen.java new file mode 100644 index 000000000..264ef8f7b --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractProgressStorageScreen.java @@ -0,0 +1,55 @@ +package com.refinedmods.refinedstorage2.platform.common.storage; + +import com.refinedmods.refinedstorage2.platform.common.support.widget.ProgressWidget; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; + +public abstract class AbstractProgressStorageScreen + extends AbstractStorageScreen { + private final ProgressWidget progressWidget; + + protected AbstractProgressStorageScreen(final T menu, + final Inventory inventory, + final Component title, + final int progressWidgetX) { + super(menu, inventory, title); + this.inventoryLabelY = 129; + this.imageWidth = 176; + this.imageHeight = 223; + this.progressWidget = new ProgressWidget( + progressWidgetX, + 54, + 16, + 70, + menu::getProgress, + this::createProgressTooltip + ); + addRenderableWidget(progressWidget); + } + + private List createProgressTooltip() { + final List tooltip = new ArrayList<>(); + if (menu.hasCapacity()) { + StorageTooltipHelper.addAmountStoredWithCapacity( + tooltip, + menu.getStored(), + menu.getCapacity(), + this::formatQuantity + ); + } else { + StorageTooltipHelper.addAmountStoredWithoutCapacity(tooltip, menu.getStored(), this::formatQuantity); + } + return tooltip; + } + + @Override + protected void renderLabels(final GuiGraphics graphics, final int mouseX, final int mouseY) { + super.renderLabels(graphics, mouseX, mouseY); + progressWidget.render(graphics, mouseX - leftPos, mouseY - topPos, 0); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageContainerMenu.java index 05621e42d..180984395 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageContainerMenu.java @@ -18,6 +18,7 @@ protected AbstractStorageContainerMenu(final MenuType type, final int syncId) registerProperty(new ClientProperty<>(PropertyTypes.FILTER_MODE, FilterMode.BLOCK)); registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); registerProperty(new ClientProperty<>(StoragePropertyTypes.ACCESS_MODE, AccessMode.INSERT_EXTRACT)); + registerProperty(new ClientProperty<>(StoragePropertyTypes.VOID_EXCESS, false)); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } @@ -46,6 +47,11 @@ protected AbstractStorageContainerMenu(final MenuType type, configContainer::getAccessMode, configContainer::setAccessMode )); + registerProperty(new ServerProperty<>( + StoragePropertyTypes.VOID_EXCESS, + configContainer::isVoidExcess, + configContainer::setVoidExcess + )); registerProperty(new ServerProperty<>( PropertyTypes.REDSTONE_MODE, configContainer::getRedstoneMode, @@ -56,4 +62,9 @@ protected AbstractStorageContainerMenu(final MenuType type, boolean shouldDisplayFilterModeWarning() { return getProperty(PropertyTypes.FILTER_MODE).getValue() == FilterMode.ALLOW && areAllResourceSlotsEmpty(); } + + boolean shouldDisplayVoidExcessModeWarning() { + return Boolean.TRUE.equals(getProperty(StoragePropertyTypes.VOID_EXCESS).getValue()) + && getProperty(PropertyTypes.FILTER_MODE).getValue() != FilterMode.ALLOW; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageScreen.java index 63a6e7a76..ee88a303e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AbstractStorageScreen.java @@ -3,53 +3,29 @@ import com.refinedmods.refinedstorage2.platform.api.support.AmountFormatting; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; -import com.refinedmods.refinedstorage2.platform.common.support.widget.FilterModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.support.widget.FuzzyModeSideButtonWidget; -import com.refinedmods.refinedstorage2.platform.common.support.widget.ProgressWidget; import com.refinedmods.refinedstorage2.platform.common.support.widget.RedstoneModeSideButtonWidget; -import java.util.ArrayList; -import java.util.List; import javax.annotation.Nullable; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public abstract class AbstractStorageScreen - extends AbstractBaseScreen { - public static final Component ALLOW_FILTER_MODE_HELP = createTranslation("gui", "storage.filter_mode.allow.help"); - public static final Component BLOCK_FILTER_MODE_HELP = createTranslation("gui", "storage.filter_mode.block.help"); +public abstract class AbstractStorageScreen extends AbstractBaseScreen { + private static final Component ALLOW_FILTER_MODE_HELP = createTranslation("gui", "storage.filter_mode.allow.help"); + private static final Component BLOCK_FILTER_MODE_HELP = createTranslation("gui", "storage.filter_mode.block.help"); - private static final Component FILTER_MODE_WARNING = createTranslation("gui", "storage.filter_mode.empty_warning"); - - private final ProgressWidget progressWidget; private final Inventory playerInventory; @Nullable private FilterModeSideButtonWidget filterModeSideButtonWidget; + @Nullable + private VoidExcessSideButtonWidget voidExcessSideButtonWidget; - protected AbstractStorageScreen(final T menu, - final Inventory inventory, - final Component title, - final int progressWidgetX) { + protected AbstractStorageScreen(final T menu, final Inventory inventory, final Component title) { super(menu, inventory, title); - - this.inventoryLabelY = 129; - this.imageWidth = 176; - this.imageHeight = 223; this.playerInventory = inventory; - - this.progressWidget = new ProgressWidget( - progressWidgetX, - 54, - 16, - 70, - menu::getProgress, - this::createTooltip - ); - addRenderableWidget(progressWidget); } @Override @@ -76,47 +52,24 @@ protected void init() { playerInventory, this )); + voidExcessSideButtonWidget = new VoidExcessSideButtonWidget( + getMenu().getProperty(StoragePropertyTypes.VOID_EXCESS) + ); + addSideButton(voidExcessSideButtonWidget); } @Override protected void containerTick() { super.containerTick(); - updateFilterModeWarning(); - } - - private void updateFilterModeWarning() { - if (filterModeSideButtonWidget == null) { - return; - } - if (getMenu().shouldDisplayFilterModeWarning()) { - filterModeSideButtonWidget.setWarning(FILTER_MODE_WARNING); - return; + if (filterModeSideButtonWidget != null) { + filterModeSideButtonWidget.setWarningVisible(getMenu().shouldDisplayFilterModeWarning()); } - filterModeSideButtonWidget.setWarning(null); - } - - private List createTooltip() { - final List tooltip = new ArrayList<>(); - if (menu.hasCapacity()) { - StorageTooltipHelper.addAmountStoredWithCapacity( - tooltip, - menu.getStored(), - menu.getCapacity(), - this::formatQuantity - ); - } else { - StorageTooltipHelper.addAmountStoredWithoutCapacity(tooltip, menu.getStored(), this::formatQuantity); + if (voidExcessSideButtonWidget != null) { + voidExcessSideButtonWidget.setWarningVisible(getMenu().shouldDisplayVoidExcessModeWarning()); } - return tooltip; } protected String formatQuantity(final long qty) { return AmountFormatting.format(qty); } - - @Override - protected void renderLabels(final GuiGraphics graphics, final int mouseX, final int mouseY) { - super.renderLabels(graphics, mouseX, mouseY); - progressWidget.render(graphics, mouseX - leftPos, mouseY - topPos, 0); - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/FilterModeSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/FilterModeSideButtonWidget.java similarity index 82% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/FilterModeSideButtonWidget.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/FilterModeSideButtonWidget.java index c007cc350..a3f5707b8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/FilterModeSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/FilterModeSideButtonWidget.java @@ -1,7 +1,8 @@ -package com.refinedmods.refinedstorage2.platform.common.support.widget; +package com.refinedmods.refinedstorage2.platform.common.storage; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractSideButtonWidget; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -12,6 +13,7 @@ public class FilterModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "filter_mode"); private static final MutableComponent SUBTEXT_BLOCK = createTranslation("gui", "filter_mode.block"); private static final MutableComponent SUBTEXT_ALLOW = createTranslation("gui", "filter_mode.allow"); + private static final Component FILTER_MODE_WARNING = createTranslation("gui", "storage.filter_mode.empty_warning"); private final ClientProperty property; private final Component helpAllow; @@ -26,6 +28,14 @@ public FilterModeSideButtonWidget(final ClientProperty property, this.helpBlock = helpBlock; } + public void setWarningVisible(final boolean visible) { + if (visible) { + setWarning(FILTER_MODE_WARNING); + } else { + setWarning(null); + } + } + private static OnPress createPressAction(final ClientProperty property) { return btn -> property.setValue(toggle(property.getValue())); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainer.java index 26b181f58..bd3743966 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainer.java @@ -21,6 +21,10 @@ public interface StorageConfigurationContainer { void setAccessMode(AccessMode accessMode); + boolean isVoidExcess(); + + void setVoidExcess(boolean voidExcess); + RedstoneMode getRedstoneMode(); void setRedstoneMode(RedstoneMode redstoneMode); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainerImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainerImpl.java index b74a9f2ca..6ba6f56a8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainerImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageConfigurationContainerImpl.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.storage; -import com.refinedmods.refinedstorage2.api.network.node.StorageConfiguration; +import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; import com.refinedmods.refinedstorage2.platform.common.support.FilterModeSettings; @@ -16,6 +16,7 @@ public final class StorageConfigurationContainerImpl implements StorageConfigura private static final String TAG_PRIORITY = "pri"; private static final String TAG_FILTER_MODE = "fim"; private static final String TAG_ACCESS_MODE = "am"; + private static final String TAG_VOID_EXCESS = "ve"; private final StorageConfiguration config; private final FilterWithFuzzyMode filter; @@ -45,12 +46,16 @@ public void load(final CompoundTag tag) { if (tag.contains(TAG_ACCESS_MODE)) { config.setAccessMode(AccessModeSettings.getAccessMode(tag.getInt(TAG_ACCESS_MODE))); } + if (tag.contains(TAG_VOID_EXCESS)) { + config.setVoidExcess(tag.getBoolean(TAG_VOID_EXCESS)); + } } public void save(final CompoundTag tag) { tag.putInt(TAG_FILTER_MODE, FilterModeSettings.getFilterMode(config.getFilterMode())); tag.putInt(TAG_PRIORITY, config.getPriority()); tag.putInt(TAG_ACCESS_MODE, AccessModeSettings.getAccessMode(config.getAccessMode())); + tag.putBoolean(TAG_VOID_EXCESS, config.isVoidExcess()); } @Override @@ -97,6 +102,17 @@ public void setAccessMode(final AccessMode accessMode) { listener.run(); } + @Override + public boolean isVoidExcess() { + return config.isVoidExcess(); + } + + @Override + public void setVoidExcess(final boolean voidExcess) { + config.setVoidExcess(voidExcess); + listener.run(); + } + @Override public RedstoneMode getRedstoneMode() { return redstoneModeSupplier.get(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StoragePropertyTypes.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StoragePropertyTypes.java index b083228b5..9a0cdfc9a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StoragePropertyTypes.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StoragePropertyTypes.java @@ -10,12 +10,17 @@ public final class StoragePropertyTypes { public static final PropertyType PRIORITY = PropertyTypes.createIntegerProperty( createIdentifier("priority") ); + public static final PropertyType ACCESS_MODE = new PropertyType<>( createIdentifier("access_mode"), AccessModeSettings::getAccessMode, AccessModeSettings::getAccessMode ); + public static final PropertyType VOID_EXCESS = PropertyTypes.createBooleanProperty( + createIdentifier("void_excess") + ); + private StoragePropertyTypes() { } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/VoidExcessSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/VoidExcessSideButtonWidget.java new file mode 100644 index 000000000..7bbbadd5e --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/VoidExcessSideButtonWidget.java @@ -0,0 +1,46 @@ +package com.refinedmods.refinedstorage2.platform.common.storage; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractYesNoSideButtonWidget; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +public class VoidExcessSideButtonWidget extends AbstractYesNoSideButtonWidget { + private static final Component HELP = createTranslation("gui", "void_excess.help"); + private static final Component ALLOWLIST_WARNING = createTranslation( + "gui", + "void_excess.allowlist_warning" + ); + + public VoidExcessSideButtonWidget(final ClientProperty property) { + super(property, createTranslation("gui", "void_excess")); + } + + public void setWarningVisible(final boolean visible) { + if (visible) { + setWarning(ALLOWLIST_WARNING); + } else { + setWarning(null); + } + } + + @Override + protected int getXTexture() { + return Boolean.TRUE.equals(property.getValue()) ? 16 : 0; + } + + @Override + protected int getYTexture() { + return 240 - 15; + } + + @Override + @Nullable + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveScreen.java index 62d0c0c06..db7199f8d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/DiskDriveScreen.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.storage.diskdrive; -import com.refinedmods.refinedstorage2.platform.common.storage.AbstractStorageScreen; +import com.refinedmods.refinedstorage2.platform.common.storage.AbstractProgressStorageScreen; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; @@ -11,7 +11,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class DiskDriveScreen extends AbstractStorageScreen { +public class DiskDriveScreen extends AbstractProgressStorageScreen { private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/disk_drive.png"); private static final MutableComponent DISKS_TEXT = createTranslation("gui", "disk_drive.disks"); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageScreen.java index 8409b7575..a438c7b46 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageScreen.java @@ -1,44 +1,24 @@ package com.refinedmods.refinedstorage2.platform.common.storage.externalstorage; import com.refinedmods.refinedstorage2.platform.common.storage.AbstractStorageScreen; -import com.refinedmods.refinedstorage2.platform.common.storage.AccessModeSideButtonWidget; -import com.refinedmods.refinedstorage2.platform.common.storage.PrioritySideButtonWidget; -import com.refinedmods.refinedstorage2.platform.common.storage.StoragePropertyTypes; import com.refinedmods.refinedstorage2.platform.common.support.AbstractFilterScreen; -import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; -import com.refinedmods.refinedstorage2.platform.common.support.widget.FilterModeSideButtonWidget; -import com.refinedmods.refinedstorage2.platform.common.support.widget.FuzzyModeSideButtonWidget; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; -public class ExternalStorageScreen extends AbstractFilterScreen { - private final Inventory playerInventory; - +public class ExternalStorageScreen extends AbstractStorageScreen { public ExternalStorageScreen(final ExternalStorageContainerMenu menu, final Inventory inventory, final Component title) { super(menu, inventory, title); - this.playerInventory = inventory; + this.inventoryLabelY = 42; + this.imageWidth = 210; + this.imageHeight = 137; } @Override - protected void init() { - super.init(); - addSideButton(new FilterModeSideButtonWidget( - getMenu().getProperty(PropertyTypes.FILTER_MODE), - AbstractStorageScreen.ALLOW_FILTER_MODE_HELP, - AbstractStorageScreen.BLOCK_FILTER_MODE_HELP - )); - addSideButton(new FuzzyModeSideButtonWidget( - getMenu().getProperty(PropertyTypes.FUZZY_MODE), - FuzzyModeSideButtonWidget.Type.STORAGE - )); - addSideButton(new AccessModeSideButtonWidget(getMenu().getProperty(StoragePropertyTypes.ACCESS_MODE))); - addSideButton(new PrioritySideButtonWidget( - getMenu().getProperty(StoragePropertyTypes.PRIORITY), - playerInventory, - this - )); + protected ResourceLocation getTexture() { + return AbstractFilterScreen.TEXTURE; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockScreen.java index e27f88ae4..de5599501 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockScreen.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.storage.storageblock; -import com.refinedmods.refinedstorage2.platform.common.storage.AbstractStorageScreen; +import com.refinedmods.refinedstorage2.platform.common.storage.AbstractProgressStorageScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -8,7 +8,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -abstract class AbstractStorageBlockScreen extends AbstractStorageScreen { +abstract class AbstractStorageBlockScreen extends AbstractProgressStorageScreen { private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/storage.png"); protected AbstractStorageBlockScreen(final AbstractStorageBlockContainerMenu menu, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java index dd47a7d05..86ea9e9c6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java @@ -10,7 +10,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; public abstract class AbstractFilterScreen extends AbstractBaseScreen { - private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/generic_filter.png"); + public static final ResourceLocation TEXTURE = createIdentifier("textures/gui/generic_filter.png"); protected AbstractFilterScreen(final T menu, final Inventory playerInventory, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java index 1890368bd..ebffd0c75 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java index 68a1f934f..565fe7567 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.configurationcard.ConfigurationCardTarget; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.support.PlayerAwareBlockEntity; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java index 069b38d6f..d89138423 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.common.support.FilterWithFuzzyMode; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java index 24c922e1d..3746b213e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.support.BlockEntityWithDrops; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java index b2077a117..37cfc37af 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBlockEntityTicker; import java.util.function.Supplier; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java index 8c5e0ec63..0ee9dbf3f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.network.AbstractNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceType.java index a727aab96..7f5b06582 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceType.java @@ -37,8 +37,8 @@ public PlatformResourceKey fromBuffer(final FriendlyByteBuf buf) { } @Override - public Optional toGridResource(final PlatformResourceKey resource, final long amount) { - return Platform.INSTANCE.getFluidGridResourceFactory().apply(new ResourceAmount(resource, amount)); + public Optional toGridResource(final ResourceAmount resourceAmount) { + return Platform.INSTANCE.getFluidGridResourceFactory().apply(resourceAmount); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceType.java index 81887897c..468f64636 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceType.java @@ -37,8 +37,8 @@ public ItemResource fromBuffer(final FriendlyByteBuf buf) { } @Override - public Optional toGridResource(final PlatformResourceKey resource, final long amount) { - return Platform.INSTANCE.getItemGridResourceFactory().apply(new ResourceAmount(resource, amount)); + public Optional toGridResource(final ResourceAmount resourceAmount) { + return Platform.INSTANCE.getItemGridResourceFactory().apply(resourceAmount); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/SchedulingModeSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/SchedulingModeSideButtonWidget.java index f504d48fd..8111e68ee 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/SchedulingModeSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/SchedulingModeSideButtonWidget.java @@ -8,7 +8,6 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -// TODO: Textures! public class SchedulingModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "scheduling_mode"); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RangeUpgradeItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RangeUpgradeItem.java index c151a645c..387fcf51a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RangeUpgradeItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RangeUpgradeItem.java @@ -6,7 +6,6 @@ import net.minecraft.world.item.Item; -// TODO: improved creative texture. public class RangeUpgradeItem extends AbstractUpgradeItem { private final boolean creative; diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json index 08acc2fcb..0e58472c8 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json @@ -129,6 +129,9 @@ "gui.refinedstorage2.access_mode.insert.help": "The storage network will only be able to insert into this storage. Contained resources will still be visible in a Grid.", "gui.refinedstorage2.access_mode.extract": "Extract only", "gui.refinedstorage2.access_mode.extract.help": "The storage network will only be able to extract from this storage.", + "gui.refinedstorage2.void_excess": "Void excess resources", + "gui.refinedstorage2.void_excess.help": "When void excess mode is turned on and the storage is full, it will keep accepting resources but void them.", + "gui.refinedstorage2.void_excess.allowlist_warning": "Void excess will only work when the storage is in allowlist mode.", "gui.refinedstorage2.upgrade_slot": "Empty upgrade slot", "gui.refinedstorage2.filter_slot.empty_filter": "Empty filter", "gui.refinedstorage2.filter_slot.left_click_for": "Left click for", diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png index 871a7fecf..340761a2d 100644 Binary files a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png differ diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java index 9f77de1ef..19f428e00 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java @@ -1,5 +1,8 @@ package com.refinedmods.refinedstorage2.api.storage.composite; +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; import org.apiguardian.api.API; @@ -8,6 +11,8 @@ * Implement this on storages that need to be aware of the fact that they are contained in a {@link CompositeStorage}. * Typically, this is needed so that storages that dynamically modify their underlying storage sources, can propagate * the changes to the parent composite list. + * Another reason to be aware of the parent composite is to be able to override the amount modified into the composite + * cache list. */ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.4") public interface CompositeAwareChild extends Storage { @@ -24,4 +29,38 @@ public interface CompositeAwareChild extends Storage { * @param parentComposite the composite storage that this {@link CompositeAwareChild} is/was contained in */ void onRemovedFromComposite(ParentComposite parentComposite); + + /** + * Inserts a resource into a storage. + * + * @param resource the resource, may not be null + * @param amount the amount, must be larger than 0 + * @param action the mode of insertion + * @param actor the source + * @return the amount inserted + */ + Amount compositeInsert(ResourceKey resource, long amount, Action action, Actor actor); + + /** + * Extracts a resource from a storage. + * + * @param resource the resource, may not be null + * @param amount the amount, must be larger than 0 + * @param action the mode of extraction + * @param actor the source + * @return the amount extracted + */ + Amount compositeExtract(ResourceKey resource, long amount, Action action, Actor actor); + + /** + * @param amount the amount + * @param amountForList the amount to be modified in the parent composite cache list + */ + record Amount(long amount, long amountForList) { + public static final Amount ZERO = new Amount(0, 0); + + public Amount withoutNotifyingList() { + return new Amount(amount, 0); + } + } } diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java index fb46c3af7..21fe2ea9a 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java @@ -79,11 +79,15 @@ public long extract(final ResourceKey resource, final long amount, final Action long remaining = amount; long toRemoveFromList = 0; for (final Storage source : sources) { - final long extractedFromSource = source.extract(resource, remaining, action, actor); - if (!(source instanceof ConsumingStorage)) { - toRemoveFromList += extractedFromSource; + if (source instanceof CompositeAwareChild compositeAwareChild) { + final Amount extracted = compositeAwareChild.compositeExtract(resource, remaining, action, actor); + remaining -= extracted.amount(); + toRemoveFromList += extracted.amountForList(); + } else { + final long extracted = source.extract(resource, remaining, action, actor); + remaining -= extracted; + toRemoveFromList += extracted; } - remaining -= extractedFromSource; if (remaining == 0) { break; } @@ -100,11 +104,20 @@ public long insert(final ResourceKey resource, final long amount, final Action a long inserted = 0; long toInsertIntoList = 0; for (final Storage source : sources) { - final long insertedIntoSource = source.insert(resource, amount - inserted, action, actor); - if (!(source instanceof ConsumingStorage)) { - toInsertIntoList += insertedIntoSource; + if (source instanceof CompositeAwareChild compositeAwareChild) { + final Amount insertedAmount = compositeAwareChild.compositeInsert( + resource, + amount - inserted, + action, + actor + ); + inserted += insertedAmount.amount(); + toInsertIntoList += insertedAmount.amountForList(); + } else { + final long insertedAmount = source.insert(resource, amount - inserted, action, actor); + inserted += insertedAmount; + toInsertIntoList += insertedAmount; } - inserted += insertedIntoSource; if (inserted == amount) { break; } @@ -146,6 +159,22 @@ public void onRemovedFromComposite(final ParentComposite parentComposite) { parentComposites.remove(parentComposite); } + @Override + public Amount compositeInsert(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + throw new UnsupportedOperationException(); + } + + @Override + public Amount compositeExtract(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + throw new UnsupportedOperationException(); + } + @Override public void onSourceAddedToChild(final Storage source) { addContentOfSourceToList(source); diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorage.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorage.java deleted file mode 100644 index 284f9ca7f..000000000 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorage.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.refinedmods.refinedstorage2.api.storage.composite; - -import com.refinedmods.refinedstorage2.api.storage.Storage; - -import org.apiguardian.api.API; - -/** - * A consuming storage is a storage that won't cause changes to be propagated in the {@link CompositeStorage} cache. - */ -@API(status = API.Status.STABLE, since = "2.0.0-milestone.1.4") -public interface ConsumingStorage extends Storage { -} diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ParentComposite.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ParentComposite.java index 2e6847945..65bf96361 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ParentComposite.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ParentComposite.java @@ -28,7 +28,6 @@ public interface ParentComposite { /** * Adds a resource to the composite storage cache. - * Useful for the {@link ConsumingStorage} to propagate changes manually. * * @param resource the resource * @param amount the amount @@ -37,7 +36,6 @@ public interface ParentComposite { /** * Removes a resource from the composite storage cache. - * Useful for the {@link ConsumingStorage} to propagate changes manually. * * @param resource the resource * @param amount the amount diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/external/ExternalStorage.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/external/ExternalStorage.java index 6195eb7fe..feb518341 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/external/ExternalStorage.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/external/ExternalStorage.java @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild; -import com.refinedmods.refinedstorage2.api.storage.composite.ConsumingStorage; import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite; import java.util.Collection; @@ -18,7 +17,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") -public class ExternalStorage implements ConsumingStorage, CompositeAwareChild { +public class ExternalStorage implements CompositeAwareChild { private final ExternalStorageProvider provider; private final Set parents = new HashSet<>(); private final ResourceList cache = new ResourceListImpl(); @@ -136,4 +135,22 @@ public void onAddedIntoComposite(final ParentComposite parentComposite) { public void onRemovedFromComposite(final ParentComposite parentComposite) { parents.remove(parentComposite); } + + @Override + public Amount compositeInsert(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + final long inserted = insert(resource, amount, action, actor); + return new Amount(inserted, 0); + } + + @Override + public Amount compositeExtract(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + final long extracted = extract(resource, amount, action, actor); + return new Amount(extracted, 0); + } } diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageCompositeStorageImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageCompositeStorageImplTest.java deleted file mode 100644 index 13fa6cca2..000000000 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageCompositeStorageImplTest.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.refinedmods.refinedstorage2.api.storage.composite; - -import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; -import com.refinedmods.refinedstorage2.api.storage.EmptyActor; -import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static com.refinedmods.refinedstorage2.api.storage.TestResource.A; -import static org.assertj.core.api.Assertions.assertThat; - -class ConsumingStorageCompositeStorageImplTest { - private CompositeStorageImpl sut; - - @BeforeEach - void setUp() { - sut = new CompositeStorageImpl(new ResourceListImpl()); - } - - @Test - void shouldLoadResourcesFromConsumingStorageWhenAddingSource() { - // Arrange - final ConsumingStorageImpl consumingStorage = new ConsumingStorageImpl(); - consumingStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - - // Act - sut.addSource(consumingStorage); - - // Assert - assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( - new ResourceAmount(A, 10) - ); - assertThat(sut.getStored()).isEqualTo(10); - } - - @Test - void shouldRemoveResourcesFromConsumingStorageWhenRemovingSource() { - // Arrange - final ConsumingStorageImpl consumingStorage = new ConsumingStorageImpl(); - consumingStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - sut.addSource(consumingStorage); - - // Act - sut.removeSource(consumingStorage); - - // Assert - assertThat(sut.getAll()).isEmpty(); - assertThat(sut.getStored()).isZero(); - } - - @Test - void shouldInsertResourceEntirelyIntoConsumingStorage() { - // Arrange - sut.addSource(new ConsumingStorageImpl()); - - // Act - final long inserted = sut.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - - // Assert - assertThat(inserted).isEqualTo(10); - assertThat(sut.getAll()).isEmpty(); - assertThat(sut.getStored()).isEqualTo(10); - } - - @Test - void shouldInsertPartlyEntirelyIntoConsumingStorage() { - // Arrange - sut.addSource(new PrioritizedStorage(10, new LimitedStorageImpl(7))); - sut.addSource(new ConsumingStorageImpl()); - - // Act - final long inserted = sut.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - - // Assert - assertThat(inserted).isEqualTo(10); - assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( - new ResourceAmount(A, 7) - ); - assertThat(sut.getStored()).isEqualTo(10); - } - - @Test - void shouldExtractResourceEntirelyFromConsumingStorage() { - // Arrange - sut.addSource(new ConsumingStorageImpl()); - sut.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - - // Act - final long extracted = sut.extract(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - - // Assert - assertThat(extracted).isEqualTo(10); - assertThat(sut.getAll()).isEmpty(); - assertThat(sut.getStored()).isZero(); - } - - @Test - void shouldExtractResourcePartlyFromConsumingStorage() { - // Arrange - sut.addSource(new PrioritizedStorage(10, new LimitedStorageImpl(7))); - sut.addSource(new ConsumingStorageImpl()); - sut.insert(A, 8, Action.EXECUTE, EmptyActor.INSTANCE); - - // Act - final long extracted = sut.extract(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - - // Assert - assertThat(extracted).isEqualTo(8); - assertThat(sut.getAll()).isEmpty(); - assertThat(sut.getStored()).isZero(); - } -} diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageImpl.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageImpl.java deleted file mode 100644 index bfb5be74f..000000000 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.refinedmods.refinedstorage2.api.storage.composite; - -import com.refinedmods.refinedstorage2.api.storage.AbstractProxyStorage; -import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; - -class ConsumingStorageImpl extends AbstractProxyStorage implements ConsumingStorage { - ConsumingStorageImpl() { - super(new InMemoryStorageImpl()); - } -}