diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java index f0ffcc3a5..c32013a72 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java @@ -9,6 +9,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.component.EnergyNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.impl.component.StorageNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; public final class NetworkTestFixtures { public static final ComponentMapFactory NETWORK_COMPONENT_MAP_FACTORY = @@ -25,7 +26,7 @@ public final class NetworkTestFixtures { ); NETWORK_COMPONENT_MAP_FACTORY.addFactory( StorageNetworkComponent.class, - network -> new StorageNetworkComponentImpl() + network -> new StorageNetworkComponentImpl(new ResourceListImpl()) ); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImpl.java index 12c16a5d7..27f9c57a3 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImpl.java @@ -17,10 +17,7 @@ public class StorageNetworkComponentImpl extends StorageChannelImpl implements StorageNetworkComponent { private static final Logger LOGGER = LoggerFactory.getLogger(StorageNetworkComponentImpl.class); - public StorageNetworkComponentImpl() { - } - - protected StorageNetworkComponentImpl(final ResourceList list) { + public StorageNetworkComponentImpl(final ResourceList list) { super(list); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/CompositeExporterTransferStrategy.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/CompositeExporterTransferStrategy.java index fccf71623..354647488 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/CompositeExporterTransferStrategy.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/CompositeExporterTransferStrategy.java @@ -23,11 +23,4 @@ public boolean transfer(final ResourceKey resource, final Actor actor, final Net } return false; } - - @Override - public String toString() { - return "CompositeExporterTransferStrategy{" - + "strategies=" + strategies - + '}'; - } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/CompositeImporterTransferStrategy.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/CompositeImporterTransferStrategy.java deleted file mode 100644 index 35d6d9014..000000000 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/CompositeImporterTransferStrategy.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.refinedmods.refinedstorage2.api.network.impl.node.importer; - -import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; -import com.refinedmods.refinedstorage2.api.resource.filter.Filter; -import com.refinedmods.refinedstorage2.api.storage.Actor; - -import java.util.Collections; -import java.util.List; - -public class CompositeImporterTransferStrategy implements ImporterTransferStrategy { - private final List strategies; - - public CompositeImporterTransferStrategy(final List strategies) { - this.strategies = Collections.unmodifiableList(strategies); - } - - @Override - public boolean transfer(final Filter filter, final Actor actor, final Network network) { - for (final ImporterTransferStrategy strategy : strategies) { - if (strategy.transfer(filter, actor, network)) { - return true; - } - } - return false; - } - - @Override - public String toString() { - return "CompositeImporterTransferStrategy{" - + "strategies=" + strategies - + '}'; - } -} 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 537316c90..dacbe7b16 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 @@ -8,32 +8,37 @@ import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.Actor; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.function.UnaryOperator; -import javax.annotation.Nullable; public class ImporterNetworkNode extends AbstractNetworkNode { private long energyUsage; private final Filter filter = new Filter(); private final Actor actor = new NetworkNodeActor(this); - @Nullable - private ImporterTransferStrategy transferStrategy; + private final List transferStrategies = new ArrayList<>(); public ImporterNetworkNode(final long energyUsage) { this.energyUsage = energyUsage; } - public void setTransferStrategy(@Nullable final ImporterTransferStrategy transferStrategy) { - this.transferStrategy = transferStrategy; + public void setTransferStrategies(final List transferStrategies) { + this.transferStrategies.clear(); + this.transferStrategies.addAll(transferStrategies); } @Override public void doWork() { super.doWork(); - if (network == null || !isActive() || transferStrategy == null) { + if (network == null || !isActive()) { return; } - transferStrategy.transfer(filter, actor, network); + for (final ImporterTransferStrategy transferStrategy : transferStrategies) { + if (transferStrategy.transfer(filter, actor, network)) { + return; + } + } } public FilterMode getFilterMode() { diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterSource.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterSource.java similarity index 92% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterSource.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterSource.java index a2fff4aa8..d7d1a97ff 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterSource.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterSource.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.network.node.importer; +package com.refinedmods.refinedstorage2.api.network.impl.node.importer; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterTransferStrategyImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterTransferStrategyImpl.java similarity index 95% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterTransferStrategyImpl.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterTransferStrategyImpl.java index 4a9e15a64..eaf157014 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterTransferStrategyImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterTransferStrategyImpl.java @@ -1,7 +1,8 @@ -package com.refinedmods.refinedstorage2.api.network.node.importer; +package com.refinedmods.refinedstorage2.api.network.impl.node.importer; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.Filter; import com.refinedmods.refinedstorage2.api.storage.Actor; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImplTest.java index b8267db73..c4720c52e 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImplTest.java @@ -6,6 +6,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; 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.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; @@ -35,7 +36,7 @@ class StorageNetworkComponentImplTest { @BeforeEach void setUp() { - sut = new StorageNetworkComponentImpl(); + sut = new StorageNetworkComponentImpl(new ResourceListImpl()); storage1 = new StorageNetworkNode(0); storage1.setNetwork(new NetworkImpl(NetworkTestFixtures.NETWORK_COMPONENT_MAP_FACTORY)); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/CompositeEnergyStorageTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/CompositeEnergyStorageTest.java index f26aa3d39..e8eeb4ad3 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/CompositeEnergyStorageTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/CompositeEnergyStorageTest.java @@ -3,6 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -340,4 +341,26 @@ void shouldExtractFromMultipleSourcesCompletelyMoreThanIsAvailable(final Action assertThat(sut.getCapacity()).isEqualTo(15); } + + @Test + void shouldNotExceedLongMax() { + // Arrange + final EnergyStorage a = new EnergyStorageImpl(Long.MAX_VALUE); + final EnergyStorage b = new EnergyStorageImpl(Long.MAX_VALUE); + + a.receive(Long.MAX_VALUE, Action.EXECUTE); + b.receive(Long.MAX_VALUE, Action.EXECUTE); + + final CompositeEnergyStorage sut = new CompositeEnergyStorage(); + sut.addSource(a); + sut.addSource(b); + + // Act + final long stored = sut.getStored(); + final long capacity = sut.getCapacity(); + + // Assert + assertThat(stored).isEqualTo(Long.MAX_VALUE); + assertThat(capacity).isEqualTo(Long.MAX_VALUE); + } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/ListeningEnergyStorageTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/ListeningEnergyStorageTest.java index 021af128e..de8f4165d 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/ListeningEnergyStorageTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/ListeningEnergyStorageTest.java @@ -136,4 +136,21 @@ void shouldExtractEnergyCompletely(final Action action) { assertThat(changeCount).isZero(); } } + + @ParameterizedTest + @EnumSource(Action.class) + void shouldNotExtractEnergyWhenThereIsNone(final Action action) { + // Arrange + sut.receive(100, Action.EXECUTE); + sut.extract(100, Action.EXECUTE); + changeCount = 0; + + // Act + final long extracted = sut.extract(1, action); + + // Assert + assertThat(extracted).isZero(); + assertThat(sut.getStored()).isZero(); + assertThat(changeCount).isZero(); + } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java index 3789625df..e8f24c153 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java @@ -5,6 +5,8 @@ import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; @@ -58,22 +60,62 @@ void shouldUseFirstSuccessfulStrategy( // Arrange storageChannel.addSource(new InMemoryStorageImpl()); storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + final Storage failingDestination = new LimitedStorageImpl(0); final Storage destination = new LimitedStorageImpl(100); sut.setTransferStrategy(new CompositeExporterTransferStrategy(List.of( - createTransferStrategy(destination, 10), + createTransferStrategy(failingDestination, 10), createTransferStrategy(destination, 10), createTransferStrategy(destination, 10) ))); - sut.setFilters(List.of(A)); + sut.setFilters(List.of(A, B)); // Act sut.doWork(); // Assert assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( - new ResourceAmount(A, 90) + new ResourceAmount(A, 90), + new ResourceAmount(B, 100) + ); + assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10) + ); + } + + @Test + void shouldUseFirstSuccessfulResourceInTheStrategy( + @InjectNetworkStorageChannel final StorageChannel storageChannel + ) { + // Arrange + storageChannel.addSource(new InMemoryStorageImpl()); + storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + + final Storage destination = new LimitedStorageImpl(100) { + @Override + public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { + if (resource != A) { + return 0; + } + return super.insert(resource, amount, action, actor); + } + }; + + sut.setTransferStrategy(new CompositeExporterTransferStrategy(List.of( + createTransferStrategy(destination, 10) + ))); + sut.setFilters(List.of(B, A)); + + // Act + sut.doWork(); + + // Assert + assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 90), + new ResourceAmount(B, 100) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10) diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/FakeImporterSource.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/FakeImporterSource.java index 8986a626d..463d52f00 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/FakeImporterSource.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/FakeImporterSource.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.importer; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java index 7357f5a38..870b03c00 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; @@ -65,7 +64,7 @@ void shouldExtractEnergy( } @Test - void shouldNotWorkWithoutTransferStrategy( + void shouldNotWorkWithoutAnyTransferStrategy( @InjectNetworkStorageChannel final StorageChannel storageChannel, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { @@ -96,7 +95,7 @@ void shouldNotWorkOrExtractEnergyWithoutBeingActive( .add(A, 100) .add(B, 100); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); sut.setActive(false); // Act @@ -120,7 +119,7 @@ void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChann .add(A, 100) .add(B, 100); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -143,16 +142,20 @@ void shouldUseFirstSuccessfulTransferStrategy( storageChannel.addSource(new InMemoryStorageImpl()); final FakeImporterSource emptySource = new FakeImporterSource(); - + final FakeImporterSource outdatedSource = new FakeImporterSource(C) + .add(C, 100); final FakeImporterSource source = new FakeImporterSource(A, B, A) .add(A, 100) .add(B, 100); - sut.setTransferStrategy(new CompositeImporterTransferStrategy(List.of( + sut.setTransferStrategies(List.of( + new ImporterTransferStrategyImpl(outdatedSource, 1) + )); + sut.setTransferStrategies(List.of( new ImporterTransferStrategyImpl(emptySource, 1), new ImporterTransferStrategyImpl(source, 1), new ImporterTransferStrategyImpl(source, 1) - ))); + )); // Act sut.doWork(); @@ -179,7 +182,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheNetwork( .add(A, 100) .add(B, 100); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -205,7 +208,7 @@ void testTransferDifferentResourceOverMultipleSlots( .add(A, 11) .add(B, 6); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -232,7 +235,7 @@ void testTransferSameResourceOverMultipleSlots( .add(B, 5); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -266,7 +269,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a .add(A, 8) .add(B, 11); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -290,7 +293,7 @@ void testTransferWithoutAnyResourcesInSource( final FakeImporterSource source = new FakeImporterSource(); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -313,7 +316,7 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel st .add(A, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -350,7 +353,7 @@ void shouldRespectAllowlistWithNormalizer( .add(A_ALTERNATIVE2, 1); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -380,7 +383,7 @@ void shouldRespectAllowlistWithoutAlternative( .add(B, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -405,7 +408,7 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChann .add(A, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -431,7 +434,7 @@ void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel st .add(B, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -460,7 +463,7 @@ void shouldRespectBlocklistWithoutAlternative( .add(A, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); @@ -485,7 +488,7 @@ void shouldRespectEmptyBlocklist(@InjectNetworkStorageChannel final StorageChann .add(B, 10); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); - sut.setTransferStrategy(strategy); + sut.setTransferStrategies(List.of(strategy)); // Act sut.doWork(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlockEntity.java index 0662ab826..8db0e297c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/importer/ImporterBlockEntity.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage2.platform.common.importer; -import com.refinedmods.refinedstorage2.api.network.impl.node.importer.CompositeImporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; @@ -65,21 +64,20 @@ public ImporterBlockEntity(final BlockPos pos, final BlockState state) { @Override protected void initialize(final ServerLevel level, final Direction direction) { - final CompositeImporterTransferStrategy strategy = createStrategy(level, direction); - LOGGER.debug("Initialized importer at {} with strategy {}", worldPosition, strategy); - getNode().setTransferStrategy(strategy); + final List strategies = createStrategies(level, direction); + LOGGER.debug("Initialized importer at {} with strategies {}", worldPosition, strategies); + getNode().setTransferStrategies(strategies); } - private CompositeImporterTransferStrategy createStrategy(final ServerLevel serverLevel, final Direction direction) { + private List createStrategies(final ServerLevel serverLevel, final Direction direction) { final Direction incomingDirection = direction.getOpposite(); final BlockPos sourcePosition = worldPosition.relative(direction); final List factories = PlatformApi.INSTANCE.getImporterTransferStrategyRegistry().getAll(); - final List strategies = factories + return factories .stream() .map(factory -> factory.create(serverLevel, sourcePosition, incomingDirection, upgradeContainer, this)) .toList(); - return new CompositeImporterTransferStrategy(strategies); } @Override diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterSource.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterSource.java index aea89b31c..b441c3775 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterSource.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterSource.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.importer; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterSource; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterTransferStrategyFactory.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterTransferStrategyFactory.java index 0d0dd8a1d..f5dabaa07 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/importer/FabricStorageImporterTransferStrategyFactory.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.fabric.importer; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java index 100f74a83..e8403490b 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterSource.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.importer; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterSource; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java index 7b3fafa52..e9387f480 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/FluidHandlerImporterTransferStrategyFactory.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.forge.importer; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java index 663b79b63..33b1ca6dd 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterSource.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.importer; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterSource; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java index 64570d9fc..7dd1c21d7 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/importer/ItemHandlerImporterTransferStrategyFactory.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.forge.importer; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterSource; +import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; -import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState;