From bbde868ec97f1d27e158414e1046318ec36e6276 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 18 Feb 2024 10:41:10 +0100 Subject: [PATCH] feat: void excess mode Only available in allowlist mode to avoid people trashing all their resources without realizing it and blaming Refined Storage. The void excess mode logic will only work when the resource was accepted through the filter, otherwise, a next storage is used instead. Requiring allowlist mode requires the player to think explicitly about the resources to be trashed. --- CHANGELOG.md | 4 + build.gradle | 15 ++- .../node/AbstractConfiguredProxyStorage.java | 43 +++++-- .../node/AbstractStorageNetworkNode.java | 12 +- .../network/node/StorageConfiguration.java | 12 ++ .../ExposedExternalStorage.java | 23 +++- .../multistorage/ExposedMultiStorage.java | 3 +- .../impl/node/storage/ExposedStorage.java | 4 +- .../storage/AbstractStorageContainerItem.java | 2 - .../api/support/resource/ResourceType.java | 3 +- .../ConfigurationCardItem.java | 1 - .../DestructorScreen.java | 2 +- .../platform/common/content/KeyMappings.java | 4 +- .../view/CompositeGridResourceFactory.java | 6 +- .../common/importer/ImporterScreen.java | 2 +- .../common/networking/NetworkCardItem.java | 1 - .../NetworkTransmitterBlockEntity.java | 1 - .../storage/AbstractStorageContainerMenu.java | 11 ++ .../common/storage/AbstractStorageScreen.java | 23 ++-- .../FilterModeSideButtonWidget.java | 12 +- .../StorageConfigurationContainer.java | 4 + .../StorageConfigurationContainerImpl.java | 16 +++ .../common/storage/StoragePropertyTypes.java | 5 + .../storage/VoidExcessSideButtonWidget.java | 46 +++++++ .../ExternalStorageScreen.java | 30 ++++- .../support/resource/FluidResourceType.java | 4 +- .../support/resource/ItemResourceType.java | 4 +- .../SchedulingModeSideButtonWidget.java | 1 - .../common/upgrade/RangeUpgradeItem.java | 1 - .../assets/refinedstorage2/lang/en_us.json | 3 + .../assets/refinedstorage2/textures/icons.png | Bin 7647 -> 4278 bytes .../composite/CompositeAwareChild.java | 39 ++++++ .../composite/CompositeStorageImpl.java | 45 +++++-- .../storage/composite/ConsumingStorage.java | 12 -- .../storage/composite/ParentComposite.java | 2 - .../api/storage/external/ExternalStorage.java | 21 +++- ...sumingStorageCompositeStorageImplTest.java | 115 ------------------ .../composite/ConsumingStorageImpl.java | 10 -- 38 files changed, 326 insertions(+), 216 deletions(-) rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{support/widget => storage}/FilterModeSideButtonWidget.java (79%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/VoidExcessSideButtonWidget.java delete mode 100644 refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorage.java delete mode 100644 refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageCompositeStorageImplTest.java delete mode 100644 refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ConsumingStorageImpl.java 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-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractConfiguredProxyStorage.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractConfiguredProxyStorage.java index d40723398..756161ab5 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractConfiguredProxyStorage.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractConfiguredProxyStorage.java @@ -4,9 +4,10 @@ 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/AbstractStorageNetworkNode.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractStorageNetworkNode.java index 2fcb85df7..a42c2b233 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractStorageNetworkNode.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/AbstractStorageNetworkNode.java @@ -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-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/StorageConfiguration.java index 9647a18e8..c35e67ce7 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/StorageConfiguration.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/StorageConfiguration.java @@ -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/node/externalstorage/ExposedExternalStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExposedExternalStorage.java index 438534771..13c742cac 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.core.Action; import com.refinedmods.refinedstorage2.api.network.node.AbstractConfiguredProxyStorage; import com.refinedmods.refinedstorage2.api.network.node.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/multistorage/ExposedMultiStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java index 76e1e2715..8823d63d8 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 @@ -6,7 +6,6 @@ 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/storage/ExposedStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/ExposedStorage.java index 1724bba1c..ec336c7ee 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 @@ -5,7 +5,6 @@ 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-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/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..f61bb38e2 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,7 +3,6 @@ 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; @@ -23,12 +22,12 @@ public abstract class AbstractStorageScreen createTooltip() { 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 79% 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..ac62f0af6 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 updateWarning(final AbstractStorageContainerMenu storageContainerMenu) { + if (storageContainerMenu.shouldDisplayFilterModeWarning()) { + 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..f7f50691b 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 @@ -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..4915e82ce --- /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 updateWarning(final AbstractStorageContainerMenu storageContainerMenu) { + if (storageContainerMenu.shouldDisplayVoidExcessModeWarning()) { + 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/externalstorage/ExternalStorageScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageScreen.java index 8409b7575..3179e632f 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 @@ -2,19 +2,27 @@ import com.refinedmods.refinedstorage2.platform.common.storage.AbstractStorageScreen; import com.refinedmods.refinedstorage2.platform.common.storage.AccessModeSideButtonWidget; +import com.refinedmods.refinedstorage2.platform.common.storage.FilterModeSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.storage.PrioritySideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.storage.StoragePropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.storage.VoidExcessSideButtonWidget; 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 javax.annotation.Nullable; + import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; public class ExternalStorageScreen extends AbstractFilterScreen { private final Inventory playerInventory; + @Nullable + private FilterModeSideButtonWidget filterModeSideButtonWidget; + @Nullable + private VoidExcessSideButtonWidget voidExcessSideButtonWidget; + public ExternalStorageScreen(final ExternalStorageContainerMenu menu, final Inventory inventory, final Component title) { @@ -25,11 +33,12 @@ public ExternalStorageScreen(final ExternalStorageContainerMenu menu, @Override protected void init() { super.init(); - addSideButton(new FilterModeSideButtonWidget( + filterModeSideButtonWidget = new FilterModeSideButtonWidget( getMenu().getProperty(PropertyTypes.FILTER_MODE), AbstractStorageScreen.ALLOW_FILTER_MODE_HELP, AbstractStorageScreen.BLOCK_FILTER_MODE_HELP - )); + ); + addSideButton(filterModeSideButtonWidget); addSideButton(new FuzzyModeSideButtonWidget( getMenu().getProperty(PropertyTypes.FUZZY_MODE), FuzzyModeSideButtonWidget.Type.STORAGE @@ -40,5 +49,20 @@ protected void init() { playerInventory, this )); + voidExcessSideButtonWidget = new VoidExcessSideButtonWidget( + getMenu().getProperty(StoragePropertyTypes.VOID_EXCESS) + ); + addSideButton(voidExcessSideButtonWidget); + } + + @Override + protected void containerTick() { + super.containerTick(); + if (filterModeSideButtonWidget != null) { + filterModeSideButtonWidget.updateWarning(getMenu()); + } + if (voidExcessSideButtonWidget != null) { + voidExcessSideButtonWidget.updateWarning(getMenu()); + } } } 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 871a7fecf1d11ad52d62462a14b224f1b997c214..340761a2dea262046fa2e731eca94546562132b2 100644 GIT binary patch literal 4278 zcmYjUc{mi@+di`xOO~O2D2bR*vP3BB$S6aW5O0>DH?oK56~)Yuy+Tt-ws{McHA0NN zvP3bqFxIk+CC1p7VZP~l|M|`zXSuHDI?uVD<-YF|Z)I^wfbR$&06+k1g0Thw!r4Lq z4}!Be-F|zMv%rHcU~PFg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v6q0bwZ}sL6<(c7Yb} z<_M9K@8blU%|30!jXg)bq45jxtjl0e)0cx?g&O#X#c=VSM zQdlC3k1XtLv&J?%1@04q_Z}d~bNmF{MNdHC5=gBuz7cujvb^uhcZOu7!=?pvNI0KK zremvA^9!)!w-7Y~rZPmN5KrzsK6Qdt}V~atD6L!sKX7l#qv`Q^~PwO7-5^99R2+EF8xgTBw{7_!J1aE zM_OXZ7$BZfb59wLxJFELhE`WZq?KzTn*}=zwd%0>6|@CC(Dr?;5cQ=Qh}s{G0}1bS1@a(oY{fz?@U;>1b<3kQ z8iwL`p%gNa&sqLWCL~1Y(yBZs`Hvh|NYIwk)jN%mY{{Z>A BvMm4r 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()); - } -}