diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridStorageChannelProvider.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridStorageChannelProvider.java deleted file mode 100644 index a9c759b2f..000000000 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridStorageChannelProvider.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.refinedmods.refinedstorage2.api.grid.watcher; - -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; - -import java.util.Set; - -import org.apiguardian.api.API; - -/** - * Provides the {@link GridWatcherManagerImpl} with {@link StorageChannel}s. - */ -@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.3") -public interface GridStorageChannelProvider { - Set getStorageChannelTypes(); - - StorageChannel getStorageChannel(StorageChannelType type); -} diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcher.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcher.java index 1276ca97f..1b070f92b 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcher.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcher.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage2.api.grid.watcher; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import javax.annotation.Nullable; @@ -23,17 +22,11 @@ public interface GridWatcher { /** * Called when a resource is changed. * - * @param storageChannelType the relevant storage channel type - * @param resource the resource - * @param change the changed amount - * @param trackedResource the tracked resource, if present + * @param resource the resource + * @param change the changed amount + * @param trackedResource the tracked resource, if present */ - void onChanged( - StorageChannelType storageChannelType, - ResourceKey resource, - long change, - @Nullable TrackedResource trackedResource - ); + void onChanged(ResourceKey resource, long change, @Nullable TrackedResource trackedResource); /** * Usually called when the grid network has been changed. diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManager.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManager.java index 2e2055c62..02fe5aca5 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManager.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManager.java @@ -1,6 +1,9 @@ package com.refinedmods.refinedstorage2.api.grid.watcher; import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; + +import javax.annotation.Nullable; import org.apiguardian.api.API; @@ -10,17 +13,15 @@ */ @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.3") public interface GridWatcherManager { - void addWatcher( - GridWatcher watcher, - Class actorType, - GridStorageChannelProvider storageChannelProvider - ); + void addWatcher(GridWatcher watcher, + Class actorType, + @Nullable StorageChannel storageChannel); - void attachAll(GridStorageChannelProvider storageChannelProvider); + void attachAll(@Nullable StorageChannel storageChannel); - void removeWatcher(GridWatcher watcher, GridStorageChannelProvider storageChannelProvider); + void removeWatcher(GridWatcher watcher, @Nullable StorageChannel storageChannel); - void detachAll(GridStorageChannelProvider storageChannelProvider); + void detachAll(StorageChannel storageChannel); void activeChanged(boolean active); } diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java index cd1c5d4ae..c86437cab 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImpl.java @@ -1,10 +1,11 @@ package com.refinedmods.refinedstorage2.api.grid.watcher; import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; import org.apiguardian.api.API; import org.slf4j.Logger; @@ -20,19 +21,21 @@ public class GridWatcherManagerImpl implements GridWatcherManager { public void addWatcher( final GridWatcher watcher, final Class actorType, - final GridStorageChannelProvider storageChannelProvider + @Nullable final StorageChannel storageChannel ) { if (watchers.containsKey(watcher)) { throw new IllegalArgumentException("Watcher is already registered"); } final GridWatcherRegistration registration = new GridWatcherRegistration(watcher, actorType); - attachAll(registration, storageChannelProvider, false); + if (storageChannel != null) { + attach(registration, storageChannel, false); + } watchers.put(watcher, registration); LOGGER.info("Added watcher {}, new count is {}", watcher, watchers.size()); } @Override - public void attachAll(final GridStorageChannelProvider storageChannelProvider) { + public void attachAll(@Nullable final StorageChannel storageChannel) { // If we get here we are affected by a network split or network merge. // At this point, all the storages that are affected by the split or merge have not yet been processed // as the grid has the highest priority. @@ -40,67 +43,46 @@ public void attachAll(final GridStorageChannelProvider storageChannelProvider) { // Invalidate all watcher data, the resources that were synced earlier are no longer valid because we have // a brand-new network. watcher.invalidate(); - // Re-attach the watcher to the new network, and send all the resources from the new network. - // Resources from the old network are not part of the new network yet, as mentioned above, - // but those will be synced when the storages are re-added. - attachAll(registration, storageChannelProvider, true); + if (storageChannel != null) { + // Re-attach the watcher to the new network, and send all the resources from the new network. + // Resources from the old network are not part of the new network yet, as mentioned above, + // but those will be synced when the storages are re-added. + attach(registration, storageChannel, true); + } }); } - private void attachAll(final GridWatcherRegistration registration, - final GridStorageChannelProvider storageChannelProvider, - final boolean replay) { - storageChannelProvider.getStorageChannelTypes().forEach(storageChannelType -> attach( - registration, - storageChannelType, - storageChannelProvider, - replay - )); - } - private void attach( final GridWatcherRegistration registration, - final StorageChannelType storageChannelType, - final GridStorageChannelProvider storageChannelProvider, + final StorageChannel storageChannel, final boolean replay ) { - LOGGER.info("Attaching {} to {}", registration, storageChannelType); - registration.attach(storageChannelProvider.getStorageChannel(storageChannelType), storageChannelType, replay); + LOGGER.info("Attaching {} to {}", registration, storageChannel); + registration.attach(storageChannel, replay); } @Override - public void removeWatcher(final GridWatcher watcher, final GridStorageChannelProvider storageChannelProvider) { + public void removeWatcher(final GridWatcher watcher, @Nullable final StorageChannel storageChannel) { final GridWatcherRegistration registration = watchers.get(watcher); if (registration == null) { throw new IllegalArgumentException("Watcher is not registered"); } - detachAll(registration, storageChannelProvider); + if (storageChannel != null) { + detach(registration, storageChannel); + } watchers.remove(watcher); LOGGER.info("Removed watcher {}, remaining {}", watcher, watchers.size()); } @Override - public void detachAll(final GridStorageChannelProvider storageChannelProvider) { + public void detachAll(final StorageChannel storageChannel) { LOGGER.info("Detaching {} watchers", watchers.size()); - watchers.values().forEach(w -> detachAll(w, storageChannelProvider)); + watchers.values().forEach(watcher -> detach(watcher, storageChannel)); } - private void detachAll(final GridWatcherRegistration registration, - final GridStorageChannelProvider storageChannelProvider) { - storageChannelProvider.getStorageChannelTypes().forEach(storageChannelType -> detach( - registration, - storageChannelType, - storageChannelProvider - )); - } - - private void detach( - final GridWatcherRegistration registration, - final StorageChannelType storageChannelType, - final GridStorageChannelProvider storageChannelProvider - ) { - LOGGER.info("Detaching {} from {}", registration, storageChannelType); - registration.detach(storageChannelProvider.getStorageChannel(storageChannelType), storageChannelType); + private void detach(final GridWatcherRegistration registration, final StorageChannel storageChannel) { + LOGGER.info("Detaching {} from {}", registration, storageChannel); + registration.detach(storageChannel); } @Override diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherRegistration.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherRegistration.java index 3f9e965fb..a7a54ef0e 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherRegistration.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherRegistration.java @@ -3,26 +3,22 @@ import com.refinedmods.refinedstorage2.api.resource.list.listenable.ResourceListListener; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import java.util.HashMap; -import java.util.Map; +import javax.annotation.Nullable; class GridWatcherRegistration { private final GridWatcher watcher; private final Class actorType; - private final Map listeners = new HashMap<>(); + @Nullable + private ResourceListListener listener; GridWatcherRegistration(final GridWatcher watcher, final Class actorType) { this.watcher = watcher; this.actorType = actorType; } - void attach(final StorageChannel storageChannel, - final StorageChannelType storageChannelType, - final boolean replay) { - final ResourceListListener listener = change -> watcher.onChanged( - storageChannelType, + void attach(final StorageChannel storageChannel, final boolean replay) { + this.listener = change -> watcher.onChanged( change.resourceAmount().getResource(), change.change(), storageChannel.findTrackedResourceByActorType( @@ -31,10 +27,8 @@ void attach(final StorageChannel storageChannel, ).orElse(null) ); storageChannel.addListener(listener); - listeners.put(storageChannelType, listener); if (replay) { storageChannel.getAll().forEach(resourceAmount -> watcher.onChanged( - storageChannelType, resourceAmount.getResource(), resourceAmount.getAmount(), storageChannel.findTrackedResourceByActorType( @@ -45,9 +39,11 @@ void attach(final StorageChannel storageChannel, } } - void detach(final StorageChannel storageChannel, final StorageChannelType storageChannelType) { - final ResourceListListener listener = listeners.get(storageChannelType); + void detach(final StorageChannel storageChannel) { + if (listener == null) { + return; + } storageChannel.removeListener(listener); - listeners.remove(storageChannelType); + listener = null; } } diff --git a/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImplTest.java b/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImplTest.java index 0007cd0c2..e2f6964dc 100644 --- a/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImplTest.java +++ b/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/watcher/GridWatcherManagerImplTest.java @@ -5,11 +5,9 @@ import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; - -import java.util.Set; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -27,29 +25,13 @@ class GridWatcherManagerImplTest { GridWatcherManager sut; - StorageChannelType storageChannelType = StorageChannelImpl::new; StorageChannel storageChannel; - GridStorageChannelProvider storageChannelProvider; @BeforeEach void setUp() { sut = new GridWatcherManagerImpl(); storageChannel = new StorageChannelImpl(); storageChannel.addSource(new InMemoryStorageImpl()); - storageChannelProvider = new GridStorageChannelProvider() { - @Override - public Set getStorageChannelTypes() { - return Set.of(storageChannelType); - } - - @Override - public StorageChannel getStorageChannel(final StorageChannelType type) { - if (type == storageChannelType) { - return storageChannel; - } - throw new IllegalArgumentException(); - } - }; } @Test @@ -59,11 +41,11 @@ void shouldAddWatcherAndNotifyOfChanges() { storageChannel.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); // Act - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); storageChannel.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); // Assert - verify(watcher, times(1)).onChanged(storageChannelType, B, 5, null); + verify(watcher, times(1)).onChanged(B, 5, null); verifyNoMoreInteractions(watcher); } @@ -71,12 +53,12 @@ void shouldAddWatcherAndNotifyOfChanges() { void shouldNotAddDuplicateWatcher() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); // Act & assert assertThrows( IllegalArgumentException.class, - () -> sut.addWatcher(watcher, FakeActor.class, storageChannelProvider), + () -> sut.addWatcher(watcher, FakeActor.class, storageChannel), "Watcher is already registered" ); } @@ -86,10 +68,10 @@ void shouldRemoveWatcher() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); storageChannel.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); // Act - sut.removeWatcher(watcher, storageChannelProvider); + sut.removeWatcher(watcher, storageChannel); storageChannel.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); // Assert @@ -104,7 +86,7 @@ void shouldNotRemoveWatcherThatIsNotRegistered() { // Act & assert assertThrows( IllegalArgumentException.class, - () -> sut.removeWatcher(watcher, storageChannelProvider), + () -> sut.removeWatcher(watcher, storageChannel), "Watcher is not registered" ); } @@ -116,16 +98,16 @@ void shouldAddAndRemoveAndAddWatcherAgain() { storageChannel.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); // Act - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); storageChannel.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); - sut.removeWatcher(watcher, storageChannelProvider); + sut.removeWatcher(watcher, storageChannel); storageChannel.insert(C, 4, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); storageChannel.insert(D, 3, Action.EXECUTE, FakeActor.INSTANCE); // Assert - verify(watcher, times(1)).onChanged(storageChannelType, B, 5, null); - verify(watcher, times(1)).onChanged(storageChannelType, D, 3, null); + verify(watcher, times(1)).onChanged(B, 5, null); + verify(watcher, times(1)).onChanged(D, 3, null); verifyNoMoreInteractions(watcher); } @@ -134,41 +116,41 @@ void shouldDetachAll() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); storageChannel.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); // Act - sut.detachAll(storageChannelProvider); + sut.detachAll(storageChannel); storageChannel.insert(B, 10, Action.EXECUTE, FakeActor.INSTANCE); assertThrows(IllegalArgumentException.class, () -> sut.addWatcher( watcher, FakeActor.class, - storageChannelProvider + storageChannel ), "Watcher is already registered"); // Assert verifyNoInteractions(watcher); } - @Test + @RepeatedTest(10000) void shouldAttachAll() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); storageChannel.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); - sut.detachAll(storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); + sut.detachAll(storageChannel); storageChannel.insert(B, 5, Action.EXECUTE, FakeActor.INSTANCE); // Act - sut.attachAll(storageChannelProvider); + sut.attachAll(storageChannel); storageChannel.insert(C, 4, Action.EXECUTE, FakeActor.INSTANCE); // Assert final InOrder inOrder = inOrder(watcher); inOrder.verify(watcher, times(1)).invalidate(); - inOrder.verify(watcher, times(1)).onChanged(storageChannelType, A, 10, null); - inOrder.verify(watcher, times(1)).onChanged(storageChannelType, B, 5, null); - inOrder.verify(watcher, times(1)).onChanged(storageChannelType, C, 4, null); - inOrder.verifyNoMoreInteractions(); + verify(watcher, times(1)).onChanged(A, 10, null); + verify(watcher, times(1)).onChanged(B, 5, null); + verify(watcher, times(1)).onChanged(C, 4, null); + verifyNoMoreInteractions(watcher); } @Test @@ -176,7 +158,7 @@ void shouldNotifyAboutActivenessChange() { // Arrange final GridWatcher watcher = mock(GridWatcher.class); sut.activeChanged(true); - sut.addWatcher(watcher, FakeActor.class, storageChannelProvider); + sut.addWatcher(watcher, FakeActor.class, storageChannel); // Act sut.activeChanged(false); diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageNetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageNetworkComponent.java index 526b23020..80abdd04e 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageNetworkComponent.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageNetworkComponent.java @@ -1,22 +1,14 @@ package com.refinedmods.refinedstorage2.api.network.component; -import com.refinedmods.refinedstorage2.api.grid.watcher.GridStorageChannelProvider; import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.List; -import java.util.function.Predicate; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.1") -public interface StorageNetworkComponent extends NetworkComponent, GridStorageChannelProvider { - StorageChannel getStorageChannel(StorageChannelType type); - - boolean hasSource(Predicate matcher); - - List getResources(StorageChannelType type, Class actorType); +public interface StorageNetworkComponent extends NetworkComponent, StorageChannel { + List getResources(Class actorType); } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageProvider.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageProvider.java index 2d358c9ec..efb73f178 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageProvider.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageProvider.java @@ -1,15 +1,12 @@ package com.refinedmods.refinedstorage2.api.network.component; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; - -import java.util.Optional; import org.apiguardian.api.API; /** * Implement this on {@link com.refinedmods.refinedstorage2.api.network.node.NetworkNode}s that can provide a storage - * for a given {@link StorageChannelType}. + * to the network. * Never modify a {@link com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel} * from a {@link com.refinedmods.refinedstorage2.api.network.node.NetworkNode} directly. * Use this interface to help you manage the lifecycle of your storage, to ensure that your storage is added or removed @@ -20,12 +17,10 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.2") public interface StorageProvider { /** - * Returns an optional storage for the given storage channel type. * This method is called when a {@link com.refinedmods.refinedstorage2.api.network.node.NetworkNode} is added or * removed from a network. * - * @param channelType the storage channel type - * @return the storage for the given channel, if present + * @return the storage */ - Optional getStorageForChannel(StorageChannelType channelType); + Storage getStorage(); } 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 b8ce1d006..2fcb85df7 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 @@ -5,7 +5,6 @@ import com.refinedmods.refinedstorage2.api.resource.filter.Filter; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.Set; import java.util.function.UnaryOperator; @@ -60,13 +59,11 @@ private void trySortSources() { return; } final StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class); - getRelevantStorageChannelTypes().forEach(type -> storage.getStorageChannel(type).sortSources()); + storage.sortSources(); } - protected abstract Set getRelevantStorageChannelTypes(); - - public void setFilterTemplates(final Set templates) { - filter.setTemplates(templates); + public void setFilters(final Set filters) { + filter.setFilters(filters); } public void setNormalizer(final UnaryOperator normalizer) { diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/externalstorage/ExternalStorageProviderFactory.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/externalstorage/ExternalStorageProviderFactory.java index 12a72d429..8b1f3dc98 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/externalstorage/ExternalStorageProviderFactory.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/externalstorage/ExternalStorageProviderFactory.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage2.api.network.node.externalstorage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import java.util.Optional; @@ -8,14 +7,14 @@ import org.apiguardian.api.API; /** - * Provides the external storage with an {@link ExternalStorageProvider} for a given {@link StorageChannelType}. + * Provides the {@link com.refinedmods.refinedstorage2.api.storage.external.ExternalStorage} + * with an {@link ExternalStorageProvider}. */ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") @FunctionalInterface public interface ExternalStorageProviderFactory { /** - * @param channelType the channel type - * @return the external storage provider + * @return the external storage provider, if present */ - Optional create(StorageChannelType channelType); + Optional create(); } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterTransferStrategyImpl.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterTransferStrategyImpl.java index 24439d397..4a9e15a64 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterTransferStrategyImpl.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/importer/ImporterTransferStrategyImpl.java @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.TransferHelper; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.Iterator; import java.util.Objects; @@ -17,22 +16,16 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.1") public class ImporterTransferStrategyImpl implements ImporterTransferStrategy { private final ImporterSource source; - private final StorageChannelType storageChannelType; private final long transferQuota; - public ImporterTransferStrategyImpl(final ImporterSource source, - final StorageChannelType storageChannelType, - final long transferQuota) { + public ImporterTransferStrategyImpl(final ImporterSource source, final long transferQuota) { this.source = source; - this.storageChannelType = storageChannelType; this.transferQuota = transferQuota; } @Override public boolean transfer(final Filter filter, final Actor actor, final Network network) { - final StorageChannel storageChannel = network - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(storageChannelType); + final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class); return transfer(filter, actor, storageChannel); } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java index c679cab47..b3ba7aba9 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java @@ -196,8 +196,7 @@ public Object resolveParameter(final ParameterContext parameterContext, private StorageChannel getNetworkStorageChannel(final String networkId) { return networkMap .get(networkId) - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE); + .getComponent(StorageNetworkComponent.class); } private EnergyNetworkComponent getNetworkEnergy(final String networkId) { 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 29c3372d4..f0ffcc3a5 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,14 +9,8 @@ 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.storage.channel.StorageChannelImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; - -import java.util.Set; public final class NetworkTestFixtures { - public static final StorageChannelType STORAGE_CHANNEL_TYPE = StorageChannelImpl::new; - public static final Set STORAGE_CHANNEL_TYPES = Set.of(STORAGE_CHANNEL_TYPE); public static final ComponentMapFactory NETWORK_COMPONENT_MAP_FACTORY = new ComponentMapFactory<>(); @@ -31,7 +25,7 @@ public final class NetworkTestFixtures { ); NETWORK_COMPONENT_MAP_FACTORY.addFactory( StorageNetworkComponent.class, - network -> new StorageNetworkComponentImpl(STORAGE_CHANNEL_TYPES) + network -> new StorageNetworkComponentImpl() ); } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java index a23961f32..363df863b 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java @@ -3,19 +3,17 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageNetworkNode; import com.refinedmods.refinedstorage2.api.storage.tracked.InMemoryTrackedStorageRepository; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.Map; public class ExternalStorageNetworkNodeFactory extends AbstractNetworkNodeFactory { @Override protected ExternalStorageNetworkNode innerCreate(final AddNetworkNode ctx, final Map properties) { - final ExternalStorageNetworkNode node = new ExternalStorageNetworkNode(getEnergyUsage(properties)); - node.initialize( - NetworkTestFixtures.STORAGE_CHANNEL_TYPES, - () -> 0L, - type -> new InMemoryTrackedStorageRepository() + final ExternalStorageNetworkNode externalStorage = new ExternalStorageNetworkNode( + getEnergyUsage(properties), + () -> 0L ); - return node; + externalStorage.setTrackingRepository(new InMemoryTrackedStorageRepository()); + return externalStorage; } } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java index fb8194f0d..bc35dea09 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java @@ -2,7 +2,6 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.Map; @@ -17,7 +16,6 @@ protected MultiStorageNetworkNode innerCreate(final AddNetworkNode ctx, final Ma return new MultiStorageNetworkNode( getEnergyUsage(properties), energyUsagePerStorage, - NetworkTestFixtures.STORAGE_CHANNEL_TYPES, size ); } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java index 810e95c96..d7c3c9d1f 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java @@ -2,16 +2,12 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.Map; public class StorageNetworkNodeFactory extends AbstractNetworkNodeFactory { @Override protected StorageNetworkNode innerCreate(final AddNetworkNode ctx, final Map properties) { - return new StorageNetworkNode( - getEnergyUsage(properties), - NetworkTestFixtures.STORAGE_CHANNEL_TYPE - ); + return new StorageNetworkNode(getEnergyUsage(properties)); } } diff --git a/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java b/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java index 5f5a0a03b..45af0666f 100644 --- a/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java +++ b/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java @@ -111,12 +111,8 @@ void shouldInjectStorageChannel( @InjectNetworkStorageChannel(networkId = "b") final StorageChannel storageChannelB ) { // Assert - assertThat(storageChannelA).isSameAs( - a.getComponent(StorageNetworkComponent.class) - .getStorageChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); - assertThat(storageChannelB).isSameAs( - b.getComponent(StorageNetworkComponent.class) - .getStorageChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + assertThat(storageChannelA).isSameAs(a.getComponent(StorageNetworkComponent.class)); + assertThat(storageChannelB).isSameAs(b.getComponent(StorageNetworkComponent.class)); } @Test 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 2bfad1394..12c16a5d7 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 @@ -3,100 +3,50 @@ import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; +import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelImpl; -import java.util.Collection; import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class StorageNetworkComponentImpl implements StorageNetworkComponent { +public class StorageNetworkComponentImpl extends StorageChannelImpl implements StorageNetworkComponent { private static final Logger LOGGER = LoggerFactory.getLogger(StorageNetworkComponentImpl.class); - private final Map channels; + public StorageNetworkComponentImpl() { + } - public StorageNetworkComponentImpl(final Collection storageChannelTypes) { - this.channels = storageChannelTypes.stream().collect(Collectors.toUnmodifiableMap( - type -> type, - StorageChannelType::create - )); + protected StorageNetworkComponentImpl(final ResourceList list) { + super(list); } @Override public void onContainerAdded(final NetworkNodeContainer container) { if (container.getNode() instanceof StorageProvider provider) { - for (final Map.Entry entry : channels.entrySet()) { - tryAddStorageFromProviderToChannel(provider, entry.getKey(), entry.getValue()); - } + final Storage storage = provider.getStorage(); + LOGGER.debug("Adding source {} from provider {}", storage, provider); + addSource(storage); } } - private void tryAddStorageFromProviderToChannel(final StorageProvider provider, - final StorageChannelType type, - final StorageChannel channel) { - provider.getStorageForChannel(type).ifPresent(storage -> { - LOGGER.debug("Adding source {} to channel {} from provider {}", storage, type, provider); - channel.addSource(storage); - }); - } - @Override public void onContainerRemoved(final NetworkNodeContainer container) { if (container.getNode() instanceof StorageProvider provider) { - for (final Map.Entry entry : channels.entrySet()) { - final StorageChannelType storageChannelType = entry.getKey(); - final StorageChannel storageChannel = entry.getValue(); - tryRemoveStorageFromProviderFromChannel(provider, storageChannelType, storageChannel); - } - } - } - - private void tryRemoveStorageFromProviderFromChannel(final StorageProvider provider, - final StorageChannelType type, - final StorageChannel channel) { - provider.getStorageForChannel(type).ifPresent(storage -> { - LOGGER.debug("Removing source {} from channel {} of provider {}", storage, type, provider); - channel.removeSource(storage); - }); - } - - @Override - public StorageChannel getStorageChannel(final StorageChannelType type) { - return channels.get(type); - } - - @Override - public Set getStorageChannelTypes() { - return channels.keySet(); - } - - @Override - public boolean hasSource(final Predicate matcher) { - for (final Map.Entry entry : channels.entrySet()) { - final StorageChannel storageChannel = entry.getValue(); - if (storageChannel.hasSource(matcher)) { - return true; - } + final Storage storage = provider.getStorage(); + LOGGER.debug("Removing source {} of provider {}", storage, provider); + removeSource(storage); } - return false; } @Override - public List getResources(final StorageChannelType type, - final Class actorType) { - final StorageChannel storageChannel = getStorageChannel(type); - return storageChannel.getAll().stream().map(resourceAmount -> new TrackedResourceAmount( + public List getResources(final Class actorType) { + return getAll().stream().map(resourceAmount -> new TrackedResourceAmount( resourceAmount, - storageChannel.findTrackedResourceByActorType(resourceAmount.getResource(), actorType).orElse(null) + findTrackedResourceByActorType(resourceAmount.getResource(), actorType).orElse(null) )).toList(); } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java index ea1936e30..0266f5c37 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java @@ -2,11 +2,10 @@ import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; public abstract class AbstractDetectorAmountStrategy implements DetectorAmountStrategy { - protected StorageChannel getStorageChannel(final Network network, final ResourceTemplate template) { - return network.getComponent(StorageNetworkComponent.class).getStorageChannel(template.storageChannelType()); + protected StorageChannel getStorageChannel(final Network network) { + return network.getComponent(StorageNetworkComponent.class); } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategy.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategy.java index 61c12c408..931249e0b 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategy.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategy.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.detector; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; public interface DetectorAmountStrategy { - long getAmount(Network network, ResourceTemplate template); + long getAmount(Network network, ResourceKey configuredResource); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategyImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategyImpl.java index cb4945b23..02ad3a74d 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategyImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorAmountStrategyImpl.java @@ -2,13 +2,13 @@ import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; public class DetectorAmountStrategyImpl extends AbstractDetectorAmountStrategy { @Override - public long getAmount(final Network network, final ResourceTemplate template) { - return getStorageChannel(network, template) - .get(template.resource()) + public long getAmount(final Network network, final ResourceKey configuredResource) { + return getStorageChannel(network) + .get(configuredResource) .map(ResourceAmount::getAmount) .orElse(0L); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java index a1a8c44f6..73dff0160 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.detector; import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import javax.annotation.Nullable; @@ -11,7 +11,7 @@ public class DetectorNetworkNode extends AbstractNetworkNode { private long amount; private DetectorMode mode = DetectorMode.EQUAL; @Nullable - private ResourceTemplate template; + private ResourceKey configuredResource; @Nullable private DetectorAmountStrategy amountStrategy; @@ -24,8 +24,8 @@ public long getEnergyUsage() { return energyUsage; } - public void setFilterTemplate(@Nullable final ResourceTemplate filterTemplate) { - this.template = filterTemplate; + public void setConfiguredResource(@Nullable final ResourceKey configuredResource) { + this.configuredResource = configuredResource; } public DetectorMode getMode() { @@ -49,10 +49,10 @@ public void setAmountStrategy(@Nullable final DetectorAmountStrategy amountStrat } public boolean isActivated() { - if (template == null || network == null || !isActive() || amountStrategy == null) { + if (configuredResource == null || network == null || !isActive() || amountStrategy == null) { return false; } - final long amountInNetwork = amountStrategy.getAmount(network, template); + final long amountInNetwork = amountStrategy.getAmount(network, configuredResource); return switch (mode) { case UNDER -> amountInNetwork < amount; case EQUAL -> amountInNetwork == amount; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java index 5e8f5a507..9db98bc38 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java @@ -44,9 +44,9 @@ public void doWork() { taskExecutor.execute(tasks, context); } - public void setFilterTemplates(final List templates) { + public void setFilters(final List filters) { tasks.clear(); - tasks.addAll(templates.stream().map(TaskImpl::new).toList()); + tasks.addAll(filters.stream().map(TaskImpl::new).toList()); } public void setEnergyUsage(final long energyUsage) { @@ -62,10 +62,10 @@ public record TaskContext(Network network, Actor actor) { } class TaskImpl implements Task { - private final ResourceKey template; + private final ResourceKey filter; - TaskImpl(final ResourceKey template) { - this.template = template; + TaskImpl(final ResourceKey filter) { + this.filter = filter; } @Override @@ -73,7 +73,7 @@ public boolean run(final TaskContext context) { if (transferStrategy == null) { return false; } - return transferStrategy.transfer(template, context.actor, context.network); + return transferStrategy.transfer(filter, context.actor, context.network); } } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java index 7d203156d..587f0201f 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java @@ -8,21 +8,16 @@ import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.api.storage.TransferHelper; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.Collection; import java.util.Collections; public class ExporterTransferStrategyImpl implements ExporterTransferStrategy { private final InsertableStorage destination; - private final StorageChannelType storageChannelType; private final long transferQuota; - public ExporterTransferStrategyImpl(final InsertableStorage destination, - final StorageChannelType storageChannelType, - final long transferQuota) { + public ExporterTransferStrategyImpl(final InsertableStorage destination, final long transferQuota) { this.destination = destination; - this.storageChannelType = storageChannelType; this.transferQuota = transferQuota; } @@ -37,8 +32,7 @@ protected Collection expand(final ResourceKey resource, final Stora @Override public boolean transfer(final ResourceKey resource, final Actor actor, final Network network) { - final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(storageChannelType); + final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class); final Collection expanded = expand(resource, storageChannel); return tryTransferExpanded(actor, storageChannel, expanded); } 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 1ca635dd1..438534771 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 @@ -23,17 +23,19 @@ public class ExposedExternalStorage extends AbstractConfiguredProxyStorage implements ConsumingStorage, CompositeAwareChild, TrackedStorage, ExternalStorageListener { private final Set parents = new HashSet<>(); - private final TrackedStorageRepository trackingRepository; private final LongSupplier clock; + @Nullable + private TrackedStorageRepository trackingRepository; - ExposedExternalStorage(final StorageConfiguration config, - final TrackedStorageRepository trackingRepository, - final LongSupplier clock) { + ExposedExternalStorage(final StorageConfiguration config, final LongSupplier clock) { super(config); - this.trackingRepository = trackingRepository; this.clock = clock; } + void setTrackingRepository(final TrackedStorageRepository trackingRepository) { + this.trackingRepository = trackingRepository; + } + @Nullable public ExternalStorageProvider getExternalStorageProvider() { final ExternalStorage delegate = getUnsafeDelegate(); @@ -91,11 +93,17 @@ public boolean detectChanges() { @Override public Optional findTrackedResourceByActorType(final ResourceKey resource, final Class actorType) { + if (trackingRepository == null) { + return Optional.empty(); + } return trackingRepository.findTrackedResourceByActorType(resource, actorType); } @Override public void beforeDetectChanges(final ResourceKey resource, final Actor actor) { + if (trackingRepository == null) { + return; + } trackingRepository.update(resource, actor, clock.getAsLong()); } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java index c31fbc503..3b5298ffb 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java @@ -4,50 +4,33 @@ import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.externalstorage.ExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorage; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageRepository; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; -import java.util.Set; import java.util.function.LongSupplier; -import java.util.stream.Collectors; import javax.annotation.Nullable; public class ExternalStorageNetworkNode extends AbstractStorageNetworkNode implements StorageProvider { private final long energyUsage; - private Map storages = Collections.emptyMap(); + private final ExposedExternalStorage storage; + @Nullable + private ExternalStorage externalStorage; - public ExternalStorageNetworkNode(final long energyUsage) { + public ExternalStorageNetworkNode(final long energyUsage, final LongSupplier clock) { this.energyUsage = energyUsage; + this.storage = new ExposedExternalStorage(this, clock); } - public void initialize(final Collection storageChannelTypes, - final LongSupplier clock, - final TrackedStorageRepositoryProvider trackedStorageRepositoryProvider) { - this.storages = storageChannelTypes.stream().collect(Collectors.toUnmodifiableMap( - type -> type, - type -> new DynamicStorage(trackedStorageRepositoryProvider.getRepository(type), clock) - )); + public void setTrackingRepository(final TrackedStorageRepository trackingRepository) { + storage.setTrackingRepository(trackingRepository); } public void initialize(final ExternalStorageProviderFactory factory) { - storages.forEach((type, storage) -> { - storage.exposedStorage.tryClearDelegate(); - initialize(factory, type, storage); - }); - } - - private void initialize(final ExternalStorageProviderFactory factory, - final StorageChannelType type, - final DynamicStorage dynamicStorage) { - factory.create(type).ifPresent(provider -> { - dynamicStorage.internalStorage = new ExternalStorage(provider, dynamicStorage.exposedStorage); + storage.tryClearDelegate(); + factory.create().ifPresent(provider -> { + this.externalStorage = new ExternalStorage(provider, storage); if (isActive()) { - dynamicStorage.setVisible(true); + setVisible(true); } }); } @@ -55,11 +38,11 @@ private void initialize(final ExternalStorageProviderFactory factory, @Override protected void onActiveChanged(final boolean newActive) { super.onActiveChanged(newActive); - storages.values().forEach(storage -> storage.setVisible(newActive)); + setVisible(newActive); } public boolean detectChanges() { - return storages.values().stream().anyMatch(storage -> storage.exposedStorage.detectChanges()); + return storage.detectChanges(); } @Override @@ -68,45 +51,18 @@ public long getEnergyUsage() { } @Override - protected Set getRelevantStorageChannelTypes() { - return storages.keySet(); - } - - @Override - public Optional getStorageForChannel(final StorageChannelType channelType) { - final DynamicStorage storage = storages.get(channelType); - if (storage == null) { - return Optional.empty(); - } - return Optional.of(storage.exposedStorage); + public Storage getStorage() { + return storage; } - private class DynamicStorage { - private final ExposedExternalStorage exposedStorage; - @Nullable - private ExternalStorage internalStorage; - - private DynamicStorage(final TrackedStorageRepository trackingRepository, final LongSupplier clock) { - this.exposedStorage = new ExposedExternalStorage( - ExternalStorageNetworkNode.this, - trackingRepository, - clock - ); - } - - public void setVisible(final boolean visible) { - if (visible) { - tryMakeInternalStorageVisible(); - } else { - exposedStorage.tryClearDelegate(); - } - } - - private void tryMakeInternalStorageVisible() { - if (internalStorage == null) { + private void setVisible(final boolean visible) { + if (visible) { + if (externalStorage == null) { return; } - exposedStorage.setDelegate(internalStorage); + storage.setDelegate(externalStorage); + } else { + storage.tryClearDelegate(); } } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/TrackedStorageRepositoryProvider.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/TrackedStorageRepositoryProvider.java deleted file mode 100644 index 02c6478c7..000000000 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/TrackedStorageRepositoryProvider.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage; - -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageRepository; - -@FunctionalInterface -public interface TrackedStorageRepositoryProvider { - TrackedStorageRepository getRepository(StorageChannelType type); -} diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportState.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportState.java index fee633b64..17a48ff1a 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportState.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportState.java @@ -2,9 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.Collection; import javax.annotation.Nullable; @@ -14,26 +12,25 @@ public interface InterfaceExportState { Collection expandExportCandidates(StorageChannel storageChannel, ResourceKey resource); - boolean isExportedResourceValid(ResourceTemplate want, - ResourceTemplate got); + boolean isExportedResourceValid(ResourceKey want, ResourceKey got); @Nullable - ResourceTemplate getRequestedResource(int slotIndex); + ResourceKey getRequestedResource(int slotIndex); long getRequestedAmount(int slotIndex); @Nullable - ResourceTemplate getExportedResource(int slotIndex); + ResourceKey getExportedResource(int slotIndex); long getExportedAmount(int slotIndex); - void setExportSlot(int slotIndex, ResourceTemplate resource, long amount); + void setExportSlot(int slotIndex, ResourceKey resource, long amount); void shrinkExportedAmount(int slotIndex, long amount); void growExportedAmount(int slotIndex, long amount); - long insert(StorageChannelType storageChannelType, ResourceKey resource, long amount, Action action); + long insert(ResourceKey resource, long amount, Action action); long extract(ResourceKey resource, long amount, Action action); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java index 209159e0b..732a0b3cd 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java @@ -8,7 +8,6 @@ import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; @@ -21,13 +20,13 @@ public class InterfaceNetworkNode extends AbstractNetworkNode { private final Actor actor = new NetworkNodeActor(this); @Nullable private InterfaceExportState exportState; - private ToLongFunction transferQuotaProvider = resourceTemplate -> Long.MAX_VALUE; + private ToLongFunction transferQuotaProvider = resource -> Long.MAX_VALUE; public InterfaceNetworkNode(final long energyUsage) { this.energyUsage = energyUsage; } - public void setTransferQuotaProvider(final ToLongFunction transferQuotaProvider) { + public void setTransferQuotaProvider(final ToLongFunction transferQuotaProvider) { this.transferQuotaProvider = transferQuotaProvider; } @@ -74,8 +73,8 @@ public void doWork() { private void doExport(final InterfaceExportState state, final int index, final StorageNetworkComponent storageComponent) { - final ResourceTemplate want = state.getRequestedResource(index); - final ResourceTemplate got = state.getExportedResource(index); + final ResourceKey want = state.getRequestedResource(index); + final ResourceKey got = state.getExportedResource(index); if (want == null && got != null) { clearExportedResource(state, index, got, storageComponent); } else if (want != null && got == null) { @@ -92,12 +91,11 @@ private void doExport(final InterfaceExportState state, private void clearExportedResource(final InterfaceExportState state, final int slot, - final ResourceTemplate got, - final StorageNetworkComponent storageComponent) { + final ResourceKey got, + final StorageChannel storageChannel) { final long currentAmount = state.getExportedAmount(slot); - final StorageChannel storageChannel = storageComponent.getStorageChannel(got.storageChannelType()); final long inserted = storageChannel.insert( - got.resource(), + got, Math.min(currentAmount, transferQuotaProvider.applyAsLong(got)), Action.EXECUTE, actor @@ -110,11 +108,10 @@ private void clearExportedResource(final InterfaceExportState state, private void doInitialExport(final InterfaceExportState state, final int slot, - final ResourceTemplate want, - final StorageNetworkComponent storageComponent) { + final ResourceKey want, + final StorageChannel storageChannel) { final long wantedAmount = state.getRequestedAmount(slot); - final StorageChannel storageChannel = storageComponent.getStorageChannel(want.storageChannelType()); - final Collection candidates = state.expandExportCandidates(storageChannel, want.resource()); + final Collection candidates = state.expandExportCandidates(storageChannel, want); for (final ResourceKey candidate : candidates) { final long extracted = storageChannel.extract( candidate, @@ -123,11 +120,7 @@ private void doInitialExport(final InterfaceExportState state, actor ); if (extracted > 0) { - state.setExportSlot( - slot, - new ResourceTemplate(candidate, want.storageChannelType()), - extracted - ); + state.setExportSlot(slot, candidate, extracted); break; } } @@ -135,7 +128,7 @@ private void doInitialExport(final InterfaceExportState state, private void doExportWithExistingResource(final InterfaceExportState state, final int slot, - final ResourceTemplate got, + final ResourceKey got, final StorageNetworkComponent storageComponent) { final long wantedAmount = state.getRequestedAmount(slot); final long currentAmount = state.getExportedAmount(slot); @@ -149,12 +142,11 @@ private void doExportWithExistingResource(final InterfaceExportState state, private void exportAdditionalResources(final InterfaceExportState state, final int slot, - final ResourceTemplate got, + final ResourceKey got, final long amount, - final StorageNetworkComponent storageComponent) { + final StorageChannel storageChannel) { final long correctedAmount = Math.min(transferQuotaProvider.applyAsLong(got), amount); - final StorageChannel storageChannel = storageComponent.getStorageChannel(got.storageChannelType()); - final long extracted = storageChannel.extract(got.resource(), correctedAmount, Action.EXECUTE, actor); + final long extracted = storageChannel.extract(got, correctedAmount, Action.EXECUTE, actor); if (extracted == 0) { return; } @@ -163,12 +155,11 @@ private void exportAdditionalResources(final InterfaceExportState state, private void returnExportedResource(final InterfaceExportState state, final int slot, - final ResourceTemplate got, + final ResourceKey got, final long amount, - final StorageNetworkComponent storageComponent) { - final StorageChannel storageChannel = storageComponent.getStorageChannel(got.storageChannelType()); + final StorageChannel storageChannel) { final long correctedAmount = Math.min(transferQuotaProvider.applyAsLong(got), Math.abs(amount)); - final long inserted = storageChannel.insert(got.resource(), correctedAmount, Action.EXECUTE, actor); + final long inserted = storageChannel.insert(got, correctedAmount, Action.EXECUTE, actor); if (inserted == 0) { return; } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImpl.java index 04a230c79..1f1bb9c77 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImpl.java @@ -7,8 +7,6 @@ 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.ResourceTemplate; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.ArrayList; import java.util.Collections; @@ -17,12 +15,9 @@ public class InterfaceExternalStorageProviderImpl implements InterfaceExternalStorageProvider { private final InterfaceNetworkNode networkNode; - private final StorageChannelType storageChannelType; - public InterfaceExternalStorageProviderImpl(final InterfaceNetworkNode networkNode, - final StorageChannelType storageChannelType) { + public InterfaceExternalStorageProviderImpl(final InterfaceNetworkNode networkNode) { this.networkNode = networkNode; - this.storageChannelType = storageChannelType; } @Override @@ -46,7 +41,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a if (exportState == null) { return 0; } - return exportState.insert(storageChannelType, resource, amount, action); + return exportState.insert(resource, amount, action); } private boolean isAnotherInterfaceActingAsExternalStorage(final Actor actor) { @@ -63,8 +58,8 @@ public Iterator iterator() { } final List slots = new ArrayList<>(); for (int i = 0; i < exportState.getSlots(); ++i) { - final ResourceTemplate resource = exportState.getExportedResource(i); - if (resource == null || resource.storageChannelType() != storageChannelType) { + final ResourceKey resource = exportState.getExportedResource(i); + if (resource == null) { continue; } slots.add(getResourceAmount(resource, exportState.getExportedAmount(i))); @@ -72,9 +67,8 @@ public Iterator iterator() { return slots.iterator(); } - private ResourceAmount getResourceAmount(final ResourceTemplate resource, - final long amount) { - return new ResourceAmount(resource.resource(), amount); + private ResourceAmount getResourceAmount(final ResourceKey resource, final long amount) { + return new ResourceAmount(resource, amount); } @Override 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 b1c3b40cb..2491e8296 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 @@ -48,8 +48,8 @@ public void setNormalizer(final UnaryOperator normalizer) { filter.setNormalizer(normalizer); } - public void setFilterTemplates(final Set templates) { - filter.setTemplates(templates); + public void setFilters(final Set filters) { + filter.setFilters(filters); } public void setEnergyUsage(final long energyUsage) { diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java similarity index 93% rename from refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedStorage.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java index 0ec86306a..76e1e2715 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedStorage.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/ExposedMultiStorage.java @@ -15,9 +15,9 @@ import java.util.List; import java.util.Optional; -class ExposedStorage extends AbstractImmutableConfiguredProxyStorage +class ExposedMultiStorage extends AbstractImmutableConfiguredProxyStorage implements CompositeStorage, CompositeAwareChild { - protected ExposedStorage(final StorageConfiguration config) { + protected ExposedMultiStorage(final StorageConfiguration config) { super(config, new CompositeStorageImpl(new ResourceListImpl())); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java index 58eeb8aa5..95704945c 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java @@ -5,20 +5,13 @@ import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.StorageState; -import com.refinedmods.refinedstorage2.api.storage.TypedStorage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; import javax.annotation.Nullable; import org.slf4j.Logger; @@ -35,31 +28,17 @@ public class MultiStorageNetworkNode extends AbstractStorageNetworkNode implemen private final long energyUsage; private final long energyUsagePerStorage; - private final TypedStorage[] cache; - private final Map exposedStorages; + private final StateTrackedStorage[] cache; + private final ExposedMultiStorage storage; private int activeStorages; public MultiStorageNetworkNode(final long energyUsage, final long energyUsagePerStorage, - final Collection storageChannelTypes, final int size) { this.energyUsage = energyUsage; this.energyUsagePerStorage = energyUsagePerStorage; - this.exposedStorages = createExposedStorages(storageChannelTypes); - this.cache = new TypedStorage[size]; - } - - private Map createExposedStorages( - final Collection storageChannelTypes - ) { - return storageChannelTypes.stream().collect(Collectors.toUnmodifiableMap( - Function.identity(), - this::createExposedStorage - )); - } - - private ExposedStorage createExposedStorage(final StorageChannelType type) { - return new ExposedStorage(this); + this.storage = new ExposedMultiStorage(this); + this.cache = new StateTrackedStorage[size]; } public void setProvider(final MultiStorageProvider provider) { @@ -89,16 +68,14 @@ private Set initializeStorage(final int index) { final Set results = new HashSet<>(); if (cache[index] != null) { - final StorageChannelType removedType = cache[index].storageChannelType(); - final ExposedStorage relevantComposite = exposedStorages.get(removedType); - results.add(new StorageChange(true, relevantComposite, cache[index].storage())); + results.add(new StorageChange(true, cache[index])); } if (provider != null) { provider.resolve(index).ifPresentOrElse(resolved -> { - cache[index] = StateTrackedStorage.of(resolved, listener); - final ExposedStorage relevantComposite = exposedStorages.get(resolved.storageChannelType()); - results.add(new StorageChange(false, relevantComposite, cache[index].storage())); + final StateTrackedStorage newStorage = new StateTrackedStorage(resolved, listener); + cache[index] = newStorage; + results.add(new StorageChange(false, newStorage)); }, () -> cache[index] = null); } @@ -110,9 +87,9 @@ private void processStorageChange(final StorageChange change) { return; } if (change.removed) { - change.exposedStorage.removeSource(change.internalStorage); + storage.removeSource(change.storage); } else { - change.exposedStorage.addSource(change.internalStorage); + storage.addSource(change.storage); } } @@ -135,20 +112,15 @@ protected void onActiveChanged(final boolean newActive) { } private void enableAllStorages() { - exposedStorages.forEach(this::enableAllStoragesForChannel); - } - - private void enableAllStoragesForChannel(final StorageChannelType type, - final ExposedStorage exposedStorage) { - for (final TypedStorage internalStorage : cache) { - if (internalStorage != null && internalStorage.storageChannelType() == type) { - exposedStorage.addSource(internalStorage.storage()); + for (final StateTrackedStorage internalStorage : cache) { + if (internalStorage != null) { + storage.addSource(internalStorage); } } } private void disableAllStorages() { - exposedStorages.values().forEach(ExposedStorage::clearSources); + storage.clearSources(); } public void setListener(final StateTrackedStorage.Listener listener) { @@ -165,32 +137,21 @@ public int getSize() { } public StorageState getState(final int index) { - final var storage = cache[index]; - if (storage == null) { + final var cached = cache[index]; + if (cached == null) { return StorageState.NONE; } if (!isActive()) { return StorageState.INACTIVE; } - return storage.storage().getState(); + return cached.getState(); } @Override - protected Set getRelevantStorageChannelTypes() { - return exposedStorages.keySet(); - } - - @Override - public Optional getStorageForChannel(final StorageChannelType channelType) { - final ExposedStorage storage = exposedStorages.get(channelType); - if (storage != null) { - return Optional.of(storage); - } - return Optional.empty(); + public Storage getStorage() { + return storage; } - private record StorageChange(boolean removed, - ExposedStorage exposedStorage, - StateTrackedStorage internalStorage) { + private record StorageChange(boolean removed, StateTrackedStorage storage) { } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProvider.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProvider.java index 00dcaa004..8dd420fa1 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProvider.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProvider.java @@ -1,11 +1,10 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.TypedStorage; import java.util.Optional; @FunctionalInterface public interface MultiStorageProvider { - Optional> resolve(int index); + Optional resolve(int index); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java index 0f5584353..659ae9106 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java @@ -3,10 +3,7 @@ import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import java.util.Optional; -import java.util.Set; import javax.annotation.Nullable; import org.slf4j.Logger; @@ -16,15 +13,12 @@ public class StorageNetworkNode extends AbstractStorageNetworkNode implements St private static final Logger LOGGER = LoggerFactory.getLogger(StorageNetworkNode.class); private final long energyUsage; - private final StorageChannelType type; - private final ExposedStorage exposedStorage = new ExposedStorage(this); - + private final ExposedStorage storage = new ExposedStorage(this); @Nullable private Storage internalStorage; - public StorageNetworkNode(final long energyUsage, final StorageChannelType type) { + public StorageNetworkNode(final long energyUsage) { this.energyUsage = energyUsage; - this.type = type; } public void setStorage(final Storage storage) { @@ -40,9 +34,9 @@ protected void onActiveChanged(final boolean newActive) { } LOGGER.debug("Storage activeness got changed to '{}', updating underlying storage", newActive); if (newActive) { - exposedStorage.setDelegate(internalStorage); + storage.setDelegate(internalStorage); } else { - exposedStorage.clearDelegate(); + storage.clearDelegate(); } } @@ -52,23 +46,15 @@ public long getEnergyUsage() { } public long getStored() { - return exposedStorage.getStored(); + return storage.getStored(); } public long getCapacity() { - return exposedStorage.getCapacity(); + return storage.getCapacity(); } @Override - protected Set getRelevantStorageChannelTypes() { - return Set.of(type); - } - - @Override - public Optional getStorageForChannel(final StorageChannelType channelType) { - if (channelType == this.type) { - return Optional.of(exposedStorage); - } - return Optional.empty(); + public Storage getStorage() { + return storage; } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java index fe36db27d..b6fb80561 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java @@ -11,7 +11,6 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.util.FakeActor; import java.util.function.Supplier; @@ -57,7 +56,6 @@ void shouldRespectPriorityWhenSplitting() { final InOrder inOrder = inOrder(slave.watcher); inOrder.verify(slave.watcher, times(1)).invalidate(); inOrder.verify(slave.watcher, times(1)).onChanged( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, SLAVE, 10L, null @@ -65,7 +63,6 @@ void shouldRespectPriorityWhenSplitting() { verifyNoMoreInteractions(slave.watcher); verify(master.watcher, times(1)).onChanged( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, SLAVE, -10L, null @@ -97,13 +94,11 @@ void shouldRespectPriorityWhenMerging() { verify(slave.watcher, times(1)).invalidate(); verify(slave.watcher).onChanged( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, SLAVE, 10L, null ); verify(slave.watcher).onChanged( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, MASTER, 10L, null @@ -111,7 +106,6 @@ void shouldRespectPriorityWhenMerging() { verifyNoMoreInteractions(slave.watcher); verify(master.watcher, times(1)).onChanged( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, SLAVE, 10L, null @@ -121,10 +115,7 @@ void shouldRespectPriorityWhenMerging() { private NetworkSide createNetworkSide(final MasterSlave side, final Supplier networkFactory) { - final StorageNetworkNode nodeA = new StorageNetworkNode( - 0, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE - ); + final StorageNetworkNode nodeA = new StorageNetworkNode(0); final InMemoryStorageImpl storage = new InMemoryStorageImpl(); storage.insert(side, 10, Action.EXECUTE, FakeActor.INSTANCE); nodeA.setStorage(storage); 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 9acba77b8..b6da58daa 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 @@ -8,7 +8,6 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; @@ -36,15 +35,15 @@ class StorageNetworkComponentImplTest { @BeforeEach void setUp() { - sut = new StorageNetworkComponentImpl(NetworkTestFixtures.STORAGE_CHANNEL_TYPES); + sut = new StorageNetworkComponentImpl(); - storage1 = new StorageNetworkNode(0, NetworkTestFixtures.STORAGE_CHANNEL_TYPE); + storage1 = new StorageNetworkNode(0); storage1.setNetwork(new NetworkImpl(NetworkTestFixtures.NETWORK_COMPONENT_MAP_FACTORY)); storage1.setStorage(new LimitedStorageImpl(100)); storage1.setActive(true); storage1Container = () -> storage1; - storage2 = new StorageNetworkNode(0, NetworkTestFixtures.STORAGE_CHANNEL_TYPE); + storage2 = new StorageNetworkNode(0); storage2.setNetwork(new NetworkImpl(NetworkTestFixtures.NETWORK_COMPONENT_MAP_FACTORY)); storage2.setStorage(new LimitedStorageImpl(100)); storage2.setActive(true); @@ -54,9 +53,7 @@ void setUp() { @Test void testInitialState() { // Act - final Collection resources = sut - .getStorageChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - .getAll(); + final Collection resources = sut.getAll(); // Assert assertThat(resources).isEmpty(); @@ -64,36 +61,31 @@ void testInitialState() { @Test void shouldAddStorageSourceContainer() { - // Arrange - final StorageChannel storageChannel = sut.getStorageChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE); - // Act - final long insertedPre = storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedPre = sut.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); sut.onContainerAdded(storage1Container); - final long insertedPost = storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedPost = sut.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); // Assert assertThat(insertedPre).isZero(); assertThat(insertedPost).isEqualTo(10); - assertThat(storageChannel.getAll()).isNotEmpty(); + assertThat(sut.getAll()).isNotEmpty(); } @Test void shouldRemoveStorageSourceContainer() { // Arrange - final StorageChannel storageChannel = sut.getStorageChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE); - sut.onContainerAdded(storage1Container); sut.onContainerAdded(storage2Container); // Ensure that we fill our 2 containers. - storageChannel.insert(A, 200, Action.EXECUTE, EmptyActor.INSTANCE); + sut.insert(A, 200, Action.EXECUTE, EmptyActor.INSTANCE); // Act - final Collection resourcesPre = new HashSet(storageChannel.getAll()); + final Collection resourcesPre = new HashSet<>(sut.getAll()); sut.onContainerRemoved(storage1Container); sut.onContainerRemoved(storage2Container); - final Collection resourcesPost = storageChannel.getAll(); + final Collection resourcesPost = sut.getAll(); // Assert assertThat(resourcesPre).isNotEmpty(); @@ -106,12 +98,8 @@ void testHasSource() { sut.onContainerAdded(storage1Container); // Act - final boolean found = sut.hasSource( - s -> s == storage1.getStorageForChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE).get() - ); - final boolean found2 = sut.hasSource( - s -> s == storage2.getStorageForChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE).get() - ); + final boolean found = sut.hasSource(s -> s == storage1.getStorage()); + final boolean found2 = sut.hasSource(s -> s == storage2.getStorage()); // Assert assertThat(found).isTrue(); @@ -121,18 +109,14 @@ void testHasSource() { @Test void shouldRetrieveResources() { // Arrange - final StorageChannel storageChannel = sut.getStorageChannel(NetworkTestFixtures.STORAGE_CHANNEL_TYPE); sut.onContainerRemoved(storage1Container); sut.onContainerRemoved(storage2Container); - storageChannel.addSource(new TrackedStorageImpl(new LimitedStorageImpl(1000), () -> 2L)); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 200, Action.EXECUTE, EmptyActor.INSTANCE); + sut.addSource(new TrackedStorageImpl(new LimitedStorageImpl(1000), () -> 2L)); + sut.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + sut.insert(B, 200, Action.EXECUTE, EmptyActor.INSTANCE); // Act - final List resources = sut.getResources( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - EmptyActor.class - ); + final List resources = sut.getResources(EmptyActor.class); // Assert assertThat(resources).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java index 7853a5bbb..a90e186e4 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java @@ -3,12 +3,10 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; @@ -43,7 +41,7 @@ void setUp(@InjectNetworkStorageChannel final StorageChannel storageChannel) { @Test void testWithoutNetwork() { // Act - sut.setFilterTemplate(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + sut.setConfiguredResource(A); sut.setNetwork(null); // Assert @@ -56,7 +54,7 @@ void testWithoutNetwork() { @Test void testWithoutActiveness() { // Act - sut.setFilterTemplate(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + sut.setConfiguredResource(A); sut.setActive(false); // Assert @@ -67,7 +65,7 @@ void testWithoutActiveness() { } @Test - void testWithoutTemplate() { + void testWithoutConfiguredResource() { // Assert assertThat(sut.isActivated()).isFalse(); assertThat(sut.getAmount()).isZero(); @@ -77,9 +75,9 @@ void testWithoutTemplate() { @ParameterizedTest @EnumSource(DetectorMode.class) - void testWithTemplateButWithoutResourceInNetwork(final DetectorMode mode) { + void testWithConfiguredResourceButWithoutResourceInNetwork(final DetectorMode mode) { // Arrange - sut.setFilterTemplate(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + sut.setConfiguredResource(A); sut.setMode(mode); // Act @@ -122,7 +120,7 @@ void testModes(final DetectorMode mode, final boolean expectedActivated, @InjectNetworkStorageChannel final StorageChannel storageChannel) { // Arrange - sut.setFilterTemplate(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + sut.setConfiguredResource(A); sut.setMode(mode); sut.setAmount(comparisonAmount); 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 883a5913d..04a36b2fc 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 @@ -15,7 +15,6 @@ import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import java.util.List; @@ -67,7 +66,7 @@ void shouldUseFirstSuccessfulStrategy( createTransferStrategy(destination, 10), createTransferStrategy(destination, 10) ))); - sut.setFilterTemplates(List.of(A)); + sut.setFilters(List.of(A)); // Act sut.doWork(); @@ -110,7 +109,7 @@ void shouldNotTransferWithoutTaskExecutor( final Storage destination = new InMemoryStorageImpl(); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); sut.setTransferStrategy(createTransferStrategy(destination, 1)); sut.setTaskExecutor(null); @@ -134,7 +133,7 @@ void shouldNotTransferWithoutStrategy(@InjectNetworkStorageChannel final Storage final Storage destination = new InMemoryStorageImpl(); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act sut.doWork(); @@ -158,7 +157,7 @@ void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChann final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); sut.setActive(false); // Act @@ -173,7 +172,7 @@ void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldNotTransferWithoutTemplates(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldNotTransferWithoutFilters(@InjectNetworkStorageChannel final StorageChannel storageChannel) { // Arrange storageChannel.addSource(new InMemoryStorageImpl()); storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); @@ -183,7 +182,7 @@ void shouldNotTransferWithoutTemplates(@InjectNetworkStorageChannel final Storag final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of()); + sut.setFilters(List.of()); // Act sut.doWork(); @@ -205,7 +204,7 @@ void shouldNotTransferIfNoResourcesAreAvailable( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act sut.doWork(); @@ -233,8 +232,8 @@ void shouldTransferWithLimitedSpaceInDestination( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(C)); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(C)); + sut.setFilters(List.of(A, B)); // Act & assert sut.doWork(); @@ -277,7 +276,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheDestination( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act sut.doWork(); @@ -305,7 +304,7 @@ void shouldTransferSingleResourceEvenIfTransferQuotaHasNotBeenMet( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act sut.doWork(); @@ -323,6 +322,6 @@ protected static ExporterTransferStrategy createTransferStrategy( final InsertableStorage destination, final long transferQuota ) { - return new ExporterTransferStrategyImpl(destination, NetworkTestFixtures.STORAGE_CHANNEL_TYPE, transferQuota); + return new ExporterTransferStrategyImpl(destination, transferQuota); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java index 989c81875..de33dcc2b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java @@ -42,7 +42,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A)); + sut.setFilters(List.of(A)); // Act sut.doWork(); @@ -74,7 +74,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act sut.doWork(); @@ -108,7 +108,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a final ExporterTransferStrategy strategy = createTransferStrategy(destination, 20); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B, C)); + sut.setFilters(List.of(A, B, C)); // Act & assert sut.doWork(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java index f2c3993fb..1ab7e19b8 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java @@ -40,7 +40,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(B, A)); + sut.setFilters(List.of(B, A)); // Act & assert sut.doWork(); @@ -76,7 +76,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act & assert sut.doWork(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java index 027c6c3d6..e5b2979cf 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java @@ -51,7 +51,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act & assert sut.doWork(); @@ -100,7 +100,7 @@ void shouldNotTransferIfThereAreNoResourcesInSource() { final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B)); + sut.setFilters(List.of(A, B)); // Act & assert sut.doWork(); @@ -120,7 +120,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B, C, D)); + sut.setFilters(List.of(A, B, C, D)); // Act & assert sut.doWork(); @@ -184,7 +184,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( } @Test - void shouldResetRoundRobinStateAfterChangingTemplates( + void shouldResetRoundRobinStateAfterChangingFilters( @InjectNetworkStorageChannel final StorageChannel storageChannel ) { // Arrange @@ -197,7 +197,7 @@ void shouldResetRoundRobinStateAfterChangingTemplates( final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); sut.setTransferStrategy(strategy); - sut.setFilterTemplates(List.of(A, B, C)); + sut.setFilters(List.of(A, B, C)); // Act & assert sut.doWork(); @@ -224,7 +224,7 @@ void shouldResetRoundRobinStateAfterChangingTemplates( ); // Now C would be the next one, but we expect to go back to A. - sut.setFilterTemplates(List.of(A, C)); + sut.setFilters(List.of(A, C)); sut.doWork(); assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java index 56b53b4ab..19af0a910 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java @@ -157,7 +157,7 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -180,7 +180,7 @@ void shouldRespectEmptyAllowlistWhenInserting( ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -201,7 +201,7 @@ void shouldRespectEmptyAllowlistWhenInserting( void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -223,7 +223,7 @@ void shouldRespectEmptyBlocklistWhenInserting( @InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageProviderFactoryImpl.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageProviderFactoryImpl.java index ac44b7914..ef9b2f787 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageProviderFactoryImpl.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageProviderFactoryImpl.java @@ -1,19 +1,14 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage; import com.refinedmods.refinedstorage2.api.network.node.externalstorage.ExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.Optional; public record ExternalStorageProviderFactoryImpl(ExternalStorageProvider provider) implements ExternalStorageProviderFactory { @Override - public Optional create(final StorageChannelType channelType) { - if (channelType == NetworkTestFixtures.STORAGE_CHANNEL_TYPE) { - return Optional.of(provider); - } - return Optional.empty(); + public Optional create() { + return Optional.of(provider); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java index f40bb4890..b2a8102ed 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java @@ -15,7 +15,6 @@ import com.refinedmods.refinedstorage2.network.test.InjectNetwork; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.util.FakeActor; @@ -102,7 +101,6 @@ void shouldNotifyWatchersOfStorageChanges( final ArgumentCaptor resources = ArgumentCaptor.forClass(ResourceKey.class); final ArgumentCaptor trackedResources = ArgumentCaptor.forClass(TrackedResource.class); verify(watcher, times(2)).onChanged( - eq(NetworkTestFixtures.STORAGE_CHANNEL_TYPE), resources.capture(), anyLong(), trackedResources.capture() @@ -171,7 +169,6 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( final ArgumentCaptor trackedResources1 = ArgumentCaptor.forClass(TrackedResource.class); verify(watcher, times(1)).onChanged( - eq(NetworkTestFixtures.STORAGE_CHANNEL_TYPE), eq(C), eq(10L), trackedResources1.capture() @@ -182,7 +179,6 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( final ArgumentCaptor trackedResources2 = ArgumentCaptor.forClass(TrackedResource.class); verify(watcher, times(1)).onChanged( - eq(NetworkTestFixtures.STORAGE_CHANNEL_TYPE), eq(A), eq(10L), trackedResources2.capture() @@ -192,7 +188,6 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( .allMatch(t -> FakeActor.INSTANCE.getName().equals(t.getSourceName())); verify(watcher, times(1)).onChanged( - eq(NetworkTestFixtures.STORAGE_CHANNEL_TYPE), eq(D), eq(10L), isNull() diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java index e1badb2de..bdd926c6e 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java @@ -2,13 +2,11 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; @@ -47,9 +45,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(5); assertThat(exportState.getExportedResource(2)).isNull(); assertThat(storageChannel.getAll()) @@ -61,9 +57,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); assertThat(exportState.getExportedResource(2)).isNull(); assertThat(storageChannel.getAll()) @@ -75,9 +69,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(exportState.getExportedResource(2)).isNull(); assertThat(storageChannel.getAll()) @@ -124,9 +116,7 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(5); assertThat(exportState.getExportedResource(2)).isNull(); assertThat(storageChannel.getAll()) @@ -135,9 +125,7 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(exportState.getExportedResource(2)).isNull(); assertThat(storageChannel.getAll()) @@ -148,9 +136,7 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave sut.doWork(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(exportState.getExportedResource(2)).isNull(); assertThat(storageChannel.getAll()) @@ -170,9 +156,7 @@ void shouldNotClearSlotWhenNoLongerRequestingAnythingAndNetworkDoesNotHaveEnough // Assert assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(exportState.getExportedResource(2)).isNull(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java index f8ddbe5aa..1502510bd 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java @@ -4,12 +4,10 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; @@ -72,9 +70,7 @@ void shouldExportToEmptySlotWhenRequestedIsNotEntirelyAvailable( // Assert assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(exportState.getExportedResource(2)).isNull(); @@ -96,9 +92,7 @@ void shouldExportToEmptySlotWhenRequestedIsLessThanTransferQuota( // Assert assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(exportState.getExportedResource(2)).isNull(); @@ -124,13 +118,9 @@ void shouldExportToEmptySlot( // Assert assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(exportState.getExportedResource(2)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(B, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(2)).isEqualTo(B); assertThat(exportState.getExportedAmount(2)).isEqualTo(2); assertThat(storageChannel.getAll()) @@ -157,9 +147,7 @@ void shouldExportResourceFuzzilyToEmptySlot( // Assert assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A_ALTERNATIVE, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(exportState.getExportedResource(2)).isNull(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java index a754ad137..1d90058c5 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java @@ -3,10 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.ArrayList; import java.util.Collection; @@ -65,9 +62,9 @@ private Collection expandExportCandidates(final StorageChannel stor } @Override - public boolean isExportedResourceValid(final ResourceTemplate want, final ResourceTemplate got) { - if (A.equals(want.resource())) { - return got.resource() == A || got.resource() == A_ALTERNATIVE || got.resource() == A_ALTERNATIVE2; + public boolean isExportedResourceValid(final ResourceKey want, final ResourceKey got) { + if (A.equals(want)) { + return got == A || got == A_ALTERNATIVE || got == A_ALTERNATIVE2; } return got.equals(want); } @@ -80,13 +77,13 @@ private void validateIndex(final int index) { @Nullable @Override - public ResourceTemplate getRequestedResource(final int slotIndex) { + public ResourceKey getRequestedResource(final int slotIndex) { validateIndex(slotIndex); final ResourceAmount resourceAmount = requested.get(slotIndex); if (resourceAmount == null) { return null; } - return new ResourceTemplate(resourceAmount.getResource(), NetworkTestFixtures.STORAGE_CHANNEL_TYPE); + return resourceAmount.getResource(); } @Override @@ -101,13 +98,13 @@ public long getRequestedAmount(final int slotIndex) { @Nullable @Override - public ResourceTemplate getExportedResource(final int slotIndex) { + public ResourceKey getExportedResource(final int slotIndex) { validateIndex(slotIndex); final ResourceAmount resourceAmount = current.get(slotIndex); if (resourceAmount == null) { return null; } - return new ResourceTemplate(resourceAmount.getResource(), NetworkTestFixtures.STORAGE_CHANNEL_TYPE); + return resourceAmount.getResource(); } @Override @@ -121,13 +118,13 @@ public long getExportedAmount(final int slotIndex) { } @Override - public void setExportSlot(final int slotIndex, final ResourceTemplate resource, final long amount) { + public void setExportSlot(final int slotIndex, final ResourceKey resource, final long amount) { validateIndex(slotIndex); - current.put(slotIndex, new ResourceAmount(resource.resource(), amount)); + current.put(slotIndex, new ResourceAmount(resource, amount)); } public void setCurrentlyExported(final int index, final ResourceKey resource, final long amount) { - setExportSlot(index, new ResourceTemplate(resource, NetworkTestFixtures.STORAGE_CHANNEL_TYPE), amount); + setExportSlot(index, resource, amount); } @Override @@ -149,18 +146,11 @@ public void growExportedAmount(final int slotIndex, final long amount) { } @Override - public long insert(final StorageChannelType storageChannelType, - final ResourceKey resource, - final long amount, - final Action action) { + public long insert(final ResourceKey resource, final long amount, final Action action) { for (int i = 0; i < getSlots(); ++i) { if (getExportedResource(i) == null) { if (action == Action.EXECUTE) { - final ResourceTemplate template = new ResourceTemplate( - resource, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE - ); - setExportSlot(i, template, amount); + setExportSlot(i, resource, amount); } return amount; } @@ -172,8 +162,8 @@ public long insert(final StorageChannelType storageChannelType, public long extract(final ResourceKey resource, final long amount, final Action action) { long extracted = 0; for (int i = 0; i < getSlots(); ++i) { - final ResourceTemplate slot = getExportedResource(i); - if (slot != null && slot.resource().equals(resource)) { + final ResourceKey slot = getExportedResource(i); + if (slot != null && slot.equals(resource)) { final long maxAmount = Math.min(getExportedAmount(i), amount - extracted); extracted += maxAmount; if (action == Action.EXECUTE) { diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java index 941981cb8..c7ac118cd 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java @@ -5,13 +5,11 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; @@ -62,9 +60,7 @@ void shouldExportAllWithDefaultTransferQuota( // Assert assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(Long.MAX_VALUE); assertThat(storageChannel.getAll()).isEmpty(); assertThat(energy.getStored()).isEqualTo(1000 - 5); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java index 77ab0684f..296564409 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java @@ -4,13 +4,11 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; @@ -51,9 +49,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -61,9 +57,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -71,9 +65,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(6); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -81,9 +73,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -93,9 +83,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( sut.doWork(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -115,9 +103,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -125,9 +111,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -135,9 +119,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(6); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -145,9 +127,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()).isEmpty(); @@ -155,9 +135,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes sut.doWork(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()).isEmpty(); } @@ -176,9 +154,7 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A_ALTERNATIVE, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -189,9 +165,7 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A_ALTERNATIVE, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -214,17 +188,13 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReachedEvenIfTheResour // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A_ALTERNATIVE, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(storageChannel.getAll()).isEmpty(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A_ALTERNATIVE, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(storageChannel.getAll()).isEmpty(); } @@ -242,9 +212,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(8); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -252,9 +220,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -264,9 +230,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( sut.doWork(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -286,9 +250,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(8); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -296,9 +258,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -308,9 +268,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( sut.doWork(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -331,9 +289,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -354,9 +310,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(B, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -367,9 +321,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(B, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -382,9 +334,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( sut.doWork(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(B, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -408,9 +358,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkI // Act & assert sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() @@ -423,9 +371,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkI sut.doWork(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(storageChannel.getAll()) .usingRecursiveFieldByFieldElementComparator() diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java index 4108c2aef..c7f39264b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java @@ -7,12 +7,10 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; @@ -51,8 +49,7 @@ void shouldExposeExportedResources( exportState.setCurrentlyExported(8, A, 1); externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNode, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNode ))); // Act @@ -70,8 +67,7 @@ void shouldNotExposeExportedResourceWithoutExportState( ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNodeWithoutExportState, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNodeWithoutExportState ))); // Act @@ -89,8 +85,7 @@ void shouldInsertIntoInterface( ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNode, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNode ))); // Act @@ -102,9 +97,7 @@ void shouldInsertIntoInterface( assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); - assertThat(exportState.getExportedResource(0)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(0)).isEqualTo(A); assertThat(exportState.getExportedAmount(0)).isEqualTo(10); } else { assertThat(networkStorage.getAll()).isEmpty(); @@ -121,8 +114,7 @@ void shouldNotInsertResourceWithoutExportState( ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNodeWithoutExportState, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNodeWithoutExportState ))); externalStorage.detectChanges(); @@ -144,8 +136,7 @@ void shouldExtractEntireResourceFromInterface( exportState.setCurrentlyExported(0, A, 50); exportState.setCurrentlyExported(1, A, 50); externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNode, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNode ))); externalStorage.detectChanges(); @@ -164,13 +155,9 @@ void shouldExtractEntireResourceFromInterface( assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 100) ); - assertThat(exportState.getExportedResource(0)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(0)).isEqualTo(A); assertThat(exportState.getExportedAmount(0)).isEqualTo(50); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(50); } } @@ -185,8 +172,7 @@ void shouldExtractPartialResourceFromInterface( exportState.setCurrentlyExported(0, A, 50); exportState.setCurrentlyExported(1, A, 50); externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNode, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNode ))); externalStorage.detectChanges(); @@ -201,21 +187,15 @@ void shouldExtractPartialResourceFromInterface( ); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedAmount(0)).isZero(); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(49); } else { assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 100) ); - assertThat(exportState.getExportedResource(0)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(0)).isEqualTo(A); assertThat(exportState.getExportedAmount(0)).isEqualTo(50); - assertThat(exportState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(50); } } @@ -229,8 +209,7 @@ void shouldNotExtractNonExistentResourceFromInterface( // Arrange exportState.setCurrentlyExported(0, A, 50); externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNode, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNode ))); externalStorage.detectChanges(); @@ -242,9 +221,7 @@ void shouldNotExtractNonExistentResourceFromInterface( assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 50) ); - assertThat(exportState.getExportedResource(0)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(0)).isEqualTo(A); assertThat(exportState.getExportedAmount(0)).isEqualTo(50); } @@ -256,8 +233,7 @@ void shouldNotExtractResourceWithoutExportState( ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - interfaceNetworkNodeWithoutExportState, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE + interfaceNetworkNodeWithoutExportState ))); externalStorage.detectChanges(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java index 044a25e00..39d4f5ad1 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java @@ -10,14 +10,12 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; @@ -62,10 +60,7 @@ void setUp(@InjectNetworkStorageChannel final StorageChannel networkStorage) { interfaceWithExternalStorage.setExportState(interfaceWithExternalStorageState); interfaceWithExternalStorage.setTransferQuotaProvider(resource -> 100); externalStorageConnectionToInterface.initialize(new ExternalStorageProviderFactoryImpl( - new InterfaceExternalStorageProviderImpl( - interfaceWithExternalStorage, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE - ) + new InterfaceExternalStorageProviderImpl(interfaceWithExternalStorage) )); interfaceWithExternalStorageState2 = new InterfaceExportStateImpl(2); @@ -73,10 +68,7 @@ void setUp(@InjectNetworkStorageChannel final StorageChannel networkStorage) { interfaceWithExternalStorage2.setExportState(interfaceWithExternalStorageState2); interfaceWithExternalStorage2.setTransferQuotaProvider(resource -> 100); externalStorageConnectionToInterface2.initialize(new ExternalStorageProviderFactoryImpl( - new InterfaceExternalStorageProviderImpl( - interfaceWithExternalStorage2, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE - ) + new InterfaceExternalStorageProviderImpl(interfaceWithExternalStorage2) )); regularInterfaceState = new InterfaceExportStateImpl(2); @@ -116,9 +108,7 @@ void shouldNotAllowInsertionByAnotherInterfaceIfThatInterfaceIsActingAsExternalS interfaceWithExternalStorage.doWork(); // Assert - assertThat(interfaceWithExternalStorageState.getExportedResource(0)) - .usingRecursiveComparison() - .isEqualTo(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + assertThat(interfaceWithExternalStorageState.getExportedResource(0)).isEqualTo(A); assertThat(interfaceWithExternalStorageState.getExportedAmount(0)).isEqualTo(15); assertThat(interfaceWithExternalStorageState2.getExportedResource(0)).isNull(); @@ -145,9 +135,7 @@ void shouldAllowInsertionByAnotherInterfaceIfThatInterfaceIsNotActingAsExternalS regularInterface.doWork(); // Assert - assertThat(interfaceWithExternalStorageState.getExportedResource(0)) - .usingRecursiveComparison() - .isEqualTo(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + assertThat(interfaceWithExternalStorageState.getExportedResource(0)).isEqualTo(A); assertThat(interfaceWithExternalStorageState.getExportedAmount(0)).isEqualTo(10); assertThat(interfaceWithExternalStorageState2.getExportedResource(0)).isNull(); @@ -174,9 +162,7 @@ void shouldNotAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsActingA externalStorageConnectionToInterface.detectChanges(); assertThat(interfaceWithExternalStorageState.getExportedResource(0)).isNull(); - assertThat(interfaceWithExternalStorageState.getExportedResource(1)) - .usingRecursiveComparison() - .isEqualTo(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + assertThat(interfaceWithExternalStorageState.getExportedResource(1)).isEqualTo(A); assertThat(interfaceWithExternalStorageState.getExportedAmount(1)).isEqualTo(10); assertThat(interfaceWithExternalStorageState2.getExportedResource(0)).isNull(); @@ -192,9 +178,7 @@ void shouldNotAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsActingA externalStorageConnectionToInterface2.detectChanges(); assertThat(interfaceWithExternalStorageState.getExportedResource(0)).isNull(); - assertThat(interfaceWithExternalStorageState.getExportedResource(1)) - .usingRecursiveComparison() - .isEqualTo(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + assertThat(interfaceWithExternalStorageState.getExportedResource(1)).isEqualTo(A); assertThat(interfaceWithExternalStorageState.getExportedAmount(1)).isEqualTo(10); assertThat(interfaceWithExternalStorageState2.getExportedResource(0)).isNull(); @@ -216,9 +200,7 @@ void shouldAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsNotActingA externalStorageConnectionToInterface.detectChanges(); assertThat(interfaceWithExternalStorageState.getExportedResource(0)).isNull(); - assertThat(interfaceWithExternalStorageState.getExportedResource(1)) - .usingRecursiveComparison() - .isEqualTo(new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE)); + assertThat(interfaceWithExternalStorageState.getExportedResource(1)).isEqualTo(A); assertThat(interfaceWithExternalStorageState.getExportedAmount(1)).isEqualTo(10); assertThat(regularInterfaceState.getExportedResource(0)).isNull(); @@ -240,9 +222,7 @@ void shouldAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsNotActingA assertThat(interfaceWithExternalStorageState.getExportedAmount(1)).isZero(); assertThat(regularInterfaceState.getExportedResource(0)).isNull(); - assertThat(regularInterfaceState.getExportedResource(1)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(A, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(regularInterfaceState.getExportedResource(1)).isEqualTo(A); assertThat(regularInterfaceState.getExportedAmount(1)).isEqualTo(10); assertThat(regularStorageInNetwork.getAll()).isEmpty(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java index f34e08595..2fc970921 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java @@ -5,12 +5,10 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportStateImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; @@ -33,10 +31,7 @@ void setUp() { exportState = new InterfaceExportStateImpl(2); iface.setExportState(exportState); iface.setTransferQuotaProvider(resource -> 100); - connection.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( - iface, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE - ))); + connection.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl(iface))); } // We don't allow self-insertions and self-extractions for the same reasons mentioned in @@ -56,9 +51,7 @@ void shouldNotAllowSelfInsertionOrSelfExtraction( connection.detectChanges(); // Assert - assertThat(exportState.getExportedResource(0)).usingRecursiveComparison().isEqualTo( - new ResourceTemplate(B, NetworkTestFixtures.STORAGE_CHANNEL_TYPE) - ); + assertThat(exportState.getExportedResource(0)).isEqualTo(B); assertThat(exportState.getExportedAmount(0)).isEqualTo(15); assertThat(exportState.getExportedResource(1)).isNull(); 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 69f4a5419..fcbddaceb 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 @@ -16,7 +16,6 @@ import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; import com.refinedmods.refinedstorage2.network.test.NetworkTest; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import java.util.List; @@ -96,11 +95,7 @@ void shouldNotWorkOrExtractEnergyWithoutBeingActive( final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 100) .add(B, 100); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); sut.setActive(false); @@ -124,11 +119,7 @@ void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChann final FakeImporterSource source = new FakeImporterSource(A, B, A) .add(A, 100) .add(B, 100); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act @@ -158,21 +149,9 @@ void shouldUseFirstSuccessfulTransferStrategy( .add(B, 100); sut.setTransferStrategy(new CompositeImporterTransferStrategy(List.of( - new ImporterTransferStrategyImpl( - emptySource, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ), - new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ), - new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ) + new ImporterTransferStrategyImpl(emptySource, 1), + new ImporterTransferStrategyImpl(source, 1), + new ImporterTransferStrategyImpl(source, 1) ))); // Act @@ -199,11 +178,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheNetwork( final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 100) .add(B, 100); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act @@ -229,11 +204,7 @@ void testTransferDifferentResourceOverMultipleSlots( final FakeImporterSource source = new FakeImporterSource(A, B, A, B) .add(A, 11) .add(B, 6); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 10 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); sut.setTransferStrategy(strategy); // Act @@ -260,11 +231,7 @@ void testTransferSameResourceOverMultipleSlots( .add(A, 20) .add(B, 5); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 10 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); sut.setTransferStrategy(strategy); // Act @@ -298,11 +265,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a final FakeImporterSource source = new FakeImporterSource(A, B, B, B) .add(A, 8) .add(B, 11); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 10 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); sut.setTransferStrategy(strategy); // Act @@ -326,11 +289,7 @@ void testTransferWithoutAnyResourcesInSource( storageChannel.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 10 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); sut.setTransferStrategy(strategy); // Act @@ -345,7 +304,7 @@ void testTransferWithoutAnyResourcesInSource( void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); storageChannel.addSource(new InMemoryStorageImpl()); @@ -353,11 +312,7 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel st .add(B, 10) .add(A, 10); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act @@ -379,7 +334,7 @@ void shouldRespectAllowlistWithNormalizer( ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); sut.setNormalizer(resource -> { if (resource == A_ALTERNATIVE || resource == A_ALTERNATIVE2) { return A; @@ -394,11 +349,7 @@ void shouldRespectAllowlistWithNormalizer( .add(A_ALTERNATIVE, 1) .add(A_ALTERNATIVE2, 1); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 10 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); sut.setTransferStrategy(strategy); // Act @@ -421,18 +372,14 @@ void shouldRespectAllowlistWithoutAlternative( ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); storageChannel.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B) .add(B, 10); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act @@ -449,7 +396,7 @@ void shouldRespectAllowlistWithoutAlternative( void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); storageChannel.addSource(new InMemoryStorageImpl()); @@ -457,11 +404,7 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChann .add(B, 10) .add(A, 10); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act @@ -479,7 +422,7 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChann void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); storageChannel.addSource(new InMemoryStorageImpl()); @@ -487,11 +430,7 @@ void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel st .add(A, 10) .add(B, 10); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act @@ -513,18 +452,14 @@ void shouldRespectBlocklistWithoutAlternative( ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); storageChannel.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A) .add(A, 10); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act @@ -541,7 +476,7 @@ void shouldRespectBlocklistWithoutAlternative( void shouldRespectEmptyBlocklist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); storageChannel.addSource(new InMemoryStorageImpl()); @@ -549,11 +484,7 @@ void shouldRespectEmptyBlocklist(@InjectNetworkStorageChannel final StorageChann .add(A, 10) .add(B, 10); - final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl( - source, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - 1 - ); + final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 1); sut.setTransferStrategy(strategy); // Act diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java index 9c2043b33..0364652b9 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java @@ -396,7 +396,7 @@ void shouldRespectAllowlistWhenInserting( ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); final Storage storage = new LimitedStorageImpl(100); provider.set(1, storage); @@ -419,7 +419,7 @@ void shouldRespectAllowlistWithNormalizerWhenInserting( ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); sut.setNormalizer(resource -> { if (resource == A_ALTERNATIVE || resource == A_ALTERNATIVE2) { return A; @@ -455,7 +455,7 @@ void shouldRespectEmptyAllowlistWhenInserting( ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); final Storage storage = new LimitedStorageImpl(100); provider.set(1, storage); @@ -478,7 +478,7 @@ void shouldRespectBlocklistWhenInserting( ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); final Storage storage = new LimitedStorageImpl(100); provider.set(1, storage); @@ -501,7 +501,7 @@ void shouldRespectEmptyBlocklistWhenInserting( ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); final Storage storage = new LimitedStorageImpl(100); provider.set(1, storage); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProviderImpl.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProviderImpl.java index 5e95debf4..09df89765 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProviderImpl.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageProviderImpl.java @@ -1,8 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.TypedStorage; -import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.HashMap; import java.util.Map; @@ -12,11 +10,8 @@ class MultiStorageProviderImpl implements MultiStorageProvider { private final Map storages = new HashMap<>(); @Override - public Optional> resolve(final int index) { - return Optional.ofNullable(storages.get(index)).map(storage -> new TypedStorage<>( - storage, - NetworkTestFixtures.STORAGE_CHANNEL_TYPE - )); + public Optional resolve(final int index) { + return Optional.ofNullable(storages.get(index)); } public void set(final int index, final Storage storage) { diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java index c698ba8ce..43d117442 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java @@ -122,7 +122,7 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -143,7 +143,7 @@ void shouldRespectEmptyAllowlistWhenInserting( @InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -163,7 +163,7 @@ void shouldRespectEmptyAllowlistWhenInserting( void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -184,7 +184,7 @@ void shouldRespectEmptyBlocklistWhenInserting( @InjectNetworkStorageChannel final StorageChannel networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); - sut.setFilterTemplates(Set.of()); + sut.setFilters(Set.of()); final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java index 119f125f7..6cb41434e 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java @@ -24,7 +24,6 @@ import com.refinedmods.refinedstorage2.platform.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy; @@ -36,6 +35,7 @@ import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; import com.refinedmods.refinedstorage2.platform.api.wirelesstransmitter.WirelessTransmitterRangeModifier; @@ -65,7 +65,7 @@ public interface PlatformApi { StorageContainerItemHelper getStorageContainerItemHelper(); - PlatformRegistry getStorageChannelTypeRegistry(); + PlatformRegistry getResourceTypeRegistry(); PlatformRegistry getImporterTransferStrategyRegistry(); @@ -135,14 +135,10 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe ResourceFactory getItemResourceFactory(); - PlatformStorageChannelType getItemStorageChannelType(); - StorageType getItemStorageType(); ResourceFactory getFluidResourceFactory(); - PlatformStorageChannelType getFluidStorageChannelType(); - StorageType getFluidStorageType(); Set getAlternativeResourceFactories(); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java index dca61a22f..1980886df 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java @@ -24,7 +24,6 @@ import com.refinedmods.refinedstorage2.platform.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy; @@ -82,8 +81,8 @@ public StorageContainerItemHelper getStorageContainerItemHelper() { } @Override - public PlatformRegistry getStorageChannelTypeRegistry() { - return ensureLoaded().getStorageChannelTypeRegistry(); + public PlatformRegistry getResourceTypeRegistry() { + return ensureLoaded().getResourceTypeRegistry(); } @Override @@ -249,11 +248,6 @@ public ResourceFactory getItemResourceFactory() { return ensureLoaded().getItemResourceFactory(); } - @Override - public PlatformStorageChannelType getItemStorageChannelType() { - return ensureLoaded().getItemStorageChannelType(); - } - @Override public StorageType getItemStorageType() { return ensureLoaded().getItemStorageType(); @@ -264,11 +258,6 @@ public ResourceFactory getFluidResourceFactory() { return ensureLoaded().getFluidResourceFactory(); } - @Override - public PlatformStorageChannelType getFluidStorageChannelType() { - return ensureLoaded().getFluidStorageChannelType(); - } - @Override public StorageType getFluidStorageType() { return ensureLoaded().getFluidStorageType(); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java index d4df3d19d..c07944903 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java @@ -5,8 +5,7 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import java.util.List; @@ -22,7 +21,7 @@ public interface Grid { boolean isGridActive(); - List getResources(StorageChannelType type, Class actorType); + List getResources(Class actorType); - GridOperations createOperations(PlatformStorageChannelType storageChannelType, Actor actor); + GridOperations createOperations(ResourceType resourceType, Actor actor); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridExtractionStrategy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridExtractionStrategy.java index 889fa8239..b53bf0a1c 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridExtractionStrategy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridExtractionStrategy.java @@ -1,17 +1,11 @@ package com.refinedmods.refinedstorage2.platform.api.grid.strategy; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") public interface GridExtractionStrategy { - boolean onExtract( - PlatformStorageChannelType storageChannelType, - ResourceKey resource, - GridExtractMode extractMode, - boolean cursor - ); + boolean onExtract(PlatformResourceKey resource, GridExtractMode extractMode, boolean cursor); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridScrollingStrategy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridScrollingStrategy.java index ed8adc932..a3d4adf96 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridScrollingStrategy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/strategy/GridScrollingStrategy.java @@ -1,17 +1,11 @@ package com.refinedmods.refinedstorage2.platform.api.grid.strategy; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") public interface GridScrollingStrategy { - boolean onScroll( - PlatformStorageChannelType storageChannelType, - ResourceKey resource, - GridScrollMode scrollMode, - int slotIndex - ); + boolean onScroll(PlatformResourceKey resource, GridScrollMode scrollMode, int slotIndex); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/view/PlatformGridResource.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/view/PlatformGridResource.java index a469a88f8..abe4ff089 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/view/PlatformGridResource.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/view/PlatformGridResource.java @@ -5,9 +5,11 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import java.util.List; import java.util.Optional; +import javax.annotation.Nullable; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; @@ -37,4 +39,7 @@ void onScroll(GridScrollMode scrollMode, int getRegistryId(); List getExtractionHints(); + + @Nullable + PlatformResourceKey getUnderlyingResource(); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/recipemod/IngredientConverter.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/recipemod/IngredientConverter.java index 1c7187d2c..aa2ff7e8a 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/recipemod/IngredientConverter.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/recipemod/IngredientConverter.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.api.recipemod; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import java.util.Optional; @@ -8,7 +8,7 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.5") public interface IngredientConverter { - Optional convertToResource(Object ingredient); + Optional convertToResource(Object ingredient); - Optional convertToIngredient(Object resource); + Optional convertToIngredient(PlatformResourceKey resource); } 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 ba0ec5e2b..b36966d29 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 @@ -1,8 +1,6 @@ package com.refinedmods.refinedstorage2.platform.api.storage; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.TypedStorage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import java.util.List; @@ -25,19 +23,15 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public abstract class AbstractStorageContainerItem extends Item implements StorageContainerItem { protected final StorageContainerItemHelper helper; - private final StorageChannelType type; - protected AbstractStorageContainerItem(final Properties properties, - final StorageChannelType type, - final StorageContainerItemHelper helper) { + protected AbstractStorageContainerItem(final Properties properties, final StorageContainerItemHelper helper) { super(properties); - this.type = type; this.helper = helper; } @Override - public Optional> resolve(final StorageRepository storageRepository, final ItemStack stack) { - return helper.resolve(storageRepository, stack).map(storage -> new TypedStorage<>(storage, type)); + public Optional resolve(final StorageRepository storageRepository, final ItemStack stack) { + return helper.resolve(storageRepository, stack); } @Override diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/StorageContainerItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/StorageContainerItem.java index 42bd3f186..b66fd0588 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/StorageContainerItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/StorageContainerItem.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage2.platform.api.storage; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.TypedStorage; import java.util.Optional; @@ -10,7 +9,7 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public interface StorageContainerItem { - Optional> resolve(StorageRepository storageRepository, ItemStack stack); + Optional resolve(StorageRepository storageRepository, ItemStack stack); Optional getInfo(StorageRepository storageRepository, ItemStack stack); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/AbstractPlatformStorageChannelType.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/AbstractPlatformStorageChannelType.java deleted file mode 100644 index 0ccff4a26..000000000 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/AbstractPlatformStorageChannelType.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.api.storage.channel; - -import com.refinedmods.refinedstorage2.api.core.CoreValidations; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; - -import java.util.function.BiConsumer; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; -import org.apiguardian.api.API; - -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") -public abstract class AbstractPlatformStorageChannelType implements PlatformStorageChannelType { - private static final String TAG_CHANGED_BY = "cb"; - private static final String TAG_CHANGED_AT = "ca"; - - private final String name; - private final StorageChannelType delegate; - private final MutableComponent title; - private final ResourceLocation textureIdentifier; - private final int textureX; - private final int textureY; - - protected AbstractPlatformStorageChannelType(final String name, - final StorageChannelType delegate, - final MutableComponent title, - final ResourceLocation textureIdentifier, - final int textureX, - final int textureY) { - this.name = name; - this.delegate = CoreValidations.validateNotNull(delegate, "Delegate cannot be null"); - this.title = title; - this.textureIdentifier = textureIdentifier; - this.textureX = textureX; - this.textureY = textureY; - } - - @Override - public CompoundTag toTag(final ResourceKey resource, final TrackedResource trackedResource) { - final CompoundTag tag = toTag(resource); - tag.putString(TAG_CHANGED_BY, trackedResource.getSourceName()); - tag.putLong(TAG_CHANGED_AT, trackedResource.getTime()); - return tag; - } - - @Override - public void fromTag(final CompoundTag tag, final BiConsumer acceptor) { - fromTag(tag).ifPresent(resource -> { - final String changedBy = tag.getString(TAG_CHANGED_BY); - final long changedAt = tag.getLong(TAG_CHANGED_AT); - acceptor.accept(resource, new TrackedResource(changedBy, changedAt)); - }); - } - - @Override - public StorageChannel create() { - return delegate.create(); - } - - @Override - public MutableComponent getTitle() { - return title; - } - - @Override - public ResourceLocation getTextureIdentifier() { - return textureIdentifier; - } - - @Override - public int getXTexture() { - return textureX; - } - - @Override - public int getYTexture() { - return textureY; - } - - @Override - public String toString() { - return name; - } -} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/FuzzyStorageChannelImpl.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/FuzzyStorageChannelImpl.java deleted file mode 100644 index 533f9e78c..000000000 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/FuzzyStorageChannelImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.api.storage.channel; - -import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelImpl; -import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceList; - -import java.util.Collection; - -import org.apiguardian.api.API; - -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") -public class FuzzyStorageChannelImpl extends StorageChannelImpl implements FuzzyStorageChannel { - private final FuzzyResourceList fuzzyList; - - public FuzzyStorageChannelImpl(final FuzzyResourceList fuzzyList) { - super(fuzzyList); - this.fuzzyList = fuzzyList; - } - - @Override - public Collection getFuzzy(final ResourceKey resource) { - return fuzzyList.getFuzzy(resource); - } -} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/PlatformStorageChannelType.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/PlatformStorageChannelType.java deleted file mode 100644 index 562aa08f5..000000000 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/PlatformStorageChannelType.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.api.storage.channel; - -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.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; - -import java.util.Optional; -import java.util.function.BiConsumer; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; -import org.apiguardian.api.API; - -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.5") -public interface PlatformStorageChannelType extends StorageChannelType { - CompoundTag toTag(ResourceKey resource); - - CompoundTag toTag(ResourceKey resource, TrackedResource trackedResource); - - void fromTag(CompoundTag tag, BiConsumer acceptor); - - Optional fromTag(CompoundTag tag); - - void toBuffer(ResourceKey resource, FriendlyByteBuf buf); - - ResourceKey fromBuffer(FriendlyByteBuf buf); - - Optional toGridResource(ResourceAmount resourceAmount); - - boolean isGridResourceBelonging(GridResource gridResource); - - MutableComponent getTitle(); - - ResourceLocation getTextureIdentifier(); - - int getXTexture(); - - int getYTexture(); - - long normalizeAmount(double amount); - - double getDisplayAmount(long amount); - - long getInterfaceExportLimit(); - - default long getInterfaceExportLimit(ResourceKey resource) { - return getInterfaceExportLimit(); - } - - GridOperations createGridOperations(StorageChannel storageChannel, Actor actor); -} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/externalstorage/PlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/externalstorage/PlatformExternalStorageProviderFactory.java index fa19c0b55..1a5d81545 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/externalstorage/PlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/externalstorage/PlatformExternalStorageProviderFactory.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage2.platform.api.storage.externalstorage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import java.util.Optional; @@ -12,10 +11,7 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") public interface PlatformExternalStorageProviderFactory { - Optional create(ServerLevel level, - BlockPos pos, - Direction direction, - StorageChannelType storageChannelType); + Optional create(ServerLevel level, BlockPos pos, Direction direction); default int getPriority() { return 0; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/AbstractResourceType.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/AbstractResourceType.java new file mode 100644 index 000000000..e634d2443 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/AbstractResourceType.java @@ -0,0 +1,51 @@ +package com.refinedmods.refinedstorage2.platform.api.support.resource; + +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") +public abstract class AbstractResourceType implements ResourceType { + private final String name; + private final MutableComponent title; + private final ResourceLocation textureIdentifier; + private final int textureX; + private final int textureY; + + protected AbstractResourceType(final String name, + final MutableComponent title, + final ResourceLocation textureIdentifier, + final int textureX, + final int textureY) { + this.name = name; + this.title = title; + this.textureIdentifier = textureIdentifier; + this.textureX = textureX; + this.textureY = textureY; + } + + @Override + public MutableComponent getTitle() { + return title; + } + + @Override + public ResourceLocation getTextureIdentifier() { + return textureIdentifier; + } + + @Override + public int getXTexture() { + return textureX; + } + + @Override + public int getYTexture() { + return textureY; + } + + @Override + public String toString() { + return name; + } +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/PlatformResourceKey.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/PlatformResourceKey.java new file mode 100644 index 000000000..b6987d6c6 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/PlatformResourceKey.java @@ -0,0 +1,18 @@ +package com.refinedmods.refinedstorage2.platform.api.support.resource; + +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.4") +public interface PlatformResourceKey extends ResourceKey { + CompoundTag toTag(); + + void toBuffer(FriendlyByteBuf buf); + + long getInterfaceExportLimit(); + + ResourceType getResourceType(); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceAmountTemplate.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceAmountTemplate.java deleted file mode 100644 index 367a9bb96..000000000 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceAmountTemplate.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.api.support.resource; - -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; - -import java.util.Objects; - -import net.minecraft.world.item.ItemStack; -import org.apiguardian.api.API; - -/** - * A ResourceAmountTemplate is the combination of a {@link com.refinedmods.refinedstorage2.api.resource.ResourceAmount} - * and a {@link ResourceTemplate}. It identifies a resource, its storage channel type and an amount. - * Additionally, for performance reasons, it provides an {@link ItemStack} representation. - */ -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.13") -public class ResourceAmountTemplate { - private final ResourceTemplate resourceTemplate; - private final long amount; - private final ItemStack stackRepresentation; - - public ResourceAmountTemplate(final ResourceKey resource, - final long amount, - final PlatformStorageChannelType storageChannelType) { - this.resourceTemplate = new ResourceTemplate(resource, storageChannelType); - this.amount = amount; - this.stackRepresentation = resource instanceof ItemResource itemResource - ? itemResource.toItemStack(amount) - : ItemStack.EMPTY; - } - - public ResourceKey getResource() { - return resourceTemplate.resource(); - } - - public PlatformStorageChannelType getStorageChannelType() { - return (PlatformStorageChannelType) resourceTemplate.storageChannelType(); - } - - public long getAmount() { - return amount; - } - - public ResourceTemplate getResourceTemplate() { - return resourceTemplate; - } - - public ItemStack getStackRepresentation() { - return stackRepresentation; - } - - public ResourceAmountTemplate withAmount(final long newAmount) { - return new ResourceAmountTemplate( - resourceTemplate.resource(), - newAmount, - (PlatformStorageChannelType) resourceTemplate.storageChannelType() - ); - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final ResourceAmountTemplate that = (ResourceAmountTemplate) o; - return Objects.equals(amount, that.amount) - && Objects.equals(resourceTemplate.resource(), that.resourceTemplate.resource()); - } - - @Override - public int hashCode() { - return Objects.hash(amount, resourceTemplate.resource()); - } -} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceContainer.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceContainer.java index 2cc1d9733..e1808bf11 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceContainer.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceContainer.java @@ -1,9 +1,8 @@ package com.refinedmods.refinedstorage2.platform.api.support.resource; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import java.util.List; import java.util.Set; @@ -26,7 +25,7 @@ public interface ResourceContainer { void change(int index, ItemStack stack, boolean tryAlternatives); - void set(int index, ResourceAmountTemplate resourceAmount); + void set(int index, ResourceAmount resourceAmount); long getAmount(int index); @@ -36,7 +35,7 @@ public interface ResourceContainer { void setAmount(int index, long amount); - long getMaxAmount(ResourceAmountTemplate resourceAmount); + long getMaxAmount(ResourceKey resource); boolean isValid(ResourceKey resource); @@ -44,12 +43,21 @@ public interface ResourceContainer { int size(); + default boolean isEmpty(int index) { + return get(index) == null; + } + + @Nullable + ResourceAmount get(int index); + @Nullable - ResourceAmountTemplate get(int index); + PlatformResourceKey getResource(int index); + + ItemStack getStackRepresentation(int index); - Set getUniqueTemplates(); + Set getUniqueResources(); - List getTemplates(); + List getResources(); void writeToUpdatePacket(FriendlyByteBuf buf); @@ -65,7 +73,7 @@ public interface ResourceContainer { Container toItemContainer(); - long insert(StorageChannelType storageChannelType, ResourceKey resource, long amount, Action action); + long insert(ResourceKey resource, long amount, Action action); long extract(ResourceKey resource, long amount, Action action); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceFactory.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceFactory.java index 732c02c36..5d37f2177 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceFactory.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceFactory.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage2.platform.api.support.resource; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import java.util.Optional; @@ -9,7 +10,7 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.13") public interface ResourceFactory { - Optional create(ItemStack stack); + Optional create(ItemStack stack); boolean isValid(ResourceKey resource); } 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 new file mode 100644 index 000000000..ea0b7fde8 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ResourceType.java @@ -0,0 +1,41 @@ +package com.refinedmods.refinedstorage2.platform.api.support.resource; + +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.api.grid.view.GridResource; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; + +import java.util.Optional; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.4") +public interface ResourceType { + Optional fromTag(CompoundTag tag); + + PlatformResourceKey fromBuffer(FriendlyByteBuf buf); + + MutableComponent getTitle(); + + ResourceLocation getTextureIdentifier(); + + int getXTexture(); + + int getYTexture(); + + long normalizeAmount(double amount); + + double getDisplayAmount(long amount); + + Optional toGridResource(PlatformResourceKey resource, long amount); + + boolean isGridResourceBelonging(GridResource gridResource); + + long getInterfaceExportLimit(); + + GridOperations createGridOperations(StorageChannel storageChannel, Actor actor); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java index 89068d786..87096e77e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java @@ -1,8 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.constructordestructor.ConstructorScreen; import com.refinedmods.refinedstorage2.platform.common.constructordestructor.DestructorScreen; import com.refinedmods.refinedstorage2.platform.common.content.Items; @@ -27,7 +25,9 @@ import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockScreen; import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlockScreen; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorScreen; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResourceRendering; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResourceRendering; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeScreen; import com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter.WirelessTransmitterScreen; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java index 61a9cbd57..637af1260 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java @@ -5,7 +5,6 @@ import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; 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.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.PlatformApiProxy; @@ -58,7 +57,6 @@ import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveBlock; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveContainerMenu; @@ -94,7 +92,9 @@ import com.refinedmods.refinedstorage2.platform.common.support.SimpleItem; import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyLootItemFunction; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeContainerBlockEntityImpl; +import com.refinedmods.refinedstorage2.platform.common.support.network.component.PlatformStorageNetworkComponent; import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.common.upgrade.FortuneUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.upgrade.RangeUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeContainerMenu; @@ -173,7 +173,7 @@ public abstract class AbstractModInitializer { protected final void initializePlatformApi() { ((PlatformApiProxy) PlatformApi.INSTANCE).setDelegate(new PlatformApiImpl()); registerAdditionalStorageTypes(); - registerAdditionalStorageChannelTypes(); + registerAdditionalResourceTypes(); registerAdditionalResourceFactories(); registerDestructorStrategyFactories(); registerConstructorStrategyFactories(); @@ -190,10 +190,10 @@ private void registerAdditionalStorageTypes() { ); } - private void registerAdditionalStorageChannelTypes() { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().register( + private void registerAdditionalResourceTypes() { + PlatformApi.INSTANCE.getResourceTypeRegistry().register( createIdentifier(FLUID_REGISTRY_KEY), - StorageChannelTypes.FLUID + ResourceTypes.FLUID ); } @@ -238,9 +238,7 @@ private void registerNetworkComponents() { ); PlatformApi.INSTANCE.getNetworkComponentMapFactory().addFactory( StorageNetworkComponent.class, - network -> new StorageNetworkComponentImpl( - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getAll() - ) + network -> new PlatformStorageNetworkComponent() ); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java index 54bdec5c8..61c22ab7e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java @@ -91,11 +91,11 @@ interface GridEntry extends SimpleEnergyUsageEntry { void setSize(GridSize size); - Optional getStorageChannelType(); + Optional getResourceTypeId(); - void setStorageChannelType(ResourceLocation storageChannelTypeId); + void setResourceTypeId(ResourceLocation resourceTypeId); - void clearStorageChannelType(); + void clearResourceType(); } interface CraftingGridEntry extends SimpleEnergyUsageEntry { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java index c79d34b4c..132868491 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Platform.java @@ -4,13 +4,13 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.ClientToServerCommunications; import com.refinedmods.refinedstorage2.platform.common.support.ServerToClientCommunications; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.MenuOpener; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.TransferManager; import com.refinedmods.refinedstorage2.platform.common.support.render.FluidRenderer; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.Optional; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index b6e8e0ccc..5eab2aa38 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -28,7 +28,6 @@ import com.refinedmods.refinedstorage2.platform.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy; @@ -40,6 +39,7 @@ import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; import com.refinedmods.refinedstorage2.platform.api.wirelesstransmitter.WirelessTransmitterRangeModifier; @@ -56,7 +56,6 @@ import com.refinedmods.refinedstorage2.platform.common.storage.StorageContainerItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.storage.StorageRepositoryImpl; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.CompositeStorageMonitorExtractionStrategy; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.CompositeStorageMonitorInsertionStrategy; import com.refinedmods.refinedstorage2.platform.common.support.energy.EnergyItemHelperImpl; @@ -70,6 +69,7 @@ import com.refinedmods.refinedstorage2.platform.common.support.registry.PlatformRegistryImpl; import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResourceFactory; import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.common.upgrade.BuiltinUpgradeDestinationsImpl; import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeRegistryImpl; import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; @@ -117,8 +117,8 @@ public class PlatformApiImpl implements PlatformApi { new NetworkBuilderImpl(new NetworkFactory(networkComponentMapFactory)); private final PlatformRegistry storageTypeRegistry = new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), StorageTypes.ITEM); - private final PlatformRegistry storageChannelTypeRegistry = - new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), StorageChannelTypes.ITEM); + private final PlatformRegistry resourceTypeRegistry = + new PlatformRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), ResourceTypes.ITEM); private final PlatformRegistry gridSynchronizerRegistry = new PlatformRegistryImpl<>(createIdentifier("off"), new NoopGridSynchronizer()); private final PlatformRegistry importerTransferStrategyRegistry = @@ -200,8 +200,8 @@ private StorageRepositoryImpl createStorageRepository() { } @Override - public PlatformRegistry getStorageChannelTypeRegistry() { - return storageChannelTypeRegistry; + public PlatformRegistry getResourceTypeRegistry() { + return resourceTypeRegistry; } @Override @@ -281,7 +281,7 @@ public PlatformRegistry getGridSynchronizerRegistry() { @Override public void writeGridScreenOpeningData(final Grid grid, final FriendlyByteBuf buf) { - AbstractGridContainerMenu.writeScreenOpeningData(storageChannelTypeRegistry, grid, buf); + AbstractGridContainerMenu.writeScreenOpeningData(grid, buf); } @Override @@ -392,11 +392,6 @@ public ResourceFactory getItemResourceFactory() { return itemResourceFactory; } - @Override - public PlatformStorageChannelType getItemStorageChannelType() { - return StorageChannelTypes.ITEM; - } - @Override public StorageType getItemStorageType() { return StorageTypes.ITEM; @@ -407,11 +402,6 @@ public ResourceFactory getFluidResourceFactory() { return fluidResourceFactory; } - @Override - public PlatformStorageChannelType getFluidStorageChannelType() { - return StorageChannelTypes.FLUID; - } - @Override public StorageType getFluidStorageType() { return StorageTypes.FLUID; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java index 9ef09ac11..21da8eb65 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformProxy.java @@ -4,13 +4,13 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.ClientToServerCommunications; import com.refinedmods.refinedstorage2.platform.common.support.ServerToClientCommunications; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.MenuOpener; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.TransferManager; import com.refinedmods.refinedstorage2.platform.common.support.render.FluidRenderer; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.Optional; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java index ba4eb7c67..deaff8a3c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java @@ -7,8 +7,7 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.constructordestructor.ConstructorStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -44,8 +43,7 @@ public final boolean apply( if (!(resource instanceof ItemResource itemResource)) { return false; } - final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM); + final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class); final long amount = getTransferAmount(); final long extractedAmount = storageChannel.extract(itemResource, amount, Action.SIMULATE, actor); if (extractedAmount == 0) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java index e8bda31e4..0b15939a8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java @@ -7,9 +7,8 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.constructordestructor.DestructorStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.function.Supplier; @@ -76,9 +75,7 @@ public boolean apply(final Filter filter, } private static StorageChannel getStorageChannel(final Supplier network) { - return network.get() - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM); + return network.get().getComponent(StorageNetworkComponent.class); } private static boolean isFastExit(final BlockState blockState) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java index 567392f1e..05e3eae2d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ConstructorBlockEntity.java @@ -57,9 +57,9 @@ public ConstructorBlockEntity(final BlockPos pos, final BlockState state) { } @Override - protected void setFilterTemplates(final List templates) { + protected void setFilters(final List filters) { this.tasks.clear(); - this.tasks.addAll(templates.stream().map(TaskImpl::new).toList()); + this.tasks.addAll(filters.stream().map(TaskImpl::new).toList()); } @Override @@ -157,10 +157,10 @@ protected record TaskContext(Network network, Player player) { } private class TaskImpl implements Task { - private final ResourceKey template; + private final ResourceKey filter; - private TaskImpl(final ResourceKey template) { - this.template = template; + private TaskImpl(final ResourceKey filter) { + this.filter = filter; } @Override @@ -168,7 +168,7 @@ public boolean run(final TaskContext context) { if (strategy == null) { return false; } - strategy.apply(template, actor, context.player, context.network); + strategy.apply(filter, actor, context.player, context.network); return true; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlockEntity.java index 045d6288f..87441fbdc 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/DestructorBlockEntity.java @@ -54,10 +54,10 @@ public DestructorBlockEntity(final BlockPos pos, final BlockState state) { UpgradeDestinations.DESTRUCTOR ); this.actor = new NetworkNodeActor(getNode()); - this.filterWithFuzzyMode = FilterWithFuzzyMode.createAndListenForUniqueTemplates( + this.filterWithFuzzyMode = FilterWithFuzzyMode.createAndListenForUniqueFilters( ResourceContainerImpl.createForFilter(), this::setChanged, - filter::setTemplates + filter::setFilters ); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java index ac47b1d28..74bdc3a7b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java @@ -7,9 +7,8 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.constructordestructor.DestructorStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.function.Supplier; @@ -74,8 +73,6 @@ private boolean tryInsert(final Actor actor, } private StorageChannel getStorageChannel(final Supplier networkSupplier) { - return networkSupplier.get() - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.FLUID); + return networkSupplier.get().getComponent(StorageNetworkComponent.class); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java index 74a92fa58..8f7d46595 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemDropConstructorStrategy.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.constructordestructor; import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java index be763c8df..b010c19fc 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java @@ -7,8 +7,7 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.constructordestructor.DestructorStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.function.Supplier; @@ -37,9 +36,7 @@ public boolean apply(final Filter filter, if (!level.isLoaded(pos)) { return false; } - final StorageChannel storageChannel = networkSupplier.get() - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM); + final StorageChannel storageChannel = networkSupplier.get().getComponent(StorageNetworkComponent.class); final List items = level.getEntitiesOfClass(ItemEntity.class, new AABB(pos)); for (final ItemEntity itemEntity : items) { tryInsert(filter, actor, storageChannel, itemEntity); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceBlockConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceBlockConstructorStrategy.java index b2dd9717f..9a6820ead 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceBlockConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceBlockConstructorStrategy.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.constructordestructor; import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFireworksConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFireworksConstructorStrategy.java index 98a804750..7033f24be 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFireworksConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFireworksConstructorStrategy.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.constructordestructor; import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java index 9cab591ff..b44515091 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java @@ -7,9 +7,8 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.constructordestructor.ConstructorStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -40,8 +39,7 @@ public boolean apply( if (!(resource instanceof FluidResource fluidResource)) { return false; } - final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.FLUID); + final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class); final long bucketAmount = Platform.INSTANCE.getBucketAmount(); final long extractedAmount = storageChannel.extract( fluidResource, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java index ba717d901..680e685a0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlockEntity.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorMode; import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorNetworkNode; import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -51,15 +51,13 @@ public DetectorBlockEntity(final BlockPos pos, final BlockState state) { Platform.INSTANCE.getConfig().getDetector().getEnergyUsage() )); final ResourceContainer resourceContainer = ResourceContainerImpl.createForFilter(1); - this.filter = FilterWithFuzzyMode.createAndListenForTemplates( + this.filter = FilterWithFuzzyMode.createAndListenForFilters( resourceContainer, () -> { propagateAmount(); setChanged(); }, - templates -> getNode().setFilterTemplate( - templates.isEmpty() ? null : templates.get(0) - ) + filters -> getNode().setConfiguredResource(filters.isEmpty() ? null : filters.get(0)) ); initialize(); } @@ -93,10 +91,10 @@ void setAmount(final double amount) { } private void propagateAmount() { - final ResourceAmountTemplate resourceAmount = filter.getFilterContainer().get(0); - final long normalizedAmount = resourceAmount == null + final PlatformResourceKey configuredResource = filter.getFilterContainer().getResource(0); + final long normalizedAmount = configuredResource == null ? (long) amount - : resourceAmount.getStorageChannelType().normalizeAmount(amount); + : configuredResource.getResourceType().normalizeAmount(amount); LOGGER.debug("Updating detector amount of {} normalized as {}", amount, normalizedAmount); getNode().setAmount(normalizedAmount); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/FuzzyDetectorAmountStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/FuzzyDetectorAmountStrategy.java index edaf65267..1a76fa7c2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/FuzzyDetectorAmountStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/FuzzyDetectorAmountStrategy.java @@ -4,7 +4,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.detector.AbstractDetectorAmountStrategy; import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorAmountStrategy; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannel; @@ -16,12 +16,12 @@ class FuzzyDetectorAmountStrategy extends AbstractDetectorAmountStrategy { } @Override - public long getAmount(final Network network, final ResourceTemplate template) { - final StorageChannel storageChannel = getStorageChannel(network, template); + public long getAmount(final Network network, final ResourceKey configuredResource) { + final StorageChannel storageChannel = getStorageChannel(network); if (!(storageChannel instanceof FuzzyStorageChannel fuzzyStorageChannel)) { - return fallback.getAmount(network, template); + return fallback.getAmount(network, configuredResource); } - return fuzzyStorageChannel.getFuzzy(template.resource()) + return fuzzyStorageChannel.getFuzzy(configuredResource) .stream() .mapToLong(ResourceAmount::getAmount) .sum(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlockEntity.java index 98d0f2e3c..36bf2469d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/ExporterBlockEntity.java @@ -95,8 +95,8 @@ protected void setTaskExecutor(final TaskExecutor templates) { - getNode().setFilterTemplates(templates); + protected void setFilters(final List filters) { + getNode().setFilters(filters); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/FuzzyExporterTransferStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/FuzzyExporterTransferStrategy.java index 5bddb7b4e..9e5bf078c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/FuzzyExporterTransferStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/exporter/FuzzyExporterTransferStrategy.java @@ -5,19 +5,14 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannel; import java.util.Collection; import java.util.stream.Collectors; public class FuzzyExporterTransferStrategy extends ExporterTransferStrategyImpl { - public FuzzyExporterTransferStrategy( - final InsertableStorage destination, - final StorageChannelType storageChannelType, - final long transferQuota - ) { - super(destination, storageChannelType, transferQuota); + public FuzzyExporterTransferStrategy(final InsertableStorage destination, final long transferQuota) { + super(destination, transferQuota); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java index 165c41ac4..51277a021 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java @@ -9,11 +9,9 @@ import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.AbstractDirectionalBlock; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ExtendedMenuProvider; import com.refinedmods.refinedstorage2.platform.common.support.network.AbstractRedstoneModeNetworkNodeContainerBlockEntity; @@ -44,20 +42,18 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte } @Override - public List getResources(final StorageChannelType type, - final Class actorType) { + public List getResources(final Class actorType) { return requireNonNull(getNode().getNetwork()) .getComponent(StorageNetworkComponent.class) - .getResources(type, actorType); + .getResources(actorType); } @Override - public GridOperations createOperations(final PlatformStorageChannelType storageChannelType, + public GridOperations createOperations(final ResourceType resourceType, final Actor actor) { final StorageChannel storageChannel = requireNonNull(getNode().getNetwork()) - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(storageChannelType); - return storageChannelType.createGridOperations(storageChannel, actor); + .getComponent(StorageNetworkComponent.class); + return resourceType.createGridOperations(storageChannel, actor); } @Override @@ -67,9 +63,7 @@ public boolean isGridActive() { @Override public Storage getItemStorage() { - return requireNonNull(getNode().getNetwork()) - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM); + return requireNonNull(getNode().getNetwork()).getComponent(StorageNetworkComponent.class); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java index 662eb8192..bf2de122c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java @@ -10,9 +10,9 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridViewBuilder; import com.refinedmods.refinedstorage2.api.grid.view.GridViewBuilderImpl; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; @@ -23,8 +23,9 @@ import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; 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 com.refinedmods.refinedstorage2.platform.common.Config; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.grid.strategy.ClientGridExtractionStrategy; @@ -85,7 +86,7 @@ public abstract class AbstractGridContainerMenu extends AbstractBaseContainerMen private Runnable sizeChangedListener; private GridSynchronizer synchronizer; @Nullable - private PlatformStorageChannelType storageChannelTypeFilter; + private ResourceType resourceTypeFilter; private boolean autoSelected; private boolean active; @Nullable @@ -104,14 +105,14 @@ protected AbstractGridContainerMenu( this.active = buf.readBoolean(); final GridViewBuilder viewBuilder = createViewBuilder(); - final int amountOfStorageChannels = buf.readInt(); - for (int i = 0; i < amountOfStorageChannels; ++i) { - final ResourceLocation id = buf.readResourceLocation(); - final PlatformStorageChannelType storageChannelType = PlatformApi.INSTANCE - .getStorageChannelTypeRegistry() - .get(id) + final int resources = buf.readInt(); + for (int i = 0; i < resources; ++i) { + final ResourceLocation resourceTypeId = buf.readResourceLocation(); + final ResourceType resourceType = PlatformApi.INSTANCE + .getResourceTypeRegistry() + .get(resourceTypeId) .orElseThrow(); - readStorageChannelFromBuffer(storageChannelType, buf, viewBuilder); + readResource(resourceType, buf, viewBuilder); } this.view = viewBuilder.build(); this.view.setSortingDirection(Platform.INSTANCE.getConfig().getGrid().getSortingDirection()); @@ -119,7 +120,7 @@ protected AbstractGridContainerMenu( this.view.setFilterAndSort(filterStorageChannel()); this.synchronizer = loadSynchronizer(); - this.storageChannelTypeFilter = loadStorageChannelType(); + this.resourceTypeFilter = loadResourceType(); this.insertionStrategy = new ClientGridInsertionStrategy(); this.extractionStrategy = new ClientGridExtractionStrategy(); this.scrollingStrategy = new ClientGridScrollingStrategy(); @@ -148,17 +149,17 @@ private Predicate filterStorageChannel() { return gridResource -> Platform.INSTANCE .getConfig() .getGrid() - .getStorageChannelType() - .flatMap(storageChannelTypeId -> PlatformApi.INSTANCE - .getStorageChannelTypeRegistry() - .get(storageChannelTypeId) + .getResourceTypeId() + .flatMap(resourceTypeId -> PlatformApi.INSTANCE + .getResourceTypeRegistry() + .get(resourceTypeId) .map(type -> type.isGridResourceBelonging(gridResource)) ).orElse(true); } private static GridViewBuilder createViewBuilder() { return new GridViewBuilderImpl( - new CompositeGridResourceFactory(PlatformApi.INSTANCE.getStorageChannelTypeRegistry()), + new CompositeGridResourceFactory(PlatformApi.INSTANCE.getResourceTypeRegistry()), GridSortingTypes.NAME, GridSortingTypes.QUANTITY ); @@ -268,19 +269,17 @@ public void onActiveChanged(final boolean newActive) { @Override public void onChanged( - final StorageChannelType storageChannelType, final ResourceKey resource, final long change, @Nullable final TrackedResource trackedResource ) { - if (!(storageChannelType instanceof PlatformStorageChannelType platformStorageChannelType)) { + if (!(resource instanceof PlatformResourceKey platformResource)) { return; } LOGGER.info("{} received a change of {} for {}", this, change, resource); Platform.INSTANCE.getServerToClientCommunications().sendGridUpdate( (ServerPlayer) playerInventory.player, - platformStorageChannelType, - resource, + platformResource, change, trackedResource ); @@ -342,12 +341,12 @@ private GridSynchronizer loadSynchronizer() { } @Nullable - private PlatformStorageChannelType loadStorageChannelType() { + private ResourceType loadResourceType() { return Platform.INSTANCE .getConfig() .getGrid() - .getStorageChannelType() - .flatMap(id -> PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(id)) + .getResourceTypeId() + .flatMap(id -> PlatformApi.INSTANCE.getResourceTypeRegistry().get(id)) .orElse(null); } @@ -356,8 +355,8 @@ public GridSynchronizer getSynchronizer() { } @Nullable - public PlatformStorageChannelType getStorageChannelType() { - return storageChannelTypeFilter; + public ResourceType getResourceType() { + return resourceTypeFilter; } public void toggleSynchronizer() { @@ -372,19 +371,18 @@ public void toggleSynchronizer() { this.synchronizer = newSynchronizer; } - public void toggleStorageChannelType() { - final PlatformRegistry registry = - PlatformApi.INSTANCE.getStorageChannelTypeRegistry(); + public void toggleResourceType() { + final PlatformRegistry registry = PlatformApi.INSTANCE.getResourceTypeRegistry(); final Config.GridEntry config = Platform.INSTANCE.getConfig().getGrid(); - final PlatformStorageChannelType newStorageChannelType = storageChannelTypeFilter == null + final ResourceType newResourceType = resourceTypeFilter == null ? registry.getDefault() - : registry.nextOrNullIfLast(storageChannelTypeFilter); - if (newStorageChannelType == null) { - config.clearStorageChannelType(); + : registry.nextOrNullIfLast(resourceTypeFilter); + if (newResourceType == null) { + config.clearResourceType(); } else { - registry.getId(newStorageChannelType).ifPresent(config::setStorageChannelType); + registry.getId(newResourceType).ifPresent(config::setResourceTypeId); } - this.storageChannelTypeFilter = newStorageChannelType; + this.resourceTypeFilter = newResourceType; this.view.sort(); } @@ -400,8 +398,7 @@ public boolean onInsert(final GridInsertMode insertMode, final boolean tryAltern } @Override - public boolean onExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public boolean onExtract(final PlatformResourceKey resource, final GridExtractMode extractMode, final boolean cursor) { if (grid != null && !grid.isGridActive()) { @@ -410,21 +407,18 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelType, if (extractionStrategy == null) { return false; } - return extractionStrategy.onExtract(storageChannelType, resource, extractMode, cursor); + return extractionStrategy.onExtract(resource, extractMode, cursor); } @Override - public boolean onScroll(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final GridScrollMode scrollMode, - final int slotIndex) { + public boolean onScroll(final PlatformResourceKey resource, final GridScrollMode scrollMode, final int slotIndex) { if (grid != null && !grid.isGridActive()) { return false; } if (scrollingStrategy == null) { return false; } - return scrollingStrategy.onScroll(storageChannelType, resource, scrollMode, slotIndex); + return scrollingStrategy.onScroll(resource, scrollMode, slotIndex); } @Override @@ -447,50 +441,36 @@ protected boolean canTransferSlot(final Slot slot) { return true; } - private static void readStorageChannelFromBuffer(final PlatformStorageChannelType type, - final FriendlyByteBuf buf, - final GridViewBuilder viewBuilder) { - final int size = buf.readInt(); - for (int i = 0; i < size; ++i) { - final ResourceKey resource = type.fromBuffer(buf); - final long amount = buf.readLong(); - final TrackedResource trackedResource = PacketUtil.readTrackedResource(buf); - viewBuilder.withResource(resource, amount, trackedResource); - } + private static void readResource(final ResourceType type, + final FriendlyByteBuf buf, + final GridViewBuilder viewBuilder) { + final ResourceKey resource = type.fromBuffer(buf); + final long amount = buf.readLong(); + final TrackedResource trackedResource = PacketUtil.readTrackedResource(buf); + viewBuilder.withResource(resource, amount, trackedResource); } public void onClear() { view.clear(); } - public static void writeScreenOpeningData(final PlatformRegistry - storageChannelTypeRegistry, - final Grid grid, - final FriendlyByteBuf buf) { + public static void writeScreenOpeningData(final Grid grid, final FriendlyByteBuf buf) { buf.writeBoolean(grid.isGridActive()); - final List types = storageChannelTypeRegistry.getAll(); - buf.writeInt(types.size()); - types.forEach(type -> writeStorageChannel(storageChannelTypeRegistry, type, grid, buf)); - } - - private static void writeStorageChannel( - final PlatformRegistry storageChannelTypeRegistry, - final PlatformStorageChannelType storageChannelType, - final Grid grid, - final FriendlyByteBuf buf - ) { - final ResourceLocation id = storageChannelTypeRegistry.getId(storageChannelType).orElseThrow(); - buf.writeResourceLocation(id); - final List resources = grid.getResources(storageChannelType, PlayerActor.class); + final List resources = grid.getResources(PlayerActor.class); buf.writeInt(resources.size()); - resources.forEach(resource -> writeGridResource(storageChannelType, resource, buf)); + resources.forEach(resource -> writeGridResource(resource, buf)); } - private static void writeGridResource(final PlatformStorageChannelType storageChannelType, - final TrackedResourceAmount resource, + private static void writeGridResource(final TrackedResourceAmount trackedResourceAmount, final FriendlyByteBuf buf) { - storageChannelType.toBuffer(resource.resourceAmount().getResource(), buf); - buf.writeLong(resource.resourceAmount().getAmount()); - PacketUtil.writeTrackedResource(buf, resource.trackedResource()); + final ResourceAmount resourceAmount = trackedResourceAmount.resourceAmount(); + final PlatformResourceKey resource = (PlatformResourceKey) resourceAmount.getResource(); + final ResourceType resourceType = resource.getResourceType(); + final ResourceLocation resourceTypeId = PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType) + .orElseThrow(); + buf.writeResourceLocation(resourceTypeId); + resource.toBuffer(buf); + buf.writeLong(resourceAmount.getAmount()); + PacketUtil.writeTrackedResource(buf, trackedResourceAmount.trackedResource()); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/ClientCraftingGridSource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/ClientCraftingGridSource.java index 00e270207..79450c3f0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/ClientCraftingGridSource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/ClientCraftingGridSource.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.grid; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java index 42a743787..bd48406f7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java @@ -6,11 +6,10 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.util.ContainerUtil; import java.util.Optional; @@ -138,9 +137,7 @@ Optional getNetwork() { } Optional getStorageChannel() { - return getNetwork().map(network -> network - .getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM)); + return getNetwork().map(network -> network.getComponent(StorageNetworkComponent.class)); } ItemStack insert(final ItemStack stack, final Player player) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java index c0f122db4..43ea346da 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java @@ -2,13 +2,13 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; import com.refinedmods.refinedstorage2.platform.common.support.RedstoneMode; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ServerProperty; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.ArrayList; import java.util.HashSet; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContext.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContext.java index 58cf18369..0ac8d7728 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContext.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContext.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.grid; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.world.entity.player.Player; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContextImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContextImpl.java index e3461da2a..2f71301fb 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContextImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridRefillContextImpl.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.grid; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.world.entity.player.Player; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java index 59495bcf2..70d19a96c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridResultSlot.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.grid; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSource.java index 9b463fa97..4616d26da 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSource.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.grid; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java index a98d843bf..b6a27e6dc 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java @@ -4,8 +4,7 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.Comparator; import java.util.List; @@ -135,7 +134,6 @@ private ResourceList createCombinedPlayerInventoryAndNetworkList(final Player pl private void addNetworkItemsIntoList(final ResourceList list) { blockEntity.getNetwork().ifPresent(network -> network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM) .getAll() .forEach(list::add)); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/SnapshotCraftingGridRefillContext.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/SnapshotCraftingGridRefillContext.java index 414de8fd4..be6b8ac63 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/SnapshotCraftingGridRefillContext.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/SnapshotCraftingGridRefillContext.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java index 59b0c06dd..c6f83b215 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java @@ -11,12 +11,10 @@ import com.refinedmods.refinedstorage2.api.storage.NoopStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.NetworkBoundItemSession; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import java.util.Collections; import java.util.List; @@ -54,7 +52,8 @@ public void removeWatcher(final GridWatcher watcher) { @Override public Storage getItemStorage() { - return getStorage().map(storage -> (Storage) storage.getStorageChannel(StorageChannelTypes.ITEM)) + return getStorage() + .map(storage -> (Storage) storage) .orElseGet(NoopStorage::new); } @@ -67,17 +66,15 @@ public boolean isGridActive() { } @Override - public List getResources(final StorageChannelType type, - final Class actorType) { - return getStorage().map(storage -> storage.getResources(type, actorType)).orElse(Collections.emptyList()); + public List getResources(final Class actorType) { + return getStorage().map(storage -> storage.getResources(actorType)).orElse(Collections.emptyList()); } @Override - public GridOperations createOperations(final PlatformStorageChannelType storageChannelType, + public GridOperations createOperations(final ResourceType resourceType, final Actor actor) { return getStorage() - .map(storage -> storage.getStorageChannel(storageChannelType)) - .map(storageChannel -> storageChannelType.createGridOperations(storageChannel, actor)) + .map(storageChannel -> resourceType.createGridOperations(storageChannel, actor)) .map(gridOperations -> (GridOperations) new WirelessGridOperations(gridOperations, session, watchers)) .orElseGet(NoopGridOperations::new); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java index 4ac595f8d..5f43eefe7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java @@ -10,14 +10,13 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.grid.view.PlatformGridResource; import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.DisabledSlot; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.SmallTextClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.support.widget.History; import com.refinedmods.refinedstorage2.platform.common.support.widget.RedstoneModeSideButtonWidget; @@ -120,7 +119,7 @@ protected void init() { addSideButton(new SortingTypeSideButtonWidget(getMenu())); addSideButton(new SizeSideButtonWidget(getMenu())); addSideButton(new AutoSelectedSideButtonWidget(getMenu())); - addSideButton(new StorageChannelTypeSideButtonWidget(getMenu())); + addSideButton(new ResourceTypeSideButtonWidget(getMenu())); final PlatformRegistry synchronizers = PlatformApi.INSTANCE.getGridSynchronizerRegistry(); if (!synchronizers.isEmpty()) { @@ -343,9 +342,9 @@ protected void renderTooltip(final GuiGraphics graphics, final int x, final int } private void renderOverStorageAreaTooltip(final GuiGraphics graphics, final int x, final int y) { - final GridResource resource = getCurrentGridResource(); + final PlatformGridResource resource = getCurrentGridResource(); if (resource != null) { - renderHoveredResourceTooltip(graphics, x, y, resource); + renderHoveredResourceTooltip(graphics, x, y, menu.getView(), resource); return; } final ItemStack carried = getMenu().getCarried(); @@ -356,16 +355,6 @@ private void renderOverStorageAreaTooltip(final GuiGraphics graphics, final int Platform.INSTANCE.renderTooltip(graphics, hints, x, y); } - private void renderHoveredResourceTooltip(final GuiGraphics graphics, - final int mouseX, - final int mouseY, - final GridResource resource) { - if (!(resource instanceof PlatformGridResource platformResource)) { - return; - } - renderHoveredResourceTooltip(graphics, mouseX, mouseY, getMenu().getView(), platformResource); - } - private void renderHoveredResourceTooltip(final GuiGraphics graphics, final int mouseX, final int mouseY, @@ -430,7 +419,7 @@ private boolean isModifiedJustNow(final LastModified lastModified) { @Nullable - public GridResource getCurrentGridResource() { + public PlatformGridResource getCurrentGridResource() { if (currentGridSlotIndex < 0) { return null; } @@ -438,7 +427,7 @@ public GridResource getCurrentGridResource() { if (currentGridSlotIndex >= viewList.size()) { return null; } - return viewList.get(currentGridSlotIndex); + return (PlatformGridResource) viewList.get(currentGridSlotIndex); } @Override @@ -459,7 +448,7 @@ public boolean mouseClicked(final double mouseX, final double mouseY, final int } final ItemStack carriedStack = getMenu().getCarried(); - final GridResource resource = getCurrentGridResource(); + final PlatformGridResource resource = getCurrentGridResource(); if (resource != null && carriedStack.isEmpty()) { mouseClickedInGrid(clickedButton, resource); @@ -483,14 +472,12 @@ private void mouseClickedInGrid(final int clickedButton) { getMenu().onInsert(mode, tryAlternatives); } - protected void mouseClickedInGrid(final int clickedButton, final GridResource resource) { - if (resource instanceof PlatformGridResource platformGridResource) { - platformGridResource.onExtract( - getExtractMode(clickedButton), - shouldExtractToCursor(), - getMenu() - ); - } + protected void mouseClickedInGrid(final int clickedButton, final PlatformGridResource resource) { + resource.onExtract( + getExtractMode(clickedButton), + shouldExtractToCursor(), + getMenu() + ); } private static GridExtractMode getExtractMode(final int clickedButton) { @@ -522,7 +509,7 @@ public boolean mouseScrolled(final double x, final double y, final double z, fin final boolean up = delta > 0; if (isOverStorageArea((int) x, (int) y)) { - final GridResource resource = getCurrentGridResource(); + final PlatformGridResource resource = getCurrentGridResource(); if (resource != null) { mouseScrolledInGrid(up, resource); } @@ -546,24 +533,16 @@ private void mouseScrolledInInventory(final boolean up, final ItemStack stack, f if (scrollMode == null) { return; } - getMenu().onScroll( - StorageChannelTypes.ITEM, - ItemResource.ofItemStack(stack), - scrollMode, - slotIndex - ); + getMenu().onScroll(ItemResource.ofItemStack(stack), scrollMode, slotIndex); } - private void mouseScrolledInGrid(final boolean up, final GridResource resource) { + private void mouseScrolledInGrid(final boolean up, final PlatformGridResource resource) { getMenu().getView().setPreventSorting(true); final GridScrollMode scrollMode = getScrollModeWhenScrollingOnGridArea(up); if (scrollMode == null) { return; } - if (!(resource instanceof PlatformGridResource platformGridResource)) { - return; - } - platformGridResource.onScroll(scrollMode, getMenu()); + resource.onScroll(scrollMode, getMenu()); } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/StorageChannelTypeSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/ResourceTypeSideButtonWidget.java similarity index 57% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/StorageChannelTypeSideButtonWidget.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/ResourceTypeSideButtonWidget.java index 649ed31db..bfa23ab2a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/StorageChannelTypeSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/ResourceTypeSideButtonWidget.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.grid.screen; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.TextureIds; import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractSideButtonWidget; @@ -11,29 +11,29 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -class StorageChannelTypeSideButtonWidget extends AbstractSideButtonWidget { - private static final MutableComponent TITLE = createTranslation("gui", "grid.storage_channel_type"); - private static final MutableComponent SUBTEXT_ALL = createTranslation("gui", "grid.storage_channel_type.all"); - private static final Component HELP = createTranslation("gui", "grid.storage_channel_type.help"); +class ResourceTypeSideButtonWidget extends AbstractSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "grid.resource_type"); + private static final MutableComponent SUBTEXT_ALL = createTranslation("gui", "grid.resource_type.all"); + private static final Component HELP = createTranslation("gui", "grid.resource_type.help"); private final AbstractGridContainerMenu menu; - StorageChannelTypeSideButtonWidget(final AbstractGridContainerMenu menu) { + ResourceTypeSideButtonWidget(final AbstractGridContainerMenu menu) { super(createPressAction(menu)); this.menu = menu; } private static OnPress createPressAction(final AbstractGridContainerMenu menu) { - return btn -> menu.toggleStorageChannelType(); + return btn -> menu.toggleResourceType(); } @Override protected ResourceLocation getTextureIdentifier() { - final PlatformStorageChannelType storageChannelType = menu.getStorageChannelType(); - if (storageChannelType == null) { + final ResourceType resourceType = menu.getResourceType(); + if (resourceType == null) { return TextureIds.ICONS; } - return storageChannelType.getTextureIdentifier(); + return resourceType.getTextureIdentifier(); } @Override @@ -43,11 +43,11 @@ protected MutableComponent getTitle() { @Override protected MutableComponent getSubText() { - final PlatformStorageChannelType storageChannelType = menu.getStorageChannelType(); - if (storageChannelType == null) { + final ResourceType resourceType = menu.getResourceType(); + if (resourceType == null) { return SUBTEXT_ALL; } - return storageChannelType.getTitle(); + return resourceType.getTitle(); } @Override @@ -57,19 +57,19 @@ protected Component getHelpText() { @Override protected int getXTexture() { - final PlatformStorageChannelType storageChannelType = menu.getStorageChannelType(); - if (storageChannelType == null) { + final ResourceType resourceType = menu.getResourceType(); + if (resourceType == null) { return 32; } - return storageChannelType.getXTexture(); + return resourceType.getXTexture(); } @Override protected int getYTexture() { - final PlatformStorageChannelType storageChannelType = menu.getStorageChannelType(); - if (storageChannelType == null) { + final ResourceType resourceType = menu.getResourceType(); + if (resourceType == null) { return 128; } - return storageChannelType.getYTexture(); + return resourceType.getYTexture(); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridExtractionStrategy.java index 78bc09d0b..a4f8d6e6f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridExtractionStrategy.java @@ -1,23 +1,16 @@ package com.refinedmods.refinedstorage2.platform.common.grid.strategy; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; public class ClientGridExtractionStrategy implements GridExtractionStrategy { @Override - public boolean onExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public boolean onExtract(final PlatformResourceKey resource, final GridExtractMode extractMode, final boolean cursor) { - Platform.INSTANCE.getClientToServerCommunications().sendGridExtract( - storageChannelType, - resource, - extractMode, - cursor - ); + Platform.INSTANCE.getClientToServerCommunications().sendGridExtract(resource, extractMode, cursor); return true; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridScrollingStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridScrollingStrategy.java index daea9066b..c3f1dbdda 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridScrollingStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/ClientGridScrollingStrategy.java @@ -1,23 +1,14 @@ package com.refinedmods.refinedstorage2.platform.common.grid.strategy; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; public class ClientGridScrollingStrategy implements GridScrollingStrategy { @Override - public boolean onScroll(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final GridScrollMode scrollMode, - final int slotIndex) { - Platform.INSTANCE.getClientToServerCommunications().sendGridScroll( - storageChannelType, - resource, - scrollMode, - slotIndex - ); + public boolean onScroll(final PlatformResourceKey resource, final GridScrollMode scrollMode, final int slotIndex) { + Platform.INSTANCE.getClientToServerCommunications().sendGridScroll(resource, scrollMode, slotIndex); return true; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridExtractionStrategy.java index 94b364857..4a3a1ba12 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridExtractionStrategy.java @@ -1,9 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.grid.strategy; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import java.util.Collections; import java.util.List; @@ -16,12 +15,11 @@ public CompositeGridExtractionStrategy(final List strate } @Override - public boolean onExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public boolean onExtract(final PlatformResourceKey resource, final GridExtractMode extractMode, final boolean cursor) { for (final GridExtractionStrategy strategy : strategies) { - if (strategy.onExtract(storageChannelType, resource, extractMode, cursor)) { + if (strategy.onExtract(resource, extractMode, cursor)) { return true; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridScrollingStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridScrollingStrategy.java index ac8d1a2b0..73bdfb5e4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridScrollingStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/strategy/CompositeGridScrollingStrategy.java @@ -1,9 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.grid.strategy; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import java.util.Collections; import java.util.List; @@ -16,12 +15,9 @@ public CompositeGridScrollingStrategy(final List strategi } @Override - public boolean onScroll(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final GridScrollMode scrollMode, - final int slotIndex) { + public boolean onScroll(final PlatformResourceKey resource, final GridScrollMode scrollMode, final int slotIndex) { for (final GridScrollingStrategy strategy : strategies) { - if (strategy.onScroll(storageChannelType, resource, scrollMode, slotIndex)) { + if (strategy.onScroll(resource, scrollMode, slotIndex)) { return true; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java index 10abeb6cf..d2fde502b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractFluidGridResourceFactory.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.Optional; import java.util.Set; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java index 3cea0fb3d..19fb2e107 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/AbstractItemGridResourceFactory.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.Optional; import java.util.Set; 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 73cc9a1b4..566afc85a 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 @@ -3,25 +3,27 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; 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; public class CompositeGridResourceFactory implements GridResourceFactory { - private final PlatformRegistry storageChannelTypeRegistry; + private final PlatformRegistry resourceTypeRegistry; - public CompositeGridResourceFactory( - final PlatformRegistry storageChannelTypeRegistry - ) { - this.storageChannelTypeRegistry = storageChannelTypeRegistry; + public CompositeGridResourceFactory(final PlatformRegistry resourceTypeRegistry) { + this.resourceTypeRegistry = resourceTypeRegistry; } @Override public Optional apply(final ResourceAmount resourceAmount) { - return storageChannelTypeRegistry.getAll() + if (!(resourceAmount.getResource() instanceof PlatformResourceKey platformResource)) { + return Optional.empty(); + } + return resourceTypeRegistry.getAll() .stream() - .flatMap(type -> type.toGridResource(resourceAmount).stream()) + .flatMap(type -> type.toGridResource(platformResource, resourceAmount.getAmount()).stream()) .findFirst(); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java index 8f5f4fb65..a50d2e9b3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/FluidGridResource.java @@ -7,9 +7,9 @@ import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.view.AbstractPlatformGridResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResourceRendering; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.MouseWithIconClientTooltipComponent; @@ -17,6 +17,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import javax.annotation.Nullable; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; @@ -60,16 +61,17 @@ public List getExtractionHints() { ).stream().toList(); } + @Nullable + @Override + public PlatformResourceKey getUnderlyingResource() { + return fluidResource; + } + @Override public void onExtract(final GridExtractMode extractMode, final boolean cursor, final GridExtractionStrategy extractionStrategy) { - extractionStrategy.onExtract( - StorageChannelTypes.FLUID, - fluidResource, - extractMode, - cursor - ); + extractionStrategy.onExtract(fluidResource, extractMode, cursor); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/ItemGridResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/ItemGridResource.java index 696b778ee..4d0108900 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/ItemGridResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/view/ItemGridResource.java @@ -8,14 +8,15 @@ import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.view.AbstractPlatformGridResource; import com.refinedmods.refinedstorage2.platform.api.support.AmountFormatting; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.MouseWithIconClientTooltipComponent; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import javax.annotation.Nullable; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -30,6 +31,7 @@ public class ItemGridResource extends AbstractPlatformGridResource { private final int id; private final ItemStack itemStack; + private final ItemResource itemResource; public ItemGridResource(final ResourceAmount resourceAmount, final ItemStack itemStack, @@ -44,7 +46,8 @@ public ItemGridResource(final ResourceAmount resourceAmount, GridResourceAttributeKeys.TAGS, tags, GridResourceAttributeKeys.TOOLTIP, Set.of(tooltip) )); - this.id = Item.getId(((ItemResource) resourceAmount.getResource()).item()); + this.itemResource = (ItemResource) resourceAmount.getResource(); + this.id = Item.getId(itemResource.item()); this.itemStack = itemStack; } @@ -52,8 +55,10 @@ public ItemStack getItemStack() { return itemStack; } - public ItemStack copyItemStack() { - return itemStack.copyWithCount(1); + @Nullable + @Override + public PlatformResourceKey getUnderlyingResource() { + return itemResource; } @Override @@ -83,22 +88,12 @@ public List getExtractionHints() { public void onExtract(final GridExtractMode extractMode, final boolean cursor, final GridExtractionStrategy extractionStrategy) { - extractionStrategy.onExtract( - StorageChannelTypes.ITEM, - resourceAmount.getResource(), - extractMode, - cursor - ); + extractionStrategy.onExtract(itemResource, extractMode, cursor); } @Override public void onScroll(final GridScrollMode scrollMode, final GridScrollingStrategy scrollingStrategy) { - scrollingStrategy.onScroll( - StorageChannelTypes.ITEM, - resourceAmount.getResource(), - scrollMode, - -1 - ); + scrollingStrategy.onScroll(itemResource, scrollMode, -1); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/ExportedResourcesContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/ExportedResourcesContainer.java index f60496149..256291e54 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/ExportedResourcesContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/ExportedResourcesContainer.java @@ -3,13 +3,10 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportState; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannel; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.resource.FuzzyModeNormalizer; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainerType; import com.refinedmods.refinedstorage2.platform.common.support.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceContainerImpl; @@ -55,12 +52,12 @@ public Collection expandExportCandidates(final StorageChannel stora } @Override - public boolean isExportedResourceValid(final ResourceTemplate want, final ResourceTemplate got) { + public boolean isExportedResourceValid(final ResourceKey want, final ResourceKey got) { if (!filter.isFuzzyMode()) { return got.equals(want); } - final ResourceKey normalizedGot = normalize(got.resource()); - final ResourceKey normalizedWant = normalize(want.resource()); + final ResourceKey normalizedGot = normalize(got); + final ResourceKey normalizedWant = normalize(want); return normalizedGot.equals(normalizedWant); } @@ -73,31 +70,19 @@ private ResourceKey normalize(final ResourceKey resource) { @Nullable @Override - public ResourceTemplate getRequestedResource(final int slotIndex) { - final ResourceAmountTemplate resourceAmount = filter.getFilterContainer().get(slotIndex); - if (resourceAmount == null) { - return null; - } - return resourceAmount.getResourceTemplate(); + public ResourceKey getRequestedResource(final int slotIndex) { + return filter.getFilterContainer().getResource(slotIndex); } @Override public long getRequestedAmount(final int slotIndex) { - final ResourceAmountTemplate resourceAmount = filter.getFilterContainer().get(slotIndex); - if (resourceAmount == null) { - return 0; - } - return resourceAmount.getAmount(); + return filter.getFilterContainer().getAmount(slotIndex); } @Nullable @Override - public ResourceTemplate getExportedResource(final int slotIndex) { - final ResourceAmountTemplate resourceAmount = get(slotIndex); - if (resourceAmount == null) { - return null; - } - return resourceAmount.getResourceTemplate(); + public ResourceKey getExportedResource(final int slotIndex) { + return getResource(slotIndex); } @Override @@ -106,12 +91,8 @@ public long getExportedAmount(final int slotIndex) { } @Override - public void setExportSlot(final int slotIndex, final ResourceTemplate resource, final long amount) { - set(slotIndex, new ResourceAmountTemplate( - resource.resource(), - amount, - (PlatformStorageChannelType) resource.storageChannelType() - )); + public void setExportSlot(final int slotIndex, final ResourceKey resource, final long amount) { + set(slotIndex, new ResourceAmount(resource, amount)); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceBlockEntity.java index db5db3846..87ec873b6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceBlockEntity.java @@ -3,10 +3,9 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.externalstorage.InterfaceExternalStorageProvider; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.externalstorage.InterfaceExternalStorageProviderImpl; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainerType; import com.refinedmods.refinedstorage2.platform.common.Platform; @@ -18,8 +17,6 @@ import com.refinedmods.refinedstorage2.platform.common.support.network.AbstractRedstoneModeNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceContainerImpl; -import java.util.HashMap; -import java.util.Map; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; @@ -44,7 +41,7 @@ public class InterfaceBlockEntity private final FilterWithFuzzyMode filter; private final ExportedResourcesContainer exportedResources; private final Container exportedResourcesAsContainer; - private final Map externalStorageProviders = new HashMap<>(); + private final InterfaceExternalStorageProvider externalStorageProvider; public InterfaceBlockEntity(final BlockPos pos, final BlockState state) { super( @@ -59,22 +56,7 @@ public InterfaceBlockEntity(final BlockPos pos, final BlockState state) { this.exportedResources.setListener(this::setChanged); getNode().setExportState(exportedResources); this.exportedResourcesAsContainer = exportedResources.toItemContainer(); - addExternalStorageProviders(); - } - - private void addExternalStorageProviders() { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getAll().forEach( - storageChannelType -> externalStorageProviders.put( - storageChannelType, - createExternalStorageProvider(storageChannelType) - ) - ); - } - - private InterfaceExternalStorageProviderImpl createExternalStorageProvider( - final PlatformStorageChannelType storageChannelType - ) { - return new InterfaceExternalStorageProviderImpl(getNode(), storageChannelType); + this.externalStorageProvider = new InterfaceExternalStorageProviderImpl(getNode()); } static ResourceContainer createFilterContainer() { @@ -91,9 +73,9 @@ static ExportedResourcesContainer createExportedResourcesContainer(final FilterW return new ExportedResourcesContainer(EXPORT_SLOTS, filter); } - static long getTransferQuota(final ResourceTemplate resourceTemplate) { - if (resourceTemplate.storageChannelType() instanceof PlatformStorageChannelType storageChannelType) { - return storageChannelType.getInterfaceExportLimit(resourceTemplate.resource()); + static long getTransferQuota(final ResourceKey resource) { + if (resource instanceof PlatformResourceKey platformResource) { + return platformResource.getInterfaceExportLimit(); } return 0; } @@ -173,7 +155,7 @@ public NonNullList getDrops() { return drops; } - InterfaceExternalStorageProvider getExternalStorageProvider(final StorageChannelType storageChannelType) { - return externalStorageProviders.get(storageChannelType); + InterfaceExternalStorageProvider getExternalStorageProvider() { + return externalStorageProvider; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfacePlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfacePlatformExternalStorageProviderFactory.java index 7836fdb7c..16969e1a6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfacePlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfacePlatformExternalStorageProviderFactory.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage2.platform.common.iface; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; @@ -14,12 +13,11 @@ public class InterfacePlatformExternalStorageProviderFactory implements Platform @Override public Optional create(final ServerLevel level, final BlockPos pos, - final Direction direction, - final StorageChannelType storageChannelType) { + final Direction direction) { if (!(level.getBlockEntity(pos) instanceof InterfaceBlockEntity)) { return Optional.empty(); } - return Optional.of(new InterfaceProxyExternalStorageProvider(level, pos, storageChannelType)); + return Optional.of(new InterfaceProxyExternalStorageProvider(level, pos)); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceProxyExternalStorageProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceProxyExternalStorageProvider.java index 8e1608779..329681e7c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceProxyExternalStorageProvider.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/iface/InterfaceProxyExternalStorageProvider.java @@ -6,7 +6,6 @@ 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.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.network.AbstractNetworkNodeContainerBlockEntity; import java.util.Collections; @@ -20,14 +19,10 @@ class InterfaceProxyExternalStorageProvider implements InterfaceExternalStorageProvider { private final Level level; private final BlockPos pos; - private final StorageChannelType storageChannelType; - InterfaceProxyExternalStorageProvider(final Level level, - final BlockPos pos, - final StorageChannelType storageChannelType) { + InterfaceProxyExternalStorageProvider(final Level level, final BlockPos pos) { this.level = level; this.pos = pos; - this.storageChannelType = storageChannelType; } private Optional tryGetInterface() { @@ -38,7 +33,7 @@ private Optional tryGetInterface() { } private Optional tryGetProvider() { - return tryGetInterface().map(iface -> iface.getExternalStorageProvider(storageChannelType)); + return tryGetInterface().map(InterfaceBlockEntity::getExternalStorageProvider); } @Override 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 0c916a295..0662ab826 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 @@ -55,10 +55,10 @@ public ImporterBlockEntity(final BlockPos pos, final BlockState state) { new ImporterNetworkNode(0), UpgradeDestinations.IMPORTER ); - this.filter = FilterWithFuzzyMode.createAndListenForUniqueTemplates( + this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( ResourceContainerImpl.createForFilter(), this::setChanged, - templates -> getNode().setFilterTemplates(templates) + filters -> getNode().setFilters(filters) ); getNode().setNormalizer(filter.createNormalizer()); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/CompositeIngredientConverter.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/CompositeIngredientConverter.java index dcb533bf1..fec6421ed 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/CompositeIngredientConverter.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/CompositeIngredientConverter.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.recipemod; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import java.util.Collection; import java.util.HashSet; @@ -11,14 +11,14 @@ public class CompositeIngredientConverter implements IngredientConverter { private final Collection converters = new HashSet<>(); @Override - public Optional convertToResource(final Object ingredient) { + public Optional convertToResource(final Object ingredient) { return converters.stream() .flatMap(converter -> converter.convertToResource(ingredient).stream()) .findFirst(); } @Override - public Optional convertToIngredient(final Object resource) { + public Optional convertToIngredient(final PlatformResourceKey resource) { return converters.stream() .flatMap(converter -> converter.convertToIngredient(resource).stream()) .findFirst(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java index 9f30b8a28..e377b7a27 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/CraftingGridRecipeTransferHandler.java @@ -1,9 +1,9 @@ package com.refinedmods.refinedstorage2.platform.common.recipemod.jei; import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.Optional; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GhostIngredientHandler.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GhostIngredientHandler.java index 34d6f9dc2..df62f1a8e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GhostIngredientHandler.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GhostIngredientHandler.java @@ -1,8 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.recipemod.jei; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; @@ -40,7 +39,7 @@ private List> getTargets(final AbstractBaseScreen screen, final List> targets = new ArrayList<>(); ingredientConverter.convertToResource(ingredient).ifPresent(resource -> { for (final ResourceSlot slot : menu.getResourceSlots()) { - if (slot.isFilter() && slot.isValid(resource.resource())) { + if (slot.isFilter() && slot.isValid(resource)) { final Rect2i bounds = getBounds(screen, slot); targets.add(new TargetImpl<>(bounds, slot.index)); } @@ -77,10 +76,9 @@ public void accept(final I ingredient) { ingredientConverter.convertToResource(ingredient).ifPresent(this::accept); } - private void accept(final ResourceTemplate resource) { + private void accept(final PlatformResourceKey resource) { Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotChange( - (PlatformStorageChannelType) resource.storageChannelType(), - resource.resource(), + resource, slotIndex ); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GridGuiContainerHandler.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GridGuiContainerHandler.java index 8c7963508..a11f0ce02 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GridGuiContainerHandler.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GridGuiContainerHandler.java @@ -1,7 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.recipemod.jei; -import com.refinedmods.refinedstorage2.api.grid.view.GridResource; +import com.refinedmods.refinedstorage2.platform.api.grid.view.PlatformGridResource; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.grid.screen.AbstractGridScreen; import java.util.Optional; @@ -27,13 +28,17 @@ public Optional> getClickableIngredientUnderMouse( final double mouseX, final double mouseY ) { - final GridResource resource = screen.getCurrentGridResource(); + final PlatformGridResource resource = screen.getCurrentGridResource(); if (resource == null) { return Optional.empty(); } - return converter - .convertToIngredient(resource) - .flatMap(ingredient -> convertToClickableIngredient(mouseX, mouseY, ingredient)); + final PlatformResourceKey underlyingResource = resource.getUnderlyingResource(); + if (underlyingResource == null) { + return Optional.empty(); + } + return converter.convertToIngredient(underlyingResource).flatMap( + ingredient -> convertToClickableIngredient(mouseX, mouseY, ingredient) + ); } private Optional> convertToClickableIngredient(final double x, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GridResourceIngredientConverter.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GridResourceIngredientConverter.java deleted file mode 100644 index e834aea76..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/GridResourceIngredientConverter.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.recipemod.jei; - -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.common.grid.view.FluidGridResource; -import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; - -import java.util.Optional; - -import mezz.jei.api.helpers.IPlatformFluidHelper; - -class GridResourceIngredientConverter implements IngredientConverter { - private final IPlatformFluidHelper fluidHelper; - - GridResourceIngredientConverter(final IPlatformFluidHelper fluidHelper) { - this.fluidHelper = fluidHelper; - } - - @Override - public Optional convertToResource(final Object ingredient) { - return Optional.empty(); - } - - @Override - public Optional convertToIngredient(final Object resource) { - if (resource instanceof ItemGridResource itemGridResource) { - return Optional.of(itemGridResource.copyItemStack()); - } - if (resource instanceof FluidGridResource fluidGridResource) { - final FluidResource fluidResource = (FluidResource) fluidGridResource.getResource(); - return Optional.of(fluidHelper.create( - fluidResource.fluid(), - fluidHelper.bucketVolume(), - fluidResource.tag() - )); - } - return Optional.empty(); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/IngredientConvertImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/IngredientConvertImpl.java new file mode 100644 index 000000000..c9bcc7efd --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/IngredientConvertImpl.java @@ -0,0 +1,47 @@ +package com.refinedmods.refinedstorage2.platform.common.recipemod.jei; + +import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; + +import java.util.Optional; + +import mezz.jei.api.helpers.IPlatformFluidHelper; +import net.minecraft.world.item.ItemStack; + +class IngredientConvertImpl implements IngredientConverter { + private final IPlatformFluidHelper fluidHelper; + + IngredientConvertImpl(final IPlatformFluidHelper fluidHelper) { + this.fluidHelper = fluidHelper; + } + + @Override + public Optional convertToResource(final Object ingredient) { + final var fluid = Platform.INSTANCE.convertJeiIngredientToFluid(ingredient); + if (fluid.isPresent()) { + return fluid.map(f -> f); + } + if (ingredient instanceof ItemStack itemStack) { + return Optional.of(ItemResource.ofItemStack(itemStack)); + } + return Optional.empty(); + } + + @Override + public Optional convertToIngredient(final PlatformResourceKey resource) { + if (resource instanceof ItemResource itemResource) { + return Optional.of(itemResource.toItemStack()); + } + if (resource instanceof FluidResource fluidResource) { + return Optional.of(fluidHelper.create( + fluidResource.fluid(), + fluidHelper.bucketVolume(), + fluidResource.tag() + )); + } + return Optional.empty(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java index 7c322fa83..767208eb4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/RefinedStorageJeiModPlugin.java @@ -87,7 +87,6 @@ private void registerGridSynchronizers() { } private void registerIngredientConverters(final IPlatformFluidHelper fluidHelper) { - PlatformApi.INSTANCE.registerIngredientConverter(new GridResourceIngredientConverter(fluidHelper)); - PlatformApi.INSTANCE.registerIngredientConverter(new ResourceIngredientConverter(fluidHelper)); + PlatformApi.INSTANCE.registerIngredientConverter(new IngredientConvertImpl(fluidHelper)); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/ResourceGuiContainerHandler.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/ResourceGuiContainerHandler.java index fef75c755..a6dc2c7c1 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/ResourceGuiContainerHandler.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/ResourceGuiContainerHandler.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.recipemod.jei; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import java.util.Optional; @@ -32,11 +32,11 @@ public Optional> getClickableIngredientUnderMouse( return convertToIngredient(baseScreen.getHoveredResource()).flatMap(this::convertToClickableIngredient); } - public Optional convertToIngredient(@Nullable final ResourceTemplate resourceTemplate) { - if (resourceTemplate == null) { + public Optional convertToIngredient(@Nullable final PlatformResourceKey resource) { + if (resource == null) { return Optional.empty(); } - return converter.convertToIngredient(resourceTemplate); + return converter.convertToIngredient(resource); } private Optional> convertToClickableIngredient(final Object ingredient) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/ResourceIngredientConverter.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/ResourceIngredientConverter.java deleted file mode 100644 index 1e808e1eb..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/recipemod/jei/ResourceIngredientConverter.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.recipemod.jei; - -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; - -import java.util.Optional; - -import mezz.jei.api.helpers.IPlatformFluidHelper; -import net.minecraft.world.item.ItemStack; - -class ResourceIngredientConverter implements IngredientConverter { - private final IPlatformFluidHelper fluidHelper; - - ResourceIngredientConverter(final IPlatformFluidHelper fluidHelper) { - this.fluidHelper = fluidHelper; - } - - @Override - public Optional convertToResource(final Object ingredient) { - final var fluid = Platform.INSTANCE.convertJeiIngredientToFluid(ingredient); - if (fluid.isPresent()) { - return fluid.map(fluidResource -> new ResourceTemplate( - fluidResource, - StorageChannelTypes.FLUID - )); - } - if (ingredient instanceof ItemStack itemStack) { - return Optional.of(new ResourceTemplate( - ItemResource.ofItemStack(itemStack), - StorageChannelTypes.ITEM - )); - } - return Optional.empty(); - } - - @Override - public Optional convertToIngredient(final Object resource) { - if (!(resource instanceof ResourceTemplate resourceTemplate)) { - return Optional.empty(); - } - if (resourceTemplate.resource() instanceof ItemResource itemResource) { - return Optional.of(itemResource.toItemStack()); - } - if (resourceTemplate.resource() instanceof FluidResource fluidResource) { - return Optional.of(fluidHelper.create( - fluidResource.fluid(), - fluidHelper.bucketVolume(), - fluidResource.tag() - )); - } - return Optional.empty(); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/BucketPlayerInventoryInsertableStorage.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/BucketPlayerInventoryInsertableStorage.java index b9a4b926a..e4a2fab44 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/BucketPlayerInventoryInsertableStorage.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/BucketPlayerInventoryInsertableStorage.java @@ -5,9 +5,9 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java index cfb7db619..5db389b00 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/DiskInventory.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageProvider; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.StorageState; -import com.refinedmods.refinedstorage2.api.storage.TypedStorage; import com.refinedmods.refinedstorage2.platform.api.storage.StorageContainerItem; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; @@ -54,7 +53,7 @@ public void setItem(final int slot, final ItemStack stack) { } @Override - public Optional> resolve(final int index) { + public Optional resolve(final int index) { if (storageRepository == null) { return Optional.empty(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageType.java index b79a5b042..ddfff6b69 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageType.java @@ -12,8 +12,9 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import javax.annotation.Nullable; @@ -44,7 +45,7 @@ public Storage fromTag(final CompoundTag tag, final Runnable listener) { ); final ListTag stacks = tag.getList(TAG_STACKS, Tag.TAG_COMPOUND); for (final Tag stackTag : stacks) { - FluidResource.fromTag((CompoundTag) stackTag).ifPresent(resource -> storage.load( + ResourceTypes.FLUID.fromTag((CompoundTag) stackTag).ifPresent(resource -> storage.load( resource, ((CompoundTag) stackTag).getLong(TAG_AMOUNT), ((CompoundTag) stackTag).getString(TAG_CHANGED_BY), @@ -98,7 +99,7 @@ private CompoundTag toTag(final Storage storage, final ResourceAmount resourceAm if (!(resourceAmount.getResource() instanceof FluidResource fluidResource)) { throw new UnsupportedOperationException(); } - final CompoundTag tag = FluidResource.toTag(fluidResource); + final CompoundTag tag = fluidResource.toTag(); tag.putLong(TAG_AMOUNT, resourceAmount.getAmount()); if (storage instanceof TrackedStorage trackedStorage) { trackedStorage diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageType.java index 3daf4fc5f..8f9d78c15 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageType.java @@ -12,7 +12,8 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import javax.annotation.Nullable; @@ -43,7 +44,7 @@ public Storage fromTag(final CompoundTag tag, final Runnable listener) { ); final ListTag stacks = tag.getList(TAG_STACKS, Tag.TAG_COMPOUND); for (final Tag stackTag : stacks) { - ItemResource.fromTag((CompoundTag) stackTag).ifPresent(resource -> storage.load( + ResourceTypes.ITEM.fromTag((CompoundTag) stackTag).ifPresent(resource -> storage.load( resource, ((CompoundTag) stackTag).getLong(TAG_AMOUNT), ((CompoundTag) stackTag).getString(TAG_CHANGED_BY), @@ -97,7 +98,7 @@ private CompoundTag toTag(final Storage storage, final ResourceAmount resourceAm if (!(resourceAmount.getResource() instanceof ItemResource itemResource)) { throw new UnsupportedOperationException(); } - final CompoundTag tag = ItemResource.toTag(itemResource); + final CompoundTag tag = itemResource.toTag(); tag.putLong(TAG_AMOUNT, resourceAmount.getAmount()); if (storage instanceof TrackedStorage trackedStorage) { trackedStorage diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/StorageChannelTypes.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/StorageChannelTypes.java deleted file mode 100644 index 16e2ca6c4..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/StorageChannelTypes.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.storage.channel; - -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; - -public final class StorageChannelTypes { - public static final PlatformStorageChannelType ITEM = new ItemStorageChannelType(); - public static final PlatformStorageChannelType FLUID = new FluidStorageChannelType(); - - private StorageChannelTypes() { - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java index 6ed95037b..964534919 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/diskdrive/AbstractDiskDriveBlockEntity.java @@ -58,14 +58,13 @@ protected AbstractDiskDriveBlockEntity(final BlockPos pos, final BlockState stat super(BlockEntities.INSTANCE.getDiskDrive(), pos, state, new MultiStorageNetworkNode( Platform.INSTANCE.getConfig().getDiskDrive().getEnergyUsage(), Platform.INSTANCE.getConfig().getDiskDrive().getEnergyUsagePerDisk(), - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getAll(), AMOUNT_OF_DISKS )); this.diskInventory = new DiskInventory((inventory, slot) -> onDiskChanged(slot), getNode().getSize()); - this.filter = FilterWithFuzzyMode.createAndListenForUniqueTemplates( + this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( ResourceContainerImpl.createForFilter(), this::setChanged, - templates -> getNode().setFilterTemplates(templates) + filters -> getNode().setFilters(filters) ); this.configContainer = new StorageConfigurationContainerImpl( getNode(), diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlockEntity.java index 4c0c3cee6..52af23de1 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageBlockEntity.java @@ -37,29 +37,23 @@ public class ExternalStorageBlockEntity private final FilterWithFuzzyMode filter; private final StorageConfigurationContainerImpl configContainer; - private final ExternalStorageTrackedStorageRepositoryProvider trackedStorageRepositoryProvider; + private final ExternalStorageTrackedStorageRepository trackedStorageRepository = + new ExternalStorageTrackedStorageRepository(this::setChanged); private final ExternalStorageWorkRate workRate = new ExternalStorageWorkRate(); private boolean initialized; public ExternalStorageBlockEntity(final BlockPos pos, final BlockState state) { super(BlockEntities.INSTANCE.getExternalStorage(), pos, state, new ExternalStorageNetworkNode( - Platform.INSTANCE.getConfig().getExternalStorage().getEnergyUsage() + Platform.INSTANCE.getConfig().getExternalStorage().getEnergyUsage(), + System::currentTimeMillis )); - this.filter = FilterWithFuzzyMode.createAndListenForUniqueTemplates( + this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( ResourceContainerImpl.createForFilter(), this::setChanged, - templates -> getNode().setFilterTemplates(templates) - ); - this.trackedStorageRepositoryProvider = new ExternalStorageTrackedStorageRepositoryProvider( - PlatformApi.INSTANCE.getStorageChannelTypeRegistry(), - this::setChanged + filters -> getNode().setFilters(filters) ); getNode().setNormalizer(filter.createNormalizer()); - getNode().initialize( - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getAll(), - System::currentTimeMillis, - trackedStorageRepositoryProvider - ); + getNode().setTrackingRepository(trackedStorageRepository); this.configContainer = new StorageConfigurationContainerImpl( getNode(), filter, @@ -94,14 +88,13 @@ void loadStorage(final ServerLevel serverLevel) { if (direction == null) { return; } - getNode().initialize(channelType -> { + getNode().initialize(() -> { final Direction incomingDirection = direction.getOpposite(); final BlockPos sourcePosition = worldPosition.relative(direction); return PlatformApi.INSTANCE .getExternalStorageProviderFactories() .stream() - .flatMap(factory -> factory.create(serverLevel, sourcePosition, incomingDirection, channelType) - .stream()) + .flatMap(factory -> factory.create(serverLevel, sourcePosition, incomingDirection).stream()) .findFirst(); }); } @@ -123,7 +116,7 @@ public void doWork() { @Override public void saveAdditional(final CompoundTag tag) { super.saveAdditional(tag); - tag.put(TAG_TRACKED_RESOURCES, trackedStorageRepositoryProvider.toTag()); + tag.put(TAG_TRACKED_RESOURCES, trackedStorageRepository.toTag()); } @Override @@ -136,7 +129,7 @@ public void writeConfiguration(final CompoundTag tag) { @Override public void load(final CompoundTag tag) { super.load(tag); - trackedStorageRepositoryProvider.fromTag(tag.getList(TAG_TRACKED_RESOURCES, Tag.TAG_COMPOUND)); + trackedStorageRepository.fromTag(tag.getList(TAG_TRACKED_RESOURCES, Tag.TAG_COMPOUND)); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageTrackedStorageRepository.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageTrackedStorageRepository.java index 12399dc5d..9661cc923 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageTrackedStorageRepository.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageTrackedStorageRepository.java @@ -4,22 +4,27 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.tracked.InMemoryTrackedStorageRepository; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import java.util.Collections; import java.util.Map; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.resources.ResourceLocation; class ExternalStorageTrackedStorageRepository extends InMemoryTrackedStorageRepository { - private final PlatformStorageChannelType type; + private static final String TAG_MODIFIED_BY = "mb"; + private static final String TAG_MODIFIED_AT = "ma"; + private static final String TAG_RESOURCE_TYPE = "rt"; + private final Runnable listener; - ExternalStorageTrackedStorageRepository(final Runnable listener, final PlatformStorageChannelType type) { + ExternalStorageTrackedStorageRepository(final Runnable listener) { this.listener = listener; - this.type = type; } @Override @@ -31,22 +36,40 @@ public void update(final ResourceKey resource, final Actor actor, final long tim ListTag toTag() { final ListTag items = new ListTag(); getPersistentTrackedResources().forEach((resource, trackedResource) -> { - final CompoundTag tag = type.toTag(resource, trackedResource); - items.add(tag); + if (!(resource instanceof PlatformResourceKey platformResource)) { + return; + } + final ResourceType resourceType = platformResource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent(id -> { + final CompoundTag tag = platformResource.toTag(); + tag.putString(TAG_MODIFIED_BY, trackedResource.getSourceName()); + tag.putLong(TAG_MODIFIED_AT, trackedResource.getTime()); + tag.putString(TAG_RESOURCE_TYPE, id.toString()); + items.add(tag); + }); }); return items; } void fromTag(final ListTag items) { - items.forEach(tag -> type.fromTag( - (CompoundTag) tag, - // call super here to avoid marking dirty. - (resource, trackedResource) -> super.update( - resource, - new PlayerActor(trackedResource.getSourceName()), - trackedResource.getTime() - ) - )); + items.forEach(tag -> { + final ResourceLocation resourceTypeId = new ResourceLocation( + ((CompoundTag) tag).getString(TAG_RESOURCE_TYPE) + ); + fromTag((CompoundTag) tag, resourceTypeId); + }); + } + + private void fromTag(final CompoundTag tag, final ResourceLocation resourceTypeId) { + PlatformApi.INSTANCE.getResourceTypeRegistry() + .get(resourceTypeId) + .flatMap(resourceType -> resourceType.fromTag(tag)) + .ifPresent(resource -> { + final String modifiedBy = tag.getString(TAG_MODIFIED_BY); + final long modifiedAt = tag.getLong(TAG_MODIFIED_AT); + // Call super here to avoid marking dirty. + super.update(resource, new PlayerActor(modifiedBy), modifiedAt); + }); } private Map getPersistentTrackedResources() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageTrackedStorageRepositoryProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageTrackedStorageRepositoryProvider.java deleted file mode 100644 index 1c7da4002..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/externalstorage/ExternalStorageTrackedStorageRepositoryProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.storage.externalstorage; - -import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.TrackedStorageRepositoryProvider; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageRepository; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry; - -import java.util.HashMap; -import java.util.Map; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; - -class ExternalStorageTrackedStorageRepositoryProvider implements TrackedStorageRepositoryProvider { - private static final String TAG_TYPE = "type"; - private static final String TAG_ITEMS = "items"; - - private final PlatformRegistry storageChannelTypeRegistry; - private final Map repositoryMap - = new HashMap<>(); - - ExternalStorageTrackedStorageRepositoryProvider( - final PlatformRegistry storageChannelTypeRegistry, - final Runnable listener - ) { - this.storageChannelTypeRegistry = storageChannelTypeRegistry; - storageChannelTypeRegistry.getAll().forEach(type -> repositoryMap.put( - type, - new ExternalStorageTrackedStorageRepository(listener, type) - )); - } - - ListTag toTag() { - final ListTag items = new ListTag(); - repositoryMap.forEach((type, repo) -> storageChannelTypeRegistry.getId(type) - .ifPresent(id -> items.add(toTag(repo, id)))); - return items; - } - - private CompoundTag toTag(final ExternalStorageTrackedStorageRepository repo, final ResourceLocation id) { - final CompoundTag tag = new CompoundTag(); - tag.putString(TAG_TYPE, id.toString()); - tag.put(TAG_ITEMS, repo.toTag()); - return tag; - } - - void fromTag(final ListTag tag) { - tag.forEach(item -> { - final String id = ((CompoundTag) item).getString(TAG_TYPE); - storageChannelTypeRegistry.get(new ResourceLocation(id)).ifPresent( - type -> repositoryMap.get(type).fromTag(((CompoundTag) item).getList(TAG_ITEMS, Tag.TAG_COMPOUND)) - ); - }); - } - - @Override - public TrackedStorageRepository getRepository(final StorageChannelType type) { - return repositoryMap.get(type); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGrid.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGrid.java index b180706ad..9b0fbd3d0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGrid.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGrid.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; import com.refinedmods.refinedstorage2.api.grid.operations.NoopGridOperations; -import com.refinedmods.refinedstorage2.api.grid.watcher.GridStorageChannelProvider; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManager; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManagerImpl; @@ -15,19 +14,16 @@ import com.refinedmods.refinedstorage2.api.storage.StorageState; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.storage.DiskInventory; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import java.util.Collections; import java.util.List; -import java.util.Set; import javax.annotation.Nullable; -class PortableGrid implements Grid, GridStorageChannelProvider { +class PortableGrid implements Grid { private final EnergyStorage energyStorage; private final DiskInventory diskInventory; private final GridWatcherManager watchers = new GridWatcherManagerImpl(); @@ -44,12 +40,16 @@ class PortableGrid implements Grid, GridStorageChannelProvider { } void updateStorage() { - watchers.detachAll(this); + if (storage != null) { + watchers.detachAll(storage.getStorageChannel()); + } + this.storage = diskInventory.resolve(0) - .map(diskStorage -> StateTrackedStorage.of(diskStorage, diskListener)) + .map(diskStorage -> new StateTrackedStorage(diskStorage, diskListener)) .map(PortableGridStorage::new) .orElse(null); - watchers.attachAll(this); + + watchers.attachAll(getStorageChannel()); } void activeChanged(final boolean active) { @@ -69,17 +69,22 @@ StorageState getStorageState() { @Override public void addWatcher(final GridWatcher watcher, final Class actorType) { energyStorage.extract(Platform.INSTANCE.getConfig().getPortableGrid().getOpenEnergyUsage(), Action.EXECUTE); - watchers.addWatcher(watcher, actorType, this); + watchers.addWatcher(watcher, actorType, getStorageChannel()); } @Override public void removeWatcher(final GridWatcher watcher) { - watchers.removeWatcher(watcher, this); + watchers.removeWatcher(watcher, getStorageChannel()); + } + + @Nullable + private StorageChannel getStorageChannel() { + return storage != null ? storage.getStorageChannel() : null; } @Override public Storage getItemStorage() { - if (storage == null || storage.getStorageChannelType() != StorageChannelTypes.ITEM) { + if (storage == null) { return new NoopStorage(); } return storage.getStorageChannel(); @@ -91,9 +96,8 @@ public boolean isGridActive() { } @Override - public List getResources(final StorageChannelType type, - final Class actorType) { - if (storage == null || storage.getStorageChannelType() != type) { + public List getResources(final Class actorType) { + if (storage == null) { return Collections.emptyList(); } final StorageChannel storageChannel = storage.getStorageChannel(); @@ -104,26 +108,13 @@ public List getResources(final StorageChannelType type, } @Override - public GridOperations createOperations(final PlatformStorageChannelType storageChannelType, + public GridOperations createOperations(final ResourceType resourceType, final Actor actor) { - if (storage == null || storage.getStorageChannelType() != storageChannelType) { + if (storage == null) { return new NoopGridOperations(); } final StorageChannel storageChannel = this.storage.getStorageChannel(); - final GridOperations operations = storageChannelType.createGridOperations(storageChannel, actor); + final GridOperations operations = resourceType.createGridOperations(storageChannel, actor); return new PortableGridOperations(operations, energyStorage); } - - @Override - public Set getStorageChannelTypes() { - return storage == null ? Collections.emptySet() : Set.of(storage.getStorageChannelType()); - } - - @Override - public StorageChannel getStorageChannel(final StorageChannelType type) { - if (storage == null || type != storage.getStorageChannelType()) { - throw new IllegalArgumentException(); - } - return storage.getStorageChannel(); - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridStorage.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridStorage.java index 5f9299b0d..aef54033c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridStorage.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridStorage.java @@ -2,27 +2,21 @@ import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage; import com.refinedmods.refinedstorage2.api.storage.StorageState; -import com.refinedmods.refinedstorage2.api.storage.TypedStorage; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; class PortableGridStorage { private final StorageChannel storageChannel; - private final TypedStorage diskStorage; + private final StateTrackedStorage diskStorage; - PortableGridStorage(final TypedStorage diskStorage) { + PortableGridStorage(final StateTrackedStorage diskStorage) { this.storageChannel = new StorageChannelImpl(); this.diskStorage = diskStorage; - this.storageChannel.addSource(diskStorage.storage()); - } - - StorageChannelType getStorageChannelType() { - return diskStorage.storageChannelType(); + this.storageChannel.addSource(diskStorage); } StorageState getState() { - return diskStorage.storage().getState(); + return diskStorage.getState(); } StorageChannel getStorageChannel() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockBlockEntity.java index 13503a5a1..2415a1c8d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/AbstractStorageBlockBlockEntity.java @@ -46,10 +46,10 @@ protected AbstractStorageBlockBlockEntity(final BlockEntityType type, final StorageNetworkNode node, final ResourceFactory resourceFactory) { super(type, pos, state, node); - this.filter = FilterWithFuzzyMode.createAndListenForUniqueTemplates( + this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( ResourceContainerImpl.createForFilter(resourceFactory), this::setChanged, - templates -> getNode().setFilterTemplates(templates) + filters -> getNode().setFilters(filters) ); this.configContainer = new StorageConfigurationContainerImpl( getNode(), diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/FluidStorageBlockBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/FluidStorageBlockBlockEntity.java index 39ca41f72..412d4d87a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/FluidStorageBlockBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/FluidStorageBlockBlockEntity.java @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -29,7 +28,7 @@ public FluidStorageBlockBlockEntity(final BlockPos pos, BlockEntities.INSTANCE.getFluidStorageBlock(variant), pos, state, - new StorageNetworkNode(getEnergyUsage(variant), StorageChannelTypes.FLUID), + new StorageNetworkNode(getEnergyUsage(variant)), PlatformApi.INSTANCE.getFluidResourceFactory() ); this.variant = variant; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/ItemStorageBlockBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/ItemStorageBlockBlockEntity.java index 11efd36ec..397d572ba 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/ItemStorageBlockBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storageblock/ItemStorageBlockBlockEntity.java @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -29,7 +28,7 @@ public ItemStorageBlockBlockEntity(final BlockPos pos, BlockEntities.INSTANCE.getItemStorageBlock(variant), pos, state, - new StorageNetworkNode(getEnergyUsage(variant), StorageChannelTypes.ITEM), + new StorageNetworkNode(getEnergyUsage(variant)), PlatformApi.INSTANCE.getItemResourceFactory() ); this.variant = variant; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/FluidStorageDiskItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/FluidStorageDiskItem.java index 6d694d57e..ebc6260a9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/FluidStorageDiskItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/FluidStorageDiskItem.java @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResourceRendering; import javax.annotation.Nullable; @@ -21,7 +20,6 @@ public class FluidStorageDiskItem extends AbstractStorageContainerItem { public FluidStorageDiskItem(final FluidStorageType.Variant variant) { super( new Item.Properties().stacksTo(1).fireResistant(), - StorageChannelTypes.FLUID, PlatformApi.INSTANCE.getStorageContainerItemHelper() ); this.variant = variant; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/ItemStorageDiskItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/ItemStorageDiskItem.java index 16a8af9e3..d2aec853b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/ItemStorageDiskItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/storagedisk/ItemStorageDiskItem.java @@ -8,7 +8,6 @@ import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import javax.annotation.Nullable; @@ -21,7 +20,6 @@ public class ItemStorageDiskItem extends AbstractStorageContainerItem { public ItemStorageDiskItem(final ItemStorageType.Variant variant) { super( new Item.Properties().stacksTo(1).fireResistant(), - StorageChannelTypes.ITEM, PlatformApi.INSTANCE.getStorageContainerItemHelper() ); this.variant = variant; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java index 550165278..87329091f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java @@ -7,10 +7,9 @@ import com.refinedmods.refinedstorage2.api.storage.TransferHelper; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.storage.BucketPlayerInventoryInsertableStorage; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import net.minecraft.world.entity.player.Player; @@ -26,11 +25,10 @@ public boolean extract(final ResourceKey resource, } final BucketPlayerInventoryInsertableStorage target = new BucketPlayerInventoryInsertableStorage( player.getInventory(), - network.getComponent(StorageNetworkComponent.class).getStorageChannel(StorageChannelTypes.ITEM), + network.getComponent(StorageNetworkComponent.class), true ); - final StorageChannel source = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.FLUID); + final StorageChannel source = network.getComponent(StorageNetworkComponent.class); return TransferHelper.transfer( fluidResource, Platform.INSTANCE.getBucketAmount(), diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java index d4e7713d7..1c428973b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java @@ -7,9 +7,8 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.Optional; import javax.annotation.Nullable; @@ -27,8 +26,7 @@ public Optional insert( if (!(configuredResource instanceof FluidResource configuredFluidResource)) { return Optional.empty(); } - final StorageChannel fluidStorageChannel = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.FLUID); + final StorageChannel fluidStorageChannel = network.getComponent(StorageNetworkComponent.class); return Platform.INSTANCE.getContainedFluid(stack) .map(extracted -> tryInsert(actor, configuredFluidResource, extracted, fluidStorageChannel)) .map(extracted -> doInsert(actor, extracted, fluidStorageChannel)); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java index 7fbeb3e6b..3c3a48991 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java @@ -6,8 +6,7 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -22,9 +21,12 @@ public boolean extract(final ResourceKey resource, if (!(resource instanceof ItemResource itemResource)) { return false; } - final long extracted = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM) - .extract(itemResource, fullStack ? itemResource.item().getMaxStackSize() : 1, Action.EXECUTE, actor); + final long extracted = network.getComponent(StorageNetworkComponent.class).extract( + itemResource, + fullStack ? itemResource.item().getMaxStackSize() : 1, + Action.EXECUTE, + actor + ); if (extracted > 0) { final ItemStack stack = itemResource.toItemStack(extracted); if (!player.getInventory().add(stack)) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java index 37b7f353e..2eb65b710 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java @@ -6,8 +6,7 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.Optional; @@ -26,9 +25,12 @@ public Optional insert(final ResourceKey configuredResource, if (!configuredItemResource.equals(resource)) { return Optional.empty(); } - final long inserted = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM) - .insert(resource, stack.getCount(), Action.EXECUTE, actor); + final long inserted = network.getComponent(StorageNetworkComponent.class).insert( + resource, + stack.getCount(), + Action.EXECUTE, + actor + ); final long remainder = stack.getCount() - inserted; if (remainder > 0) { return Optional.of(resource.toItemStack(remainder)); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java index e74f4dcfc..9e76ff199 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java @@ -9,8 +9,6 @@ import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannel; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -19,6 +17,7 @@ import com.refinedmods.refinedstorage2.platform.common.support.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ExtendedMenuProvider; import com.refinedmods.refinedstorage2.platform.common.support.network.AbstractRedstoneModeNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceContainerImpl; import javax.annotation.Nullable; @@ -87,24 +86,23 @@ private void trySendDisplayUpdate(final Level level) { } private long getAmount() { - final ResourceAmountTemplate template = filter.getFilterContainer().get(0); - if (template == null) { + final ResourceKey configuredResource = getConfiguredResource(); + if (configuredResource == null) { return 0; } final Network network = getNode().getNetwork(); if (network == null) { return 0; } - return getAmount(network, template); + return getAmount(network, configuredResource); } - private long getAmount(final Network network, final ResourceAmountTemplate template) { - final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class) - .getStorageChannel(template.getStorageChannelType()); + private long getAmount(final Network network, final ResourceKey configuredResource) { + final StorageChannel storageChannel = network.getComponent(StorageNetworkComponent.class); if (!filter.isFuzzyMode() || !(storageChannel instanceof FuzzyStorageChannel fuzzyStorageChannel)) { - return storageChannel.get(template.getResource()).map(ResourceAmount::getAmount).orElse(0L); + return storageChannel.get(configuredResource).map(ResourceAmount::getAmount).orElse(0L); } - return fuzzyStorageChannel.getFuzzy(template.getResource()).stream().mapToLong(ResourceAmount::getAmount).sum(); + return fuzzyStorageChannel.getFuzzy(configuredResource).stream().mapToLong(ResourceAmount::getAmount).sum(); } public void extract(final Player player) { @@ -115,21 +113,21 @@ public void extract(final Player player) { if (network == null) { return; } - final ResourceAmountTemplate template = getFilteredResource(); - if (template == null) { + final ResourceKey configuredResource = getConfiguredResource(); + if (configuredResource == null) { return; } - extract(level, player, template.getResource(), network); + doExtract(level, player, configuredResource, network); } - private void extract( + private void doExtract( final Level level, final Player player, - final ResourceKey template, + final ResourceKey configuredResource, final Network network ) { final boolean success = PlatformApi.INSTANCE.getStorageMonitorExtractionStrategy().extract( - template, + configuredResource, !player.isShiftKeyDown(), player, new PlayerActor(player), @@ -160,26 +158,26 @@ private boolean doInsert(final Player player, final InteractionHand hand) { if (network == null) { return false; } - final ResourceAmountTemplate template = getFilteredResource(); - if (template == null) { + final ResourceKey configuredResource = getConfiguredResource(); + if (configuredResource == null) { return false; } final ItemStack heldStack = player.getItemInHand(hand); if (heldStack.isEmpty()) { return doInsertAll(player); } - return doInsert(player, hand, heldStack, template.getResource(), network); + return doInsert(player, hand, heldStack, configuredResource, network); } private boolean doInsert( final Player player, final InteractionHand hand, final ItemStack heldStack, - final ResourceKey template, + final ResourceKey configuredResource, final Network network ) { return PlatformApi.INSTANCE.getStorageMonitorInsertionStrategy().insert( - template, + configuredResource, heldStack, new PlayerActor(player), network @@ -201,13 +199,13 @@ private boolean doInsertAll(final Player player, final ItemResource lastInserted if (network == null) { return false; } - final ResourceAmountTemplate template = getFilteredResource(); - if (template == null) { + final ResourceKey configuredResource = getConfiguredResource(); + if (configuredResource == null) { return false; } boolean success = false; for (int i = 0; i < player.getInventory().getContainerSize(); ++i) { - success |= tryInsertSlot(player, lastInsertedItem, i, template.getResource(), network); + success |= tryInsertSlot(player, lastInsertedItem, i, configuredResource, network); } return success; } @@ -216,7 +214,7 @@ private boolean tryInsertSlot( final Player player, final ItemResource lastInsertedItem, final int inventorySlotIndex, - final ResourceKey template, + final ResourceKey configuredResource, final Network network ) { final ItemStack slot = player.getInventory().getItem(inventorySlotIndex); @@ -228,7 +226,7 @@ private boolean tryInsertSlot( return false; } return PlatformApi.INSTANCE.getStorageMonitorInsertionStrategy().insert( - template, + configuredResource, slot, new PlayerActor(player), network @@ -247,8 +245,8 @@ public void setFuzzyMode(final boolean fuzzyMode) { } @Nullable - public ResourceAmountTemplate getFilteredResource() { - return filter.getFilterContainer().get(0); + public ResourceKey getConfiguredResource() { + return filter.getFilterContainer().getResource(0); } public long getCurrentAmount() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntityRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntityRenderer.java index a8d5358db..0a24f4ef0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntityRenderer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntityRenderer.java @@ -2,7 +2,6 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirectionType; @@ -42,8 +41,8 @@ public void render(final StorageMonitorBlockEntity blockEntity, if (!blockEntity.isCurrentlyActive()) { return; } - final ResourceAmountTemplate template = blockEntity.getFilteredResource(); - if (template == null) { + final ResourceKey resource = blockEntity.getConfiguredResource(); + if (resource == null) { return; } doRender( @@ -51,7 +50,7 @@ public void render(final StorageMonitorBlockEntity blockEntity, poseStack, vertexConsumers, direction, - template, + resource, blockEntity.getCurrentAmount() ); } @@ -60,11 +59,9 @@ private void doRender(final Level level, final PoseStack poseStack, final MultiBufferSource vertexConsumers, final BiDirection direction, - final ResourceAmountTemplate template, + final ResourceKey resource, final long amount) { - final ResourceRendering resourceRendering = PlatformApi.INSTANCE.getResourceRendering( - template.getResource() - ); + final ResourceRendering resourceRendering = PlatformApi.INSTANCE.getResourceRendering(resource); doRender( poseStack, vertexConsumers, @@ -72,7 +69,7 @@ private void doRender(final Level level, resourceRendering.getDisplayedAmount(amount, false), level, resourceRendering, - template.getResource() + resource ); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorInsertTracker.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorInsertTracker.java index 61deefca7..7fa430dfe 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorInsertTracker.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorInsertTracker.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.storagemonitor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.HashMap; import java.util.Map; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java index 5a31c025f..cfc317897 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractBaseScreen.java @@ -1,9 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.support; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeMapping; @@ -103,15 +102,16 @@ protected final void renderResourceSlots(final GuiGraphics graphics) { } private void tryRenderResourceSlot(final GuiGraphics graphics, final ResourceSlot slot) { - final ResourceAmountTemplate resourceAmount = slot.getResourceAmount(); - if (resourceAmount == null) { + final ResourceKey resource = slot.getResource(); + if (resource == null) { return; } renderResourceSlot( graphics, leftPos + slot.x, topPos + slot.y, - resourceAmount, + resource, + slot.getAmount(), slot.shouldRenderAmount() ); } @@ -119,12 +119,13 @@ private void tryRenderResourceSlot(final GuiGraphics graphics, final ResourceSlo private void renderResourceSlot(final GuiGraphics graphics, final int x, final int y, - final ResourceAmountTemplate resourceAmount, + final ResourceKey resource, + final long amount, final boolean renderAmount) { - final ResourceRendering rendering = PlatformApi.INSTANCE.getResourceRendering(resourceAmount.getResource()); - rendering.render(resourceAmount.getResource(), graphics, x, y); + final ResourceRendering rendering = PlatformApi.INSTANCE.getResourceRendering(resource); + rendering.render(resource, graphics, x, y); if (renderAmount) { - renderResourceSlotAmount(graphics, x, y, resourceAmount.getAmount(), rendering); + renderResourceSlotAmount(graphics, x, y, amount, rendering); } } @@ -206,11 +207,11 @@ private List getUpgradeTooltip(final ItemStack carried, } public List getResourceTooltip(final ItemStack carried, final ResourceSlot resourceSlot) { - final ResourceAmountTemplate resourceAmount = resourceSlot.getResourceAmount(); - if (resourceAmount == null) { + final ResourceKey resource = resourceSlot.getResource(); + if (resource == null) { return getTooltipForEmptySlot(carried, resourceSlot); } - return getTooltipForResource(resourceAmount, resourceSlot); + return getTooltipForResource(resource, resourceSlot); } private List getTooltipForEmptySlot(final ItemStack carried, @@ -253,11 +254,11 @@ public static MouseWithIconClientTooltipComponent.IconRenderer getResourceRender return (graphics, x, y) -> PlatformApi.INSTANCE.getResourceRendering(resource).render(resource, graphics, x, y); } - private List getTooltipForResource(final ResourceAmountTemplate resourceAmount, + private List getTooltipForResource(final ResourceKey resource, final ResourceSlot resourceSlot) { final List tooltip = PlatformApi.INSTANCE - .getResourceRendering(resourceAmount.getResource()) - .getTooltip(resourceAmount.getResource()) + .getResourceRendering(resource) + .getTooltip(resource) .stream() .map(Component::getVisualOrderText) .map(ClientTooltipComponent::create) @@ -283,7 +284,7 @@ && getMenu() instanceof AbstractResourceContainerMenu containerMenu) { } private boolean tryOpenResourceAmountScreen(final ResourceSlot slot) { - final boolean isFilterSlot = slot.getResourceAmount() != null; + final boolean isFilterSlot = slot.getResource() != null; final boolean canModifyAmount = isFilterSlot && slot.canModifyAmount(); final boolean isNotTryingToRemoveFilter = !hasShiftDown(); final boolean isNotCarryingItem = getMenu().getCarried().isEmpty(); @@ -296,10 +297,11 @@ private boolean tryOpenResourceAmountScreen(final ResourceSlot slot) { } @Nullable - public ResourceTemplate getHoveredResource() { - return hoveredSlot instanceof ResourceSlot resourceSlot && resourceSlot.getResourceAmount() != null - ? resourceSlot.getResourceAmount().getResourceTemplate() - : null; + public PlatformResourceKey getHoveredResource() { + if (hoveredSlot instanceof ResourceSlot resourceSlot) { + return resourceSlot.getResource(); + } + return null; } public int getLeftPos() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java index 03ed04203..5aeca9c19 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java @@ -2,26 +2,19 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyType; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.UUID; public interface ClientToServerCommunications { - void sendGridExtract(PlatformStorageChannelType storageChannelType, - ResourceKey resource, - GridExtractMode mode, - boolean cursor); + void sendGridExtract(PlatformResourceKey resource, GridExtractMode mode, boolean cursor); - void sendGridScroll(PlatformStorageChannelType storageChannelType, - ResourceKey resource, - GridScrollMode mode, - int slotIndex); + void sendGridScroll(PlatformResourceKey resource, GridScrollMode mode, int slotIndex); void sendGridInsert(GridInsertMode mode, boolean tryAlternatives); @@ -35,11 +28,7 @@ void sendGridScroll(PlatformStorageChannelType storageChannelType, void sendResourceSlotChange(int slotIndex, boolean tryAlternatives); - void sendResourceFilterSlotChange( - PlatformStorageChannelType storageChannelType, - ResourceKey resource, - int slotIndex - ); + void sendResourceFilterSlotChange(PlatformResourceKey resource, int slotIndex); void sendResourceSlotAmountChange(int slotIndex, long amount); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/FilterWithFuzzyMode.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/FilterWithFuzzyMode.java index 0371f9fb1..8008773f9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/FilterWithFuzzyMode.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/FilterWithFuzzyMode.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.FuzzyModeNormalizer; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; @@ -21,20 +20,20 @@ public final class FilterWithFuzzyMode { @Nullable private final Runnable listener; @Nullable - private final Consumer> uniqueTemplateListener; + private final Consumer> uniqueFilterListener; @Nullable - private final Consumer> templateListener; + private final Consumer> filterListener; private boolean fuzzyMode; private FilterWithFuzzyMode(final ResourceContainer filterContainer, @Nullable final Runnable listener, - @Nullable final Consumer> uniqueTemplateListener, - @Nullable final Consumer> templateListener) { + @Nullable final Consumer> uniqueFilterListener, + @Nullable final Consumer> filterListener) { this.filterContainer = filterContainer; this.listener = listener; - this.uniqueTemplateListener = uniqueTemplateListener; - this.templateListener = templateListener; + this.uniqueFilterListener = uniqueFilterListener; + this.filterListener = filterListener; this.filterContainer.setListener(this::filterContainerChanged); } @@ -55,7 +54,7 @@ public boolean isFuzzyMode() { public void setFuzzyMode(final boolean fuzzyMode) { this.fuzzyMode = fuzzyMode; - // We need to reload the templates as the normalizer will give different outputs now. + // We need to reload the filters as the normalizer will give different outputs now. notifyListeners(); if (listener != null) { listener.run(); @@ -73,11 +72,11 @@ public void load(final CompoundTag tag) { } private void notifyListeners() { - if (uniqueTemplateListener != null) { - uniqueTemplateListener.accept(filterContainer.getUniqueTemplates()); + if (uniqueFilterListener != null) { + uniqueFilterListener.accept(filterContainer.getUniqueResources()); } - if (templateListener != null) { - templateListener.accept(filterContainer.getTemplates()); + if (filterListener != null) { + filterListener.accept(filterContainer.getResources()); } } @@ -103,19 +102,19 @@ public static FilterWithFuzzyMode create(final ResourceContainer resourceContain return new FilterWithFuzzyMode(resourceContainer, listener, null, null); } - public static FilterWithFuzzyMode createAndListenForTemplates( + public static FilterWithFuzzyMode createAndListenForFilters( final ResourceContainer resourceContainer, final Runnable listener, - final Consumer> templateListener + final Consumer> filterListener ) { - return new FilterWithFuzzyMode(resourceContainer, listener, null, templateListener); + return new FilterWithFuzzyMode(resourceContainer, listener, null, filterListener); } - public static FilterWithFuzzyMode createAndListenForUniqueTemplates( + public static FilterWithFuzzyMode createAndListenForUniqueFilters( final ResourceContainer resourceContainer, final Runnable listener, - final Consumer> templateListener + final Consumer> filterListener ) { - return new FilterWithFuzzyMode(resourceContainer, listener, templateListener, null); + return new FilterWithFuzzyMode(resourceContainer, listener, filterListener, null); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ServerToClientCommunications.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ServerToClientCommunications.java index c28c17ce2..ac865be62 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ServerToClientCommunications.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ServerToClientCommunications.java @@ -1,10 +1,9 @@ package com.refinedmods.refinedstorage2.platform.common.support; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.storage.StorageInfo; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterStatus; import java.util.UUID; @@ -20,15 +19,14 @@ public interface ServerToClientCommunications { void sendGridActiveness(ServerPlayer player, boolean active); void sendGridUpdate(ServerPlayer player, - PlatformStorageChannelType storageChannelType, - ResourceKey resource, + PlatformResourceKey resource, long change, @Nullable TrackedResource trackedResource); void sendGridClear(ServerPlayer player); void sendResourceSlotUpdate(ServerPlayer player, - @Nullable ResourceAmountTemplate resourceAmount, + @Nullable ResourceAmount resourceAmount, int slotIndex); void sendStorageInfoResponse(ServerPlayer player, UUID id, StorageInfo storageInfo); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractResourceContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractResourceContainerMenu.java index fbb026ec7..a979f3513 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractResourceContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractResourceContainerMenu.java @@ -1,8 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.support.containermenu; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; @@ -48,16 +47,12 @@ private Optional getResourceSlot(final int slotIndex) { return Optional.empty(); } - public void handleResourceSlotUpdate(final int slotIndex, - @Nullable final ResourceAmountTemplate resourceAmount) { + public void handleResourceSlotUpdate(final int slotIndex, @Nullable final ResourceAmount resourceAmount) { getResourceSlot(slotIndex).ifPresent(slot -> slot.change(resourceAmount)); } - - public void handleResourceFilterSlotUpdate(final int slotIndex, - final PlatformStorageChannelType storageChannelType, - final ResourceKey resource) { - getResourceSlot(slotIndex).ifPresent(slot -> slot.setFilter(storageChannelType, resource)); + public void handleResourceFilterSlotUpdate(final int slotIndex, final PlatformResourceKey resource) { + getResourceSlot(slotIndex).ifPresent(slot -> slot.setFilter(resource)); } public void handleResourceSlotChange(final int slotIndex, final boolean tryAlternatives) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ResourceSlot.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ResourceSlot.java index 6bf27fa78..2bf95a802 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ResourceSlot.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ResourceSlot.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.support.containermenu; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainerType; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory; @@ -29,7 +29,7 @@ public class ResourceSlot extends Slot { private final ResourceContainer resourceContainer; private final Component helpText; @Nullable - private ResourceAmountTemplate cachedResource; + private ResourceAmount cachedResource; public ResourceSlot(final ResourceContainer resourceContainer, final int index, @@ -93,19 +93,27 @@ public boolean isDisabled() { } @Nullable - public ResourceAmountTemplate getResourceAmount() { - return resourceContainer.get(getContainerSlot()); + public PlatformResourceKey getResource() { + return resourceContainer.getResource(getContainerSlot()); + } + + public long getAmount() { + return resourceContainer.getAmount(getContainerSlot()); + } + + private ItemStack getStackRepresentation() { + return resourceContainer.getStackRepresentation(getContainerSlot()); } public boolean isEmpty() { - return getResourceAmount() == null; + return resourceContainer.isEmpty(getContainerSlot()); } public void change(final ItemStack stack, final boolean tryAlternatives) { resourceContainer.change(getContainerSlot(), stack, tryAlternatives); } - public void change(@Nullable final ResourceAmountTemplate instance) { + public void change(@Nullable final ResourceAmount instance) { if (instance == null) { resourceContainer.remove(getContainerSlot()); } else { @@ -113,14 +121,13 @@ public void change(@Nullable final ResourceAmountTemplate instance) { } } - public void setFilter(final PlatformStorageChannelType storageChannelType, final ResourceKey resource) { + public void setFilter(final PlatformResourceKey resource) { if (!isFilter() || !isValid(resource)) { return; } - resourceContainer.set(getContainerSlot(), new ResourceAmountTemplate( + resourceContainer.set(getContainerSlot(), new ResourceAmount( resource, - storageChannelType.normalizeAmount(1D), - storageChannelType + resource.getResourceType().normalizeAmount(1D) )); } @@ -144,30 +151,28 @@ public void changeAmount(final long amount) { } public void changeAmountOnClient(final double amount) { - final ResourceAmountTemplate resourceAmount = getResourceAmount(); - if (resourceAmount == null) { + final PlatformResourceKey resource = getResource(); + if (resource == null) { return; } - final long normalizedAmount = resourceAmount.getStorageChannelType().normalizeAmount(amount); + final long normalizedAmount = resource.getResourceType().normalizeAmount(amount); Platform.INSTANCE.getClientToServerCommunications().sendResourceSlotAmountChange(index, normalizedAmount); } public boolean contains(final ItemStack stack) { - final ResourceAmountTemplate resourceAmount = getResourceAmount(); - return resourceAmount != null && ItemStack.matches(stack, resourceAmount.getStackRepresentation()); + return ItemStack.matches(stack, getStackRepresentation()); } public void broadcastChanges(final Player player) { - final ResourceAmountTemplate resourceAmount = getResourceAmount(); - if (!Objects.equals(resourceAmount, cachedResource)) { + final ResourceAmount currentResourceAmount = resourceContainer.get(getContainerSlot()); + if (!Objects.equals(currentResourceAmount, cachedResource)) { LOGGER.debug("Resource slot {} has changed", getContainerSlot()); - this.cachedResource = resourceAmount; - broadcastChange((ServerPlayer) player, resourceAmount); + this.cachedResource = currentResourceAmount; + broadcastChange((ServerPlayer) player, currentResourceAmount); } } - private void broadcastChange(final ServerPlayer player, - @Nullable final ResourceAmountTemplate contents) { + private void broadcastChange(final ServerPlayer player, @Nullable final ResourceAmount contents) { Platform.INSTANCE.getServerToClientCommunications().sendResourceSlotUpdate(player, contents, index); } @@ -186,19 +191,19 @@ public boolean mayPlace(final ItemStack stack) { } public double getDisplayAmount() { - final ResourceAmountTemplate resourceAmount = getResourceAmount(); - if (resourceAmount == null) { + final PlatformResourceKey resource = getResource(); + if (resource == null) { return 0; } - return resourceAmount.getStorageChannelType().getDisplayAmount(resourceAmount.getAmount()); + return resource.getResourceType().getDisplayAmount(getAmount()); } public double getMaxAmountWhenModifying() { - final ResourceAmountTemplate resourceAmount = getResourceAmount(); - if (resourceAmount == null) { + final ResourceKey resource = getResource(); + if (resource == null) { return 0; } - return resourceContainer.getMaxAmount(resourceAmount); + return resourceContainer.getMaxAmount(resource); } public Component getHelpText() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java index 4d452c803..069b38d6f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.common.support.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.support.SchedulingMode; import com.refinedmods.refinedstorage2.platform.common.support.SchedulingModeType; @@ -12,7 +11,6 @@ import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeDestinations; import java.util.List; -import java.util.stream.Collectors; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -37,12 +35,10 @@ protected AbstractSchedulingNetworkNodeContainerBlockEntity( ) { super(type, pos, state, node, destination); this.schedulingMode = new SchedulingMode<>(this::setChanged, this::setTaskExecutor); - this.filter = FilterWithFuzzyMode.createAndListenForTemplates( + this.filter = FilterWithFuzzyMode.createAndListenForFilters( ResourceContainerImpl.createForFilter(), this::setChanged, - templates -> setFilterTemplates( - templates.stream().map(ResourceTemplate::resource).collect(Collectors.toList()) - ) + this::setFilters ); } @@ -86,5 +82,5 @@ public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByte protected abstract void setTaskExecutor(TaskExecutor taskExecutor); - protected abstract void setFilterTemplates(List templates); + protected abstract void setFilters(List filters); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/PlatformStorageNetworkComponent.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/PlatformStorageNetworkComponent.java new file mode 100644 index 000000000..2dc393e0e --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/PlatformStorageNetworkComponent.java @@ -0,0 +1,29 @@ +package com.refinedmods.refinedstorage2.platform.common.support.network.component; + +import com.refinedmods.refinedstorage2.api.network.impl.component.StorageNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannel; +import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceList; +import com.refinedmods.refinedstorage2.platform.common.support.resource.list.FuzzyResourceListImpl; + +import java.util.Collection; + +public class PlatformStorageNetworkComponent extends StorageNetworkComponentImpl implements FuzzyStorageChannel { + private final FuzzyResourceList fuzzyResourceList; + + public PlatformStorageNetworkComponent() { + this(new FuzzyResourceListImpl(new ResourceListImpl())); + } + + private PlatformStorageNetworkComponent(final FuzzyResourceList fuzzyResourceList) { + super(fuzzyResourceList); + this.fuzzyResourceList = fuzzyResourceList; + } + + @Override + public Collection getFuzzy(final ResourceKey resource) { + return fuzzyResourceList.getFuzzy(resource); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/package-info.java new file mode 100644 index 000000000..4f36cc79b --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.common.support.network.component; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/FluidRenderer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/FluidRenderer.java index e5d76bc35..34773c624 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/FluidRenderer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/render/FluidRenderer.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.render; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.List; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/AbstractResourceContainerContainerAdapter.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/AbstractResourceContainerContainerAdapter.java index 998b30a50..b1cc8437f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/AbstractResourceContainerContainerAdapter.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/AbstractResourceContainerContainerAdapter.java @@ -1,9 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.support.resource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Player; @@ -24,7 +23,7 @@ public int getContainerSize() { @Override public boolean isEmpty() { for (int i = 0; i < container.size(); ++i) { - if (container.get(i) != null) { + if (!container.isEmpty(i)) { return false; } } @@ -33,18 +32,14 @@ public boolean isEmpty() { @Override public ItemStack getItem(final int slotIndex) { - final ResourceAmountTemplate resourceAmount = container.get(slotIndex); - if (resourceAmount != null) { - return resourceAmount.getStackRepresentation(); - } - return ItemStack.EMPTY; + return container.getStackRepresentation(slotIndex); } @Override public ItemStack removeItem(final int slotIndex, final int amount) { - final ResourceAmountTemplate resourceAmount = container.get(slotIndex); - if (resourceAmount != null && resourceAmount.getResource() instanceof ItemResource itemResource) { - final long maxRemove = Math.min(amount, resourceAmount.getAmount()); + final ResourceKey resource = container.getResource(slotIndex); + if (resource instanceof ItemResource itemResource) { + final long maxRemove = Math.min(amount, container.getAmount(slotIndex)); container.shrink(slotIndex, maxRemove); return itemResource.toItemStack(maxRemove); } @@ -53,10 +48,10 @@ public ItemStack removeItem(final int slotIndex, final int amount) { @Override public ItemStack removeItemNoUpdate(final int slotIndex) { - final ResourceAmountTemplate resourceAmount = container.get(slotIndex); - if (resourceAmount != null && resourceAmount.getResource() instanceof ItemResource itemResource) { + final ResourceKey resource = container.getResource(slotIndex); + if (resource instanceof ItemResource itemResource) { final ItemStack stack = itemResource.toItemStack(); - final long maxRemove = Math.min(stack.getMaxStackSize(), resourceAmount.getAmount()); + final long maxRemove = Math.min(stack.getMaxStackSize(), container.getAmount(slotIndex)); container.shrink(slotIndex, maxRemove); return stack.copyWithCount((int) maxRemove); } @@ -65,22 +60,21 @@ public ItemStack removeItemNoUpdate(final int slotIndex) { @Override public boolean canPlaceItem(final int slot, final ItemStack stack) { - return container.get(slot) == null; + return container.isEmpty(slot); } @Override public void setItem(final int slotIndex, final ItemStack itemStack) { - final ResourceAmountTemplate resourceAmount = container.get(slotIndex); + final ResourceKey resource = container.getResource(slotIndex); if (itemStack.isEmpty()) { - if (resourceAmount != null && resourceAmount.getStorageChannelType() == StorageChannelTypes.ITEM) { + if (resource instanceof ItemResource) { container.remove(slotIndex); } return; } - container.set(slotIndex, new ResourceAmountTemplate( + container.set(slotIndex, new ResourceAmount( ItemResource.ofItemStack(itemStack), - itemStack.getCount(), - StorageChannelTypes.ITEM + itemStack.getCount() )); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResource.java similarity index 54% rename from refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResource.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResource.java index 45058bad2..7d1095013 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResource.java @@ -1,20 +1,25 @@ -package com.refinedmods.refinedstorage2.platform.api.support.resource; +package com.refinedmods.refinedstorage2.platform.common.support.resource; import com.refinedmods.refinedstorage2.api.core.CoreValidations; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.FuzzyModeNormalizer; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import java.util.Optional; import javax.annotation.Nullable; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") -public record FluidResource(Fluid fluid, @Nullable CompoundTag tag) implements ResourceKey, FuzzyModeNormalizer { +public record FluidResource(Fluid fluid, @Nullable CompoundTag tag) + implements PlatformResourceKey, FuzzyModeNormalizer { private static final String TAG_TAG = "tag"; private static final String TAG_ID = "id"; @@ -28,16 +33,7 @@ public ResourceKey normalize() { return new FluidResource(fluid, null); } - public static CompoundTag toTag(final FluidResource fluidResource) { - final CompoundTag tag = new CompoundTag(); - if (fluidResource.tag() != null) { - tag.put(TAG_TAG, fluidResource.tag()); - } - tag.putString(TAG_ID, BuiltInRegistries.FLUID.getKey(fluidResource.fluid()).toString()); - return tag; - } - - public static Optional fromTag(final CompoundTag tag) { + static Optional fromTag(final CompoundTag tag) { final ResourceLocation id = new ResourceLocation(tag.getString(TAG_ID)); final Fluid fluid = BuiltInRegistries.FLUID.get(id); if (fluid == Fluids.EMPTY) { @@ -46,4 +42,30 @@ public static Optional fromTag(final CompoundTag tag) { final CompoundTag itemTag = tag.contains(TAG_TAG) ? tag.getCompound(TAG_TAG) : null; return Optional.of(new FluidResource(fluid, itemTag)); } + + @Override + public CompoundTag toTag() { + final CompoundTag nbt = new CompoundTag(); + if (tag != null) { + nbt.put(TAG_TAG, tag); + } + nbt.putString(TAG_ID, BuiltInRegistries.FLUID.getKey(fluid).toString()); + return nbt; + } + + @Override + public void toBuffer(final FriendlyByteBuf buf) { + buf.writeVarInt(BuiltInRegistries.FLUID.getId(fluid)); + buf.writeNbt(tag); + } + + @Override + public long getInterfaceExportLimit() { + return ResourceTypes.FLUID.getInterfaceExportLimit(); + } + + @Override + public ResourceType getResourceType() { + return ResourceTypes.FLUID; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceFactory.java index 312ae17e6..a6e829864 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceFactory.java @@ -1,11 +1,9 @@ package com.refinedmods.refinedstorage2.platform.common.support.resource; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import java.util.Optional; @@ -13,11 +11,10 @@ public class FluidResourceFactory implements ResourceFactory { @Override - public Optional create(final ItemStack stack) { - return Platform.INSTANCE.getContainedFluid(stack).map(result -> new ResourceAmountTemplate( + public Optional create(final ItemStack stack) { + return Platform.INSTANCE.getContainedFluid(stack).map(result -> new ResourceAmount( result.fluid(), - Platform.INSTANCE.getBucketAmount(), - StorageChannelTypes.FLUID + Platform.INSTANCE.getBucketAmount() )); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceRendering.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceRendering.java index f6e1848e9..82fb68926 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceRendering.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceRendering.java @@ -2,7 +2,6 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.AmountFormatting; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering; import com.refinedmods.refinedstorage2.platform.common.Platform; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/FluidStorageChannelType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceType.java similarity index 55% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/FluidStorageChannelType.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceType.java index 422aef67d..59d40a340 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/FluidStorageChannelType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceType.java @@ -1,19 +1,13 @@ -package com.refinedmods.refinedstorage2.platform.common.storage.channel; +package com.refinedmods.refinedstorage2.platform.common.support.resource; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperationsImpl; import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; -import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.AbstractPlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannelImpl; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceList; -import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceListImpl; +import com.refinedmods.refinedstorage2.platform.api.support.resource.AbstractResourceType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.grid.view.FluidGridResource; import com.refinedmods.refinedstorage2.platform.common.support.TextureIds; @@ -26,16 +20,14 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -class FluidStorageChannelType extends AbstractPlatformStorageChannelType { - FluidStorageChannelType() { +class FluidResourceType extends AbstractResourceType { + private static final String TAG_TAG = "tag"; + private static final String TAG_ID = "id"; + + FluidResourceType() { super( "FLUID", - () -> { - final ResourceList list = new ResourceListImpl(); - final FuzzyResourceList fuzzyList = new FuzzyResourceListImpl(list); - return new FuzzyStorageChannelImpl(fuzzyList); - }, - createTranslation("misc", "storage_channel_type.fluid"), + createTranslation("misc", "resource_type.fluid"), TextureIds.ICONS, 16, 128 @@ -43,21 +35,13 @@ class FluidStorageChannelType extends AbstractPlatformStorageChannelType { } @Override - public void toBuffer(final ResourceKey resource, final FriendlyByteBuf buf) { - if (!(resource instanceof FluidResource fluidResource)) { - throw new UnsupportedOperationException(); - } - PacketUtil.writeFluidResource(buf, fluidResource); - } - - @Override - public FluidResource fromBuffer(final FriendlyByteBuf buf) { + public PlatformResourceKey fromBuffer(final FriendlyByteBuf buf) { return PacketUtil.readFluidResource(buf); } @Override - public Optional toGridResource(final ResourceAmount resourceAmount) { - return Platform.INSTANCE.getFluidGridResourceFactory().apply(resourceAmount); + public Optional toGridResource(final PlatformResourceKey resource, final long amount) { + return Platform.INSTANCE.getFluidGridResourceFactory().apply(new ResourceAmount(resource, amount)); } @Override @@ -91,15 +75,7 @@ public GridOperations createGridOperations(final StorageChannel storageChannel, } @Override - public CompoundTag toTag(final ResourceKey resource) { - if (!(resource instanceof FluidResource fluidResource)) { - throw new UnsupportedOperationException(); - } - return FluidResource.toTag(fluidResource); - } - - @Override - public Optional fromTag(final CompoundTag tag) { + public Optional fromTag(final CompoundTag tag) { return FluidResource.fromTag(tag); } } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResource.java similarity index 65% rename from refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResource.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResource.java index 16be7f729..261c97128 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResource.java @@ -1,13 +1,17 @@ -package com.refinedmods.refinedstorage2.platform.api.support.resource; +package com.refinedmods.refinedstorage2.platform.common.support.resource; import com.refinedmods.refinedstorage2.api.core.CoreValidations; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.FuzzyModeNormalizer; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import java.util.Optional; import javax.annotation.Nullable; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -17,7 +21,7 @@ import org.slf4j.LoggerFactory; @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") -public record ItemResource(Item item, @Nullable CompoundTag tag) implements ResourceKey, FuzzyModeNormalizer { +public record ItemResource(Item item, @Nullable CompoundTag tag) implements PlatformResourceKey, FuzzyModeNormalizer { private static final Logger LOGGER = LoggerFactory.getLogger(ItemResource.class); private static final String TAG_TAG = "tag"; @@ -48,20 +52,37 @@ public ResourceKey normalize() { return new ItemResource(item, null); } - public static ItemResource ofItemStack(final ItemStack itemStack) { - return new ItemResource(itemStack.getItem(), itemStack.getTag()); + @Override + public CompoundTag toTag() { + final CompoundTag nbt = new CompoundTag(); + if (this.tag != null) { + nbt.put(TAG_TAG, this.tag); + } + nbt.putString(TAG_ID, BuiltInRegistries.ITEM.getKey(item).toString()); + return nbt; } - public static CompoundTag toTag(final ItemResource itemResource) { - final CompoundTag tag = new CompoundTag(); - if (itemResource.tag() != null) { - tag.put(TAG_TAG, itemResource.tag()); - } - tag.putString(TAG_ID, BuiltInRegistries.ITEM.getKey(itemResource.item()).toString()); - return tag; + @Override + public void toBuffer(final FriendlyByteBuf buf) { + buf.writeVarInt(Item.getId(item)); + buf.writeNbt(tag); + } + + @Override + public long getInterfaceExportLimit() { + return item.getMaxStackSize(); + } + + @Override + public ResourceType getResourceType() { + return ResourceTypes.ITEM; + } + + public static ItemResource ofItemStack(final ItemStack itemStack) { + return new ItemResource(itemStack.getItem(), itemStack.getTag()); } - public static Optional fromTag(final CompoundTag tag) { + static Optional fromTag(final CompoundTag tag) { final ResourceLocation id = new ResourceLocation(tag.getString(TAG_ID)); final Item item = BuiltInRegistries.ITEM.get(id); if (item == Items.AIR) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceFactory.java index a807f7216..56143b94a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceFactory.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceFactory.java @@ -1,10 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.support.resource; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import java.util.Optional; @@ -12,15 +10,11 @@ public class ItemResourceFactory implements ResourceFactory { @Override - public Optional create(final ItemStack stack) { + public Optional create(final ItemStack stack) { if (stack.isEmpty()) { return Optional.empty(); } - return Optional.of(new ResourceAmountTemplate( - ItemResource.ofItemStack(stack), - stack.getCount(), - StorageChannelTypes.ITEM - )); + return Optional.of(new ResourceAmount(ItemResource.ofItemStack(stack), stack.getCount())); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceRendering.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceRendering.java index aaf3e5a29..86c143b66 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceRendering.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceRendering.java @@ -2,7 +2,6 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.AmountFormatting; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering; import java.util.Collections; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/ItemStorageChannelType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceType.java similarity index 52% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/ItemStorageChannelType.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceType.java index daf4a9c06..4f9aa3bbc 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/ItemStorageChannelType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceType.java @@ -1,19 +1,13 @@ -package com.refinedmods.refinedstorage2.platform.common.storage.channel; +package com.refinedmods.refinedstorage2.platform.common.support.resource; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperationsImpl; import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; -import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.AbstractPlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannelImpl; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceList; -import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceListImpl; +import com.refinedmods.refinedstorage2.platform.api.support.resource.AbstractResourceType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; import com.refinedmods.refinedstorage2.platform.common.support.TextureIds; @@ -26,38 +20,26 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -class ItemStorageChannelType extends AbstractPlatformStorageChannelType { - ItemStorageChannelType() { +// TODO: Verify fuzzy mode. +class ItemResourceType extends AbstractResourceType { + ItemResourceType() { super( "ITEM", - () -> { - final ResourceList list = new ResourceListImpl(); - final FuzzyResourceList fuzzyList = new FuzzyResourceListImpl(list); - return new FuzzyStorageChannelImpl(fuzzyList); - }, - createTranslation("misc", "storage_channel_type.item"), + createTranslation("misc", "resource_type.item"), TextureIds.ICONS, 0, 128 ); } - @Override - public void toBuffer(final ResourceKey resource, final FriendlyByteBuf buf) { - if (!(resource instanceof ItemResource itemResource)) { - throw new UnsupportedOperationException(); - } - PacketUtil.writeItemResource(buf, itemResource); - } - @Override public ItemResource fromBuffer(final FriendlyByteBuf buf) { return PacketUtil.readItemResource(buf); } @Override - public Optional toGridResource(final ResourceAmount resourceAmount) { - return Platform.INSTANCE.getItemGridResourceFactory().apply(resourceAmount); + public Optional toGridResource(final PlatformResourceKey resource, final long amount) { + return Platform.INSTANCE.getItemGridResourceFactory().apply(new ResourceAmount(resource, amount)); } @Override @@ -80,14 +62,6 @@ public long getInterfaceExportLimit() { return 64; } - @Override - public long getInterfaceExportLimit(final ResourceKey resource) { - if (!(resource instanceof ItemResource itemResource)) { - throw new UnsupportedOperationException(); - } - return itemResource.item().getMaxStackSize(); - } - @Override public GridOperations createGridOperations(final StorageChannel storageChannel, final Actor actor) { return new GridOperationsImpl( @@ -99,15 +73,7 @@ public GridOperations createGridOperations(final StorageChannel storageChannel, } @Override - public CompoundTag toTag(final ResourceKey resource) { - if (!(resource instanceof ItemResource itemResource)) { - throw new UnsupportedOperationException(); - } - return ItemResource.toTag(itemResource); - } - - @Override - public Optional fromTag(final CompoundTag tag) { + public Optional fromTag(final CompoundTag tag) { return ItemResource.fromTag(tag); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceContainerImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceContainerImpl.java index 689d7c488..f58be8381 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceContainerImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceContainerImpl.java @@ -2,15 +2,14 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.core.CoreValidations; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainerType; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceFactory; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.util.MathUtil; import java.util.ArrayList; @@ -28,9 +27,9 @@ import net.minecraft.world.item.ItemStack; public class ResourceContainerImpl implements ResourceContainer { - private final ResourceAmountTemplate[] slots; + private final ResourceContainerSlot[] slots; private final ResourceContainerType type; - private final ToLongFunction maxAmountProvider; + private final ToLongFunction maxAmountProvider; private final ResourceFactory primaryResourceFactory; private final Set alternativeResourceFactories; @@ -39,10 +38,10 @@ public class ResourceContainerImpl implements ResourceContainer { public ResourceContainerImpl(final int size, final ResourceContainerType type, - final ToLongFunction maxAmountProvider, + final ToLongFunction maxAmountProvider, final ResourceFactory primaryResourceFactory, final Set alternativeResourceFactories) { - this.slots = new ResourceAmountTemplate[size]; + this.slots = new ResourceContainerSlot[size]; this.type = type; this.maxAmountProvider = maxAmountProvider; this.primaryResourceFactory = primaryResourceFactory; @@ -77,13 +76,13 @@ public void change(final int index, final ItemStack stack, final boolean tryAlte } @Override - public void set(final int index, final ResourceAmountTemplate resourceAmount) { + public void set(final int index, final ResourceAmount resourceAmount) { setSilently(index, resourceAmount); changed(); } - private void setSilently(final int index, final ResourceAmountTemplate resourceAmount) { - slots[index] = resourceAmount; + private void setSilently(final int index, final ResourceAmount resourceAmount) { + slots[index] = new ResourceContainerSlot(resourceAmount); } @Override @@ -101,11 +100,11 @@ public boolean isValid(final ResourceKey resource) { @Override public long getAmount(final int index) { - final ResourceAmountTemplate resourceAmount = slots[index]; - if (resourceAmount == null) { + final ResourceContainerSlot slot = slots[index]; + if (slot == null) { return 0; } - return resourceAmount.getAmount(); + return slot.getResourceAmount().getAmount(); } @Override @@ -122,22 +121,22 @@ public void shrink(final int index, final long amount) { @Override public void setAmount(final int index, final long amount) { - final ResourceAmountTemplate resourceAmount = slots[index]; - if (resourceAmount == null) { + final ResourceContainerSlot slot = slots[index]; + if (slot == null) { return; } - final long newAmount = MathUtil.clamp(amount, 0, getMaxAmount(resourceAmount)); + final long newAmount = MathUtil.clamp(amount, 0, getMaxAmount(slot.getResourceAmount().getResource())); if (newAmount == 0) { remove(index); } else { - slots[index] = resourceAmount.withAmount(newAmount); + slots[index] = slot.withAmount(newAmount); } changed(); } @Override - public long getMaxAmount(final ResourceAmountTemplate resourceAmount) { - return maxAmountProvider.applyAsLong(resourceAmount.getResourceTemplate()); + public long getMaxAmount(final ResourceKey resource) { + return maxAmountProvider.applyAsLong(resource); } @Override @@ -157,39 +156,62 @@ public int size() { @Override @Nullable - public ResourceAmountTemplate get(final int index) { - return slots[index]; + public ResourceAmount get(final int index) { + final ResourceContainerSlot slot = slots[index]; + if (slot == null) { + return null; + } + return slot.getResourceAmount(); + } + + @Nullable + @Override + public PlatformResourceKey getResource(final int index) { + final ResourceContainerSlot slot = slots[index]; + if (slot == null) { + return null; + } + return slot.getPlatformResource(); + } + + @Override + public ItemStack getStackRepresentation(final int index) { + final ResourceContainerSlot slot = slots[index]; + if (slot == null) { + return ItemStack.EMPTY; + } + return slot.getStackRepresentation(); } @Override - public Set getUniqueTemplates() { + public Set getUniqueResources() { final Set result = new HashSet<>(); for (int i = 0; i < size(); ++i) { - final ResourceAmountTemplate resourceAmount = slots[i]; - if (resourceAmount == null) { + final ResourceContainerSlot slot = slots[i]; + if (slot == null) { continue; } - result.add(resourceAmount.getResourceTemplate().resource()); + result.add(slot.getResourceAmount().getResource()); } return result; } @Override - public List getTemplates() { - final List result = new ArrayList<>(); + public List getResources() { + final List result = new ArrayList<>(); for (int i = 0; i < size(); ++i) { - final ResourceAmountTemplate resourceAmount = slots[i]; - if (resourceAmount == null) { + final ResourceContainerSlot slot = slots[i]; + if (slot == null) { continue; } - result.add(resourceAmount.getResourceTemplate()); + result.add(slot.getResourceAmount().getResource()); } return result; } @Override public void writeToUpdatePacket(final FriendlyByteBuf buf) { - for (final ResourceAmountTemplate slot : slots) { + for (final ResourceContainerSlot slot : slots) { if (slot == null) { buf.writeBoolean(false); continue; @@ -198,13 +220,13 @@ public void writeToUpdatePacket(final FriendlyByteBuf buf) { } } - private void writeToUpdatePacket(final FriendlyByteBuf buf, final ResourceAmountTemplate resourceAmount) { - final PlatformStorageChannelType storageChannelType = resourceAmount.getStorageChannelType(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresentOrElse(id -> { + private void writeToUpdatePacket(final FriendlyByteBuf buf, final ResourceContainerSlot slot) { + final ResourceType resourceType = slot.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresentOrElse(id -> { buf.writeBoolean(true); buf.writeResourceLocation(id); - storageChannelType.toBuffer(resourceAmount.getResource(), buf); - buf.writeLong(resourceAmount.getAmount()); + slot.getPlatformResource().toBuffer(buf); + buf.writeLong(slot.getAmount()); }, () -> buf.writeBoolean(false)); } @@ -216,24 +238,24 @@ public void readFromUpdatePacket(final int index, final FriendlyByteBuf buf) { return; } final ResourceLocation id = buf.readResourceLocation(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(id).ifPresent( - storageChannelType -> readFromUpdatePacket(index, buf, storageChannelType) + PlatformApi.INSTANCE.getResourceTypeRegistry().get(id).ifPresent( + resourceType -> readFromUpdatePacket(index, buf, resourceType) ); } private void readFromUpdatePacket(final int index, final FriendlyByteBuf buf, - final PlatformStorageChannelType storageChannelType) { - final ResourceKey resource = storageChannelType.fromBuffer(buf); + final ResourceType resourceType) { + final ResourceKey resource = resourceType.fromBuffer(buf); final long amount = buf.readLong(); - setSilently(index, new ResourceAmountTemplate(resource, amount, storageChannelType)); + setSilently(index, new ResourceAmount(resource, amount)); } @Override public CompoundTag toTag() { final CompoundTag tag = new CompoundTag(); for (int i = 0; i < size(); ++i) { - final ResourceAmountTemplate resourceAmount = slots[i]; + final ResourceContainerSlot resourceAmount = slots[i]; if (resourceAmount == null) { continue; } @@ -244,22 +266,21 @@ public CompoundTag toTag() { private void addToTag(final CompoundTag tag, final int index, - final ResourceAmountTemplate resourceAmount) { - final PlatformStorageChannelType storageChannelType = resourceAmount.getStorageChannelType(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresent( - storageChannelTypeId -> addToTag(tag, index, resourceAmount, storageChannelType, storageChannelTypeId) + final ResourceContainerSlot resourceAmount) { + final ResourceType resourceType = resourceAmount.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent( + resourceTypeId -> addToTag(tag, index, resourceAmount, resourceTypeId) ); } private void addToTag(final CompoundTag tag, final int index, - final ResourceAmountTemplate resourceAmount, - final PlatformStorageChannelType storageChannelType, - final ResourceLocation storageChannelTypeId) { + final ResourceContainerSlot slot, + final ResourceLocation resourceTypeId) { final CompoundTag serialized = new CompoundTag(); - serialized.putString("t", storageChannelTypeId.toString()); - serialized.put("v", storageChannelType.toTag(resourceAmount.getResource())); - serialized.putLong("a", resourceAmount.getAmount()); + serialized.putString("t", resourceTypeId.toString()); + serialized.put("v", slot.getPlatformResource().toTag()); + serialized.putLong("a", slot.getAmount()); tag.put("s" + index, serialized); } @@ -277,19 +298,17 @@ public void fromTag(final CompoundTag tag) { } private void fromTag(final int index, final CompoundTag tag) { - final ResourceLocation storageChannelTypeId = new ResourceLocation(tag.getString("t")); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(storageChannelTypeId).ifPresent( - storageChannelType -> fromTag(index, tag, storageChannelType) + final ResourceLocation resourceTypeId = new ResourceLocation(tag.getString("t")); + PlatformApi.INSTANCE.getResourceTypeRegistry().get(resourceTypeId).ifPresent( + resourceType -> fromTag(index, tag, resourceType) ); } - private void fromTag(final int index, - final CompoundTag tag, - final PlatformStorageChannelType storageChannelType) { + private void fromTag(final int index, final CompoundTag tag, final ResourceType resourceType) { final long amount = tag.getLong("a"); - storageChannelType.fromTag(tag.getCompound("v")).ifPresent(resource -> setSilently( + resourceType.fromTag(tag.getCompound("v")).ifPresent(resource -> setSilently( index, - new ResourceAmountTemplate(resource, amount, storageChannelType) + new ResourceAmount(resource, amount) )); } @@ -323,26 +342,22 @@ public void setChanged() { } @Override - public long insert(final StorageChannelType storageChannelType, - final ResourceKey resource, - final long amount, - final Action action) { - if (!(storageChannelType instanceof PlatformStorageChannelType platformStorageChannelType)) { - return 0; + public long insert(final ResourceKey resource, final long amount, final Action action) { + if (!(resource instanceof PlatformResourceKey platformResource)) { + return 0L; } long remainder = amount; for (int i = 0; i < size(); ++i) { - final ResourceAmountTemplate existing = get(i); - if (existing == null) { - remainder -= insertIntoEmptySlot(i, resource, action, platformStorageChannelType, remainder); - } else if (existing.getResource().equals(resource)) { + final ResourceAmount slot = get(i); + if (slot == null) { + remainder -= insertIntoEmptySlot(i, platformResource, action, remainder); + } else if (slot.getResource().equals(resource)) { remainder -= insertIntoExistingSlot( i, - platformStorageChannelType, - resource, + platformResource, action, remainder, - existing + slot ); } if (remainder == 0) { @@ -353,28 +368,22 @@ public long insert(final StorageChannelType storageChannelType, } private long insertIntoEmptySlot(final int slotIndex, - final ResourceKey resource, + final PlatformResourceKey resource, final Action action, - final PlatformStorageChannelType platformStorageChannelType, final long amount) { - final long inserted = Math.min(platformStorageChannelType.getInterfaceExportLimit(resource), amount); + final long inserted = Math.min(resource.getInterfaceExportLimit(), amount); if (action == Action.EXECUTE) { - set(slotIndex, new ResourceAmountTemplate( - resource, - inserted, - platformStorageChannelType - )); + set(slotIndex, new ResourceAmount(resource, inserted)); } return inserted; } private long insertIntoExistingSlot(final int slotIndex, - final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + final PlatformResourceKey resource, final Action action, final long amount, - final ResourceAmountTemplate existing) { - final long spaceRemaining = storageChannelType.getInterfaceExportLimit(resource) - existing.getAmount(); + final ResourceAmount existing) { + final long spaceRemaining = resource.getInterfaceExportLimit() - existing.getAmount(); final long inserted = Math.min(spaceRemaining, amount); if (action == Action.EXECUTE) { grow(slotIndex, inserted); @@ -386,12 +395,12 @@ private long insertIntoExistingSlot(final int slotIndex, public long extract(final ResourceKey resource, final long amount, final Action action) { long extracted = 0; for (int i = 0; i < size(); ++i) { - final ResourceAmountTemplate slot = get(i); - if (slot == null || !resource.equals(slot.getResource())) { + final ResourceAmount slotContents = get(i); + if (slotContents == null || !resource.equals(slotContents.getResource())) { continue; } final long stillNeeded = amount - extracted; - final long toExtract = Math.min(slot.getAmount(), stillNeeded); + final long toExtract = Math.min(slotContents.getAmount(), stillNeeded); if (action == Action.EXECUTE) { shrink(i, toExtract); } @@ -410,9 +419,9 @@ public ResourceContainer copy() { alternativeResourceFactories ); for (int i = 0; i < size(); ++i) { - final ResourceAmountTemplate resourceAmount = get(i); - if (resourceAmount != null) { - copy.set(i, resourceAmount); + final ResourceAmount slotContents = get(i); + if (slotContents != null) { + copy.set(i, slotContents); } } return copy; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceContainerSlot.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceContainerSlot.java new file mode 100644 index 000000000..fcb7efd05 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceContainerSlot.java @@ -0,0 +1,62 @@ +package com.refinedmods.refinedstorage2.platform.common.support.resource; + +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; + +import java.util.Objects; + +import net.minecraft.world.item.ItemStack; + +class ResourceContainerSlot { + private final ResourceAmount resourceAmount; + private final ItemStack stackRepresentation; + + ResourceContainerSlot(final ResourceAmount resourceAmount) { + this.resourceAmount = resourceAmount; + this.stackRepresentation = resourceAmount.getResource() instanceof ItemResource itemResource + ? itemResource.toItemStack(resourceAmount.getAmount()) + : ItemStack.EMPTY; + } + + long getAmount() { + return resourceAmount.getAmount(); + } + + ResourceAmount getResourceAmount() { + return resourceAmount; + } + + PlatformResourceKey getPlatformResource() { + return (PlatformResourceKey) resourceAmount.getResource(); + } + + ResourceType getResourceType() { + return getPlatformResource().getResourceType(); + } + + ItemStack getStackRepresentation() { + return stackRepresentation; + } + + ResourceContainerSlot withAmount(final long newAmount) { + return new ResourceContainerSlot(new ResourceAmount(resourceAmount.getResource(), newAmount)); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ResourceContainerSlot that = (ResourceContainerSlot) o; + return Objects.equals(resourceAmount, that.resourceAmount); + } + + @Override + public int hashCode() { + return Objects.hash(resourceAmount); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceTypes.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceTypes.java new file mode 100644 index 000000000..2b572aa99 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ResourceTypes.java @@ -0,0 +1,11 @@ +package com.refinedmods.refinedstorage2.platform.common.support.resource; + +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; + +public final class ResourceTypes { + public static final ResourceType ITEM = new ItemResourceType(); + public static final ResourceType FLUID = new FluidResourceType(); + + private ResourceTypes() { + } +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/list/FuzzyResourceListImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/FuzzyResourceListImpl.java similarity index 94% rename from refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/list/FuzzyResourceListImpl.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/FuzzyResourceListImpl.java index 9f780978a..9c62ba6f3 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/resource/list/FuzzyResourceListImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/FuzzyResourceListImpl.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.platform.api.support.resource.list; +package com.refinedmods.refinedstorage2.platform.common.support.resource.list; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; @@ -6,6 +6,7 @@ import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListOperationResult; import com.refinedmods.refinedstorage2.platform.api.support.resource.FuzzyModeNormalizer; +import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceList; import java.util.Collection; import java.util.Collections; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/package-info.java similarity index 72% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/package-info.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/package-info.java index 72cbfb5b1..1491d8830 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/channel/package-info.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.platform.common.storage.channel; +package com.refinedmods.refinedstorage2.platform.common.support.resource.list; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/tooltip/ResourceClientTooltipComponent.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/tooltip/ResourceClientTooltipComponent.java index 70b079330..79b983225 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/tooltip/ResourceClientTooltipComponent.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/tooltip/ResourceClientTooltipComponent.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.support.tooltip; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceRendering; import java.util.Objects; @@ -13,10 +13,10 @@ import net.minecraft.network.chat.Component; public class ResourceClientTooltipComponent implements ClientTooltipComponent { - private final ResourceAmountTemplate resourceAmount; + private final ResourceAmount resourceAmount; private final Component name; - public ResourceClientTooltipComponent(final ResourceAmountTemplate resourceAmount) { + public ResourceClientTooltipComponent(final ResourceAmount resourceAmount) { this.resourceAmount = resourceAmount; this.name = getNameWithAmount(resourceAmount); } @@ -48,7 +48,7 @@ public void renderImage(final Font font, final int x, final int y, final GuiGrap ); } - private static Component getNameWithAmount(final ResourceAmountTemplate resourceAmount) { + private static Component getNameWithAmount(final ResourceAmount resourceAmount) { final ResourceRendering rendering = PlatformApi.INSTANCE.getResourceRendering( resourceAmount.getResource() ); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RegulatorUpgradeItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RegulatorUpgradeItem.java index 5410cff06..dfa3e843d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RegulatorUpgradeItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/upgrade/RegulatorUpgradeItem.java @@ -1,9 +1,10 @@ package com.refinedmods.refinedstorage2.platform.common.upgrade; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; import com.refinedmods.refinedstorage2.platform.api.upgrade.AbstractUpgradeItem; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry; @@ -59,19 +60,19 @@ public InteractionResultHolder use(final Level level, final Player pl @Override public Optional getTooltipImage(final ItemStack stack) { - return Optional.of(new RegulatorTooltipComponent(HELP, getFilteredResource(stack))); + return Optional.of(new RegulatorTooltipComponent(HELP, getConfiguredResource(stack))); } @Nullable - private ResourceAmountTemplate getFilteredResource(final ItemStack stack) { + private ResourceAmount getConfiguredResource(final ItemStack stack) { final ResourceContainer container = getResourceFilterContainer(stack); - final ResourceAmountTemplate resourceAmount = container.get(0); - if (resourceAmount == null) { + final PlatformResourceKey resource = container.getResource(0); + if (resource == null) { return null; } final double amount = getAmount(stack); - final long normalizedAmount = resourceAmount.getStorageChannelType().normalizeAmount(amount); - return resourceAmount.withAmount(normalizedAmount); + final long normalizedAmount = resource.getResourceType().normalizeAmount(amount); + return new ResourceAmount(resource, normalizedAmount); } public double getAmount(final ItemStack stack) { @@ -99,21 +100,21 @@ public long getEnergyUsage() { public OptionalLong getDesiredAmount(final ItemStack stack, final ResourceKey resource) { final ResourceContainer container = getResourceFilterContainer(stack); - final ResourceAmountTemplate filteredResource = container.get(0); - if (filteredResource == null) { + final PlatformResourceKey configuredResource = container.getResource(0); + if (configuredResource == null) { return OptionalLong.empty(); } - final boolean same = filteredResource.getResource().equals(resource); + final boolean same = configuredResource.equals(resource); if (!same) { return OptionalLong.empty(); } final double amount = getAmount(stack); - final long normalizedAmount = filteredResource.getStorageChannelType().normalizeAmount(amount); + final long normalizedAmount = configuredResource.getResourceType().normalizeAmount(amount); return OptionalLong.of(normalizedAmount); } public record RegulatorTooltipComponent(Component helpText, - @Nullable ResourceAmountTemplate filteredResource) + @Nullable ResourceAmount configuredResource) implements TooltipComponent { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java index 791d2e55c..bd04f3482 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/PacketUtil.java @@ -1,8 +1,9 @@ package com.refinedmods.refinedstorage2.platform.common.util; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import javax.annotation.Nullable; @@ -15,23 +16,13 @@ public final class PacketUtil { private PacketUtil() { } - public static void writeItemResource(final FriendlyByteBuf buf, final ItemResource itemResource) { - buf.writeVarInt(Item.getId(itemResource.item())); - buf.writeNbt(itemResource.tag()); - } - public static ItemResource readItemResource(final FriendlyByteBuf buf) { final int id = buf.readVarInt(); final CompoundTag nbt = buf.readNbt(); return new ItemResource(Item.byId(id), nbt); } - public static void writeFluidResource(final FriendlyByteBuf buf, final FluidResource itemResource) { - buf.writeVarInt(BuiltInRegistries.FLUID.getId(itemResource.fluid())); - buf.writeNbt(itemResource.tag()); - } - - public static FluidResource readFluidResource(final FriendlyByteBuf buf) { + public static PlatformResourceKey readFluidResource(final FriendlyByteBuf buf) { final int id = buf.readVarInt(); final CompoundTag nbt = buf.readNbt(); return new FluidResource(BuiltInRegistries.FLUID.byId(id), nbt); 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 aca94c00e..690cfd92f 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 @@ -66,9 +66,9 @@ "gui.refinedstorage2.grid.synchronizer.rei.help": "Sync the search box text to the REI filter.", "gui.refinedstorage2.grid.synchronizer.rei.two_way": "REI two-way", "gui.refinedstorage2.grid.synchronizer.rei.two_way.help": "Sync the search box text to the JEI filter, and the JEI filter to the search box text.", - "gui.refinedstorage2.grid.storage_channel_type": "Storage channel", - "gui.refinedstorage2.grid.storage_channel_type.all": "All", - "gui.refinedstorage2.grid.storage_channel_type.help": "Filter resources from a specific storage channel.", + "gui.refinedstorage2.grid.resource_type": "Resource type", + "gui.refinedstorage2.grid.resource_type.all": "All", + "gui.refinedstorage2.grid.resource_type.help": "Filter specific resource types.", "gui.refinedstorage2.crafting_grid.move.network": "Move items to network", "gui.refinedstorage2.crafting_grid.move.inventory": "Move items to inventory", "gui.refinedstorage2.detector.mode": "Mode", @@ -232,8 +232,8 @@ "misc.refinedstorage2.last_modified.weeks": "Last modified %d weeks ago by %s", "misc.refinedstorage2.last_modified.year": "Last modified %d year ago by %s", "misc.refinedstorage2.last_modified.years": "Last modified %d years ago by %s", - "misc.refinedstorage2.storage_channel_type.item": "Item", - "misc.refinedstorage2.storage_channel_type.fluid": "Fluid", + "misc.refinedstorage2.resource_type.item": "Item", + "misc.refinedstorage2.resource_type.fluid": "Fluid", "misc.refinedstorage2.press_shift_for_help": "Press SHIFT for help", "key.refinedstorage2.focus_search_bar": "Focus search bar", "key.refinedstorage2.clear_crafting_grid_matrix_to_network": "Clear Crafting Grid matrix to network", @@ -254,7 +254,7 @@ "text.autoconfig.refinedstorage2.option.grid.smoothScrolling": "Smooth scrolling", "text.autoconfig.refinedstorage2.option.grid.autoSelected": "Auto selected search box", "text.autoconfig.refinedstorage2.option.grid.synchronizer": "Synchronizer", - "text.autoconfig.refinedstorage2.option.grid.storageChannelType": "Storage channel", + "text.autoconfig.refinedstorage2.option.grid.resourceType": "Resource type", "text.autoconfig.refinedstorage2.option.grid.sortingDirection": "Sorting direction", "text.autoconfig.refinedstorage2.option.grid.sortingType": "Sorting type", "text.autoconfig.refinedstorage2.option.grid.size": "Size", diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/zh_cn.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/zh_cn.json index 80ba42bdc..78416601b 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/zh_cn.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/zh_cn.json @@ -64,9 +64,9 @@ "gui.refinedstorage2.grid.synchronizer.rei.help": "将搜索框文本同步到 REI 过滤器。", "gui.refinedstorage2.grid.synchronizer.rei.two_way": "REI 双向", "gui.refinedstorage2.grid.synchronizer.rei.two_way.help": "将搜索框文本同步到 JEI 过滤器,并将 JEI 过滤器同步到搜索框文本。", - "gui.refinedstorage2.grid.storage_channel_type": "存储通道", - "gui.refinedstorage2.grid.storage_channel_type.all": "全部", - "gui.refinedstorage2.grid.storage_channel_type.help": "从特定的存储通道中过滤资源。", + "gui.refinedstorage2.grid.resource_type": "存储通道", + "gui.refinedstorage2.grid.resource_type.all": "全部", + "gui.refinedstorage2.grid.resource_type.help": "从特定的存储通道中过滤资源。", "gui.refinedstorage2.crafting_grid.move.network": "将物品移动到网络。", "gui.refinedstorage2.crafting_grid.move.inventory": "将物品移动到物品栏。", "gui.refinedstorage2.detector.mode": "模式", @@ -230,8 +230,8 @@ "misc.refinedstorage2.last_modified.weeks": "%d 周前由 %s 修改", "misc.refinedstorage2.last_modified.year": "%d 年前由 %s 修改", "misc.refinedstorage2.last_modified.years": "%d 年前由 %s 修改", - "misc.refinedstorage2.storage_channel_type.item": "物品", - "misc.refinedstorage2.storage_channel_type.fluid": "流体", + "misc.refinedstorage2.resource_type.item": "物品", + "misc.refinedstorage2.resource_type.fluid": "流体", "misc.refinedstorage2.press_shift_for_help": "按下 SHIFT 获取帮助", "key.refinedstorage2.focus_search_bar": "聚焦搜索栏", "key.refinedstorage2.clear_crafting_grid_matrix_to_network": "清除制作终端矩阵到网络", @@ -252,7 +252,7 @@ "text.autoconfig.refinedstorage2.option.grid.smoothScrolling": "平滑滚动", "text.autoconfig.refinedstorage2.option.grid.autoSelected": "自动选择搜索框", "text.autoconfig.refinedstorage2.option.grid.synchronizer": "同步器", - "text.autoconfig.refinedstorage2.option.grid.storageChannelType": "存储通道类型", + "text.autoconfig.refinedstorage2.option.grid.resourceType": "存储通道类型", "text.autoconfig.refinedstorage2.option.grid.sortingDirection": "排序方向", "text.autoconfig.refinedstorage2.option.grid.sortingType": "排序类型", "text.autoconfig.refinedstorage2.option.grid.size": "大小", diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java index 9dc2cf9c9..5f1e86fef 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/TestPlatform.java @@ -4,13 +4,13 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategyFactory; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.support.ClientToServerCommunications; import com.refinedmods.refinedstorage2.platform.common.support.ServerToClientCommunications; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.MenuOpener; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.TransferManager; import com.refinedmods.refinedstorage2.platform.common.support.render.FluidRenderer; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.Optional; diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/grid/GridSortingTypesTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/grid/GridSortingTypesTest.java index 6a3c64e86..5257a4a34 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/grid/GridSortingTypesTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/grid/GridSortingTypesTest.java @@ -7,8 +7,8 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridViewBuilder; import com.refinedmods.refinedstorage2.api.grid.view.GridViewBuilderImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.grid.view.AbstractItemGridResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import java.util.Comparator; diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageTypeTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageTypeTest.java index 067e97ca4..dfbfd1832 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageTypeTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/FluidStorageTypeTest.java @@ -13,8 +13,8 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.SimpleListener; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import net.minecraft.nbt.CompoundTag; diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageTypeTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageTypeTest.java index 2164c5a05..dbf632236 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageTypeTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/ItemStorageTypeTest.java @@ -13,8 +13,8 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.SimpleListener; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import net.minecraft.nbt.CompoundTag; diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/PlatformStorageTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/PlatformStorageTest.java index 8eb16b203..d86c9a56a 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/PlatformStorageTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/PlatformStorageTest.java @@ -10,8 +10,8 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.SimpleListener; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import net.minecraft.world.item.Items; diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageRepositoryImplTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageRepositoryImplTest.java index ef8393a03..7ed352c33 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageRepositoryImplTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageRepositoryImplTest.java @@ -12,8 +12,8 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.StorageInfo; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.PlatformTestFixtures; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import java.util.Optional; diff --git a/refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResourceTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceTest.java similarity index 84% rename from refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResourceTest.java rename to refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceTest.java index 6ce1c0184..1df545f93 100644 --- a/refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/FluidResourceTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/FluidResourceTest.java @@ -1,6 +1,7 @@ -package com.refinedmods.refinedstorage2.platform.api.support.resource; +package com.refinedmods.refinedstorage2.platform.common.support.resource; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import java.util.Optional; @@ -33,8 +34,8 @@ void testSerialization(final boolean hasTag) { final FluidResource fluidResource = new FluidResource(Fluids.WATER, fluidTag); // Act - final CompoundTag serialized = FluidResource.toTag(fluidResource); - final Optional deserialized = FluidResource.fromTag(serialized); + final CompoundTag serialized = fluidResource.toTag(); + final Optional deserialized = FluidResource.fromTag(serialized); // Assert assertThat(deserialized).isPresent().contains(fluidResource); @@ -44,11 +45,11 @@ void testSerialization(final boolean hasTag) { void testDeserializationWithInvalidFluid() { // Arrange final FluidResource fluidResource = new FluidResource(Fluids.WATER, null); - final CompoundTag serialized = FluidResource.toTag(fluidResource); + final CompoundTag serialized = fluidResource.toTag(); serialized.putString("id", "minecraft:non_existent"); // Act - final Optional deserialized = FluidResource.fromTag(serialized); + final Optional deserialized = FluidResource.fromTag(serialized); // Assert assertThat(deserialized).isEmpty(); diff --git a/refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResourceTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceTest.java similarity index 86% rename from refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResourceTest.java rename to refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceTest.java index de3fa28d1..0d95f19a5 100644 --- a/refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/ItemResourceTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/ItemResourceTest.java @@ -1,6 +1,7 @@ -package com.refinedmods.refinedstorage2.platform.api.support.resource; +package com.refinedmods.refinedstorage2.platform.common.support.resource; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import java.util.Optional; @@ -35,8 +36,8 @@ void testSerialization(final boolean hasTag) { final ItemResource itemResource = new ItemResource(Items.DIRT, itemTag); // Act - final CompoundTag serialized = ItemResource.toTag(itemResource); - final Optional deserialized = ItemResource.fromTag(serialized); + final CompoundTag serialized = itemResource.toTag(); + final Optional deserialized = ItemResource.fromTag(serialized); // Assert assertThat(deserialized).isPresent().contains(itemResource); @@ -46,11 +47,11 @@ void testSerialization(final boolean hasTag) { void testDeserializationWithInvalidItem() { // Arrange final ItemResource itemResource = new ItemResource(Items.DIRT, null); - final CompoundTag serialized = ItemResource.toTag(itemResource); + final CompoundTag serialized = itemResource.toTag(); serialized.putString("id", "minecraft:non_existent"); // Act - final Optional deserialized = ItemResource.fromTag(serialized); + final Optional deserialized = ItemResource.fromTag(serialized); // Assert assertThat(deserialized).isEmpty(); diff --git a/refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/list/FuzzyResourceListImplTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/FuzzyResourceListImplTest.java similarity index 97% rename from refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/list/FuzzyResourceListImplTest.java rename to refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/FuzzyResourceListImplTest.java index 3d1b652ba..77b523331 100644 --- a/refinedstorage2-platform-api/src/test/java/com/refinedmods/refinedstorage2/platform/api/support/resource/list/FuzzyResourceListImplTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/support/resource/list/FuzzyResourceListImplTest.java @@ -1,8 +1,9 @@ -package com.refinedmods.refinedstorage2.platform.api.support.resource.list; +package com.refinedmods.refinedstorage2.platform.common.support.resource.list; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.support.resource.list.FuzzyResourceList; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; import java.util.Collection; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java index d1e24f9bd..18eac2b73 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ClientModInitializerImpl.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.fabric; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.upgrade.AbstractUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.AbstractClientModInitializer; import com.refinedmods.refinedstorage2.platform.common.configurationcard.ConfigurationCardItemPropertyFunction; @@ -341,20 +341,20 @@ private void registerCustomTooltips() { } if (data instanceof RegulatorUpgradeItem.RegulatorTooltipComponent component) { final ClientTooltipComponent help = HelpClientTooltipComponent.create(component.helpText()); - return component.filteredResource() == null + return component.configuredResource() == null ? help - : createRegulatorUpgradeClientTooltipComponent(component.filteredResource(), help); + : createRegulatorUpgradeClientTooltipComponent(component.configuredResource(), help); } return null; }); } private CompositeClientTooltipComponent createRegulatorUpgradeClientTooltipComponent( - final ResourceAmountTemplate filteredResource, + final ResourceAmount configuredResource, final ClientTooltipComponent help ) { return new CompositeClientTooltipComponent(List.of( - new ResourceClientTooltipComponent(filteredResource), + new ResourceClientTooltipComponent(configuredResource), help )); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java index d6d95a1c5..a35756902 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java @@ -217,7 +217,7 @@ private static class GridEntryImpl implements GridEntry { private String synchronizer = ""; - private String storageChannelType = ""; + private String resourceTypeId = ""; private GridSortingDirection sortingDirection = GridSortingDirection.ASCENDING; @@ -325,22 +325,22 @@ public void setSize(final GridSize size) { } @Override - public Optional getStorageChannelType() { - if (storageChannelType == null || storageChannelType.trim().isBlank()) { + public Optional getResourceTypeId() { + if (resourceTypeId == null || resourceTypeId.trim().isBlank()) { return Optional.empty(); } - return Optional.of(storageChannelType).map(ResourceLocation::new); + return Optional.of(resourceTypeId).map(ResourceLocation::new); } @Override - public void setStorageChannelType(final ResourceLocation storageChannelTypeId) { - this.storageChannelType = storageChannelTypeId.toString(); + public void setResourceTypeId(final ResourceLocation resourceTypeId) { + this.resourceTypeId = resourceTypeId.toString(); save(); } @Override - public void clearStorageChannelType() { - this.storageChannelType = ""; + public void clearResourceType() { + this.resourceTypeId = ""; save(); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java index aa770478a..93908e0ec 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java @@ -1,8 +1,6 @@ package com.refinedmods.refinedstorage2.platform.fabric; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.AbstractModInitializer; import com.refinedmods.refinedstorage2.platform.common.PlatformProxy; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -15,12 +13,13 @@ import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.util.ServerEventQueue; import com.refinedmods.refinedstorage2.platform.fabric.exporter.FabricStorageExporterTransferStrategyFactory; @@ -132,7 +131,6 @@ private void registerImporterTransferStrategyFactories() { createIdentifier("item"), new FabricStorageImporterTransferStrategyFactory<>( ItemStorage.SIDED, - StorageChannelTypes.ITEM, VariantUtil::ofItemVariant, resource -> resource instanceof ItemResource itemResource ? VariantUtil.toItemVariant(itemResource) : null, @@ -143,7 +141,6 @@ private void registerImporterTransferStrategyFactories() { createIdentifier("fluid"), new FabricStorageImporterTransferStrategyFactory<>( FluidStorage.SIDED, - StorageChannelTypes.FLUID, VariantUtil::ofFluidVariant, resource -> resource instanceof FluidResource fluidResource ? VariantUtil.toFluidVariant(fluidResource) : null, @@ -157,7 +154,6 @@ private void registerExporterTransferStrategyFactories() { createIdentifier("item"), new FabricStorageExporterTransferStrategyFactory<>( ItemStorage.SIDED, - StorageChannelTypes.ITEM, resource -> resource instanceof ItemResource itemResource ? VariantUtil.toItemVariant(itemResource) : null, 1 @@ -167,7 +163,6 @@ private void registerExporterTransferStrategyFactories() { createIdentifier("fluid"), new FabricStorageExporterTransferStrategyFactory<>( FluidStorage.SIDED, - StorageChannelTypes.FLUID, resource -> resource instanceof FluidResource fluidResource ? VariantUtil.toFluidVariant(fluidResource) : null, FluidConstants.BUCKET @@ -179,7 +174,6 @@ private void registerExternalStorageProviderFactories() { PlatformApi.INSTANCE.addExternalStorageProviderFactory(new InterfacePlatformExternalStorageProviderFactory()); PlatformApi.INSTANCE.addExternalStorageProviderFactory( new FabricStoragePlatformExternalStorageProviderFactory<>( - StorageChannelTypes.ITEM, ItemStorage.SIDED, VariantUtil::ofItemVariant, resource -> resource instanceof ItemResource itemResource @@ -187,7 +181,6 @@ private void registerExternalStorageProviderFactories() { )); PlatformApi.INSTANCE.addExternalStorageProviderFactory( new FabricStoragePlatformExternalStorageProviderFactory<>( - StorageChannelTypes.FLUID, FluidStorage.SIDED, VariantUtil::ofFluidVariant, resource -> resource instanceof FluidResource fluidResource diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java index d93447396..6757008a1 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/PlatformImpl.java @@ -3,11 +3,11 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.AbstractPlatform; import com.refinedmods.refinedstorage2.platform.common.Config; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.TransferManager; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.util.CustomBlockPlaceContext; import com.refinedmods.refinedstorage2.platform.fabric.grid.strategy.ItemGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.fabric.grid.view.FabricFluidGridResourceFactory; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/exporter/FabricStorageExporterTransferStrategyFactory.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/exporter/FabricStorageExporterTransferStrategyFactory.java index 5db040433..1e07454d2 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/exporter/FabricStorageExporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/exporter/FabricStorageExporterTransferStrategyFactory.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.exporter.ExporterTransferStrategyImpl; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; @@ -21,16 +20,13 @@ public class FabricStorageExporterTransferStrategyFactory implements ExporterTransferStrategyFactory { private final BlockApiLookup, Direction> lookup; - private final StorageChannelType storageChannelType; private final Function toPlatformMapper; private final long singleAmount; public FabricStorageExporterTransferStrategyFactory(final BlockApiLookup, Direction> lookup, - final StorageChannelType storageChannelType, final Function toPlatformMapper, final long singleAmount) { this.lookup = lookup; - this.storageChannelType = storageChannelType; this.toPlatformMapper = toPlatformMapper; this.singleAmount = singleAmount; } @@ -60,8 +56,8 @@ private ExporterTransferStrategyImpl create(final boolean fuzzyMode, final FabricStorageInsertableStorage insertTarget, final long transferQuota) { if (fuzzyMode) { - return new FuzzyExporterTransferStrategy(insertTarget, storageChannelType, transferQuota); + return new FuzzyExporterTransferStrategy(insertTarget, transferQuota); } - return new ExporterTransferStrategyImpl(insertTarget, storageChannelType, transferQuota); + return new ExporterTransferStrategyImpl(insertTarget, transferQuota); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridExtractionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridExtractionStrategy.java index 9f21fd410..ea2616144 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridExtractionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridExtractionStrategy.java @@ -3,16 +3,15 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.fabric.util.SimpleSingleStackStorage; import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; @@ -39,15 +38,14 @@ public class FluidGridExtractionStrategy implements GridExtractionStrategy { public FluidGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { - this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.FLUID, new PlayerActor(player)); this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); this.itemStorage = grid.getItemStorage(); } @Override - public boolean onExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public boolean onExtract(final PlatformResourceKey resource, final GridExtractMode extractMode, final boolean cursor) { if (resource instanceof FluidResource fluidResource) { diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridInsertionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridInsertionStrategy.java index 77b0a59f2..a02c50bcb 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridInsertionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/FluidGridInsertionStrategy.java @@ -6,8 +6,8 @@ import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import javax.annotation.Nullable; @@ -36,7 +36,7 @@ public FluidGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { this.containerMenu = containerMenu; - this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.FLUID, new PlayerActor(player)); this.player = player; this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridExtractionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridExtractionStrategy.java index 037660e91..b40f135fa 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridExtractionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridExtractionStrategy.java @@ -3,13 +3,12 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage; @@ -29,14 +28,13 @@ public class ItemGridExtractionStrategy implements GridExtractionStrategy { public ItemGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { - this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.ITEM, new PlayerActor(player)); this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); } @Override - public boolean onExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public boolean onExtract(final PlatformResourceKey resource, final GridExtractMode extractMode, final boolean cursor) { if (resource instanceof ItemResource itemResource) { diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridInsertionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridInsertionStrategy.java index 95f2c7813..1632bea91 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridInsertionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridInsertionStrategy.java @@ -6,8 +6,8 @@ import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; @@ -32,7 +32,7 @@ public ItemGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { this.containerMenu = containerMenu; - this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.ITEM, new PlayerActor(player)); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridScrollingStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridScrollingStrategy.java index 7f0d1ba42..7d51b15b0 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridScrollingStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/strategy/ItemGridScrollingStrategy.java @@ -4,14 +4,13 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage; @@ -31,18 +30,13 @@ public class ItemGridScrollingStrategy implements GridScrollingStrategy { public ItemGridScrollingStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { - this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.ITEM, new PlayerActor(player)); this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); } @Override - public boolean onScroll( - final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final GridScrollMode scrollMode, - final int slotIndex - ) { + public boolean onScroll(final PlatformResourceKey resource, final GridScrollMode scrollMode, final int slotIndex) { if (resource instanceof ItemResource itemResource) { final Storage playerStorage = slotIndex >= 0 ? playerInventoryStorage.getSlot(slotIndex) diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/view/FabricFluidGridResourceFactory.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/view/FabricFluidGridResourceFactory.java index 7312ea82d..21eb541e1 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/view/FabricFluidGridResourceFactory.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/grid/view/FabricFluidGridResourceFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.grid.view; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.grid.view.AbstractFluidGridResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.stream.Collectors; 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 518af0e01..0d0dd8a1d 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 @@ -4,7 +4,6 @@ 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.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; @@ -20,18 +19,15 @@ public class FabricStorageImporterTransferStrategyFactory

implements ImporterTransferStrategyFactory { private final BlockApiLookup, Direction> lookup; - private final StorageChannelType storageChannelType; private final Function fromPlatformMapper; private final Function toPlatformMapper; private final long singleAmount; public FabricStorageImporterTransferStrategyFactory(final BlockApiLookup, Direction> lookup, - final StorageChannelType storageChannelType, final Function fromPlatformMapper, final Function toPlatformMapper, final long singleAmount) { this.lookup = lookup; - this.storageChannelType = storageChannelType; this.fromPlatformMapper = fromPlatformMapper; this.toPlatformMapper = toPlatformMapper; this.singleAmount = singleAmount; @@ -52,10 +48,9 @@ public ImporterTransferStrategy create(final ServerLevel level, direction, amountOverride ); - return new ImporterTransferStrategyImpl( - source, - storageChannelType, - upgradeState.has(Items.INSTANCE.getStackUpgrade()) ? singleAmount * 64 : singleAmount - ); + final long transferQuota = upgradeState.has(Items.INSTANCE.getStackUpgrade()) + ? singleAmount * 64 + : singleAmount; + return new ImporterTransferStrategyImpl(source, transferQuota); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java index d2000826f..064d16ddb 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java @@ -2,16 +2,15 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.ClientToServerCommunications; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyType; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.UUID; @@ -24,33 +23,29 @@ public class ClientToServerCommunicationsImpl implements ClientToServerCommunications { @Override - public void sendGridExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final GridExtractMode mode, - final boolean cursor) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresent(id -> sendToServer( + public void sendGridExtract(final PlatformResourceKey resource, final GridExtractMode mode, final boolean cursor) { + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent(id -> sendToServer( PacketIds.GRID_EXTRACT, buf -> { buf.writeResourceLocation(id); GridExtractPacket.writeMode(buf, mode); buf.writeBoolean(cursor); - storageChannelType.toBuffer(resource, buf); + resource.toBuffer(buf); } )); } @Override - public void sendGridScroll(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final GridScrollMode mode, - final int slotIndex) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresent(id -> sendToServer( + public void sendGridScroll(final PlatformResourceKey resource, final GridScrollMode mode, final int slotIndex) { + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent(id -> sendToServer( PacketIds.GRID_SCROLL, buf -> { buf.writeResourceLocation(id); GridScrollPacket.writeMode(buf, mode); buf.writeInt(slotIndex); - storageChannelType.toBuffer(resource, buf); + resource.toBuffer(buf); } )); } @@ -75,7 +70,7 @@ public void sendCraftingGridRecipeTransfer(final List> recipe for (final List slotPossibilities : recipe) { buf.writeInt(slotPossibilities.size()); for (final ItemResource slotPossibility : slotPossibilities) { - PacketUtil.writeItemResource(buf, slotPossibility); + slotPossibility.toBuffer(buf); } } }); @@ -102,16 +97,14 @@ public void sendResourceSlotChange(final int slotIndex, final boolean tryAlterna }); } - @Override - public void sendResourceFilterSlotChange(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final int slotIndex) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType) + public void sendResourceFilterSlotChange(final PlatformResourceKey resource, final int slotIndex) { + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType) .ifPresent(id -> sendToServer(PacketIds.RESOURCE_FILTER_SLOT_CHANGE, buf -> { buf.writeInt(slotIndex); buf.writeResourceLocation(id); - storageChannelType.toBuffer(resource, buf); + resource.toBuffer(buf); })); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/CraftingGridRecipeTransferPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/CraftingGridRecipeTransferPacket.java index 40e57730e..4efffd0da 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/CraftingGridRecipeTransferPacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/CraftingGridRecipeTransferPacket.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import java.util.ArrayList; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridExtractPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridExtractPacket.java index ffcd80bcb..da105453e 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridExtractPacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridExtractPacket.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -24,12 +24,12 @@ public void receive(final MinecraftServer server, final FriendlyByteBuf buf, final PacketSender responseSender) { final ResourceLocation id = buf.readResourceLocation(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry() + PlatformApi.INSTANCE.getResourceTypeRegistry() .get(id) .ifPresent(type -> handle(type, buf, player, server)); } - private void handle(final PlatformStorageChannelType type, + private void handle(final ResourceType type, final FriendlyByteBuf buf, final Player player, final MinecraftServer server) { @@ -37,8 +37,8 @@ private void handle(final PlatformStorageChannelType type, if (menu instanceof GridExtractionStrategy strategy) { final GridExtractMode mode = getMode(buf.readByte()); final boolean cursor = buf.readBoolean(); - final ResourceKey resource = type.fromBuffer(buf); - server.execute(() -> strategy.onExtract(type, resource, mode, cursor)); + final PlatformResourceKey resource = type.fromBuffer(buf); + server.execute(() -> strategy.onExtract(resource, mode, cursor)); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridScrollPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridScrollPacket.java index 13a7a318e..81bb55218 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridScrollPacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridScrollPacket.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -24,12 +24,12 @@ public void receive(final MinecraftServer server, final FriendlyByteBuf buf, final PacketSender responseSender) { final ResourceLocation id = buf.readResourceLocation(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry() + PlatformApi.INSTANCE.getResourceTypeRegistry() .get(id) .ifPresent(type -> handle(type, buf, player, server)); } - private void handle(final PlatformStorageChannelType type, + private void handle(final ResourceType type, final FriendlyByteBuf buf, final Player player, final MinecraftServer server) { @@ -37,8 +37,8 @@ private void handle(final PlatformStorageChannelType type, if (menu instanceof GridScrollingStrategy strategy) { final GridScrollMode mode = getMode(buf.readByte()); final int slotIndex = buf.readInt(); - final ResourceKey resource = type.fromBuffer(buf); - server.execute(() -> strategy.onScroll(type, resource, mode, slotIndex)); + final PlatformResourceKey resource = type.fromBuffer(buf); + server.execute(() -> strategy.onScroll(resource, mode, slotIndex)); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceFilterSlotChangePacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceFilterSlotChangePacket.java index 24425e1f7..eb56e7747 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceFilterSlotChangePacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceFilterSlotChangePacket.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; import net.fabricmc.fabric.api.networking.v1.PacketSender; @@ -21,21 +21,21 @@ public void receive(final MinecraftServer server, final FriendlyByteBuf buf, final PacketSender responseSender) { final int slotIndex = buf.readInt(); - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry() - .get(storageChannelTypeId) - .ifPresent(storageChannelType -> handle(storageChannelType, buf, server, slotIndex, player)); + final ResourceLocation resourceTypeId = buf.readResourceLocation(); + PlatformApi.INSTANCE.getResourceTypeRegistry() + .get(resourceTypeId) + .ifPresent(resourceType -> handle(resourceType, buf, server, slotIndex, player)); } - private void handle(final PlatformStorageChannelType storageChannelType, + private void handle(final ResourceType resourceType, final FriendlyByteBuf buf, final MinecraftServer server, final int slotIndex, final ServerPlayer serverPlayer) { - final ResourceKey resource = storageChannelType.fromBuffer(buf); + final PlatformResourceKey resource = resourceType.fromBuffer(buf); server.execute(() -> { if (serverPlayer.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { - containerMenu.handleResourceFilterSlotUpdate(slotIndex, storageChannelType, resource); + containerMenu.handleResourceFilterSlotUpdate(slotIndex, resource); } }); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/GridUpdatePacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/GridUpdatePacket.java index 1cab95a4d..87e6a12e3 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/GridUpdatePacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/GridUpdatePacket.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; @@ -21,10 +21,10 @@ public void receive(final Minecraft client, final FriendlyByteBuf buf, final PacketSender responseSender) { final ResourceLocation id = buf.readResourceLocation(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(id).ifPresent(type -> handle(type, buf, client)); + PlatformApi.INSTANCE.getResourceTypeRegistry().get(id).ifPresent(type -> handle(type, buf, client)); } - private void handle(final PlatformStorageChannelType type, + private void handle(final ResourceType type, final FriendlyByteBuf buf, final Minecraft client) { final ResourceKey resource = type.fromBuffer(buf); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceSlotUpdatePacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceSlotUpdatePacket.java index dd742884f..19569352a 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceSlotUpdatePacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceSlotUpdatePacket.java @@ -1,9 +1,9 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.s2c; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; import java.util.function.Consumer; @@ -25,7 +25,7 @@ public void receive(final Minecraft client, final boolean present = buf.readBoolean(); if (present) { final ResourceLocation id = buf.readResourceLocation(); - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(id).ifPresent( + PlatformApi.INSTANCE.getResourceTypeRegistry().get(id).ifPresent( type -> handle(type, buf, client, slotIndex) ); } else { @@ -33,16 +33,15 @@ public void receive(final Minecraft client, } } - private void handle(final PlatformStorageChannelType type, + private void handle(final ResourceType type, final FriendlyByteBuf buf, final Minecraft client, final int slotIndex) { final ResourceKey resource = type.fromBuffer(buf); final long amount = buf.readLong(); - handle(client, containerMenu -> containerMenu.handleResourceSlotUpdate(slotIndex, new ResourceAmountTemplate( + handle(client, containerMenu -> containerMenu.handleResourceSlotUpdate(slotIndex, new ResourceAmount( resource, - amount, - type + amount ))); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java index 4ecfe5098..19c2f4644 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java @@ -1,11 +1,11 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.s2c; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.StorageInfo; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterStatus; import com.refinedmods.refinedstorage2.platform.common.support.ServerToClientCommunications; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; @@ -42,16 +42,16 @@ public void sendGridActiveness(final ServerPlayer player, final boolean active) @Override public void sendGridUpdate(final ServerPlayer player, - final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + final PlatformResourceKey resource, final long change, @Nullable final TrackedResource trackedResource) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresent(id -> sendToPlayer( + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent(id -> sendToPlayer( player, PacketIds.GRID_UPDATE, buf -> { buf.writeResourceLocation(id); - storageChannelType.toBuffer(resource, buf); + resource.toBuffer(buf); buf.writeLong(change); PacketUtil.writeTrackedResource(buf, trackedResource); } @@ -66,31 +66,27 @@ public void sendGridClear(final ServerPlayer player) { @Override public void sendResourceSlotUpdate(final ServerPlayer player, - @Nullable final ResourceAmountTemplate resourceAmount, + @Nullable final ResourceAmount resourceAmount, final int slotIndex) { sendToPlayer(player, PacketIds.RESOURCE_SLOT_UPDATE, buf -> { buf.writeInt(slotIndex); - if (resourceAmount != null) { - sendResourceSlotUpdate( - resourceAmount.getStorageChannelType(), - resourceAmount.getResource(), - resourceAmount.getAmount(), - buf - ); + if (resourceAmount != null + && resourceAmount.getResource() instanceof PlatformResourceKey platformResource) { + sendResourceSlotUpdate(platformResource, resourceAmount.getAmount(), buf); } else { buf.writeBoolean(false); } }); } - private void sendResourceSlotUpdate(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + private void sendResourceSlotUpdate(final PlatformResourceKey resource, final long amount, final FriendlyByteBuf buf) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresentOrElse(id -> { + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresentOrElse(id -> { buf.writeBoolean(true); buf.writeResourceLocation(id); - storageChannelType.toBuffer(resource, buf); + resource.toBuffer(buf); buf.writeLong(amount); }, () -> buf.writeBoolean(false)); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/CraftingGridTransferHandler.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/CraftingGridTransferHandler.java index a2d70b4cc..3b8878195 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/CraftingGridTransferHandler.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/CraftingGridTransferHandler.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei; import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.awt.Color; import java.util.List; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/DraggableStackVisitorImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/DraggableStackVisitorImpl.java index c19b02e65..f8dd525f8 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/DraggableStackVisitorImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/DraggableStackVisitorImpl.java @@ -1,8 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; @@ -38,7 +37,7 @@ public Stream getDraggableAcceptingBounds( final List bounds = new ArrayList<>(); ingredientConverter.convertToResource(value).ifPresent(resource -> { for (final ResourceSlot slot : menu.getResourceSlots()) { - if (slot.isFilter() && slot.isValid(resource.resource())) { + if (slot.isFilter() && slot.isValid(resource)) { bounds.add(BoundsProvider.ofRectangle(toRectangle(screen, slot))); } } @@ -55,7 +54,7 @@ public DraggedAcceptorResult acceptDraggedStack( final var menu = screen.getMenu(); final Object value = stack.getStack().getValue(); return ingredientConverter.convertToResource(value) - .map(resourceTemplate -> accept(context, menu, screen, resourceTemplate)) + .map(resource -> accept(context, menu, screen, resource)) .orElse(DraggedAcceptorResult.PASS); } @@ -63,18 +62,14 @@ private DraggedAcceptorResult accept( final DraggingContext> context, final AbstractResourceContainerMenu menu, final AbstractBaseScreen screen, - final ResourceTemplate resource + final PlatformResourceKey resource ) { for (final ResourceSlot slot : menu.getResourceSlots()) { final Rectangle slotBounds = toRectangle(screen, slot); if (!slotBounds.contains(context.getCurrentPosition())) { continue; } - Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotChange( - (PlatformStorageChannelType) resource.storageChannelType(), - resource.resource(), - slot.index - ); + Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotChange(resource, slot.index); return DraggedAcceptorResult.ACCEPTED; } return DraggedAcceptorResult.PASS; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/GridFocusedStackProvider.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/GridFocusedStackProvider.java index 0809e36cd..57f24807f 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/GridFocusedStackProvider.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/GridFocusedStackProvider.java @@ -1,7 +1,8 @@ package com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei; -import com.refinedmods.refinedstorage2.api.grid.view.GridResource; +import com.refinedmods.refinedstorage2.platform.api.grid.view.PlatformGridResource; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.grid.screen.AbstractGridScreen; import dev.architectury.event.CompoundEventResult; @@ -22,11 +23,15 @@ public CompoundEventResult> provide(final Screen screen, final Poi if (!(screen instanceof AbstractGridScreen gridScreen)) { return CompoundEventResult.pass(); } - final GridResource resource = gridScreen.getCurrentGridResource(); + final PlatformGridResource resource = gridScreen.getCurrentGridResource(); if (resource == null) { return CompoundEventResult.pass(); } - final Object converted = converter.convertToIngredient(resource).orElse(null); + final PlatformResourceKey underlyingResource = resource.getUnderlyingResource(); + if (underlyingResource == null) { + return CompoundEventResult.pass(); + } + final Object converted = converter.convertToIngredient(underlyingResource).orElse(null); if (converted instanceof EntryStack stack) { return CompoundEventResult.interruptTrue(stack); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/GridResourceIngredientConverter.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/GridResourceIngredientConverter.java deleted file mode 100644 index da695ae3e..000000000 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/GridResourceIngredientConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei; - -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.common.grid.view.FluidGridResource; -import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; - -import java.util.Optional; - -import dev.architectury.fluid.FluidStack; -import me.shedaniel.rei.api.common.util.EntryStacks; - -class GridResourceIngredientConverter implements IngredientConverter { - @Override - public Optional convertToResource(final Object ingredient) { - return Optional.empty(); - } - - @Override - public Optional convertToIngredient(final Object resource) { - if (resource instanceof ItemGridResource itemGridResource) { - return Optional.of(EntryStacks.of(itemGridResource.copyItemStack())); - } - if (resource instanceof FluidGridResource fluidGridResource) { - final FluidResource fluidResource = (FluidResource) fluidGridResource.getResource(); - final FluidStack fluidStack = FluidStack.create( - fluidResource.fluid(), - FluidStack.bucketAmount(), - fluidResource.tag() - ); - return Optional.of(EntryStacks.of(fluidStack)); - } - return Optional.empty(); - } -} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/IngredientConverterImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/IngredientConverterImpl.java new file mode 100644 index 000000000..454255833 --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/IngredientConverterImpl.java @@ -0,0 +1,41 @@ +package com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei; + +import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; + +import java.util.Optional; + +import dev.architectury.fluid.FluidStack; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.world.item.ItemStack; + +class IngredientConverterImpl implements IngredientConverter { + @Override + public Optional convertToResource(final Object ingredient) { + if (ingredient instanceof FluidStack fluidStack) { + return Optional.of(new FluidResource(fluidStack.getFluid(), fluidStack.getTag())); + } + if (ingredient instanceof ItemStack itemStack) { + return Optional.of(ItemResource.ofItemStack(itemStack)); + } + return Optional.empty(); + } + + @Override + public Optional convertToIngredient(final PlatformResourceKey resource) { + if (resource instanceof ItemResource itemResource) { + return Optional.of(EntryStacks.of(itemResource.toItemStack())); + } + if (resource instanceof FluidResource fluidResource) { + final FluidStack fluidStack = FluidStack.create( + fluidResource.fluid(), + FluidStack.bucketAmount(), + fluidResource.tag() + ); + return Optional.of(EntryStacks.of(fluidStack)); + } + return Optional.empty(); + } +} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java index b41b31f7c..466e8260d 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -45,8 +45,7 @@ public void registerTransferHandlers(final TransferHandlerRegistry registry) { } public static void registerIngredientConverters() { - PlatformApi.INSTANCE.registerIngredientConverter(new GridResourceIngredientConverter()); - PlatformApi.INSTANCE.registerIngredientConverter(new ResourceIngredientConverter()); + PlatformApi.INSTANCE.registerIngredientConverter(new IngredientConverterImpl()); } @Override diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/ResourceFocusedStackProvider.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/ResourceFocusedStackProvider.java index 057669972..b69667c36 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/ResourceFocusedStackProvider.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/ResourceFocusedStackProvider.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import dev.architectury.event.CompoundEventResult; @@ -22,7 +22,7 @@ public CompoundEventResult> provide(final Screen screen, final Poi if (!(screen instanceof AbstractBaseScreen baseScreen)) { return CompoundEventResult.pass(); } - final ResourceTemplate hoveredResource = baseScreen.getHoveredResource(); + final PlatformResourceKey hoveredResource = baseScreen.getHoveredResource(); if (hoveredResource == null) { return CompoundEventResult.pass(); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/ResourceIngredientConverter.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/ResourceIngredientConverter.java deleted file mode 100644 index 41f6ed950..000000000 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/ResourceIngredientConverter.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.fabric.recipemod.rei; - -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; - -import java.util.Optional; - -import dev.architectury.fluid.FluidStack; -import me.shedaniel.rei.api.common.util.EntryStacks; -import net.minecraft.world.item.ItemStack; - -class ResourceIngredientConverter implements IngredientConverter { - @Override - public Optional convertToResource(final Object ingredient) { - if (ingredient instanceof FluidStack fluidStack) { - return Optional.of(new ResourceTemplate( - new FluidResource(fluidStack.getFluid(), fluidStack.getTag()), - StorageChannelTypes.FLUID - )); - } - if (ingredient instanceof ItemStack itemStack) { - return Optional.of(new ResourceTemplate( - ItemResource.ofItemStack(itemStack), - StorageChannelTypes.ITEM - )); - } - return Optional.empty(); - } - - @Override - public Optional convertToIngredient(final Object resource) { - if (!(resource instanceof ResourceTemplate resourceTemplate)) { - return Optional.empty(); - } - if (resourceTemplate.resource() instanceof ItemResource itemResource) { - return Optional.of(EntryStacks.of(itemResource.toItemStack())); - } - if (resourceTemplate.resource() instanceof FluidResource fluidResource) { - final FluidStack fluidStack = FluidStack.create( - fluidResource.fluid(), - FluidStack.bucketAmount(), - fluidResource.tag() - ); - return Optional.of(EntryStacks.of(fluidStack)); - } - return Optional.empty(); - } -} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/externalstorage/FabricStoragePlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/externalstorage/FabricStoragePlatformExternalStorageProviderFactory.java index 67f1745f3..7c55e17ed 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/externalstorage/FabricStoragePlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/storage/externalstorage/FabricStoragePlatformExternalStorageProviderFactory.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage2.platform.fabric.storage.externalstorage; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; @@ -16,16 +15,13 @@ public class FabricStoragePlatformExternalStorageProviderFactory implements PlatformExternalStorageProviderFactory { - private final StorageChannelType theStorageChannelType; private final BlockApiLookup, Direction> lookup; private final Function fromPlatformMapper; private final Function toPlatformMapper; - public FabricStoragePlatformExternalStorageProviderFactory(final StorageChannelType storageChannelType, - final BlockApiLookup, Direction> lookup, + public FabricStoragePlatformExternalStorageProviderFactory(final BlockApiLookup, Direction> lookup, final Function fromPlatformMapper, final Function toPlatformMapper) { - this.theStorageChannelType = storageChannelType; this.lookup = lookup; this.fromPlatformMapper = fromPlatformMapper; this.toPlatformMapper = toPlatformMapper; @@ -34,11 +30,7 @@ public FabricStoragePlatformExternalStorageProviderFactory(final StorageChannelT @Override public Optional create(final ServerLevel level, final BlockPos pos, - final Direction direction, - final StorageChannelType storageChannelType) { - if (storageChannelType != theStorageChannelType) { - return Optional.empty(); - } + final Direction direction) { return Optional.of(new FabricStorageExternalStorageProvider<>( lookup, fromPlatformMapper, diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/FluidVariantFluidRenderer.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/FluidVariantFluidRenderer.java index 063b62e4b..a63ca4f1c 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/FluidVariantFluidRenderer.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/render/FluidVariantFluidRenderer.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.support.render; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.support.render.AbstractFluidRenderer; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.fabric.support.resource.VariantUtil; import java.util.HashMap; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/ResourceContainerFluidStorageAdapter.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/ResourceContainerFluidStorageAdapter.java index 150f61785..396a3875d 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/ResourceContainerFluidStorageAdapter.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/ResourceContainerFluidStorageAdapter.java @@ -1,10 +1,11 @@ package com.refinedmods.refinedstorage2.platform.fabric.support.resource; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.ArrayList; import java.util.Iterator; @@ -32,21 +33,11 @@ public ResourceContainerFluidStorageAdapter(final ResourceContainer resourceCont public long insert(final FluidVariant fluidVariant, final long maxAmount, final TransactionContext transaction) { StoragePreconditions.notBlankNotNegative(fluidVariant, maxAmount); final FluidResource fluidResource = ofFluidVariant(fluidVariant); - final long insertedSimulated = resourceContainer.insert( - StorageChannelTypes.FLUID, - fluidResource, - maxAmount, - Action.SIMULATE - ); + final long insertedSimulated = resourceContainer.insert(fluidResource, maxAmount, Action.SIMULATE); if (insertedSimulated > 0) { updateSnapshots(transaction); } - return resourceContainer.insert( - StorageChannelTypes.FLUID, - fluidResource, - maxAmount, - Action.EXECUTE - ); + return resourceContainer.insert(fluidResource, maxAmount, Action.EXECUTE); } @Override @@ -77,7 +68,7 @@ protected ResourceContainer createSnapshot() { @Override protected void readSnapshot(final ResourceContainer snapshot) { for (int i = 0; i < snapshot.size(); ++i) { - final ResourceAmountTemplate snapshotSlot = snapshot.get(i); + final ResourceAmount snapshotSlot = snapshot.get(i); if (snapshotSlot == null) { resourceContainer.remove(i); } else { @@ -95,13 +86,13 @@ private StorageViewImpl(final int index) { @Override public long extract(final FluidVariant resource, final long maxAmount, final TransactionContext transaction) { - final ResourceAmountTemplate slot = resourceContainer.get(index); - if (slot == null - || !(slot.getResource() instanceof FluidResource fluidResource) + final ResourceAmount resourceAmount = resourceContainer.get(index); + if (resourceAmount == null + || !(resourceAmount.getResource() instanceof FluidResource fluidResource) || !resource.equals(toFluidVariant(fluidResource))) { return 0; } - final long extracted = Math.min(maxAmount, slot.getAmount()); + final long extracted = Math.min(maxAmount, resourceAmount.getAmount()); if (extracted > 0) { updateSnapshots(transaction); } @@ -111,13 +102,13 @@ public long extract(final FluidVariant resource, final long maxAmount, final Tra @Override public boolean isResourceBlank() { - return resourceContainer.get(index) == null; + return resourceContainer.isEmpty(index); } @Override public FluidVariant getResource() { - final ResourceAmountTemplate slot = resourceContainer.get(index); - if (slot == null || !(slot.getResource() instanceof FluidResource fluidResource)) { + final PlatformResourceKey resource = resourceContainer.getResource(index); + if (!(resource instanceof FluidResource fluidResource)) { return FluidVariant.blank(); } return toFluidVariant(fluidResource); @@ -125,20 +116,16 @@ public FluidVariant getResource() { @Override public long getAmount() { - final ResourceAmountTemplate slot = resourceContainer.get(index); - if (slot == null) { - return 0; - } - return slot.getAmount(); + return resourceContainer.getAmount(index); } @Override public long getCapacity() { - final ResourceAmountTemplate slot = resourceContainer.get(index); - if (slot == null) { + final ResourceKey resource = resourceContainer.getResource(index); + if (resource == null) { return 0; } - return resourceContainer.getMaxAmount(slot); + return resourceContainer.getMaxAmount(resource); } } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/VariantUtil.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/VariantUtil.java index 2713c50e9..fa5c3b2f9 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/VariantUtil.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/support/resource/VariantUtil.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.support.resource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java index 8dc9f09a3..90c5f8129 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ClientModInitializer.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.forge; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; import com.refinedmods.refinedstorage2.platform.api.upgrade.AbstractUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.AbstractClientModInitializer; import com.refinedmods.refinedstorage2.platform.common.configurationcard.ConfigurationCardItemPropertyFunction; @@ -207,19 +207,19 @@ public static void onRegisterTooltipFactories(final RegisterClientTooltipCompone RegulatorUpgradeItem.RegulatorTooltipComponent.class, component -> { final ClientTooltipComponent help = HelpClientTooltipComponent.create(component.helpText()); - return component.filteredResource() == null + return component.configuredResource() == null ? help - : createRegulatorUpgradeClientTooltipComponent(component.filteredResource(), help); + : createRegulatorUpgradeClientTooltipComponent(component.configuredResource(), help); } ); } private static CompositeClientTooltipComponent createRegulatorUpgradeClientTooltipComponent( - final ResourceAmountTemplate filteredResource, + final ResourceAmount configuredResource, final ClientTooltipComponent help ) { return new CompositeClientTooltipComponent(List.of( - new ResourceClientTooltipComponent(filteredResource), + new ResourceClientTooltipComponent(configuredResource), help )); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java index 10348249b..3055b0a68 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ConfigImpl.java @@ -258,7 +258,7 @@ private class GridEntryImpl implements GridEntry { private final ModConfigSpec.BooleanValue smoothScrolling; private final ModConfigSpec.BooleanValue autoSelected; private final ModConfigSpec.ConfigValue synchronizer; - private final ModConfigSpec.ConfigValue storageChannelType; + private final ModConfigSpec.ConfigValue resourceType; private final ModConfigSpec.EnumValue sortingDirection; private final ModConfigSpec.EnumValue sortingType; private final ModConfigSpec.EnumValue size; @@ -292,9 +292,9 @@ private class GridEntryImpl implements GridEntry { synchronizer = builder .comment("The synchronization type of the Grid search box") .define("synchronizer", ""); - storageChannelType = builder - .comment("The storage channel type to be shown") - .define("storageChannelType", ""); + resourceType = builder + .comment("The resource type to be shown") + .define("resourceType", ""); sortingDirection = builder .comment("The sorting direction") .defineEnum("sortingDirection", GridSortingDirection.ASCENDING); @@ -401,21 +401,21 @@ public void setSize(final GridSize size) { } @Override - public Optional getStorageChannelType() { - if (storageChannelType == null || storageChannelType.get().trim().isBlank()) { + public Optional getResourceTypeId() { + if (resourceType == null || resourceType.get().trim().isBlank()) { return Optional.empty(); } - return Optional.of(storageChannelType.get()).map(ResourceLocation::new); + return Optional.of(resourceType.get()).map(ResourceLocation::new); } @Override - public void setStorageChannelType(final ResourceLocation storageChannelTypeId) { - this.storageChannelType.set(storageChannelTypeId.toString()); + public void setResourceTypeId(final ResourceLocation resourceTypeId) { + this.resourceType.set(resourceTypeId.toString()); } @Override - public void clearStorageChannelType() { - this.storageChannelType.set(""); + public void clearResourceType() { + this.resourceType.set(""); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java index b308117cb..7c7f53d80 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/PlatformImpl.java @@ -3,11 +3,11 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.AbstractPlatform; import com.refinedmods.refinedstorage2.platform.common.Config; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.TransferManager; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.util.CustomBlockPlaceContext; import com.refinedmods.refinedstorage2.platform.forge.grid.strategy.ItemGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.forge.grid.view.ForgeFluidGridResourceFactory; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java index d1dbf5efc..f9f457d80 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/FluidHandlerExporterTransferStrategyFactory.java @@ -8,7 +8,6 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.exporter.FuzzyExporterTransferStrategy; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import com.refinedmods.refinedstorage2.platform.forge.storage.FluidHandlerInsertableStorage; @@ -33,8 +32,8 @@ public ExporterTransferStrategy create(final ServerLevel level, final long transferQuota = (upgradeState.has(Items.INSTANCE.getStackUpgrade()) ? 64 : 1) * Platform.INSTANCE.getBucketAmount(); if (fuzzyMode) { - return new FuzzyExporterTransferStrategy(destination, StorageChannelTypes.FLUID, transferQuota); + return new FuzzyExporterTransferStrategy(destination, transferQuota); } - return new ExporterTransferStrategyImpl(destination, StorageChannelTypes.FLUID, transferQuota); + return new ExporterTransferStrategyImpl(destination, transferQuota); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java index 1a8dd3a14..1c170b677 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/exporter/ItemHandlerExporterTransferStrategyFactory.java @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.exporter.FuzzyExporterTransferStrategy; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; @@ -27,8 +26,8 @@ public ExporterTransferStrategy create(final ServerLevel level, final ItemHandlerInsertableStorage destination = new ItemHandlerInsertableStorage(coordinates, amountOverride); final int transferQuota = upgradeState.has(Items.INSTANCE.getStackUpgrade()) ? 64 : 1; if (fuzzyMode) { - return new FuzzyExporterTransferStrategy(destination, StorageChannelTypes.ITEM, transferQuota); + return new FuzzyExporterTransferStrategy(destination, transferQuota); } - return new ExporterTransferStrategyImpl(destination, StorageChannelTypes.ITEM, transferQuota); + return new ExporterTransferStrategyImpl(destination, transferQuota); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java index 0a689c10b..0e716b99a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridExtractionStrategy.java @@ -3,17 +3,16 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; -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.Storage; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import javax.annotation.Nullable; @@ -42,14 +41,13 @@ public FluidGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { this.menu = containerMenu; - this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.FLUID, new PlayerActor(player)); this.playerInventoryStorage = new PlayerMainInvWrapper(player.getInventory()); this.itemStorage = grid.getItemStorage(); } @Override - public boolean onExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public boolean onExtract(final PlatformResourceKey resource, final GridExtractMode extractMode, final boolean cursor) { if (resource instanceof FluidResource fluidResource) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java index b0433bd55..65bd05106 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/FluidGridInsertionStrategy.java @@ -6,8 +6,8 @@ import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import javax.annotation.Nullable; @@ -28,7 +28,7 @@ public class FluidGridInsertionStrategy implements GridInsertionStrategy { public FluidGridInsertionStrategy(final AbstractContainerMenu menu, final Player player, final Grid grid) { this.menu = menu; - this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.FLUID, new PlayerActor(player)); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java index 91ae89750..fc691d78a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridExtractionStrategy.java @@ -2,14 +2,13 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; @@ -26,14 +25,13 @@ public class ItemGridExtractionStrategy implements GridExtractionStrategy { public ItemGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { - this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.ITEM, new PlayerActor(player)); this.playerInventoryStorage = new PlayerMainInvWrapper(player.getInventory()); this.playerCursorItemHandler = new CursorItemHandler(containerMenu); } @Override - public boolean onExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public boolean onExtract(final PlatformResourceKey resource, final GridExtractMode extractMode, final boolean cursor) { if (resource instanceof ItemResource itemResource) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java index d14f9efe2..732d2adee 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridInsertionStrategy.java @@ -6,8 +6,8 @@ import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerExtractableStorage; @@ -18,7 +18,7 @@ import net.neoforged.neoforge.items.wrapper.InvWrapper; import net.neoforged.neoforge.items.wrapper.RangedWrapper; -import static com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource.ofItemStack; +import static com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource.ofItemStack; public class ItemGridInsertionStrategy implements GridInsertionStrategy { private final AbstractContainerMenu containerMenu; @@ -29,7 +29,7 @@ public ItemGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { this.containerMenu = containerMenu; - this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.ITEM, new PlayerActor(player)); this.playerCursorItemHandler = new CursorItemHandler(containerMenu); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java index 2b55a1eb0..2b5b88169 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/strategy/ItemGridScrollingStrategy.java @@ -3,15 +3,14 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCache; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerExtractableStorage; import com.refinedmods.refinedstorage2.platform.forge.storage.ItemHandlerInsertableStorage; @@ -33,17 +32,14 @@ public class ItemGridScrollingStrategy implements GridScrollingStrategy { public ItemGridScrollingStrategy(final AbstractContainerMenu containerMenu, final Player player, final Grid grid) { - this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); + this.gridOperations = grid.createOperations(ResourceTypes.ITEM, new PlayerActor(player)); this.playerInventory = player.getInventory(); this.playerInventoryStorage = new PlayerMainInvWrapper(playerInventory); this.playerCursorItemHandler = new CursorItemHandler(containerMenu); } @Override - public boolean onScroll(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final GridScrollMode scrollMode, - final int slotIndex) { + public boolean onScroll(final PlatformResourceKey resource, final GridScrollMode scrollMode, final int slotIndex) { if (resource instanceof ItemResource itemResource) { final IItemHandler playerStorage = slotIndex >= 0 ? new RangedWrapper(new InvWrapper(playerInventory), slotIndex, slotIndex + 1) diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java index 82e5e732f..1ab14c5d6 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/grid/view/ForgeFluidGridResourceFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.grid.view; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.grid.view.AbstractFluidGridResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import net.neoforged.fml.ModList; import net.neoforged.neoforge.fluids.FluidType; 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 e65256fee..7b3fafa52 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 @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; import com.refinedmods.refinedstorage2.platform.common.content.Items; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import net.minecraft.core.BlockPos; @@ -30,6 +29,6 @@ public ImporterTransferStrategy create(final ServerLevel level, final int transferQuota = upgradeState.has(Items.INSTANCE.getStackUpgrade()) ? FluidType.BUCKET_VOLUME * 64 : FluidType.BUCKET_VOLUME; - return new ImporterTransferStrategyImpl(source, StorageChannelTypes.FLUID, transferQuota); + return new ImporterTransferStrategyImpl(source, transferQuota); } } 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 08ab018ab..64570d9fc 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 @@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeState; import com.refinedmods.refinedstorage2.platform.common.content.Items; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import net.minecraft.core.BlockPos; @@ -27,6 +26,6 @@ public ImporterTransferStrategy create(final ServerLevel level, direction ), amountOverride); final int transferQuota = upgradeState.has(Items.INSTANCE.getStackUpgrade()) ? 64 : 1; - return new ImporterTransferStrategyImpl(source, StorageChannelTypes.ITEM, transferQuota); + return new ImporterTransferStrategyImpl(source, transferQuota); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/CraftingGridTransferHandler.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/CraftingGridTransferHandler.java index 79f183995..5c54da32e 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/CraftingGridTransferHandler.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/CraftingGridTransferHandler.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.forge.recipemod.rei; import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.awt.Color; import java.util.List; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/DraggableStackVisitorImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/DraggableStackVisitorImpl.java index 60b5d6dd7..bd3ed0f80 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/DraggableStackVisitorImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/DraggableStackVisitorImpl.java @@ -1,8 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.recipemod.rei; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; @@ -38,7 +37,7 @@ public Stream getDraggableAcceptingBounds( final List bounds = new ArrayList<>(); ingredientConverter.convertToResource(value).ifPresent(resource -> { for (final ResourceSlot slot : menu.getResourceSlots()) { - if (slot.isFilter() && slot.isValid(resource.resource())) { + if (slot.isFilter() && slot.isValid(resource)) { bounds.add(BoundsProvider.ofRectangle(toRectangle(screen, slot))); } } @@ -55,7 +54,7 @@ public DraggedAcceptorResult acceptDraggedStack( final var menu = screen.getMenu(); final Object value = stack.getStack().getValue(); return ingredientConverter.convertToResource(value) - .map(resourceTemplate -> accept(context, menu, screen, resourceTemplate)) + .map(resource -> accept(context, menu, screen, resource)) .orElse(DraggedAcceptorResult.PASS); } @@ -63,18 +62,14 @@ private DraggedAcceptorResult accept( final DraggingContext> context, final AbstractResourceContainerMenu menu, final AbstractBaseScreen screen, - final ResourceTemplate resource + final PlatformResourceKey resource ) { for (final ResourceSlot slot : menu.getResourceSlots()) { final Rectangle slotBounds = toRectangle(screen, slot); if (!slotBounds.contains(context.getCurrentPosition())) { continue; } - Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotChange( - (PlatformStorageChannelType) resource.storageChannelType(), - resource.resource(), - slot.index - ); + Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotChange(resource, slot.index); return DraggedAcceptorResult.ACCEPTED; } return DraggedAcceptorResult.PASS; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/GridFocusedStackProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/GridFocusedStackProvider.java index 0ed91efad..9d6479d42 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/GridFocusedStackProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/GridFocusedStackProvider.java @@ -1,7 +1,8 @@ package com.refinedmods.refinedstorage2.platform.forge.recipemod.rei; -import com.refinedmods.refinedstorage2.api.grid.view.GridResource; +import com.refinedmods.refinedstorage2.platform.api.grid.view.PlatformGridResource; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.grid.screen.AbstractGridScreen; import dev.architectury.event.CompoundEventResult; @@ -22,11 +23,15 @@ public CompoundEventResult> provide(final Screen screen, final Poi if (!(screen instanceof AbstractGridScreen gridScreen)) { return CompoundEventResult.pass(); } - final GridResource resource = gridScreen.getCurrentGridResource(); + final PlatformGridResource resource = gridScreen.getCurrentGridResource(); if (resource == null) { return CompoundEventResult.pass(); } - final Object converted = converter.convertToIngredient(resource).orElse(null); + final PlatformResourceKey underlyingResource = resource.getUnderlyingResource(); + if (underlyingResource == null) { + return CompoundEventResult.pass(); + } + final Object converted = converter.convertToIngredient(underlyingResource).orElse(null); if (converted instanceof EntryStack stack) { return CompoundEventResult.interruptTrue(stack); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/GridResourceIngredientConverter.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/GridResourceIngredientConverter.java deleted file mode 100644 index 08085c1cb..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/GridResourceIngredientConverter.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.recipemod.rei; - -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.common.grid.view.FluidGridResource; -import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; - -import java.util.Optional; - -import dev.architectury.fluid.FluidStack; -import me.shedaniel.rei.api.common.util.EntryStacks; - -class GridResourceIngredientConverter implements IngredientConverter { - @Override - public Optional convertToResource(final Object ingredient) { - return Optional.empty(); - } - - @Override - public Optional convertToIngredient(final Object resource) { - if (resource instanceof ItemGridResource itemGridResource) { - return Optional.of(EntryStacks.of(itemGridResource.copyItemStack())); - } - if (resource instanceof FluidGridResource fluidGridResource) { - final FluidResource fluidResource = (FluidResource) fluidGridResource.getResource(); - final FluidStack fluidStack = FluidStack.create( - fluidResource.fluid(), - FluidStack.bucketAmount(), - fluidResource.tag() - ); - return Optional.of(EntryStacks.of(fluidStack)); - } - return Optional.empty(); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/IngredientConverterImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/IngredientConverterImpl.java new file mode 100644 index 000000000..1adb1d641 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/IngredientConverterImpl.java @@ -0,0 +1,41 @@ +package com.refinedmods.refinedstorage2.platform.forge.recipemod.rei; + +import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; + +import java.util.Optional; + +import dev.architectury.fluid.FluidStack; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.world.item.ItemStack; + +class IngredientConverterImpl implements IngredientConverter { + @Override + public Optional convertToResource(final Object ingredient) { + if (ingredient instanceof FluidStack fluidStack) { + return Optional.of(new FluidResource(fluidStack.getFluid(), fluidStack.getTag())); + } + if (ingredient instanceof ItemStack itemStack) { + return Optional.of(ItemResource.ofItemStack(itemStack)); + } + return Optional.empty(); + } + + @Override + public Optional convertToIngredient(final PlatformResourceKey resource) { + if (resource instanceof ItemResource itemResource) { + return Optional.of(EntryStacks.of(itemResource.toItemStack())); + } + if (resource instanceof FluidResource fluidResource) { + final FluidStack fluidStack = FluidStack.create( + fluidResource.fluid(), + FluidStack.bucketAmount(), + fluidResource.tag() + ); + return Optional.of(EntryStacks.of(fluidStack)); + } + return Optional.empty(); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java index 285bb35ac..1e73e5325 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -39,8 +39,7 @@ public void registerScreens(final ScreenRegistry registry) { } public static void registerIngredientConverters() { - PlatformApi.INSTANCE.registerIngredientConverter(new GridResourceIngredientConverter()); - PlatformApi.INSTANCE.registerIngredientConverter(new ResourceIngredientConverter()); + PlatformApi.INSTANCE.registerIngredientConverter(new IngredientConverterImpl()); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/ResourceFocusedStackProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/ResourceFocusedStackProvider.java index 3b50a1b53..6ee58c9e3 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/ResourceFocusedStackProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/ResourceFocusedStackProvider.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.recipemod.rei; -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import dev.architectury.event.CompoundEventResult; @@ -22,7 +22,7 @@ public CompoundEventResult> provide(final Screen screen, final Poi if (!(screen instanceof AbstractBaseScreen baseScreen)) { return CompoundEventResult.pass(); } - final ResourceTemplate hoveredResource = baseScreen.getHoveredResource(); + final PlatformResourceKey hoveredResource = baseScreen.getHoveredResource(); if (hoveredResource == null) { return CompoundEventResult.pass(); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/ResourceIngredientConverter.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/ResourceIngredientConverter.java deleted file mode 100644 index 62171c428..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/ResourceIngredientConverter.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.recipemod.rei; - -import com.refinedmods.refinedstorage2.api.storage.ResourceTemplate; -import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; - -import java.util.Optional; - -import dev.architectury.fluid.FluidStack; -import me.shedaniel.rei.api.common.util.EntryStacks; -import net.minecraft.world.item.ItemStack; - -class ResourceIngredientConverter implements IngredientConverter { - @Override - public Optional convertToResource(final Object ingredient) { - if (ingredient instanceof FluidStack fluidStack) { - return Optional.of(new ResourceTemplate( - new FluidResource(fluidStack.getFluid(), fluidStack.getTag()), - StorageChannelTypes.FLUID - )); - } - if (ingredient instanceof ItemStack itemStack) { - return Optional.of(new ResourceTemplate( - ItemResource.ofItemStack(itemStack), - StorageChannelTypes.ITEM - )); - } - return Optional.empty(); - } - - @Override - public Optional convertToIngredient(final Object resource) { - if (!(resource instanceof ResourceTemplate resourceTemplate)) { - return Optional.empty(); - } - if (resourceTemplate.resource() instanceof ItemResource itemResource) { - return Optional.of(EntryStacks.of(itemResource.toItemStack())); - } - if (resourceTemplate.resource() instanceof FluidResource fluidResource) { - final FluidStack fluidStack = FluidStack.create( - fluidResource.fluid(), - FluidStack.bucketAmount(), - fluidResource.tag() - ); - return Optional.of(EntryStacks.of(fluidStack)); - } - return Optional.empty(); - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCache.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCache.java index d686f076b..28f7ed94c 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCache.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/CapabilityCache.java @@ -14,7 +14,7 @@ import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; -import static com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource.ofItemStack; +import static com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource.ofItemStack; import static com.refinedmods.refinedstorage2.platform.forge.support.resource.VariantUtil.ofFluidStack; public interface CapabilityCache { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java index 22b333baa..cfe13b84d 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerExtractableStorage.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import net.neoforged.neoforge.fluids.FluidStack; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java index e2eed5f9d..35ad156c2 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/FluidHandlerInsertableStorage.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.capability.IFluidHandler; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java index 93e7bc03c..3b0b27fb3 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ForgeHandlerUtil.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.forge.storage; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.fluids.FluidStack; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java index 8935638d2..41756c205 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerExtractableStorage.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.items.IItemHandler; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java index 1b5276e95..fe34d4d41 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/ItemHandlerInsertableStorage.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.platform.api.exporter.AmountOverride; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.items.IItemHandler; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java index b9edd5e05..b5ad12fed 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/FluidHandlerPlatformExternalStorageProviderFactory.java @@ -1,9 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import java.util.Optional; @@ -16,11 +14,7 @@ public class FluidHandlerPlatformExternalStorageProviderFactory implements Platf @Override public Optional create(final ServerLevel level, final BlockPos pos, - final Direction direction, - final StorageChannelType storageChannelType) { - if (storageChannelType != StorageChannelTypes.FLUID) { - return Optional.empty(); - } + final Direction direction) { return Optional.of(new FluidHandlerExternalStorageProvider(new CapabilityCacheImpl(level, pos, direction))); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java index 7d4e4c85a..cf1fa0c57 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/storage/externalstorage/ItemHandlerPlatformExternalStorageProviderFactory.java @@ -1,9 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.storage.externalstorage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.platform.api.storage.externalstorage.PlatformExternalStorageProviderFactory; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.storage.CapabilityCacheImpl; import java.util.Optional; @@ -16,11 +14,7 @@ public class ItemHandlerPlatformExternalStorageProviderFactory implements Platfo @Override public Optional create(final ServerLevel level, final BlockPos pos, - final Direction direction, - final StorageChannelType storageChannelType) { - if (storageChannelType != StorageChannelTypes.ITEM) { - return Optional.empty(); - } + final Direction direction) { return Optional.of(new ItemHandlerExternalStorageProvider(new CapabilityCacheImpl(level, pos, direction))); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java index e38a59076..7554e91d4 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java @@ -2,14 +2,14 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.ClientToServerCommunications; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyType; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import java.util.List; import java.util.UUID; @@ -23,13 +23,13 @@ private void sendPacket(final CustomPacketPayload packet) { } @Override - public void sendGridExtract(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public void sendGridExtract(final PlatformResourceKey resource, final GridExtractMode mode, final boolean cursor) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType) + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType) .ifPresent(id -> sendPacket(new GridExtractPacket( - storageChannelType, + resourceType, id, resource, mode, @@ -38,14 +38,14 @@ public void sendGridExtract(final PlatformStorageChannelType storageChannelType, } @Override - public void sendGridScroll(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + public void sendGridScroll(final PlatformResourceKey resource, final GridScrollMode mode, final int slotIndex) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry() - .getId(storageChannelType) + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry() + .getId(resourceType) .ifPresent(id -> sendPacket(new GridScrollPacket( - storageChannelType, + resourceType, id, resource, mode, @@ -84,14 +84,13 @@ public void sendResourceSlotChange(final int slotIndex, final boolean tryAlterna } @Override - public void sendResourceFilterSlotChange(final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, - final int slotIndex) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresent( + public void sendResourceFilterSlotChange(final PlatformResourceKey resource, final int slotIndex) { + final ResourceType resourceType = resource.getResourceType(); + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resourceType).ifPresent( id -> sendPacket(new ResourceFilterSlotChangePacket( slotIndex, resource, - storageChannelType, + resourceType, id )) ); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridRecipeTransferPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridRecipeTransferPacket.java index 45289443c..6fcd9799b 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridRecipeTransferPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/CraftingGridRecipeTransferPacket.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import java.util.ArrayList; @@ -34,7 +34,7 @@ public void write(final FriendlyByteBuf buf) { for (final List slotPossibilities : recipe) { buf.writeInt(slotPossibilities.size()); for (final ItemResource slotPossibility : slotPossibilities) { - PacketUtil.writeItemResource(buf, slotPossibility); + slotPossibility.toBuffer(buf); } } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridExtractPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridExtractPacket.java index ec0015e78..7bee58044 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridExtractPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridExtractPacket.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import net.minecraft.network.FriendlyByteBuf; @@ -13,24 +13,24 @@ import net.neoforged.neoforge.network.handling.PlayPayloadContext; public record GridExtractPacket( - PlatformStorageChannelType storageChannelType, - ResourceLocation storageChannelTypeId, - ResourceKey resource, + ResourceType resourceType, + ResourceLocation resourceTypeId, + PlatformResourceKey resource, GridExtractMode mode, boolean cursor ) implements CustomPacketPayload { public static GridExtractPacket decode(final FriendlyByteBuf buf) { - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - final PlatformStorageChannelType storageChannelType = PlatformApi.INSTANCE - .getStorageChannelTypeRegistry() - .get(storageChannelTypeId) + final ResourceLocation resourceTypeId = buf.readResourceLocation(); + final ResourceType resourceType = PlatformApi.INSTANCE + .getResourceTypeRegistry() + .get(resourceTypeId) .orElseThrow(); final GridExtractMode mode = getMode(buf.readByte()); final boolean cursor = buf.readBoolean(); - final ResourceKey resource = storageChannelType.fromBuffer(buf); + final PlatformResourceKey resource = resourceType.fromBuffer(buf); return new GridExtractPacket( - storageChannelType, - storageChannelTypeId, + resourceType, + resourceTypeId, resource, mode, cursor @@ -40,12 +40,7 @@ public static GridExtractPacket decode(final FriendlyByteBuf buf) { public static void handle(final GridExtractPacket packet, final PlayPayloadContext ctx) { ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { if (player.containerMenu instanceof GridExtractionStrategy strategy) { - strategy.onExtract( - packet.storageChannelType, - packet.resource, - packet.mode, - packet.cursor - ); + strategy.onExtract(packet.resource, packet.mode, packet.cursor); } })); } @@ -67,10 +62,10 @@ public static void writeMode(final FriendlyByteBuf buf, final GridExtractMode mo @Override public void write(final FriendlyByteBuf buf) { - buf.writeResourceLocation(storageChannelTypeId); + buf.writeResourceLocation(resourceTypeId); writeMode(buf, mode); buf.writeBoolean(cursor); - storageChannelType.toBuffer(resource, buf); + resource.toBuffer(buf); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridScrollPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridScrollPacket.java index 3eb7eac38..5c4ee0e9a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridScrollPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/GridScrollPacket.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import net.minecraft.network.FriendlyByteBuf; @@ -13,24 +13,24 @@ import net.neoforged.neoforge.network.handling.PlayPayloadContext; public record GridScrollPacket( - PlatformStorageChannelType storageChannelType, - ResourceLocation storageChannelTypeId, - ResourceKey resource, + ResourceType resourceType, + ResourceLocation resourceTypeId, + PlatformResourceKey resource, GridScrollMode mode, int slotIndex ) implements CustomPacketPayload { public static GridScrollPacket decode(final FriendlyByteBuf buf) { - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - final PlatformStorageChannelType storageChannelType = PlatformApi.INSTANCE - .getStorageChannelTypeRegistry() - .get(storageChannelTypeId) + final ResourceLocation resourceTypeId = buf.readResourceLocation(); + final ResourceType resourceType = PlatformApi.INSTANCE + .getResourceTypeRegistry() + .get(resourceTypeId) .orElseThrow(); final GridScrollMode mode = getMode(buf.readByte()); final int slotIndex = buf.readInt(); - final ResourceKey resource = storageChannelType.fromBuffer(buf); + final PlatformResourceKey resource = resourceType.fromBuffer(buf); return new GridScrollPacket( - storageChannelType, - storageChannelTypeId, + resourceType, + resourceTypeId, resource, mode, slotIndex @@ -40,12 +40,7 @@ public static GridScrollPacket decode(final FriendlyByteBuf buf) { public static void handle(final GridScrollPacket packet, final PlayPayloadContext ctx) { ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { if (player.containerMenu instanceof GridScrollingStrategy strategy) { - strategy.onScroll( - packet.storageChannelType, - packet.resource, - packet.mode, - packet.slotIndex - ); + strategy.onScroll(packet.resource, packet.mode, packet.slotIndex); } })); } @@ -69,10 +64,10 @@ private static void writeMode(final FriendlyByteBuf buf, final GridScrollMode mo @Override public void write(final FriendlyByteBuf buf) { - buf.writeResourceLocation(storageChannelTypeId); + buf.writeResourceLocation(resourceTypeId); writeMode(buf, mode); buf.writeInt(slotIndex); - storageChannelType.toBuffer(resource, buf); + resource.toBuffer(buf); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java index 18de28ccf..fc73cf246 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ResourceFilterSlotChangePacket.java @@ -1,12 +1,11 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; -import java.util.Objects; import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; @@ -14,28 +13,30 @@ import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.network.handling.PlayPayloadContext; +import static java.util.Objects.requireNonNull; + public record ResourceFilterSlotChangePacket( int slotIndex, @Nullable - ResourceKey resource, + PlatformResourceKey resource, @Nullable - PlatformStorageChannelType storageChannelType, + ResourceType resourceType, @Nullable - ResourceLocation storageChannelTypeId + ResourceLocation resourceTypeId ) implements CustomPacketPayload { public static ResourceFilterSlotChangePacket decode(final FriendlyByteBuf buf) { final int slotIndex = buf.readInt(); - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - return PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(storageChannelTypeId) - .map(storageChannelType -> decode(buf, slotIndex, storageChannelType, storageChannelTypeId)) - .orElseGet(() -> new ResourceFilterSlotChangePacket(slotIndex, null, null, storageChannelTypeId)); + final ResourceLocation resourceTypeId = buf.readResourceLocation(); + return PlatformApi.INSTANCE.getResourceTypeRegistry().get(resourceTypeId) + .map(resourceType -> decode(buf, slotIndex, resourceType, resourceTypeId)) + .orElseGet(() -> new ResourceFilterSlotChangePacket(slotIndex, null, null, resourceTypeId)); } private static ResourceFilterSlotChangePacket decode(final FriendlyByteBuf buf, final int slotIndex, - final PlatformStorageChannelType type, + final ResourceType type, final ResourceLocation typeId) { - final ResourceKey resource = type.fromBuffer(buf); + final PlatformResourceKey resource = type.fromBuffer(buf); return new ResourceFilterSlotChangePacket(slotIndex, resource, type, typeId); } @@ -43,11 +44,7 @@ public static void handle(final ResourceFilterSlotChangePacket packet, final PlayPayloadContext ctx) { ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { if (player.containerMenu instanceof AbstractResourceContainerMenu containerMenu) { - containerMenu.handleResourceFilterSlotUpdate( - packet.slotIndex, - Objects.requireNonNull(packet.storageChannelType), - Objects.requireNonNull(packet.resource) - ); + containerMenu.handleResourceFilterSlotUpdate(packet.slotIndex, requireNonNull(packet.resource)); } })); } @@ -55,8 +52,8 @@ public static void handle(final ResourceFilterSlotChangePacket packet, @Override public void write(final FriendlyByteBuf buf) { buf.writeInt(slotIndex); - buf.writeResourceLocation(Objects.requireNonNull(storageChannelTypeId)); - Objects.requireNonNull(storageChannelType).toBuffer(Objects.requireNonNull(resource), buf); + buf.writeResourceLocation(requireNonNull(resourceTypeId)); + requireNonNull(resource).toBuffer(buf); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java index de7538192..95257c1fd 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/GridUpdatePacket.java @@ -1,9 +1,9 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; @@ -16,24 +16,22 @@ import net.neoforged.neoforge.network.handling.PlayPayloadContext; public record GridUpdatePacket( - PlatformStorageChannelType storageChannelType, - ResourceLocation storageChannelTypeId, - ResourceKey resource, + ResourceLocation resourceTypeId, + PlatformResourceKey resource, long amount, @Nullable TrackedResource trackedResource ) implements CustomPacketPayload { public static GridUpdatePacket decode(final FriendlyByteBuf buf) { - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - final PlatformStorageChannelType storageChannelType = PlatformApi.INSTANCE - .getStorageChannelTypeRegistry() - .get(storageChannelTypeId) + final ResourceLocation resourceTypeId = buf.readResourceLocation(); + final ResourceType resourceType = PlatformApi.INSTANCE + .getResourceTypeRegistry() + .get(resourceTypeId) .orElseThrow(); - final ResourceKey resource = storageChannelType.fromBuffer(buf); + final PlatformResourceKey resource = resourceType.fromBuffer(buf); final long amount = buf.readLong(); final TrackedResource trackedResource = PacketUtil.readTrackedResource(buf); return new GridUpdatePacket( - storageChannelType, - storageChannelTypeId, + resourceTypeId, resource, amount, trackedResource @@ -50,8 +48,8 @@ public static void handle(final GridUpdatePacket packet, final PlayPayloadContex @Override public void write(final FriendlyByteBuf buf) { - buf.writeResourceLocation(storageChannelTypeId); - storageChannelType.toBuffer(resource, buf); + buf.writeResourceLocation(resourceTypeId); + resource.toBuffer(buf); buf.writeLong(amount); PacketUtil.writeTrackedResource(buf, trackedResource); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ResourceSlotUpdatePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ResourceSlotUpdatePacket.java index fbf32e65f..a2a1c0938 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ResourceSlotUpdatePacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ResourceSlotUpdatePacket.java @@ -1,9 +1,9 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceType; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractResourceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; @@ -16,8 +16,8 @@ public record ResourceSlotUpdatePacket( int slotIndex, - @Nullable ResourceAmountTemplate resourceAmount, - @Nullable ResourceLocation storageChannelTypeId + @Nullable ResourceAmount resourceAmount, + @Nullable ResourceLocation resourceTypeId ) implements CustomPacketPayload { public static ResourceSlotUpdatePacket decode(final FriendlyByteBuf buf) { @@ -26,19 +26,18 @@ public static ResourceSlotUpdatePacket decode(final FriendlyByteBuf buf) { if (!present) { return new ResourceSlotUpdatePacket(slotIndex, null, null); } - final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); - return PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(storageChannelTypeId).map( - storageChannelType -> decode(buf, slotIndex, storageChannelType) + final ResourceLocation resourceTypeId = buf.readResourceLocation(); + return PlatformApi.INSTANCE.getResourceTypeRegistry().get(resourceTypeId).map( + resourceType -> decode(buf, slotIndex, resourceType) ).orElseGet(() -> new ResourceSlotUpdatePacket(slotIndex, null, null)); } private static ResourceSlotUpdatePacket decode(final FriendlyByteBuf buf, final int slotIndex, - final PlatformStorageChannelType type) { - final ResourceKey resource = type.fromBuffer(buf); + final ResourceType type) { + final PlatformResourceKey resource = type.fromBuffer(buf); final long amount = buf.readLong(); - final ResourceAmountTemplate resourceAmount = new ResourceAmountTemplate(resource, amount, type); - return new ResourceSlotUpdatePacket(slotIndex, resourceAmount, null); + return new ResourceSlotUpdatePacket(slotIndex, new ResourceAmount(resource, amount), null); } public static void handle(final ResourceSlotUpdatePacket packet, @@ -53,11 +52,11 @@ public static void handle(final ResourceSlotUpdatePacket packet, @Override public void write(final FriendlyByteBuf buf) { buf.writeInt(slotIndex); - final boolean present = resourceAmount != null && storageChannelTypeId != null; + final boolean present = resourceAmount != null && resourceTypeId != null; buf.writeBoolean(present); if (present) { - buf.writeResourceLocation(storageChannelTypeId); - resourceAmount.getStorageChannelType().toBuffer(resourceAmount.getResource(), buf); + buf.writeResourceLocation(resourceTypeId); + ((PlatformResourceKey) resourceAmount.getResource()).toBuffer(buf); buf.writeLong(resourceAmount.getAmount()); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ServerToClientCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ServerToClientCommunicationsImpl.java index 01740f4ba..572261c2c 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ServerToClientCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/s2c/ServerToClientCommunicationsImpl.java @@ -1,11 +1,10 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.s2c; -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.StorageInfo; -import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.platform.api.support.resource.PlatformResourceKey; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterStatus; import com.refinedmods.refinedstorage2.platform.common.support.ServerToClientCommunications; @@ -38,15 +37,11 @@ public void sendGridActiveness(final ServerPlayer player, final boolean active) @Override public void sendGridUpdate(final ServerPlayer player, - final PlatformStorageChannelType storageChannelType, - final ResourceKey resource, + final PlatformResourceKey resource, final long change, @Nullable final TrackedResource trackedResource) { - PlatformApi.INSTANCE - .getStorageChannelTypeRegistry() - .getId(storageChannelType) + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(resource.getResourceType()) .ifPresent(id -> sendToPlayer(player, new GridUpdatePacket( - storageChannelType, id, resource, change, @@ -61,11 +56,10 @@ public void sendGridClear(final ServerPlayer player) { @Override public void sendResourceSlotUpdate(final ServerPlayer player, - @Nullable final ResourceAmountTemplate resourceAmount, + @Nullable final ResourceAmount resourceAmount, final int slotIndex) { - if (resourceAmount != null) { - PlatformApi.INSTANCE.getStorageChannelTypeRegistry() - .getId(resourceAmount.getStorageChannelType()) + if (resourceAmount != null && resourceAmount.getResource() instanceof PlatformResourceKey platformResource) { + PlatformApi.INSTANCE.getResourceTypeRegistry().getId(platformResource.getResourceType()) .ifPresent(id -> sendToPlayer(player, new ResourceSlotUpdatePacket( slotIndex, resourceAmount, diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java index 4cd49fde3..84df21784 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/render/FluidStackFluidRenderer.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.support.render; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.common.support.render.AbstractFluidRenderer; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.Collections; import java.util.HashMap; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java index 0703151c8..de24cbc94 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/ResourceContainerFluidHandlerAdapter.java @@ -1,9 +1,10 @@ package com.refinedmods.refinedstorage2.platform.forge.support.resource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceAmountTemplate; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; -import com.refinedmods.refinedstorage2.platform.common.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import javax.annotation.Nullable; @@ -28,7 +29,7 @@ public int getTanks() { @Override public FluidStack getFluidInTank(final int tank) { - final ResourceAmountTemplate resourceAmount = container.get(tank); + final ResourceAmount resourceAmount = container.get(tank); if (resourceAmount == null || !(resourceAmount.getResource() instanceof FluidResource fluidResource)) { return FluidStack.EMPTY; } @@ -37,9 +38,9 @@ public FluidStack getFluidInTank(final int tank) { @Override public int getTankCapacity(final int tank) { - final ResourceAmountTemplate resourceAmount = container.get(tank); - if (resourceAmount == null || resourceAmount.getResource() instanceof FluidResource) { - return (int) StorageChannelTypes.FLUID.getInterfaceExportLimit(); + final ResourceKey resource = container.getResource(tank); + if (resource == null || resource instanceof FluidResource) { + return (int) ResourceTypes.FLUID.getInterfaceExportLimit(); } return 0; } @@ -51,12 +52,7 @@ public boolean isFluidValid(final int tank, final FluidStack stack) { @Override public int fill(final FluidStack resource, final FluidAction action) { - return (int) container.insert( - StorageChannelTypes.FLUID, - ofFluidStack(resource), - resource.getAmount(), - toAction(action) - ); + return (int) container.insert(ofFluidStack(resource), resource.getAmount(), toAction(action)); } @Override @@ -85,8 +81,8 @@ public FluidStack drain(final int maxDrain, final FluidAction action) { @Nullable private FluidResource findExtractableFluidResource() { for (int i = 0; i < container.size(); ++i) { - final ResourceAmountTemplate resourceAmount = container.get(i); - if (resourceAmount == null || !(resourceAmount.getResource() instanceof FluidResource fluidResource)) { + final ResourceKey resource = container.getResource(i); + if (!(resource instanceof FluidResource fluidResource)) { continue; } return fluidResource; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java index 0a3cd6f8a..27367bae7 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/resource/VariantUtil.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.support.resource; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.platform.api.support.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.common.support.resource.FluidResource; import java.util.Objects; diff --git a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/filter/Filter.java b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/filter/Filter.java index f30c2612b..fd0dbb8b4 100644 --- a/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/filter/Filter.java +++ b/refinedstorage2-resource-api/src/main/java/com/refinedmods/refinedstorage2/api/resource/filter/Filter.java @@ -11,7 +11,7 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public class Filter { - private final Set templates = new HashSet<>(); + private final Set filters = new HashSet<>(); private FilterMode mode = FilterMode.BLOCK; private UnaryOperator normalizer = value -> value; @@ -27,16 +27,16 @@ public void setMode(final FilterMode mode) { this.mode = mode; } - public boolean isAllowed(final ResourceKey template) { - final ResourceKey normalized = normalizer.apply(template); + public boolean isAllowed(final ResourceKey resource) { + final ResourceKey normalized = normalizer.apply(resource); return switch (mode) { - case ALLOW -> templates.contains(normalized); - case BLOCK -> !templates.contains(normalized); + case ALLOW -> filters.contains(normalized); + case BLOCK -> !filters.contains(normalized); }; } - public void setTemplates(final Set templates) { - this.templates.clear(); - this.templates.addAll(templates.stream().map(normalizer).collect(Collectors.toSet())); + public void setFilters(final Set filters) { + this.filters.clear(); + this.filters.addAll(filters.stream().map(normalizer).collect(Collectors.toSet())); } } diff --git a/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/filter/FilterTest.java b/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/filter/FilterTest.java index a1f7c0b36..232edb367 100644 --- a/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/filter/FilterTest.java +++ b/refinedstorage2-resource-api/src/test/java/com/refinedmods/refinedstorage2/api/resource/filter/FilterTest.java @@ -49,7 +49,7 @@ void testEmptyAllowlistAllowsNone() { void testAllowlist() { // Arrange sut.setMode(FilterMode.ALLOW); - sut.setTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); // Act final boolean allowsDirt = sut.isAllowed(A); @@ -65,7 +65,7 @@ void testAllowlist() { @Test void testBlocklist() { // Arrange - sut.setTemplates(Set.of(A, B)); + sut.setFilters(Set.of(A, B)); // Act final boolean allowsDirt = sut.isAllowed(A); @@ -79,16 +79,16 @@ void testBlocklist() { } @Test - void shouldBeAbleToModifyTemplates() { + void shouldBeAbleToModifyFilters() { // Arrange - sut.setTemplates(Set.of(B)); + sut.setFilters(Set.of(B)); final boolean allowsDirt = sut.isAllowed(A); final boolean allowsStone = sut.isAllowed(B); final boolean allowsSponge = sut.isAllowed(C); // Act - sut.setTemplates(Set.of(A, C)); + sut.setFilters(Set.of(A, C)); final boolean allowsDirtAfter = sut.isAllowed(A); final boolean allowsStoneAfter = sut.isAllowed(B); @@ -114,7 +114,7 @@ void testAllowlistNormalizer() { return resource; }); sut.setMode(FilterMode.ALLOW); - sut.setTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); // Act & assert assertThat(sut.isAllowed(A)).isTrue(); @@ -132,7 +132,7 @@ void testBlocklistNormalizer() { return resource; }); sut.setMode(FilterMode.BLOCK); - sut.setTemplates(Set.of(A)); + sut.setFilters(Set.of(A)); // Act & assert assertThat(sut.isAllowed(A)).isFalse(); diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/ResourceTemplate.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/ResourceTemplate.java deleted file mode 100644 index d95cf68aa..000000000 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/ResourceTemplate.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.refinedmods.refinedstorage2.api.storage; - -import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; - -import org.apiguardian.api.API; - -/** - * A resource template adds storage channel information to a resource. - * - * @param resource the resource - * @param storageChannelType the storage channel type - */ -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.13") -public record ResourceTemplate(ResourceKey resource, StorageChannelType storageChannelType) { -} diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/StateTrackedStorage.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/StateTrackedStorage.java index c6b91f14c..7b4fd4401 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/StateTrackedStorage.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/StateTrackedStorage.java @@ -96,16 +96,6 @@ public Optional findTrackedResourceByActorType(final ResourceKe : Optional.empty(); } - public static TypedStorage of( - final TypedStorage delegate, - @Nullable final Listener listener - ) { - return new TypedStorage<>( - new StateTrackedStorage(delegate.storage(), listener), - delegate.storageChannelType() - ); - } - @FunctionalInterface public interface Listener { void onStorageStateChanged(); diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/TypedStorage.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/TypedStorage.java deleted file mode 100644 index e3ab40a5b..000000000 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/TypedStorage.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.refinedmods.refinedstorage2.api.storage; - -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; - -public record TypedStorage(S storage, StorageChannelType storageChannelType) { -} diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelType.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelType.java deleted file mode 100644 index 9de341c90..000000000 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.refinedmods.refinedstorage2.api.storage.channel; - -import org.apiguardian.api.API; - -@API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") -@FunctionalInterface -public interface StorageChannelType { - StorageChannel create(); -}