diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa2be3fc..1ca687a57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,21 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Wireless Grid +- Creative Wireless Grid + ### Changed - The Forge variant now targets NeoForge instead of Forge. +- You can now always open the Wireless Grid, even if there is no network bound or if the Wireless Grid is out of + energy. + +### Fixed + +- Fixed inactive Grid slots still rendering resources. +- Fixed being able to interact with inactive Grid. ## [2.0.0-milestone.2.14] - 2023-08-19 diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridExtractMode.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridExtractMode.java similarity index 88% rename from refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridExtractMode.java rename to refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridExtractMode.java index 1d3acdaa7..1bfe449d2 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridExtractMode.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridExtractMode.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.grid.service; +package com.refinedmods.refinedstorage2.api.grid.operations; import org.apiguardian.api.API; diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridInsertMode.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridInsertMode.java similarity index 83% rename from refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridInsertMode.java rename to refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridInsertMode.java index f709e31f2..d714701ac 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridInsertMode.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridInsertMode.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.grid.service; +package com.refinedmods.refinedstorage2.api.grid.operations; import org.apiguardian.api.API; diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridService.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperations.java similarity index 70% rename from refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridService.java rename to refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperations.java index d64d8afba..0def0f376 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridService.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperations.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.grid.service; +package com.refinedmods.refinedstorage2.api.grid.operations; import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; @@ -6,12 +6,12 @@ import org.apiguardian.api.API; /** - * The grid service is the service that the grid uses to interact with the storage network. + * Grid operations, used for grids to interact with the storage network. * * @param the resource type */ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.2") -public interface GridService { +public interface GridOperations { /** * Tries to move a resource from the network storage to the destination. * The amount being extracted depends on the extraction mode. @@ -20,7 +20,7 @@ public interface GridService { * @param extractMode the extract mode * @param destination the destination */ - void extract(T resource, GridExtractMode extractMode, InsertableStorage destination); + boolean extract(T resource, GridExtractMode extractMode, InsertableStorage destination); /** * Tries to move a resource from the source to the network storage. @@ -30,5 +30,5 @@ public interface GridService { * @param insertMode the insertion mode * @param source the source */ - void insert(T resource, GridInsertMode insertMode, ExtractableStorage source); + boolean insert(T resource, GridInsertMode insertMode, ExtractableStorage source); } diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceImpl.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperationsImpl.java similarity index 73% rename from refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceImpl.java rename to refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperationsImpl.java index 5eaf38de1..8100984e8 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceImpl.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/GridOperationsImpl.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.grid.service; +package com.refinedmods.refinedstorage2.api.grid.operations; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.Actor; @@ -12,7 +12,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.2") -public class GridServiceImpl implements GridService { +public class GridOperationsImpl implements GridOperations { private final StorageChannel storageChannel; private final Actor actor; private final ToLongFunction maxAmountProvider; @@ -20,15 +20,15 @@ public class GridServiceImpl implements GridService { /** * @param storageChannel the storage channel to act on - * @param actor the actor performing the grid interactions + * @param actor the actor performing the grid operations * @param maxAmountProvider provider for the maximum amount of a given resource * @param singleAmount amount that needs to be extracted when using * {@link GridInsertMode#SINGLE_RESOURCE} or {@link GridExtractMode#SINGLE_RESOURCE} */ - public GridServiceImpl(final StorageChannel storageChannel, - final Actor actor, - final ToLongFunction maxAmountProvider, - final long singleAmount) { + public GridOperationsImpl(final StorageChannel storageChannel, + final Actor actor, + final ToLongFunction maxAmountProvider, + final long singleAmount) { this.storageChannel = storageChannel; this.actor = actor; this.maxAmountProvider = maxAmountProvider; @@ -36,12 +36,13 @@ public GridServiceImpl(final StorageChannel storageChannel, } @Override - public void extract(final T resource, final GridExtractMode extractMode, final InsertableStorage destination) { + public boolean extract(final T resource, final GridExtractMode extractMode, + final InsertableStorage destination) { final long amount = getExtractableAmount(resource, extractMode); if (amount == 0) { - return; + return false; } - TransferHelper.transfer(resource, amount, actor, storageChannel, destination, storageChannel); + return TransferHelper.transfer(resource, amount, actor, storageChannel, destination, storageChannel) > 0; } private long getExtractableAmount(final T resource, final GridExtractMode extractMode) { @@ -65,11 +66,11 @@ private long adjustExtractableAmountAccordingToExtractMode(final GridExtractMode } @Override - public void insert(final T resource, final GridInsertMode insertMode, final ExtractableStorage source) { + public boolean insert(final T resource, final GridInsertMode insertMode, final ExtractableStorage source) { final long amount = switch (insertMode) { case ENTIRE_RESOURCE -> maxAmountProvider.applyAsLong(resource); case SINGLE_RESOURCE -> singleAmount; }; - TransferHelper.transfer(resource, amount, actor, source, storageChannel, null); + return TransferHelper.transfer(resource, amount, actor, source, storageChannel, null) > 0; } } diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/package-info.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/package-info.java similarity index 77% rename from refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/package-info.java rename to refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/package-info.java index 5d73e2f33..f469b2dd1 100644 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/package-info.java +++ b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/operations/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.api.grid.service; +package com.refinedmods.refinedstorage2.api.grid.operations; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceFactory.java b/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceFactory.java deleted file mode 100644 index ee01a95bc..000000000 --- a/refinedstorage2-grid-api/src/main/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceFactory.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.refinedmods.refinedstorage2.api.grid.service; - -import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; - -import java.util.function.ToLongFunction; - -import org.apiguardian.api.API; - -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") -public interface GridServiceFactory { - GridService create( - StorageChannelType storageChannelType, - Actor actor, - ToLongFunction maxAmountProvider, - long singleAmount - ); -} diff --git a/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceImplTest.java b/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/service/GridOperationsImplTest.java similarity index 88% rename from refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceImplTest.java rename to refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/service/GridOperationsImplTest.java index fc81eddc5..9bf3e05e0 100644 --- a/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/service/GridServiceImplTest.java +++ b/refinedstorage2-grid-api/src/test/java/com/refinedmods/refinedstorage2/api/grid/service/GridOperationsImplTest.java @@ -1,6 +1,9 @@ package com.refinedmods.refinedstorage2.api.grid.service; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperationsImpl; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; @@ -19,16 +22,16 @@ import static org.assertj.core.api.Assertions.assertThat; -class GridServiceImplTest { +class GridOperationsImplTest { private static final long MAX_COUNT = 15; private StorageChannel storageChannel; - private GridServiceImpl sut; + private GridOperationsImpl sut; @BeforeEach void setUp() { storageChannel = new StorageChannelImpl<>(); - sut = new GridServiceImpl<>(storageChannel, GridActor.INSTANCE, r -> MAX_COUNT, 1); + sut = new GridOperationsImpl<>(storageChannel, GridActor.INSTANCE, r -> MAX_COUNT, 1); } @Nested @@ -44,9 +47,11 @@ void shouldInsertIntoDestination(final GridInsertMode insertMode) { storageChannel.addSource(destination); // Act - sut.insert("A", insertMode, source); + final boolean success = sut.insert("A", insertMode, source); // Assert + assertThat(success).isTrue(); + final long expectedAmount = switch (insertMode) { case ENTIRE_RESOURCE -> MAX_COUNT; case SINGLE_RESOURCE -> 1; @@ -74,9 +79,10 @@ void shouldNotInsertIntoDestinationWhenResourceIsNotPresentInSource(final GridIn storageChannel.addSource(destination); // Act - sut.insert("A", insertMode, source); + final boolean success = sut.insert("A", insertMode, source); // Assert + assertThat(success).isFalse(); assertThat(storageChannel.getAll()).isEmpty(); assertThat(source.getAll()).isEmpty(); assertThat(storageChannel.findTrackedResourceByActorType("A", GridActor.class)).isEmpty(); @@ -94,9 +100,10 @@ void shouldNotInsertIntoDestinationWhenNoSpaceIsPresentInDestination(final GridI storageChannel.insert("A", 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.insert("A", insertMode, source); + final boolean success = sut.insert("A", insertMode, source); // Assert + assertThat(success).isFalse(); assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount<>("A", 100) ); @@ -120,9 +127,10 @@ void shouldInsertIntoDestinationWithRemainder() { storageChannel.insert("A", 100 - MAX_COUNT + 1, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.insert("A", GridInsertMode.ENTIRE_RESOURCE, source); + final boolean success = sut.insert("A", GridInsertMode.ENTIRE_RESOURCE, source); // Assert + assertThat(success).isTrue(); assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount<>("A", 100) ); @@ -163,9 +171,10 @@ public long extract(final String resource, storageChannel.insert("A", 100 - MAX_COUNT + 1, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.insert("A", GridInsertMode.ENTIRE_RESOURCE, source); + final boolean success = sut.insert("A", GridInsertMode.ENTIRE_RESOURCE, source); // Assert + assertThat(success).isFalse(); assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount<>("A", 100 - MAX_COUNT + 1) ); @@ -189,9 +198,11 @@ void shouldExtractFromSourceToDestination(final GridExtractMode extractMode) { storageChannel.insert("A", 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.extract("A", extractMode, destination); + final boolean success = sut.extract("A", extractMode, destination); // Assert + assertThat(success).isTrue(); + final long expectedExtracted = switch (extractMode) { case ENTIRE_RESOURCE -> MAX_COUNT; case HALF_RESOURCE -> MAX_COUNT / 2; @@ -220,9 +231,10 @@ void shouldNotExtractFromSourceWhenResourceIsNotPresentInSource(final GridExtrac storageChannel.addSource(source); // Act - sut.extract("A", extractMode, destination); + final boolean success = sut.extract("A", extractMode, destination); // Assert + assertThat(success).isFalse(); assertThat(storageChannel.getAll()).isEmpty(); assertThat(destination.getAll()).isEmpty(); assertThat(storageChannel.findTrackedResourceByActorType("A", GridActor.class)).isNotPresent(); @@ -240,9 +252,10 @@ void shouldNotExtractFromSourceIfThereIsNoSpaceInDestination(final GridExtractMo storageChannel.insert("A", 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.extract("A", extractMode, destination); + final boolean success = sut.extract("A", extractMode, destination); // Assert + assertThat(success).isFalse(); assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount<>("A", 100) ); @@ -265,9 +278,10 @@ void shouldExtractEntireResourceFromSourceToDestinationIfResourceIsLessThanMaxCo storageChannel.insert("A", MAX_COUNT - 1, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.extract("A", GridExtractMode.ENTIRE_RESOURCE, destination); + final boolean success = sut.extract("A", GridExtractMode.ENTIRE_RESOURCE, destination); // Assert + assertThat(success).isTrue(); assertThat(storageChannel.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount<>("A", MAX_COUNT - 1) @@ -288,9 +302,10 @@ void shouldExtractEntireResourceWithRemainderFromSourceToDestinationIfThereIsNot storageChannel.insert("A", 100, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.extract("A", GridExtractMode.ENTIRE_RESOURCE, destination); + final boolean success = sut.extract("A", GridExtractMode.ENTIRE_RESOURCE, destination); // Assert + assertThat(success).isTrue(); assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount<>("A", 100 - MAX_COUNT + 1) ); @@ -316,9 +331,10 @@ void shouldExtractSingleAmountIfResourceHasSingleAmountWhenExtractingHalfResourc storageChannel.insert("A", 1, Action.EXECUTE, EmptyActor.INSTANCE); // Act - sut.extract("A", GridExtractMode.HALF_RESOURCE, destination); + final boolean success = sut.extract("A", GridExtractMode.HALF_RESOURCE, destination); // Assert + assertThat(success).isTrue(); assertThat(storageChannel.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount<>("A", 1) diff --git a/refinedstorage2-network-api/build.gradle b/refinedstorage2-network-api/build.gradle index 7e5b45359..1190d4beb 100644 --- a/refinedstorage2-network-api/build.gradle +++ b/refinedstorage2-network-api/build.gradle @@ -9,6 +9,7 @@ dependencies { implementation project(':refinedstorage2-core-api') implementation project(':refinedstorage2-resource-api') implementation project(':refinedstorage2-storage-api') + implementation project(':refinedstorage2-grid-api') } enableJavadoc() 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 54443e624..e5d67684f 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,9 +1,12 @@ package com.refinedmods.refinedstorage2.api.network.component; +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; @@ -13,4 +16,6 @@ public interface StorageNetworkComponent extends NetworkComponent { StorageChannel getStorageChannel(StorageChannelType type); boolean hasSource(Predicate> matcher); + + List> getResources(StorageChannelType type, Class actorType); } 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 80bbc17e9..13e98a7fd 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,11 +3,14 @@ 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.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.Collection; +import java.util.List; import java.util.Map; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -84,4 +87,14 @@ public boolean hasSource(final Predicate> matcher) { } 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<>( + resourceAmount, + storageChannel.findTrackedResourceByActorType(resourceAmount.getResource(), actorType).orElse(null) + )).toList(); + } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java index 14dfd52ad..bc97f4261 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNode.java @@ -1,55 +1,24 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.grid; import com.refinedmods.refinedstorage2.api.grid.GridWatcher; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; -import com.refinedmods.refinedstorage2.api.grid.service.GridServiceFactory; -import com.refinedmods.refinedstorage2.api.grid.service.GridServiceImpl; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode; -import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; 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.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.ToLongFunction; import javax.annotation.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static java.util.Objects.requireNonNull; -public class GridNetworkNode extends AbstractNetworkNode implements GridServiceFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(GridNetworkNode.class); - - private final Collection> storageChannelTypes; - private final Map watchers = new HashMap<>(); +public class GridNetworkNode extends AbstractNetworkNode { private final long energyUsage; + private final GridWatchers watchers; public GridNetworkNode(final long energyUsage, final Collection> storageChannelTypes) { this.energyUsage = energyUsage; - this.storageChannelTypes = storageChannelTypes; - } - - private StorageChannel getStorageChannel(final StorageChannelType type) { - if (network == null) { - throw new IllegalStateException("Network must be present to retrieve storage channel"); - } - return network.getComponent(StorageNetworkComponent.class).getStorageChannel(type); - } - - public List> getResources(final StorageChannelType type, - final Class actorType) { - final StorageChannel storageChannel = getStorageChannel(type); - return storageChannel.getAll().stream().map(resourceAmount -> new GridResource<>( - resourceAmount, - storageChannel.findTrackedResourceByActorType(resourceAmount.getResource(), actorType).orElse(null) - )).toList(); + this.watchers = new GridWatchers(storageChannelTypes); } @Override @@ -58,80 +27,27 @@ public long getEnergyUsage() { } public void addWatcher(final GridWatcher watcher, final Class actorType) { - if (watchers.containsKey(watcher)) { - throw new IllegalArgumentException("Watcher is already registered"); - } - final GridWatcherRegistration registration = new GridWatcherRegistration(watcher, actorType); - attachAll(registration); - watchers.put(watcher, registration); - LOGGER.info("Added watcher {}, new count is {}", watcher, watchers.size()); - } - - private void attachAll(final GridWatcherRegistration registration) { - storageChannelTypes.forEach(storageChannelType -> attach(registration, storageChannelType)); - } - - private void attach(final GridWatcherRegistration registration, - final StorageChannelType storageChannelType) { - LOGGER.info("Attaching {} to {}", registration, storageChannelType); - registration.attach(getStorageChannel(storageChannelType), storageChannelType); + watchers.addWatcher(watcher, actorType, requireNonNull(network)); } public void removeWatcher(final GridWatcher watcher) { - final GridWatcherRegistration registration = watchers.get(watcher); - if (registration == null) { - throw new IllegalArgumentException("Watcher is not registered"); - } - detachAll(registration); - watchers.remove(watcher); - LOGGER.info("Removed watcher {}, remaining {}", watcher, watchers.size()); - } - - private void detachAll(final GridWatcherRegistration registration) { - storageChannelTypes.forEach(storageChannelType -> detach(registration, storageChannelType)); - } - - private void detach(final GridWatcherRegistration registration, - final StorageChannelType storageChannelType) { - LOGGER.info("Detaching {} from {}", registration, storageChannelType); - registration.detach(getStorageChannel(storageChannelType), storageChannelType); + watchers.removeWatcher(watcher, requireNonNull(network)); } @Override protected void onActiveChanged(final boolean newActive) { super.onActiveChanged(newActive); - watchers.keySet().forEach(watcher -> watcher.onActiveChanged(newActive)); + watchers.activeChanged(newActive); } @Override public void setNetwork(@Nullable final Network network) { - LOGGER.info("Network has changed to {}, detaching {} watchers", network, watchers.size()); if (this.network != null) { - watchers.values().forEach(this::detachAll); + watchers.detachAll(this.network); } super.setNetwork(network); if (this.network != null) { - watchers.forEach((watcher, registration) -> { - watcher.onNetworkChanged(); - attachAll(registration); - }); + watchers.attachAll(this.network); } } - - @Override - public GridService create( - final StorageChannelType storageChannelType, - final Actor actor, - final ToLongFunction maxAmountProvider, - final long singleAmount - ) { - final StorageChannel storageChannel = getStorageChannel(storageChannelType); - return new GridServiceImpl<>(storageChannel, actor, maxAmountProvider, singleAmount); - } - - public record GridResource( - ResourceAmount resourceAmount, - @Nullable TrackedResource trackedResource - ) { - } } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatchers.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatchers.java new file mode 100644 index 000000000..1c2da61a2 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridWatchers.java @@ -0,0 +1,96 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.grid; + +import com.refinedmods.refinedstorage2.api.grid.GridWatcher; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +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.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GridWatchers { + public static final Logger LOGGER = LoggerFactory.getLogger(GridWatchers.class); + + private final Collection> storageChannelTypes; + private final Map watchers = new HashMap<>(); + + public GridWatchers(final Collection> storageChannelTypes) { + this.storageChannelTypes = storageChannelTypes; + } + + private StorageChannel getStorageChannel(final Network network, final StorageChannelType type) { + return network.getComponent(StorageNetworkComponent.class).getStorageChannel(type); + } + + public void addWatcher( + final GridWatcher watcher, + final Class actorType, + final Network network + ) { + if (watchers.containsKey(watcher)) { + throw new IllegalArgumentException("Watcher is already registered"); + } + final GridWatcherRegistration registration = new GridWatcherRegistration(watcher, actorType); + attachAll(registration, network); + watchers.put(watcher, registration); + LOGGER.info("Added watcher {}, new count is {}", watcher, watchers.size()); + } + + public void attachAll(final Network network) { + watchers.forEach((watcher, registration) -> { + watcher.onNetworkChanged(); + attachAll(registration, network); + }); + } + + private void attachAll(final GridWatcherRegistration registration, final Network network) { + storageChannelTypes.forEach(storageChannelType -> attach(registration, storageChannelType, network)); + } + + private void attach( + final GridWatcherRegistration registration, + final StorageChannelType storageChannelType, + final Network network + ) { + LOGGER.info("Attaching {} to {}", registration, storageChannelType); + registration.attach(getStorageChannel(network, storageChannelType), storageChannelType); + } + + public void removeWatcher(final GridWatcher watcher, final Network network) { + final GridWatcherRegistration registration = watchers.get(watcher); + if (registration == null) { + throw new IllegalArgumentException("Watcher is not registered"); + } + detachAll(registration, network); + watchers.remove(watcher); + LOGGER.info("Removed watcher {}, remaining {}", watcher, watchers.size()); + } + + public void detachAll(final Network network) { + LOGGER.info("Detaching {} watchers", watchers.size()); + watchers.values().forEach(w -> detachAll(w, network)); + } + + private void detachAll(final GridWatcherRegistration registration, final Network network) { + storageChannelTypes.forEach(storageChannelType -> detach(registration, storageChannelType, network)); + } + + private void detach( + final GridWatcherRegistration registration, + final StorageChannelType storageChannelType, + final Network network + ) { + LOGGER.info("Detaching {} from {}", registration, storageChannelType); + registration.detach(getStorageChannel(network, storageChannelType), storageChannelType); + } + + public void activeChanged(final boolean active) { + watchers.keySet().forEach(watcher -> watcher.onActiveChanged(active)); + } +} 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 1794daf67..22b4d45a6 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 @@ -7,12 +7,16 @@ import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; 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; import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.Collection; import java.util.HashSet; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -111,4 +115,33 @@ void testHasSource() { assertThat(found).isTrue(); assertThat(found2).isFalse(); } + + @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); + + // Act + final List> resources = sut.getResources( + NetworkTestFixtures.STORAGE_CHANNEL_TYPE, + EmptyActor.class + ); + + // Assert + assertThat(resources).usingRecursiveFieldByFieldElementComparator().containsExactly( + new TrackedResourceAmount<>( + new ResourceAmount<>("A", 100), + new TrackedResource("Empty", 2L) + ), + new TrackedResourceAmount<>( + new ResourceAmount<>("B", 200), + new TrackedResource("Empty", 2L) + ) + ); + } } 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 8a387dba1..76c337178 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 @@ -2,10 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.GridWatcher; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; @@ -22,9 +19,6 @@ import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.util.FakeActor; -import java.util.Collection; -import java.util.List; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -66,27 +60,6 @@ void testInitialState() { assertThat(sut.getEnergyUsage()).isEqualTo(5); } - @Test - void shouldRetrieveResources() { - // Act - final List> resources = sut.getResources( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - EmptyActor.class - ); - - // Assert - assertThat(resources).usingRecursiveFieldByFieldElementComparator().containsExactly( - new GridNetworkNode.GridResource<>( - new ResourceAmount<>("A", 100), - new TrackedResource("Empty", 2L) - ), - new GridNetworkNode.GridResource<>( - new ResourceAmount<>("B", 200), - new TrackedResource("Empty", 2L) - ) - ); - } - @Test void shouldNotifyWatchersOfActivenessChanges() { // Arrange @@ -207,43 +180,4 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( verifyNoMoreInteractions(watcher); } - - @Test - void shouldCreateService( - @InjectNetworkStorageChannel final StorageChannel networkStorage - ) { - // Arrange - final GridService service = sut.create( - NetworkTestFixtures.STORAGE_CHANNEL_TYPE, - FakeActor.INSTANCE, - r -> 5L, - 1 - ); - - final InMemoryStorageImpl source = new InMemoryStorageImpl<>(); - source.insert("Z", 10, Action.EXECUTE, EmptyActor.INSTANCE); - - // Act - service.insert("Z", GridInsertMode.SINGLE_RESOURCE, source); - final Collection> afterSingle = networkStorage - .getAll() - .stream() - .map(ra -> new ResourceAmount<>(ra.getResource(), ra.getAmount())) - .toList(); - - service.insert("Z", GridInsertMode.ENTIRE_RESOURCE, source); - final Collection> afterEntire = networkStorage - .getAll() - .stream() - .map(ra -> new ResourceAmount<>(ra.getResource(), ra.getAmount())) - .toList(); - - // Assert - assertThat(afterSingle).usingRecursiveFieldByFieldElementComparator().contains( - new ResourceAmount<>("Z", 1) - ); - assertThat(afterEntire).usingRecursiveFieldByFieldElementComparator().contains( - new ResourceAmount<>("Z", 6) - ); - } } 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 17ac75f30..64524468d 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 @@ -1,13 +1,12 @@ package com.refinedmods.refinedstorage2.platform.api; import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; -import com.refinedmods.refinedstorage2.api.grid.service.GridServiceFactory; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHint; @@ -18,7 +17,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerHelper; +import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; @@ -49,7 +48,7 @@ public interface PlatformApi { StorageRepository getStorageRepository(Level level); - StorageContainerHelper getStorageContainerHelper(); + StorageContainerItemHelper getStorageContainerItemHelper(); PlatformRegistry> getStorageChannelTypeRegistry(); @@ -85,7 +84,7 @@ public interface PlatformApi { GridInsertionStrategy createGridInsertionStrategy(AbstractContainerMenu containerMenu, Player player, - GridServiceFactory gridServiceFactory); + Grid grid); void addGridInsertionStrategyFactory(GridInsertionStrategyFactory insertionStrategyFactory); @@ -95,14 +94,13 @@ GridInsertionStrategy createGridInsertionStrategy(AbstractContainerMenu containe GridExtractionStrategy createGridExtractionStrategy(AbstractContainerMenu containerMenu, Player player, - GridServiceFactory gridServiceFactory, - Storage itemStorage); + Grid grid); void addGridExtractionStrategyFactory(GridExtractionStrategyFactory extractionStrategyFactory); GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containerMenu, Player player, - GridServiceFactory gridServiceFactory); + Grid grid); void addGridScrollingStrategyFactory(GridScrollingStrategyFactory scrollingStrategyFactory); 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 351748608..f370f3ff1 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 @@ -1,13 +1,12 @@ package com.refinedmods.refinedstorage2.platform.api; import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; -import com.refinedmods.refinedstorage2.api.grid.service.GridServiceFactory; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionHint; @@ -18,7 +17,7 @@ import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.grid.GridSynchronizer; import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter; -import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerHelper; +import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; @@ -63,8 +62,8 @@ public StorageRepository getStorageRepository(final Level level) { } @Override - public StorageContainerHelper getStorageContainerHelper() { - return ensureLoaded().getStorageContainerHelper(); + public StorageContainerItemHelper getStorageContainerItemHelper() { + return ensureLoaded().getStorageContainerItemHelper(); } @Override @@ -152,8 +151,8 @@ public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final @Override public GridInsertionStrategy createGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final GridServiceFactory gridServiceFactory) { - return ensureLoaded().createGridInsertionStrategy(containerMenu, player, gridServiceFactory); + final Grid grid) { + return ensureLoaded().createGridInsertionStrategy(containerMenu, player, grid); } @Override @@ -174,9 +173,8 @@ public GridInsertionHints getGridInsertionHints() { @Override public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final GridServiceFactory gridServiceFactory, - final Storage itemStorage) { - return ensureLoaded().createGridExtractionStrategy(containerMenu, player, gridServiceFactory, itemStorage); + final Grid grid) { + return ensureLoaded().createGridExtractionStrategy(containerMenu, player, grid); } @Override @@ -187,8 +185,8 @@ public void addGridExtractionStrategyFactory(final GridExtractionStrategyFactory @Override public GridScrollingStrategy createGridScrollingStrategy(final AbstractContainerMenu containerMenu, final Player player, - final GridServiceFactory gridServiceFactory) { - return ensureLoaded().createGridScrollingStrategy(containerMenu, player, gridServiceFactory); + final Grid grid) { + return ensureLoaded().createGridScrollingStrategy(containerMenu, player, grid); } @Override 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 new file mode 100644 index 000000000..3248a1016 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/Grid.java @@ -0,0 +1,29 @@ +package com.refinedmods.refinedstorage2.platform.api.grid; + +import com.refinedmods.refinedstorage2.api.grid.GridWatcher; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +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.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; + +import java.util.List; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.0") +public interface Grid { + void addWatcher(GridWatcher watcher, Class actorType); + + void removeWatcher(GridWatcher watcher); + + Storage getItemStorage(); + + boolean isActive(); + + List> getResources(StorageChannelType type, Class actorType); + + GridOperations createOperations(PlatformStorageChannelType storageChannelType, Actor actor); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategy.java index df59fcc81..e29436908 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategy.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.api.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import org.apiguardian.api.API; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategyFactory.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategyFactory.java index c15fa1986..877fb4f60 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategyFactory.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridExtractionStrategyFactory.java @@ -1,8 +1,5 @@ package com.refinedmods.refinedstorage2.platform.api.grid; -import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; - import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import org.apiguardian.api.API; @@ -10,10 +7,5 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") @FunctionalInterface public interface GridExtractionStrategyFactory { - GridExtractionStrategy create( - AbstractContainerMenu containerMenu, - Player player, - PlatformGridServiceFactory gridServiceFactory, - Storage itemStorage - ); + GridExtractionStrategy create(AbstractContainerMenu containerMenu, Player player, Grid grid); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategy.java index 49915b25f..0d5d01618 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategy.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.api.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import org.apiguardian.api.API; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategyFactory.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategyFactory.java index cf04338da..2bcf1db77 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategyFactory.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridInsertionStrategyFactory.java @@ -7,9 +7,5 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") @FunctionalInterface public interface GridInsertionStrategyFactory { - GridInsertionStrategy create( - AbstractContainerMenu containerMenu, - Player player, - PlatformGridServiceFactory gridServiceFactory - ); + GridInsertionStrategy create(AbstractContainerMenu containerMenu, Player player, Grid grid); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridScrollingStrategyFactory.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridScrollingStrategyFactory.java index 47596e0f9..2ce809ea7 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridScrollingStrategyFactory.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/GridScrollingStrategyFactory.java @@ -7,9 +7,5 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") @FunctionalInterface public interface GridScrollingStrategyFactory { - GridScrollingStrategy create( - AbstractContainerMenu containerMenu, - Player player, - PlatformGridServiceFactory gridServiceFactory - ); + GridScrollingStrategy create(AbstractContainerMenu containerMenu, Player player, Grid grid); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java index 09e47ed3b..92ef6a334 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.api.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import java.util.List; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridServiceFactory.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridServiceFactory.java deleted file mode 100644 index 9e5d30c3f..000000000 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridServiceFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.api.grid; - -import com.refinedmods.refinedstorage2.api.grid.service.GridService; -import com.refinedmods.refinedstorage2.api.grid.service.GridServiceFactory; -import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; - -import org.apiguardian.api.API; - -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") -public interface PlatformGridServiceFactory extends GridServiceFactory { - GridService createForItem(Actor actor); - - GridService createForFluid(Actor actor); -} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractStorageContainerItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractStorageContainerItem.java index 2b18688f8..42109c34a 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractStorageContainerItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/AbstractStorageContainerItem.java @@ -26,12 +26,12 @@ // TODO: Tags/ore dict in recipes @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public abstract class AbstractStorageContainerItem extends Item implements StorageContainerItem { - protected final StorageContainerHelper helper; + protected final StorageContainerItemHelper helper; private final StorageChannelType type; protected AbstractStorageContainerItem(final Properties properties, final StorageChannelType type, - final StorageContainerHelper helper) { + final StorageContainerItemHelper helper) { super(properties); this.type = type; this.helper = helper; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/StorageContainerHelper.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/StorageContainerItemHelper.java similarity index 97% rename from refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/StorageContainerHelper.java rename to refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/StorageContainerItemHelper.java index d69b5a77d..4121a6b9b 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/StorageContainerHelper.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/StorageContainerItemHelper.java @@ -19,7 +19,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.5") -public interface StorageContainerHelper { +public interface StorageContainerItemHelper { Optional> resolve(StorageRepository storageRepository, ItemStack stack); void set(StorageRepository storageRepository, ItemStack stack, Storage storage); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/AbstractStorageContainerBlockItem.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/AbstractStorageContainerBlockItem.java index 828382572..928d8b643 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/AbstractStorageContainerBlockItem.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/item/block/AbstractStorageContainerBlockItem.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.api.item.block; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerHelper; +import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import java.util.List; @@ -24,12 +24,12 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.4") public abstract class AbstractStorageContainerBlockItem extends BlockItem { - protected final StorageContainerHelper helper; + protected final StorageContainerItemHelper helper; protected AbstractStorageContainerBlockItem( final Block block, final Properties properties, - final StorageContainerHelper helper + final StorageContainerItemHelper helper ) { super(block, properties); this.helper = helper; 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 index 7a30b980c..666e9d079 100644 --- 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 @@ -1,7 +1,10 @@ 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.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; @@ -49,4 +52,6 @@ public interface PlatformStorageChannelType extends StorageChannelType { default long getInterfaceExportLimit(T resource) { return 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 c8d7bf777..b5a709626 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 @@ -3,6 +3,8 @@ import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.GridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.WirelessGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.internal.resource.FluidResourceRendering; import com.refinedmods.refinedstorage2.platform.common.internal.resource.ItemResourceRendering; @@ -32,8 +34,9 @@ public abstract class AbstractClientModInitializer { protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getDiskDrive(), DiskDriveScreen::new); - registration.register(Menus.INSTANCE.getGrid(), GridScreen::new); + registration.register(Menus.INSTANCE.getGrid(), GridScreen::new); registration.register(Menus.INSTANCE.getCraftingGrid(), CraftingGridScreen::new); + registration.register(Menus.INSTANCE.getWirelessGrid(), GridScreen::new); registration.register(Menus.INSTANCE.getController(), ControllerScreen::new); registration.register(Menus.INSTANCE.getItemStorage(), ItemStorageBlockScreen::new); registration.register(Menus.INSTANCE.getFluidStorage(), FluidStorageBlockScreen::new); 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 e7c070ae4..5c64e28ef 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 @@ -45,6 +45,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.detector.DetectorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.CraftingGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.GridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.WirelessGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ExternalStorageContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.FluidStorageBlockContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.ItemStorageBlockContainerMenu; @@ -71,6 +72,7 @@ import com.refinedmods.refinedstorage2.platform.common.item.RegulatorUpgradeItem; import com.refinedmods.refinedstorage2.platform.common.item.SimpleItem; import com.refinedmods.refinedstorage2.platform.common.item.SimpleUpgradeItem; +import com.refinedmods.refinedstorage2.platform.common.item.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.item.WrenchItem; import com.refinedmods.refinedstorage2.platform.common.item.block.FluidStorageBlockBlockItem; import com.refinedmods.refinedstorage2.platform.common.item.block.ItemStorageBlockBlockItem; @@ -85,6 +87,7 @@ import net.minecraft.sounds.SoundEvent; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -116,6 +119,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SILICON; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_BLOCK; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_HOUSING; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WIRELESS_GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WRENCH; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.forFluidStorageBlock; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.forFluidStorageDisk; @@ -231,7 +235,9 @@ protected final void registerBlocks( protected final void registerItems( final RegistryCallback callback, - final Supplier regulatorUpgradeItemSupplier + final Supplier regulatorUpgradeItemSupplier, + final Supplier wirelessGridItemSupplier, + final Supplier creativeWirelessGridItemSupplier ) { registerSimpleItems(callback); Blocks.INSTANCE.getGrid().registerItems(callback); @@ -247,6 +253,11 @@ protected final void registerItems( Blocks.INSTANCE.getDestructor().registerItems(callback, Items.INSTANCE::addDestructor); registerStorageItems(callback); registerUpgrades(callback, regulatorUpgradeItemSupplier); + Items.INSTANCE.setWirelessGrid(callback.register(ContentIds.WIRELESS_GRID, wirelessGridItemSupplier)); + Items.INSTANCE.setCreativeWirelessGrid(callback.register( + ContentIds.CREATIVE_WIRELESS_GRID, + creativeWirelessGridItemSupplier + )); } private void registerSimpleItems(final RegistryCallback callback) { @@ -501,6 +512,10 @@ protected final void registerMenus(final RegistryCallback> callback, CRAFTING_GRID, () -> menuTypeFactory.create(CraftingGridContainerMenu::new) )); + Menus.INSTANCE.setWirelessGrid(callback.register( + WIRELESS_GRID, + () -> menuTypeFactory.create(WirelessGridContainerMenu::new) + )); Menus.INSTANCE.setItemStorage(callback.register( ITEM_STORAGE_BLOCK, () -> menuTypeFactory.create(ItemStorageBlockContainerMenu::new) @@ -563,4 +578,8 @@ protected final void registerRecipeSerializers(final RegistryCallback gridInsertionStrategyFactories = new ArrayList<>(); private final GridInsertionHintsImpl gridInsertionHints = new GridInsertionHintsImpl( new ItemGridInsertionHint(), @@ -145,8 +142,8 @@ public StorageRepository getStorageRepository(final Level level) { } @Override - public StorageContainerHelper getStorageContainerHelper() { - return storageContainerHelper; + public StorageContainerItemHelper getStorageContainerItemHelper() { + return storageContainerItemHelper; } private StorageRepositoryImpl createStorageRepository(final CompoundTag tag) { @@ -250,20 +247,17 @@ public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final @Override public GridInsertionStrategy createGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final GridServiceFactory gridServiceFactory) { - final PlatformGridServiceFactory platformGridServiceFactory = new PlatformGridServiceFactoryImpl( - gridServiceFactory - ); + final Grid grid) { return new CompositeGridInsertionStrategy( Platform.INSTANCE.getDefaultGridInsertionStrategyFactory().create( containerMenu, player, - platformGridServiceFactory + grid ), gridInsertionStrategyFactories.stream().map(f -> f.create( containerMenu, player, - platformGridServiceFactory + grid )).toList() ); } @@ -286,14 +280,10 @@ public GridInsertionHints getGridInsertionHints() { @Override public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final GridServiceFactory gridServiceFactory, - final Storage itemStorage) { - final PlatformGridServiceFactory platformGridServiceFactory = new PlatformGridServiceFactoryImpl( - gridServiceFactory - ); + final Grid grid) { final List strategies = gridExtractionStrategyFactories .stream() - .map(f -> f.create(containerMenu, player, platformGridServiceFactory, itemStorage)) + .map(f -> f.create(containerMenu, player, grid)) .toList(); return new CompositeGridExtractionStrategy(strategies); } @@ -306,13 +296,10 @@ public void addGridExtractionStrategyFactory(final GridExtractionStrategyFactory @Override public GridScrollingStrategy createGridScrollingStrategy(final AbstractContainerMenu containerMenu, final Player player, - final GridServiceFactory gridServiceFactory) { - final PlatformGridServiceFactory platformGridServiceFactory = new PlatformGridServiceFactoryImpl( - gridServiceFactory - ); + final Grid grid) { final List strategies = gridScrollingStrategyFactories .stream() - .map(f -> f.create(containerMenu, player, platformGridServiceFactory)) + .map(f -> f.create(containerMenu, player, grid)) .toList(); return new CompositeGridScrollingStrategy(strategies); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractStorageBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractStorageBlock.java index 35a5b3287..7bf6b4629 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractStorageBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/AbstractStorageBlock.java @@ -65,7 +65,7 @@ private void apply(final ItemStack stack, final AbstractStorageBlockBlockEntity< final UUID storageId = storageBlockEntity.getStorageId(); if (storageId != null) { LOGGER.debug("Transferred storage {} at {} to stack", storageId, storageBlockEntity.getBlockPos()); - PlatformApi.INSTANCE.getStorageContainerHelper().setId(stack, storageId); + PlatformApi.INSTANCE.getStorageContainerItemHelper().setId(stack, storageId); } else { LOGGER.warn("Storage block {} has no associated storage ID!", storageBlockEntity.getBlockPos()); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java index 4f45fd2f0..0c252a86d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/AbstractGridBlockEntity.java @@ -1,36 +1,32 @@ package com.refinedmods.refinedstorage2.platform.common.block.entity.grid; import com.refinedmods.refinedstorage2.api.grid.GridWatcher; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.container.NetworkNodeContainerPriorities; import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode; 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.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.registry.PlatformRegistry; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; -import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import java.util.List; import java.util.Objects; import net.minecraft.core.BlockPos; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -public abstract class AbstractGridBlockEntity - extends AbstractInternalNetworkNodeContainerBlockEntity - implements ExtendedMenuProvider { - private final PlatformRegistry> storageChannelTypeRegistry; - +public abstract class AbstractGridBlockEntity extends AbstractInternalNetworkNodeContainerBlockEntity + implements Grid, MenuProvider { protected AbstractGridBlockEntity(final BlockEntityType type, final BlockPos pos, final BlockState state, @@ -39,47 +35,43 @@ protected AbstractGridBlockEntity(final BlockEntityType getItemStorage() { + @Override + public List> getResources(final StorageChannelType type, + final Class actorType) { return Objects.requireNonNull(getNode().getNetwork()) .getComponent(StorageNetworkComponent.class) - .getStorageChannel(StorageChannelTypes.ITEM); + .getResources(type, actorType); } @Override - public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { - buf.writeBoolean(getNode().isActive()); - final List> types = storageChannelTypeRegistry.getAll(); - buf.writeInt(types.size()); - types.forEach(type -> writeStorageChannel(type, buf)); + public GridOperations createOperations(final PlatformStorageChannelType storageChannelType, + final Actor actor) { + final StorageChannel storageChannel = Objects.requireNonNull(getNode().getNetwork()) + .getComponent(StorageNetworkComponent.class) + .getStorageChannel(storageChannelType); + return storageChannelType.createGridOperations(storageChannel, actor); } - private void writeStorageChannel(final PlatformStorageChannelType storageChannelType, - final FriendlyByteBuf buf) { - final ResourceLocation id = storageChannelTypeRegistry.getId(storageChannelType).orElseThrow(); - buf.writeResourceLocation(id); - final List> resources = getNode().getResources( - storageChannelType, - PlayerActor.class - ); - buf.writeInt(resources.size()); - resources.forEach(resource -> writeGridResource(storageChannelType, resource, buf)); + @Override + public boolean isActive() { + return getNode().isActive(); } - private void writeGridResource(final PlatformStorageChannelType storageChannelType, - final GridNetworkNode.GridResource resource, - final FriendlyByteBuf buf) { - storageChannelType.toBuffer(resource.resourceAmount().getResource(), buf); - buf.writeLong(resource.resourceAmount().getAmount()); - PacketUtil.writeTrackedResource(buf, resource.trackedResource()); + @Override + public Storage getItemStorage() { + return Objects.requireNonNull(getNode().getNetwork()) + .getComponent(StorageNetworkComponent.class) + .getStorageChannel(StorageChannelTypes.ITEM); } + @Override public void addWatcher(final GridWatcher watcher, final Class actorType) { getNode().addWatcher(watcher, actorType); } + @Override public void removeWatcher(final GridWatcher watcher) { getNode().removeWatcher(watcher); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java index 81408ea0d..733451ef6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/CraftingGridBlockEntity.java @@ -8,6 +8,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.CraftingGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; @@ -22,7 +23,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.ResultContainer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; @@ -104,9 +104,9 @@ public Component getDisplayName() { return createTranslation("block", "crafting_grid"); } - @Nullable @Override - public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + @Nullable + public AbstractGridContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { return new CraftingGridContainerMenu(syncId, inventory, this); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java index f0d2bca8c..702ac5de2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/grid/GridBlockEntity.java @@ -1,6 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.block.entity.grid; import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.GridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -10,7 +11,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.block.state.BlockState; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @@ -25,9 +25,9 @@ public Component getDisplayName() { return createTranslation("block", "grid"); } - @Nullable @Override - public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + @Nullable + public AbstractGridContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { return new GridContainerMenu(syncId, inventory, this); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/grid/AbstractGridBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/grid/AbstractGridBlock.java index 81dbf09ba..27aa3852c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/grid/AbstractGridBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/grid/AbstractGridBlock.java @@ -1,18 +1,25 @@ package com.refinedmods.refinedstorage2.platform.common.block.grid; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.common.block.AbstractDirectionalBlock; import com.refinedmods.refinedstorage2.platform.common.block.BlockConstants; import com.refinedmods.refinedstorage2.platform.common.block.BlockItemProvider; import com.refinedmods.refinedstorage2.platform.common.block.ColorableBlock; import com.refinedmods.refinedstorage2.platform.common.block.direction.BiDirectionType; import com.refinedmods.refinedstorage2.platform.common.block.direction.DirectionType; +import com.refinedmods.refinedstorage2.platform.common.menu.GridExtendedMenuProvider; import com.refinedmods.refinedstorage2.platform.common.util.BiDirection; +import net.minecraft.core.BlockPos; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.MenuProvider; import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; @@ -61,4 +68,18 @@ public DyeColor getColor() { public boolean canAlwaysConnect() { return true; } + + @Override + @SuppressWarnings("deprecation") + public MenuProvider getMenuProvider(final BlockState state, final Level level, final BlockPos pos) { + final BlockEntity blockEntity = level.getBlockEntity(pos); + if (blockEntity instanceof Grid grid && blockEntity instanceof MenuProvider menuProvider) { + return new GridExtendedMenuProvider( + grid, + PlatformApi.INSTANCE.getStorageChannelTypeRegistry(), + menuProvider + ); + } + return null; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java index 0120e3f42..e503cf6dd 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractBaseContainerMenu.java @@ -33,6 +33,10 @@ protected AbstractBaseContainerMenu(final MenuType type, final int syncId) { this.transferManager = Platform.INSTANCE.createTransferManager(this); } + public boolean hasProperty(final PropertyType type) { + return propertyMap.containsKey(type); + } + @SuppressWarnings("unchecked") public ClientProperty getProperty(final PropertyType type) { return (ClientProperty) propertyMap.get(type); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java index a8f54c3d7..71f13a5c4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/AbstractGridContainerMenu.java @@ -1,10 +1,10 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.grid; import com.refinedmods.refinedstorage2.api.grid.GridWatcher; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.api.grid.query.GridQueryParserException; import com.refinedmods.refinedstorage2.api.grid.query.GridQueryParserImpl; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.grid.view.GridSortingDirection; import com.refinedmods.refinedstorage2.api.grid.view.GridView; @@ -13,6 +13,7 @@ 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; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.GridResourceAttributeKeys; @@ -24,11 +25,7 @@ import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.Config; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.block.entity.grid.AbstractGridBlockEntity; import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractBaseContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ClientProperty; -import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; -import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ServerProperty; import com.refinedmods.refinedstorage2.platform.common.internal.grid.ClientGridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.common.internal.grid.ClientGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.common.internal.grid.ClientGridScrollingStrategy; @@ -37,7 +34,6 @@ import com.refinedmods.refinedstorage2.platform.common.internal.grid.view.CompositeGridResourceFactory; import com.refinedmods.refinedstorage2.platform.common.screen.grid.GridSearchBox; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; -import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; import com.refinedmods.refinedstorage2.query.lexer.LexerTokenMappings; import com.refinedmods.refinedstorage2.query.parser.ParserOperatorMappings; @@ -76,7 +72,7 @@ public abstract class AbstractGridContainerMenu extends AbstractBaseContainerMen private final Inventory playerInventory; private final GridView view; @Nullable - private AbstractGridBlockEntity grid; + private Grid grid; private GridInsertionStrategy insertionStrategy; private GridExtractionStrategy extractionStrategy; @@ -104,8 +100,6 @@ protected AbstractGridContainerMenu( this.playerInventory = playerInventory; - registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); - this.active = buf.readBoolean(); final GridViewBuilder viewBuilder = createViewBuilder(); @@ -135,18 +129,12 @@ protected AbstractGridContainerMenu( final MenuType menuType, final int syncId, final Inventory playerInventory, - final AbstractGridBlockEntity grid + final Grid grid ) { super(menuType, syncId); this.view = createViewBuilder().build(); - registerProperty(new ServerProperty<>( - PropertyTypes.REDSTONE_MODE, - grid::getRedstoneMode, - grid::setRedstoneMode - )); - this.playerInventory = playerInventory; this.grid = grid; this.grid.addWatcher(this, PlayerActor.class); @@ -309,18 +297,17 @@ private void initStrategies() { this.insertionStrategy = PlatformApi.INSTANCE.createGridInsertionStrategy( this, playerInventory.player, - Objects.requireNonNull(grid).getNode() + Objects.requireNonNull(grid) ); this.extractionStrategy = PlatformApi.INSTANCE.createGridExtractionStrategy( this, playerInventory.player, - Objects.requireNonNull(grid).getNode(), - grid.getItemStorage() + Objects.requireNonNull(grid) ); this.scrollingStrategy = PlatformApi.INSTANCE.createGridScrollingStrategy( this, playerInventory.player, - Objects.requireNonNull(grid).getNode() + Objects.requireNonNull(grid) ); } @@ -402,6 +389,9 @@ public void toggleStorageChannelType() { @Override public boolean onInsert(final GridInsertMode insertMode, final boolean tryAlternatives) { + if (grid != null && !grid.isActive()) { + return false; + } return insertionStrategy.onInsert(insertMode, tryAlternatives); } @@ -410,6 +400,9 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelT final T resource, final GridExtractMode extractMode, final boolean cursor) { + if (grid != null && !grid.isActive()) { + return false; + } return extractionStrategy.onExtract(storageChannelType, resource, extractMode, cursor); } @@ -418,6 +411,9 @@ public boolean onScroll(final PlatformStorageChannelType storageChannelTy final T resource, final GridScrollMode scrollMode, final int slotIndex) { + if (grid != null && !grid.isActive()) { + return false; + } return scrollingStrategy.onScroll(storageChannelType, resource, scrollMode, slotIndex); } @@ -428,7 +424,7 @@ public boolean onTransfer(final int slotIndex) { @Override public ItemStack quickMoveStack(final Player playerEntity, final int slotIndex) { - if (!playerEntity.level().isClientSide()) { + if (!playerEntity.level().isClientSide() && grid != null && grid.isActive()) { final Slot slot = getSlot(slotIndex); if (slot.hasItem()) { insertionStrategy.onTransfer(slot.index); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/CraftingGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/CraftingGridContainerMenu.java index 748032bfd..d7bec2098 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/CraftingGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/CraftingGridContainerMenu.java @@ -4,8 +4,12 @@ import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.block.entity.grid.CraftingGridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ServerProperty; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.internal.grid.view.ItemGridResource; +import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; import java.util.ArrayList; import java.util.HashSet; @@ -39,6 +43,7 @@ public CraftingGridContainerMenu(final int syncId, final Inventory playerInvento this.source = new ClientCraftingGridSource(); this.player = playerInventory.player; addSlots(0); + registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } public CraftingGridContainerMenu(final int syncId, @@ -48,6 +53,11 @@ public CraftingGridContainerMenu(final int syncId, this.source = new CraftingGridSourceImpl(grid); this.player = playerInventory.player; addSlots(0); + registerProperty(new ServerProperty<>( + PropertyTypes.REDSTONE_MODE, + grid::getRedstoneMode, + grid::setRedstoneMode + )); } public void setActivenessListener(@Nullable final Consumer activenessListener) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/GridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/GridContainerMenu.java index 1648a3cad..f51e0d5b6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/GridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/GridContainerMenu.java @@ -1,7 +1,11 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.grid; import com.refinedmods.refinedstorage2.platform.common.block.entity.grid.GridBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ServerProperty; import com.refinedmods.refinedstorage2.platform.common.content.Menus; +import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; @@ -10,10 +14,16 @@ public class GridContainerMenu extends AbstractGridContainerMenu { public GridContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getGrid(), syncId, playerInventory, buf); addSlots(0); + registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } public GridContainerMenu(final int syncId, final Inventory playerInventory, final GridBlockEntity grid) { super(Menus.INSTANCE.getGrid(), syncId, playerInventory, grid); addSlots(0); + registerProperty(new ServerProperty<>( + PropertyTypes.REDSTONE_MODE, + grid::getRedstoneMode, + grid::setRedstoneMode + )); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/WirelessGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/WirelessGridContainerMenu.java new file mode 100644 index 000000000..ab5c5a9cc --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/grid/WirelessGridContainerMenu.java @@ -0,0 +1,25 @@ +package com.refinedmods.refinedstorage2.platform.common.containermenu.grid; + +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; +import com.refinedmods.refinedstorage2.platform.common.content.Menus; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; + +public class WirelessGridContainerMenu extends AbstractGridContainerMenu { + public WirelessGridContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { + super(Menus.INSTANCE.getWirelessGrid(), syncId, playerInventory, buf); + this.disabledPlayerInventorySlot = PlayerSlotReference.of(buf); + addSlots(0); + } + + public WirelessGridContainerMenu(final int syncId, + final Inventory playerInventory, + final Grid grid, + final PlayerSlotReference slotReference) { + super(Menus.INSTANCE.getWirelessGrid(), syncId, playerInventory, grid); + this.disabledPlayerInventorySlot = slotReference; + addSlots(0); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java index ce53b49a8..4b7850122 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentIds.java @@ -42,6 +42,8 @@ public final class ContentIds { public static final ResourceLocation DETECTOR = createIdentifier("detector"); public static final ResourceLocation DESTRUCTOR = createIdentifier("destructor"); public static final ResourceLocation CONSTRUCTOR = createIdentifier("constructor"); + public static final ResourceLocation WIRELESS_GRID = createIdentifier("wireless_grid"); + public static final ResourceLocation CREATIVE_WIRELESS_GRID = createIdentifier("creative_wireless_grid"); private ContentIds() { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java index aeae6eebf..3feb4311d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/ContentNames.java @@ -5,19 +5,18 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public final class ContentNames { - private static final String BLOCK_CATEGORY = "block"; - - public static final MutableComponent CABLE = createTranslation(BLOCK_CATEGORY, "cable"); - public static final MutableComponent GRID = createTranslation(BLOCK_CATEGORY, "grid"); - public static final MutableComponent CRAFTING_GRID = createTranslation(BLOCK_CATEGORY, "crafting_grid"); - public static final MutableComponent DETECTOR = createTranslation(BLOCK_CATEGORY, "detector"); - public static final MutableComponent IMPORTER = createTranslation(BLOCK_CATEGORY, "importer"); - public static final MutableComponent EXPORTER = createTranslation(BLOCK_CATEGORY, "exporter"); - public static final MutableComponent EXTERNAL_STORAGE = createTranslation(BLOCK_CATEGORY, "external_storage"); - public static final MutableComponent CONSTRUCTOR = createTranslation(BLOCK_CATEGORY, "constructor"); - public static final MutableComponent DESTRUCTOR = createTranslation(BLOCK_CATEGORY, "destructor"); - public static final MutableComponent CONTROLLER = createTranslation(BLOCK_CATEGORY, "controller"); - public static final MutableComponent CREATIVE_CONTROLLER = createTranslation(BLOCK_CATEGORY, "creative_controller"); + public static final MutableComponent CABLE = createTranslation("block", "cable"); + public static final MutableComponent GRID = createTranslation("block", "grid"); + public static final MutableComponent CRAFTING_GRID = createTranslation("block", "crafting_grid"); + public static final MutableComponent DETECTOR = createTranslation("block", "detector"); + public static final MutableComponent IMPORTER = createTranslation("block", "importer"); + public static final MutableComponent EXPORTER = createTranslation("block", "exporter"); + public static final MutableComponent EXTERNAL_STORAGE = createTranslation("block", "external_storage"); + public static final MutableComponent CONSTRUCTOR = createTranslation("block", "constructor"); + public static final MutableComponent DESTRUCTOR = createTranslation("block", "destructor"); + public static final MutableComponent CONTROLLER = createTranslation("block", "controller"); + public static final MutableComponent CREATIVE_CONTROLLER = createTranslation("block", "creative_controller"); + public static final MutableComponent WIRELESS_GRID = createTranslation("item", "wireless_grid"); private ContentNames() { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java index 35dcd9eb0..d4e9fff53 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/CreativeModeTabItems.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.content; +import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.item.ProcessorItem; @@ -8,79 +9,87 @@ import java.util.function.Consumer; import java.util.function.Supplier; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; public final class CreativeModeTabItems { private CreativeModeTabItems() { } - public static void append(final Consumer consumer) { + public static void append(final Consumer consumer) { appendBlocks(consumer); appendItems(consumer); } - private static void appendBlocks(final Consumer consumer) { - Items.INSTANCE.getAllControllers().stream().map(Supplier::get).forEach(consumer); - Items.INSTANCE.getCables().stream().map(Supplier::get).forEach(consumer); - Items.INSTANCE.getImporters().stream().map(Supplier::get).forEach(consumer); - Items.INSTANCE.getExporters().stream().map(Supplier::get).forEach(consumer); - Items.INSTANCE.getExternalStorages().stream().map(Supplier::get).forEach(consumer); - Items.INSTANCE.getConstructors().stream().map(Supplier::get).forEach(consumer); - Items.INSTANCE.getDestructors().stream().map(Supplier::get).forEach(consumer); - consumer.accept(Blocks.INSTANCE.getDiskDrive()); + private static void appendBlocks(final Consumer consumer) { + final Consumer itemConsumer = item -> consumer.accept(new ItemStack(item)); + Items.INSTANCE.getAllControllers().stream().map(Supplier::get).forEach(itemConsumer); + Items.INSTANCE.getCables().stream().map(Supplier::get).forEach(itemConsumer); + Items.INSTANCE.getImporters().stream().map(Supplier::get).forEach(itemConsumer); + Items.INSTANCE.getExporters().stream().map(Supplier::get).forEach(itemConsumer); + Items.INSTANCE.getExternalStorages().stream().map(Supplier::get).forEach(itemConsumer); + Items.INSTANCE.getConstructors().stream().map(Supplier::get).forEach(itemConsumer); + Items.INSTANCE.getDestructors().stream().map(Supplier::get).forEach(itemConsumer); + itemConsumer.accept(Blocks.INSTANCE.getDiskDrive()); appendBlockColors(consumer, Blocks.INSTANCE.getGrid()); appendBlockColors(consumer, Blocks.INSTANCE.getCraftingGrid()); - Items.INSTANCE.getDetectors().stream().map(Supplier::get).forEach(consumer); - consumer.accept(Blocks.INSTANCE.getInterface()); - Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> consumer.accept( + Items.INSTANCE.getDetectors().stream().map(Supplier::get).forEach(itemConsumer); + itemConsumer.accept(Blocks.INSTANCE.getInterface()); + Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> itemConsumer.accept( Blocks.INSTANCE.getItemStorageBlock(variant) )); - Arrays.stream(FluidStorageType.Variant.values()).forEach(variant -> consumer.accept( + Arrays.stream(FluidStorageType.Variant.values()).forEach(variant -> itemConsumer.accept( Blocks.INSTANCE.getFluidStorageBlock(variant) )); - consumer.accept(Blocks.INSTANCE.getMachineCasing()); - consumer.accept(Blocks.INSTANCE.getQuartzEnrichedIronBlock()); + itemConsumer.accept(Blocks.INSTANCE.getMachineCasing()); + itemConsumer.accept(Blocks.INSTANCE.getQuartzEnrichedIronBlock()); } - private static void appendBlockColors(final Consumer consumer, final BlockColorMap map) { - map.values().forEach(consumer); + private static void appendBlockColors(final Consumer consumer, final BlockColorMap map) { + map.values().forEach(block -> consumer.accept(new ItemStack(block))); } - private static void appendItems(final Consumer consumer) { - consumer.accept(Items.INSTANCE.getQuartzEnrichedIron()); - consumer.accept(Items.INSTANCE.getSilicon()); - consumer.accept(Items.INSTANCE.getProcessorBinding()); - consumer.accept(Items.INSTANCE.getWrench()); + private static void appendItems(final Consumer consumer) { + final Consumer itemConsumer = item -> consumer.accept(new ItemStack(item)); + itemConsumer.accept(Items.INSTANCE.getQuartzEnrichedIron()); + itemConsumer.accept(Items.INSTANCE.getSilicon()); + itemConsumer.accept(Items.INSTANCE.getProcessorBinding()); + itemConsumer.accept(Items.INSTANCE.getWrench()); - Arrays.stream(ProcessorItem.Type.values()).map(Items.INSTANCE::getProcessor).forEach(consumer); + Arrays.stream(ProcessorItem.Type.values()).map(Items.INSTANCE::getProcessor).forEach(itemConsumer); - consumer.accept(Items.INSTANCE.getConstructionCore()); - consumer.accept(Items.INSTANCE.getDestructionCore()); + itemConsumer.accept(Items.INSTANCE.getConstructionCore()); + itemConsumer.accept(Items.INSTANCE.getDestructionCore()); Arrays.stream(ItemStorageType.Variant.values()) .filter(variant -> variant != ItemStorageType.Variant.CREATIVE) .map(Items.INSTANCE::getItemStoragePart) - .forEach(consumer); + .forEach(itemConsumer); Arrays.stream(FluidStorageType.Variant.values()) .filter(variant -> variant != FluidStorageType.Variant.CREATIVE) .map(Items.INSTANCE::getFluidStoragePart) - .forEach(consumer); + .forEach(itemConsumer); - Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> consumer.accept( + Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> itemConsumer.accept( Items.INSTANCE.getItemStorageDisk(variant) )); - Arrays.stream(FluidStorageType.Variant.values()).forEach(variant -> consumer.accept( + Arrays.stream(FluidStorageType.Variant.values()).forEach(variant -> itemConsumer.accept( Items.INSTANCE.getFluidStorageDisk(variant) )); - consumer.accept(Items.INSTANCE.getStorageHousing()); + itemConsumer.accept(Items.INSTANCE.getStorageHousing()); - consumer.accept(Items.INSTANCE.getUpgrade()); - consumer.accept(Items.INSTANCE.getSpeedUpgrade()); - consumer.accept(Items.INSTANCE.getStackUpgrade()); - consumer.accept(Items.INSTANCE.getFortune1Upgrade()); - consumer.accept(Items.INSTANCE.getFortune2Upgrade()); - consumer.accept(Items.INSTANCE.getFortune3Upgrade()); - consumer.accept(Items.INSTANCE.getSilkTouchUpgrade()); - consumer.accept(Items.INSTANCE.getRegulatorUpgrade()); + itemConsumer.accept(Items.INSTANCE.getUpgrade()); + itemConsumer.accept(Items.INSTANCE.getSpeedUpgrade()); + itemConsumer.accept(Items.INSTANCE.getStackUpgrade()); + itemConsumer.accept(Items.INSTANCE.getFortune1Upgrade()); + itemConsumer.accept(Items.INSTANCE.getFortune2Upgrade()); + itemConsumer.accept(Items.INSTANCE.getFortune3Upgrade()); + itemConsumer.accept(Items.INSTANCE.getSilkTouchUpgrade()); + itemConsumer.accept(Items.INSTANCE.getRegulatorUpgrade()); + itemConsumer.accept(Items.INSTANCE.getWirelessGrid()); + if (Platform.INSTANCE.getConfig().getWirelessGrid().getUseEnergy()) { + consumer.accept(Items.INSTANCE.getWirelessGrid().getAtCapacity()); + } + itemConsumer.accept(Items.INSTANCE.getCreativeWirelessGrid()); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java index 475b3862c..2f2c93fb9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java @@ -35,6 +35,11 @@ public final class DefaultEnergyUsage { public static final long SILK_TOUCH_UPGRADE = 16; public static final long REGULATOR_UPGRADE = 16; + public static final long WIRELESS_GRID_CAPACITY = 1000; + public static final long WIRELESS_GRID_OPEN = 5; + public static final long WIRELESS_GRID_INSERT = 5; + public static final long WIRELESS_GRID_EXTRACT = 5; + private DefaultEnergyUsage() { } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java index f8fdd852a..a6bf1c7b3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Items.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.item.ProcessorItem; +import com.refinedmods.refinedstorage2.platform.common.item.WirelessGridItem; import java.util.ArrayList; import java.util.Collections; @@ -68,6 +69,10 @@ public final class Items { private Supplier silkTouchUpgrade; @Nullable private Supplier regulatorUpgrade; + @Nullable + private Supplier wirelessGrid; + @Nullable + private Supplier creativeWirelessGrid; private Items() { } @@ -304,4 +309,20 @@ public AbstractUpgradeItem getRegulatorUpgrade() { public void setRegulatorUpgrade(final Supplier regulatorUpgrade) { this.regulatorUpgrade = regulatorUpgrade; } + + public WirelessGridItem getWirelessGrid() { + return Objects.requireNonNull(wirelessGrid).get(); + } + + public void setWirelessGrid(final Supplier supplier) { + this.wirelessGrid = supplier; + } + + public WirelessGridItem getCreativeWirelessGrid() { + return Objects.requireNonNull(creativeWirelessGrid).get(); + } + + public void setCreativeWirelessGrid(final Supplier supplier) { + this.creativeWirelessGrid = supplier; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java index 0e87cfefd..4c063bc99 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Menus.java @@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.detector.DetectorContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.CraftingGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.GridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.WirelessGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.ExternalStorageContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.FluidStorageBlockContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.ItemStorageBlockContainerMenu; @@ -31,6 +32,8 @@ public final class Menus { @Nullable private Supplier> craftingGrid; @Nullable + private Supplier> wirelessGrid; + @Nullable private Supplier> controller; @Nullable private Supplier> itemStorage; @@ -72,6 +75,14 @@ public void setCraftingGrid(final Supplier> this.craftingGrid = supplier; } + public MenuType getWirelessGrid() { + return Objects.requireNonNull(wirelessGrid).get(); + } + + public void setWirelessGrid(final Supplier> supplier) { + this.wirelessGrid = supplier; + } + public MenuType getController() { return Objects.requireNonNull(controller).get(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridExtractionStrategy.java index 255294c19..11898dbf8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridExtractionStrategy.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.internal.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.Platform; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridInsertionStrategy.java index 035bb5001..5024aa0c2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridInsertionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/ClientGridInsertionStrategy.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.internal.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.common.Platform; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridExtractionStrategy.java index 59849090d..2a44a9a78 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridExtractionStrategy.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.internal.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridInsertionStrategy.java index 2c92a7adf..ee726499f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridInsertionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/CompositeGridInsertionStrategy.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.internal.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; import java.util.Collections; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/PlatformGridServiceFactoryImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/PlatformGridServiceFactoryImpl.java deleted file mode 100644 index 193e11ce1..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/PlatformGridServiceFactoryImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.internal.grid; - -import com.refinedmods.refinedstorage2.api.grid.service.GridService; -import com.refinedmods.refinedstorage2.api.grid.service.GridServiceFactory; -import com.refinedmods.refinedstorage2.api.storage.Actor; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; -import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; - -import java.util.function.ToLongFunction; - -public class PlatformGridServiceFactoryImpl implements PlatformGridServiceFactory { - private final GridServiceFactory delegate; - - public PlatformGridServiceFactoryImpl(final GridServiceFactory delegate) { - this.delegate = delegate; - } - - @Override - public GridService create(final StorageChannelType storageChannelType, - final Actor actor, - final ToLongFunction maxAmountProvider, - final long singleAmount) { - return delegate.create(storageChannelType, actor, maxAmountProvider, singleAmount); - } - - @Override - @SuppressWarnings({"deprecation", "RedundantSuppression"}) // forge deprecates stack insensitive getMaxStackSize - public GridService createForItem(final Actor actor) { - return create( - StorageChannelTypes.ITEM, - actor, - itemResource -> itemResource.item().getMaxStackSize(), - 1 - ); - } - - @Override - public GridService createForFluid(final Actor actor) { - return create( - StorageChannelTypes.FLUID, - actor, - fluidResource -> Long.MAX_VALUE, - Platform.INSTANCE.getBucketAmount() - ); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java new file mode 100644 index 000000000..718b18a73 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGrid.java @@ -0,0 +1,141 @@ +package com.refinedmods.refinedstorage2.platform.common.internal.grid; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.grid.GridWatcher; +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.network.Network; +import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridWatchers; +import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; +import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; +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.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.api.network.node.PlatformNetworkNodeContainer; +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.item.NetworkBoundItemContext; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import net.minecraft.server.MinecraftServer; + +public class WirelessGrid implements Grid { + private final MinecraftServer server; + private final NetworkBoundItemContext ctx; + private final GridWatchers watchers; + + public WirelessGrid(final MinecraftServer server, final NetworkBoundItemContext ctx) { + this.server = server; + this.ctx = ctx; + this.watchers = new GridWatchers(PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getAll()); + } + + private Optional getNetwork() { + if (ctx.getNetworkReference() == null) { + return Optional.empty(); + } + return Optional.ofNullable(server.getLevel(ctx.getNetworkReference().dimensionKey())) + .map(level -> level.getBlockEntity(ctx.getNetworkReference().pos())) + .filter(PlatformNetworkNodeContainer.class::isInstance) + .map(PlatformNetworkNodeContainer.class::cast) + .map(PlatformNetworkNodeContainer::getNode) + .map(NetworkNode::getNetwork); + } + + private Optional getStorage() { + return getNetwork().map(network -> network.getComponent(StorageNetworkComponent.class)); + } + + @Override + public void addWatcher(final GridWatcher watcher, final Class actorType) { + getNetwork().ifPresent(network -> watchers.addWatcher(watcher, actorType, network)); + } + + @Override + public void removeWatcher(final GridWatcher watcher) { + getNetwork().ifPresent(network -> watchers.removeWatcher(watcher, network)); + } + + @Override + public Storage getItemStorage() { + return getStorage().map(storage -> (Storage) storage.getStorageChannel(StorageChannelTypes.ITEM)) + .orElseGet(NoOpStorage::new); + } + + @Override + public boolean isActive() { + final boolean networkActive = getNetwork().map( + network -> network.getComponent(EnergyNetworkComponent.class).getStored() > 0 + ).orElse(false); + return networkActive && ctx.isActive(); + } + + @Override + public List> getResources(final StorageChannelType type, + final Class actorType) { + return getStorage().map(storage -> storage.getResources(type, actorType)).orElse(Collections.emptyList()); + } + + @Override + public GridOperations createOperations(final PlatformStorageChannelType storageChannelType, + final Actor actor) { + return getStorage() + .map(storage -> storage.getStorageChannel(storageChannelType)) + .map(storageChannel -> storageChannelType.createGridOperations(storageChannel, actor)) + .map(gridOperations -> (GridOperations) new WirelessGridOperations<>(gridOperations, ctx, watchers)) + .orElseGet(this::createNoOpGridOperations); + } + + private GridOperations createNoOpGridOperations() { + return new GridOperations<>() { + @Override + public boolean extract(final T resource, + final GridExtractMode extractMode, + final InsertableStorage destination) { + return false; + } + + @Override + public boolean insert(final T resource, + final GridInsertMode insertMode, + final ExtractableStorage source) { + return false; + } + }; + } + + private static class NoOpStorage implements Storage { + @Override + public long extract(final T resource, final long amount, final Action action, final Actor actor) { + return 0; + } + + @Override + public long insert(final T resource, final long amount, final Action action, final Actor actor) { + return 0; + } + + @Override + public Collection> getAll() { + return Collections.emptyList(); + } + + @Override + public long getStored() { + return 0; + } + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGridOperations.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGridOperations.java new file mode 100644 index 000000000..89801bf3f --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/WirelessGridOperations.java @@ -0,0 +1,55 @@ +package com.refinedmods.refinedstorage2.platform.common.internal.grid; + +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.network.impl.node.grid.GridWatchers; +import com.refinedmods.refinedstorage2.api.storage.ExtractableStorage; +import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.item.NetworkBoundItemContext; + +public class WirelessGridOperations implements GridOperations { + private final GridOperations delegate; + private final NetworkBoundItemContext ctx; + private final GridWatchers watchers; + + public WirelessGridOperations(final GridOperations delegate, + final NetworkBoundItemContext ctx, + final GridWatchers watchers) { + this.delegate = delegate; + this.ctx = ctx; + this.watchers = watchers; + } + + @Override + public boolean extract(final T resource, + final GridExtractMode extractMode, + final InsertableStorage destination) { + final boolean success = delegate.extract(resource, extractMode, destination); + if (success) { + drain(Platform.INSTANCE.getConfig().getWirelessGrid().getExtractEnergyUsage()); + } + return success; + } + + @Override + public boolean insert(final T resource, + final GridInsertMode insertMode, + final ExtractableStorage source) { + final boolean success = delegate.insert(resource, insertMode, source); + if (success) { + drain(Platform.INSTANCE.getConfig().getWirelessGrid().getInsertEnergyUsage()); + } + return success; + } + + private void drain(final long amount) { + final boolean wasActive = ctx.isActive(); + ctx.drain(amount); + final boolean isActive = ctx.isActive(); + if (wasActive != isActive) { + watchers.activeChanged(isActive); + } + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java index d03e37d16..fa89652c7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.internal.grid.view; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.GridResourceAttributeKeys; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java index a41205faa..0ecce143f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.internal.grid.view; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.grid.GridResourceAttributeKeys; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/StorageContainerHelperImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/StorageContainerItemHelperImpl.java similarity index 98% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/StorageContainerHelperImpl.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/StorageContainerItemHelperImpl.java index 6f88b224d..8f2688022 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/StorageContainerHelperImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/item/StorageContainerItemHelperImpl.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.StorageInfo; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerHelper; +import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.common.internal.storage.StorageTooltipHelper; @@ -25,7 +25,7 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; -public class StorageContainerHelperImpl implements StorageContainerHelper { +public class StorageContainerItemHelperImpl implements StorageContainerItemHelper { private static final String TAG_ID = "id"; @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java index 0e0afd624..b9566d1c2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java @@ -1,9 +1,13 @@ package com.refinedmods.refinedstorage2.platform.common.internal.storage.channel; +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.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.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceList; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceListImpl; @@ -72,6 +76,17 @@ public long getInterfaceExportLimit() { return Platform.INSTANCE.getBucketAmount() * 16; } + @Override + public GridOperations createGridOperations(final StorageChannel storageChannel, + final Actor actor) { + return new GridOperationsImpl<>( + storageChannel, + actor, + fluidResource -> Long.MAX_VALUE, + Platform.INSTANCE.getBucketAmount() + ); + } + @Override public CompoundTag toTag(final FluidResource resource) { return FluidResource.toTag(resource); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java index ed469a7d2..307e1dcb7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java @@ -1,9 +1,13 @@ package com.refinedmods.refinedstorage2.platform.common.internal.storage.channel; +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.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.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceList; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceListImpl; @@ -78,6 +82,20 @@ public long getInterfaceExportLimit(final ItemResource resource) { return resource.item().getMaxStackSize(); } + @Override + @SuppressWarnings("deprecation") + public GridOperations createGridOperations( + final StorageChannel storageChannel, + final Actor actor + ) { + return new GridOperationsImpl<>( + storageChannel, + actor, + itemResource -> itemResource.item().getMaxStackSize(), + 1 + ); + } + @Override public CompoundTag toTag(final ItemResource resource) { return ItemResource.toTag(resource); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java new file mode 100644 index 000000000..414c04959 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/AbstractNetworkBoundItem.java @@ -0,0 +1,163 @@ +package com.refinedmods.refinedstorage2.platform.common.item; + +import com.refinedmods.refinedstorage2.platform.api.item.HelpTooltipComponent; +import com.refinedmods.refinedstorage2.platform.api.network.node.PlatformNetworkNodeContainer; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Consumer; +import javax.annotation.Nullable; + +import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.Registries; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createStoredWithCapacityTranslation; +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +public abstract class AbstractNetworkBoundItem extends Item { + private static final MutableComponent UNBOUND = createTranslation("item", "network_item.unbound") + .withStyle(ChatFormatting.RED); + private static final Component UNBOUND_HELP = createTranslation("item", "network_item.unbound.help"); + + private static final String TAG_X = "x"; + private static final String TAG_Y = "y"; + private static final String TAG_Z = "z"; + private static final String TAG_DIMENSION = "dim"; + + private final ItemEnergyProvider energyProvider; + + protected AbstractNetworkBoundItem(final Properties properties, final ItemEnergyProvider energyProvider) { + super(properties); + this.energyProvider = energyProvider; + } + + public boolean isBound(final ItemStack stack) { + final CompoundTag tag = stack.getTag(); + if (tag == null) { + return false; + } + return tag.contains(TAG_X) && tag.contains(TAG_Y) && tag.contains(TAG_Z) && tag.contains(TAG_DIMENSION); + } + + private Optional getNetworkReference(final ItemStack stack) { + if (!isBound(stack)) { + return Optional.empty(); + } + final CompoundTag tag = Objects.requireNonNull(stack.getTag()); + final int x = tag.getInt(TAG_X); + final int y = tag.getInt(TAG_Y); + final int z = tag.getInt(TAG_Z); + final ResourceLocation dimension = new ResourceLocation(tag.getString(TAG_DIMENSION)); + return Optional.of(new NetworkBoundItemContext.NetworkReference( + ResourceKey.create(Registries.DIMENSION, dimension), + new BlockPos(x, y, z) + )); + } + + protected void tryUse( + final ItemStack stack, + final ServerPlayer player, + final PlayerSlotReference slotReference, + final Consumer contextConsumer + ) { + final Optional networkReference = getNetworkReference(stack); + contextConsumer.accept(new NetworkBoundItemContext( + player, + slotReference, + energyProvider, + networkReference.orElse(null) + )); + } + + @Override + public InteractionResult useOn(final UseOnContext ctx) { + if (ctx.getPlayer() == null) { + return InteractionResult.PASS; + } + final ItemStack stack = ctx.getPlayer().getItemInHand(ctx.getHand()); + final BlockEntity blockEntity = ctx.getLevel().getBlockEntity(ctx.getClickedPos()); + if (!(blockEntity instanceof PlatformNetworkNodeContainer)) { + return InteractionResult.PASS; + } + final CompoundTag tag = stack.getOrCreateTag(); + tag.putInt(TAG_X, blockEntity.getBlockPos().getX()); + tag.putInt(TAG_Y, blockEntity.getBlockPos().getY()); + tag.putInt(TAG_Z, blockEntity.getBlockPos().getZ()); + tag.putString(TAG_DIMENSION, ctx.getLevel().dimension().location().toString()); + return InteractionResult.SUCCESS; + } + + @Override + public void appendHoverText(final ItemStack stack, + @Nullable final Level level, + final List tooltip, + final TooltipFlag flag) { + super.appendHoverText(stack, level, tooltip, flag); + getNetworkReference(stack).ifPresentOrElse( + network -> tooltip.add(createTranslation( + "item", + "network_item.bound_to", + network.pos().getX(), + network.pos().getY(), + network.pos().getZ() + ).withStyle(ChatFormatting.GRAY)), + () -> tooltip.add(UNBOUND) + ); + if (!energyProvider.isEnabled()) { + return; + } + final long stored = energyProvider.getStored(stack); + final long capacity = energyProvider.getCapacity(stack); + final double pct = stored / (double) capacity; + tooltip.add(createStoredWithCapacityTranslation(stored, capacity, pct).withStyle(ChatFormatting.GRAY)); + } + + @Override + public boolean isBarVisible(final ItemStack stack) { + return energyProvider.isEnabled(); + } + + @Override + public int getBarWidth(final ItemStack stack) { + return (int) Math.round((energyProvider.getStored(stack) / (double) energyProvider.getCapacity(stack)) * 13D); + } + + @Override + public int getBarColor(final ItemStack stack) { + return Mth.hsvToRgb( + Math.max(0.0F, (float) energyProvider.getStored(stack) / (float) energyProvider.getCapacity(stack)) / 3.0F, + 1.0F, + 1.0F + ); + } + + public ItemStack getAtCapacity() { + return energyProvider.getAtCapacity(new ItemStack(this)); + } + + @Override + public Optional getTooltipImage(final ItemStack stack) { + if (isBound(stack)) { + return Optional.empty(); + } + return Optional.of(new HelpTooltipComponent(UNBOUND_HELP)); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/CreativeItemEnergyProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/CreativeItemEnergyProvider.java new file mode 100644 index 000000000..9ae378966 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/CreativeItemEnergyProvider.java @@ -0,0 +1,38 @@ +package com.refinedmods.refinedstorage2.platform.common.item; + +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +public class CreativeItemEnergyProvider implements ItemEnergyProvider { + public static final ItemEnergyProvider INSTANCE = new CreativeItemEnergyProvider(); + + private CreativeItemEnergyProvider() { + } + + @Override + public boolean isEnabled() { + return false; + } + + @Override + public long getStored(final ItemStack stack) { + return 0; + } + + @Override + public long getCapacity(final ItemStack stack) { + return 0; + } + + @Override + public void drain(final Player player, final PlayerSlotReference slotReference, final long amount) { + // no op + } + + @Override + public ItemStack getAtCapacity(final ItemStack stack) { + return stack.copy(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/FluidStorageDiskItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/FluidStorageDiskItem.java index 320d8edb6..d439ac758 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/FluidStorageDiskItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/FluidStorageDiskItem.java @@ -29,7 +29,7 @@ public FluidStorageDiskItem(final FluidStorageType.Variant variant) { super( new Item.Properties().stacksTo(1).fireResistant(), StorageChannelTypes.FLUID, - PlatformApi.INSTANCE.getStorageContainerHelper() + PlatformApi.INSTANCE.getStorageContainerItemHelper() ); this.variant = variant; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/ItemEnergyProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/ItemEnergyProvider.java new file mode 100644 index 000000000..ee89f47c6 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/ItemEnergyProvider.java @@ -0,0 +1,18 @@ +package com.refinedmods.refinedstorage2.platform.common.item; + +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +public interface ItemEnergyProvider { + boolean isEnabled(); + + long getStored(ItemStack stack); + + long getCapacity(ItemStack stack); + + void drain(Player player, PlayerSlotReference slotReference, long amount); + + ItemStack getAtCapacity(ItemStack stack); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/ItemStorageDiskItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/ItemStorageDiskItem.java index 658df67bd..e9efa237b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/ItemStorageDiskItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/ItemStorageDiskItem.java @@ -29,7 +29,7 @@ public ItemStorageDiskItem(final ItemStorageType.Variant variant) { super( new Item.Properties().stacksTo(1).fireResistant(), StorageChannelTypes.ITEM, - PlatformApi.INSTANCE.getStorageContainerHelper() + PlatformApi.INSTANCE.getStorageContainerItemHelper() ); this.variant = variant; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/NetworkBoundItemContext.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/NetworkBoundItemContext.java new file mode 100644 index 000000000..fec2e3638 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/NetworkBoundItemContext.java @@ -0,0 +1,49 @@ +package com.refinedmods.refinedstorage2.platform.common.item; + +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; + +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; + +public class NetworkBoundItemContext { + private final Player player; + private final PlayerSlotReference playerSlotReference; + private final ItemEnergyProvider energyProvider; + @Nullable + private final NetworkReference networkReference; + + public NetworkBoundItemContext( + final Player player, + final PlayerSlotReference playerSlotReference, + final ItemEnergyProvider energyProvider, + @Nullable final NetworkReference networkReference + ) { + this.player = player; + this.playerSlotReference = playerSlotReference; + this.energyProvider = energyProvider; + this.networkReference = networkReference; + } + + public boolean isActive() { + if (!energyProvider.isEnabled()) { + return true; + } + return energyProvider.getStored(player.getInventory().getItem(playerSlotReference.getSlotIndex())) > 0; + } + + public void drain(final long amount) { + energyProvider.drain(player, playerSlotReference, amount); + } + + @Nullable + public NetworkReference getNetworkReference() { + return networkReference; + } + + public record NetworkReference(ResourceKey dimensionKey, BlockPos pos) { + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java index 9eb7ba255..6eff0b8cf 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/RegulatorUpgradeItem.java @@ -41,10 +41,6 @@ public RegulatorUpgradeItem(final UpgradeRegistry registry) { super(new Item.Properties(), registry); } - public static boolean allowNbtUpdateAnimation(final ItemStack oldStack, final ItemStack newStack) { - return oldStack.getItem() != newStack.getItem(); - } - @Override public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { final ItemStack stack = player.getItemInHand(hand); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/WirelessGridItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/WirelessGridItem.java new file mode 100644 index 000000000..9377db11e --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/WirelessGridItem.java @@ -0,0 +1,53 @@ +package com.refinedmods.refinedstorage2.platform.common.item; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; +import com.refinedmods.refinedstorage2.platform.common.internal.grid.WirelessGrid; +import com.refinedmods.refinedstorage2.platform.common.menu.WirelessGridExtendedMenuProvider; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; + +public class WirelessGridItem extends AbstractNetworkBoundItem { + public WirelessGridItem(final ItemEnergyProvider energyProvider) { + super(new Item.Properties().stacksTo(1), energyProvider); + } + + @Override + public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { + final ItemStack stack = player.getItemInHand(hand); + if (player instanceof ServerPlayer serverPlayer && level.getServer() != null) { + final PlayerSlotReference slotReference = PlayerSlotReference.of(player, hand); + tryUse( + stack, + serverPlayer, + slotReference, + ctx -> open(level.getServer(), serverPlayer, ctx, slotReference) + ); + } + return InteractionResultHolder.consume(stack); + } + + private void open( + final MinecraftServer server, + final ServerPlayer player, + final NetworkBoundItemContext ctx, + final PlayerSlotReference slotReference + ) { + ctx.drain(Platform.INSTANCE.getConfig().getWirelessGrid().getOpenEnergyUsage()); + final Grid grid = new WirelessGrid(server, ctx); + Platform.INSTANCE.getMenuOpener().openMenu(player, new WirelessGridExtendedMenuProvider( + grid, + PlatformApi.INSTANCE.getStorageChannelTypeRegistry(), + slotReference + )); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/FluidStorageBlockBlockItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/FluidStorageBlockBlockItem.java index ed5683cec..fc90f5772 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/FluidStorageBlockBlockItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/FluidStorageBlockBlockItem.java @@ -28,7 +28,7 @@ public FluidStorageBlockBlockItem(final Block block, final FluidStorageType.Vari super( block, new Item.Properties().stacksTo(1).fireResistant(), - PlatformApi.INSTANCE.getStorageContainerHelper() + PlatformApi.INSTANCE.getStorageContainerItemHelper() ); this.variant = variant; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockBlockItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockBlockItem.java index 3622ded74..f34d72258 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockBlockItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/item/block/ItemStorageBlockBlockItem.java @@ -28,7 +28,7 @@ public ItemStorageBlockBlockItem(final Block block, final ItemStorageType.Varian super( block, new Item.Properties().stacksTo(1).fireResistant(), - PlatformApi.INSTANCE.getStorageContainerHelper() + PlatformApi.INSTANCE.getStorageContainerItemHelper() ); this.variant = variant; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/GridExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/GridExtendedMenuProvider.java new file mode 100644 index 000000000..364ec831b --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/GridExtendedMenuProvider.java @@ -0,0 +1,70 @@ +package com.refinedmods.refinedstorage2.platform.common.menu; + +import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.api.registry.PlatformRegistry; +import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; + +import java.util.List; +import javax.annotation.Nullable; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; + +public class GridExtendedMenuProvider implements ExtendedMenuProvider { + private final Grid grid; + private final PlatformRegistry> storageChannelTypeRegistry; + private final MenuProvider menuProvider; + + public GridExtendedMenuProvider(final Grid grid, + final PlatformRegistry> storageChannelTypeRegistry, + final MenuProvider menuProvider) { + this.grid = grid; + this.storageChannelTypeRegistry = storageChannelTypeRegistry; + this.menuProvider = menuProvider; + } + + @Override + public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { + buf.writeBoolean(grid.isActive()); + final List> types = storageChannelTypeRegistry.getAll(); + buf.writeInt(types.size()); + types.forEach(type -> writeStorageChannel(type, buf)); + } + + private void writeStorageChannel(final PlatformStorageChannelType storageChannelType, + final FriendlyByteBuf buf) { + final ResourceLocation id = storageChannelTypeRegistry.getId(storageChannelType).orElseThrow(); + buf.writeResourceLocation(id); + final List> resources = grid.getResources(storageChannelType, PlayerActor.class); + buf.writeInt(resources.size()); + resources.forEach(resource -> writeGridResource(storageChannelType, resource, buf)); + } + + private void writeGridResource(final PlatformStorageChannelType storageChannelType, + final TrackedResourceAmount resource, + final FriendlyByteBuf buf) { + storageChannelType.toBuffer(resource.resourceAmount().getResource(), buf); + buf.writeLong(resource.resourceAmount().getAmount()); + PacketUtil.writeTrackedResource(buf, resource.trackedResource()); + } + + @Override + public Component getDisplayName() { + return menuProvider.getDisplayName(); + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return menuProvider.createMenu(syncId, inventory, player); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/WirelessGridExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/WirelessGridExtendedMenuProvider.java new file mode 100644 index 000000000..e234d788b --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/menu/WirelessGridExtendedMenuProvider.java @@ -0,0 +1,44 @@ +package com.refinedmods.refinedstorage2.platform.common.menu; + +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; +import com.refinedmods.refinedstorage2.platform.api.registry.PlatformRegistry; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.WirelessGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; + +public class WirelessGridExtendedMenuProvider extends GridExtendedMenuProvider { + private final PlayerSlotReference slotReference; + + public WirelessGridExtendedMenuProvider(final Grid grid, + final PlatformRegistry> + storageChannelTypeRegistry, + final PlayerSlotReference slotReference) { + super(grid, storageChannelTypeRegistry, new MenuProvider() { + @Override + public Component getDisplayName() { + return ContentNames.WIRELESS_GRID; + } + + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return new WirelessGridContainerMenu(syncId, inventory, grid, slotReference); + } + }); + this.slotReference = slotReference; + } + + @Override + public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { + super.writeScreenOpeningData(player, buf); + slotReference.writeToBuf(buf); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java index c61f9deb1..80ecb1d5b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.packet; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/NetworkItemItemPropertyFunction.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/NetworkItemItemPropertyFunction.java new file mode 100644 index 000000000..8d6b046cf --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/render/NetworkItemItemPropertyFunction.java @@ -0,0 +1,26 @@ +package com.refinedmods.refinedstorage2.platform.common.render; + +import com.refinedmods.refinedstorage2.platform.common.item.AbstractNetworkBoundItem; + +import javax.annotation.Nullable; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; + +public class NetworkItemItemPropertyFunction implements ClampedItemPropertyFunction { + public static final ResourceLocation NAME = new ResourceLocation("active"); + + @Override + public float unclampedCall(final ItemStack itemStack, + @Nullable final ClientLevel clientLevel, + @Nullable final LivingEntity livingEntity, + final int i) { + if (itemStack.getItem() instanceof AbstractNetworkBoundItem boundItem) { + return boundItem.isBound(itemStack) ? 1 : 0; + } + return 0; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ControllerScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ControllerScreen.java index f6bbb1c73..e7b023401 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ControllerScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ControllerScreen.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage2.platform.common.screen; -import com.refinedmods.refinedstorage2.platform.api.util.AmountFormatting; import com.refinedmods.refinedstorage2.platform.common.containermenu.ControllerContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; import com.refinedmods.refinedstorage2.platform.common.screen.widget.ProgressWidget; @@ -15,6 +14,7 @@ import net.minecraft.world.entity.player.Inventory; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createStoredWithCapacityTranslation; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class ControllerScreen extends AbstractBaseScreen { @@ -59,12 +59,10 @@ private double getPercentageFull() { } private List createTooltip() { - return Collections.singletonList(createTranslation( - "misc", - "stored_with_capacity", - AmountFormatting.format(getMenu().getStored()), - AmountFormatting.format(getMenu().getCapacity()), - String.valueOf((int) (getPercentageFull() * 100D)) + return Collections.singletonList(createStoredWithCapacityTranslation( + getMenu().getStored(), + getMenu().getCapacity(), + getPercentageFull() )); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/AbstractGridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/AbstractGridScreen.java index 76d26131c..b85597730 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/AbstractGridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/AbstractGridScreen.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.screen.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.api.grid.view.GridResource; import com.refinedmods.refinedstorage2.api.grid.view.GridView; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; @@ -14,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.DisabledSlot; import com.refinedmods.refinedstorage2.platform.common.internal.grid.view.ItemGridResource; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.screen.AbstractBaseScreen; @@ -112,7 +113,9 @@ protected void init() { addWidget(scrollbar); addWidget(searchField); - addSideButton(new RedstoneModeSideButtonWidget(getMenu().getProperty(PropertyTypes.REDSTONE_MODE))); + if (getMenu().hasProperty(PropertyTypes.REDSTONE_MODE)) { + addSideButton(new RedstoneModeSideButtonWidget(getMenu().getProperty(PropertyTypes.REDSTONE_MODE))); + } addSideButton(new SortingDirectionSideButtonWidget(getMenu())); addSideButton(new SortingTypeSideButtonWidget(getMenu())); addSideButton(new SizeSideButtonWidget(getMenu())); @@ -253,24 +256,32 @@ private void renderCell(final GuiGraphics graphics, final int idx, final int column) { final GridView view = getMenu().getView(); - final int slotX = rowX + 1 + (column * 18); final int slotY = rowY + 1; - - GridResource resource = null; - if (idx < view.getViewList().size()) { - resource = view.getViewList().get(idx); - renderResourceWithAmount(graphics, slotX, slotY, resource); + if (!getMenu().isActive()) { + renderDisabledSlot(graphics, slotX, slotY); + } else { + renderSlot(graphics, mouseX, mouseY, idx, view, slotX, slotY); } + } + private void renderSlot(final GuiGraphics graphics, + final int mouseX, + final int mouseY, + final int idx, + final GridView view, + final int slotX, + final int slotY) { final boolean inBounds = mouseX >= slotX && mouseY >= slotY && mouseX <= slotX + 16 && mouseY <= slotY + 16; - - if (!getMenu().isActive()) { - renderDisabledSlot(graphics, slotX, slotY); - } else if (inBounds && isOverStorageArea(mouseX, mouseY)) { + GridResource resource = null; + if (idx < view.getViewList().size()) { + resource = view.getViewList().get(idx); + renderResourceWithAmount(graphics, slotX, slotY, resource); + } + if (inBounds && isOverStorageArea(mouseX, mouseY)) { renderSelection(graphics, slotX, slotY); if (resource != null) { gridSlotNumber = idx; @@ -505,7 +516,7 @@ public boolean mouseScrolled(final double x, final double y, final double delta) if (isOverStorageArea((int) x, (int) y) && gridSlotNumber >= 0) { mouseScrolledInGrid(up); - } else if (hoveredSlot != null && hoveredSlot.hasItem()) { + } else if (hoveredSlot != null && hoveredSlot.hasItem() && !(hoveredSlot instanceof DisabledSlot)) { mouseScrolledInInventory(up, hoveredSlot); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/GridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/GridScreen.java index 23d439a8b..27c23f6a9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/GridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/grid/GridScreen.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.screen.grid; -import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.GridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.AbstractGridContainerMenu; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -8,10 +8,10 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -public class GridScreen extends AbstractGridScreen { +public class GridScreen extends AbstractGridScreen { private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/grid.png"); - public GridScreen(final GridContainerMenu menu, final Inventory inventory, final Component title) { + public GridScreen(final T menu, final Inventory inventory, final Component title) { super(menu, inventory, title, 99); this.inventoryLabelY = 75; this.imageWidth = 227; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/IdentifierUtil.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/IdentifierUtil.java index 016668985..dac67542a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/IdentifierUtil.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/util/IdentifierUtil.java @@ -1,5 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.util; +import com.refinedmods.refinedstorage2.platform.api.util.AmountFormatting; + import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -30,6 +32,20 @@ public static MutableComponent createTranslation(final String category, final St return Component.translatable(createTranslationKey(category, value), args); } + public static MutableComponent createStoredWithCapacityTranslation( + final long stored, + final long capacity, + final double pct + ) { + return createTranslation( + "misc", + "stored_with_capacity", + AmountFormatting.format(stored), + AmountFormatting.format(capacity), + String.valueOf((int) (pct * 100D)) + ); + } + public static MutableComponent createTranslationAsHeading(final String category, final String value) { return Component.literal("<") .append(createTranslation(category, value)) 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 6a8e575b5..f10b5053a 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 @@ -179,6 +179,11 @@ "item.refinedstorage2.fortune_upgrade.3": "Fortune III Upgrade", "item.refinedstorage2.regulator_upgrade": "Regulator Upgrade", "item.refinedstorage2.regulator_upgrade.help": "In an Exporter, will only export if the amount in the target is less than configured in the upgrade. In an Importer, will only import if the amount in the target is more than configured in the upgrade. Use item to configure.", + "item.refinedstorage2.wireless_grid": "Wireless Grid", + "item.refinedstorage2.creative_wireless_grid": "Creative Wireless Grid", + "item.refinedstorage2.network_item.unbound": "Unbound.", + "item.refinedstorage2.network_item.unbound.help": "Use on any storage network device to bind.", + "item.refinedstorage2.network_item.bound_to": "Bound to %d, %d, %d.", "misc.refinedstorage2.stored": "Stored: %s", "misc.refinedstorage2.stored_with_capacity": "Stored: %s / %s (%d%%)", "misc.refinedstorage2.total": "%d total", @@ -262,6 +267,12 @@ "text.autoconfig.refinedstorage2.option.iface.energyUsage": "Energy usage", "text.autoconfig.refinedstorage2.option.externalStorage": "External Storage", "text.autoconfig.refinedstorage2.option.externalStorage.energyUsage": "Energy usage", + "text.autoconfig.refinedstorage2.option.wirelessGrid": "Wireless Grid", + "text.autoconfig.refinedstorage2.option.wirelessGrid.useEnergy": "Use energy", + "text.autoconfig.refinedstorage2.option.wirelessGrid.energyCapacity": "Energy capacity", + "text.autoconfig.refinedstorage2.option.wirelessGrid.openEnergyUsage": "Open energy usage", + "text.autoconfig.refinedstorage2.option.wirelessGrid.insertEnergyUsage": "Insert energy usage", + "text.autoconfig.refinedstorage2.option.wirelessGrid.extractEnergyUsage": "Extract energy usage", "advancements.refinedstorage2.root.description": "Use one or multiple Controllers in a network to provide your network with energy", "advancements.refinedstorage2.connecting": "Connecting", "advancements.refinedstorage2.connecting.description": "Use Cable to connect devices with each other, or place devices against each other", @@ -290,5 +301,7 @@ "advancements.refinedstorage2.construction": "Construction", "advancements.refinedstorage2.construction.description": "Get blocks from the storage network into the world with a Constructor", "advancements.refinedstorage2.destruction": "Destruction", - "advancements.refinedstorage2.destruction.description": "Get blocks from in the world into the storage network with a Destructor" + "advancements.refinedstorage2.destruction.description": "Get blocks from in the world into the storage network with a Destructor", + "advancements.refinedstorage2.wireless": "Wireless", + "advancements.refinedstorage2.wireless.description": "Access your resources wirelessly with a Wireless Grid." } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/creative_wireless_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/creative_wireless_grid.json new file mode 100644 index 000000000..380a93266 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/creative_wireless_grid.json @@ -0,0 +1,17 @@ +{ + "parent": "item/generated", + "overrides": [ + { + "predicate": { + "active": 0 + }, + "model": "refinedstorage2:item/wireless_grid/inactive" + }, + { + "predicate": { + "active": 1 + }, + "model": "refinedstorage2:item/wireless_grid/active" + } + ] +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid.json new file mode 100644 index 000000000..380a93266 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid.json @@ -0,0 +1,17 @@ +{ + "parent": "item/generated", + "overrides": [ + { + "predicate": { + "active": 0 + }, + "model": "refinedstorage2:item/wireless_grid/inactive" + }, + { + "predicate": { + "active": 1 + }, + "model": "refinedstorage2:item/wireless_grid/active" + } + ] +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid/active.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid/active.json new file mode 100644 index 000000000..5f850e26c --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid/active.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "refinedstorage2:item/wireless_grid/active" + } +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid/inactive.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid/inactive.json new file mode 100644 index 000000000..2b26791e5 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/wireless_grid/inactive.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "refinedstorage2:item/wireless_grid/inactive" + } +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/wireless_grid/active.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/wireless_grid/active.png new file mode 100644 index 000000000..1d5f5b240 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/wireless_grid/active.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/wireless_grid/inactive.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/wireless_grid/inactive.png new file mode 100644 index 000000000..577fab77d Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/wireless_grid/inactive.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/wireless.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/wireless.json new file mode 100644 index 000000000..605971517 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/wireless.json @@ -0,0 +1,28 @@ +{ + "display": { + "icon": { + "item": "refinedstorage2:wireless_grid" + }, + "title": { + "translate": "advancements.refinedstorage2.wireless" + }, + "description": { + "translate": "advancements.refinedstorage2.wireless.description" + } + }, + "parent": "refinedstorage2:root", + "criteria": { + "wireless_grid_in_inventory": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": [ + "refinedstorage2:wireless_grid" + ] + } + ] + } + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/wireless_grid.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/wireless_grid.json new file mode 100644 index 000000000..3e5dcb128 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/wireless_grid.json @@ -0,0 +1,25 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "EPE", + "EGE", + "EAE" + ], + "key": { + "E": { + "item": "refinedstorage2:quartz_enriched_iron" + }, + "P": { + "item": "minecraft:ender_pearl" + }, + "G": { + "tag": "refinedstorage2:grids" + }, + "A": { + "item": "refinedstorage2:advanced_processor" + } + }, + "result": { + "item": "refinedstorage2:wireless_grid" + } +} \ No newline at end of file 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 b1f540812..4845a2739 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 @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.item.RegulatorUpgradeItem; +import com.refinedmods.refinedstorage2.platform.common.render.NetworkItemItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.render.model.ControllerModelPredicateProvider; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.CompositeClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.HelpClientTooltipComponent; @@ -37,7 +38,7 @@ import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; +import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.TooltipComponentCallback; import net.fabricmc.loader.api.FabricLoader; @@ -48,6 +49,7 @@ import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; +import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; @@ -86,6 +88,7 @@ public > void registerGridSynchronizers(); registerResourceRendering(); registerAlternativeGridHints(); + registerItemProperties(); } private void setRenderLayers() { @@ -219,12 +222,12 @@ private void registerCustomModels() { final ResourceLocation diskDriveIdentifier = createIdentifier("block/disk_drive"); final ResourceLocation diskDriveIdentifierItem = createIdentifier("item/disk_drive"); - ModelLoadingRegistry.INSTANCE.registerResourceProvider(resourceManager -> (identifier, ctx) -> { - if (identifier.equals(diskDriveIdentifier) || identifier.equals(diskDriveIdentifierItem)) { + ModelLoadingPlugin.register(pluginContext -> pluginContext.resolveModel().register(context -> { + if (context.id().equals(diskDriveIdentifier) || context.id().equals(diskDriveIdentifierItem)) { return new DiskDriveUnbakedModel(); } return null; - }); + })); } private void registerCustomTooltips() { @@ -294,4 +297,17 @@ private void registerReiGridSynchronizers() { new ReiGridSynchronizer(reiProxy, true) ); } + + private void registerItemProperties() { + ItemProperties.register( + Items.INSTANCE.getWirelessGrid(), + NetworkItemItemPropertyFunction.NAME, + new NetworkItemItemPropertyFunction() + ); + ItemProperties.register( + Items.INSTANCE.getCreativeWirelessGrid(), + NetworkItemItemPropertyFunction.NAME, + new NetworkItemItemPropertyFunction() + ); + } } 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 01ead64e8..198f01772 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 @@ -64,6 +64,9 @@ public class ConfigImpl implements ConfigData, com.refinedmods.refinedstorage2.p @ConfigEntry.Gui.CollapsibleObject private SimpleEnergyUsageEntryImpl constructor = new SimpleEnergyUsageEntryImpl(DefaultEnergyUsage.CONSTRUCTOR); + @ConfigEntry.Gui.CollapsibleObject + private WirelessGridEntryImpl wirelessGrid = new WirelessGridEntryImpl(); + public static ConfigImpl get() { return AutoConfig.getConfigHolder(ConfigImpl.class).getConfig(); } @@ -143,6 +146,11 @@ public SimpleEnergyUsageEntry getConstructor() { return constructor; } + @Override + public WirelessGridEntry getWirelessGrid() { + return wirelessGrid; + } + private static class GridEntryImpl implements GridEntry { private boolean largeFont = false; @@ -465,4 +473,41 @@ public long getRegulatorUpgradeEnergyUsage() { return regulatorUpgradeEnergyUsage; } } + + private static class WirelessGridEntryImpl implements WirelessGridEntry { + private boolean useEnergy = true; + + private long energyCapacity = DefaultEnergyUsage.WIRELESS_GRID_CAPACITY; + + private long openEnergyUsage = DefaultEnergyUsage.WIRELESS_GRID_OPEN; + + private long insertEnergyUsage = DefaultEnergyUsage.WIRELESS_GRID_INSERT; + + private long extractEnergyUsage = DefaultEnergyUsage.WIRELESS_GRID_EXTRACT; + + @Override + public boolean getUseEnergy() { + return useEnergy; + } + + @Override + public long getEnergyCapacity() { + return energyCapacity; + } + + @Override + public long getOpenEnergyUsage() { + return openEnergyUsage; + } + + @Override + public long getInsertEnergyUsage() { + return insertEnergyUsage; + } + + @Override + public long getExtractEnergyUsage() { + return extractEnergyUsage; + } + } } 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 696cc52e4..b84cf1172 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 @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.common.AbstractModInitializer; +import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.block.AbstractBaseBlock; import com.refinedmods.refinedstorage2.platform.common.block.entity.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.iface.InterfaceBlockEntity; @@ -12,13 +13,17 @@ import com.refinedmods.refinedstorage2.platform.common.content.Blocks; import com.refinedmods.refinedstorage2.platform.common.content.CreativeModeTabItems; import com.refinedmods.refinedstorage2.platform.common.content.DirectRegistryCallback; +import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.MenuTypeFactory; import com.refinedmods.refinedstorage2.platform.common.internal.network.node.iface.externalstorage.InterfacePlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; +import com.refinedmods.refinedstorage2.platform.common.item.CreativeItemEnergyProvider; import com.refinedmods.refinedstorage2.platform.common.item.RegulatorUpgradeItem; +import com.refinedmods.refinedstorage2.platform.common.item.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.util.TickHandler; import com.refinedmods.refinedstorage2.platform.fabric.block.entity.FabricDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.fabric.integration.energy.ControllerTeamRebornEnergy; +import com.refinedmods.refinedstorage2.platform.fabric.integration.energy.TeamRebornEnergyItemEnergyProvider; import com.refinedmods.refinedstorage2.platform.fabric.internal.grid.FluidGridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.fabric.internal.grid.FluidGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.fabric.internal.grid.ItemGridExtractionStrategy; @@ -75,6 +80,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import team.reborn.energy.api.EnergyStorage; +import team.reborn.energy.api.base.SimpleEnergyItem; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @@ -110,10 +116,7 @@ private void registerAdditionalGridInsertionStrategyFactories() { } private void registerGridExtractionStrategyFactories() { - PlatformApi.INSTANCE.addGridExtractionStrategyFactory( - (containerMenu, player, gridServiceFactory, itemStorage) -> - new ItemGridExtractionStrategy(containerMenu, player, gridServiceFactory) - ); + PlatformApi.INSTANCE.addGridExtractionStrategyFactory(ItemGridExtractionStrategy::new); PlatformApi.INSTANCE.addGridExtractionStrategyFactory(FluidGridExtractionStrategy::new); } @@ -197,7 +200,25 @@ public boolean allowNbtUpdateAnimation(final Player player, final InteractionHand hand, final ItemStack oldStack, final ItemStack newStack) { - return RegulatorUpgradeItem.allowNbtUpdateAnimation(oldStack, newStack); + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + }, + () -> new WirelessGridItem(new TeamRebornEnergyItemEnergyProvider()) { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + }, + () -> new WirelessGridItem(CreativeItemEnergyProvider.INSTANCE) { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } } ); @@ -280,6 +301,7 @@ private void registerSidedHandlers() { BlockEntities.INSTANCE.getInterface() ); registerControllerEnergy(); + registerWirelessGridEnergy(); } private void registerItemStorage(final Predicate test, @@ -302,6 +324,15 @@ private void registerControllerEnergy() { ); } + private void registerWirelessGridEnergy() { + EnergyStorage.ITEM.registerForItems((stack, context) -> SimpleEnergyItem.createStorage( + context, + Platform.INSTANCE.getConfig().getWirelessGrid().getEnergyCapacity(), + Platform.INSTANCE.getConfig().getWirelessGrid().getEnergyCapacity(), + Platform.INSTANCE.getConfig().getWirelessGrid().getEnergyCapacity() + ), Items.INSTANCE.getWirelessGrid()); + } + private void registerTickHandler() { ServerTickEvents.START_SERVER_TICK.register(server -> TickHandler.runQueuedActions()); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/energy/TeamRebornEnergyItemEnergyProvider.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/energy/TeamRebornEnergyItemEnergyProvider.java new file mode 100644 index 000000000..0c0fdda4e --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/energy/TeamRebornEnergyItemEnergyProvider.java @@ -0,0 +1,65 @@ +package com.refinedmods.refinedstorage2.platform.fabric.integration.energy; + +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; +import com.refinedmods.refinedstorage2.platform.common.item.ItemEnergyProvider; + +import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; +import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import team.reborn.energy.api.EnergyStorage; +import team.reborn.energy.api.base.SimpleEnergyItem; + +public class TeamRebornEnergyItemEnergyProvider implements ItemEnergyProvider { + @Override + public boolean isEnabled() { + return Platform.INSTANCE.getConfig().getWirelessGrid().getUseEnergy(); + } + + @Override + public long getStored(final ItemStack stack) { + final EnergyStorage energyStorage = EnergyStorage.ITEM.find(stack, ContainerItemContext.withConstant(stack)); + if (energyStorage == null) { + return 0; + } + return energyStorage.getAmount(); + } + + @Override + public long getCapacity(final ItemStack stack) { + final EnergyStorage energyStorage = EnergyStorage.ITEM.find(stack, ContainerItemContext.withConstant(stack)); + if (energyStorage == null) { + return 0; + } + return energyStorage.getCapacity(); + } + + @Override + public void drain(final Player player, final PlayerSlotReference slotReference, final long amount) { + if (!isEnabled()) { + return; + } + final PlayerInventoryStorage inventoryStorage = PlayerInventoryStorage.of(player); + final ContainerItemContext ctx = ContainerItemContext.ofPlayerSlot( + player, + inventoryStorage.getSlot(slotReference.getSlotIndex()) + ); + final EnergyStorage energyStorage = EnergyStorage.ITEM.find(ctx.getItemVariant().toStack(), ctx); + if (energyStorage == null) { + return; + } + try (Transaction tx = Transaction.openOuter()) { + energyStorage.extract(amount, tx); + tx.commit(); + } + } + + @Override + public ItemStack getAtCapacity(final ItemStack stack) { + final ItemStack copied = stack.copy(); + SimpleEnergyItem.setStoredEnergyUnchecked(copied, getCapacity(copied)); + return copied; + } +} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java index 1e11c22bb..a38915a68 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridExtractionStrategy.java @@ -1,16 +1,17 @@ package com.refinedmods.refinedstorage2.platform.fabric.internal.grid; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; 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.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.fabric.util.BucketSingleStackStorage; import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; @@ -29,19 +30,18 @@ public class FluidGridExtractionStrategy implements GridExtractionStrategy { private static final ItemVariant BUCKET_ITEM_VARIANT = ItemVariant.of(Items.BUCKET); private static final ItemResource BUCKET_ITEM_RESOURCE = new ItemResource(Items.BUCKET, null); - private final GridService gridService; + private final GridOperations gridOperations; private final PlayerInventoryStorage playerInventoryStorage; private final net.fabricmc.fabric.api.transfer.v1.storage.Storage playerCursorStorage; private final Storage itemStorage; public FluidGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory, - final Storage itemStorage) { - this.gridService = gridServiceFactory.createForFluid(new PlayerActor(player)); + final Grid grid) { + this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); - this.itemStorage = itemStorage; + this.itemStorage = grid.getItemStorage(); } @Override @@ -73,7 +73,7 @@ private void extractWithBucketInStorage(final FluidResource fluidResource, if (destination == null) { return; } - gridService.extract(fluidResource, mode, (resource, amount, action, source) -> { + gridOperations.extract(fluidResource, mode, (resource, amount, action, source) -> { try (Transaction tx = Transaction.openOuter()) { final long inserted = destination.insert(toFluidVariant(resource), amount, tx); final boolean couldInsertBucket = insertResultingBucketIntoInventory(interceptingStorage, cursor, tx); @@ -102,7 +102,7 @@ private void extractWithBucketInInventory(final FluidResource fluidResource, if (dest == null) { return; } - gridService.extract(fluidResource, mode, (resource, amount, action, source) -> { + gridOperations.extract(fluidResource, mode, (resource, amount, action, source) -> { try (Transaction innerTx = tx.openNested()) { final long inserted = dest.insert(toFluidVariant(resource), amount, innerTx); final boolean couldInsertBucket = insertResultingBucketIntoInventory( diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridInsertionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridInsertionStrategy.java index b7cc3c1b1..43f17db9e 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridInsertionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/FluidGridInsertionStrategy.java @@ -1,12 +1,13 @@ package com.refinedmods.refinedstorage2.platform.fabric.internal.grid; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import javax.annotation.Nullable; @@ -27,15 +28,15 @@ public class FluidGridInsertionStrategy implements GridInsertionStrategy { private final AbstractContainerMenu containerMenu; - private final GridService gridService; + private final GridOperations gridOperations; private final Player player; private final PlayerInventoryStorage playerInventoryStorage; public FluidGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory) { + final Grid grid) { this.containerMenu = containerMenu; - this.gridService = gridServiceFactory.createForFluid(new PlayerActor(player)); + this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); this.player = player; this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); } @@ -51,7 +52,7 @@ public boolean onInsert(final GridInsertMode insertMode, final boolean tryAltern return false; } final FluidResource fluidResource = ofFluidVariant(extractableResource); - gridService.insert(fluidResource, insertMode, (resource, amount, action, source) -> { + gridOperations.insert(fluidResource, insertMode, (resource, amount, action, source) -> { final FluidVariant fluidVariant = toFluidVariant(resource); try (Transaction tx = Transaction.openOuter()) { final long extracted = cursorStorage.extract(fluidVariant, amount, tx); @@ -90,7 +91,7 @@ public boolean onTransfer(final int slotIndex) { return false; } final FluidResource fluidResource = ofFluidVariant(extractableResource); - gridService.insert(fluidResource, GridInsertMode.ENTIRE_RESOURCE, (resource, amount, action, source) -> { + gridOperations.insert(fluidResource, GridInsertMode.ENTIRE_RESOURCE, (resource, amount, action, source) -> { final FluidVariant fluidVariant = toFluidVariant(resource); try (Transaction tx = Transaction.openOuter()) { final long extracted = fluidSlotStorage.extract(fluidVariant, amount, tx); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridExtractionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridExtractionStrategy.java index a42673aef..919890924 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridExtractionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridExtractionStrategy.java @@ -1,13 +1,14 @@ package com.refinedmods.refinedstorage2.platform.fabric.internal.grid; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage; @@ -20,14 +21,14 @@ import static com.refinedmods.refinedstorage2.platform.fabric.util.VariantUtil.toItemVariant; public class ItemGridExtractionStrategy implements GridExtractionStrategy { - private final GridService gridService; + private final GridOperations gridOperations; private final PlayerInventoryStorage playerInventoryStorage; private final SingleSlotStorage playerCursorStorage; public ItemGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory) { - this.gridService = gridServiceFactory.createForItem(new PlayerActor(player)); + final Grid grid) { + this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); } @@ -38,7 +39,7 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelT final GridExtractMode extractMode, final boolean cursor) { if (resource instanceof ItemResource itemResource) { - gridService.extract(itemResource, extractMode, (r, amount, action, source) -> { + gridOperations.extract(itemResource, extractMode, (r, amount, action, source) -> { final ItemVariant itemVariant = toItemVariant(r); try (Transaction tx = Transaction.openOuter()) { final long inserted = insert(itemVariant, amount, tx, cursor); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridInsertionStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridInsertionStrategy.java index c7a0b3d85..90c572e7c 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridInsertionStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridInsertionStrategy.java @@ -1,12 +1,13 @@ package com.refinedmods.refinedstorage2.platform.fabric.internal.grid; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; @@ -24,14 +25,14 @@ public class ItemGridInsertionStrategy implements GridInsertionStrategy { private final AbstractContainerMenu containerMenu; - private final GridService gridService; + private final GridOperations gridOperations; private final SingleSlotStorage playerCursorStorage; public ItemGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory) { + final Grid grid) { this.containerMenu = containerMenu; - this.gridService = gridServiceFactory.createForItem(new PlayerActor(player)); + this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); } @@ -42,7 +43,7 @@ public boolean onInsert(final GridInsertMode insertMode, final boolean tryAltern return false; } final ItemResource itemResource = new ItemResource(carried.getItem(), carried.getTag()); - gridService.insert(itemResource, insertMode, (resource, amount, action, source) -> { + gridOperations.insert(itemResource, insertMode, (resource, amount, action, source) -> { try (Transaction tx = Transaction.openOuter()) { final ItemVariant itemVariant = toItemVariant(resource); final long extracted = playerCursorStorage.extract(itemVariant, amount, tx); @@ -65,7 +66,7 @@ public boolean onTransfer(final int slotIndex) { return false; } final ItemResource itemResource = ofItemVariant(itemVariantInSlot); - gridService.insert(itemResource, GridInsertMode.ENTIRE_RESOURCE, (resource, amount, action, source) -> { + gridOperations.insert(itemResource, GridInsertMode.ENTIRE_RESOURCE, (resource, amount, action, source) -> { try (Transaction tx = Transaction.openOuter()) { final ItemVariant itemVariant = toItemVariant(resource); final long extracted = storage.extract(itemVariant, amount, tx); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridScrollingStrategy.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridScrollingStrategy.java index 00394e630..ffcbad1b4 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridScrollingStrategy.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/internal/grid/ItemGridScrollingStrategy.java @@ -1,15 +1,16 @@ package com.refinedmods.refinedstorage2.platform.fabric.internal.grid; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +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.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage; @@ -22,14 +23,14 @@ import static com.refinedmods.refinedstorage2.platform.fabric.util.VariantUtil.toItemVariant; public class ItemGridScrollingStrategy implements GridScrollingStrategy { - private final GridService gridService; + private final GridOperations gridOperations; private final PlayerInventoryStorage playerInventoryStorage; private final SingleSlotStorage playerCursorStorage; public ItemGridScrollingStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory) { - this.gridService = gridServiceFactory.createForItem(new PlayerActor(player)); + final Grid grid) { + this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); this.playerInventoryStorage = PlayerInventoryStorage.of(player.getInventory()); this.playerCursorStorage = PlayerInventoryStorage.getCursorStorage(containerMenu); } @@ -57,7 +58,7 @@ public boolean onScroll( private void handleInventoryToGridScroll(final ItemResource itemResource, final Storage sourceStorage) { - gridService.insert(itemResource, GridInsertMode.SINGLE_RESOURCE, (resource, amount, action, source) -> { + gridOperations.insert(itemResource, GridInsertMode.SINGLE_RESOURCE, (resource, amount, action, source) -> { try (Transaction tx = Transaction.openOuter()) { final ItemVariant itemVariant = toItemVariant(resource); final long extracted = sourceStorage.extract(itemVariant, amount, tx); @@ -71,7 +72,7 @@ private void handleInventoryToGridScroll(final ItemResource itemResource, private void handleGridToInventoryScroll(final ItemResource itemResource, final Storage destinationStorage) { - gridService.extract(itemResource, GridExtractMode.SINGLE_RESOURCE, (resource, amount, action, source) -> { + gridOperations.extract(itemResource, GridExtractMode.SINGLE_RESOURCE, (resource, amount, action, source) -> { final ItemVariant itemVariant = toItemVariant(resource); try (Transaction tx = Transaction.openOuter()) { final long inserted = destinationStorage.insert(itemVariant, amount, tx); 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 988877404..0816073e8 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 @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; 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 e6e4b2763..566550c86 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,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridInsertPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridInsertPacket.java index cc397e629..a398baf28 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridInsertPacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/GridInsertPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; import net.fabricmc.fabric.api.networking.v1.PacketSender; 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 b33a7c9dc..a445c4e4f 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 @@ -9,6 +9,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.item.RegulatorUpgradeItem; +import com.refinedmods.refinedstorage2.platform.common.render.NetworkItemItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.render.model.ControllerModelPredicateProvider; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.CompositeClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.screen.tooltip.HelpClientTooltipComponent; @@ -67,6 +68,7 @@ public > void MenuScreens.register(type, factory::create); } })); + e.enqueueWork(ClientModInitializer::registerItemProperties); registerBlockEntityRenderer(); registerGridSynchronizers(); registerResourceRendering(); @@ -180,4 +182,17 @@ private static CompositeClientTooltipComponent createRegulatorUpgradeClientT help )); } + + private static void registerItemProperties() { + ItemProperties.register( + Items.INSTANCE.getWirelessGrid(), + NetworkItemItemPropertyFunction.NAME, + new NetworkItemItemPropertyFunction() + ); + ItemProperties.register( + Items.INSTANCE.getCreativeWirelessGrid(), + NetworkItemItemPropertyFunction.NAME, + new NetworkItemItemPropertyFunction() + ); + } } 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 72cc663d0..cb67f1fd6 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 @@ -33,6 +33,7 @@ public class ConfigImpl implements Config { private final SimpleEnergyUsageEntry detector; private final SimpleEnergyUsageEntry destructor; private final SimpleEnergyUsageEntry constructor; + private final WirelessGridEntry wirelessGrid; public ConfigImpl() { cable = new SimpleEnergyUsageEntryImpl("cable", "Cable", DefaultEnergyUsage.CABLE); @@ -54,6 +55,7 @@ public ConfigImpl() { detector = new SimpleEnergyUsageEntryImpl("detector", "Detector", DefaultEnergyUsage.DETECTOR); destructor = new SimpleEnergyUsageEntryImpl("destructor", "Destructor", DefaultEnergyUsage.DESTRUCTOR); constructor = new SimpleEnergyUsageEntryImpl("constructor", "Constructor", DefaultEnergyUsage.CONSTRUCTOR); + wirelessGrid = new WirelessGridEntryImpl(); spec = builder.build(); } @@ -136,6 +138,11 @@ public SimpleEnergyUsageEntry getConstructor() { return constructor; } + @Override + public WirelessGridEntry getWirelessGrid() { + return wirelessGrid; + } + private class SimpleEnergyUsageEntryImpl implements SimpleEnergyUsageEntry { private final ForgeConfigSpec.LongValue energyUsage; @@ -591,4 +598,46 @@ public long getRegulatorUpgradeEnergyUsage() { return regulatorUpgradeEnergyUsage.get(); } } + + private class WirelessGridEntryImpl implements WirelessGridEntry { + private final ForgeConfigSpec.BooleanValue useEnergy; + private final ForgeConfigSpec.LongValue energyCapacity; + private final ForgeConfigSpec.LongValue openEnergyUsage; + private final ForgeConfigSpec.LongValue extractEnergyUsage; + private final ForgeConfigSpec.LongValue insertEnergyUsage; + + WirelessGridEntryImpl() { + builder.push("wirelessGrid"); + useEnergy = builder.comment("Whether the Wireless Grid uses energy").define("useEnergy", true); + energyCapacity = builder.comment("The energy capacity of the Wireless Grid") + .defineInRange("energyCapacity", DefaultEnergyUsage.WIRELESS_GRID_CAPACITY, 0, Long.MAX_VALUE); + openEnergyUsage = builder.comment("The energy used by the Wireless Grid to open") + .defineInRange("openEnergyUsage", DefaultEnergyUsage.WIRELESS_GRID_OPEN, 0, Long.MAX_VALUE); + extractEnergyUsage = builder.comment("The energy used by the Wireless Grid to extract resources") + .defineInRange("extractEnergyUsage", DefaultEnergyUsage.WIRELESS_GRID_EXTRACT, 0, Long.MAX_VALUE); + insertEnergyUsage = builder.comment("The energy used by the Wireless Grid to insert resources") + .defineInRange("insertEnergyUsage", DefaultEnergyUsage.WIRELESS_GRID_INSERT, 0, Long.MAX_VALUE); + builder.pop(); + } + + public boolean getUseEnergy() { + return useEnergy.get(); + } + + public long getEnergyCapacity() { + return energyCapacity.get(); + } + + public long getOpenEnergyUsage() { + return openEnergyUsage.get(); + } + + public long getExtractEnergyUsage() { + return extractEnergyUsage.get(); + } + + public long getInsertEnergyUsage() { + return insertEnergyUsage.get(); + } + } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java index cd558bd41..95056229a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java @@ -2,6 +2,7 @@ import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.AbstractModInitializer; +import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.block.AbstractBaseBlock; import com.refinedmods.refinedstorage2.platform.common.block.entity.ControllerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.diskdrive.AbstractDiskDriveBlockEntity; @@ -13,10 +14,14 @@ import com.refinedmods.refinedstorage2.platform.common.content.MenuTypeFactory; import com.refinedmods.refinedstorage2.platform.common.content.RegistryCallback; import com.refinedmods.refinedstorage2.platform.common.internal.network.node.iface.externalstorage.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.item.CreativeItemEnergyProvider; import com.refinedmods.refinedstorage2.platform.common.item.RegulatorUpgradeItem; +import com.refinedmods.refinedstorage2.platform.common.item.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; import com.refinedmods.refinedstorage2.platform.common.util.TickHandler; import com.refinedmods.refinedstorage2.platform.forge.block.entity.ForgeDiskDriveBlockEntity; +import com.refinedmods.refinedstorage2.platform.forge.integration.energy.ForgeEnergyCapabilityProvider; +import com.refinedmods.refinedstorage2.platform.forge.integration.energy.ForgeEnergyItemEnergyProvider; import com.refinedmods.refinedstorage2.platform.forge.internal.grid.FluidGridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.forge.internal.grid.FluidGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.forge.internal.grid.ItemGridExtractionStrategy; @@ -40,6 +45,7 @@ import net.minecraft.core.Direction; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; +import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.Container; @@ -120,7 +126,7 @@ public ModInitializer() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegister); MinecraftForge.EVENT_BUS.addListener(this::registerWrenchingEvent); - MinecraftForge.EVENT_BUS.addGenericListener(BlockEntity.class, this::registerCapabilities); + MinecraftForge.EVENT_BUS.addGenericListener(BlockEntity.class, this::registerBlockEntityCapabilities); } private void registerAdditionalGridInsertionStrategyFactories() { @@ -128,10 +134,7 @@ private void registerAdditionalGridInsertionStrategyFactories() { } private void registerGridExtractionStrategyFactories() { - PlatformApi.INSTANCE.addGridExtractionStrategyFactory( - (containerMenu, player, gridServiceFactory, itemStorage) -> - new ItemGridExtractionStrategy(containerMenu, player, gridServiceFactory) - ); + PlatformApi.INSTANCE.addGridExtractionStrategyFactory(ItemGridExtractionStrategy::new); PlatformApi.INSTANCE.addGridExtractionStrategyFactory(FluidGridExtractionStrategy::new); } @@ -188,7 +191,31 @@ private void registerItems() { public boolean shouldCauseReequipAnimation(final ItemStack oldStack, final ItemStack newStack, final boolean slotChanged) { - return RegulatorUpgradeItem.allowNbtUpdateAnimation(oldStack, newStack); + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + }, + () -> new WirelessGridItem(new ForgeEnergyItemEnergyProvider()) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } + + @Override + public ICapabilityProvider initCapabilities(final ItemStack stack, @Nullable final CompoundTag tag) { + return new ForgeEnergyCapabilityProvider( + stack, + (int) Platform.INSTANCE.getConfig().getWirelessGrid().getEnergyCapacity() + ); + } + }, + () -> new WirelessGridItem(CreativeItemEnergyProvider.INSTANCE) { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } } ); @@ -274,7 +301,7 @@ public void registerWrenchingEvent(final PlayerInteractEvent.RightClickBlock e) } @SubscribeEvent - public void registerCapabilities(final AttachCapabilitiesEvent e) { + public void registerBlockEntityCapabilities(final AttachCapabilitiesEvent e) { if (e.getObject() instanceof ControllerBlockEntity controllerBlockEntity) { registerControllerEnergy(e, controllerBlockEntity); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ForgeEnergyCapabilityProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ForgeEnergyCapabilityProvider.java new file mode 100644 index 000000000..7c72772d0 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ForgeEnergyCapabilityProvider.java @@ -0,0 +1,29 @@ +package com.refinedmods.refinedstorage2.platform.forge.integration.energy; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.core.Direction; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.energy.IEnergyStorage; + +public class ForgeEnergyCapabilityProvider implements ICapabilityProvider { + private final LazyOptional capability; + + public ForgeEnergyCapabilityProvider(final ItemStack stack, final int energyCapacity) { + this.capability = LazyOptional.of(() -> new ItemEnergyStorage(stack, energyCapacity)); + } + + @Nonnull + @Override + public LazyOptional getCapability(@Nonnull final Capability cap, @Nullable final Direction direction) { + if (cap == ForgeCapabilities.ENERGY) { + return capability.cast(); + } + return LazyOptional.empty(); + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ForgeEnergyItemEnergyProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ForgeEnergyItemEnergyProvider.java new file mode 100644 index 000000000..ed0e2c866 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ForgeEnergyItemEnergyProvider.java @@ -0,0 +1,47 @@ +package com.refinedmods.refinedstorage2.platform.forge.integration.energy; + +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.PlayerSlotReference; +import com.refinedmods.refinedstorage2.platform.common.item.ItemEnergyProvider; + +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.energy.IEnergyStorage; + +public class ForgeEnergyItemEnergyProvider implements ItemEnergyProvider { + @Override + public boolean isEnabled() { + return Platform.INSTANCE.getConfig().getWirelessGrid().getUseEnergy(); + } + + @Override + public long getStored(final ItemStack stack) { + return stack.getCapability(ForgeCapabilities.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0); + } + + @Override + public long getCapacity(final ItemStack stack) { + return stack.getCapability(ForgeCapabilities.ENERGY).map(IEnergyStorage::getMaxEnergyStored).orElse(0); + } + + @Override + public void drain(final Player player, final PlayerSlotReference slotReference, final long amount) { + if (!isEnabled()) { + return; + } + final ItemStack stack = player.getInventory().getItem(slotReference.getSlotIndex()); + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent( + energyStorage -> energyStorage.extractEnergy((int) amount, false) + ); + } + + @Override + public ItemStack getAtCapacity(final ItemStack stack) { + final ItemStack copied = stack.copy(); + copied.getCapability(ForgeCapabilities.ENERGY).ifPresent( + energyStorage -> energyStorage.receiveEnergy(energyStorage.getMaxEnergyStored(), false) + ); + return copied; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ItemEnergyStorage.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ItemEnergyStorage.java new file mode 100644 index 000000000..21396b5de --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/energy/ItemEnergyStorage.java @@ -0,0 +1,37 @@ +package com.refinedmods.refinedstorage2.platform.forge.integration.energy; + +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.energy.EnergyStorage; + +public class ItemEnergyStorage extends EnergyStorage { + private static final String TAG_ENERGY = "energy"; + + private final ItemStack stack; + + public ItemEnergyStorage(final ItemStack stack, final int capacity) { + super(capacity, capacity, capacity); + this.stack = stack; + if (stack.getTag() != null) { + this.energy = stack.getTag().getInt(TAG_ENERGY); + } + } + + @Override + public int receiveEnergy(final int maxReceive, final boolean simulate) { + final int received = super.receiveEnergy(maxReceive, simulate); + if (received > 0 && !simulate) { + stack.getOrCreateTag().putInt(TAG_ENERGY, getEnergyStored()); + } + return received; + } + + @Override + public int extractEnergy(final int maxExtract, final boolean simulate) { + final int extracted = super.extractEnergy(maxExtract, simulate); + if (extracted > 0 && !simulate) { + stack.getOrCreateTag().putInt(TAG_ENERGY, getEnergyStored()); + } + return extracted; + } +} + diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridExtractionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridExtractionStrategy.java index 985c8f37c..16becd7e7 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridExtractionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridExtractionStrategy.java @@ -1,17 +1,18 @@ package com.refinedmods.refinedstorage2.platform.forge.internal.grid; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; 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.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import javax.annotation.Nullable; @@ -32,18 +33,17 @@ public class FluidGridExtractionStrategy implements GridExtractionStrategy { private static final ItemResource BUCKET_ITEM_RESOURCE = new ItemResource(Items.BUCKET, null); private final AbstractContainerMenu menu; - private final GridService gridService; + private final GridOperations gridOperations; private final PlayerMainInvWrapper playerInventoryStorage; private final Storage itemStorage; public FluidGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory, - final Storage itemStorage) { + final Grid grid) { this.menu = containerMenu; - this.gridService = gridServiceFactory.createForFluid(new PlayerActor(player)); + this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); this.playerInventoryStorage = new PlayerMainInvWrapper(player.getInventory()); - this.itemStorage = itemStorage; + this.itemStorage = grid.getItemStorage(); } @Override @@ -78,7 +78,7 @@ private void extract(final FluidResource fluidResource, if (destination == null) { return; // shouldn't happen } - gridService.extract(fluidResource, mode, (resource, amount, action, source) -> { + gridOperations.extract(fluidResource, mode, (resource, amount, action, source) -> { final int inserted = destination.fill(toFluidStack(resource, amount), toFluidAction(action)); if (action == Action.EXECUTE) { extractSourceBucket(bucketFromInventory, source); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridInsertionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridInsertionStrategy.java index 53d921d5a..18d394ed9 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridInsertionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/FluidGridInsertionStrategy.java @@ -1,12 +1,13 @@ package com.refinedmods.refinedstorage2.platform.forge.internal.grid; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import javax.annotation.Nullable; @@ -23,13 +24,11 @@ public class FluidGridInsertionStrategy implements GridInsertionStrategy { private final AbstractContainerMenu menu; - private final GridService gridService; + private final GridOperations gridOperations; - public FluidGridInsertionStrategy(final AbstractContainerMenu menu, - final Player player, - final PlatformGridServiceFactory serviceFactory) { + public FluidGridInsertionStrategy(final AbstractContainerMenu menu, final Player player, final Grid grid) { this.menu = menu; - this.gridService = serviceFactory.createForFluid(new PlayerActor(player)); + this.gridOperations = grid.createOperations(StorageChannelTypes.FLUID, new PlayerActor(player)); } @Override @@ -43,7 +42,7 @@ public boolean onInsert(final GridInsertMode insertMode, final boolean tryAltern return false; } final FluidResource fluidResource = ofFluidStack(extractableResource); - gridService.insert(fluidResource, insertMode, (resource, amount, action, source) -> { + gridOperations.insert(fluidResource, insertMode, (resource, amount, action, source) -> { final FluidStack toDrain = toFluidStack(resource, amount == Long.MAX_VALUE ? Integer.MAX_VALUE : amount); final FluidStack drained = cursorStorage.drain(toDrain, toFluidAction(action)); if (action == Action.EXECUTE) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridExtractionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridExtractionStrategy.java index b385741f0..ccf65d8b9 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridExtractionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridExtractionStrategy.java @@ -1,13 +1,14 @@ package com.refinedmods.refinedstorage2.platform.forge.internal.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.internal.storage.InteractionCoordinates; import com.refinedmods.refinedstorage2.platform.forge.internal.storage.ItemHandlerInsertableStorage; @@ -17,14 +18,14 @@ import net.minecraftforge.items.wrapper.PlayerMainInvWrapper; public class ItemGridExtractionStrategy implements GridExtractionStrategy { - private final GridService gridService; + private final GridOperations gridOperations; private final PlayerMainInvWrapper playerInventoryStorage; private final CursorStorage playerCursorStorage; public ItemGridExtractionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory) { - this.gridService = gridServiceFactory.createForItem(new PlayerActor(player)); + final Grid grid) { + this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); this.playerInventoryStorage = new PlayerMainInvWrapper(player.getInventory()); this.playerCursorStorage = new CursorStorage(containerMenu); } @@ -36,7 +37,7 @@ public boolean onExtract(final PlatformStorageChannelType storageChannelT final boolean cursor) { if (resource instanceof ItemResource itemResource) { final IItemHandler handler = cursor ? playerCursorStorage : playerInventoryStorage; - gridService.extract( + gridOperations.extract( itemResource, extractMode, new ItemHandlerInsertableStorage(InteractionCoordinates.ofItemHandler(handler), AmountOverride.NONE) diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridInsertionStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridInsertionStrategy.java index 350975dc0..90125ebf8 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridInsertionStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridInsertionStrategy.java @@ -1,12 +1,13 @@ package com.refinedmods.refinedstorage2.platform.forge.internal.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; +import com.refinedmods.refinedstorage2.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.internal.storage.InteractionCoordinates; import com.refinedmods.refinedstorage2.platform.forge.internal.storage.ItemHandlerExtractableStorage; @@ -21,14 +22,14 @@ public class ItemGridInsertionStrategy implements GridInsertionStrategy { private final AbstractContainerMenu containerMenu; - private final GridService gridService; + private final GridOperations gridOperations; private final CursorStorage playerCursorStorage; public ItemGridInsertionStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory) { + final Grid grid) { this.containerMenu = containerMenu; - this.gridService = gridServiceFactory.createForItem(new PlayerActor(player)); + this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); this.playerCursorStorage = new CursorStorage(containerMenu); } @@ -39,7 +40,7 @@ public boolean onInsert(final GridInsertMode insertMode, final boolean tryAltern return false; } final ItemResource itemResource = new ItemResource(carried.getItem(), carried.getTag()); - gridService.insert( + gridOperations.insert( itemResource, insertMode, new ItemHandlerExtractableStorage( @@ -63,7 +64,7 @@ public boolean onTransfer(final int slotIndex) { return false; } final ItemResource itemResource = ofItemStack(itemStackInSlot); - gridService.insert( + gridOperations.insert( itemResource, GridInsertMode.ENTIRE_RESOURCE, new ItemHandlerExtractableStorage( diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridScrollingStrategy.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridScrollingStrategy.java index 915fb7d05..a0a4579fe 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridScrollingStrategy.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/internal/grid/ItemGridScrollingStrategy.java @@ -1,15 +1,16 @@ package com.refinedmods.refinedstorage2.platform.forge.internal.grid; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridService; +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.platform.api.grid.Grid; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollingStrategy; -import com.refinedmods.refinedstorage2.platform.api.grid.PlatformGridServiceFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.AmountOverride; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.forge.internal.storage.InteractionCoordinates; import com.refinedmods.refinedstorage2.platform.forge.internal.storage.ItemHandlerExtractableStorage; import com.refinedmods.refinedstorage2.platform.forge.internal.storage.ItemHandlerInsertableStorage; @@ -23,15 +24,15 @@ import net.minecraftforge.items.wrapper.RangedWrapper; public class ItemGridScrollingStrategy implements GridScrollingStrategy { - private final GridService gridService; + private final GridOperations gridOperations; private final Inventory playerInventory; private final PlayerMainInvWrapper playerInventoryStorage; private final CursorStorage playerCursorStorage; public ItemGridScrollingStrategy(final AbstractContainerMenu containerMenu, final Player player, - final PlatformGridServiceFactory gridServiceFactory) { - this.gridService = gridServiceFactory.createForItem(new PlayerActor(player)); + final Grid grid) { + this.gridOperations = grid.createOperations(StorageChannelTypes.ITEM, new PlayerActor(player)); this.playerInventory = player.getInventory(); this.playerInventoryStorage = new PlayerMainInvWrapper(playerInventory); this.playerCursorStorage = new CursorStorage(containerMenu); @@ -57,7 +58,7 @@ public boolean onScroll(final PlatformStorageChannelType storageChannelTy } private void handleInventoryToGridScroll(final ItemResource itemResource, final IItemHandler sourceStorage) { - gridService.insert( + gridOperations.insert( itemResource, GridInsertMode.SINGLE_RESOURCE, new ItemHandlerExtractableStorage( @@ -68,7 +69,7 @@ private void handleInventoryToGridScroll(final ItemResource itemResource, final } private void handleGridToInventoryScroll(final ItemResource itemResource, final IItemHandler destinationStorage) { - gridService.extract( + gridOperations.extract( itemResource, GridExtractMode.SINGLE_RESOURCE, new ItemHandlerInsertableStorage( diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java index de9677c1b..0da99cec5 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridExtractPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridExtractPacket.java index 9efffc86e..2a3d73130 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridExtractPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridExtractPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; -import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridExtractMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java index 137b261aa..628caf98b 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/GridInsertPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; -import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; +import com.refinedmods.refinedstorage2.api.grid.operations.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategy; import java.util.function.Supplier; diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/TrackedResourceAmount.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/TrackedResourceAmount.java new file mode 100644 index 000000000..9ceaee775 --- /dev/null +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/TrackedResourceAmount.java @@ -0,0 +1,12 @@ +package com.refinedmods.refinedstorage2.api.storage; + +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; + +import javax.annotation.Nullable; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.0") +public record TrackedResourceAmount(ResourceAmount resourceAmount, @Nullable TrackedResource trackedResource) { +}