From 1c9d66d32ad6877a98957332b3af0965f6912b0a Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 16 Mar 2024 21:11:38 +0100 Subject: [PATCH 1/7] refactor: move network components to their related package instead of one global package --- .../refinedstorage2/api/network/Network.java | 1 - .../network/{component => }/NetworkComponent.java | 8 +------- .../EnergyNetworkComponent.java | 4 +++- .../{component => node}/GraphNetworkComponent.java | 3 ++- .../node/container/NetworkNodeContainer.java | 3 ++- .../StorageNetworkComponent.java | 3 ++- .../{component => storage}/StorageProvider.java | 2 +- .../{component => storage}/package-info.java | 2 +- .../network/test/NetworkTestExtension.java | 4 ++-- .../network/test/NetworkTestFixtures.java | 14 +++++++------- .../network/test/NetworkTestExtensionTest.java | 6 +++--- .../api/network/impl/NetworkBuilderImpl.java | 2 +- .../api/network/impl/NetworkFactory.java | 2 +- .../api/network/impl/NetworkImpl.java | 2 +- .../api/network/impl/component/package-info.java | 7 ------- .../EnergyNetworkComponentImpl.java | 5 ++--- .../GraphNetworkComponentImpl.java | 4 ++-- .../detector/AbstractDetectorAmountStrategy.java | 2 +- .../exporter/ExporterTransferStrategyImpl.java | 2 +- .../ExternalStorageNetworkNode.java | 2 +- .../network/impl/node/grid/GridNetworkNode.java | 2 +- .../impl/node/iface/InterfaceNetworkNode.java | 2 +- .../importer/ImporterTransferStrategyImpl.java | 2 +- .../node/multistorage/MultiStorageNetworkNode.java | 2 +- .../impl/node/storage/StorageNetworkNode.java | 2 +- .../network/impl/storage/AbstractNetworkNode.java | 2 +- .../impl/storage/AbstractStorageNetworkNode.java | 2 +- .../StorageNetworkComponentImpl.java | 6 +++--- .../impl/AbstractNetworkBuilderImplTest.java | 2 +- .../impl/InitializeNetworkBuilderImplTest.java | 2 +- .../network/impl/RemoveNetworkBuilderImplTest.java | 2 +- .../network/impl/UpdateNetworkBuilderImplTest.java | 2 +- .../EnergyNetworkComponentImplTest.java | 5 ++--- .../GraphNetworkComponentImplTest.java | 5 ++--- .../network/impl/node/SimpleNetworkNodeTest.java | 2 +- .../exporter/AbstractExporterNetworkNodeTest.java | 2 +- .../impl/node/iface/InterfaceNetworkNodeTest.java | 2 +- .../node/importer/ImporterNetworkNodeTest.java | 2 +- .../StorageNetworkComponentImplTest.java | 4 ++-- .../refinedstorage2/platform/api/PlatformApi.java | 2 +- .../platform/api/PlatformApiProxy.java | 2 +- .../platform/common/AbstractModInitializer.java | 10 +++++----- .../platform/common/PlatformApiImpl.java | 2 +- .../AbstractItemConstructorStrategy.java | 2 +- .../BlockBreakDestructorStrategy.java | 2 +- .../FluidBreakDestructorStrategy.java | 2 +- .../ItemPickupDestructorStrategy.java | 2 +- .../PlaceFluidConstructorStrategy.java | 2 +- .../common/grid/AbstractGridBlockEntity.java | 2 +- .../common/grid/CraftingGridBlockEntity.java | 2 +- .../common/grid/CraftingGridSourceImpl.java | 2 +- .../platform/common/grid/WirelessGrid.java | 4 ++-- .../networking/NetworkTransmitterBlockEntity.java | 2 +- .../FluidStorageMonitorExtractionStrategy.java | 2 +- .../FluidStorageMonitorInsertionStrategy.java | 2 +- .../ItemStorageMonitorExtractionStrategy.java | 2 +- .../ItemStorageMonitorInsertionStrategy.java | 2 +- .../storagemonitor/StorageMonitorBlockEntity.java | 2 +- .../NetworkNodeContainerBlockEntityImpl.java | 2 +- .../bounditem/NetworkBoundItemSessionImpl.java | 2 +- .../component/PlatformStorageNetworkComponent.java | 2 +- 61 files changed, 85 insertions(+), 97 deletions(-) rename refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/{component => }/NetworkComponent.java (81%) rename refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/{component => energy}/EnergyNetworkComponent.java (65%) rename refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/{component => node}/GraphNetworkComponent.java (89%) rename refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/{component => storage}/StorageNetworkComponent.java (79%) rename refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/{component => storage}/StorageProvider.java (94%) rename refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/{component => storage}/package-info.java (76%) delete mode 100644 refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/package-info.java rename refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/{component => energy}/EnergyNetworkComponentImpl.java (82%) rename refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/{component => node}/GraphNetworkComponentImpl.java (96%) rename refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/{component => storage}/StorageNetworkComponentImpl.java (88%) rename refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/{component => energy}/EnergyNetworkComponentImplTest.java (92%) rename refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/{component => node}/GraphNetworkComponentImplTest.java (97%) rename refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/{component => storage}/StorageNetworkComponentImplTest.java (96%) diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/Network.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/Network.java index a0dba68c0..1eaec0ac4 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/Network.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/Network.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage2.api.network; import com.refinedmods.refinedstorage2.api.core.component.ComponentAccessor; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import java.util.Set; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/NetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/NetworkComponent.java similarity index 81% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/NetworkComponent.java rename to refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/NetworkComponent.java index 1d669a715..6795743a1 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/NetworkComponent.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/NetworkComponent.java @@ -1,6 +1,5 @@ -package com.refinedmods.refinedstorage2.api.network.component; +package com.refinedmods.refinedstorage2.api.network; -import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import java.util.Set; @@ -10,22 +9,17 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.1") public interface NetworkComponent { default void onContainerAdded(NetworkNodeContainer container) { - } default void onContainerRemoved(NetworkNodeContainer container) { - } default void onNetworkRemoved() { - } default void onNetworkSplit(Set networks) { - } default void onNetworkMergedWith(Network newMainNetwork) { - } } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/EnergyNetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/energy/EnergyNetworkComponent.java similarity index 65% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/EnergyNetworkComponent.java rename to refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/energy/EnergyNetworkComponent.java index c8f6067b3..59f01fd78 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/EnergyNetworkComponent.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/energy/EnergyNetworkComponent.java @@ -1,4 +1,6 @@ -package com.refinedmods.refinedstorage2.api.network.component; +package com.refinedmods.refinedstorage2.api.network.energy; + +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import org.apiguardian.api.API; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/GraphNetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/GraphNetworkComponent.java similarity index 89% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/GraphNetworkComponent.java rename to refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/GraphNetworkComponent.java index 3fd9c1071..4da9fa7f0 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/GraphNetworkComponent.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/GraphNetworkComponent.java @@ -1,5 +1,6 @@ -package com.refinedmods.refinedstorage2.api.network.component; +package com.refinedmods.refinedstorage2.api.network.node; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import java.util.Set; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java index 3f7aaf65d..5964ff5ef 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.node.container; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import javax.annotation.Nullable; @@ -18,7 +19,7 @@ public interface NetworkNodeContainer { * If it changes after adding it into the graph, the container would not be removed from the key index when the * container is removed! * The container can be queried by - * {@link com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent#getContainer(Object)}. + * {@link GraphNetworkComponent#getContainer(Object)}. * * @return the key, or null if indexing is not required */ 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/storage/StorageNetworkComponent.java similarity index 79% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageNetworkComponent.java rename to refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageNetworkComponent.java index 80abdd04e..7b6a9ad0d 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/storage/StorageNetworkComponent.java @@ -1,5 +1,6 @@ -package com.refinedmods.refinedstorage2.api.network.component; +package com.refinedmods.refinedstorage2.api.network.storage; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageProvider.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageProvider.java similarity index 94% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageProvider.java rename to refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageProvider.java index efb73f178..ee7e1cad5 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/StorageProvider.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageProvider.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.network.component; +package com.refinedmods.refinedstorage2.api.network.storage; import com.refinedmods.refinedstorage2.api.storage.Storage; diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/package-info.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/package-info.java similarity index 76% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/package-info.java rename to refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/package-info.java index 6eb332e32..8ed1419ba 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/component/package-info.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.api.network.component; +package com.refinedmods.refinedstorage2.api.network.storage; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java index 7eabe5bba..96c5afaa1 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtension.java @@ -2,13 +2,13 @@ import com.refinedmods.refinedstorage2.api.core.Action; 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.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.api.network.impl.NetworkImpl; import com.refinedmods.refinedstorage2.api.network.impl.energy.EnergyStorageImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.controller.ControllerNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.nodefactory.NetworkNodeFactory; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java index c32013a72..71914cc5f 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTestFixtures.java @@ -2,13 +2,13 @@ import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.impl.component.EnergyNetworkComponentImpl; -import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponentImpl; -import com.refinedmods.refinedstorage2.api.network.impl.component.StorageNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.energy.EnergyNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.impl.node.GraphNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; public final class NetworkTestFixtures { diff --git a/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java b/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java index 45af0666f..fa703a9b1 100644 --- a/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java +++ b/refinedstorage2-network-test/src/test/java/com/refinedmods/refinedstorage2/network/test/NetworkTestExtensionTest.java @@ -1,13 +1,13 @@ package com.refinedmods.refinedstorage2.network.test; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.MultiStorageNetworkNodeFactory; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkBuilderImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkBuilderImpl.java index 5023859cc..52404150c 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkBuilderImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkBuilderImpl.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.api.network.Connections; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.NetworkBuilder; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkFactory.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkFactory.java index 9cf601583..e03c4d389 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkFactory.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkFactory.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; public class NetworkFactory { private final ComponentMapFactory componentMapFactory; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkImpl.java index b9e1378d0..fd14afd8c 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/NetworkImpl.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.component.ComponentMap; import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import java.util.Set; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/package-info.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/package-info.java deleted file mode 100644 index af8789144..000000000 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -@ParametersAreNonnullByDefault -@FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.api.network.impl.component; - -import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/EnergyNetworkComponentImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImpl.java similarity index 82% rename from refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/EnergyNetworkComponentImpl.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImpl.java index 142afe2c2..e9bfe0a3b 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/EnergyNetworkComponentImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImpl.java @@ -1,9 +1,8 @@ -package com.refinedmods.refinedstorage2.api.network.impl.component; +package com.refinedmods.refinedstorage2.api.network.impl.energy; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.api.network.impl.energy.CompositeEnergyStorage; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; public class EnergyNetworkComponentImpl implements EnergyNetworkComponent { diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/GraphNetworkComponentImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/GraphNetworkComponentImpl.java similarity index 96% rename from refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/GraphNetworkComponentImpl.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/GraphNetworkComponentImpl.java index 9ce369dc1..8abdde984 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/GraphNetworkComponentImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/GraphNetworkComponentImpl.java @@ -1,7 +1,7 @@ -package com.refinedmods.refinedstorage2.api.network.impl.component; +package com.refinedmods.refinedstorage2.api.network.impl.node; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import java.util.Collections; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java index 0266f5c37..84000d748 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/AbstractDetectorAmountStrategy.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.detector; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; public abstract class AbstractDetectorAmountStrategy implements DetectorAmountStrategy { diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java index 587f0201f..086e9250c 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterTransferStrategyImpl.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.exporter; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java index 6d4d66bb2..7ea8a845b 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage; -import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.externalstorage.ExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorage; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageRepository; 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 255721c6c..1df665710 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 @@ -4,8 +4,8 @@ import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManager; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManagerImpl; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.Actor; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java index 5ebb5580e..95a969da1 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNode.java @@ -1,11 +1,11 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExposedExternalStorage; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.externalstorage.InterfaceExternalStorageProvider; import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterTransferStrategyImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterTransferStrategyImpl.java index eaf157014..bd343045f 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterTransferStrategyImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterTransferStrategyImpl.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.importer; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.Filter; import com.refinedmods.refinedstorage2.api.storage.Actor; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java index 667f40117..463778f84 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage; -import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider; import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.StorageState; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java index 6b0b57a45..ca7e2773f 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.storage; -import com.refinedmods.refinedstorage2.api.network.component.StorageProvider; import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider; import com.refinedmods.refinedstorage2.api.storage.Storage; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java index 8a6955d77..62668a51e 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.storage; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractStorageNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractStorageNetworkNode.java index 3712bbe59..695e0a26f 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractStorageNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractStorageNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.storage; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.Filter; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; 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/storage/StorageNetworkComponentImpl.java similarity index 88% rename from refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImpl.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImpl.java index 27f9c57a3..6e25cc557 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/storage/StorageNetworkComponentImpl.java @@ -1,8 +1,8 @@ -package com.refinedmods.refinedstorage2.api.network.impl.component; +package com.refinedmods.refinedstorage2.api.network.impl.storage; -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.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider; import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/AbstractNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/AbstractNetworkBuilderImplTest.java index 756321467..7baf1d54b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/AbstractNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/AbstractNetworkBuilderImplTest.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.NetworkBuilder; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/InitializeNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/InitializeNetworkBuilderImplTest.java index 76f4d1e9a..4fdfe747f 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/InitializeNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/InitializeNetworkBuilderImplTest.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import org.junit.jupiter.api.Test; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/RemoveNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/RemoveNetworkBuilderImplTest.java index 16aeb3b0d..d83d71a2a 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/RemoveNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/RemoveNetworkBuilderImplTest.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import java.util.List; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/UpdateNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/UpdateNetworkBuilderImplTest.java index deba09825..bfa4da26f 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/UpdateNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/UpdateNetworkBuilderImplTest.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import java.util.Set; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/EnergyNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImplTest.java similarity index 92% rename from refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/EnergyNetworkComponentImplTest.java rename to refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImplTest.java index 784282354..e7ca16904 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/EnergyNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImplTest.java @@ -1,8 +1,7 @@ -package com.refinedmods.refinedstorage2.api.network.impl.component; +package com.refinedmods.refinedstorage2.api.network.impl.energy; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.impl.energy.EnergyStorageImpl; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.controller.ControllerNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/GraphNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/GraphNetworkComponentImplTest.java similarity index 97% rename from refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/GraphNetworkComponentImplTest.java rename to refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/GraphNetworkComponentImplTest.java index 901e04bb8..b577f37c2 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/GraphNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/GraphNetworkComponentImplTest.java @@ -1,8 +1,7 @@ -package com.refinedmods.refinedstorage2.api.network.impl.component; +package com.refinedmods.refinedstorage2.api.network.impl.node; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.NetworkImpl; -import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNodeTest.java index 2adab7ad3..cb3d53eb9 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNodeTest.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java index e8f24c153..e36a0c7f9 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/AbstractExporterNetworkNodeTest.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.exporter; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java index 3e995a5ca..7365d7687 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceNetworkNodeTest.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java index 870b03c00..03e491b57 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.importer; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; 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/storage/StorageNetworkComponentImplTest.java similarity index 96% rename from refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/component/StorageNetworkComponentImplTest.java rename to refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java index c4720c52e..0e8246008 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/storage/StorageNetworkComponentImplTest.java @@ -1,10 +1,10 @@ -package com.refinedmods.refinedstorage2.api.network.impl.component; +package com.refinedmods.refinedstorage2.api.network.impl.storage; import com.refinedmods.refinedstorage2.api.core.Action; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.NetworkImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; 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 74ce585f4..50b2d335d 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 @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.constructordestructor.ConstructorStrategyFactory; 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 840eebc04..0e1fb87cf 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 @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.api.constructordestructor.ConstructorStrategyFactory; 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 e692aaa46..400979c2c 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 @@ -1,11 +1,11 @@ package com.refinedmods.refinedstorage2.platform.common; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.impl.component.EnergyNetworkComponentImpl; -import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.energy.EnergyNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.impl.node.GraphNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.PlatformApiProxy; import com.refinedmods.refinedstorage2.platform.api.upgrade.AbstractUpgradeItem; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index 07d5805d0..c8185d7ea 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.NetworkBuilder; -import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent; +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; import com.refinedmods.refinedstorage2.api.network.impl.NetworkBuilderImpl; import com.refinedmods.refinedstorage2.api.network.impl.NetworkFactory; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java index deaff8a3c..fd1086858 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/AbstractItemConstructorStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java index 0b15939a8..923363145 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/BlockBreakDestructorStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.filter.Filter; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java index 74bdc3a7b..f258547be 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/FluidBreakDestructorStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.filter.Filter; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java index b010c19fc..43c6a13e8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/ItemPickupDestructorStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.filter.Filter; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java index b44515091..16cd1b25c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/constructordestructor/PlaceFluidConstructorStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java index 51277a021..a5d0b50e5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridBlockEntity.java @@ -2,9 +2,9 @@ import com.refinedmods.refinedstorage2.api.grid.operations.GridOperations; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; -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.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java index bd48406f7..e331a52e4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridBlockEntity.java @@ -2,8 +2,8 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.platform.api.storage.PlayerActor; import com.refinedmods.refinedstorage2.platform.common.Platform; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java index b6a27e6dc..7fad1dd98 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridSourceImpl.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.grid; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java index 4389dadac..c9a66bada 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGrid.java @@ -5,8 +5,8 @@ import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManager; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManagerImpl; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.NoopStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java index 03adbb4bf..295f425cd 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterBlockEntity.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.networking; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; import com.refinedmods.refinedstorage2.platform.common.Platform; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java index 87329091f..4d941915c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorExtractionStrategy.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.storagemonitor; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.TransferHelper; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java index 1c428973b..3929d4a31 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/FluidStorageMonitorInsertionStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java index 915d9ce36..5a91d2740 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorExtractionStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java index 2eb65b710..63b251f10 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/ItemStorageMonitorInsertionStrategy.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java index 9e76ff199..e9b4fac46 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storagemonitor/StorageMonitorBlockEntity.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.storagemonitor; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java index 0ee9dbf3f..47e629a7c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeContainerBlockEntityImpl.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.network.AbstractNetworkNodeContainerBlockEntity; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/bounditem/NetworkBoundItemSessionImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/bounditem/NetworkBoundItemSessionImpl.java index a1ffad1c5..5011671a2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/bounditem/NetworkBoundItemSessionImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/bounditem/NetworkBoundItemSessionImpl.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.platform.api.support.network.PlatformNetworkNodeContainer; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.NetworkBoundItemSession; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/PlatformStorageNetworkComponent.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/PlatformStorageNetworkComponent.java index 2dc393e0e..879384f6d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/PlatformStorageNetworkComponent.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/component/PlatformStorageNetworkComponent.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network.component; -import com.refinedmods.refinedstorage2.api.network.impl.component.StorageNetworkComponentImpl; +import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; From 4a57de7e3e5c07b5146e5adfc994f87620a43bd3 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 16 Mar 2024 21:39:49 +0100 Subject: [PATCH 2/7] feat: security primitives --- .../node/container/NetworkNodeContainer.java | 3 +- .../api/network/security/Operation.java | 7 ++++ .../api/network/security/SecurityActor.java | 7 ++++ .../network/security/SecurityDecision.java | 19 +++++++++ .../security/SecurityDecisionProvider.java | 8 ++++ .../security/SecurityNetworkComponent.java | 10 +++++ .../api/network/security/package-info.java | 7 ++++ .../SecurityNetworkComponentImpl.java | 42 +++++++++++++++++++ .../network/impl/security/package-info.java | 7 ++++ .../SecurityNetworkComponentImplTest.java | 36 ++++++++++++++++ 10 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Operation.java create mode 100644 refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityActor.java create mode 100644 refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecision.java create mode 100644 refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java create mode 100644 refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java create mode 100644 refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/package-info.java create mode 100644 refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java create mode 100644 refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/package-info.java create mode 100644 refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java index 5964ff5ef..1bbc43a2b 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/node/container/NetworkNodeContainer.java @@ -18,8 +18,7 @@ public interface NetworkNodeContainer { * The key must be kept stable, and must stay the same for the lifetime of the container. * If it changes after adding it into the graph, the container would not be removed from the key index when the * container is removed! - * The container can be queried by - * {@link GraphNetworkComponent#getContainer(Object)}. + * The container can be queried by {@link GraphNetworkComponent#getContainer(Object)}. * * @return the key, or null if indexing is not required */ diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Operation.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Operation.java new file mode 100644 index 000000000..4089f95cc --- /dev/null +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Operation.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage2.api.network.security; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +public interface Operation { +} diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityActor.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityActor.java new file mode 100644 index 000000000..07514890c --- /dev/null +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityActor.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage2.api.network.security; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +public interface SecurityActor { +} diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecision.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecision.java new file mode 100644 index 000000000..74f0ab94f --- /dev/null +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecision.java @@ -0,0 +1,19 @@ +package com.refinedmods.refinedstorage2.api.network.security; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +public enum SecurityDecision { + /** + * Allow the operation. + */ + ALLOW, + /** + * Deny the operation. + */ + DENY, + /** + * Pass the decision to the next {@link SecurityDecisionProvider}. + */ + PASS +} diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java new file mode 100644 index 000000000..a8e540744 --- /dev/null +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java @@ -0,0 +1,8 @@ +package com.refinedmods.refinedstorage2.api.network.security; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +public interface SecurityDecisionProvider { + SecurityDecision isAllowed(Operation operation, SecurityActor actor); +} diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java new file mode 100644 index 000000000..ecae20e11 --- /dev/null +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java @@ -0,0 +1,10 @@ +package com.refinedmods.refinedstorage2.api.network.security; + +import com.refinedmods.refinedstorage2.api.network.NetworkComponent; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +public interface SecurityNetworkComponent extends NetworkComponent { + boolean isAllowed(Operation operation, SecurityActor actor); +} diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/package-info.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/package-info.java new file mode 100644 index 000000000..225161f99 --- /dev/null +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.api.network.security; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java new file mode 100644 index 000000000..28c647db7 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java @@ -0,0 +1,42 @@ +package com.refinedmods.refinedstorage2.api.network.impl.security; + +import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; +import com.refinedmods.refinedstorage2.api.network.security.Operation; +import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; +import com.refinedmods.refinedstorage2.api.network.security.SecurityDecision; +import com.refinedmods.refinedstorage2.api.network.security.SecurityDecisionProvider; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; + +import java.util.HashSet; +import java.util.Set; + +public class SecurityNetworkComponentImpl implements SecurityNetworkComponent { + private final Set providers = new HashSet<>(); + + @Override + public void onContainerAdded(final NetworkNodeContainer container) { + if (container instanceof SecurityDecisionProvider provider) { + providers.add(provider); + } + } + + @Override + public void onContainerRemoved(final NetworkNodeContainer container) { + if (container instanceof SecurityDecisionProvider provider) { + providers.remove(provider); + } + } + + @Override + public boolean isAllowed(final Operation operation, final SecurityActor actor) { + for (final SecurityDecisionProvider provider : providers) { + final SecurityDecision decision = provider.isAllowed(operation, actor); + if (decision == SecurityDecision.DENY) { + return false; + } else if (decision == SecurityDecision.ALLOW) { + return true; + } + } + return true; + } +} diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/package-info.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/package-info.java new file mode 100644 index 000000000..ea536fa20 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.api.network.impl.security; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java new file mode 100644 index 000000000..a0205f01e --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.api.network.impl.security; + +import com.refinedmods.refinedstorage2.api.network.security.Operation; +import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import static org.assertj.core.api.Assertions.assertThat; + +class SecurityNetworkComponentImplTest { + SecurityNetworkComponent sut; + + @BeforeEach + void setUp() { + sut = new SecurityNetworkComponentImpl(); + } + + @EnumSource(TestPermissions.class) + @ParameterizedTest + void everythingIsAllowedByDefault(final TestPermissions permission) { + // Act & assert + assertThat(sut.isAllowed(permission, TestActors.X)).isTrue(); + assertThat(sut.isAllowed(permission, TestActors.Y)).isTrue(); + } + + enum TestPermissions implements Operation { + A, B + } + + enum TestActors implements SecurityActor { + X, Y + } +} From 95f14db7497daca0b09a1747db8c33556d1d0d0a Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 17 Mar 2024 15:21:50 +0100 Subject: [PATCH 3/7] docs: note about crowdin --- .github/CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f8c8c5b5c..875b35587 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -42,6 +42,10 @@ Valid examples are: - `fix/GH-123/add-branch-linting` - `docs/GH-123/cleanup` +## Translations + +If you want to contribute to the translations of this project, please use [Crowdin](https://crowdin.com/project/refined-storage-2). + ## Versioning This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). From d47cae747d1f89d4ac62702e704335ee65a26628 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 17 Mar 2024 15:21:55 +0100 Subject: [PATCH 4/7] feat: security card item --- .../common/AbstractModInitializer.java | 3 +++ .../platform/common/content/ContentIds.java | 1 + .../common/content/CreativeModeTabItems.java | 1 + .../platform/common/content/Items.java | 11 ++++++++ .../common/security/SecurityCardItem.java | 14 ++++++++++ .../SecurityCardItemPropertyFunction.java | 24 ++++++++++++++++++ .../common/security/package-info.java | 7 +++++ .../assets/refinedstorage2/lang/en_us.json | 1 + .../models/item/security_card.json | 17 +++++++++++++ .../models/item/security_card/active.json | 6 +++++ .../models/item/security_card/inactive.json | 6 +++++ .../textures/gui/security_card.png | Bin 0 -> 1142 bytes .../textures/item/security_card/active.png | Bin 0 -> 1602 bytes .../textures/item/security_card/inactive.png | Bin 0 -> 1603 bytes .../recipes/security_card.json | 22 ++++++++++++++++ .../fabric/ClientModInitializerImpl.java | 6 +++++ .../platform/forge/ClientModInitializer.java | 6 +++++ 17 files changed, 125 insertions(+) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItemPropertyFunction.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/package-info.java create mode 100755 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/active.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/inactive.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/security_card.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/security_card/active.png create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/security_card/inactive.png create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/security_card.json 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 400979c2c..52e60ce8c 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 @@ -55,6 +55,7 @@ import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes; @@ -151,6 +152,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.QUARTZ_ENRICHED_IRON; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.QUARTZ_ENRICHED_IRON_BLOCK; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.REGULATOR_UPGRADE; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SECURITY_CARD; 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; @@ -360,6 +362,7 @@ private void registerSimpleItems(final RegistryCallback callback) { ConfigurationCardItem::new )); Items.INSTANCE.setNetworkCard(callback.register(ContentIds.NETWORK_CARD, NetworkCardItem::new)); + Items.INSTANCE.setSecurityCard(callback.register(SECURITY_CARD, SecurityCardItem::new)); } private void registerProcessor(final RegistryCallback callback, final ProcessorItem.Type type) { 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 0eb7ca2bb..b902d1f91 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 @@ -54,6 +54,7 @@ public final class ContentIds { public static final ResourceLocation NETWORK_TRANSMITTER = createIdentifier("network_transmitter"); public static final ResourceLocation PORTABLE_GRID = createIdentifier("portable_grid"); public static final ResourceLocation CREATIVE_PORTABLE_GRID = createIdentifier("creative_portable_grid"); + public static final ResourceLocation SECURITY_CARD = createIdentifier("security_card"); private ContentIds() { } 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 239dd8ea5..f1c73e3f3 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 @@ -103,5 +103,6 @@ private static void appendItems(final Consumer consumer) { itemConsumer.accept(Items.INSTANCE.getCreativeWirelessGrid()); itemConsumer.accept(Items.INSTANCE.getConfigurationCard()); itemConsumer.accept(Items.INSTANCE.getNetworkCard()); + itemConsumer.accept(Items.INSTANCE.getSecurityCard()); } } 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 75b7eea13..c961a74cc 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 @@ -5,6 +5,7 @@ import com.refinedmods.refinedstorage2.platform.common.controller.CreativeControllerBlockItem; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.misc.ProcessorItem; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem; @@ -92,6 +93,8 @@ public final class Items { private Supplier portableGrid; @Nullable private Supplier creativePortableGrid; + @Nullable + private Supplier securityCard; private Items() { } @@ -415,4 +418,12 @@ public PortableGridBlockItem getCreativePortableGrid() { public void setCreativePortableGrid(final Supplier supplier) { this.creativePortableGrid = supplier; } + + public SecurityCardItem getSecurityCard() { + return requireNonNull(securityCard).get(); + } + + public void setSecurityCard(final Supplier securityCard) { + this.securityCard = securityCard; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java new file mode 100644 index 000000000..f7a082f50 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java @@ -0,0 +1,14 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +public class SecurityCardItem extends Item { + public SecurityCardItem() { + super(new Item.Properties().stacksTo(1)); + } + + boolean isActive(final ItemStack stack) { + return false; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItemPropertyFunction.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItemPropertyFunction.java new file mode 100644 index 000000000..1d36f5a53 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItemPropertyFunction.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +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 SecurityCardItemPropertyFunction 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 SecurityCardItem cardItem) { + return cardItem.isActive(itemStack) ? 1 : 0; + } + return 0; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/package-info.java new file mode 100644 index 000000000..77692e9ab --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; 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 0e58472c8..23e61b007 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 @@ -219,6 +219,7 @@ "item.refinedstorage2.network_card.unbound": "Unbound.", "item.refinedstorage2.network_card.bound_help": "Insert into a Network Transmitter. Use while crouching to clear binding.", "item.refinedstorage2.network_card.bound": "Bound to %d, %d, %d in %s.", + "item.refinedstorage2.security_card": "Security Card", "misc.refinedstorage2.stored": "Stored: %s", "misc.refinedstorage2.stored_with_capacity": "Stored: %s / %s (%d%%)", "misc.refinedstorage2.total": "%d total", diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card.json new file mode 100755 index 000000000..9bf6e03d2 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card.json @@ -0,0 +1,17 @@ +{ + "parent": "item/generated", + "overrides": [ + { + "predicate": { + "active": 0 + }, + "model": "refinedstorage2:item/security_card/inactive" + }, + { + "predicate": { + "active": 1 + }, + "model": "refinedstorage2:item/security_card/active" + } + ] +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/active.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/active.json new file mode 100644 index 000000000..c007d44dc --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/active.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "refinedstorage2:item/security_card/active" + } +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/inactive.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/inactive.json new file mode 100644 index 000000000..3753723ad --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/security_card/inactive.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "refinedstorage2:item/security_card/inactive" + } +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/security_card.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/security_card.png new file mode 100644 index 0000000000000000000000000000000000000000..de3f689808cebc73f03e7767eb29731f0cc5d969 GIT binary patch literal 1142 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIGwruBVG* zNX4ADcVqpuB1IZ5HWzC2I4uhlR!o%hIb<%;&eL7@B74_uwHKlj9@S;<{WSfqVbl%lASXTU3l<9ZBZZF$?G>J!0!vFA5{|mQo-em(bxP3M=R_H7IwetZ)DsCtLV zVFm+sbmQiJmYDU|#rGdD@lD=;e|GY@?a$YQt?qtaaBF!zmyPdbSN#n)bB@*RH$Ofn z|NO>3kIV2FhH1%-o3#u;-{@6VuneX!!iDa4nUDT_Ch^?yUWfPp zWpC7f-#Z5+P}kS%u>G+lLklO-=q5+Xxi`-Xtj(Ba8vnL5W4a48f+B;`&6y6$+~g>+ z&0|#XVE~~wZ=4;X8_&)>Jf}apai<)J`B#R2dH!)-qFo8}&rPlzutT>oeJ;ph-6sc2 z&^A-PZ~q^2{If)|j#&4{Z{MD^a~t|Ue&4RqJ$?H0>iMku-dtyP(EIX{^VLVa%#} zSi!^ifG8v3U`howC@LKZ!OI$r&xw8fvqXt0gZu;wAu<^9dZTd-Tl0dI{zt|Ot$ABH zOG8$gXG%FztcNor1{QPoaz{}^Q4MD1JYrFZ5}YARy|hm-;A&9(BBMMM=A>1QY!s18 zm2z4x%|hg~lt3K{shn0RP=`}aIIv>KI8tA}-nMuQ-_Y^6q{)55AOygR6JTK7j-{K#^Q~x)AkSGd@Hp{=7C-zG0$msU@D2RvW z!$kYU3F5?2xoJH5sYEi`VZb#u|J8T4ncd$KX`O9tY{qY&r%#-VC-iPko4IkR7Yk?)-xL-25vkeH%idkSu)al;mUUoZfpw1toKD zob552e!t#&=D_icWNuGflchQwCQyZ9Q(xc8*0#SUJ>1#na^>X)`uC36`p3{#ee*ZK z4_8k|BI~EThlA-n&(GWYYTLo)>0`m|rk^j?Os%$Mw&q6SzX&DgHkvWX>szXtn$qnD zmS%^->?%Q+RP5TRl@IKSD__1if1eFZOWqwS*&UZ!(=ISm>c9IH#~M1q;q;Ybif8SF z&jtDye7{<80iU(4spzv}3P?>nclz|`i#<;s+a3&HWL8w(E)+*R%>?C9(aEyNmv z#^xhS4lG?Fs|)x0fw~KajvT3CmDh&q>nm-U?VzQhBPYYwVNtc^w@c z_4by_k--U5fySQ7>n%Us@3?hqW@{02@9Pz^*^`n=7^c~}kCj(09`$7~82q4%Qf8vl z-v2Qa+Nf_Pw(L`X=#cE#Cm#57f)v^{xu$(_`^s^V{f7@Lf+o|<3DYMR gz46J=@(rUT0|TSRpV)k&I{H^P=uG&*{8bfy1AyycJOBUy literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/security_card/inactive.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/security_card/inactive.png new file mode 100644 index 0000000000000000000000000000000000000000..bc3f9b102a4628bb90cddebd778f7eba6a8dfb27 GIT binary patch literal 1603 zcmbVMdrT8|9PfNG-a588*z~MMtMhtyrLApkA*BymLlJ2=nL5_%-Bpg#yLvrn(cv~l zpaF-**K|`bh9PcI34w?Zj54R_A6?^^LHB?m7-N`#(~7vcD^RyTj9KHdJYI~^pv~s?_|S})#jOh-JVUwdO;(q~nrS=hK^cOl#%UV?7@g=QBAY<* z;>}%zlE<4~L|Ss#98-n@qn$!DBqQ`XT^yRnQ>J=dDCQtoz(#B$DHZ>I+j%}f;wt_+ zi3v8jG(;Y0*uoIzEtwW7)xzm&x>;m~u}AiVGR!MO_dggdwLho6RQvG2?~OZcDL? zfU*fUUC3ZuKJ1IaU@mqqR}>QDtWm6CNG>U8ftJP!odm@iwJJXMMTnEQ!cNF-QV}8s zWnw}MCL>}3L`60UC?@0*k4tI#k6%F>L5rVGMVkd;TXv^$S>0UFIj)&apflEP_^ zds!$=lU{2HhAbj*JwrQzi8w3B7ufLM{GY_*|2KXRXA~4FmVXsb_=&5?(D8XIaF^%J zL{MA@FVeB)xD z(ztRY>)_$~*!5Q{1cUl7sJb({RTVbtsu{N~bk;gP-#$3FMtCWqy!GjiLA5URRPgb( z`wvq5zE6;ay#9nar_Vm1;-@G14PSym2!LIJ$ zs%O*ve!sb?r^+R(q8pUIr<7zmpkF^Y*%ui-tFsQ@up#L-BY!(7slWF|hky4kZPob$ z5u>LUkcj~Jx?%BLK|_0xaGF?VYoH#SW_mSs3CiT7!LN@%dG zPESv7T}wZ$8Lr(>HoD9mJbqdBwLd9h#x%C5=%T$TuxHPlvm1qi z{i{D38=gP#A!&(=9abgoJa=c|lkxGs;CP@w3MH_Gg`8G2Dk`eta{m=vw7Uy;`Fqx8 z)LR4XpXiVG9X(-L{=>b8QLkOHA(BHGGPzv6eE-F(S0k^DEEyUa^4|Nhb7TZ*&xK~E zuj#I;uHNgO*}OhxkD+w@OiRmmgPN3@JJ^x2{s&_+S$qUMhFh(@X|G^`{O0y6d16M| zvTJqS_UwkzfdS%=M~`e`3-QJ?MVrui|IVB|}5wms(4qhuQ{(f{{Q_qUIz8Pq(&-ZF+ z+QR7A*ilS@*>gAUa@2I$8h4v#?ib%t?18E1*H!|zjdQ7Q+q1Sy8Un2fMKox literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/security_card.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/security_card.json new file mode 100644 index 000000000..073ce7ff8 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/security_card.json @@ -0,0 +1,22 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "EEE", + "CAC", + "EEE" + ], + "key": { + "E": { + "item": "refinedstorage2:quartz_enriched_iron" + }, + "C": { + "item": "refinedstorage2:network_card" + }, + "A": { + "item": "refinedstorage2:advanced_processor" + } + }, + "result": { + "item": "refinedstorage2:security_card" + } +} \ 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 18eac2b73..0d4f6ce6f 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 @@ -13,6 +13,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.controller.ControllerModelPredicateProvider; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkCardItemPropertyFunction; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorBlockEntityRenderer; import com.refinedmods.refinedstorage2.platform.common.support.network.bounditem.NetworkBoundItemItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; @@ -427,5 +428,10 @@ private void registerItemProperties() { NetworkCardItemPropertyFunction.NAME, new NetworkCardItemPropertyFunction() ); + ItemProperties.register( + Items.INSTANCE.getSecurityCard(), + SecurityCardItemPropertyFunction.NAME, + new SecurityCardItemPropertyFunction() + ); } } 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 90c5f8129..7f0734f01 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 @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings; import com.refinedmods.refinedstorage2.platform.common.controller.ControllerModelPredicateProvider; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkCardItemPropertyFunction; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorBlockEntityRenderer; import com.refinedmods.refinedstorage2.platform.common.support.network.bounditem.NetworkBoundItemItemPropertyFunction; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.CompositeClientTooltipComponent; @@ -245,5 +246,10 @@ private static void registerItemProperties() { NetworkCardItemPropertyFunction.NAME, new NetworkCardItemPropertyFunction() ); + ItemProperties.register( + Items.INSTANCE.getSecurityCard(), + SecurityCardItemPropertyFunction.NAME, + new SecurityCardItemPropertyFunction() + ); } } From 5d5b3702d1192b2537c4cb2f45bf61e00c49c2ef Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sat, 23 Mar 2024 16:09:54 +0100 Subject: [PATCH 5/7] feat: security card screen --- .../{Operation.java => Permission.java} | 2 +- .../security/SecurityDecisionProvider.java | 2 +- .../security/SecurityNetworkComponent.java | 2 +- .../SecurityNetworkComponentImpl.java | 6 +- .../SecurityNetworkComponentImplTest.java | 4 +- .../platform/api/PlatformApi.java | 9 +- .../platform/api/PlatformApiProxy.java | 18 +- .../api/security/BuiltinPermissions.java | 14 ++ .../api/security/PlatformPermission.java | 15 ++ .../platform/api/security/package-info.java | 7 + .../common/AbstractClientModInitializer.java | 2 + .../common/AbstractModInitializer.java | 21 +- .../platform/common/Config.java | 18 +- .../platform/common/PlatformApiImpl.java | 24 ++- .../platform/common/content/ContentNames.java | 2 + .../platform/common/content/Menus.java | 11 + .../grid/AbstractGridContainerMenu.java | 23 +-- .../grid/CraftingGridContainerMenu.java | 8 +- .../common/grid/GridContainerMenu.java | 4 +- .../grid/WirelessGridContainerMenu.java | 4 +- .../grid/screen/AbstractGridScreen.java | 155 ++++----------- .../common/security/BuiltinPermission.java | 76 +++++++ .../security/SecurityCardContainerMenu.java | 57 ++++++ .../SecurityCardExtendedMenuProvider.java | 48 +++++ .../common/security/SecurityCardItem.java | 92 ++++++++- .../common/security/SecurityCardScreen.java | 148 ++++++++++++++ .../common/storage/StorageTooltipHelper.java | 8 +- .../AbstractPortableGridContainerMenu.java | 4 +- .../PortableGridBlockContainerMenu.java | 4 +- .../PortableGridItemContainerMenu.java | 4 +- .../stretching/AbstractStretchingScreen.java | 188 ++++++++++++++++++ .../stretching/ScreenSize.java} | 6 +- .../stretching/ScreenSizeListener.java | 5 + .../ScreenSizeSideButtonWidget.java} | 38 ++-- .../support/stretching/package-info.java | 7 + .../support/widget/CustomCheckboxWidget.java | 76 +++++++ .../support/widget/ScrollbarWidget.java | 24 ++- .../assets/refinedstorage2/lang/en_us.json | 35 +++- .../textures/gui/security_card.png | Bin 1142 -> 1100 bytes .../platform/fabric/ConfigImpl.java | 58 +++--- .../platform/fabric/ModInitializerImpl.java | 14 +- .../platform/forge/ConfigImpl.java | 66 +++--- .../platform/forge/ModInitializer.java | 13 +- 43 files changed, 1036 insertions(+), 286 deletions(-) rename refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/{Operation.java => Permission.java} (84%) create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/BuiltinPermissions.java create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java create mode 100644 refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/package-info.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{grid/GridSize.java => support/stretching/ScreenSize.java} (69%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java rename refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/{grid/screen/SizeSideButtonWidget.java => support/stretching/ScreenSizeSideButtonWidget.java} (53%) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/package-info.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Operation.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Permission.java similarity index 84% rename from refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Operation.java rename to refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Permission.java index 4089f95cc..83d8d54d9 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Operation.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/Permission.java @@ -3,5 +3,5 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") -public interface Operation { +public interface Permission { } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java index a8e540744..fe65abda1 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java @@ -4,5 +4,5 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") public interface SecurityDecisionProvider { - SecurityDecision isAllowed(Operation operation, SecurityActor actor); + SecurityDecision isAllowed(Permission permission, SecurityActor actor); } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java index ecae20e11..834fc0332 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java @@ -6,5 +6,5 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") public interface SecurityNetworkComponent extends NetworkComponent { - boolean isAllowed(Operation operation, SecurityActor actor); + boolean isAllowed(Permission permission, SecurityActor actor); } diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java index 28c647db7..ea7f962e7 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImpl.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.security; import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; -import com.refinedmods.refinedstorage2.api.network.security.Operation; +import com.refinedmods.refinedstorage2.api.network.security.Permission; import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; import com.refinedmods.refinedstorage2.api.network.security.SecurityDecision; import com.refinedmods.refinedstorage2.api.network.security.SecurityDecisionProvider; @@ -28,9 +28,9 @@ public void onContainerRemoved(final NetworkNodeContainer container) { } @Override - public boolean isAllowed(final Operation operation, final SecurityActor actor) { + public boolean isAllowed(final Permission permission, final SecurityActor actor) { for (final SecurityDecisionProvider provider : providers) { - final SecurityDecision decision = provider.isAllowed(operation, actor); + final SecurityDecision decision = provider.isAllowed(permission, actor); if (decision == SecurityDecision.DENY) { return false; } else if (decision == SecurityDecision.ALLOW) { diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java index a0205f01e..36f8b1158 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.security; -import com.refinedmods.refinedstorage2.api.network.security.Operation; +import com.refinedmods.refinedstorage2.api.network.security.Permission; import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; @@ -26,7 +26,7 @@ void everythingIsAllowedByDefault(final TestPermissions permission) { assertThat(sut.isAllowed(permission, TestActors.Y)).isTrue(); } - enum TestPermissions implements Operation { + enum TestPermissions implements Permission { A, B } 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 50b2d335d..f75dbef1d 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 @@ -20,6 +20,8 @@ import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.security.BuiltinPermissions; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; @@ -45,7 +47,6 @@ import java.util.Set; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -91,8 +92,6 @@ public interface PlatformApi { StorageMonitorInsertionStrategy getStorageMonitorInsertionStrategy(); - MutableComponent createTranslation(String category, String value, Object... args); - ComponentMapFactory getNetworkComponentMapFactory(); PlatformRegistry getGridSynchronizerRegistry(); @@ -180,4 +179,8 @@ EnergyStorage asBlockItemEnergyStorage( SlotReference createInventorySlotReference(Player player, InteractionHand hand); void useNetworkBoundItem(Player player, Item... items); + + BuiltinPermissions getBuiltinPermissions(); + + PlatformRegistry getPermissionRegistry(); } 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 0e1fb87cf..59603d009 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 @@ -20,6 +20,8 @@ import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.security.BuiltinPermissions; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; @@ -46,7 +48,6 @@ import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -146,11 +147,6 @@ public StorageMonitorInsertionStrategy getStorageMonitorInsertionStrategy() { return ensureLoaded().getStorageMonitorInsertionStrategy(); } - @Override - public MutableComponent createTranslation(final String category, final String value, final Object... args) { - return ensureLoaded().createTranslation(category, value, args); - } - @Override public ComponentMapFactory getNetworkComponentMapFactory() { return ensureLoaded().getNetworkComponentMapFactory(); @@ -357,6 +353,16 @@ public void useNetworkBoundItem(final Player player, final Item... items) { ensureLoaded().useNetworkBoundItem(player, items); } + @Override + public BuiltinPermissions getBuiltinPermissions() { + return ensureLoaded().getBuiltinPermissions(); + } + + @Override + public PlatformRegistry getPermissionRegistry() { + return ensureLoaded().getPermissionRegistry(); + } + private PlatformApi ensureLoaded() { if (delegate == null) { throw new IllegalStateException("Platform API not loaded yet"); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/BuiltinPermissions.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/BuiltinPermissions.java new file mode 100644 index 000000000..5ff12f708 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/BuiltinPermissions.java @@ -0,0 +1,14 @@ +package com.refinedmods.refinedstorage2.platform.api.security; + +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +public record BuiltinPermissions( + PlatformPermission insert, + PlatformPermission extract, + PlatformPermission autocrafting, + PlatformPermission modify, + PlatformPermission build, + PlatformPermission security +) { +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java new file mode 100644 index 000000000..67ca7333c --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java @@ -0,0 +1,15 @@ +package com.refinedmods.refinedstorage2.platform.api.security; + +import com.refinedmods.refinedstorage2.api.network.security.Permission; + +import net.minecraft.network.chat.Component; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +public interface PlatformPermission extends Permission { + Component getName(); + + Component getDescription(); + + Component getOwnerName(); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/package-info.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/package-info.java new file mode 100644 index 000000000..256520c96 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.api.security; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractClientModInitializer.java index 87096e77e..ba8ba4096 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 @@ -17,6 +17,7 @@ import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceScreen; import com.refinedmods.refinedstorage2.platform.common.importer.ImporterScreen; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterScreen; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardScreen; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveScreen; @@ -67,6 +68,7 @@ protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getNetworkTransmitter(), NetworkTransmitterScreen::new); registration.register(Menus.INSTANCE.getPortableGridBlock(), PortableGridScreen::new); registration.register(Menus.INSTANCE.getPortableGridItem(), PortableGridScreen::new); + registration.register(Menus.INSTANCE.getSecurityCard(), SecurityCardScreen::new); } protected static void registerAlternativeGridHints() { 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 52e60ce8c..6659b7e90 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 @@ -55,6 +55,8 @@ import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.BuiltinPermission; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; @@ -183,6 +185,7 @@ protected final void initializePlatformApi() { registerStorageMonitorExtractionStrategies(); registerNetworkComponents(); registerWirelessTransmitterRangeModifiers(); + registerPermissions(); } private void registerAdditionalStorageTypes() { @@ -252,6 +255,15 @@ private void registerWirelessTransmitterRangeModifiers() { ); } + private void registerPermissions() { + for (final BuiltinPermission permission : BuiltinPermission.values()) { + if (permission == BuiltinPermission.SECURITY) { + continue; + } + PlatformApi.INSTANCE.getPermissionRegistry().register(permission.getId(), permission); + } + } + protected final void registerBlocks( final RegistryCallback callback, final BiFunction diskDriveBlockEntityFactory, @@ -307,7 +319,8 @@ protected final void registerItems( final Supplier wirelessGridItemSupplier, final Supplier creativeWirelessGridItemSupplier, final Supplier portableGridBlockItemSupplier, - final Supplier creativePortableGridBlockItemSupplier + final Supplier creativePortableGridBlockItemSupplier, + final Supplier securityCardItemSupplier ) { registerSimpleItems(callback); Blocks.INSTANCE.getGrid().registerItems(callback); @@ -337,6 +350,7 @@ protected final void registerItems( CREATIVE_PORTABLE_GRID, creativePortableGridBlockItemSupplier )); + Items.INSTANCE.setSecurityCard(callback.register(SECURITY_CARD, securityCardItemSupplier)); } private void registerSimpleItems(final RegistryCallback callback) { @@ -362,7 +376,6 @@ private void registerSimpleItems(final RegistryCallback callback) { ConfigurationCardItem::new )); Items.INSTANCE.setNetworkCard(callback.register(ContentIds.NETWORK_CARD, NetworkCardItem::new)); - Items.INSTANCE.setSecurityCard(callback.register(SECURITY_CARD, SecurityCardItem::new)); } private void registerProcessor(final RegistryCallback callback, final ProcessorItem.Type type) { @@ -714,6 +727,10 @@ protected final void registerMenus(final RegistryCallback> callback, createIdentifier("portable_grid_item"), () -> menuTypeFactory.create(PortableGridItemContainerMenu::new) )); + Menus.INSTANCE.setSecurityCard(callback.register( + SECURITY_CARD, + () -> menuTypeFactory.create(SecurityCardContainerMenu::new) + )); } protected final void registerLootFunctions(final RegistryCallback callback) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java index 61c22ab7e..d8ddad985 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/Config.java @@ -2,8 +2,8 @@ import com.refinedmods.refinedstorage2.api.grid.view.GridSortingDirection; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridMatrixCloseBehavior; -import com.refinedmods.refinedstorage2.platform.common.grid.GridSize; import com.refinedmods.refinedstorage2.platform.common.grid.GridSortingTypes; +import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSize; import java.util.Optional; @@ -52,6 +52,14 @@ public interface Config { PortableGridEntry getPortableGrid(); + boolean isSmoothScrolling(); + + ScreenSize getScreenSize(); + + void setScreenSize(ScreenSize size); + + int getMaxRowsStretch(); + interface SimpleEnergyUsageEntry { long getEnergyUsage(); } @@ -59,16 +67,12 @@ interface SimpleEnergyUsageEntry { interface GridEntry extends SimpleEnergyUsageEntry { boolean isLargeFont(); - int getMaxRowsStretch(); - boolean isPreventSortingWhileShiftIsDown(); boolean isDetailedTooltip(); boolean isRememberSearchQuery(); - boolean isSmoothScrolling(); - boolean isAutoSelected(); void setAutoSelected(boolean autoSelected); @@ -87,10 +91,6 @@ interface GridEntry extends SimpleEnergyUsageEntry { void setSortingType(GridSortingTypes sortingType); - GridSize getSize(); - - void setSize(GridSize size); - Optional getResourceTypeId(); void setResourceTypeId(ResourceLocation resourceTypeId); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index c8185d7ea..687522c80 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -24,6 +24,8 @@ import com.refinedmods.refinedstorage2.platform.api.grid.strategy.GridScrollingStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.recipemod.IngredientConverter; +import com.refinedmods.refinedstorage2.platform.api.security.BuiltinPermissions; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.storage.StorageContainerItemHelper; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.StorageType; @@ -52,6 +54,7 @@ import com.refinedmods.refinedstorage2.platform.common.grid.strategy.CompositeGridInsertionStrategy; import com.refinedmods.refinedstorage2.platform.common.grid.strategy.CompositeGridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.common.recipemod.CompositeIngredientConverter; +import com.refinedmods.refinedstorage2.platform.common.security.BuiltinPermission; import com.refinedmods.refinedstorage2.platform.common.storage.ClientStorageRepository; import com.refinedmods.refinedstorage2.platform.common.storage.StorageContainerItemHelperImpl; import com.refinedmods.refinedstorage2.platform.common.storage.StorageRepositoryImpl; @@ -72,7 +75,6 @@ import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceTypes; import com.refinedmods.refinedstorage2.platform.common.upgrade.BuiltinUpgradeDestinationsImpl; import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeRegistryImpl; -import com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil; import com.refinedmods.refinedstorage2.platform.common.util.ServerEventQueue; import com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter.CompositeWirelessTransmitterRangeModifier; @@ -92,7 +94,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; @@ -164,6 +165,10 @@ public class PlatformApiImpl implements PlatformApi { InventorySlotReferenceFactory.INSTANCE ); private final CompositeSlotReferenceProvider slotReferenceProvider = new CompositeSlotReferenceProvider(); + private final PlatformRegistry permissionRegistry = new PlatformRegistryImpl<>( + BuiltinPermission.SECURITY.getId(), + BuiltinPermission.SECURITY + ); @Override public PlatformRegistry getStorageTypeRegistry() { @@ -264,11 +269,6 @@ public StorageMonitorInsertionStrategy getStorageMonitorInsertionStrategy() { return storageMonitorInsertionStrategy; } - @Override - public MutableComponent createTranslation(final String category, final String value, final Object... args) { - return IdentifierUtil.createTranslation(category, value, args); - } - @Override public ComponentMapFactory getNetworkComponentMapFactory() { return networkComponentMapFactory; @@ -527,4 +527,14 @@ public void useNetworkBoundItem(final Player player, final Item... items) { slotReference -> Platform.INSTANCE.getClientToServerCommunications().sendUseNetworkBoundItem(slotReference) ); } + + @Override + public BuiltinPermissions getBuiltinPermissions() { + return BuiltinPermission.VIEW; + } + + @Override + public PlatformRegistry getPermissionRegistry() { + return permissionRegistry; + } } 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 0d94ede1c..bfb5cd6f8 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,6 +5,7 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public final class ContentNames { + public static final MutableComponent MOD = createTranslation("itemGroup", "general"); public static final MutableComponent CABLE = name("cable"); public static final MutableComponent GRID = name("grid"); public static final MutableComponent CRAFTING_GRID = name("crafting_grid"); @@ -25,6 +26,7 @@ public final class ContentNames { public static final MutableComponent NETWORK_RECEIVER = name("network_receiver"); public static final MutableComponent NETWORK_TRANSMITTER = name("network_transmitter"); public static final MutableComponent PORTABLE_GRID = name("portable_grid"); + public static final MutableComponent SECURITY_CARD = createTranslation("item", "security_card"); private ContentNames() { } 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 98e8a9e96..78ab613f8 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 @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.importer.ImporterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockContainerMenu; @@ -71,6 +72,8 @@ public final class Menus { private Supplier> portableGridBlock; @Nullable private Supplier> portableGridItem; + @Nullable + private Supplier> securityCard; private Menus() { } @@ -234,4 +237,12 @@ public MenuType getPortableGridItem() { public void setPortableGridItem(final Supplier> portableGridItem) { this.portableGridItem = portableGridItem; } + + public MenuType getSecurityCard() { + return requireNonNull(securityCard).get(); + } + + public void setSecurityCard(final Supplier> securityCard) { + this.securityCard = securityCard; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java index bf2de122c..0ca32b10f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/AbstractGridContainerMenu.java @@ -33,6 +33,7 @@ import com.refinedmods.refinedstorage2.platform.common.grid.strategy.ClientGridScrollingStrategy; import com.refinedmods.refinedstorage2.platform.common.grid.view.CompositeGridResourceFactory; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSizeListener; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import com.refinedmods.refinedstorage2.query.lexer.LexerTokenMappings; import com.refinedmods.refinedstorage2.query.parser.ParserOperatorMappings; @@ -57,7 +58,7 @@ import static java.util.Objects.requireNonNull; public abstract class AbstractGridContainerMenu extends AbstractBaseContainerMenu - implements GridWatcher, GridInsertionStrategy, GridExtractionStrategy, GridScrollingStrategy { + implements GridWatcher, GridInsertionStrategy, GridExtractionStrategy, GridScrollingStrategy, ScreenSizeListener { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGridContainerMenu.class); private static final GridQueryParserImpl QUERY_PARSER = new GridQueryParserImpl( LexerTokenMappings.DEFAULT_MAPPINGS, @@ -82,8 +83,6 @@ public abstract class AbstractGridContainerMenu extends AbstractBaseContainerMen private GridExtractionStrategy extractionStrategy; @Nullable private GridScrollingStrategy scrollingStrategy; - @Nullable - private Runnable sizeChangedListener; private GridSynchronizer synchronizer; @Nullable private ResourceType resourceTypeFilter; @@ -172,10 +171,6 @@ public void onResourceUpdate(final ResourceKey resource, view.onChange(resource, amount, trackedResource); } - public void setSizeChangedListener(@Nullable final Runnable sizeChangedListener) { - this.sizeChangedListener = sizeChangedListener; - } - public GridSortingDirection getSortingDirection() { return Platform.INSTANCE.getConfig().getGrid().getSortingDirection(); } @@ -196,17 +191,6 @@ public void setSortingType(final GridSortingTypes sortingType) { view.sort(); } - public GridSize getSize() { - return Platform.INSTANCE.getConfig().getGrid().getSize(); - } - - public void setSize(final GridSize size) { - Platform.INSTANCE.getConfig().getGrid().setSize(size); - if (sizeChangedListener != null) { - sizeChangedListener.run(); - } - } - public void setSearchBox(final GridSearchBox searchBox) { this.searchBox = searchBox; registerViewUpdatingListener(searchBox); @@ -250,7 +234,8 @@ public void removed(final Player playerEntity) { } } - public void addSlots(final int playerInventoryY) { + @Override + public void initSlots(final int playerInventoryY) { resetSlots(); addPlayerInventory(playerInventory, 8, playerInventoryY); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java index 43ea346da..4ef029e92 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/CraftingGridContainerMenu.java @@ -41,7 +41,7 @@ public CraftingGridContainerMenu(final int syncId, final Inventory playerInvento super(Menus.INSTANCE.getCraftingGrid(), syncId, playerInventory, buf); this.source = new ClientCraftingGridSource(); this.player = playerInventory.player; - addSlots(0); + initSlots(0); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } @@ -51,7 +51,7 @@ public CraftingGridContainerMenu(final int syncId, final Inventory playerInvento super(Menus.INSTANCE.getCraftingGrid(), syncId, playerInventory, grid); this.source = new CraftingGridSourceImpl(grid); this.player = playerInventory.player; - addSlots(0); + initSlots(0); registerProperty(new ServerProperty<>( PropertyTypes.REDSTONE_MODE, grid::getRedstoneMode, @@ -88,8 +88,8 @@ public ItemStack quickMoveStack(final Player actor, final int slotIndex) { } @Override - public void addSlots(final int playerInventoryY) { - super.addSlots(playerInventoryY); + public void initSlots(final int playerInventoryY) { + super.initSlots(playerInventoryY); craftingMatrixSlots.clear(); for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java index e2d5eb918..d3ce3af2e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridContainerMenu.java @@ -12,13 +12,13 @@ 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); + initSlots(0); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } GridContainerMenu(final int syncId, final Inventory playerInventory, final GridBlockEntity grid) { super(Menus.INSTANCE.getGrid(), syncId, playerInventory, grid); - addSlots(0); + initSlots(0); registerProperty(new ServerProperty<>( PropertyTypes.REDSTONE_MODE, grid::getRedstoneMode, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java index 7ecfa7dfa..33ccc6987 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/WirelessGridContainerMenu.java @@ -12,7 +12,7 @@ public class WirelessGridContainerMenu extends AbstractGridContainerMenu { public WirelessGridContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getWirelessGrid(), syncId, playerInventory, buf); this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); - addSlots(0); + initSlots(0); } WirelessGridContainerMenu(final int syncId, @@ -21,6 +21,6 @@ public WirelessGridContainerMenu(final int syncId, final Inventory playerInvento final SlotReference slotReference) { super(Menus.INSTANCE.getWirelessGrid(), syncId, playerInventory, grid); this.disabledSlot = slotReference; - addSlots(0); + initSlots(0); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java index a46f2213e..454afcd89 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java @@ -14,20 +14,18 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage2.platform.common.grid.view.ItemGridResource; -import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.DisabledSlot; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage2.platform.common.support.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.common.support.stretching.AbstractStretchingScreen; import com.refinedmods.refinedstorage2.platform.common.support.tooltip.SmallTextClientTooltipComponent; import com.refinedmods.refinedstorage2.platform.common.support.widget.History; import com.refinedmods.refinedstorage2.platform.common.support.widget.RedstoneModeSideButtonWidget; -import com.refinedmods.refinedstorage2.platform.common.support.widget.ScrollbarWidget; import com.refinedmods.refinedstorage2.query.lexer.SyntaxHighlighter; import com.refinedmods.refinedstorage2.query.lexer.SyntaxHighlighterColors; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import javax.annotation.Nullable; import com.mojang.blaze3d.systems.RenderSystem; @@ -43,16 +41,14 @@ import org.slf4j.LoggerFactory; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; +import static java.util.Objects.requireNonNullElse; -public abstract class AbstractGridScreen extends AbstractBaseScreen { +public abstract class AbstractGridScreen extends AbstractStretchingScreen { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGridScreen.class); private static final int MODIFIED_JUST_NOW_MAX_SECONDS = 10; - private static final int TOP_HEIGHT = 19; - private static final int INVENTORY_INCLUDING_TITLE_HEIGHT = 99; private static final int COLUMNS = 9; - private static final int MIN_ROWS = 3; private static final int DISABLED_SLOT_COLOR = 0xFF5B5B5B; private static final int SELECTION_SLOT_COLOR = -2130706433; @@ -63,10 +59,7 @@ public abstract class AbstractGridScreen ex @Nullable GridSearchBoxWidget searchField; - @Nullable - private ScrollbarWidget scrollbar; private int totalRows; - private int visibleRows; private int currentGridSlotIndex; protected AbstractGridScreen(final T menu, @@ -75,17 +68,12 @@ protected AbstractGridScreen(final T menu, final int bottomHeight) { super(menu, playerInventory, text); this.bottomHeight = bottomHeight; - this.menu.setSizeChangedListener(this::init); } @Override protected void init() { LOGGER.info("Initializing grid screen"); - this.visibleRows = calculateVisibleRows(); - this.imageHeight = TOP_HEIGHT + (visibleRows * 18) + bottomHeight; - this.inventoryLabelY = imageHeight - INVENTORY_INCLUDING_TITLE_HEIGHT + 4; - super.init(); if (searchField == null) { @@ -103,14 +91,9 @@ protected void init() { } getMenu().setSearchBox(searchField); - getMenu().addSlots(imageHeight - INVENTORY_INCLUDING_TITLE_HEIGHT + 17); - - this.scrollbar = new ScrollbarWidget(leftPos + 174, topPos + 20, 12, (visibleRows * 18) - 2); - this.scrollbar.setScrollAnimation(Platform.INSTANCE.getConfig().getGrid().isSmoothScrolling()); - this.getMenu().getView().setListener(this::resourcesChanged); - resourcesChanged(); + getMenu().getView().setListener(this::updateScrollbar); + updateScrollbar(); - addWidget(scrollbar); addWidget(searchField); if (getMenu().hasProperty(PropertyTypes.REDSTONE_MODE)) { @@ -118,7 +101,6 @@ protected void init() { } addSideButton(new SortingDirectionSideButtonWidget(getMenu())); addSideButton(new SortingTypeSideButtonWidget(getMenu())); - addSideButton(new SizeSideButtonWidget(getMenu())); addSideButton(new AutoSelectedSideButtonWidget(getMenu())); addSideButton(new ResourceTypeSideButtonWidget(getMenu())); @@ -150,70 +132,54 @@ private void trySynchronizeToGrid() { searchField.setValue(text); } - private void resourcesChanged() { - if (scrollbar == null) { - return; - } - totalRows = (int) Math.ceil((float) getMenu().getView().getViewList().size() / (float) COLUMNS); - scrollbar.setEnabled(totalRows > visibleRows); - final int rowsExcludingVisibleOnes = totalRows - visibleRows; - final int maxOffset = scrollbar.isScrollAnimation() - ? (rowsExcludingVisibleOnes * 18) - : rowsExcludingVisibleOnes; - scrollbar.setMaxOffset(maxOffset); - } - - private int calculateVisibleRows() { - final int screenSpaceAvailable = height - TOP_HEIGHT - bottomHeight; - final int maxRows = getMaxRows(); - return Math.max(MIN_ROWS, Math.min((screenSpaceAvailable / 18) - MIN_ROWS, maxRows)); - } - - private int getMaxRows() { - return switch (getMenu().getSize()) { - case STRETCH -> Platform.INSTANCE.getConfig().getGrid().getMaxRowsStretch(); - case SMALL -> 3; - case MEDIUM -> 5; - case LARGE -> 8; - case EXTRA_LARGE -> 12; - }; + private void updateScrollbar() { + this.totalRows = (int) Math.ceil((float) getMenu().getView().getViewList().size() / (float) COLUMNS); + updateScrollbar(totalRows); } private boolean isOverStorageArea(final int mouseX, final int mouseY) { final int relativeMouseX = mouseX - leftPos; final int relativeMouseY = mouseY - topPos; return relativeMouseX >= 7 - && relativeMouseY >= TOP_HEIGHT && relativeMouseX <= 168 - && relativeMouseY <= TOP_HEIGHT + (visibleRows * 18); + && isInStretchedArea(relativeMouseY); } @Override - protected void renderBg(final GuiGraphics graphics, final float delta, final int mouseX, final int mouseY) { - final int x = (width - imageWidth) / 2; - final int y = (height - imageHeight) / 2; - - graphics.blit(getTexture(), x, y, 0, 0, imageWidth, TOP_HEIGHT); - - for (int row = 0; row < visibleRows; ++row) { + protected void renderStretchingBackground(final GuiGraphics graphics, final int x, final int y, final int rows) { + for (int row = 0; row < rows; ++row) { int textureY = 37; if (row == 0) { textureY = 19; - } else if (row == visibleRows - 1) { + } else if (row == rows - 1) { textureY = 55; } - graphics.blit(getTexture(), x, y + TOP_HEIGHT + (18 * row), 0, textureY, imageWidth, 18); + graphics.blit(getTexture(), x, y + (ROW_SIZE * row), 0, textureY, imageWidth, ROW_SIZE); } + } - graphics.blit(getTexture(), x, y + TOP_HEIGHT + (18 * visibleRows), 0, 73, imageWidth, bottomHeight); + @Override + protected int getBottomHeight() { + return bottomHeight; + } - currentGridSlotIndex = -1; + @Override + protected int getBottomV() { + return 73; + } - graphics.enableScissor(x + 7, y + TOP_HEIGHT, x + 7 + (18 * COLUMNS), y + TOP_HEIGHT + (visibleRows * 18)); - for (int row = 0; row < Math.max(totalRows, visibleRows); ++row) { - renderRow(graphics, mouseX, mouseY, x, y, row); + @Override + protected void renderRows(final GuiGraphics graphics, + final int x, + final int y, + final int topHeight, + final int rows, + final int mouseX, + final int mouseY) { + currentGridSlotIndex = -1; + for (int row = 0; row < Math.max(totalRows, rows); ++row) { + renderRow(graphics, mouseX, mouseY, x, y, topHeight, row, rows); } - graphics.disableScissor(); } private void renderRow(final GuiGraphics graphics, @@ -221,33 +187,22 @@ private void renderRow(final GuiGraphics graphics, final int mouseY, final int x, final int y, - final int row) { + final int topHeight, + final int row, + final int visibleRows) { final int rowX = x + 7; - final int rowY = y + TOP_HEIGHT + (row * 18) - getScrollbarOffset(); - - final boolean isOutOfFrame = (rowY < y + TOP_HEIGHT - 18) || (rowY > y + TOP_HEIGHT + (visibleRows * 18)); + final int rowY = y + topHeight + (row * ROW_SIZE) - getScrollbarOffset(); + final boolean isOutOfFrame = (rowY < y + topHeight - ROW_SIZE) + || (rowY > y + topHeight + (ROW_SIZE * visibleRows)); if (isOutOfFrame) { return; } - - graphics.blit(getTexture(), rowX, rowY, 0, 238, 162, 18); - + graphics.blit(getTexture(), rowX, rowY, 0, 238, 162, ROW_SIZE); for (int column = 0; column < COLUMNS; ++column) { renderCell(graphics, mouseX, mouseY, rowX, rowY, (row * COLUMNS) + column, column); } } - private int getScrollbarOffset() { - if (scrollbar == null) { - return 0; - } - final int scrollbarOffset = (int) scrollbar.getOffset(); - if (!scrollbar.isScrollAnimation()) { - return scrollbarOffset * 18; - } - return scrollbarOffset; - } - private void renderCell(final GuiGraphics graphics, final int mouseX, final int mouseY, @@ -256,7 +211,7 @@ 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 slotX = rowX + 1 + (column * ROW_SIZE); final int slotY = rowY + 1; if (!getMenu().isActive()) { renderDisabledSlot(graphics, slotX, slotY); @@ -308,8 +263,8 @@ private void renderAmount(final GuiGraphics graphics, } final String text = resource.isZeroed() ? "0" : platformResource.getDisplayedAmount(); final int color = resource.isZeroed() - ? Objects.requireNonNullElse(ChatFormatting.RED.getColor(), 15) - : Objects.requireNonNullElse(ChatFormatting.WHITE.getColor(), 15); + ? requireNonNullElse(ChatFormatting.RED.getColor(), 15) + : requireNonNullElse(ChatFormatting.WHITE.getColor(), 15); final boolean large = (minecraft != null && minecraft.isEnforceUnicode()) || Platform.INSTANCE.getConfig().getGrid().isLargeFont(); renderAmount(graphics, slotX, slotY, text, color, large); @@ -439,9 +394,6 @@ public PlatformResourceKey getCurrentResource() { @Override public void render(final GuiGraphics graphics, final int mouseX, final int mouseY, final float partialTicks) { super.render(graphics, mouseX, mouseY, partialTicks); - if (scrollbar != null) { - scrollbar.render(graphics, mouseX, mouseY, partialTicks); - } if (searchField != null) { searchField.render(graphics, 0, 0, 0); } @@ -449,10 +401,6 @@ public void render(final GuiGraphics graphics, final int mouseX, final int mouse @Override public boolean mouseClicked(final double mouseX, final double mouseY, final int clickedButton) { - if (scrollbar != null && scrollbar.mouseClicked(mouseX, mouseY, clickedButton)) { - return true; - } - final ItemStack carriedStack = getMenu().getCarried(); final PlatformGridResource resource = getCurrentGridResource(); @@ -497,19 +445,6 @@ private static boolean shouldExtractToCursor() { return !hasShiftDown(); } - @Override - public void mouseMoved(final double mx, final double my) { - if (scrollbar != null) { - scrollbar.mouseMoved(mx, my); - } - super.mouseMoved(mx, my); - } - - @Override - public boolean mouseReleased(final double mx, final double my, final int button) { - return (scrollbar != null && scrollbar.mouseReleased(mx, my, button)) || super.mouseReleased(mx, my, button); - } - @Override public boolean mouseScrolled(final double x, final double y, final double z, final double delta) { final boolean up = delta > 0; @@ -523,9 +458,7 @@ public boolean mouseScrolled(final double x, final double y, final double z, fin mouseScrolledInInventory(up, hoveredSlot); } - final boolean didScrollbar = - scrollbar != null && !hasShiftDown() && !hasControlDown() && scrollbar.mouseScrolled(x, y, z, delta); - return didScrollbar || super.mouseScrolled(x, y, z, delta); + return super.mouseScrolled(x, y, z, delta); } private void mouseScrolledInInventory(final boolean up, final Slot slot) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java new file mode 100644 index 000000000..ba2f4ba90 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java @@ -0,0 +1,76 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.security.BuiltinPermissions; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; + +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +public enum BuiltinPermission implements PlatformPermission { + /** + * Whether the player can insert resources into a network. + */ + INSERT("insert"), + /** + * Whether the player can extract resources from a network. + */ + EXTRACT("extract"), + /** + * Whether the player can start, cancel or view an autocrafting task. + */ + AUTOCRAFTING("autocrafting"), + /** + * Whether the player can open network device GUIs. + */ + MODIFY("modify"), + /** + * Whether the player can add or remove network devices. + */ + BUILD("build"), + /** + * Whether the player can manage the security options for a network. + */ + SECURITY("security"); + + public static final BuiltinPermissions VIEW = new BuiltinPermissions( + INSERT, + EXTRACT, + AUTOCRAFTING, + MODIFY, + BUILD, + SECURITY + ); + + private final ResourceLocation id; + private final Component name; + private final Component description; + + BuiltinPermission(final String id) { + this.id = createIdentifier(id); + this.name = createTranslation("permission", id); + this.description = createTranslation("permission", id + ".description"); + } + + public ResourceLocation getId() { + return id; + } + + @Override + public Component getName() { + return name; + } + + @Override + public Component getDescription() { + return description; + } + + @Override + public Component getOwnerName() { + return ContentNames.MOD; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java new file mode 100644 index 000000000..4bbc6bdbd --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java @@ -0,0 +1,57 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.common.content.Menus; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSizeListener; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +public class SecurityCardContainerMenu extends AbstractBaseContainerMenu implements ScreenSizeListener { + private final Inventory playerInventory; + private final List permissions; + + public SecurityCardContainerMenu(final int syncId, + final Inventory playerInventory, + final FriendlyByteBuf buf) { + super(Menus.INSTANCE.getSecurityCard(), syncId); + this.playerInventory = playerInventory; + this.permissions = new ArrayList<>(); + this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); + final int amountOfPermissions = buf.readInt(); + for (int i = 0; i < amountOfPermissions; ++i) { + final ResourceLocation id = buf.readResourceLocation(); + PlatformApi.INSTANCE.getPermissionRegistry().get(id).ifPresent(permission -> permissions.add(new Permission( + id, + permission.getName(), + permission.getDescription(), + permission.getOwnerName() + ))); + } + } + + SecurityCardContainerMenu(final int syncId, final Inventory playerInventory) { + super(Menus.INSTANCE.getSecurityCard(), syncId); + this.playerInventory = playerInventory; + this.permissions = new ArrayList<>(); + } + + List getPermissions() { + return permissions; + } + + @Override + public void initSlots(final int playerInventoryY) { + resetSlots(); + addPlayerInventory(playerInventory, 8, playerInventoryY); + } + + record Permission(ResourceLocation id, Component name, Component description, Component ownerName) { + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java new file mode 100644 index 000000000..b5a4a2cbb --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java @@ -0,0 +1,48 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ExtendedMenuProvider; + +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.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; + +class SecurityCardExtendedMenuProvider implements ExtendedMenuProvider { + private final SlotReference slotReference; + + SecurityCardExtendedMenuProvider(final SlotReference slotReference) { + this.slotReference = slotReference; + } + + @Override + public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { + PlatformApi.INSTANCE.writeSlotReference(slotReference, buf); + final List permissions = PlatformApi.INSTANCE.getPermissionRegistry().getAll(); + buf.writeInt(permissions.size()); + for (final PlatformPermission permission : permissions) { + final ResourceLocation id = PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).orElseThrow(); + buf.writeResourceLocation(id); + } + } + + @Override + public Component getDisplayName() { + return ContentNames.SECURITY_CARD; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return new SecurityCardContainerMenu(syncId, inventory); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java index f7a082f50..5dd31e8a2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java @@ -1,14 +1,104 @@ package com.refinedmods.refinedstorage2.platform.common.security; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent; +import com.refinedmods.refinedstorage2.platform.common.Platform; + +import java.util.List; +import java.util.Optional; +import javax.annotation.Nullable; + +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +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.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.level.Level; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class SecurityCardItem extends Item { + private static final Component UNBOUND_HELP = createTranslation("item", "security_card.unbound.help"); + private static final Component BOUND_HELP = createTranslation("item", "security_card.bound.help"); + + private static final String TAG_BOUND_TO = "boundto"; + private static final String TAG_BOUND_TO_NAME = "boundtoname"; + public SecurityCardItem() { super(new Item.Properties().stacksTo(1)); } + @Override + public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { + final ItemStack stack = player.getItemInHand(hand); + if (player instanceof ServerPlayer serverPlayer) { + if (serverPlayer.isCrouching()) { + bindOrUnbind(serverPlayer, stack); + } else { + Platform.INSTANCE.getMenuOpener().openMenu(serverPlayer, new SecurityCardExtendedMenuProvider( + PlatformApi.INSTANCE.createInventorySlotReference(player, hand) + )); + } + } + return InteractionResultHolder.consume(stack); + } + + private void bindOrUnbind(final ServerPlayer player, final ItemStack stack) { + if (stack.hasTag()) { + unbind(player, stack); + } else { + bind(player, stack); + } + } + + private void unbind(final ServerPlayer player, final ItemStack stack) { + stack.setTag(null); + player.sendSystemMessage(createTranslation( + "item", + "security_card.unbound" + )); + } + + private void bind(final ServerPlayer player, final ItemStack stack) { + stack.getOrCreateTag().putUUID(TAG_BOUND_TO, player.getGameProfile().getId()); + stack.getOrCreateTag().putString(TAG_BOUND_TO_NAME, player.getGameProfile().getName()); + player.sendSystemMessage(createTranslation( + "item", + "security_card.bound", + Component.literal(player.getGameProfile().getName()).withStyle(ChatFormatting.YELLOW) + )); + } + + @Override + public void appendHoverText(final ItemStack stack, + @Nullable final Level level, + final List lines, + final TooltipFlag flag) { + super.appendHoverText(stack, level, lines, flag); + if (stack.getTag() == null) { + lines.add(createTranslation("item", "security_card.unbound").withStyle(ChatFormatting.GRAY)); + return; + } + final Component boundToName = Component.literal(stack.getTag().getString(TAG_BOUND_TO_NAME)) + .withStyle(ChatFormatting.YELLOW); + lines.add(createTranslation( + "item", + "security_card.bound", + boundToName + ).withStyle(ChatFormatting.GRAY)); + } + + @Override + public Optional getTooltipImage(final ItemStack stack) { + return Optional.of(new HelpTooltipComponent(isActive(stack) ? BOUND_HELP : UNBOUND_HELP)); + } + boolean isActive(final ItemStack stack) { - return false; + return stack.getTag() != null && stack.getTag().contains(TAG_BOUND_TO); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java new file mode 100644 index 000000000..db6ab736d --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java @@ -0,0 +1,148 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.common.support.stretching.AbstractStretchingScreen; +import com.refinedmods.refinedstorage2.platform.common.support.widget.CustomCheckboxWidget; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.resources.ResourceLocation; +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.createTranslation; + +public class SecurityCardScreen extends AbstractStretchingScreen { + private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/security_card.png"); + + private static final int BINDING_RIGHT_PADDING = 6; + private static final int BINDING_WIDTH = 80; + private static final MutableComponent UNBOUND_TITLE = Component.literal("<") + .append(createTranslation("gui", "security_card.unbound")) + .append(">"); + + private final List checkboxes = new ArrayList<>(); + + public SecurityCardScreen(final SecurityCardContainerMenu menu, + final Inventory playerInventory, + final Component text) { + super(menu, playerInventory, text); + this.inventoryLabelY = 97; + this.imageWidth = 193; + this.imageHeight = 176; + } + + @Override + protected void init() { + super.init(); + + checkboxes.clear(); + final List permissions = getMenu().getPermissions(); + for (int i = 0; i < permissions.size(); ++i) { + final CustomCheckboxWidget checkbox = createPermissionCheckbox(permissions.get(i), i); + addWidget(checkbox); + checkboxes.add(checkbox); + } + updateScrollbar(checkboxes.size()); + + final Button playerButton = Button.builder(UNBOUND_TITLE, btn -> toggleBoundPlayer()) + .pos(leftPos + imageWidth - BINDING_RIGHT_PADDING - BINDING_WIDTH, topPos + 4) + .size(BINDING_WIDTH, 14) + .build(); + addRenderableWidget(playerButton); + } + + private CustomCheckboxWidget createPermissionCheckbox( + final SecurityCardContainerMenu.Permission permission, + final int index + ) { + final CustomCheckboxWidget checkbox = new CustomCheckboxWidget( + leftPos + 10, + getPermissionCheckboxY(index), + permission.name(), + font, + false + ); + checkbox.setTooltip(getPermissionTooltip(permission)); + return checkbox; + } + + private Tooltip getPermissionTooltip(final SecurityCardContainerMenu.Permission permission) { + final MutableComponent ownerName = permission.ownerName().copy().withStyle( + Style.EMPTY.withItalic(true).withColor(ChatFormatting.GRAY) + ); + return Tooltip.create(permission.description().copy().append("\n").append(ownerName)); + } + + private int getPermissionCheckboxY(final int index) { + return topPos + 19 + (index * ROW_SIZE) + 3; + } + + @Override + protected int getScrollPanePadding() { + return 4; + } + + private void toggleBoundPlayer() { + // todo! + } + + @Override + protected void scrollbarChanged(final int rows) { + final int offset = getScrollbarOffset(); + for (int i = 0; i < checkboxes.size(); ++i) { + final CustomCheckboxWidget checkbox = checkboxes.get(i); + final int y = getPermissionCheckboxY(i) - offset; + checkbox.visible = y >= (topPos + 19 - ROW_SIZE) && y < (topPos + 19 + (rows * ROW_SIZE)); + checkbox.setY(y); + } + } + + @Override + protected void renderRows(final GuiGraphics graphics, + final int x, + final int y, + final int topHeight, + final int rows, + final int mouseX, + final int mouseY) { + for (final CustomCheckboxWidget checkbox : checkboxes) { + checkbox.render(graphics, mouseX, mouseY, 0); + } + } + + @Override + protected void renderStretchingBackground(final GuiGraphics graphics, final int x, final int y, final int rows) { + for (int row = 0; row < rows; ++row) { + int textureY = 37; + if (row == 0) { + textureY = 19; + } else if (row == rows - 1) { + textureY = 55; + } + graphics.blit(getTexture(), x, y + (ROW_SIZE * row), 0, textureY, imageWidth, ROW_SIZE); + } + } + + @Override + protected int getBottomHeight() { + return 99; + } + + @Override + protected int getBottomV() { + return 73; + } + + @Override + protected ResourceLocation getTexture() { + return TEXTURE; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageTooltipHelper.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageTooltipHelper.java index 8b7334c2b..3b3d562f0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageTooltipHelper.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/StorageTooltipHelper.java @@ -1,13 +1,13 @@ package com.refinedmods.refinedstorage2.platform.common.storage; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; - import java.util.List; import java.util.function.LongFunction; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + final class StorageTooltipHelper { private StorageTooltipHelper() { } @@ -15,7 +15,7 @@ private StorageTooltipHelper() { static void addAmountStoredWithoutCapacity(final List tooltip, final long stored, final LongFunction quantityFormatter) { - tooltip.add(PlatformApi.INSTANCE.createTranslation( + tooltip.add(createTranslation( "misc", "stored", Component.literal(quantityFormatter.apply(stored)).withStyle(ChatFormatting.WHITE) @@ -31,7 +31,7 @@ static void addAmountStoredWithCapacity(final List tooltip, return; } final int progress = (int) ((double) stored / capacity * 100D); - tooltip.add(PlatformApi.INSTANCE.createTranslation( + tooltip.add(createTranslation( "misc", "stored_with_capacity", Component.literal(quantityFormatter.apply(stored)).withStyle(ChatFormatting.WHITE), diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java index ab9a16b06..82dc1c709 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/AbstractPortableGridContainerMenu.java @@ -65,8 +65,8 @@ protected boolean canTransferSlot(final Slot slot) { } @Override - public void addSlots(final int playerInventoryY) { - super.addSlots(playerInventoryY); + public void initSlots(final int playerInventoryY) { + super.initSlots(playerInventoryY); diskSlot = new ValidatedSlot( diskInventory, 0, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java index 880c59258..799c8ac19 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridBlockContainerMenu.java @@ -15,7 +15,7 @@ public PortableGridBlockContainerMenu(final int syncId, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getPortableGridBlock(), syncId, playerInventory, buf); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); - addSlots(0); + initSlots(0); } PortableGridBlockContainerMenu(final int syncId, @@ -34,6 +34,6 @@ public PortableGridBlockContainerMenu(final int syncId, portableGrid::getRedstoneMode, portableGrid::setRedstoneMode )); - addSlots(0); + initSlots(0); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java index 995c5af9c..c6c58ffb2 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/portablegrid/PortableGridItemContainerMenu.java @@ -16,7 +16,7 @@ public PortableGridItemContainerMenu(final int syncId, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getPortableGridItem(), syncId, playerInventory, buf); this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); - addSlots(0); + initSlots(0); } PortableGridItemContainerMenu(final int syncId, @@ -34,6 +34,6 @@ public PortableGridItemContainerMenu(final int syncId, energyStorage ); this.disabledSlot = slotReference; - addSlots(0); + initSlots(0); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java new file mode 100644 index 000000000..eac896eea --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java @@ -0,0 +1,188 @@ +package com.refinedmods.refinedstorage2.platform.common.support.stretching; + +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseScreen; +import com.refinedmods.refinedstorage2.platform.common.support.widget.ScrollbarWidget; + +import javax.annotation.Nullable; + +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; + +public abstract class AbstractStretchingScreen + extends AbstractBaseScreen { + protected static final int ROW_SIZE = 18; + + private static final int TOP_HEIGHT = 19; + private static final int COLUMNS = 9; + private static final int MIN_ROWS = 3; + private static final int INVENTORY_INCLUDING_TITLE_HEIGHT = 99; + private static final int ROW_PADDING = 3; + + private int visibleRows; + @Nullable + private ScrollbarWidget scrollbar; + + protected AbstractStretchingScreen(final T menu, + final Inventory playerInventory, + final Component text) { + super(menu, playerInventory, text); + } + + @Override + protected void init() { + this.visibleRows = calculateVisibleRows(); + this.imageHeight = TOP_HEIGHT + (ROW_SIZE * visibleRows) + getBottomHeight(); + this.inventoryLabelY = imageHeight - INVENTORY_INCLUDING_TITLE_HEIGHT + 4; + + getMenu().initSlots(imageHeight - INVENTORY_INCLUDING_TITLE_HEIGHT + 17); + + super.init(); + + addSideButton(new ScreenSizeSideButtonWidget(this)); + + this.scrollbar = new ScrollbarWidget(leftPos + 174, topPos + 20, 12, (visibleRows * ROW_SIZE) - 2); + this.scrollbar.setListener(offset -> scrollbarChanged(visibleRows)); + addWidget(scrollbar); + } + + protected final int getScrollbarOffset() { + if (scrollbar == null) { + return 0; + } + final int scrollbarOffset = (int) scrollbar.getOffset(); + if (!scrollbar.isSmoothScrolling()) { + return scrollbarOffset * ROW_SIZE; + } + return scrollbarOffset; + } + + protected void scrollbarChanged(final int rows) { + // empty + } + + @Override + protected void renderBg(final GuiGraphics graphics, final float delta, final int mouseX, final int mouseY) { + final int x = (width - imageWidth) / 2; + final int y = (height - imageHeight) / 2; + renderBackground(graphics, x, y); + renderRows(graphics, mouseX, mouseY, x, y); + } + + private void renderBackground(final GuiGraphics graphics, final int x, final int y) { + graphics.blit(getTexture(), x, y, 0, 0, imageWidth, TOP_HEIGHT); + renderStretchingBackground(graphics, x, y + TOP_HEIGHT, visibleRows); + graphics.blit( + getTexture(), + x, + y + TOP_HEIGHT + (ROW_SIZE * visibleRows), + 0, + getBottomV(), + imageWidth, + getBottomHeight() + ); + } + + private void renderRows(final GuiGraphics graphics, final int mouseX, final int mouseY, final int x, final int y) { + graphics.enableScissor( + x + 7, + y + TOP_HEIGHT + 1, + x + 7 + (ROW_SIZE * COLUMNS), + y + TOP_HEIGHT + 1 + (ROW_SIZE * visibleRows) - 2 + ); + renderRows(graphics, x, y, TOP_HEIGHT, visibleRows, mouseX, mouseY); + graphics.disableScissor(); + } + + protected abstract void renderRows( + GuiGraphics graphics, + int x, + int y, + int topHeight, + int rows, + int mouseX, + int mouseY + ); + + protected abstract void renderStretchingBackground(GuiGraphics graphics, int x, int y, int rows); + + @Override + public void render(final GuiGraphics graphics, final int mouseX, final int mouseY, final float partialTicks) { + super.render(graphics, mouseX, mouseY, partialTicks); + if (scrollbar != null) { + scrollbar.render(graphics, mouseX, mouseY, partialTicks); + } + } + + @Override + public boolean mouseClicked(final double mouseX, final double mouseY, final int clickedButton) { + if (scrollbar != null && scrollbar.mouseClicked(mouseX, mouseY, clickedButton)) { + return true; + } + return super.mouseClicked(mouseX, mouseY, clickedButton); + } + + @Override + public void mouseMoved(final double mx, final double my) { + if (scrollbar != null) { + scrollbar.mouseMoved(mx, my); + } + super.mouseMoved(mx, my); + } + + @Override + public boolean mouseReleased(final double mx, final double my, final int button) { + return (scrollbar != null && scrollbar.mouseReleased(mx, my, button)) || super.mouseReleased(mx, my, button); + } + + @Override + public boolean mouseScrolled(final double x, final double y, final double z, final double delta) { + final boolean didScrollbar = scrollbar != null + && !hasShiftDown() + && !hasControlDown() + && scrollbar.mouseScrolled(x, y, z, delta); + return didScrollbar || super.mouseScrolled(x, y, z, delta); + } + + private int calculateVisibleRows() { + final int screenSpaceAvailable = height - TOP_HEIGHT - getBottomHeight(); + final int maxRows = getMaxRows(); + return Math.max(MIN_ROWS, Math.min((screenSpaceAvailable / ROW_SIZE) - ROW_PADDING, maxRows)); + } + + protected final boolean isInStretchedArea(final int y) { + return y >= TOP_HEIGHT && y < TOP_HEIGHT + (ROW_SIZE * visibleRows); + } + + private int getMaxRows() { + return switch (Platform.INSTANCE.getConfig().getScreenSize()) { + case STRETCH -> Platform.INSTANCE.getConfig().getMaxRowsStretch(); + case SMALL -> 3; + case MEDIUM -> 5; + case LARGE -> 8; + case EXTRA_LARGE -> 12; + }; + } + + protected final void updateScrollbar(final int totalRows) { + if (scrollbar == null) { + return; + } + scrollbar.setEnabled(totalRows > visibleRows); + final int rowsExcludingVisibleOnes = totalRows - visibleRows; + final int maxOffset = scrollbar.isSmoothScrolling() + ? ((rowsExcludingVisibleOnes * ROW_SIZE) + getScrollPanePadding()) + : rowsExcludingVisibleOnes; + scrollbar.setMaxOffset(maxOffset); + } + + protected abstract int getBottomHeight(); + + protected abstract int getBottomV(); + + protected int getScrollPanePadding() { + return 0; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridSize.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSize.java similarity index 69% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridSize.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSize.java index f045e4881..79efb5b0c 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/GridSize.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSize.java @@ -1,13 +1,13 @@ -package com.refinedmods.refinedstorage2.platform.common.grid; +package com.refinedmods.refinedstorage2.platform.common.support.stretching; -public enum GridSize { +public enum ScreenSize { STRETCH, SMALL, MEDIUM, LARGE, EXTRA_LARGE; - public GridSize toggle() { + public ScreenSize toggle() { return switch (this) { case STRETCH -> SMALL; case SMALL -> MEDIUM; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java new file mode 100644 index 000000000..f26c565bf --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeListener.java @@ -0,0 +1,5 @@ +package com.refinedmods.refinedstorage2.platform.common.support.stretching; + +public interface ScreenSizeListener { + void initSlots(int playerInventoryY); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/SizeSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeSideButtonWidget.java similarity index 53% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/SizeSideButtonWidget.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeSideButtonWidget.java index 957c0b467..e4affb966 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/SizeSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/ScreenSizeSideButtonWidget.java @@ -1,35 +1,36 @@ -package com.refinedmods.refinedstorage2.platform.common.grid.screen; +package com.refinedmods.refinedstorage2.platform.common.support.stretching; -import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractSideButtonWidget; import net.minecraft.network.chat.MutableComponent; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -class SizeSideButtonWidget extends AbstractSideButtonWidget { - private static final MutableComponent TITLE = createTranslation("gui", "grid.size"); +public class ScreenSizeSideButtonWidget extends AbstractSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "screen_size"); - private static final MutableComponent SUBTEXT_STRETCH = createTranslation("gui", "grid.size.stretch"); - private static final MutableComponent SUBTEXT_SMALL = createTranslation("gui", "grid.size.small"); - private static final MutableComponent SUBTEXT_MEDIUM = createTranslation("gui", "grid.size.medium"); - private static final MutableComponent SUBTEXT_LARGE = createTranslation("gui", "grid.size.large"); - private static final MutableComponent SUBTEXT_EXTRA_LARGE = createTranslation("gui", "grid.size.extra_large"); + private static final MutableComponent SUBTEXT_STRETCH = createTranslation("gui", "screen_size.stretch"); + private static final MutableComponent SUBTEXT_SMALL = createTranslation("gui", "screen_size.small"); + private static final MutableComponent SUBTEXT_MEDIUM = createTranslation("gui", "screen_size.medium"); + private static final MutableComponent SUBTEXT_LARGE = createTranslation("gui", "screen_size.large"); + private static final MutableComponent SUBTEXT_EXTRA_LARGE = createTranslation("gui", "screen_size.extra_large"); - private final AbstractGridContainerMenu menu; - - SizeSideButtonWidget(final AbstractGridContainerMenu menu) { - super(createPressAction(menu)); - this.menu = menu; + public ScreenSizeSideButtonWidget(final AbstractStretchingScreen stretchingScreen) { + super(createPressAction(stretchingScreen)); } - private static OnPress createPressAction(final AbstractGridContainerMenu menu) { - return btn -> menu.setSize(menu.getSize().toggle()); + private static OnPress createPressAction(final AbstractStretchingScreen stretchingScreen) { + return btn -> { + Platform.INSTANCE.getConfig().setScreenSize(Platform.INSTANCE.getConfig().getScreenSize().toggle()); + stretchingScreen.init(); + }; } @Override protected int getXTexture() { - return switch (menu.getSize()) { + final ScreenSize screenSize = Platform.INSTANCE.getConfig().getScreenSize(); + return switch (screenSize) { case STRETCH -> 64 + 48; case SMALL -> 64; case MEDIUM -> 64 + 16; @@ -49,7 +50,8 @@ protected MutableComponent getTitle() { @Override protected MutableComponent getSubText() { - return switch (menu.getSize()) { + final ScreenSize screenSize = Platform.INSTANCE.getConfig().getScreenSize(); + return switch (screenSize) { case STRETCH -> SUBTEXT_STRETCH; case SMALL -> SUBTEXT_SMALL; case MEDIUM -> SUBTEXT_MEDIUM; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/package-info.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/package-info.java new file mode 100644 index 000000000..c18a46a5b --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.platform.common.support.stretching; + +import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java new file mode 100644 index 000000000..3912a253f --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java @@ -0,0 +1,76 @@ +package com.refinedmods.refinedstorage2.platform.common.support.widget; + +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractButton; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +// A custom checkbox so we can change the font color. +public class CustomCheckboxWidget extends AbstractButton { + private static final ResourceLocation CHECKBOX_SELECTED_HIGHLIGHTED_SPRITE = new ResourceLocation( + "widget/checkbox_selected_highlighted" + ); + private static final ResourceLocation CHECKBOX_SELECTED_SPRITE = new ResourceLocation( + "widget/checkbox_selected" + ); + private static final ResourceLocation CHECKBOX_HIGHLIGHTED_SPRITE = new ResourceLocation( + "widget/checkbox_highlighted" + ); + private static final ResourceLocation CHECKBOX_SPRITE = new ResourceLocation("widget/checkbox"); + + private static final int BOX_SIZE = 9 + 8; + + private boolean selected; + + public CustomCheckboxWidget(final int x, + final int y, + final Component text, + final Font font, + final boolean selected) { + super(x, y, BOX_SIZE + 4 + font.width(text), BOX_SIZE, text); + this.selected = selected; + } + + public void onPress() { + this.selected = !this.selected; + } + + public boolean selected() { + return this.selected; + } + + public void updateWidgetNarration(final NarrationElementOutput output) { + output.add(NarratedElementType.TITLE, this.createNarrationMessage()); + if (this.active) { + if (this.isFocused()) { + output.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.focused")); + } else { + output.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.hovered")); + } + } + } + + public void renderWidget(final GuiGraphics graphics, final int mouseX, final int mouseY, final float partialTicks) { + final Minecraft minecraft = Minecraft.getInstance(); + RenderSystem.enableDepthTest(); + final Font font = minecraft.font; + graphics.setColor(1.0F, 1.0F, 1.0F, this.alpha); + RenderSystem.enableBlend(); + final ResourceLocation sprite; + if (selected) { + sprite = isFocused() ? CHECKBOX_SELECTED_HIGHLIGHTED_SPRITE : CHECKBOX_SELECTED_SPRITE; + } else { + sprite = isFocused() ? CHECKBOX_HIGHLIGHTED_SPRITE : CHECKBOX_SPRITE; + } + final int x = getX() + BOX_SIZE + 4; + final int y = (getY() + (height >> 1)) - (9 >> 1); + graphics.blitSprite(sprite, getX(), getY(), BOX_SIZE, BOX_SIZE); + graphics.setColor(1.0F, 1.0F, 1.0F, 1.0F); + graphics.drawString(font, getMessage(), x, y, 4210752, false); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java index 2925c0a8a..9111b4348 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/ScrollbarWidget.java @@ -1,5 +1,10 @@ package com.refinedmods.refinedstorage2.platform.common.support.widget; +import com.refinedmods.refinedstorage2.platform.common.Platform; + +import java.util.function.DoubleConsumer; +import javax.annotation.Nullable; + import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.narration.NarrationElementOutput; @@ -15,27 +20,31 @@ public class ScrollbarWidget extends AbstractWidget { private static final int ANIMATION_SCROLL_DURATION_IN_TICKS = 10; private static final double ANIMATION_SCROLL_HEIGHT_IN_PIXELS = 30; + private final boolean smoothScrolling; + private double offset; private double maxOffset; private boolean enabled = true; private boolean clicked; - private boolean scrollAnimation; private int animationScrollDirection = 0; private double animationStartOffset; private double animationTickCounter; private int animationSpeed; + @Nullable + private DoubleConsumer listener; public ScrollbarWidget(final int x, final int y, final int width, final int height) { super(x, y, width, height, Component.empty()); + this.smoothScrolling = Platform.INSTANCE.getConfig().isSmoothScrolling(); } - public boolean isScrollAnimation() { - return scrollAnimation; + public void setListener(@Nullable final DoubleConsumer listener) { + this.listener = listener; } - public void setScrollAnimation(final boolean scrollAnimation) { - this.scrollAnimation = scrollAnimation; + public boolean isSmoothScrolling() { + return smoothScrolling; } public void setEnabled(final boolean enabled) { @@ -127,7 +136,7 @@ public boolean mouseReleased(final double mouseX, final double mouseY, final int public boolean mouseScrolled(final double x, final double y, final double z, final double delta) { if (enabled) { final int scrollDirection = Math.max(Math.min(-(int) delta, 1), -1); - if (scrollAnimation) { + if (smoothScrolling) { startScrollAnimation(scrollDirection); } else { setOffset(offset + scrollDirection); @@ -161,6 +170,9 @@ public double getOffset() { public void setOffset(final double offset) { this.offset = Math.min(Math.max(0, offset), maxOffset); + if (listener != null) { + listener.accept(this.offset); + } } private void updateOffset(final double mouseY) { 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 23e61b007..943ade269 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 @@ -47,12 +47,6 @@ "gui.refinedstorage2.grid.sorting.type.name": "Name", "gui.refinedstorage2.grid.sorting.type.id": "ID", "gui.refinedstorage2.grid.sorting.type.last_modified": "Last modified", - "gui.refinedstorage2.grid.size": "Size", - "gui.refinedstorage2.grid.size.stretch": "Stretch", - "gui.refinedstorage2.grid.size.small": "Small", - "gui.refinedstorage2.grid.size.medium": "Medium", - "gui.refinedstorage2.grid.size.large": "Large", - "gui.refinedstorage2.grid.size.extra_large": "Extra large", "gui.refinedstorage2.grid.auto_selected": "Auto-selected", "gui.refinedstorage2.grid.auto_selected.help": "Whether to auto-select the search box when opening the Grid.", "gui.refinedstorage2.grid.synchronizer": "Synchronization mode", @@ -71,6 +65,12 @@ "gui.refinedstorage2.grid.resource_type.help": "Filter specific resource types.", "gui.refinedstorage2.crafting_grid.move.network": "Move items to network", "gui.refinedstorage2.crafting_grid.move.inventory": "Move items to inventory", + "gui.refinedstorage2.screen_size": "Screen size", + "gui.refinedstorage2.screen_size.stretch": "Stretch", + "gui.refinedstorage2.screen_size.small": "Small", + "gui.refinedstorage2.screen_size.medium": "Medium", + "gui.refinedstorage2.screen_size.large": "Large", + "gui.refinedstorage2.screen_size.extra_large": "Extra large", "gui.refinedstorage2.detector.mode": "Mode", "gui.refinedstorage2.detector.mode.under": "Emit redstone signal when under the amount", "gui.refinedstorage2.detector.mode.equal": "Emit redstone signal when on the amount", @@ -142,6 +142,7 @@ "gui.refinedstorage2.network_transmitter.status.missing_network_card": "Missing Network Card", "gui.refinedstorage2.network_transmitter.status.transmitting": "%d block(s)", "gui.refinedstorage2.network_transmitter.status.receiver_unreachable": "Unreachable", + "gui.refinedstorage2.security_card.unbound": "Unbound", "item.refinedstorage2.controller.help": "Provides the storage network with energy. Multiple are allowed in a single storage network.", "item.refinedstorage2.creative_controller.help": "Provides the storage network with an infinite source of energy.", "item.refinedstorage2.disk_drive.help": "Accepts storage disks to provide the storage network with storage space.", @@ -220,6 +221,10 @@ "item.refinedstorage2.network_card.bound_help": "Insert into a Network Transmitter. Use while crouching to clear binding.", "item.refinedstorage2.network_card.bound": "Bound to %d, %d, %d in %s.", "item.refinedstorage2.security_card": "Security Card", + "item.refinedstorage2.security_card.unbound": "Unbound.", + "item.refinedstorage2.security_card.unbound.help": "Use while crouching to bind to the current player. Right click to configure.", + "item.refinedstorage2.security_card.bound": "Bound to %s.", + "item.refinedstorage2.security_card.bound.help": "Use while crouching to clear binding. Right click to configure.", "misc.refinedstorage2.stored": "Stored: %s", "misc.refinedstorage2.stored_with_capacity": "Stored: %s / %s (%d%%)", "misc.refinedstorage2.total": "%d total", @@ -247,21 +252,33 @@ "category.refinedstorage2.key_bindings": "Refined Storage 2", "curios.identifier.refinedstorage2": "Refined Storage 2", "trinkets.slot.refinedstorage2.wireless": "Refined Storage 2", + "permission.refinedstorage2.insert": "Insert", + "permission.refinedstorage2.insert.description": "Whether the player can insert resources in a network.", + "permission.refinedstorage2.extract": "Extract", + "permission.refinedstorage2.extract.description": "Whether the player can extract resources from a network.", + "permission.refinedstorage2.autocrafting": "Autocrafting", + "permission.refinedstorage2.autocrafting.description": "Whether the player can start, cancel or view an autocrafting task.", + "permission.refinedstorage2.modify": "Modify", + "permission.refinedstorage2.modify.description": "Whether the player can open network device GUIs.", + "permission.refinedstorage2.build": "Build", + "permission.refinedstorage2.build.description": "Whether the player can add or remove network devices.", + "permission.refinedstorage2.security": "Security", + "permission.refinedstorage2.security.description": "Whether the player can manage the security options for a network.", "text.autoconfig.refinedstorage2.title": "Refined Storage 2", + "text.autoconfig.refinedstorage2.option.smoothScrolling": "Smooth scrolling", "text.autoconfig.refinedstorage2.option.grid": "Grid", "text.autoconfig.refinedstorage2.option.grid.largeFont": "Large font", - "text.autoconfig.refinedstorage2.option.grid.maxRowsStretch": "Maximum amount of rows when stretched", "text.autoconfig.refinedstorage2.option.grid.preventSortingWhileShiftIsDown": "Prevent sorting while SHIFT is down", "text.autoconfig.refinedstorage2.option.grid.detailedTooltip": "Detailed tooltip", "text.autoconfig.refinedstorage2.option.grid.rememberSearchQuery": "Remember search query", "text.autoconfig.refinedstorage2.option.grid.energyUsage": "Energy usage", - "text.autoconfig.refinedstorage2.option.grid.smoothScrolling": "Smooth scrolling", "text.autoconfig.refinedstorage2.option.grid.autoSelected": "Auto selected search box", "text.autoconfig.refinedstorage2.option.grid.synchronizer": "Synchronizer", "text.autoconfig.refinedstorage2.option.grid.resourceTypeId": "Resource type", "text.autoconfig.refinedstorage2.option.grid.sortingDirection": "Sorting direction", "text.autoconfig.refinedstorage2.option.grid.sortingType": "Sorting type", - "text.autoconfig.refinedstorage2.option.grid.size": "Size", + "text.autoconfig.refinedstorage2.option.screenSize": "Screen size", + "text.autoconfig.refinedstorage2.option.maxRowsStretch": "Maximum amount of rows when screen size is stretched", "text.autoconfig.refinedstorage2.option.craftingGrid": "Crafting Grid", "text.autoconfig.refinedstorage2.option.craftingGrid.energyUsage": "Energy usage", "text.autoconfig.refinedstorage2.option.craftingGrid.craftingMatrixCloseBehavior": "Crafting matrix close behavior", diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/security_card.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/gui/security_card.png index de3f689808cebc73f03e7767eb29731f0cc5d969..a6e5b98c47836cb127fe45c043e5a7c86055ec7f 100644 GIT binary patch literal 1100 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIGvAv!{z= zNX4ADcW>uD3J__#m^&qCg;L&Qlcpzj8A|y9>{Fgr&TuiF?D!-}+UMWadqo$YX>{2q zYTtVKs(+(`d-;3jH3x6=C(5{Ax3}E2ZnaS3tts8}9hP5Sd208)SFd6j&OQJ9*N@qJ z)BX3WSG_8*2w~kXeB;mG#%}pdId=cV9xNAP;80@_@L^Dx!Qf!P*pR@)aFB(eiIagv z7)`?e`o0~v-{zI_?O3rjtoHu@&pY4$iHnWFv%bmAnlj9d`4Lkn$qD=8V+vV?npDf<-=CD0$-df+P z#zcu%6*jYy&uxDm@o%FHiD9{W7eCP8!v;Qeg2iVN=k8i1b-ZxRs$cmZn|d9dtw}uh zyVoKAzwC|r?{m+&DHMmBcjWe`Tg6D^IXoJwI9bLQxKjQTo^7 z9G0lQbkbsev*3w2SI;L}hMO}Tl)A}bA`kcNhSmIxxvXaCyv6tOS<~#cG0oom%Tmry z|F|w@62SfqVbl%lASXTU3l<9ZBZZF$?G>J!0!vFA5{|mQo-em(bxP3M=R_H7IwetZ)DsCtLV zVFm+sbmQiJmYDU|#rGdD@lD=;e|GY@?a$YQt?qtaaBF!zmyPdbSN#n)bB@*RH$Ofn z|NO>3kIV2FhH1%-o3#u;-{@6VuneX!!iDa4nUDT_Ch^?yUWfPp zWpC7f-#Z5+P}kS%u>G+lLklO-=q5+Xxi`-Xtj(Ba8vnL5W4a48f+B;`&6y6$+~g>+ z&0|#XVE~~wZ=4;X8_&)>Jf}apai<)J`B#R2dH!)-qFo8}&rPlzutT>oeJ;ph-6sc2 z&^A-PZ~q^2{If)|j#&4{Z{MD^a~t|Ue&4RqJ$?H0>iMku-dtyP(EIX{^VLVa getResourceTypeId() { if (resourceTypeId == null || resourceTypeId.trim().isBlank()) { 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 93908e0ec..31b8aec40 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 @@ -6,6 +6,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntityTypeFactory; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.content.CreativeModeTabItems; import com.refinedmods.refinedstorage2.platform.common.content.DirectRegistryCallback; import com.refinedmods.refinedstorage2.platform.common.content.Items; @@ -13,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; @@ -84,7 +86,6 @@ import team.reborn.energy.api.EnergyStorage; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; public class ModInitializerImpl extends AbstractModInitializer implements ModInitializer { private static final Logger LOGGER = LoggerFactory.getLogger(ModInitializerImpl.class); @@ -241,6 +242,15 @@ public boolean allowNbtUpdateAnimation(final Player player, final ItemStack newStack) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } + }, + () -> new SecurityCardItem() { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } } ); registerUpgradeMappings(); @@ -272,7 +282,7 @@ private void registerCreativeModeTab() { BuiltInRegistries.CREATIVE_MODE_TAB, createIdentifier("general"), CreativeModeTab.builder(CreativeModeTab.Row.TOP, 0) - .title(createTranslation("itemGroup", "general")) + .title(ContentNames.MOD) .icon(() -> new ItemStack(Blocks.INSTANCE.getCreativeController().getDefault())) .displayItems((params, output) -> CreativeModeTabItems.append(output::accept)) .build() 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 3055b0a68..202a56c63 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 @@ -4,8 +4,8 @@ import com.refinedmods.refinedstorage2.platform.common.Config; import com.refinedmods.refinedstorage2.platform.common.content.DefaultEnergyUsage; import com.refinedmods.refinedstorage2.platform.common.grid.CraftingGridMatrixCloseBehavior; -import com.refinedmods.refinedstorage2.platform.common.grid.GridSize; import com.refinedmods.refinedstorage2.platform.common.grid.GridSortingTypes; +import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSize; import java.util.Optional; @@ -40,6 +40,9 @@ public class ConfigImpl implements Config { private final SimpleEnergyUsageEntry networkReceiver; private final SimpleEnergyUsageEntry networkTransmitter; private final PortableGridEntry portableGrid; + private final ModConfigSpec.BooleanValue smoothScrolling; + private final ModConfigSpec.EnumValue screenSize; + private final ModConfigSpec.IntValue maxRowsStretch; public ConfigImpl() { cable = new SimpleEnergyUsageEntryImpl("cable", "Cable", DefaultEnergyUsage.CABLE); @@ -79,6 +82,15 @@ public ConfigImpl() { DefaultEnergyUsage.NETWORK_TRANSMITTER ); portableGrid = new PortableGridEntryImpl(); + smoothScrolling = builder + .comment("Whether scrollbars should use smooth scrolling") + .define("smoothScrolling", true); + screenSize = builder + .comment("The screen size") + .defineEnum("screenSize", ScreenSize.STRETCH); + maxRowsStretch = builder + .comment("The maximum amount of rows that can be displayed when the screen size is stretched") + .defineInRange("maxRowsStretch", 256, 3, 256); spec = builder.build(); } @@ -86,6 +98,16 @@ public ModConfigSpec getSpec() { return spec; } + @Override + public ScreenSize getScreenSize() { + return screenSize.get(); + } + + @Override + public void setScreenSize(final ScreenSize screenSize) { + this.screenSize.set(screenSize); + } + @Override public GridEntry getGrid() { return grid; @@ -191,6 +213,16 @@ public PortableGridEntry getPortableGrid() { return portableGrid; } + @Override + public boolean isSmoothScrolling() { + return smoothScrolling.get(); + } + + @Override + public int getMaxRowsStretch() { + return maxRowsStretch.get(); + } + private class SimpleEnergyUsageEntryImpl implements SimpleEnergyUsageEntry { private final ModConfigSpec.LongValue energyUsage; @@ -250,27 +282,21 @@ public long getEnergyUsagePerDisk() { private class GridEntryImpl implements GridEntry { private final ModConfigSpec.BooleanValue largeFont; - private final ModConfigSpec.IntValue maxRowsStretch; private final ModConfigSpec.BooleanValue preventSortingWhileShiftIsDown; private final ModConfigSpec.BooleanValue detailedTooltip; private final ModConfigSpec.BooleanValue rememberSearchQuery; private final ModConfigSpec.LongValue energyUsage; - private final ModConfigSpec.BooleanValue smoothScrolling; private final ModConfigSpec.BooleanValue autoSelected; private final ModConfigSpec.ConfigValue synchronizer; private final ModConfigSpec.ConfigValue resourceType; private final ModConfigSpec.EnumValue sortingDirection; private final ModConfigSpec.EnumValue sortingType; - private final ModConfigSpec.EnumValue size; GridEntryImpl() { builder.push("grid"); largeFont = builder .comment("Whether the Grid should use a large font for quantities") .define("largeFont", false); - maxRowsStretch = builder - .comment("The maximum amount of rows that can be displayed when the Grid is in stretch view mode") - .defineInRange("maxRowsStretch", 256, 3, 256); preventSortingWhileShiftIsDown = builder .comment("Whether the Grid should avoid sorting when shift is held down") .define("preventSortingWhileShiftIsDown", true); @@ -283,9 +309,6 @@ private class GridEntryImpl implements GridEntry { energyUsage = builder .comment("The energy used by the Grid") .defineInRange(ENERGY_USAGE, DefaultEnergyUsage.GRID, 0, Long.MAX_VALUE); - smoothScrolling = builder - .comment("Whether the Grid should use smooth scrolling") - .define("smoothScrolling", true); autoSelected = builder .comment("Whether the Grid search box is auto selected") .define("autoSelected", false); @@ -301,9 +324,6 @@ private class GridEntryImpl implements GridEntry { sortingType = builder .comment("The sorting type") .defineEnum("sortingType", GridSortingTypes.QUANTITY); - size = builder - .comment("The size") - .defineEnum("size", GridSize.STRETCH); builder.pop(); } @@ -312,11 +332,6 @@ public boolean isLargeFont() { return largeFont.get(); } - @Override - public int getMaxRowsStretch() { - return maxRowsStretch.get(); - } - @Override public boolean isPreventSortingWhileShiftIsDown() { return preventSortingWhileShiftIsDown.get(); @@ -337,11 +352,6 @@ public long getEnergyUsage() { return energyUsage.get(); } - @Override - public boolean isSmoothScrolling() { - return smoothScrolling.get(); - } - @Override public boolean isAutoSelected() { return autoSelected.get(); @@ -390,16 +400,6 @@ public void setSortingType(final GridSortingTypes sortingType) { this.sortingType.set(sortingType); } - @Override - public GridSize getSize() { - return this.size.get(); - } - - @Override - public void setSize(final GridSize size) { - this.size.set(size); - } - @Override public Optional getResourceTypeId() { if (resourceType == null || resourceType.get().trim().isBlank()) { 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 a1edc8856..01885de40 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 @@ -6,6 +6,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntityTypeFactory; import com.refinedmods.refinedstorage2.platform.common.content.Blocks; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.content.CreativeModeTabItems; import com.refinedmods.refinedstorage2.platform.common.content.DirectRegistryCallback; import com.refinedmods.refinedstorage2.platform.common.content.Items; @@ -13,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.RegistryCallback; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseBlock; @@ -96,7 +98,6 @@ import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.MOD_ID; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @Mod(IdentifierUtil.MOD_ID) public class ModInitializer extends AbstractModInitializer { @@ -245,6 +246,14 @@ public boolean shouldCauseReequipAnimation(final ItemStack oldStack, final boolean slotChanged) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } + }, + () -> new SecurityCardItem() { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } } ); itemRegistry.register(eventBus); @@ -358,7 +367,7 @@ public void onRegister(final RegisterEvent e) { e.register(Registries.CREATIVE_MODE_TAB, helper -> helper.register( createIdentifier("general"), CreativeModeTab.builder() - .title(createTranslation("itemGroup", "general")) + .title(ContentNames.MOD) .icon(() -> new ItemStack(Blocks.INSTANCE.getController().getDefault())) .displayItems((params, output) -> CreativeModeTabItems.append(output::accept)) .build() From 52bbb3a7780ad1d5f7be449c1ef709c7b885112d Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 31 Mar 2024 13:11:42 +0200 Subject: [PATCH 6/7] feat: security security logic --- CHANGELOG.md | 11 ++ .../security/SecurityDecisionProvider.java | 1 + .../security/SecurityNetworkComponent.java | 1 + .../SecurityNetworkComponentImplTest.java | 30 ++- .../api/security/PlatformPermission.java | 2 + .../grid/screen/AbstractGridScreen.java | 4 +- .../common/security/BuiltinPermission.java | 5 + .../security/SecurityCardContainerMenu.java | 137 ++++++++++++- .../SecurityCardExtendedMenuProvider.java | 26 ++- .../common/security/SecurityCardItem.java | 73 ++++--- .../common/security/SecurityCardModel.java | 89 +++++++++ .../common/security/SecurityCardScreen.java | 180 ++++++++++++++---- .../support/ClientToServerCommunications.java | 9 + .../common/support/packet/PacketIds.java | 5 + .../stretching/AbstractStretchingScreen.java | 10 +- .../support/widget/CustomCheckboxWidget.java | 26 ++- .../assets/refinedstorage2/lang/en_us.json | 3 + .../platform/fabric/ModInitializerImpl.java | 15 ++ .../c2s/ClientToServerCommunicationsImpl.java | 27 +++ .../c2s/SecurityCardBoundPlayerPacket.java | 27 +++ .../c2s/SecurityCardPermissionPacket.java | 26 +++ .../SecurityCardResetPermissionPacket.java | 25 +++ .../platform/forge/ModInitializer.java | 18 ++ .../c2s/ClientToServerCommunicationsImpl.java | 17 ++ .../c2s/SecurityCardBoundPlayerPacket.java | 42 ++++ .../c2s/SecurityCardPermissionPacket.java | 35 ++++ .../SecurityCardResetPermissionPacket.java | 33 ++++ 27 files changed, 787 insertions(+), 90 deletions(-) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardBoundPlayerPacket.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java create mode 100644 refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardBoundPlayerPacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java create mode 100644 refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e384f902..82119cd5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Security Card + +### Changed + +- The permissions for a Security Card must be configured through the card itself, instead of via the Security Manager. +- The Security Card can be bound to other (currently online) players via its GUI. +- The binding of a Security Card can now be cleared. +- The Security Card tooltip and GUI now show whether the permission has been touched/changed in any way. + ### Fixed - Wireless Grid name not being correct in the GUI. diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java index fe65abda1..effdbe7cc 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityDecisionProvider.java @@ -3,6 +3,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +@FunctionalInterface public interface SecurityDecisionProvider { SecurityDecision isAllowed(Permission permission, SecurityActor actor); } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java index 834fc0332..fcda6ad8c 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityNetworkComponent.java @@ -5,6 +5,7 @@ import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") +@FunctionalInterface public interface SecurityNetworkComponent extends NetworkComponent { boolean isAllowed(Permission permission, SecurityActor actor); } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java index 36f8b1158..198fa3115 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/security/SecurityNetworkComponentImplTest.java @@ -1,12 +1,15 @@ package com.refinedmods.refinedstorage2.api.network.impl.security; +import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; +import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer; import com.refinedmods.refinedstorage2.api.network.security.Permission; import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; +import com.refinedmods.refinedstorage2.api.network.security.SecurityDecision; +import com.refinedmods.refinedstorage2.api.network.security.SecurityDecisionProvider; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -18,12 +21,13 @@ void setUp() { sut = new SecurityNetworkComponentImpl(); } - @EnumSource(TestPermissions.class) - @ParameterizedTest - void everythingIsAllowedByDefault(final TestPermissions permission) { + @Test + void everythingIsAllowedByDefault() { // Act & assert - assertThat(sut.isAllowed(permission, TestActors.X)).isTrue(); - assertThat(sut.isAllowed(permission, TestActors.Y)).isTrue(); + sut.onContainerAdded(new TestContainer()); + assertThat(sut.isAllowed(TestPermissions.A, TestActors.X)).isTrue(); + assertThat(sut.isAllowed(TestPermissions.B, TestActors.Y)).isFalse(); + sut.onContainerRemoved(new TestContainer()); } enum TestPermissions implements Permission { @@ -33,4 +37,16 @@ enum TestPermissions implements Permission { enum TestActors implements SecurityActor { X, Y } + + private static class TestContainer implements SecurityDecisionProvider, NetworkNodeContainer { + @Override + public SecurityDecision isAllowed(final Permission permission, final SecurityActor actor) { + return permission == TestPermissions.A ? SecurityDecision.ALLOW : SecurityDecision.DENY; + } + + @Override + public NetworkNode getNode() { + throw new RuntimeException(); + } + } } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java index 67ca7333c..d93d77ef0 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformPermission.java @@ -12,4 +12,6 @@ public interface PlatformPermission extends Permission { Component getDescription(); Component getOwnerName(); + + boolean isAllowedByDefault(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java index 454afcd89..dd20dde26 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/grid/screen/AbstractGridScreen.java @@ -71,11 +71,9 @@ protected AbstractGridScreen(final T menu, } @Override - protected void init() { + protected void init(final int rows) { LOGGER.info("Initializing grid screen"); - super.init(); - if (searchField == null) { searchField = new GridSearchBoxWidget( font, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java index ba2f4ba90..bd2d820a6 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/BuiltinPermission.java @@ -73,4 +73,9 @@ public Component getDescription() { public Component getOwnerName() { return ContentNames.MOD; } + + @Override + public boolean isAllowedByDefault() { + return true; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java index 4bbc6bdbd..40e71de9f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java @@ -1,57 +1,182 @@ package com.refinedmods.refinedstorage2.platform.common.security; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSizeListener; import java.util.ArrayList; import java.util.List; +import java.util.UUID; +import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; public class SecurityCardContainerMenu extends AbstractBaseContainerMenu implements ScreenSizeListener { private final Inventory playerInventory; - private final List permissions; + private final List permissions = new ArrayList<>(); + private final List players = new ArrayList<>(); + + @Nullable + private Player boundTo; public SecurityCardContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { super(Menus.INSTANCE.getSecurityCard(), syncId); this.playerInventory = playerInventory; - this.permissions = new ArrayList<>(); + this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); + final int amountOfPermissions = buf.readInt(); for (int i = 0; i < amountOfPermissions; ++i) { final ResourceLocation id = buf.readResourceLocation(); + final boolean allowed = buf.readBoolean(); + final boolean dirty = buf.readBoolean(); PlatformApi.INSTANCE.getPermissionRegistry().get(id).ifPresent(permission -> permissions.add(new Permission( id, permission.getName(), permission.getDescription(), - permission.getOwnerName() + permission.getOwnerName(), + allowed, + dirty ))); } + + if (buf.readBoolean()) { + this.boundTo = new Player(buf.readUUID(), buf.readUtf()); + } + + final int amountOfPlayers = buf.readInt(); + for (int i = 0; i < amountOfPlayers; ++i) { + final UUID id = buf.readUUID(); + final String name = buf.readUtf(); + players.add(new Player(id, name)); + } } - SecurityCardContainerMenu(final int syncId, final Inventory playerInventory) { + SecurityCardContainerMenu(final int syncId, final Inventory playerInventory, final SlotReference disabledSlot) { super(Menus.INSTANCE.getSecurityCard(), syncId); this.playerInventory = playerInventory; - this.permissions = new ArrayList<>(); + this.disabledSlot = disabledSlot; } List getPermissions() { return permissions; } + List getPlayers() { + return players; + } + + @Nullable + Player getBoundTo() { + return boundTo; + } + @Override public void initSlots(final int playerInventoryY) { resetSlots(); addPlayerInventory(playerInventory, 8, playerInventoryY); } - record Permission(ResourceLocation id, Component name, Component description, Component ownerName) { + public void setPermission(final ResourceLocation permissionId, final boolean allowed) { + if (disabledSlot == null) { + return; + } + disabledSlot.resolve(playerInventory.player).ifPresent(stack -> setPermission(permissionId, allowed, stack)); + } + + private void setPermission(final ResourceLocation permissionId, final boolean allowed, final ItemStack stack) { + if (stack.getItem() instanceof SecurityCardItem securityCardItem) { + securityCardItem.getModel(stack).setPermission(permissionId, allowed); + } + } + + public void resetPermissionServer(final ResourceLocation permissionId) { + if (disabledSlot == null) { + return; + } + disabledSlot.resolve(playerInventory.player).ifPresent(stack -> resetPermissionServer(permissionId, stack)); + } + + private void resetPermissionServer(final ResourceLocation permissionId, final ItemStack stack) { + if (stack.getItem() instanceof SecurityCardItem securityCardItem) { + securityCardItem.getModel(stack).resetPermission(permissionId); + } + } + + public void setBoundPlayer(final MinecraftServer server, @Nullable final UUID playerId) { + if (disabledSlot == null) { + return; + } + disabledSlot.resolve(playerInventory.player).ifPresent(stack -> setBoundPlayer(server, playerId, stack)); + } + + private void setBoundPlayer(final MinecraftServer server, @Nullable final UUID playerId, final ItemStack stack) { + if (stack.getItem() instanceof SecurityCardItem securityCardItem) { + final ServerPlayer player = playerId == null ? null : server.getPlayerList().getPlayer(playerId); + securityCardItem.getModel(stack).setBoundPlayer(player); + } + } + + Permission changePermission(final ResourceLocation permissionId, final boolean selected) { + Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardPermission(permissionId, selected); + return updatePermissionLocally(permissionId, selected, true); + } + + Permission resetPermission(final ResourceLocation permissionId) { + final PlatformPermission permission = PlatformApi.INSTANCE.getPermissionRegistry() + .get(permissionId) + .orElseThrow(); + final boolean allowed = permission.isAllowedByDefault(); + Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardResetPermission(permissionId); + return updatePermissionLocally(permissionId, allowed, false); + } + + private Permission updatePermissionLocally(final ResourceLocation permissionId, + final boolean allowed, + final boolean dirty) { + final Permission localPermission = permissions.stream().filter(p -> p.id().equals(permissionId)) + .findFirst() + .orElseThrow(); + final int index = permissions.indexOf(localPermission); + final Permission updatedLocalPermission = new Permission( + localPermission.id(), + localPermission.name(), + localPermission.description(), + localPermission.ownerName(), + allowed, + dirty + ); + permissions.set(index, updatedLocalPermission); + return updatedLocalPermission; + } + + void changeBoundPlayer(@Nullable final Player player) { + Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardBoundPlayer( + player == null ? null : player.id() + ); + this.boundTo = player; + } + + record Permission(ResourceLocation id, + Component name, + Component description, + Component ownerName, + boolean allowed, + boolean dirty) { + } + + record Player(UUID id, String name) { } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java index b5a4a2cbb..393cfd486 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java @@ -6,6 +6,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ExtendedMenuProvider; +import java.util.Collections; import java.util.List; import javax.annotation.Nullable; @@ -19,19 +20,40 @@ class SecurityCardExtendedMenuProvider implements ExtendedMenuProvider { private final SlotReference slotReference; + private final SecurityCardModel model; - SecurityCardExtendedMenuProvider(final SlotReference slotReference) { + SecurityCardExtendedMenuProvider(final SlotReference slotReference, final SecurityCardModel model) { this.slotReference = slotReference; + this.model = model; } @Override public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { PlatformApi.INSTANCE.writeSlotReference(slotReference, buf); + final List permissions = PlatformApi.INSTANCE.getPermissionRegistry().getAll(); buf.writeInt(permissions.size()); for (final PlatformPermission permission : permissions) { final ResourceLocation id = PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).orElseThrow(); buf.writeResourceLocation(id); + buf.writeBoolean(model.isAllowed(permission)); + buf.writeBoolean(model.isDirty(permission)); + } + + final boolean bound = model.getBoundPlayerId() != null && model.getBoundPlayerName() != null; + buf.writeBoolean(bound); + if (bound) { + buf.writeUUID(model.getBoundPlayerId()); + buf.writeUtf(model.getBoundPlayerName()); + } + + final List players = player.getServer() == null + ? Collections.emptyList() + : player.getServer().getPlayerList().getPlayers(); + buf.writeInt(players.size()); + for (final ServerPlayer otherPlayer : players) { + buf.writeUUID(otherPlayer.getUUID()); + buf.writeUtf(otherPlayer.getGameProfile().getName()); } } @@ -43,6 +65,6 @@ public Component getDisplayName() { @Nullable @Override public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { - return new SecurityCardContainerMenu(syncId, inventory); + return new SecurityCardContainerMenu(syncId, inventory, slotReference); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java index 5dd31e8a2..bc819ad2b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java @@ -10,6 +10,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; @@ -26,47 +27,54 @@ public class SecurityCardItem extends Item { private static final Component UNBOUND_HELP = createTranslation("item", "security_card.unbound.help"); private static final Component BOUND_HELP = createTranslation("item", "security_card.bound.help"); - private static final String TAG_BOUND_TO = "boundto"; - private static final String TAG_BOUND_TO_NAME = "boundtoname"; - public SecurityCardItem() { super(new Item.Properties().stacksTo(1)); } + SecurityCardModel getModel(final ItemStack stack) { + return new SecurityCardModel(stack); + } + + boolean isActive(final ItemStack stack) { + return SecurityCardModel.isActive(stack); + } + @Override public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { final ItemStack stack = player.getItemInHand(hand); if (player instanceof ServerPlayer serverPlayer) { - if (serverPlayer.isCrouching()) { - bindOrUnbind(serverPlayer, stack); - } else { - Platform.INSTANCE.getMenuOpener().openMenu(serverPlayer, new SecurityCardExtendedMenuProvider( - PlatformApi.INSTANCE.createInventorySlotReference(player, hand) - )); - } + use(hand, serverPlayer, stack); } return InteractionResultHolder.consume(stack); } - private void bindOrUnbind(final ServerPlayer player, final ItemStack stack) { + private void use(final InteractionHand hand, final ServerPlayer player, final ItemStack stack) { + if (player.isCrouching()) { + bindOrClear(player, stack); + return; + } + Platform.INSTANCE.getMenuOpener().openMenu(player, new SecurityCardExtendedMenuProvider( + PlatformApi.INSTANCE.createInventorySlotReference(player, hand), + getModel(stack) + )); + } + + private void bindOrClear(final ServerPlayer player, final ItemStack stack) { if (stack.hasTag()) { - unbind(player, stack); + clear(player, stack); } else { bind(player, stack); } } - private void unbind(final ServerPlayer player, final ItemStack stack) { + private void clear(final ServerPlayer player, final ItemStack stack) { stack.setTag(null); - player.sendSystemMessage(createTranslation( - "item", - "security_card.unbound" - )); + player.sendSystemMessage(createTranslation("item", "security_card.cleared")); } private void bind(final ServerPlayer player, final ItemStack stack) { - stack.getOrCreateTag().putUUID(TAG_BOUND_TO, player.getGameProfile().getId()); - stack.getOrCreateTag().putString(TAG_BOUND_TO_NAME, player.getGameProfile().getName()); + final SecurityCardModel model = getModel(stack); + model.setBoundPlayer(player); player.sendSystemMessage(createTranslation( "item", "security_card.bound", @@ -80,25 +88,36 @@ public void appendHoverText(final ItemStack stack, final List lines, final TooltipFlag flag) { super.appendHoverText(stack, level, lines, flag); - if (stack.getTag() == null) { + final SecurityCardModel model = getModel(stack); + + final String boundPlayerName = model.getBoundPlayerName(); + if (boundPlayerName == null) { lines.add(createTranslation("item", "security_card.unbound").withStyle(ChatFormatting.GRAY)); return; } - final Component boundToName = Component.literal(stack.getTag().getString(TAG_BOUND_TO_NAME)) - .withStyle(ChatFormatting.YELLOW); + lines.add(createTranslation( "item", "security_card.bound", - boundToName + Component.literal(boundPlayerName).withStyle(ChatFormatting.YELLOW) ).withStyle(ChatFormatting.GRAY)); + + PlatformApi.INSTANCE.getPermissionRegistry().getAll().forEach(permission -> { + final boolean allowed = model.isAllowed(permission); + final boolean dirty = model.isDirty(permission); + final Style style = Style.EMPTY + .withColor(allowed ? ChatFormatting.GREEN : ChatFormatting.RED) + .withItalic(dirty); + final Component permissionTooltip = Component.literal(allowed ? "✓ " : "❌ ") + .append(permission.getName()) + .append(dirty ? " (*)" : "") + .withStyle(style); + lines.add(permissionTooltip); + }); } @Override public Optional getTooltipImage(final ItemStack stack) { return Optional.of(new HelpTooltipComponent(isActive(stack) ? BOUND_HELP : UNBOUND_HELP)); } - - boolean isActive(final ItemStack stack) { - return stack.getTag() != null && stack.getTag().contains(TAG_BOUND_TO); - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java new file mode 100644 index 000000000..5ef43ae9d --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java @@ -0,0 +1,89 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; + +import java.util.UUID; +import javax.annotation.Nullable; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; + +class SecurityCardModel { + private static final String TAG_BOUND_PLAYER_ID = "bid"; + private static final String TAG_BOUND_PLAYER_NAME = "bname"; + private static final String TAG_PERMISSIONS = "permissions"; + + private final ItemStack stack; + + SecurityCardModel(final ItemStack stack) { + this.stack = stack; + } + + boolean isAllowed(final PlatformPermission permission) { + if (stack.getTag() != null && stack.getTag().contains(TAG_PERMISSIONS)) { + final ResourceLocation permissionId = PlatformApi.INSTANCE.getPermissionRegistry() + .getId(permission) + .orElseThrow(); + final CompoundTag permissionsTag = stack.getTag().getCompound(TAG_PERMISSIONS); + final boolean dirty = permissionsTag.contains(permissionId.toString()); + if (dirty) { + return permissionsTag.getBoolean(permissionId.toString()); + } + } + return permission.isAllowedByDefault(); + } + + boolean isDirty(final PlatformPermission permission) { + final ResourceLocation permissionId = PlatformApi.INSTANCE.getPermissionRegistry() + .getId(permission) + .orElseThrow(); + return stack.getTag() != null + && stack.getTag().contains(TAG_PERMISSIONS) + && stack.getTag().getCompound(TAG_PERMISSIONS).contains(permissionId.toString()); + } + + void setPermission(final ResourceLocation permissionId, final boolean allowed) { + final CompoundTag permissionsTag = stack.getOrCreateTagElement(TAG_PERMISSIONS); + permissionsTag.putBoolean(permissionId.toString(), allowed); + } + + void resetPermission(final ResourceLocation permissionId) { + final CompoundTag permissionsTag = stack.getOrCreateTagElement(TAG_PERMISSIONS); + permissionsTag.remove(permissionId.toString()); + } + + @Nullable + UUID getBoundPlayerId() { + return (stack.getTag() == null || !stack.getTag().contains(TAG_BOUND_PLAYER_ID)) + ? null + : stack.getTag().getUUID(TAG_BOUND_PLAYER_ID); + } + + @Nullable + String getBoundPlayerName() { + return (stack.getTag() == null || !stack.getTag().contains(TAG_BOUND_PLAYER_NAME)) + ? null + : stack.getTag().getString(TAG_BOUND_PLAYER_NAME); + } + + void setBoundPlayer(@Nullable final ServerPlayer player) { + final CompoundTag tag = stack.getOrCreateTag(); + if (player == null) { + tag.remove(TAG_BOUND_PLAYER_ID); + tag.remove(TAG_BOUND_PLAYER_NAME); + return; + } + tag.putUUID(TAG_BOUND_PLAYER_ID, player.getGameProfile().getId()); + tag.putString(TAG_BOUND_PLAYER_NAME, player.getGameProfile().getName()); + } + + static boolean isActive(final ItemStack stack) { + return stack.getTag() != null + && stack.getTag().contains(TAG_BOUND_PLAYER_ID) + && stack.getTag().contains(TAG_BOUND_PLAYER_NAME) + && stack.getTag().contains(TAG_PERMISSIONS); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java index db6ab736d..7669855ca 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; +import javax.annotation.Nullable; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiGraphics; @@ -22,13 +23,19 @@ public class SecurityCardScreen extends AbstractStretchingScreen { private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/security_card.png"); - private static final int BINDING_RIGHT_PADDING = 6; - private static final int BINDING_WIDTH = 80; + private static final int BOUND_PLAYER_BUTTON_RIGHT_PADDING = 6; + private static final int BOUND_PLAYER_BUTTON_WIDTH = 80; private static final MutableComponent UNBOUND_TITLE = Component.literal("<") .append(createTranslation("gui", "security_card.unbound")) .append(">"); - private final List checkboxes = new ArrayList<>(); + private static final int RESET_BUTTON_WIDTH = 40; + private static final int RESET_BUTTON_RIGHT_PADDING = 16; + private static final Component RESET_TITLE = createTranslation("gui", "security_card.permission.reset"); + private static final Component MODIFIED_TITLE = createTranslation("gui", "security_card.permission.modified") + .withStyle(Style.EMPTY.withItalic(true).withColor(ChatFormatting.YELLOW)); + + private final List permissions = new ArrayList<>(); public SecurityCardScreen(final SecurityCardContainerMenu menu, final Inventory playerInventory, @@ -40,68 +47,148 @@ public SecurityCardScreen(final SecurityCardContainerMenu menu, } @Override - protected void init() { - super.init(); - - checkboxes.clear(); - final List permissions = getMenu().getPermissions(); - for (int i = 0; i < permissions.size(); ++i) { - final CustomCheckboxWidget checkbox = createPermissionCheckbox(permissions.get(i), i); - addWidget(checkbox); - checkboxes.add(checkbox); + protected void init(final int rows) { + permissions.clear(); + final List menuPermissions = getMenu().getPermissions(); + for (int i = 0; i < menuPermissions.size(); ++i) { + final Permission permission = createPermission(menuPermissions.get(i), i, rows); + addWidget(permission.checkbox); + addWidget(permission.resetButton); + permissions.add(permission); } - updateScrollbar(checkboxes.size()); - - final Button playerButton = Button.builder(UNBOUND_TITLE, btn -> toggleBoundPlayer()) - .pos(leftPos + imageWidth - BINDING_RIGHT_PADDING - BINDING_WIDTH, topPos + 4) - .size(BINDING_WIDTH, 14) + updateScrollbar(permissions.size()); + + final Component boundToText = menu.getBoundTo() == null + ? UNBOUND_TITLE + : Component.literal(menu.getBoundTo().name()); + final Button boundPlayerButton = Button.builder(boundToText, this::toggleBoundPlayer) + .pos(leftPos + imageWidth - BOUND_PLAYER_BUTTON_RIGHT_PADDING - BOUND_PLAYER_BUTTON_WIDTH, topPos + 4) + .size(BOUND_PLAYER_BUTTON_WIDTH, 14) .build(); - addRenderableWidget(playerButton); + addRenderableWidget(boundPlayerButton); } - private CustomCheckboxWidget createPermissionCheckbox( - final SecurityCardContainerMenu.Permission permission, - final int index + private Permission createPermission( + final SecurityCardContainerMenu.Permission menuPermission, + final int index, + final int rows ) { + final int y = getPermissionY(index); + final boolean visible = isPermissionVisible(rows, y); + final CustomCheckboxWidget checkbox = createPermissionCheckbox(menuPermission, y, visible); + final Button resetButton = createPermissionResetButton(menuPermission, checkbox, y, visible); + checkbox.setOnPressed((c, selected) -> updatePermission(menuPermission, resetButton, c, selected)); + return new Permission(checkbox, resetButton); + } + + private CustomCheckboxWidget createPermissionCheckbox(final SecurityCardContainerMenu.Permission menuPermission, + final int y, + final boolean visible) { final CustomCheckboxWidget checkbox = new CustomCheckboxWidget( leftPos + 10, - getPermissionCheckboxY(index), - permission.name(), + y, + getPermissionName(menuPermission), font, - false + menuPermission.allowed() ); - checkbox.setTooltip(getPermissionTooltip(permission)); + checkbox.visible = visible; + checkbox.setTooltip(getPermissionTooltip(menuPermission)); return checkbox; } - private Tooltip getPermissionTooltip(final SecurityCardContainerMenu.Permission permission) { - final MutableComponent ownerName = permission.ownerName().copy().withStyle( + private void updatePermission(final SecurityCardContainerMenu.Permission menuPermission, + final Button resetButton, + final CustomCheckboxWidget checkbox, + final boolean allowed) { + updateCheckboxAndResetButton(checkbox, resetButton, menu.changePermission(menuPermission.id(), allowed)); + } + + private Tooltip getPermissionTooltip(final SecurityCardContainerMenu.Permission menuPermission) { + final MutableComponent ownerName = menuPermission.ownerName().copy().withStyle( Style.EMPTY.withItalic(true).withColor(ChatFormatting.GRAY) ); - return Tooltip.create(permission.description().copy().append("\n").append(ownerName)); + final MutableComponent tooltip = menuPermission.description().copy().append("\n").append(ownerName); + return Tooltip.create(menuPermission.dirty() ? tooltip.append("\n").append(MODIFIED_TITLE) : tooltip); } - private int getPermissionCheckboxY(final int index) { + private Button createPermissionResetButton(final SecurityCardContainerMenu.Permission menuPermission, + final CustomCheckboxWidget checkbox, + final int y, + final boolean visible) { + final Button resetButton = Button.builder(RESET_TITLE, btn -> resetPermission(menuPermission, checkbox, btn)) + .pos(leftPos + imageWidth - RESET_BUTTON_RIGHT_PADDING - RESET_BUTTON_WIDTH - 11, y) + .size(RESET_BUTTON_WIDTH, 16) + .build(); + resetButton.visible = visible; + resetButton.active = menuPermission.dirty(); + return resetButton; + } + + private void resetPermission(final SecurityCardContainerMenu.Permission menuPermission, + final CustomCheckboxWidget checkbox, + final Button resetButton) { + updateCheckboxAndResetButton(checkbox, resetButton, menu.resetPermission(menuPermission.id())); + } + + private void updateCheckboxAndResetButton(final CustomCheckboxWidget checkbox, + final Button resetButton, + final SecurityCardContainerMenu.Permission menuPermission) { + checkbox.setMessage(getPermissionName(menuPermission)); + checkbox.setTooltip(getPermissionTooltip(menuPermission)); + checkbox.setSelected(menuPermission.allowed()); + resetButton.active = menuPermission.dirty(); + } + + private Component getPermissionName(final SecurityCardContainerMenu.Permission menuPermission) { + if (!menuPermission.dirty()) { + return menuPermission.name(); + } + return menuPermission.name().copy().append(" (*)").setStyle(Style.EMPTY.withItalic(true)); + } + + private int getPermissionY(final int index) { return topPos + 19 + (index * ROW_SIZE) + 3; } + private boolean isPermissionVisible(final int rows, final int y) { + return y >= (topPos + 19 - ROW_SIZE) && y < (topPos + 19 + (rows * ROW_SIZE)); + } + @Override protected int getScrollPanePadding() { return 4; } - private void toggleBoundPlayer() { - // todo! + private void toggleBoundPlayer(final Button button) { + if (menu.getPlayers().isEmpty()) { + return; + } + if (menu.getBoundTo() == null) { + setBoundPlayer(button, menu.getPlayers().get(0)); + return; + } + final int nextIndex = menu.getPlayers().indexOf(menu.getBoundTo()) + 1; + if (nextIndex >= menu.getPlayers().size()) { + setBoundPlayer(button, null); + } else { + setBoundPlayer(button, menu.getPlayers().get(nextIndex)); + } + } + + private void setBoundPlayer(final Button button, @Nullable final SecurityCardContainerMenu.Player player) { + menu.changeBoundPlayer(player); + button.setMessage(player == null ? UNBOUND_TITLE : Component.literal(player.name())); } @Override protected void scrollbarChanged(final int rows) { final int offset = getScrollbarOffset(); - for (int i = 0; i < checkboxes.size(); ++i) { - final CustomCheckboxWidget checkbox = checkboxes.get(i); - final int y = getPermissionCheckboxY(i) - offset; - checkbox.visible = y >= (topPos + 19 - ROW_SIZE) && y < (topPos + 19 + (rows * ROW_SIZE)); - checkbox.setY(y); + for (int i = 0; i < permissions.size(); ++i) { + final Permission permission = permissions.get(i); + final int y = getPermissionY(i) - offset; + final boolean visible = isPermissionVisible(rows, y); + permission.setY(y); + permission.setVisible(visible); } } @@ -113,8 +200,8 @@ protected void renderRows(final GuiGraphics graphics, final int rows, final int mouseX, final int mouseY) { - for (final CustomCheckboxWidget checkbox : checkboxes) { - checkbox.render(graphics, mouseX, mouseY, 0); + for (final Permission permission : permissions) { + permission.render(graphics, mouseX, mouseY); } } @@ -145,4 +232,21 @@ protected int getBottomV() { protected ResourceLocation getTexture() { return TEXTURE; } + + private record Permission(CustomCheckboxWidget checkbox, Button resetButton) { + private void setY(final int y) { + checkbox.setY(y); + resetButton.setY(y); + } + + private void setVisible(final boolean visible) { + checkbox.visible = visible; + resetButton.visible = visible; + } + + private void render(final GuiGraphics graphics, final int mouseX, final int mouseY) { + checkbox.render(graphics, mouseX, mouseY, 0); + resetButton.render(graphics, mouseX, mouseY, 0); + } + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java index 5aeca9c19..c1d47204b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/ClientToServerCommunications.java @@ -10,6 +10,9 @@ import java.util.List; import java.util.UUID; +import javax.annotation.Nullable; + +import net.minecraft.resources.ResourceLocation; public interface ClientToServerCommunications { void sendGridExtract(PlatformResourceKey resource, GridExtractMode mode, boolean cursor); @@ -35,4 +38,10 @@ public interface ClientToServerCommunications { void sendSingleAmountChange(double amount); void sendUseNetworkBoundItem(SlotReference slotReference); + + void sendSecurityCardPermission(ResourceLocation permissionId, boolean allowed); + + void sendSecurityCardResetPermission(ResourceLocation permissionId); + + void sendSecurityCardBoundPlayer(@Nullable UUID playerId); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/PacketIds.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/PacketIds.java index bf476c452..1d3eea67a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/PacketIds.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/packet/PacketIds.java @@ -26,6 +26,11 @@ public final class PacketIds { public static final ResourceLocation SINGLE_AMOUNT_CHANGE = createIdentifier("detector_amount_change"); public static final ResourceLocation USE_NETWORK_BOUND_ITEM = createIdentifier("use_network_bound_item"); public static final ResourceLocation NETWORK_TRANSMITTER_STATUS = createIdentifier("network_transmitter_status"); + public static final ResourceLocation SECURITY_CARD_PERMISSION = createIdentifier("security_card_permission"); + public static final ResourceLocation SECURITY_CARD_RESET_PERMISSION = createIdentifier( + "security_card_reset_permission" + ); + public static final ResourceLocation SECURITY_CARD_BOUND_PLAYER = createIdentifier("security_card_bound_player"); private PacketIds() { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java index eac896eea..8c73972d9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/stretching/AbstractStretchingScreen.java @@ -41,11 +41,17 @@ protected void init() { super.init(); - addSideButton(new ScreenSizeSideButtonWidget(this)); - this.scrollbar = new ScrollbarWidget(leftPos + 174, topPos + 20, 12, (visibleRows * ROW_SIZE) - 2); this.scrollbar.setListener(offset -> scrollbarChanged(visibleRows)); addWidget(scrollbar); + + init(visibleRows); + + addSideButton(new ScreenSizeSideButtonWidget(this)); + } + + protected void init(final int rows) { + // no op } protected final int getScrollbarOffset() { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java index 3912a253f..ed1032afb 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/CustomCheckboxWidget.java @@ -1,5 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.support.widget; +import javax.annotation.Nullable; + import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -25,6 +27,8 @@ public class CustomCheckboxWidget extends AbstractButton { private static final int BOX_SIZE = 9 + 8; + @Nullable + private OnPressed onPressed; private boolean selected; public CustomCheckboxWidget(final int x, @@ -36,18 +40,25 @@ public CustomCheckboxWidget(final int x, this.selected = selected; } + public void setOnPressed(@Nullable final OnPressed onPressed) { + this.onPressed = onPressed; + } + public void onPress() { this.selected = !this.selected; + if (onPressed != null) { + onPressed.onPressed(this, selected); + } } - public boolean selected() { - return this.selected; + public void setSelected(final boolean selected) { + this.selected = selected; } public void updateWidgetNarration(final NarrationElementOutput output) { - output.add(NarratedElementType.TITLE, this.createNarrationMessage()); - if (this.active) { - if (this.isFocused()) { + output.add(NarratedElementType.TITLE, createNarrationMessage()); + if (active) { + if (isFocused()) { output.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.focused")); } else { output.add(NarratedElementType.USAGE, Component.translatable("narration.checkbox.usage.hovered")); @@ -73,4 +84,9 @@ public void renderWidget(final GuiGraphics graphics, final int mouseX, final int graphics.setColor(1.0F, 1.0F, 1.0F, 1.0F); graphics.drawString(font, getMessage(), x, y, 4210752, false); } + + @FunctionalInterface + public interface OnPressed { + void onPressed(CustomCheckboxWidget checkbox, boolean selected); + } } 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 943ade269..a1a39448a 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 @@ -143,6 +143,8 @@ "gui.refinedstorage2.network_transmitter.status.transmitting": "%d block(s)", "gui.refinedstorage2.network_transmitter.status.receiver_unreachable": "Unreachable", "gui.refinedstorage2.security_card.unbound": "Unbound", + "gui.refinedstorage2.security_card.permission.reset": "Reset", + "gui.refinedstorage2.security_card.permission.modified": "Modified", "item.refinedstorage2.controller.help": "Provides the storage network with energy. Multiple are allowed in a single storage network.", "item.refinedstorage2.creative_controller.help": "Provides the storage network with an infinite source of energy.", "item.refinedstorage2.disk_drive.help": "Accepts storage disks to provide the storage network with storage space.", @@ -221,6 +223,7 @@ "item.refinedstorage2.network_card.bound_help": "Insert into a Network Transmitter. Use while crouching to clear binding.", "item.refinedstorage2.network_card.bound": "Bound to %d, %d, %d in %s.", "item.refinedstorage2.security_card": "Security Card", + "item.refinedstorage2.security_card.cleared": "Cleared binding.", "item.refinedstorage2.security_card.unbound": "Unbound.", "item.refinedstorage2.security_card.unbound.help": "Use while crouching to bind to the current player. Right click to configure.", "item.refinedstorage2.security_card.bound": "Bound to %s.", 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 31b8aec40..0676e4244 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 @@ -39,6 +39,9 @@ import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.ResourceFilterSlotChangePacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.ResourceSlotAmountChangePacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.ResourceSlotChangePacket; +import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.SecurityCardBoundPlayerPacket; +import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.SecurityCardPermissionPacket; +import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.SecurityCardResetPermissionPacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.SingleAmountChangePacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.StorageInfoRequestPacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.UseNetworkBoundItemPacket; @@ -314,6 +317,18 @@ private void registerPackets() { ); ServerPlayNetworking.registerGlobalReceiver(PacketIds.SINGLE_AMOUNT_CHANGE, new SingleAmountChangePacket()); ServerPlayNetworking.registerGlobalReceiver(PacketIds.USE_NETWORK_BOUND_ITEM, new UseNetworkBoundItemPacket()); + ServerPlayNetworking.registerGlobalReceiver( + PacketIds.SECURITY_CARD_PERMISSION, + new SecurityCardPermissionPacket() + ); + ServerPlayNetworking.registerGlobalReceiver( + PacketIds.SECURITY_CARD_RESET_PERMISSION, + new SecurityCardResetPermissionPacket() + ); + ServerPlayNetworking.registerGlobalReceiver( + PacketIds.SECURITY_CARD_BOUND_PLAYER, + new SecurityCardBoundPlayerPacket() + ); } private void registerSidedHandlers() { 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 064d16ddb..d61df1fc2 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 @@ -15,6 +15,7 @@ import java.util.List; import java.util.UUID; import java.util.function.Consumer; +import javax.annotation.Nullable; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; @@ -129,6 +130,32 @@ public void sendUseNetworkBoundItem(final SlotReference slotReference) { ); } + @Override + public void sendSecurityCardPermission(final ResourceLocation permissionId, final boolean allowed) { + sendToServer( + PacketIds.SECURITY_CARD_PERMISSION, + buf -> { + buf.writeResourceLocation(permissionId); + buf.writeBoolean(allowed); + } + ); + } + + @Override + public void sendSecurityCardResetPermission(final ResourceLocation permissionId) { + sendToServer(PacketIds.SECURITY_CARD_RESET_PERMISSION, buf -> buf.writeResourceLocation(permissionId)); + } + + @Override + public void sendSecurityCardBoundPlayer(@Nullable final UUID playerId) { + sendToServer(PacketIds.SECURITY_CARD_BOUND_PLAYER, buf -> { + buf.writeBoolean(playerId != null); + if (playerId != null) { + buf.writeUUID(playerId); + } + }); + } + private static void sendToServer(final ResourceLocation id, final Consumer bufConsumer) { final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); bufConsumer.accept(buf); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardBoundPlayerPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardBoundPlayerPacket.java new file mode 100644 index 000000000..ccca1783c --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardBoundPlayerPacket.java @@ -0,0 +1,27 @@ +package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; + +import java.util.UUID; + +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; + +public class SecurityCardBoundPlayerPacket implements ServerPlayNetworking.PlayChannelHandler { + @Override + public void receive(final MinecraftServer server, + final ServerPlayer player, + final ServerGamePacketListenerImpl handler, + final FriendlyByteBuf buf, + final PacketSender responseSender) { + final boolean hasPlayer = buf.readBoolean(); + final UUID playerId = hasPlayer ? buf.readUUID() : null; + if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + server.execute(() -> securityCardContainerMenu.setBoundPlayer(server, playerId)); + } + } +} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java new file mode 100644 index 000000000..9c392195b --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java @@ -0,0 +1,26 @@ +package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; + +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; + +public class SecurityCardPermissionPacket implements ServerPlayNetworking.PlayChannelHandler { + @Override + public void receive(final MinecraftServer server, + final ServerPlayer player, + final ServerGamePacketListenerImpl handler, + final FriendlyByteBuf buf, + final PacketSender responseSender) { + final ResourceLocation permissionId = buf.readResourceLocation(); + final boolean allowed = buf.readBoolean(); + if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + server.execute(() -> securityCardContainerMenu.setPermission(permissionId, allowed)); + } + } +} diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java new file mode 100644 index 000000000..16e54f230 --- /dev/null +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java @@ -0,0 +1,25 @@ +package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; + +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; + +public class SecurityCardResetPermissionPacket implements ServerPlayNetworking.PlayChannelHandler { + @Override + public void receive(final MinecraftServer server, + final ServerPlayer player, + final ServerGamePacketListenerImpl handler, + final FriendlyByteBuf buf, + final PacketSender responseSender) { + final ResourceLocation permissionId = buf.readResourceLocation(); + if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + server.execute(() -> securityCardContainerMenu.resetPermissionServer(permissionId)); + } + } +} 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 01885de40..647cf114e 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 @@ -46,6 +46,9 @@ import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.ResourceFilterSlotChangePacket; import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.ResourceSlotAmountChangePacket; import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.ResourceSlotChangePacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.SecurityCardBoundPlayerPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.SecurityCardPermissionPacket; +import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.SecurityCardResetPermissionPacket; import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.SingleAmountChangePacket; import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.StorageInfoRequestPacket; import com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s.UseNetworkBoundItemPacket; @@ -504,6 +507,21 @@ private static void registerClientToServerPackets(final IPayloadRegistrar regist UseNetworkBoundItemPacket::decode, handler -> handler.server(UseNetworkBoundItemPacket::handle) ); + registrar.play( + PacketIds.SECURITY_CARD_PERMISSION, + SecurityCardPermissionPacket::decode, + handler -> handler.server(SecurityCardPermissionPacket::handle) + ); + registrar.play( + PacketIds.SECURITY_CARD_RESET_PERMISSION, + SecurityCardResetPermissionPacket::decode, + handler -> handler.server(SecurityCardResetPermissionPacket::handle) + ); + registrar.play( + PacketIds.SECURITY_CARD_BOUND_PLAYER, + SecurityCardBoundPlayerPacket::decode, + handler -> handler.server(SecurityCardBoundPlayerPacket::handle) + ); } @SubscribeEvent diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java index 7554e91d4..3380b0937 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/ClientToServerCommunicationsImpl.java @@ -13,8 +13,10 @@ import java.util.List; import java.util.UUID; +import javax.annotation.Nullable; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.network.PacketDistributor; public class ClientToServerCommunicationsImpl implements ClientToServerCommunications { @@ -110,4 +112,19 @@ public void sendSingleAmountChange(final double amount) { public void sendUseNetworkBoundItem(final SlotReference slotReference) { sendPacket(new UseNetworkBoundItemPacket(slotReference)); } + + @Override + public void sendSecurityCardPermission(final ResourceLocation permissionId, final boolean allowed) { + sendPacket(new SecurityCardPermissionPacket(permissionId, allowed)); + } + + @Override + public void sendSecurityCardResetPermission(final ResourceLocation permissionId) { + sendPacket(new SecurityCardResetPermissionPacket(permissionId)); + } + + @Override + public void sendSecurityCardBoundPlayer(@Nullable final UUID playerId) { + sendPacket(new SecurityCardBoundPlayerPacket(playerId)); + } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardBoundPlayerPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardBoundPlayerPacket.java new file mode 100644 index 000000000..465576003 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardBoundPlayerPacket.java @@ -0,0 +1,42 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import java.util.UUID; +import javax.annotation.Nullable; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record SecurityCardBoundPlayerPacket(@Nullable UUID playerId) implements CustomPacketPayload { + public static SecurityCardBoundPlayerPacket decode(final FriendlyByteBuf buf) { + return new SecurityCardBoundPlayerPacket(buf.readBoolean() ? buf.readUUID() : null); + } + + public static void handle(final SecurityCardBoundPlayerPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.getServer() == null) { + return; + } + if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + securityCardContainerMenu.setBoundPlayer(player.getServer(), packet.playerId); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeBoolean(playerId != null); + if (playerId != null) { + buf.writeUUID(playerId); + } + } + + @Override + public ResourceLocation id() { + return PacketIds.SECURITY_CARD_BOUND_PLAYER; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java new file mode 100644 index 000000000..c1807187c --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java @@ -0,0 +1,35 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record SecurityCardPermissionPacket(ResourceLocation permissionId, boolean allowed) + implements CustomPacketPayload { + public static SecurityCardPermissionPacket decode(final FriendlyByteBuf buf) { + return new SecurityCardPermissionPacket(buf.readResourceLocation(), buf.readBoolean()); + } + + public static void handle(final SecurityCardPermissionPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + securityCardContainerMenu.setPermission(packet.permissionId, packet.allowed); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeResourceLocation(permissionId); + buf.writeBoolean(allowed); + } + + @Override + public ResourceLocation id() { + return PacketIds.SECURITY_CARD_PERMISSION; + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java new file mode 100644 index 000000000..f517c608d --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java @@ -0,0 +1,33 @@ +package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.network.handling.PlayPayloadContext; + +public record SecurityCardResetPermissionPacket(ResourceLocation permissionId) implements CustomPacketPayload { + public static SecurityCardResetPermissionPacket decode(final FriendlyByteBuf buf) { + return new SecurityCardResetPermissionPacket(buf.readResourceLocation()); + } + + public static void handle(final SecurityCardResetPermissionPacket packet, final PlayPayloadContext ctx) { + ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { + if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + securityCardContainerMenu.resetPermissionServer(packet.permissionId); + } + })); + } + + @Override + public void write(final FriendlyByteBuf buf) { + buf.writeResourceLocation(permissionId); + } + + @Override + public ResourceLocation id() { + return PacketIds.SECURITY_CARD_RESET_PERMISSION; + } +} From c071fd661ad9db0cf8f9c9a54ce639bc7509e8ac Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 31 Mar 2024 20:00:13 +0200 Subject: [PATCH 7/7] feat: fallback security card --- CHANGELOG.md | 2 + .../common/AbstractClientModInitializer.java | 2 + .../common/AbstractModInitializer.java | 14 +- .../platform/common/content/ContentIds.java | 1 + .../platform/common/content/ContentNames.java | 1 + .../common/content/CreativeModeTabItems.java | 1 + .../platform/common/content/Items.java | 11 + .../platform/common/content/Menus.java | 13 ++ .../AbstractSecurityCardContainerMenu.java | 135 +++++++++++ ...tractSecurityCardExtendedMenuProvider.java | 36 +++ .../security/AbstractSecurityCardItem.java | 92 ++++++++ .../security/AbstractSecurityCardScreen.java | 216 ++++++++++++++++++ .../FallbackSecurityCardContainerMenu.java | 21 ++ ...lbackSecurityCardExtendedMenuProvider.java | 31 +++ .../security/FallbackSecurityCardItem.java | 37 +++ .../security/FallbackSecurityCardScreen.java | 12 + .../security/PlayerSecurityCardModel.java | 53 +++++ .../security/SecurityCardContainerMenu.java | 115 +--------- .../SecurityCardExtendedMenuProvider.java | 30 +-- .../common/security/SecurityCardItem.java | 97 +++----- .../common/security/SecurityCardModel.java | 40 +--- .../common/security/SecurityCardScreen.java | 198 +--------------- .../assets/refinedstorage2/lang/en_us.json | 6 +- .../models/item/fallback_security_card.json | 6 + .../textures/item/security_card/fallback.png | Bin 0 -> 570 bytes .../recipes/fallback_security_card.json | 14 ++ .../platform/fabric/ModInitializerImpl.java | 10 + .../c2s/SecurityCardPermissionPacket.java | 4 +- .../SecurityCardResetPermissionPacket.java | 4 +- .../platform/forge/ModInitializer.java | 9 + .../c2s/SecurityCardPermissionPacket.java | 4 +- .../SecurityCardResetPermissionPacket.java | 4 +- 32 files changed, 778 insertions(+), 441 deletions(-) create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardExtendedMenuProvider.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardContainerMenu.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardExtendedMenuProvider.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardScreen.java create mode 100644 refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java create mode 100755 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/fallback_security_card.json create mode 100644 refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/security_card/fallback.png create mode 100644 refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fallback_security_card.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 82119cd5e..9f90e9936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added - Security Card +- Fallback Security Card ### Changed @@ -17,6 +18,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - The Security Card can be bound to other (currently online) players via its GUI. - The binding of a Security Card can now be cleared. - The Security Card tooltip and GUI now show whether the permission has been touched/changed in any way. +- A global (fallback) permission set for a network can be defined using the Fallback Security Card instead of using an "unbound" Security Card. ### Fixed 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 ba8ba4096..8c24202b4 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 @@ -17,6 +17,7 @@ import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceScreen; import com.refinedmods.refinedstorage2.platform.common.importer.ImporterScreen; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterScreen; +import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardScreen; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardScreen; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; @@ -69,6 +70,7 @@ protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getPortableGridBlock(), PortableGridScreen::new); registration.register(Menus.INSTANCE.getPortableGridItem(), PortableGridScreen::new); registration.register(Menus.INSTANCE.getSecurityCard(), SecurityCardScreen::new); + registration.register(Menus.INSTANCE.getFallbackSecurityCard(), FallbackSecurityCardScreen::new); } protected static void registerAlternativeGridHints() { 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 6659b7e90..e1d95c1a6 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 @@ -56,6 +56,8 @@ import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.BuiltinPermission; +import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; @@ -141,6 +143,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DISK_DRIVE; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.EXPORTER; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.EXTERNAL_STORAGE; +import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.FALLBACK_SECURITY_CARD; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.FLUID_STORAGE_BLOCK; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.GRID; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.IMPORTER; @@ -320,7 +323,8 @@ protected final void registerItems( final Supplier creativeWirelessGridItemSupplier, final Supplier portableGridBlockItemSupplier, final Supplier creativePortableGridBlockItemSupplier, - final Supplier securityCardItemSupplier + final Supplier securityCardItemSupplier, + final Supplier fallbackSecurityCardItemSupplier ) { registerSimpleItems(callback); Blocks.INSTANCE.getGrid().registerItems(callback); @@ -351,6 +355,10 @@ protected final void registerItems( creativePortableGridBlockItemSupplier )); Items.INSTANCE.setSecurityCard(callback.register(SECURITY_CARD, securityCardItemSupplier)); + Items.INSTANCE.setFallbackSecurityCard(callback.register( + FALLBACK_SECURITY_CARD, + fallbackSecurityCardItemSupplier + )); } private void registerSimpleItems(final RegistryCallback callback) { @@ -731,6 +739,10 @@ protected final void registerMenus(final RegistryCallback> callback, SECURITY_CARD, () -> menuTypeFactory.create(SecurityCardContainerMenu::new) )); + Menus.INSTANCE.setFallbackSecurityCard(callback.register( + FALLBACK_SECURITY_CARD, + () -> menuTypeFactory.create(FallbackSecurityCardContainerMenu::new) + )); } protected final void registerLootFunctions(final RegistryCallback callback) { 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 b902d1f91..0955232ba 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 @@ -55,6 +55,7 @@ public final class ContentIds { public static final ResourceLocation PORTABLE_GRID = createIdentifier("portable_grid"); public static final ResourceLocation CREATIVE_PORTABLE_GRID = createIdentifier("creative_portable_grid"); public static final ResourceLocation SECURITY_CARD = createIdentifier("security_card"); + public static final ResourceLocation FALLBACK_SECURITY_CARD = createIdentifier("fallback_security_card"); 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 bfb5cd6f8..06afd3e37 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 @@ -27,6 +27,7 @@ public final class ContentNames { public static final MutableComponent NETWORK_TRANSMITTER = name("network_transmitter"); public static final MutableComponent PORTABLE_GRID = name("portable_grid"); public static final MutableComponent SECURITY_CARD = createTranslation("item", "security_card"); + public static final MutableComponent FALLBACK_SECURITY_CARD = createTranslation("item", "fallback_security_card"); 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 f1c73e3f3..c5bb5336a 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 @@ -104,5 +104,6 @@ private static void appendItems(final Consumer consumer) { itemConsumer.accept(Items.INSTANCE.getConfigurationCard()); itemConsumer.accept(Items.INSTANCE.getNetworkCard()); itemConsumer.accept(Items.INSTANCE.getSecurityCard()); + itemConsumer.accept(Items.INSTANCE.getFallbackSecurityCard()); } } 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 c961a74cc..bd99e3a14 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 @@ -5,6 +5,7 @@ import com.refinedmods.refinedstorage2.platform.common.controller.CreativeControllerBlockItem; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.misc.ProcessorItem; +import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; @@ -95,6 +96,8 @@ public final class Items { private Supplier creativePortableGrid; @Nullable private Supplier securityCard; + @Nullable + private Supplier fallbackSecurityCard; private Items() { } @@ -426,4 +429,12 @@ public SecurityCardItem getSecurityCard() { public void setSecurityCard(final Supplier securityCard) { this.securityCard = securityCard; } + + public FallbackSecurityCardItem getFallbackSecurityCard() { + return requireNonNull(fallbackSecurityCard).get(); + } + + public void setFallbackSecurityCard(final Supplier fallbackSecurityCard) { + this.fallbackSecurityCard = fallbackSecurityCard; + } } 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 78ab613f8..45433d8f0 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 @@ -11,6 +11,7 @@ import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.importer.ImporterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveContainerMenu; import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageContainerMenu; @@ -74,6 +75,8 @@ public final class Menus { private Supplier> portableGridItem; @Nullable private Supplier> securityCard; + @Nullable + private Supplier> fallbackSecurityCard; private Menus() { } @@ -245,4 +248,14 @@ public MenuType getSecurityCard() { public void setSecurityCard(final Supplier> securityCard) { this.securityCard = securityCard; } + + public MenuType getFallbackSecurityCard() { + return requireNonNull(fallbackSecurityCard).get(); + } + + public void setFallbackSecurityCard( + final Supplier> fallbackSecurityCard + ) { + this.fallbackSecurityCard = fallbackSecurityCard; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java new file mode 100644 index 000000000..272153b45 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardContainerMenu.java @@ -0,0 +1,135 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSizeListener; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; + +public abstract class AbstractSecurityCardContainerMenu extends AbstractBaseContainerMenu + implements ScreenSizeListener { + protected final Inventory playerInventory; + private final List permissions = new ArrayList<>(); + + protected AbstractSecurityCardContainerMenu(final MenuType menuType, + final int syncId, + final Inventory playerInventory, + final FriendlyByteBuf buf) { + super(menuType, syncId); + this.playerInventory = playerInventory; + this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); + final int amountOfPermissions = buf.readInt(); + for (int i = 0; i < amountOfPermissions; ++i) { + final ResourceLocation id = buf.readResourceLocation(); + final boolean allowed = buf.readBoolean(); + final boolean dirty = buf.readBoolean(); + PlatformApi.INSTANCE.getPermissionRegistry().get(id).ifPresent(permission -> permissions.add(new Permission( + id, + permission.getName(), + permission.getDescription(), + permission.getOwnerName(), + allowed, + dirty + ))); + } + } + + protected AbstractSecurityCardContainerMenu(final MenuType menuType, + final int syncId, + final Inventory playerInventory, + final SlotReference disabledSlot) { + super(menuType, syncId); + this.playerInventory = playerInventory; + this.disabledSlot = disabledSlot; + } + + List getPermissions() { + return permissions; + } + + @Override + public void initSlots(final int playerInventoryY) { + resetSlots(); + addPlayerInventory(playerInventory, 8, playerInventoryY); + } + + public void setPermission(final ResourceLocation permissionId, final boolean allowed) { + if (disabledSlot == null) { + return; + } + disabledSlot.resolve(playerInventory.player).ifPresent(stack -> setPermission(permissionId, allowed, stack)); + } + + private void setPermission(final ResourceLocation permissionId, final boolean allowed, final ItemStack stack) { + if (stack.getItem() instanceof AbstractSecurityCardItem securityCardItem) { + final SecurityCardModel model = securityCardItem.createModel(stack); + model.setPermission(permissionId, allowed); + } + } + + public void resetPermissionServer(final ResourceLocation permissionId) { + if (disabledSlot == null) { + return; + } + disabledSlot.resolve(playerInventory.player).ifPresent(stack -> resetPermissionServer(permissionId, stack)); + } + + private void resetPermissionServer(final ResourceLocation permissionId, final ItemStack stack) { + if (stack.getItem() instanceof AbstractSecurityCardItem securityCardItem) { + final SecurityCardModel model = securityCardItem.createModel(stack); + model.resetPermission(permissionId); + } + } + + Permission changePermission(final ResourceLocation permissionId, final boolean selected) { + Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardPermission(permissionId, selected); + return updatePermissionLocally(permissionId, selected, true); + } + + Permission resetPermission(final ResourceLocation permissionId) { + final PlatformPermission permission = PlatformApi.INSTANCE.getPermissionRegistry() + .get(permissionId) + .orElseThrow(); + final boolean allowed = permission.isAllowedByDefault(); + Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardResetPermission(permissionId); + return updatePermissionLocally(permissionId, allowed, false); + } + + private Permission updatePermissionLocally(final ResourceLocation permissionId, + final boolean allowed, + final boolean dirty) { + final Permission localPermission = permissions.stream().filter(p -> p.id().equals(permissionId)) + .findFirst() + .orElseThrow(); + final int index = permissions.indexOf(localPermission); + final Permission updatedLocalPermission = new Permission( + localPermission.id(), + localPermission.name(), + localPermission.description(), + localPermission.ownerName(), + allowed, + dirty + ); + permissions.set(index, updatedLocalPermission); + return updatedLocalPermission; + } + + record Permission(ResourceLocation id, + Component name, + Component description, + Component ownerName, + boolean allowed, + boolean dirty) { + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardExtendedMenuProvider.java new file mode 100644 index 000000000..6b0540a82 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardExtendedMenuProvider.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ExtendedMenuProvider; + +import java.util.List; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; + +abstract class AbstractSecurityCardExtendedMenuProvider implements ExtendedMenuProvider { + private final SlotReference slotReference; + private final SecurityCardModel model; + + AbstractSecurityCardExtendedMenuProvider(final SlotReference slotReference, final SecurityCardModel model) { + this.slotReference = slotReference; + this.model = model; + } + + @Override + public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { + PlatformApi.INSTANCE.writeSlotReference(slotReference, buf); + + final List permissions = PlatformApi.INSTANCE.getPermissionRegistry().getAll(); + buf.writeInt(permissions.size()); + for (final PlatformPermission permission : permissions) { + final ResourceLocation id = PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).orElseThrow(); + buf.writeResourceLocation(id); + buf.writeBoolean(model.isAllowed(permission)); + buf.writeBoolean(model.isDirty(permission)); + } + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java new file mode 100644 index 000000000..4a5f0b17f --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardItem.java @@ -0,0 +1,92 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.Platform; + +import java.util.List; +import javax.annotation.Nullable; + +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +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.item.TooltipFlag; +import net.minecraft.world.level.Level; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +abstract class AbstractSecurityCardItem extends Item { + protected AbstractSecurityCardItem(final Properties properties) { + super(properties); + } + + @Override + public void appendHoverText(final ItemStack stack, + @Nullable final Level level, + final List lines, + final TooltipFlag flag) { + super.appendHoverText(stack, level, lines, flag); + final M model = createModel(stack); + if (addTooltip(stack, lines, model)) { + addPermissions(lines, model); + } + } + + protected boolean addTooltip(final ItemStack stack, final List lines, final M model) { + return true; + } + + private void addPermissions(final List lines, final SecurityCardModel model) { + PlatformApi.INSTANCE.getPermissionRegistry().getAll().forEach(permission -> { + final boolean allowed = model.isAllowed(permission); + final boolean dirty = model.isDirty(permission); + final Style style = Style.EMPTY + .withColor(allowed ? ChatFormatting.GREEN : ChatFormatting.RED) + .withItalic(dirty); + final Component permissionTooltip = Component.literal(allowed ? "✓ " : "❌ ") + .append(permission.getName()) + .append(dirty ? " (*)" : "") + .withStyle(style); + lines.add(permissionTooltip); + }); + } + + @Override + public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { + final ItemStack stack = player.getItemInHand(hand); + if (player instanceof ServerPlayer serverPlayer) { + final M model = createModel(stack); + use(hand, serverPlayer, stack, model); + } + return InteractionResultHolder.consume(stack); + } + + private void use(final InteractionHand hand, final ServerPlayer player, final ItemStack stack, final M model) { + if (player.isCrouching()) { + tryClear(player, model); + return; + } + Platform.INSTANCE.getMenuOpener().openMenu(player, createMenuProvider( + PlatformApi.INSTANCE.createInventorySlotReference(player, hand), + model + )); + } + + void tryClear(final ServerPlayer player, final M model) { + model.clear(); + player.sendSystemMessage(createTranslation("item", "security_card.cleared")); + } + + abstract M createModel(ItemStack stack); + + abstract AbstractSecurityCardExtendedMenuProvider createMenuProvider( + SlotReference slotReference, + M model + ); +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java new file mode 100644 index 000000000..cdc1d2760 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/AbstractSecurityCardScreen.java @@ -0,0 +1,216 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.common.support.stretching.AbstractStretchingScreen; +import com.refinedmods.refinedstorage2.platform.common.support.widget.CustomCheckboxWidget; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.resources.ResourceLocation; +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.createTranslation; + +public abstract class AbstractSecurityCardScreen + extends AbstractStretchingScreen { + private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/security_card.png"); + + private static final int RESET_BUTTON_WIDTH = 40; + private static final int RESET_BUTTON_RIGHT_PADDING = 16; + private static final Component RESET_TITLE = createTranslation("gui", "security_card.permission.reset"); + private static final Component MODIFIED_TITLE = createTranslation("gui", "security_card.permission.modified") + .withStyle(Style.EMPTY.withItalic(true).withColor(ChatFormatting.YELLOW)); + + private final List permissions = new ArrayList<>(); + + public AbstractSecurityCardScreen(final T menu, final Inventory playerInventory, final Component text) { + super(menu, playerInventory, text); + this.inventoryLabelY = 97; + this.imageWidth = 193; + this.imageHeight = 176; + } + + @Override + protected void init(final int rows) { + permissions.clear(); + final List menuPermissions = getMenu().getPermissions(); + for (int i = 0; i < menuPermissions.size(); ++i) { + final Permission permission = createPermission(menuPermissions.get(i), i, rows); + addWidget(permission.checkbox); + addWidget(permission.resetButton); + permissions.add(permission); + } + updateScrollbar(permissions.size()); + } + + private Permission createPermission( + final AbstractSecurityCardContainerMenu.Permission menuPermission, + final int index, + final int rows + ) { + final int y = getPermissionY(index); + final boolean visible = isPermissionVisible(rows, y); + final CustomCheckboxWidget checkbox = createPermissionCheckbox(menuPermission, y, visible); + final Button resetButton = createPermissionResetButton(menuPermission, checkbox, y, visible); + checkbox.setOnPressed((c, selected) -> updatePermission(menuPermission, resetButton, c, selected)); + return new Permission(checkbox, resetButton); + } + + private CustomCheckboxWidget createPermissionCheckbox( + final AbstractSecurityCardContainerMenu.Permission menuPermission, + final int y, + final boolean visible + ) { + final CustomCheckboxWidget checkbox = new CustomCheckboxWidget( + leftPos + 10, + y, + getPermissionName(menuPermission), + font, + menuPermission.allowed() + ); + checkbox.visible = visible; + checkbox.setTooltip(getPermissionTooltip(menuPermission)); + return checkbox; + } + + private void updatePermission(final AbstractSecurityCardContainerMenu.Permission menuPermission, + final Button resetButton, + final CustomCheckboxWidget checkbox, + final boolean allowed) { + updateCheckboxAndResetButton(checkbox, resetButton, menu.changePermission(menuPermission.id(), allowed)); + } + + private Tooltip getPermissionTooltip(final AbstractSecurityCardContainerMenu.Permission menuPermission) { + final MutableComponent ownerName = menuPermission.ownerName().copy().withStyle( + Style.EMPTY.withItalic(true).withColor(ChatFormatting.GRAY) + ); + final MutableComponent tooltip = menuPermission.description().copy().append("\n").append(ownerName); + return Tooltip.create(menuPermission.dirty() ? tooltip.append("\n").append(MODIFIED_TITLE) : tooltip); + } + + private Button createPermissionResetButton(final AbstractSecurityCardContainerMenu.Permission menuPermission, + final CustomCheckboxWidget checkbox, + final int y, + final boolean visible) { + final Button resetButton = Button.builder(RESET_TITLE, btn -> resetPermission(menuPermission, checkbox, btn)) + .pos(leftPos + imageWidth - RESET_BUTTON_RIGHT_PADDING - RESET_BUTTON_WIDTH - 11, y) + .size(RESET_BUTTON_WIDTH, 16) + .build(); + resetButton.visible = visible; + resetButton.active = menuPermission.dirty(); + return resetButton; + } + + private void resetPermission(final AbstractSecurityCardContainerMenu.Permission menuPermission, + final CustomCheckboxWidget checkbox, + final Button resetButton) { + updateCheckboxAndResetButton(checkbox, resetButton, menu.resetPermission(menuPermission.id())); + } + + private void updateCheckboxAndResetButton(final CustomCheckboxWidget checkbox, + final Button resetButton, + final AbstractSecurityCardContainerMenu.Permission menuPermission) { + checkbox.setMessage(getPermissionName(menuPermission)); + checkbox.setTooltip(getPermissionTooltip(menuPermission)); + checkbox.setSelected(menuPermission.allowed()); + resetButton.active = menuPermission.dirty(); + } + + private Component getPermissionName(final AbstractSecurityCardContainerMenu.Permission menuPermission) { + if (!menuPermission.dirty()) { + return menuPermission.name(); + } + return menuPermission.name().copy().append(" (*)").setStyle(Style.EMPTY.withItalic(true)); + } + + private int getPermissionY(final int index) { + return topPos + 19 + (index * ROW_SIZE) + 3; + } + + private boolean isPermissionVisible(final int rows, final int y) { + return y >= (topPos + 19 - ROW_SIZE) && y < (topPos + 19 + (rows * ROW_SIZE)); + } + + @Override + protected int getScrollPanePadding() { + return 4; + } + + @Override + protected void scrollbarChanged(final int rows) { + final int offset = getScrollbarOffset(); + for (int i = 0; i < permissions.size(); ++i) { + final Permission permission = permissions.get(i); + final int y = getPermissionY(i) - offset; + final boolean visible = isPermissionVisible(rows, y); + permission.setY(y); + permission.setVisible(visible); + } + } + + @Override + protected void renderRows(final GuiGraphics graphics, + final int x, + final int y, + final int topHeight, + final int rows, + final int mouseX, + final int mouseY) { + for (final Permission permission : permissions) { + permission.render(graphics, mouseX, mouseY); + } + } + + @Override + protected void renderStretchingBackground(final GuiGraphics graphics, final int x, final int y, final int rows) { + for (int row = 0; row < rows; ++row) { + int textureY = 37; + if (row == 0) { + textureY = 19; + } else if (row == rows - 1) { + textureY = 55; + } + graphics.blit(getTexture(), x, y + (ROW_SIZE * row), 0, textureY, imageWidth, ROW_SIZE); + } + } + + @Override + protected int getBottomHeight() { + return 99; + } + + @Override + protected int getBottomV() { + return 73; + } + + @Override + protected ResourceLocation getTexture() { + return TEXTURE; + } + + private record Permission(CustomCheckboxWidget checkbox, Button resetButton) { + private void setY(final int y) { + checkbox.setY(y); + resetButton.setY(y); + } + + private void setVisible(final boolean visible) { + checkbox.visible = visible; + resetButton.visible = visible; + } + + private void render(final GuiGraphics graphics, final int mouseX, final int mouseY) { + checkbox.render(graphics, mouseX, mouseY, 0); + resetButton.render(graphics, mouseX, mouseY, 0); + } + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardContainerMenu.java new file mode 100644 index 000000000..67eb37da1 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardContainerMenu.java @@ -0,0 +1,21 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.content.Menus; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; + +public class FallbackSecurityCardContainerMenu extends AbstractSecurityCardContainerMenu { + public FallbackSecurityCardContainerMenu(final int syncId, + final Inventory playerInventory, + final FriendlyByteBuf buf) { + super(Menus.INSTANCE.getFallbackSecurityCard(), syncId, playerInventory, buf); + } + + FallbackSecurityCardContainerMenu(final int syncId, + final Inventory playerInventory, + final SlotReference disabledSlot) { + super(Menus.INSTANCE.getFallbackSecurityCard(), syncId, playerInventory, disabledSlot); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardExtendedMenuProvider.java new file mode 100644 index 000000000..f631beb08 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardExtendedMenuProvider.java @@ -0,0 +1,31 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; + +import javax.annotation.Nullable; + +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; + +class FallbackSecurityCardExtendedMenuProvider extends AbstractSecurityCardExtendedMenuProvider { + private final SlotReference slotReference; + + FallbackSecurityCardExtendedMenuProvider(final SlotReference slotReference, final SecurityCardModel model) { + super(slotReference, model); + this.slotReference = slotReference; + } + + @Override + public Component getDisplayName() { + return ContentNames.FALLBACK_SECURITY_CARD; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return new FallbackSecurityCardContainerMenu(syncId, inventory, slotReference); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java new file mode 100644 index 000000000..0fa8b8460 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardItem.java @@ -0,0 +1,37 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent; +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; + +import java.util.Optional; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.inventory.tooltip.TooltipComponent; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +public class FallbackSecurityCardItem extends AbstractSecurityCardItem { + private static final Component HELP = createTranslation("item", "fallback_security_card.help"); + + public FallbackSecurityCardItem() { + super(new Item.Properties().stacksTo(1)); + } + + @Override + SecurityCardModel createModel(final ItemStack stack) { + return new SecurityCardModel(stack); + } + + @Override + AbstractSecurityCardExtendedMenuProvider createMenuProvider(final SlotReference slotReference, + final SecurityCardModel model) { + return new FallbackSecurityCardExtendedMenuProvider(slotReference, model); + } + + @Override + public Optional getTooltipImage(final ItemStack stack) { + return Optional.of(new HelpTooltipComponent(HELP)); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardScreen.java new file mode 100644 index 000000000..3ea220f41 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/FallbackSecurityCardScreen.java @@ -0,0 +1,12 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; + +public class FallbackSecurityCardScreen extends AbstractSecurityCardScreen { + public FallbackSecurityCardScreen(final FallbackSecurityCardContainerMenu menu, + final Inventory playerInventory, + final Component text) { + super(menu, playerInventory, text); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java new file mode 100644 index 000000000..ffc0c8279 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/PlayerSecurityCardModel.java @@ -0,0 +1,53 @@ +package com.refinedmods.refinedstorage2.platform.common.security; + +import java.util.UUID; +import javax.annotation.Nullable; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; + +class PlayerSecurityCardModel extends SecurityCardModel { + private static final String TAG_BOUND_PLAYER_ID = "bid"; + private static final String TAG_BOUND_PLAYER_NAME = "bname"; + + PlayerSecurityCardModel(final ItemStack stack) { + super(stack); + } + + @Nullable + UUID getBoundPlayerId() { + return (stack.getTag() == null || !stack.getTag().contains(TAG_BOUND_PLAYER_ID)) + ? null + : stack.getTag().getUUID(TAG_BOUND_PLAYER_ID); + } + + @Nullable + String getBoundPlayerName() { + return (stack.getTag() == null || !stack.getTag().contains(TAG_BOUND_PLAYER_NAME)) + ? null + : stack.getTag().getString(TAG_BOUND_PLAYER_NAME); + } + + void setBoundPlayer(@Nullable final ServerPlayer player) { + final CompoundTag tag = stack.getOrCreateTag(); + if (player == null) { + tag.remove(TAG_BOUND_PLAYER_ID); + tag.remove(TAG_BOUND_PLAYER_NAME); + return; + } + tag.putUUID(TAG_BOUND_PLAYER_ID, player.getGameProfile().getId()); + tag.putString(TAG_BOUND_PLAYER_NAME, player.getGameProfile().getName()); + } + + @Override + boolean isActive() { + return super.isActive() && isActive(stack); + } + + static boolean isActive(final ItemStack stack) { + return stack.getTag() != null + && stack.getTag().contains(TAG_BOUND_PLAYER_ID) + && stack.getTag().contains(TAG_BOUND_PLAYER_NAME); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java index 40e71de9f..9e5177c04 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardContainerMenu.java @@ -1,11 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.security; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.content.Menus; -import com.refinedmods.refinedstorage2.platform.common.support.AbstractBaseContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.stretching.ScreenSizeListener; import java.util.ArrayList; @@ -14,16 +11,12 @@ import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; -public class SecurityCardContainerMenu extends AbstractBaseContainerMenu implements ScreenSizeListener { - private final Inventory playerInventory; - private final List permissions = new ArrayList<>(); +public class SecurityCardContainerMenu extends AbstractSecurityCardContainerMenu implements ScreenSizeListener { private final List players = new ArrayList<>(); @Nullable @@ -32,30 +25,10 @@ public class SecurityCardContainerMenu extends AbstractBaseContainerMenu impleme public SecurityCardContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { - super(Menus.INSTANCE.getSecurityCard(), syncId); - this.playerInventory = playerInventory; - - this.disabledSlot = PlatformApi.INSTANCE.getSlotReference(buf).orElse(null); - - final int amountOfPermissions = buf.readInt(); - for (int i = 0; i < amountOfPermissions; ++i) { - final ResourceLocation id = buf.readResourceLocation(); - final boolean allowed = buf.readBoolean(); - final boolean dirty = buf.readBoolean(); - PlatformApi.INSTANCE.getPermissionRegistry().get(id).ifPresent(permission -> permissions.add(new Permission( - id, - permission.getName(), - permission.getDescription(), - permission.getOwnerName(), - allowed, - dirty - ))); - } - + super(Menus.INSTANCE.getSecurityCard(), syncId, playerInventory, buf); if (buf.readBoolean()) { this.boundTo = new Player(buf.readUUID(), buf.readUtf()); } - final int amountOfPlayers = buf.readInt(); for (int i = 0; i < amountOfPlayers; ++i) { final UUID id = buf.readUUID(); @@ -65,13 +38,7 @@ public SecurityCardContainerMenu(final int syncId, } SecurityCardContainerMenu(final int syncId, final Inventory playerInventory, final SlotReference disabledSlot) { - super(Menus.INSTANCE.getSecurityCard(), syncId); - this.playerInventory = playerInventory; - this.disabledSlot = disabledSlot; - } - - List getPermissions() { - return permissions; + super(Menus.INSTANCE.getSecurityCard(), syncId, playerInventory, disabledSlot); } List getPlayers() { @@ -83,38 +50,6 @@ Player getBoundTo() { return boundTo; } - @Override - public void initSlots(final int playerInventoryY) { - resetSlots(); - addPlayerInventory(playerInventory, 8, playerInventoryY); - } - - public void setPermission(final ResourceLocation permissionId, final boolean allowed) { - if (disabledSlot == null) { - return; - } - disabledSlot.resolve(playerInventory.player).ifPresent(stack -> setPermission(permissionId, allowed, stack)); - } - - private void setPermission(final ResourceLocation permissionId, final boolean allowed, final ItemStack stack) { - if (stack.getItem() instanceof SecurityCardItem securityCardItem) { - securityCardItem.getModel(stack).setPermission(permissionId, allowed); - } - } - - public void resetPermissionServer(final ResourceLocation permissionId) { - if (disabledSlot == null) { - return; - } - disabledSlot.resolve(playerInventory.player).ifPresent(stack -> resetPermissionServer(permissionId, stack)); - } - - private void resetPermissionServer(final ResourceLocation permissionId, final ItemStack stack) { - if (stack.getItem() instanceof SecurityCardItem securityCardItem) { - securityCardItem.getModel(stack).resetPermission(permissionId); - } - } - public void setBoundPlayer(final MinecraftServer server, @Nullable final UUID playerId) { if (disabledSlot == null) { return; @@ -125,43 +60,11 @@ public void setBoundPlayer(final MinecraftServer server, @Nullable final UUID pl private void setBoundPlayer(final MinecraftServer server, @Nullable final UUID playerId, final ItemStack stack) { if (stack.getItem() instanceof SecurityCardItem securityCardItem) { final ServerPlayer player = playerId == null ? null : server.getPlayerList().getPlayer(playerId); - securityCardItem.getModel(stack).setBoundPlayer(player); + final PlayerSecurityCardModel model = securityCardItem.createModel(stack); + model.setBoundPlayer(player); } } - Permission changePermission(final ResourceLocation permissionId, final boolean selected) { - Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardPermission(permissionId, selected); - return updatePermissionLocally(permissionId, selected, true); - } - - Permission resetPermission(final ResourceLocation permissionId) { - final PlatformPermission permission = PlatformApi.INSTANCE.getPermissionRegistry() - .get(permissionId) - .orElseThrow(); - final boolean allowed = permission.isAllowedByDefault(); - Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardResetPermission(permissionId); - return updatePermissionLocally(permissionId, allowed, false); - } - - private Permission updatePermissionLocally(final ResourceLocation permissionId, - final boolean allowed, - final boolean dirty) { - final Permission localPermission = permissions.stream().filter(p -> p.id().equals(permissionId)) - .findFirst() - .orElseThrow(); - final int index = permissions.indexOf(localPermission); - final Permission updatedLocalPermission = new Permission( - localPermission.id(), - localPermission.name(), - localPermission.description(), - localPermission.ownerName(), - allowed, - dirty - ); - permissions.set(index, updatedLocalPermission); - return updatedLocalPermission; - } - void changeBoundPlayer(@Nullable final Player player) { Platform.INSTANCE.getClientToServerCommunications().sendSecurityCardBoundPlayer( player == null ? null : player.id() @@ -169,14 +72,6 @@ void changeBoundPlayer(@Nullable final Player player) { this.boundTo = player; } - record Permission(ResourceLocation id, - Component name, - Component description, - Component ownerName, - boolean allowed, - boolean dirty) { - } - record Player(UUID id, String name) { } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java index 393cfd486..2c60c85b1 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardExtendedMenuProvider.java @@ -1,10 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.security; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; -import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ExtendedMenuProvider; import java.util.Collections; import java.util.List; @@ -12,39 +9,30 @@ 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.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -class SecurityCardExtendedMenuProvider implements ExtendedMenuProvider { +class SecurityCardExtendedMenuProvider extends AbstractSecurityCardExtendedMenuProvider { private final SlotReference slotReference; - private final SecurityCardModel model; + private final PlayerSecurityCardModel playerModel; - SecurityCardExtendedMenuProvider(final SlotReference slotReference, final SecurityCardModel model) { + SecurityCardExtendedMenuProvider(final SlotReference slotReference, final PlayerSecurityCardModel model) { + super(slotReference, model); this.slotReference = slotReference; - this.model = model; + this.playerModel = model; } @Override public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { - PlatformApi.INSTANCE.writeSlotReference(slotReference, buf); + super.writeScreenOpeningData(player, buf); - final List permissions = PlatformApi.INSTANCE.getPermissionRegistry().getAll(); - buf.writeInt(permissions.size()); - for (final PlatformPermission permission : permissions) { - final ResourceLocation id = PlatformApi.INSTANCE.getPermissionRegistry().getId(permission).orElseThrow(); - buf.writeResourceLocation(id); - buf.writeBoolean(model.isAllowed(permission)); - buf.writeBoolean(model.isDirty(permission)); - } - - final boolean bound = model.getBoundPlayerId() != null && model.getBoundPlayerName() != null; + final boolean bound = playerModel.getBoundPlayerId() != null && playerModel.getBoundPlayerName() != null; buf.writeBoolean(bound); if (bound) { - buf.writeUUID(model.getBoundPlayerId()); - buf.writeUtf(model.getBoundPlayerName()); + buf.writeUUID(playerModel.getBoundPlayerId()); + buf.writeUtf(playerModel.getBoundPlayerName()); } final List players = player.getServer() == null diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java index bc819ad2b..c10b17af0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardItem.java @@ -1,29 +1,21 @@ package com.refinedmods.refinedstorage2.platform.common.security; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.support.HelpTooltipComponent; -import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference; import java.util.List; import java.util.Optional; -import javax.annotation.Nullable; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; 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.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.level.Level; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; -public class SecurityCardItem extends Item { +public class SecurityCardItem extends AbstractSecurityCardItem { private static final Component UNBOUND_HELP = createTranslation("item", "security_card.unbound.help"); private static final Component BOUND_HELP = createTranslation("item", "security_card.bound.help"); @@ -31,49 +23,16 @@ public SecurityCardItem() { super(new Item.Properties().stacksTo(1)); } - SecurityCardModel getModel(final ItemStack stack) { - return new SecurityCardModel(stack); - } - - boolean isActive(final ItemStack stack) { - return SecurityCardModel.isActive(stack); - } - @Override - public InteractionResultHolder use(final Level level, final Player player, final InteractionHand hand) { - final ItemStack stack = player.getItemInHand(hand); - if (player instanceof ServerPlayer serverPlayer) { - use(hand, serverPlayer, stack); - } - return InteractionResultHolder.consume(stack); - } - - private void use(final InteractionHand hand, final ServerPlayer player, final ItemStack stack) { - if (player.isCrouching()) { - bindOrClear(player, stack); + void tryClear(final ServerPlayer player, final PlayerSecurityCardModel model) { + if (model.isCleared()) { + bind(player, model); return; } - Platform.INSTANCE.getMenuOpener().openMenu(player, new SecurityCardExtendedMenuProvider( - PlatformApi.INSTANCE.createInventorySlotReference(player, hand), - getModel(stack) - )); - } - - private void bindOrClear(final ServerPlayer player, final ItemStack stack) { - if (stack.hasTag()) { - clear(player, stack); - } else { - bind(player, stack); - } - } - - private void clear(final ServerPlayer player, final ItemStack stack) { - stack.setTag(null); - player.sendSystemMessage(createTranslation("item", "security_card.cleared")); + super.tryClear(player, model); } - private void bind(final ServerPlayer player, final ItemStack stack) { - final SecurityCardModel model = getModel(stack); + private void bind(final ServerPlayer player, final PlayerSecurityCardModel model) { model.setBoundPlayer(player); player.sendSystemMessage(createTranslation( "item", @@ -83,41 +42,39 @@ private void bind(final ServerPlayer player, final ItemStack stack) { } @Override - public void appendHoverText(final ItemStack stack, - @Nullable final Level level, - final List lines, - final TooltipFlag flag) { - super.appendHoverText(stack, level, lines, flag); - final SecurityCardModel model = getModel(stack); - + protected boolean addTooltip(final ItemStack stack, + final List lines, + final PlayerSecurityCardModel model) { final String boundPlayerName = model.getBoundPlayerName(); if (boundPlayerName == null) { lines.add(createTranslation("item", "security_card.unbound").withStyle(ChatFormatting.GRAY)); - return; + return false; } - lines.add(createTranslation( "item", "security_card.bound", Component.literal(boundPlayerName).withStyle(ChatFormatting.YELLOW) ).withStyle(ChatFormatting.GRAY)); - - PlatformApi.INSTANCE.getPermissionRegistry().getAll().forEach(permission -> { - final boolean allowed = model.isAllowed(permission); - final boolean dirty = model.isDirty(permission); - final Style style = Style.EMPTY - .withColor(allowed ? ChatFormatting.GREEN : ChatFormatting.RED) - .withItalic(dirty); - final Component permissionTooltip = Component.literal(allowed ? "✓ " : "❌ ") - .append(permission.getName()) - .append(dirty ? " (*)" : "") - .withStyle(style); - lines.add(permissionTooltip); - }); + return true; } @Override public Optional getTooltipImage(final ItemStack stack) { return Optional.of(new HelpTooltipComponent(isActive(stack) ? BOUND_HELP : UNBOUND_HELP)); } + + @Override + PlayerSecurityCardModel createModel(final ItemStack stack) { + return new PlayerSecurityCardModel(stack); + } + + @Override + AbstractSecurityCardExtendedMenuProvider createMenuProvider(final SlotReference slotReference, + final PlayerSecurityCardModel model) { + return new SecurityCardExtendedMenuProvider(slotReference, model); + } + + boolean isActive(final ItemStack stack) { + return PlayerSecurityCardModel.isActive(stack); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java index 5ef43ae9d..8b6c09ba0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardModel.java @@ -3,20 +3,14 @@ import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.security.PlatformPermission; -import java.util.UUID; -import javax.annotation.Nullable; - import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; class SecurityCardModel { - private static final String TAG_BOUND_PLAYER_ID = "bid"; - private static final String TAG_BOUND_PLAYER_NAME = "bname"; private static final String TAG_PERMISSIONS = "permissions"; - private final ItemStack stack; + protected final ItemStack stack; SecurityCardModel(final ItemStack stack) { this.stack = stack; @@ -55,35 +49,15 @@ void resetPermission(final ResourceLocation permissionId) { permissionsTag.remove(permissionId.toString()); } - @Nullable - UUID getBoundPlayerId() { - return (stack.getTag() == null || !stack.getTag().contains(TAG_BOUND_PLAYER_ID)) - ? null - : stack.getTag().getUUID(TAG_BOUND_PLAYER_ID); + boolean isActive() { + return stack.getTag() != null && stack.getTag().contains(TAG_PERMISSIONS); } - @Nullable - String getBoundPlayerName() { - return (stack.getTag() == null || !stack.getTag().contains(TAG_BOUND_PLAYER_NAME)) - ? null - : stack.getTag().getString(TAG_BOUND_PLAYER_NAME); + boolean isCleared() { + return stack.getTag() == null; } - void setBoundPlayer(@Nullable final ServerPlayer player) { - final CompoundTag tag = stack.getOrCreateTag(); - if (player == null) { - tag.remove(TAG_BOUND_PLAYER_ID); - tag.remove(TAG_BOUND_PLAYER_NAME); - return; - } - tag.putUUID(TAG_BOUND_PLAYER_ID, player.getGameProfile().getId()); - tag.putString(TAG_BOUND_PLAYER_NAME, player.getGameProfile().getName()); - } - - static boolean isActive(final ItemStack stack) { - return stack.getTag() != null - && stack.getTag().contains(TAG_BOUND_PLAYER_ID) - && stack.getTag().contains(TAG_BOUND_PLAYER_NAME) - && stack.getTag().contains(TAG_PERMISSIONS); + public void clear() { + stack.setTag(null); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java index 7669855ca..a0b900925 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/security/SecurityCardScreen.java @@ -1,63 +1,30 @@ package com.refinedmods.refinedstorage2.platform.common.security; -import com.refinedmods.refinedstorage2.platform.common.support.stretching.AbstractStretchingScreen; -import com.refinedmods.refinedstorage2.platform.common.support.widget.CustomCheckboxWidget; - -import java.util.ArrayList; -import java.util.List; import javax.annotation.Nullable; -import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.Tooltip; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Style; -import net.minecraft.resources.ResourceLocation; 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.createTranslation; -public class SecurityCardScreen extends AbstractStretchingScreen { - private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/security_card.png"); - +public class SecurityCardScreen extends AbstractSecurityCardScreen { private static final int BOUND_PLAYER_BUTTON_RIGHT_PADDING = 6; private static final int BOUND_PLAYER_BUTTON_WIDTH = 80; private static final MutableComponent UNBOUND_TITLE = Component.literal("<") .append(createTranslation("gui", "security_card.unbound")) .append(">"); - private static final int RESET_BUTTON_WIDTH = 40; - private static final int RESET_BUTTON_RIGHT_PADDING = 16; - private static final Component RESET_TITLE = createTranslation("gui", "security_card.permission.reset"); - private static final Component MODIFIED_TITLE = createTranslation("gui", "security_card.permission.modified") - .withStyle(Style.EMPTY.withItalic(true).withColor(ChatFormatting.YELLOW)); - - private final List permissions = new ArrayList<>(); - public SecurityCardScreen(final SecurityCardContainerMenu menu, final Inventory playerInventory, final Component text) { super(menu, playerInventory, text); - this.inventoryLabelY = 97; - this.imageWidth = 193; - this.imageHeight = 176; } @Override protected void init(final int rows) { - permissions.clear(); - final List menuPermissions = getMenu().getPermissions(); - for (int i = 0; i < menuPermissions.size(); ++i) { - final Permission permission = createPermission(menuPermissions.get(i), i, rows); - addWidget(permission.checkbox); - addWidget(permission.resetButton); - permissions.add(permission); - } - updateScrollbar(permissions.size()); - + super.init(rows); final Component boundToText = menu.getBoundTo() == null ? UNBOUND_TITLE : Component.literal(menu.getBoundTo().name()); @@ -68,97 +35,6 @@ protected void init(final int rows) { addRenderableWidget(boundPlayerButton); } - private Permission createPermission( - final SecurityCardContainerMenu.Permission menuPermission, - final int index, - final int rows - ) { - final int y = getPermissionY(index); - final boolean visible = isPermissionVisible(rows, y); - final CustomCheckboxWidget checkbox = createPermissionCheckbox(menuPermission, y, visible); - final Button resetButton = createPermissionResetButton(menuPermission, checkbox, y, visible); - checkbox.setOnPressed((c, selected) -> updatePermission(menuPermission, resetButton, c, selected)); - return new Permission(checkbox, resetButton); - } - - private CustomCheckboxWidget createPermissionCheckbox(final SecurityCardContainerMenu.Permission menuPermission, - final int y, - final boolean visible) { - final CustomCheckboxWidget checkbox = new CustomCheckboxWidget( - leftPos + 10, - y, - getPermissionName(menuPermission), - font, - menuPermission.allowed() - ); - checkbox.visible = visible; - checkbox.setTooltip(getPermissionTooltip(menuPermission)); - return checkbox; - } - - private void updatePermission(final SecurityCardContainerMenu.Permission menuPermission, - final Button resetButton, - final CustomCheckboxWidget checkbox, - final boolean allowed) { - updateCheckboxAndResetButton(checkbox, resetButton, menu.changePermission(menuPermission.id(), allowed)); - } - - private Tooltip getPermissionTooltip(final SecurityCardContainerMenu.Permission menuPermission) { - final MutableComponent ownerName = menuPermission.ownerName().copy().withStyle( - Style.EMPTY.withItalic(true).withColor(ChatFormatting.GRAY) - ); - final MutableComponent tooltip = menuPermission.description().copy().append("\n").append(ownerName); - return Tooltip.create(menuPermission.dirty() ? tooltip.append("\n").append(MODIFIED_TITLE) : tooltip); - } - - private Button createPermissionResetButton(final SecurityCardContainerMenu.Permission menuPermission, - final CustomCheckboxWidget checkbox, - final int y, - final boolean visible) { - final Button resetButton = Button.builder(RESET_TITLE, btn -> resetPermission(menuPermission, checkbox, btn)) - .pos(leftPos + imageWidth - RESET_BUTTON_RIGHT_PADDING - RESET_BUTTON_WIDTH - 11, y) - .size(RESET_BUTTON_WIDTH, 16) - .build(); - resetButton.visible = visible; - resetButton.active = menuPermission.dirty(); - return resetButton; - } - - private void resetPermission(final SecurityCardContainerMenu.Permission menuPermission, - final CustomCheckboxWidget checkbox, - final Button resetButton) { - updateCheckboxAndResetButton(checkbox, resetButton, menu.resetPermission(menuPermission.id())); - } - - private void updateCheckboxAndResetButton(final CustomCheckboxWidget checkbox, - final Button resetButton, - final SecurityCardContainerMenu.Permission menuPermission) { - checkbox.setMessage(getPermissionName(menuPermission)); - checkbox.setTooltip(getPermissionTooltip(menuPermission)); - checkbox.setSelected(menuPermission.allowed()); - resetButton.active = menuPermission.dirty(); - } - - private Component getPermissionName(final SecurityCardContainerMenu.Permission menuPermission) { - if (!menuPermission.dirty()) { - return menuPermission.name(); - } - return menuPermission.name().copy().append(" (*)").setStyle(Style.EMPTY.withItalic(true)); - } - - private int getPermissionY(final int index) { - return topPos + 19 + (index * ROW_SIZE) + 3; - } - - private boolean isPermissionVisible(final int rows, final int y) { - return y >= (topPos + 19 - ROW_SIZE) && y < (topPos + 19 + (rows * ROW_SIZE)); - } - - @Override - protected int getScrollPanePadding() { - return 4; - } - private void toggleBoundPlayer(final Button button) { if (menu.getPlayers().isEmpty()) { return; @@ -179,74 +55,4 @@ private void setBoundPlayer(final Button button, @Nullable final SecurityCardCon menu.changeBoundPlayer(player); button.setMessage(player == null ? UNBOUND_TITLE : Component.literal(player.name())); } - - @Override - protected void scrollbarChanged(final int rows) { - final int offset = getScrollbarOffset(); - for (int i = 0; i < permissions.size(); ++i) { - final Permission permission = permissions.get(i); - final int y = getPermissionY(i) - offset; - final boolean visible = isPermissionVisible(rows, y); - permission.setY(y); - permission.setVisible(visible); - } - } - - @Override - protected void renderRows(final GuiGraphics graphics, - final int x, - final int y, - final int topHeight, - final int rows, - final int mouseX, - final int mouseY) { - for (final Permission permission : permissions) { - permission.render(graphics, mouseX, mouseY); - } - } - - @Override - protected void renderStretchingBackground(final GuiGraphics graphics, final int x, final int y, final int rows) { - for (int row = 0; row < rows; ++row) { - int textureY = 37; - if (row == 0) { - textureY = 19; - } else if (row == rows - 1) { - textureY = 55; - } - graphics.blit(getTexture(), x, y + (ROW_SIZE * row), 0, textureY, imageWidth, ROW_SIZE); - } - } - - @Override - protected int getBottomHeight() { - return 99; - } - - @Override - protected int getBottomV() { - return 73; - } - - @Override - protected ResourceLocation getTexture() { - return TEXTURE; - } - - private record Permission(CustomCheckboxWidget checkbox, Button resetButton) { - private void setY(final int y) { - checkbox.setY(y); - resetButton.setY(y); - } - - private void setVisible(final boolean visible) { - checkbox.visible = visible; - resetButton.visible = visible; - } - - private void render(final GuiGraphics graphics, final int mouseX, final int mouseY) { - checkbox.render(graphics, mouseX, mouseY, 0); - resetButton.render(graphics, mouseX, mouseY, 0); - } - } } 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 a1a39448a..5ccab4c59 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 @@ -225,9 +225,11 @@ "item.refinedstorage2.security_card": "Security Card", "item.refinedstorage2.security_card.cleared": "Cleared binding.", "item.refinedstorage2.security_card.unbound": "Unbound.", - "item.refinedstorage2.security_card.unbound.help": "Use while crouching to bind to the current player. Right click to configure.", + "item.refinedstorage2.security_card.unbound.help": "Right click to configure. Use while crouching to bind to the current player.", "item.refinedstorage2.security_card.bound": "Bound to %s.", - "item.refinedstorage2.security_card.bound.help": "Use while crouching to clear binding. Right click to configure.", + "item.refinedstorage2.security_card.bound.help": "Right click to configure. Use while crouching to clear configuration and binding.", + "item.refinedstorage2.fallback_security_card": "Fallback Security Card", + "item.refinedstorage2.fallback_security_card.help": "Acts as a fallback if no matching Security Card for a player is found. Right click to configure. Use while crouching to clear configuration.", "misc.refinedstorage2.stored": "Stored: %s", "misc.refinedstorage2.stored_with_capacity": "Stored: %s / %s (%d%%)", "misc.refinedstorage2.total": "%d total", diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/fallback_security_card.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/fallback_security_card.json new file mode 100755 index 000000000..2ec96d3b9 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/models/item/fallback_security_card.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "refinedstorage2:item/security_card/fallback" + } +} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/security_card/fallback.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/item/security_card/fallback.png new file mode 100644 index 0000000000000000000000000000000000000000..af70c71432c506a5b8adc4ad7d54c8b4428b812c GIT binary patch literal 570 zcmV-A0>%A_P)8t4$^!J8l*J%}Dma=N7H zNgOd`jSiBYf|XL#i!OT^NE#Fr!qZ|bo)$8!QBq_?mm(oqD}9|BTH3>G|MUC(zV~?F z12jYs1kzG>W|GMyDT+d|SnT|gR4PT|@t6vQ0^Qs{qI>VYX_utaX&Q}2l+Wks>hnEf z><{SH-k~;0CX=DTU_iNCjyB#L(e3WfQxcEIqe^sVz3g_o@qL`f!`@{~58h&7x`JzW zY+!z!;L(pBTrL+FhS}+KI>`%v!|`~WoK7d^!~E;;8(A~D@(SBqI)t8mfyH7$tJQ)iiYlybpI z-|t8HwSv2rAwEwofz?m(^wmXJtyVOfO%#j8Q}90#1c78(CP5JB{lOCo27@GuBKdqi z?LROS3Q@n`r)V@vk|Yt&^XI>TNF+j%BvCjV{{Jfs1Ol4i-wWmVZ{CiDp#T5?07*qo IM6N<$f|=<4lmGw# literal 0 HcmV?d00001 diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fallback_security_card.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fallback_security_card.json new file mode 100644 index 000000000..0186f81b7 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/fallback_security_card.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { + "item": "refinedstorage2:security_card" + }, + { + "item": "minecraft:paper" + } + ], + "result": { + "item": "refinedstorage2:fallback_security_card" + } +} 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 0676e4244..907e9a872 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 @@ -14,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem; @@ -254,6 +255,15 @@ public boolean allowNbtUpdateAnimation(final Player player, final ItemStack newStack) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } + }, + () -> new FallbackSecurityCardItem() { + @Override + public boolean allowNbtUpdateAnimation(final Player player, + final InteractionHand hand, + final ItemStack oldStack, + final ItemStack newStack) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } } ); registerUpgradeMappings(); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java index 9c392195b..cfebef7b1 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardPermissionPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.AbstractSecurityCardContainerMenu; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -19,7 +19,7 @@ public void receive(final MinecraftServer server, final PacketSender responseSender) { final ResourceLocation permissionId = buf.readResourceLocation(); final boolean allowed = buf.readBoolean(); - if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + if (player.containerMenu instanceof AbstractSecurityCardContainerMenu securityCardContainerMenu) { server.execute(() -> securityCardContainerMenu.setPermission(permissionId, allowed)); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java index 16e54f230..ded155bf9 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/SecurityCardResetPermissionPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.c2s; -import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.AbstractSecurityCardContainerMenu; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -18,7 +18,7 @@ public void receive(final MinecraftServer server, final FriendlyByteBuf buf, final PacketSender responseSender) { final ResourceLocation permissionId = buf.readResourceLocation(); - if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + if (player.containerMenu instanceof AbstractSecurityCardContainerMenu securityCardContainerMenu) { server.execute(() -> securityCardContainerMenu.resetPermissionServer(permissionId)); } } 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 647cf114e..af65f270d 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 @@ -14,6 +14,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.RegistryCallback; import com.refinedmods.refinedstorage2.platform.common.grid.WirelessGridItem; import com.refinedmods.refinedstorage2.platform.common.iface.InterfacePlatformExternalStorageProviderFactory; +import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardItem; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem; import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType; @@ -257,6 +258,14 @@ public boolean shouldCauseReequipAnimation(final ItemStack oldStack, final boolean slotChanged) { return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); } + }, + () -> new FallbackSecurityCardItem() { + @Override + public boolean shouldCauseReequipAnimation(final ItemStack oldStack, + final ItemStack newStack, + final boolean slotChanged) { + return AbstractModInitializer.allowNbtUpdateAnimation(oldStack, newStack); + } } ); itemRegistry.register(eventBus); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java index c1807187c..16a8f5353 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardPermissionPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; -import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.AbstractSecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import net.minecraft.network.FriendlyByteBuf; @@ -16,7 +16,7 @@ public static SecurityCardPermissionPacket decode(final FriendlyByteBuf buf) { public static void handle(final SecurityCardPermissionPacket packet, final PlayPayloadContext ctx) { ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { - if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + if (player.containerMenu instanceof AbstractSecurityCardContainerMenu securityCardContainerMenu) { securityCardContainerMenu.setPermission(packet.permissionId, packet.allowed); } })); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java index f517c608d..cdd621829 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/support/packet/c2s/SecurityCardResetPermissionPacket.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.forge.support.packet.c2s; -import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.security.AbstractSecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.support.packet.PacketIds; import net.minecraft.network.FriendlyByteBuf; @@ -15,7 +15,7 @@ public static SecurityCardResetPermissionPacket decode(final FriendlyByteBuf buf public static void handle(final SecurityCardResetPermissionPacket packet, final PlayPayloadContext ctx) { ctx.player().ifPresent(player -> ctx.workHandler().submitAsync(() -> { - if (player.containerMenu instanceof SecurityCardContainerMenu securityCardContainerMenu) { + if (player.containerMenu instanceof AbstractSecurityCardContainerMenu securityCardContainerMenu) { securityCardContainerMenu.resetPermissionServer(packet.permissionId); } }));