diff --git a/CHANGELOG.md b/CHANGELOG.md index c207434b9..c62a7f8ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,16 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Relay + ### Changed - The Detector, Network Receiver, Network Transmitter and Security Manager will now always connect regardless of color. +- The Relay now has a "pass-through" mode. By default, pass-through is on, which means that when the Relay is active, the network signal from the input network will be passed through as-is to the output side. +- When the "pass-through" mode on the Relay is off, the network signal from the input network will no longer be passed through as-is to the output side, but you can choose to pass the energy buffer, security settings or (specific) storage resources of the input network to the output network. +- When using the Relay when "pass-through" mode is off, and when passing all storage resources or specific storage resources, you can choose the filter mode, whether fuzzy mode is enabled, the access mode and the priority of the storage exposed to the output network. ### Fixed diff --git a/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java b/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java index e69e7880d..370f57cf1 100644 --- a/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java +++ b/refinedstorage2-core-api/src/main/java/com/refinedmods/refinedstorage2/api/core/component/ComponentMapFactory.java @@ -26,9 +26,13 @@ public ComponentMapFactory copy() { return new ComponentMapFactory<>(new LinkedHashMap<>(factories)); } + @SuppressWarnings("unchecked") public ComponentMap buildComponentMap(final X context) { final Map, C> components = new LinkedHashMap<>(); - factories.forEach((componentType, factory) -> components.put(componentType, factory.apply(context))); + factories.forEach((componentType, factory) -> { + final C component = factory.apply(context); + components.put(componentType, component); + }); return new ComponentMap<>(components); } } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/energy/EnergyProvider.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/energy/EnergyProvider.java index 12a671534..8af73c121 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/energy/EnergyProvider.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/energy/EnergyProvider.java @@ -9,4 +9,8 @@ public interface EnergyProvider { long getCapacity(); long extract(long amount); + + default boolean contains(EnergyProvider energyProvider) { + return false; + } } 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 65648e5fc..eb4f3ff1f 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 @@ -11,7 +11,11 @@ default SecurityDecision isAllowed(Permission permission) { return SecurityDecision.PASS; } - default boolean isActive() { + default boolean isProviderActive() { return true; } + + default boolean contains(SecurityNetworkComponent component) { + return false; + } } 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 fcda6ad8c..e87cfa4b2 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,7 +5,8 @@ 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); + + boolean contains(SecurityNetworkComponent component); } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityPolicy.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityPolicy.java index fce560a79..0f997651f 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityPolicy.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/security/SecurityPolicy.java @@ -9,6 +9,10 @@ public record SecurityPolicy(Set allowedPermissions) { public static final SecurityPolicy EMPTY = new SecurityPolicy(Collections.emptySet()); + public static SecurityPolicy of(final Permission... permissions) { + return new SecurityPolicy(Set.of(permissions)); + } + public boolean isAllowed(final Permission permission) { return allowedPermissions.contains(permission); } diff --git a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageNetworkComponent.java b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageNetworkComponent.java index 7b6a9ad0d..29a27ead8 100644 --- a/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageNetworkComponent.java +++ b/refinedstorage2-network-api/src/main/java/com/refinedmods/refinedstorage2/api/network/storage/StorageNetworkComponent.java @@ -2,6 +2,7 @@ import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; @@ -12,4 +13,6 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.1") public interface StorageNetworkComponent extends NetworkComponent, StorageChannel { List getResources(Class actorType); + + boolean contains(Storage storage); } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkSecurityComponent.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkSecurityComponent.java new file mode 100644 index 000000000..d0b87298c --- /dev/null +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkSecurityComponent.java @@ -0,0 +1,12 @@ +package com.refinedmods.refinedstorage2.network.test; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface InjectNetworkSecurityComponent { + String networkId() default "default"; +} diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageChannel.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageComponent.java similarity index 86% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageChannel.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageComponent.java index 58b66a386..a78bd1f77 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageChannel.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/InjectNetworkStorageComponent.java @@ -7,6 +7,6 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) -public @interface InjectNetworkStorageChannel { +public @interface InjectNetworkStorageComponent { String networkId() default "default"; } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTest.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTest.java index bfa7b10aa..15b6880bb 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTest.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/NetworkTest.java @@ -9,6 +9,8 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayInputNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayOutputNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; import com.refinedmods.refinedstorage2.network.test.nodefactory.ControllerNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.DetectorNetworkNodeFactory; @@ -18,6 +20,8 @@ import com.refinedmods.refinedstorage2.network.test.nodefactory.ImporterNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.InterfaceNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.MultiStorageNetworkNodeFactory; +import com.refinedmods.refinedstorage2.network.test.nodefactory.RelayInputNetworkNodeFactory; +import com.refinedmods.refinedstorage2.network.test.nodefactory.RelayOutputNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.SimpleNetworkNodeFactory; import com.refinedmods.refinedstorage2.network.test.nodefactory.StorageNetworkNodeFactory; @@ -41,5 +45,7 @@ @RegisterNetworkNode(value = InterfaceNetworkNodeFactory.class, clazz = InterfaceNetworkNode.class) @RegisterNetworkNode(value = ExternalStorageNetworkNodeFactory.class, clazz = ExternalStorageNetworkNode.class) @RegisterNetworkNode(value = DetectorNetworkNodeFactory.class, clazz = DetectorNetworkNode.class) +@RegisterNetworkNode(value = RelayInputNetworkNodeFactory.class, clazz = RelayInputNetworkNode.class) +@RegisterNetworkNode(value = RelayOutputNetworkNodeFactory.class, clazz = RelayOutputNetworkNode.class) public @interface NetworkTest { } 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 96c5afaa1..dbcb0be5a 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 @@ -8,13 +8,14 @@ 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.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.nodefactory.NetworkNodeFactory; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -33,9 +34,10 @@ public class NetworkTestExtension implements BeforeEachCallback, ParameterResolv @Override public void beforeEach(final ExtensionContext extensionContext) { - extensionContext - .getTestInstances() - .ifPresent(testInstances -> testInstances.getAllInstances().forEach(this::processTestInstance)); + extensionContext.getTestInstances().ifPresent( + testInstances -> testInstances.getAllInstances().forEach(this::processTestInstance) + ); + extensionContext.getTestMethod().ifPresent(this::processTestMethod); } private void processTestInstance(final Object testInstance) { @@ -45,6 +47,10 @@ private void processTestInstance(final Object testInstance) { addNetworkNodes(testInstance); } + private void processTestMethod(final Method method) { + setupNetworks(method); + } + private void registerNetworkNodes(final Object testInstance) { for (final RegisterNetworkNode annotation : getAnnotations(testInstance, RegisterNetworkNode.class)) { try { @@ -61,10 +67,22 @@ private void registerNetworkNodes(final Object testInstance) { private void setupNetworks(final Object testInstance) { for (final SetupNetwork annotation : getAnnotations(testInstance, SetupNetwork.class)) { - final Network network = new NetworkImpl(NetworkTestFixtures.NETWORK_COMPONENT_MAP_FACTORY); + setupNetwork(annotation); + } + } + + private void setupNetworks(final Method method) { + for (final SetupNetwork annotation : method.getAnnotationsByType(SetupNetwork.class)) { + setupNetwork(annotation); + } + } + + private void setupNetwork(final SetupNetwork annotation) { + final Network network = new NetworkImpl(NetworkTestFixtures.NETWORK_COMPONENT_MAP_FACTORY); + if (annotation.setupEnergy()) { setupNetworkEnergy(annotation.energyCapacity(), annotation.energyStored(), network); - networkMap.put(annotation.id(), network); } + networkMap.put(annotation.id(), network); } private List getAnnotations(final Object testInstance, final Class annotationType) { @@ -173,8 +191,9 @@ private void setField(final Object instance, final Field field, final Object val @Override public boolean supportsParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException { - return parameterContext.isAnnotated(InjectNetworkStorageChannel.class) + return parameterContext.isAnnotated(InjectNetworkStorageComponent.class) || parameterContext.isAnnotated(InjectNetworkEnergyComponent.class) + || parameterContext.isAnnotated(InjectNetworkSecurityComponent.class) || parameterContext.isAnnotated(InjectNetwork.class); } @@ -182,26 +201,29 @@ public boolean supportsParameter(final ParameterContext parameterContext, public Object resolveParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException { return parameterContext - .findAnnotation(InjectNetworkStorageChannel.class) - .map(annotation -> (Object) getNetworkStorageChannel(annotation.networkId())) + .findAnnotation(InjectNetworkStorageComponent.class) + .map(annotation -> (Object) getNetworkStorage(annotation.networkId())) .or(() -> parameterContext .findAnnotation(InjectNetworkEnergyComponent.class) .map(annotation -> (Object) getNetworkEnergy(annotation.networkId()))) + .or(() -> parameterContext + .findAnnotation(InjectNetworkSecurityComponent.class) + .map(annotation -> (Object) getNetworkSecurity(annotation.networkId()))) .or(() -> parameterContext .findAnnotation(InjectNetwork.class) .map(annotation -> networkMap.get(annotation.value()))) .orElseThrow(); } - private StorageChannel getNetworkStorageChannel(final String networkId) { - return networkMap - .get(networkId) - .getComponent(StorageNetworkComponent.class); + private StorageNetworkComponent getNetworkStorage(final String networkId) { + return networkMap.get(networkId).getComponent(StorageNetworkComponent.class); } private EnergyNetworkComponent getNetworkEnergy(final String networkId) { - return networkMap - .get(networkId) - .getComponent(EnergyNetworkComponent.class); + return networkMap.get(networkId).getComponent(EnergyNetworkComponent.class); + } + + private SecurityNetworkComponent getNetworkSecurity(final String networkId) { + return networkMap.get(networkId).getComponent(SecurityNetworkComponent.class); } } 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 71914cc5f..4cbfc678c 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 @@ -6,10 +6,14 @@ 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.security.SecurityNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; public final class NetworkTestFixtures { public static final ComponentMapFactory NETWORK_COMPONENT_MAP_FACTORY = @@ -28,6 +32,10 @@ public final class NetworkTestFixtures { StorageNetworkComponent.class, network -> new StorageNetworkComponentImpl(new ResourceListImpl()) ); + NETWORK_COMPONENT_MAP_FACTORY.addFactory( + SecurityNetworkComponent.class, + network -> new SecurityNetworkComponentImpl(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) + ); } private NetworkTestFixtures() { diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetwork.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetwork.java index 33d86306c..566fc4889 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetwork.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetwork.java @@ -7,12 +7,14 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) +@Target({ElementType.TYPE, ElementType.METHOD}) @Repeatable(SetupNetworks.class) public @interface SetupNetwork { long energyStored() default Long.MAX_VALUE; long energyCapacity() default Long.MAX_VALUE; + boolean setupEnergy() default true; + String id() default "default"; } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetworks.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetworks.java index d1eb45dbd..409d5b997 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetworks.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/SetupNetworks.java @@ -6,7 +6,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) +@Target({ElementType.TYPE, ElementType.METHOD}) public @interface SetupNetworks { SetupNetwork[] value(); } diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeActor.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeActor.java similarity index 82% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeActor.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeActor.java index 27f1d6963..c746b2e03 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/FakeActor.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeActor.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.network.test.util; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.storage.Actor; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakePermissions.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakePermissions.java new file mode 100644 index 000000000..8e8e42914 --- /dev/null +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakePermissions.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage2.network.test.fake; + +import com.refinedmods.refinedstorage2.api.network.security.Permission; + +public enum FakePermissions implements Permission { + ALLOW_BY_DEFAULT, OTHER, OTHER2 +} diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/TestResource.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeResources.java similarity index 58% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/TestResource.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeResources.java index d5fa8fd57..3a3f9faca 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/TestResource.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeResources.java @@ -1,8 +1,8 @@ -package com.refinedmods.refinedstorage2.network.test; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; -public enum TestResource implements ResourceKey { +public enum FakeResources implements ResourceKey { A, A_ALTERNATIVE, A_ALTERNATIVE2, diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeSecurityActors.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeSecurityActors.java new file mode 100644 index 000000000..c0852bf24 --- /dev/null +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/FakeSecurityActors.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage2.network.test.fake; + +import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; + +public enum FakeSecurityActors implements SecurityActor { + A, B, C +} diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/package-info.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/package-info.java similarity index 78% rename from refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/package-info.java rename to refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/package-info.java index a2f32aa2c..c0900bc54 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/util/package-info.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/fake/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @FieldsAndMethodsAreNonnullByDefault -package com.refinedmods.refinedstorage2.network.test.util; +package com.refinedmods.refinedstorage2.network.test.fake; import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java index e6093f416..995a66a29 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/AbstractNetworkNodeFactory.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java index 7db29d3ee..4b2e9d739 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ControllerNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.controller.ControllerNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java index c6f1830fb..84bb4f968 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/DetectorNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java index 1c1addc8c..785efded3 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExporterNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.exporter.ExporterNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java index 3827224d0..dab53f6ce 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ExternalStorageNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.storage.tracked.InMemoryTrackedStorageRepository; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java index 48ae36153..b44076bb4 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/GridNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java index 8cd7444af..95cd430c4 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/ImporterNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java index dca9012be..96a33ac88 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/InterfaceNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java index 7543f8b51..0e56caffe 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/MultiStorageNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/RelayInputNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/RelayInputNetworkNodeFactory.java new file mode 100644 index 000000000..a5a404150 --- /dev/null +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/RelayInputNetworkNodeFactory.java @@ -0,0 +1,14 @@ +package com.refinedmods.refinedstorage2.network.test.nodefactory; + +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayInputNetworkNode; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; + +import java.util.Map; + +public class RelayInputNetworkNodeFactory extends AbstractNetworkNodeFactory { + @Override + protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map properties) { + return new RelayInputNetworkNode(getEnergyUsage(properties)); + } +} diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/RelayOutputNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/RelayOutputNetworkNodeFactory.java new file mode 100644 index 000000000..5fe51e9f1 --- /dev/null +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/RelayOutputNetworkNodeFactory.java @@ -0,0 +1,14 @@ +package com.refinedmods.refinedstorage2.network.test.nodefactory; + +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayOutputNetworkNode; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; + +import java.util.Map; + +public class RelayOutputNetworkNodeFactory extends AbstractNetworkNodeFactory { + @Override + protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map properties) { + return new RelayOutputNetworkNode(getEnergyUsage(properties)); + } +} diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java index ad1c8380f..894ca653f 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/SimpleNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; diff --git a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java index 2c7cb7aca..9600b77f0 100644 --- a/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java +++ b/refinedstorage2-network-test/src/main/java/com/refinedmods/refinedstorage2/network/test/nodefactory/StorageNetworkNodeFactory.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.network.test.nodefactory; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import java.util.Map; 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 fa703a9b1..f842ed7c8 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 @@ -7,8 +7,8 @@ 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.security.SecurityNetworkComponent; 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; import com.refinedmods.refinedstorage2.network.test.nodefactory.SimpleNetworkNodeFactory; @@ -62,6 +62,29 @@ void shouldSetNetwork() { assertThat(storageInB.getNetwork()).isEqualTo(b); } + @Test + @SetupNetwork(id = "method_test") + void shouldSetNetworkThroughMethod( + @InjectNetwork("method_test") final Network network + ) { + // Assert + assertThat(network) + .isNotNull() + .isNotEqualTo(a) + .isNotEqualTo(b); + } + + @Test + @SetupNetwork(id = "without_energy", setupEnergy = false) + void shouldNotSetupEnergy( + @InjectNetworkEnergyComponent(networkId = "without_energy") final EnergyNetworkComponent energy + ) { + // Assert + assertThat(energy.getStored()).isZero(); + assertThat(energy.getCapacity()).isZero(); + assertThat(energy.extract(1)).isZero(); + } + @Test void shouldSetActivenessOfNetworkNode() { // Assert @@ -106,13 +129,13 @@ void shouldAddNetworkNodeToGraph() { } @Test - void shouldInjectStorageChannel( - @InjectNetworkStorageChannel(networkId = "a") final StorageChannel storageChannelA, - @InjectNetworkStorageChannel(networkId = "b") final StorageChannel storageChannelB + void shouldInjectNetworkStorageComponent( + @InjectNetworkStorageComponent(networkId = "a") final StorageNetworkComponent networkStorageA, + @InjectNetworkStorageComponent(networkId = "b") final StorageNetworkComponent networkStorageB ) { // Assert - assertThat(storageChannelA).isSameAs(a.getComponent(StorageNetworkComponent.class)); - assertThat(storageChannelB).isSameAs(b.getComponent(StorageNetworkComponent.class)); + assertThat(networkStorageA).isSameAs(a.getComponent(StorageNetworkComponent.class)); + assertThat(networkStorageB).isSameAs(b.getComponent(StorageNetworkComponent.class)); } @Test @@ -125,6 +148,16 @@ void shouldInjectNetworkEnergyComponent( assertThat(networkEnergyB).isSameAs(b.getComponent(EnergyNetworkComponent.class)); } + @Test + void shouldInjectNetworkSecurityComponent( + @InjectNetworkSecurityComponent(networkId = "a") final SecurityNetworkComponent networkSecurityA, + @InjectNetworkSecurityComponent(networkId = "b") final SecurityNetworkComponent networkSecurityB + ) { + // Assert + assertThat(networkSecurityA).isSameAs(a.getComponent(SecurityNetworkComponent.class)); + assertThat(networkSecurityB).isSameAs(b.getComponent(SecurityNetworkComponent.class)); + } + @Test void shouldInjectNetworkThroughParameter( @InjectNetwork("a") final Network injectedA, 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 52404150c..2ab334726 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 @@ -163,7 +163,9 @@ private void splitNetworks(final ConnectionProvider connectionProvider, connectionProvider.sortDeterministically(removedEntries).stream().sorted(HIGHEST_PRIORITY_FIRST).forEach(e -> { if (e.getNode().getNetwork() == null) { - throw new IllegalStateException("Network of resulting removed node cannot be empty"); + throw new IllegalStateException( + "Network of resulting removed node (" + e.getNode() + ") cannot be empty" + ); } e.getNode().getNetwork().removeContainer(e); e.getNode().setNetwork(null); diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImpl.java index 8a6aed6db..2c158a91a 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/energy/EnergyNetworkComponentImpl.java @@ -59,4 +59,14 @@ public long extract(final long amount) { } return extracted; } + + @Override + public boolean contains(final EnergyProvider energyProvider) { + for (final EnergyProvider provider : providers) { + if (provider.contains(energyProvider)) { + return true; + } + } + return false; + } } 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/node/AbstractNetworkNode.java similarity index 94% rename from refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/AbstractNetworkNode.java rename to refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/AbstractNetworkNode.java index 62668a51e..ab56f816f 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/node/AbstractNetworkNode.java @@ -1,4 +1,4 @@ -package com.refinedmods.refinedstorage2.api.network.impl.storage; +package com.refinedmods.refinedstorage2.api.network.impl.node; import com.refinedmods.refinedstorage2.api.network.Network; import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java index 7a2e3af67..c96642d8f 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/SimpleNetworkNode.java @@ -1,7 +1,5 @@ package com.refinedmods.refinedstorage2.api.network.impl.node; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; - public class SimpleNetworkNode extends AbstractNetworkNode { private long energyUsage; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java index 005649dac..c5ff7f7aa 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/controller/ControllerNetworkNode.java @@ -3,7 +3,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyProvider; import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java index fb6d9c53c..80a6d0ece 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.detector; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import javax.annotation.Nullable; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java index 9ae1f3962..456528588 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/ExporterNetworkNode.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.exporter; import com.refinedmods.refinedstorage2.api.network.Network; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.Task; 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 1df665710..14bd41a2e 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,7 +4,7 @@ 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.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.Actor; 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 95a969da1..2e48a7f8d 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,9 +1,9 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; 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; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java index dacbe7b16..75174753e 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.importer; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayComponentType.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayComponentType.java new file mode 100644 index 000000000..c9ba9ddcf --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayComponentType.java @@ -0,0 +1,7 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +public enum RelayComponentType { + ENERGY, + SECURITY, + STORAGE +} diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayInputNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayInputNetworkNode.java new file mode 100644 index 000000000..955f7c097 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayInputNetworkNode.java @@ -0,0 +1,116 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; + +import java.util.HashSet; +import java.util.Set; +import java.util.function.UnaryOperator; +import javax.annotation.Nullable; + +public class RelayInputNetworkNode extends AbstractNetworkNode { + private final long energyUsage; + private final Set componentTypes = new HashSet<>(); + + @Nullable + private RelayOutputNetworkNode outputNode; + + public RelayInputNetworkNode(final long energyUsage) { + this.energyUsage = energyUsage; + } + + @Override + public void setNetwork(@Nullable final Network network) { + super.setNetwork(network); + updateComponents(); + } + + @Override + protected void onActiveChanged(final boolean newActive) { + super.onActiveChanged(newActive); + updateComponents(); + } + + public void setOutputNode(@Nullable final RelayOutputNetworkNode outputNode) { + this.outputNode = outputNode; + } + + public void setComponentTypes(final Set componentTypes) { + this.componentTypes.clear(); + this.componentTypes.addAll(componentTypes); + updateComponents(); + } + + public void updateComponentType(final RelayComponentType componentType, final boolean enabled) { + if (enabled) { + componentTypes.add(componentType); + } else { + componentTypes.remove(componentType); + } + updateComponents(); + } + + private void updateComponents() { + if (outputNode == null) { + return; + } + final boolean valid = network != null && isActive(); + final boolean hasEnergy = componentTypes.contains(RelayComponentType.ENERGY); + outputNode.setEnergyDelegate(valid && hasEnergy + ? network.getComponent(EnergyNetworkComponent.class) + : null); + final boolean hasSecurity = componentTypes.contains(RelayComponentType.SECURITY); + outputNode.setSecurityDelegate(valid && hasSecurity + ? network.getComponent(SecurityNetworkComponent.class) + : null); + final boolean hasStorage = componentTypes.contains(RelayComponentType.STORAGE); + outputNode.setStorageDelegate(valid && hasStorage + ? network.getComponent(StorageNetworkComponent.class) + : null); + } + + public void setAccessMode(final AccessMode accessMode) { + if (outputNode != null) { + outputNode.setAccessMode(accessMode); + } + } + + public void setPriority(final int priority) { + if (outputNode != null) { + outputNode.setPriority(priority); + } + } + + public void setFilters(final Set filters) { + if (outputNode != null) { + outputNode.setFilters(filters); + } + } + + public void setFilterMode(final FilterMode filterMode) { + if (outputNode != null) { + outputNode.setFilterMode(filterMode); + } + } + + public void setFilterNormalizer(final UnaryOperator normalizer) { + if (outputNode != null) { + outputNode.setFilterNormalizer(normalizer); + } + } + + public boolean hasComponentType(final RelayComponentType componentType) { + return componentTypes.contains(componentType); + } + + @Override + public long getEnergyUsage() { + return energyUsage; + } +} diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputNetworkNode.java new file mode 100644 index 000000000..2abe51359 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputNetworkNode.java @@ -0,0 +1,123 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyProvider; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; +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 com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.storage.Storage; + +import java.util.Set; +import java.util.function.UnaryOperator; +import javax.annotation.Nullable; + +public class RelayOutputNetworkNode extends AbstractNetworkNode + implements EnergyProvider, SecurityDecisionProvider, StorageProvider { + private final long energyUsage; + private final RelayOutputStorage storage = new RelayOutputStorage(); + + @Nullable + private EnergyNetworkComponent energyDelegate; + @Nullable + private SecurityNetworkComponent securityDelegate; + + public RelayOutputNetworkNode(final long energyUsage) { + this.energyUsage = energyUsage; + } + + void setEnergyDelegate(@Nullable final EnergyNetworkComponent energyDelegate) { + this.energyDelegate = energyDelegate; + } + + void setSecurityDelegate(@Nullable final SecurityNetworkComponent securityDelegate) { + this.securityDelegate = securityDelegate; + } + + void setStorageDelegate(@Nullable final StorageNetworkComponent storageDelegate) { + this.storage.setDelegate(storageDelegate); + } + + void setAccessMode(final AccessMode accessMode) { + this.storage.setAccessMode(accessMode); + } + + void setPriority(final int priority) { + this.storage.setPriority(priority); + if (network != null) { + network.getComponent(StorageNetworkComponent.class).sortSources(); + } + } + + void setFilters(final Set filters) { + this.storage.setFilters(filters); + } + + void setFilterMode(final FilterMode filterMode) { + this.storage.setFilterMode(filterMode); + } + + void setFilterNormalizer(final UnaryOperator normalizer) { + this.storage.setFilterNormalizer(normalizer); + } + + @Override + public long getEnergyUsage() { + if (energyDelegate != null || securityDelegate != null || storage.hasDelegate()) { + return energyUsage; + } + return 0; + } + + @Override + public long getStored() { + return energyDelegate == null || energyDelegate.contains(energyDelegate) ? 0 : energyDelegate.getStored(); + } + + @Override + public long getCapacity() { + return energyDelegate == null || energyDelegate.contains(energyDelegate) ? 0 : energyDelegate.getCapacity(); + } + + @Override + public long extract(final long amount) { + return energyDelegate == null || energyDelegate.contains(energyDelegate) ? 0 : energyDelegate.extract(amount); + } + + @Override + public boolean contains(final EnergyProvider energyProvider) { + return energyProvider == energyDelegate + || (energyDelegate != null && energyDelegate.contains(energyProvider)); + } + + @Override + public boolean contains(final SecurityNetworkComponent securityComponent) { + return securityComponent == securityDelegate + || (securityDelegate != null && securityDelegate.contains(securityComponent)); + } + + @Override + public SecurityDecision isAllowed(final Permission permission, final SecurityActor actor) { + if (securityDelegate == null || securityDelegate.contains(securityDelegate)) { + return SecurityDecision.PASS; + } + return securityDelegate.isAllowed(permission, actor) ? SecurityDecision.ALLOW : SecurityDecision.DENY; + } + + @Override + public boolean isProviderActive() { + return isActive() && securityDelegate != null; + } + + @Override + public Storage getStorage() { + return storage; + } +} diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputStorage.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputStorage.java new file mode 100644 index 000000000..c0693fb68 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayOutputStorage.java @@ -0,0 +1,181 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +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.resource.filter.Filter; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; +import com.refinedmods.refinedstorage2.api.resource.list.listenable.ResourceListListener; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.storage.Actor; +import com.refinedmods.refinedstorage2.api.storage.Storage; +import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild; +import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite; +import com.refinedmods.refinedstorage2.api.storage.composite.Priority; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.function.UnaryOperator; +import javax.annotation.Nullable; + +class RelayOutputStorage implements CompositeAwareChild, ResourceListListener, Priority { + private final Set parentComposites = new HashSet<>(); + private final Filter filter = new Filter(); + + @Nullable + private StorageNetworkComponent delegate; + private AccessMode accessMode = AccessMode.INSERT_EXTRACT; + private int priority; + + boolean hasDelegate() { + return delegate != null; + } + + void setAccessMode(final AccessMode accessMode) { + this.accessMode = accessMode; + } + + void setPriority(final int priority) { + this.priority = priority; + } + + void setFilters(final Set filters) { + reset(() -> filter.setFilters(filters)); + } + + void setFilterMode(final FilterMode filterMode) { + reset(() -> filter.setMode(filterMode)); + } + + void setFilterNormalizer(final UnaryOperator normalizer) { + reset(() -> filter.setNormalizer(normalizer)); + } + + private void reset(final Runnable action) { + final StorageNetworkComponent oldDelegate = delegate; + setDelegate(null); + action.run(); + setDelegate(oldDelegate); + } + + void setDelegate(@Nullable final StorageNetworkComponent delegate) { + if (this.delegate != null) { + parentComposites.forEach(parent -> getAll().forEach(resourceAmount -> parent.removeFromCache( + resourceAmount.getResource(), + resourceAmount.getAmount() + ))); + this.delegate.removeListener(this); + } + this.delegate = delegate; + if (delegate != null) { + parentComposites.forEach(parent -> getAll().forEach(resourceAmount -> parent.addToCache( + resourceAmount.getResource(), + resourceAmount.getAmount() + ))); + delegate.addListener(this); + } + } + + @Override + public void onAddedIntoComposite(final ParentComposite parentComposite) { + parentComposites.add(parentComposite); + } + + @Override + public void onRemovedFromComposite(final ParentComposite parentComposite) { + parentComposites.remove(parentComposite); + } + + @Override + public boolean contains(final Storage storage) { + return storage == delegate || (delegate != null && delegate.contains(storage)); + } + + @Override + public Amount compositeInsert(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + if (delegate == null + || accessMode == AccessMode.EXTRACT + || delegate.contains(delegate) + || !filter.isAllowed(resource)) { + return Amount.ZERO; + } + final long inserted = delegate.insert(resource, amount, action, actor); + return new Amount(inserted, 0); + } + + @Override + public Amount compositeExtract(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + if (delegate == null + || accessMode == AccessMode.INSERT + || delegate.contains(delegate) + || !filter.isAllowed(resource)) { + return Amount.ZERO; + } + final long extracted = delegate.extract(resource, amount, action, actor); + return new Amount(extracted, 0); + } + + @Override + public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { + throw new UnsupportedOperationException(); + } + + @Override + public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection getAll() { + if (delegate == null || delegate.contains(delegate)) { + return Collections.emptyList(); + } + return delegate.getAll() + .stream() + .filter(resourceAmount -> filter.isAllowed(resourceAmount.getResource())) + .toList(); + } + + @Override + public long getStored() { + if (delegate == null || delegate.contains(delegate)) { + return 0; + } + return delegate.getAll() + .stream() + .filter(resourceAmount -> filter.isAllowed(resourceAmount.getResource())) + .mapToLong(ResourceAmount::getAmount) + .sum(); + } + + @Override + public void onChanged(final ResourceList.OperationResult change) { + if (delegate != null && delegate.contains(delegate)) { + return; + } + final ResourceKey resource = change.resourceAmount().getResource(); + if (!filter.isAllowed(resource)) { + return; + } + if (change.change() > 0) { + parentComposites.forEach(parent -> parent.addToCache(resource, change.change())); + } else { + parentComposites.forEach(parent -> parent.removeFromCache(resource, -change.change())); + } + } + + @Override + public int getPriority() { + return priority; + } +} diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/package-info.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/package-info.java new file mode 100644 index 000000000..9b2bc6065 --- /dev/null +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@FieldsAndMethodsAreNonnullByDefault +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +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/node/security/SecurityDecisionProviderProxyNetworkNode.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/security/SecurityDecisionProviderProxyNetworkNode.java index 1ab5c878d..db3c3b443 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/security/SecurityDecisionProviderProxyNetworkNode.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/node/security/SecurityDecisionProviderProxyNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.security; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.security.Permission; import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; import com.refinedmods.refinedstorage2.api.network.security.SecurityDecision; @@ -50,4 +50,17 @@ public SecurityDecision isAllowed(final Permission permission) { } return delegate.isAllowed(permission); } + + @Override + public boolean isProviderActive() { + return isActive(); + } + + public static SecurityDecisionProviderProxyNetworkNode activeSecurityDecisionProvider( + final SecurityDecisionProvider provider + ) { + final SecurityDecisionProviderProxyNetworkNode node = new SecurityDecisionProviderProxyNetworkNode(0, provider); + node.setActive(true); + return node; + } } 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 1b3eceeb0..a2d7f9918 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 @@ -38,7 +38,7 @@ public void onContainerRemoved(final NetworkNodeContainer container) { @Override public boolean isAllowed(final Permission permission, final SecurityActor actor) { final Set activeProviders = providers.stream() - .filter(SecurityDecisionProvider::isActive) + .filter(SecurityDecisionProvider::isProviderActive) .collect(Collectors.toSet()); if (activeProviders.isEmpty()) { return defaultPolicy.isAllowed(permission); @@ -57,6 +57,16 @@ public boolean isAllowed(final Permission permission, final SecurityActor actor) return tryFallback(permission, activeProviders); } + @Override + public boolean contains(final SecurityNetworkComponent component) { + for (final SecurityDecisionProvider provider : providers) { + if (provider.contains(component)) { + return true; + } + } + return false; + } + private boolean tryFallback(final Permission permission, final Set activeProviders) { final Set decisions = activeProviders.stream().map(provider -> CoreValidations.validateNotNull(provider.isAllowed(permission), "Decision cannot be null") 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 695e0a26f..c2cad2cd6 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,5 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl.storage; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.resource.filter.Filter; diff --git a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImpl.java b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImpl.java index 6e25cc557..3fbe66dc0 100644 --- a/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImpl.java +++ b/refinedstorage2-network/src/main/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImpl.java @@ -46,4 +46,9 @@ public List getResources(final Class act findTrackedResourceByActorType(resourceAmount.getResource(), actorType).orElse(null) )).toList(); } + + @Override + public boolean contains(final Storage storage) { + return this.storage.contains(storage); + } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java index b6fb80561..b5b5bea44 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/PriorityNetworkBuilderImplTest.java @@ -11,7 +11,7 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.function.Supplier; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java index 8d43fe645..8d9ab159a 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/SpyingNetworkNode.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.api.network.impl; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; public final class SpyingNetworkNode extends AbstractNetworkNode { private final long energyUsage; diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java index 936654442..d22d2903b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/detector/DetectorNetworkNodeTest.java @@ -1,11 +1,11 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.detector; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; @@ -19,7 +19,7 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -33,8 +33,8 @@ class DetectorNetworkNodeTest { DetectorNetworkNode sut; @BeforeEach - void setUp(@InjectNetworkStorageChannel final StorageChannel storageChannel) { - storageChannel.addSource(new InMemoryStorageImpl()); + void setUp(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { + storage.addSource(new InMemoryStorageImpl()); sut.setAmountStrategy(new DetectorAmountStrategyImpl()); } @@ -118,14 +118,14 @@ void testModes(final DetectorMode mode, final long comparisonAmount, final long amountInNetwork, final boolean expectedActivated, - @InjectNetworkStorageChannel final StorageChannel storageChannel) { + @InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setConfiguredResource(A); sut.setMode(mode); sut.setAmount(comparisonAmount); if (amountInNetwork > 0) { - storageChannel.insert(A, amountInNetwork, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A, amountInNetwork, Action.EXECUTE, EmptyActor.INSTANCE); } // Act 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 e36a0c7f9..da0d68d44 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 @@ -4,6 +4,7 @@ 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.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.api.storage.Actor; @@ -11,11 +12,10 @@ import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.InsertableStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -24,9 +24,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -55,12 +55,12 @@ void testInitialState() { @Test void shouldUseFirstSuccessfulStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage failingDestination = new LimitedStorageImpl(0); final Storage destination = new LimitedStorageImpl(100); @@ -76,7 +76,7 @@ void shouldUseFirstSuccessfulStrategy( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 100) ); @@ -87,12 +87,12 @@ void shouldUseFirstSuccessfulStrategy( @Test void shouldUseFirstSuccessfulResourceInTheStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new LimitedStorageImpl(100) { @Override @@ -113,7 +113,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 100) ); @@ -142,12 +142,12 @@ void shouldNotTransferWithoutNetwork() { @Test void shouldNotTransferWithoutTaskExecutor( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); @@ -159,7 +159,7 @@ void shouldNotTransferWithoutTaskExecutor( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -167,11 +167,11 @@ void shouldNotTransferWithoutTaskExecutor( } @Test - void shouldNotTransferWithoutStrategy(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldNotTransferWithoutStrategy(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); @@ -181,7 +181,7 @@ void shouldNotTransferWithoutStrategy(@InjectNetworkStorageChannel final Storage sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -189,11 +189,11 @@ void shouldNotTransferWithoutStrategy(@InjectNetworkStorageChannel final Storage } @Test - void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldNotTransferIfInactive(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); @@ -206,7 +206,7 @@ void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -214,11 +214,11 @@ void shouldNotTransferIfInactive(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldNotTransferWithoutFilters(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldNotTransferWithoutFilters(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); @@ -230,7 +230,7 @@ void shouldNotTransferWithoutFilters(@InjectNetworkStorageChannel final StorageC sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -239,7 +239,7 @@ void shouldNotTransferWithoutFilters(@InjectNetworkStorageChannel final StorageC @Test void shouldNotTransferIfNoResourcesAreAvailable( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange final Storage destination = new InMemoryStorageImpl(); @@ -254,19 +254,19 @@ void shouldNotTransferIfNoResourcesAreAvailable( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).isEmpty(); } @Test void shouldTransferWithLimitedSpaceInDestination( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new LimitedStorageImpl(5); destination.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); @@ -280,7 +280,7 @@ void shouldTransferWithLimitedSpaceInDestination( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 96), new ResourceAmount(B, 100), new ResourceAmount(C, 100) @@ -292,7 +292,7 @@ void shouldTransferWithLimitedSpaceInDestination( sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 96), new ResourceAmount(B, 100), new ResourceAmount(C, 100) @@ -305,12 +305,12 @@ void shouldTransferWithLimitedSpaceInDestination( @Test void shouldNotTransferIfThereIsNoSpaceInTheDestination( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new LimitedStorageImpl(1); destination.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); @@ -324,7 +324,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheDestination( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) ); @@ -335,12 +335,12 @@ void shouldNotTransferIfThereIsNoSpaceInTheDestination( @Test void shouldTransferSingleResourceEvenIfTransferQuotaHasNotBeenMet( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 6, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 6, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -352,7 +352,7 @@ void shouldTransferSingleResourceEvenIfTransferQuotaHasNotBeenMet( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 7) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java index 4f94d158f..b993f78d3 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/FirstAvailableExporterNetworkNodeTest.java @@ -5,24 +5,24 @@ import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; +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.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import java.util.List; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static org.assertj.core.api.Assertions.assertThat; class FirstAvailableExporterNetworkNodeTest extends AbstractExporterNetworkNodeTest { @@ -32,11 +32,11 @@ protected TaskExecutor createTaskExecutor() { } @Test - void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 1L)); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 1L)); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 1); @@ -48,27 +48,27 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 99), new ResourceAmount(B, 100) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); - assertThat(storageChannel.findTrackedResourceByActorType(A, NetworkNodeActor.class)) + assertThat(storage.findTrackedResourceByActorType(A, NetworkNodeActor.class)) .get() .usingRecursiveComparison() .isEqualTo(new TrackedResource(ExporterNetworkNode.class.getName(), 1)); - assertThat(storageChannel.findTrackedResourceByActorType(B, NetworkNodeActor.class)).isEmpty(); + assertThat(storage.findTrackedResourceByActorType(B, NetworkNodeActor.class)).isEmpty(); } @Test void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -80,7 +80,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 7) ); @@ -88,13 +88,13 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( @Test void shouldUseNextResourceIfFirstOneIsNotAcceptedInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(C, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(C, 10, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl() { @Override @@ -113,7 +113,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10), new ResourceAmount(C, 10) ); @@ -123,7 +123,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -133,7 +133,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 10) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java index fe2e90ddc..8c78adcb9 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RandomExporterNetworkNodeTest.java @@ -4,19 +4,19 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.task.RandomTaskExecutor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import java.util.List; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; class RandomExporterNetworkNodeTest extends AbstractExporterNetworkNodeTest { @@ -30,11 +30,11 @@ protected TaskExecutor createTaskExecutor() { } @Test - void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); @@ -45,7 +45,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 100) ); @@ -55,7 +55,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 100) ); @@ -66,11 +66,11 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha @Test void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(B, 7, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -81,14 +81,14 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 7) ); sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 7) ); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java index 278f6c6b3..d09f2cc24 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/exporter/RoundRobinExporterNetworkNodeTest.java @@ -4,22 +4,22 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.task.RoundRobinTaskExecutor; import com.refinedmods.refinedstorage2.api.network.node.exporter.ExporterTransferStrategy; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; -import static com.refinedmods.refinedstorage2.network.test.TestResource.D; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.D; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -41,11 +41,11 @@ protected TaskExecutor createTaskExecutor() { } @Test - void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); @@ -56,7 +56,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 100) ); @@ -68,7 +68,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 95) ); @@ -81,7 +81,7 @@ void shouldTransfer(@InjectNetworkStorageChannel final StorageChannel storageCha sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 95) ); @@ -109,12 +109,12 @@ void shouldNotTransferIfThereAreNoResourcesInSource() { @Test void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(D, 9, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(D, 9, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 10); @@ -125,7 +125,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(D, 9) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( @@ -134,7 +134,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(C, 8), new ResourceAmount(D, 9) @@ -142,18 +142,18 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(C, 8), new ResourceAmount(D, 9) ); - storageChannel.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 2) ); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -164,7 +164,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 1), new ResourceAmount(B, 2), @@ -174,7 +174,7 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( sut.doWork(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(destination.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 1), new ResourceAmount(B, 2), @@ -185,13 +185,13 @@ void shouldUseNextResourceIfFirstOneIsNotAvailableInSameCycle( @Test void shouldResetRoundRobinStateAfterChangingFilters( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); final Storage destination = new InMemoryStorageImpl(); final ExporterTransferStrategy strategy = createTransferStrategy(destination, 5); @@ -202,7 +202,7 @@ void shouldResetRoundRobinStateAfterChangingFilters( // Act & assert sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 100), new ResourceAmount(C, 100) @@ -213,7 +213,7 @@ void shouldResetRoundRobinStateAfterChangingFilters( sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 95), new ResourceAmount(B, 95), new ResourceAmount(C, 100) @@ -227,7 +227,7 @@ void shouldResetRoundRobinStateAfterChangingFilters( sut.setFilters(List.of(A, C)); sut.doWork(); - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 90), new ResourceAmount(B, 95), new ResourceAmount(C, 100) diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java index bc6bff232..218848016 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java @@ -2,23 +2,23 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageProvider; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.Optional; import java.util.Set; @@ -30,9 +30,9 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ class ExternalStorageNetworkNodeTest { ExternalStorageNetworkNode sut; @Test - void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void testInitialState(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Act final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); final long extracted = networkStorage.extract(A, 10, Action.EXECUTE, FakeActor.INSTANCE); @@ -66,7 +66,7 @@ void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkS } @Test - void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInitialize(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -81,7 +81,7 @@ void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkS @Test void shouldBeAbleToInitializeMultipleTimes( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage1 = new InMemoryStorageImpl(); @@ -111,7 +111,7 @@ void shouldBeAbleToInitializeMultipleTimes( } @Test - void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInsert(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -132,7 +132,7 @@ void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStora } @Test - void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldExtract(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); @@ -154,7 +154,8 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor } @Test - void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectAllowlistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A, B)); @@ -176,7 +177,7 @@ void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -198,7 +199,8 @@ void shouldRespectEmptyAllowlistWhenInserting( } @Test - void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectBlocklistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A, B)); @@ -220,7 +222,7 @@ void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of()); @@ -243,7 +245,8 @@ void shouldRespectEmptyBlocklistWhenInserting( @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -265,7 +268,8 @@ void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -287,7 +291,7 @@ void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, } @Test - void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotInsertWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -303,7 +307,7 @@ void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotExtractWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new InMemoryStorageImpl(); storage.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); @@ -321,7 +325,7 @@ void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChan @Test void shouldHideStorageContentsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -340,7 +344,8 @@ void shouldHideStorageContentsWhenInactive( } @Test - void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldShowStorageContentsWhenActive( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -363,7 +368,7 @@ void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final Stor @Test void shouldNoLongerShowOnNetworkWhenRemoved( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -384,8 +389,8 @@ void shouldNoLongerShowOnNetworkWhenRemoved( @Test void shouldNotifyNewNetworkAboutChangesWhenChangingNetworks( - @InjectNetworkStorageChannel final StorageChannel networkStorage, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherNetworkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherNetworkStorage, @InjectNetwork final Network network, @InjectNetwork("other") final Network otherNetwork ) { @@ -415,8 +420,8 @@ void shouldNotifyNewNetworkAboutChangesWhenChangingNetworks( @Test void shouldNoLongerNotifyOldNetworkAboutChangesWhenChangingNetworks( - @InjectNetworkStorageChannel final StorageChannel networkStorage, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherNetworkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherNetworkStorage, @InjectNetwork final Network network, @InjectNetwork("other") final Network otherNetwork ) { @@ -450,7 +455,7 @@ void shouldNoLongerNotifyOldNetworkAboutChangesWhenChangingNetworks( @Test void shouldNoLongerShowOnNetworkWhenRemovedWithoutInitializedStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Act @@ -465,7 +470,7 @@ void shouldNoLongerShowOnNetworkWhenRemovedWithoutInitializedStorage( @EnumSource(Action.class) void shouldTrackChangesWhenExtracting( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -502,7 +507,7 @@ void shouldTrackChangesWhenExtracting( @EnumSource(Action.class) void shouldNotTrackChangesWhenExtractionFailed( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -525,7 +530,7 @@ void shouldNotTrackChangesWhenExtractionFailed( @EnumSource(Action.class) void shouldTrackChangesWhenInserting( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -561,7 +566,7 @@ void shouldTrackChangesWhenInserting( @EnumSource(Action.class) void shouldNotTrackChangesWhenInsertionFailed( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(0); @@ -581,7 +586,7 @@ void shouldNotTrackChangesWhenInsertionFailed( } private AtomicBoolean trackWhetherResourceHasChangedAndTrackedResourceIsAvailable( - final StorageChannel networkStorage + final StorageNetworkComponent networkStorage ) { final AtomicBoolean found = new AtomicBoolean(); networkStorage.addListener(change -> { @@ -602,7 +607,7 @@ void shouldNotDetectChangesWithoutConnectedStorage() { } @Test - void shouldDetectChanges(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectChanges(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); final ExternalStorageProvider provider = new StorageExternalStorageProvider(storage); @@ -631,7 +636,7 @@ class PriorityTest { @ParameterizedTest @ValueSource(booleans = {true, false}) void shouldRespectPriority(final boolean oneHasPriority, - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage1 = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L); final ExternalStorageProvider provider1 = new StorageExternalStorageProvider(storage1); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java index c90aa1436..5d28eab96 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/grid/GridNetworkNodeTest.java @@ -3,30 +3,30 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcher; import com.refinedmods.refinedstorage2.api.network.Network; +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.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; -import static com.refinedmods.refinedstorage2.network.test.TestResource.D; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.D; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyLong; @@ -48,14 +48,14 @@ class GridNetworkNodeTest { @BeforeEach void setUp( - @InjectNetworkStorageChannel final StorageChannel storage, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherStorageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherStorage ) { storage.addSource(new TrackedStorageImpl(new LimitedStorageImpl(1000), () -> 2L)); storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); storage.insert(B, 200, Action.EXECUTE, EmptyActor.INSTANCE); - otherStorageChannel.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 3L)); + otherStorage.addSource(new TrackedStorageImpl(new InMemoryStorageImpl(), () -> 3L)); } @Test @@ -85,7 +85,7 @@ void shouldNotifyWatchersOfActivenessChanges() { @Test void shouldNotifyWatchersOfStorageChanges( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final GridWatcher watcher = mock(GridWatcher.class); @@ -141,8 +141,8 @@ void shouldNotBeAbleToAddDuplicateWatcher() { void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( @InjectNetwork("other") final Network otherNetwork, @InjectNetwork final Network network, - @InjectNetworkStorageChannel final StorageChannel storageChannel, - @InjectNetworkStorageChannel(networkId = "other") final StorageChannel otherStorageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage, + @InjectNetworkStorageComponent(networkId = "other") final StorageNetworkComponent otherStorage ) { // Arrange final GridWatcher watcher = mock(GridWatcher.class); @@ -150,19 +150,19 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork( // Act // This one shouldn't be ignored! - otherStorageChannel.insert(C, 10, Action.EXECUTE, FakeActor.INSTANCE); + otherStorage.insert(C, 10, Action.EXECUTE, FakeActor.INSTANCE); sut.setNetwork(otherNetwork); network.removeContainer(() -> sut); otherNetwork.addContainer(() -> sut); // these one shouldn't be ignored either - otherStorageChannel.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); - otherStorageChannel.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); + otherStorage.insert(A, 10, Action.EXECUTE, FakeActor.INSTANCE); + otherStorage.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); // these should be ignored - storageChannel.insert(B, 10, Action.EXECUTE, FakeActor.INSTANCE); - storageChannel.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 10, Action.EXECUTE, FakeActor.INSTANCE); + storage.insert(D, 10, Action.EXECUTE, EmptyActor.INSTANCE); // Assert verify(watcher, times(1)).invalidate(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java index 673d43a55..27a2b136a 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ClearSlotInterfaceNetworkNodeTest.java @@ -1,19 +1,19 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -34,10 +34,10 @@ void setUp() { @Test void shouldClearSlotWhenNoLongerRequestingAnything( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); exportState.setCurrentlyExported(1, A, 7); exportState.setCurrentlyExported(2, B, 2); @@ -48,7 +48,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(5); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 2), @@ -60,7 +60,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 4), @@ -72,7 +72,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 6), @@ -83,7 +83,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 7), @@ -96,7 +96,7 @@ void shouldClearSlotWhenNoLongerRequestingAnything( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 7), @@ -106,10 +106,10 @@ void shouldClearSlotWhenNoLongerRequestingAnything( @Test void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHaveEnoughSpace( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(3)); + storage.addSource(new LimitedStorageImpl(3)); exportState.setCurrentlyExported(1, A, 7); @@ -119,7 +119,7 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(5); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 2)); @@ -128,7 +128,7 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -139,14 +139,14 @@ void shouldClearSlotPartiallyWhenNoLongerRequestingAnythingButNetworkDoesNotHave assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldNotClearSlotWhenNoLongerRequestingAnythingAndNetworkDoesNotHaveEnoughSpace( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(1, A, 7); @@ -160,6 +160,6 @@ void shouldNotClearSlotWhenNoLongerRequestingAnythingAndNetworkDoesNotHaveEnough assertThat(exportState.getExportedAmount(1)).isEqualTo(7); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java index 7a41bd42b..a54ed32c7 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/ExportToEmptySlotInterfaceNetworkNodeTest.java @@ -1,22 +1,22 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -37,7 +37,7 @@ void setUp() { @Test void shouldNotExportToEmptySlotWhenRequestedIsNotAvailable( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setRequestedResource(1, A, 1); @@ -50,16 +50,16 @@ void shouldNotExportToEmptySlotWhenRequestedIsNotAvailable( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldExportToEmptySlotWhenRequestedIsNotEntirelyAvailable( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -74,16 +74,16 @@ void shouldExportToEmptySlotWhenRequestedIsNotEntirelyAvailable( assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldExportToEmptySlotWhenRequestedIsLessThanTransferQuota( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -96,19 +96,19 @@ void shouldExportToEmptySlotWhenRequestedIsLessThanTransferQuota( assertThat(exportState.getExportedAmount(1)).isEqualTo(1); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 9)); } @Test void shouldExportToEmptySlot( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 7); exportState.setRequestedResource(2, B, 2); @@ -123,7 +123,7 @@ void shouldExportToEmptySlot( assertThat(exportState.getExportedResource(2)).isEqualTo(B); assertThat(exportState.getExportedAmount(2)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 8), @@ -133,12 +133,12 @@ void shouldExportToEmptySlot( @Test void shouldExportResourceFuzzilyToEmptySlot( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -151,7 +151,7 @@ void shouldExportResourceFuzzilyToEmptySlot( assertThat(exportState.getExportedAmount(1)).isEqualTo(2); assertThat(exportState.getExportedResource(2)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 8), diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java index df0b48887..ed4e50d7c 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/InterfaceExportStateImpl.java @@ -13,9 +13,9 @@ import java.util.Map; import javax.annotation.Nullable; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; public class InterfaceExportStateImpl implements InterfaceExportState { private final Map requested = new HashMap<>(); 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 7365d7687..3ce965776 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 @@ -2,20 +2,20 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -46,12 +46,12 @@ void shouldExtractEnergy( @Test void shouldExportAllWithDefaultTransferQuota( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, Long.MAX_VALUE, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, Long.MAX_VALUE, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, Long.MAX_VALUE); @@ -62,18 +62,18 @@ void shouldExportAllWithDefaultTransferQuota( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(Long.MAX_VALUE); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(energy.getStored()).isEqualTo(1000 - 5); } @Test void shouldNotExportAnythingWithoutBeingActive( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -86,7 +86,7 @@ void shouldNotExportAnythingWithoutBeingActive( // Assert assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 10)); assertThat(energy.getStored()).isEqualTo(1000); @@ -94,12 +94,12 @@ void shouldNotExportAnythingWithoutBeingActive( @Test void shouldNotExportAnythingWithoutNetwork( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -112,7 +112,7 @@ void shouldNotExportAnythingWithoutNetwork( // Assert assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 10)); assertThat(energy.getStored()).isEqualTo(1000); @@ -120,12 +120,12 @@ void shouldNotExportAnythingWithoutNetwork( @Test void shouldNotExportAnythingWithoutExportState( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); sut.setExportState(null); sut.setTransferQuotaProvider(resource -> 2); @@ -136,7 +136,7 @@ void shouldNotExportAnythingWithoutExportState( // Assert assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 10)); assertThat(energy.getStored()).isEqualTo(1000 - 5); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java index 78d1d5ace..14886930f 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/KeepExportingInterfaceNetworkNodeTest.java @@ -1,23 +1,23 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.iface; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -38,11 +38,11 @@ void setUp() { @Test void shouldKeepExportingResourceUntilWantedAmountIsReached( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 7); @@ -51,7 +51,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 8)); @@ -59,7 +59,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 6)); @@ -67,7 +67,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(6); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 4)); @@ -75,7 +75,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -85,18 +85,18 @@ void shouldKeepExportingResourceUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughResources( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -105,7 +105,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 5)); @@ -113,7 +113,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -121,7 +121,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(6); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 1)); @@ -129,7 +129,7 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); sut.doWork(); sut.doWork(); @@ -137,17 +137,17 @@ void shouldKeepExportingResourceUntilWantedAmountIsReachedAndNetworkHasEnoughRes assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); - storageChannel.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A_ALTERNATIVE, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.insert(A_ALTERNATIVE2, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 10); @@ -156,7 +156,7 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 8), @@ -167,7 +167,7 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(4); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 6), @@ -177,11 +177,11 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReached( @Test void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReachedEvenIfTheResourceIsNoLongerAvailableInTheNetwork( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(A_ALTERNATIVE, 1, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A_ALTERNATIVE, 1, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, A, 1); @@ -190,21 +190,21 @@ void shouldKeepExportingResourceFuzzilyUntilWantedAmountIsReachedEvenIfTheResour assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A_ALTERNATIVE); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @Test void shouldReturnResourceToNetworkUntilWantedAmountIsReached( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); exportState.setRequestedResource(1, A, 7); exportState.setCurrentlyExported(1, A, 10); @@ -214,7 +214,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(8); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 2)); @@ -222,7 +222,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -232,17 +232,17 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReached( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(3)); + storage.addSource(new LimitedStorageImpl(3)); exportState.setRequestedResource(1, A, 5); exportState.setCurrentlyExported(1, A, 10); @@ -252,7 +252,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(8); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 2)); @@ -260,7 +260,7 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); @@ -270,18 +270,18 @@ void shouldReturnResourceToNetworkUntilWantedAmountIsReachedAndNetworkIsFull( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(7); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactly(new ResourceAmount(A, 3)); } @Test void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new InMemoryStorageImpl()); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, B, 3); exportState.setCurrentlyExported(1, A, 3); @@ -291,7 +291,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(1); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 2), @@ -301,7 +301,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( sut.doWork(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isNull(); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -312,7 +312,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -323,7 +323,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -336,7 +336,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(B); assertThat(exportState.getExportedAmount(1)).isEqualTo(3); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 3), @@ -346,11 +346,11 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecified( @Test void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkIsFull( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(11)); - storageChannel.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new LimitedStorageImpl(11)); + storage.insert(B, 10, Action.EXECUTE, EmptyActor.INSTANCE); exportState.setRequestedResource(1, B, 3); exportState.setCurrentlyExported(1, A, 3); @@ -360,7 +360,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkI assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 1), @@ -373,7 +373,7 @@ void shouldReturnResourceToNetworkAndExportOtherResourceIfSpecifiedUntilNetworkI assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(2); - assertThat(storageChannel.getAll()) + assertThat(storage.getAll()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder( new ResourceAmount(A, 1), diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java index 3c4425d8e..efe2a893b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/InterfaceExternalStorageProviderImplTest.java @@ -5,11 +5,11 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageProviderFactoryImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportStateImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -18,8 +18,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -42,7 +42,7 @@ void setUp() { @Test void shouldExposeExportedResources( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 100); @@ -56,14 +56,14 @@ void shouldExposeExportedResources( externalStorage.detectChanges(); // Assert - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 101) ); } @Test void shouldNotExposeExportedResourceWithoutExportState( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -74,14 +74,14 @@ void shouldNotExposeExportedResourceWithoutExportState( externalStorage.detectChanges(); // Assert - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @ParameterizedTest @EnumSource(Action.class) void shouldInsertIntoInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -89,18 +89,18 @@ void shouldInsertIntoInterface( ))); // Act - final long inserted = networkStorage.insert(A, 10, action, EmptyActor.INSTANCE); + final long inserted = storage.insert(A, 10, action, EmptyActor.INSTANCE); // Assert assertThat(inserted).isEqualTo(10); if (action == Action.EXECUTE) { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); assertThat(exportState.getExportedAmount(0)).isEqualTo(10); } else { - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedAmount(0)).isZero(); } @@ -110,7 +110,7 @@ void shouldInsertIntoInterface( @EnumSource(Action.class) void shouldNotInsertResourceWithoutExportState( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -119,18 +119,18 @@ void shouldNotInsertResourceWithoutExportState( externalStorage.detectChanges(); // Act - final long inserted = networkStorage.insert(A, 101, action, EmptyActor.INSTANCE); + final long inserted = storage.insert(A, 101, action, EmptyActor.INSTANCE); // Assert assertThat(inserted).isZero(); - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } @ParameterizedTest @EnumSource(Action.class) void shouldExtractEntireResourceFromInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 50); @@ -141,18 +141,18 @@ void shouldExtractEntireResourceFromInterface( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(A, 101, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(A, 101, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isEqualTo(100); if (action == Action.EXECUTE) { - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(exportState.getExportedResource(0)).isNull(); assertThat(exportState.getExportedAmount(0)).isZero(); assertThat(exportState.getExportedResource(1)).isNull(); assertThat(exportState.getExportedAmount(1)).isZero(); } else { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 100) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); @@ -166,7 +166,7 @@ void shouldExtractEntireResourceFromInterface( @EnumSource(Action.class) void shouldExtractPartialResourceFromInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 50); @@ -177,12 +177,12 @@ void shouldExtractPartialResourceFromInterface( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(A, 51, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(A, 51, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isEqualTo(51); if (action == Action.EXECUTE) { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 49) ); assertThat(exportState.getExportedResource(0)).isNull(); @@ -190,7 +190,7 @@ void shouldExtractPartialResourceFromInterface( assertThat(exportState.getExportedResource(1)).isEqualTo(A); assertThat(exportState.getExportedAmount(1)).isEqualTo(49); } else { - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 100) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); @@ -204,7 +204,7 @@ void shouldExtractPartialResourceFromInterface( @EnumSource(Action.class) void shouldNotExtractNonExistentResourceFromInterface( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange exportState.setCurrentlyExported(0, A, 50); @@ -214,11 +214,11 @@ void shouldNotExtractNonExistentResourceFromInterface( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(B, 1, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(B, 1, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isZero(); - assertThat(networkStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 50) ); assertThat(exportState.getExportedResource(0)).isEqualTo(A); @@ -229,7 +229,7 @@ void shouldNotExtractNonExistentResourceFromInterface( @EnumSource(Action.class) void shouldNotExtractResourceWithoutExportState( final Action action, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange externalStorage.initialize(new ExternalStorageProviderFactoryImpl(new InterfaceExternalStorageProviderImpl( @@ -238,10 +238,10 @@ void shouldNotExtractResourceWithoutExportState( externalStorage.detectChanges(); // Act - final long extracted = networkStorage.extract(A, 101, action, EmptyActor.INSTANCE); + final long extracted = storage.extract(A, 101, action, EmptyActor.INSTANCE); // Assert assertThat(extracted).isZero(); - assertThat(networkStorage.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java index ace9aaf46..10fca42e2 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/IoLoopInterfaceExternalStorageProviderImplTest.java @@ -7,21 +7,21 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.StorageExternalStorageProvider; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportStateImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -54,7 +54,7 @@ class IoLoopInterfaceExternalStorageProviderImplTest { ExternalStorageNetworkNode externalStorageWithNonInterfaceConnection; @BeforeEach - void setUp(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void setUp(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { interfaceWithExternalStorageState = new InterfaceExportStateImpl(2); interfaceWithExternalStorageState.setRequestedResource(1, A, 10); interfaceWithExternalStorage.setExportState(interfaceWithExternalStorageState); @@ -92,7 +92,7 @@ void setUp(@InjectNetworkStorageChannel final StorageChannel networkStorage) { // and would double count them because the External Storage update is later. @Test void shouldNotAllowInsertionByAnotherInterfaceIfThatInterfaceIsActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -121,7 +121,7 @@ void shouldNotAllowInsertionByAnotherInterfaceIfThatInterfaceIsActingAsExternalS @Test void shouldAllowInsertionByAnotherInterfaceIfThatInterfaceIsNotActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -155,7 +155,7 @@ void shouldAllowInsertionByAnotherInterfaceIfThatInterfaceIsNotActingAsExternalS // isn't allowed as it would create an extraction loop causing the Interfaces to constantly steal from each other. @Test void shouldNotAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Act & assert interfaceWithExternalStorage.doWork(); @@ -193,7 +193,7 @@ void shouldNotAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsActingA @Test void shouldAllowExtractionRequestedByAnotherInterfaceIfThatInterfaceIsNotActingAsExternalStorage( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Act & assert interfaceWithExternalStorage.doWork(); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java index 1c73869e7..12e5d5f7e 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/iface/externalstorage/SelfIoInterfaceExternalStorageProviderImplTest.java @@ -4,17 +4,17 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageProviderFactoryImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceExportStateImpl; import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -38,7 +38,7 @@ void setUp() { // IoLoopInterfaceExternalStorageProviderImplTest. @Test void shouldNotAllowSelfInsertionOrSelfExtraction( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange // this would try to do a self-insert as it's an unwanted resource. 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 03e491b57..d01189c90 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/importer/ImporterNetworkNodeTest.java @@ -3,17 +3,17 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage2.api.network.node.importer.ImporterTransferStrategy; +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.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -23,11 +23,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -65,14 +65,14 @@ void shouldExtractEnergy( @Test void shouldNotWorkWithoutAnyTransferStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Act sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(energy.getStored()).isEqualTo(1000 - 5); } @@ -85,11 +85,11 @@ void shouldNotWorkWithoutNetwork() { @Test void shouldNotWorkOrExtractEnergyWithoutBeingActive( - @InjectNetworkStorageChannel final StorageChannel storageChannel, + @InjectNetworkStorageComponent final StorageNetworkComponent storage, @InjectNetworkEnergyComponent final EnergyNetworkComponent energy ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 100) @@ -102,7 +102,7 @@ void shouldNotWorkOrExtractEnergyWithoutBeingActive( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A, 100), new ResourceAmount(B, 100) @@ -111,9 +111,9 @@ void shouldNotWorkOrExtractEnergyWithoutBeingActive( } @Test - void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void testTransfer(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B, A) .add(A, 100) @@ -125,7 +125,7 @@ void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -136,10 +136,10 @@ void testTransfer(@InjectNetworkStorageChannel final StorageChannel storageChann @Test void shouldUseFirstSuccessfulTransferStrategy( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource emptySource = new FakeImporterSource(); final FakeImporterSource outdatedSource = new FakeImporterSource(C) @@ -161,7 +161,7 @@ void shouldUseFirstSuccessfulTransferStrategy( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -172,11 +172,11 @@ void shouldUseFirstSuccessfulTransferStrategy( @Test void shouldNotTransferIfThereIsNoSpaceInTheNetwork( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new LimitedStorageImpl(100)); - storageChannel.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); + storage.addSource(new LimitedStorageImpl(100)); + storage.insert(C, 100, Action.EXECUTE, EmptyActor.INSTANCE); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 100) @@ -188,7 +188,7 @@ void shouldNotTransferIfThereIsNoSpaceInTheNetwork( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(C, 100) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -199,10 +199,10 @@ void shouldNotTransferIfThereIsNoSpaceInTheNetwork( @Test void testTransferDifferentResourceOverMultipleSlots( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B, A, B) .add(A, 11) @@ -214,7 +214,7 @@ void testTransferDifferentResourceOverMultipleSlots( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -225,10 +225,10 @@ void testTransferDifferentResourceOverMultipleSlots( @Test void testTransferSameResourceOverMultipleSlots( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, A, A, B) .add(A, 20) @@ -241,7 +241,7 @@ void testTransferSameResourceOverMultipleSlots( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -252,10 +252,10 @@ void testTransferSameResourceOverMultipleSlots( @Test void testTransferWhereResourceIsNotAccepted( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl() { + storage.addSource(new InMemoryStorageImpl() { @Override public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { if (A.equals(resource)) { @@ -275,7 +275,7 @@ public long insert(final ResourceKey resource, final long amount, final Action a sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 10) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -286,10 +286,10 @@ public long insert(final ResourceKey resource, final long amount, final Action a @Test void testTransferWithoutAnyResourcesInSource( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(); final ImporterTransferStrategy strategy = new ImporterTransferStrategyImpl(source, 10); @@ -299,17 +299,17 @@ void testTransferWithoutAnyResourcesInSource( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); assertThat(source.getAll()).isEmpty(); } @Test - void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectAllowlist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B, A) .add(B, 10) @@ -322,7 +322,7 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel st sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -333,7 +333,7 @@ void shouldRespectAllowlist(@InjectNetworkStorageChannel final StorageChannel st @Test void shouldRespectAllowlistWithNormalizer( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -345,7 +345,7 @@ void shouldRespectAllowlistWithNormalizer( return resource; }); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B, A_ALTERNATIVE, A_ALTERNATIVE2) .add(B, 10) @@ -360,7 +360,7 @@ void shouldRespectAllowlistWithNormalizer( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(A_ALTERNATIVE, 1), new ResourceAmount(A_ALTERNATIVE2, 1) ); @@ -371,13 +371,13 @@ void shouldRespectAllowlistWithNormalizer( @Test void shouldRespectAllowlistWithoutAlternative( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B) .add(B, 10); @@ -389,19 +389,19 @@ void shouldRespectAllowlistWithoutAlternative( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 10) ); } @Test - void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectEmptyAllowlist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of()); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(B, A) .add(B, 10) @@ -414,7 +414,7 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( new ResourceAmount(B, 10), new ResourceAmount(A, 10) @@ -422,12 +422,12 @@ void shouldRespectEmptyAllowlist(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectBlocklist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 10) @@ -440,7 +440,7 @@ void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel st sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(B, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( @@ -451,13 +451,13 @@ void shouldRespectBlocklist(@InjectNetworkStorageChannel final StorageChannel st @Test void shouldRespectBlocklistWithoutAlternative( - @InjectNetworkStorageChannel final StorageChannel storageChannel + @InjectNetworkStorageComponent final StorageNetworkComponent storage ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A)); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A) .add(A, 10); @@ -469,19 +469,19 @@ void shouldRespectBlocklistWithoutAlternative( sut.doWork(); // Assert - assertThat(storageChannel.getAll()).isEmpty(); + assertThat(storage.getAll()).isEmpty(); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); } @Test - void shouldRespectEmptyBlocklist(@InjectNetworkStorageChannel final StorageChannel storageChannel) { + void shouldRespectEmptyBlocklist(@InjectNetworkStorageComponent final StorageNetworkComponent storage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of()); - storageChannel.addSource(new InMemoryStorageImpl()); + storage.addSource(new InMemoryStorageImpl()); final FakeImporterSource source = new FakeImporterSource(A, B) .add(A, 10) @@ -494,7 +494,7 @@ void shouldRespectEmptyBlocklist(@InjectNetworkStorageChannel final StorageChann sut.doWork(); // Assert - assertThat(storageChannel.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + assertThat(storage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 1) ); assertThat(source.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java index 058500dea..3c696ab91 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/MultiStorageNetworkNodeTest.java @@ -2,6 +2,7 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; @@ -10,15 +11,14 @@ import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.StorageState; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; import com.refinedmods.refinedstorage2.network.test.InjectNetwork; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.Collection; import java.util.HashSet; @@ -30,12 +30,12 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A_ALTERNATIVE2; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B_ALTERNATIVE; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE2; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static com.refinedmods.refinedstorage2.network.test.nodefactory.MultiStorageNetworkNodeFactory.PROPERTY_ENERGY_USAGE_PER_STORAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -64,7 +64,7 @@ void setUp() { @Test void shouldInitializeButNotShowResourcesYet( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(10); @@ -82,7 +82,7 @@ void shouldInitializeButNotShowResourcesYet( @Test void shouldInitializeAndShowResourcesAfterEnabling( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -103,7 +103,7 @@ void shouldInitializeAndShowResourcesAfterEnabling( @Test void shouldInitializeMultipleTimes( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage1 = new LimitedStorageImpl(10); @@ -127,7 +127,7 @@ void shouldInitializeMultipleTimes( } @Test - void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void testInitialState(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Assert assertThat(sut.getEnergyUsage()).isEqualTo(BASE_USAGE); assertThat(sut.getFilterMode()).isEqualTo(FilterMode.BLOCK); @@ -176,7 +176,7 @@ void testState(final boolean active) { } @Test - void shouldDetectNewStorage(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectNewStorage(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange initializeAndActivate(); @@ -195,7 +195,7 @@ void shouldDetectNewStorage(@InjectNetworkStorageChannel final StorageChannel ne } @Test - void shouldDetectChangedStorage(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectChangedStorage(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage originalStorage = new LimitedStorageImpl(10); originalStorage.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); @@ -223,7 +223,7 @@ void shouldDetectChangedStorage(@InjectNetworkStorageChannel final StorageChanne } @Test - void shouldDetectRemovedStorage(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldDetectRemovedStorage(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(10); storage.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); @@ -259,7 +259,7 @@ void shouldNotDetectStorageChangeInInvalidIndex() { @Test void shouldNotUpdateNetworkStorageWhenChangingStorageWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -282,7 +282,7 @@ void shouldNotUpdateNetworkStorageWhenChangingStorageWhenInactive( @Test void shouldHaveResourcesFromStoragePresentInNetwork( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -305,7 +305,7 @@ void shouldHaveResourcesFromStoragePresentInNetwork( } @Test - void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInsert(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage1 = new LimitedStorageImpl(100); provider.set(1, storage1); @@ -347,7 +347,7 @@ void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStora } @Test - void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldExtract(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage1 = new LimitedStorageImpl(100); storage1.insert(A, 50, Action.EXECUTE, EmptyActor.INSTANCE); @@ -392,7 +392,7 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor @Test void shouldRespectAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -415,7 +415,7 @@ void shouldRespectAllowlistWhenInserting( @Test void shouldRespectAllowlistWithNormalizerWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -451,7 +451,7 @@ void shouldRespectAllowlistWithNormalizerWhenInserting( @Test void shouldRespectEmptyAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.ALLOW); @@ -474,7 +474,7 @@ void shouldRespectEmptyAllowlistWhenInserting( @Test void shouldRespectBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); @@ -497,7 +497,7 @@ void shouldRespectBlocklistWhenInserting( @Test void shouldRespectEmptyBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setFilterMode(FilterMode.BLOCK); @@ -522,7 +522,7 @@ void shouldRespectEmptyBlocklistWhenInserting( @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenInserting( final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -545,7 +545,7 @@ void shouldRespectAccessModeWhenInserting( @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenExtracting( final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -568,7 +568,7 @@ void shouldRespectAccessModeWhenExtracting( @Test void shouldNotAllowInsertsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -586,7 +586,7 @@ void shouldNotAllowInsertsWhenInactive( @Test void shouldNotAllowExtractsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -605,7 +605,7 @@ void shouldNotAllowExtractsWhenInactive( @Test void shouldHideFromNetworkWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -626,7 +626,7 @@ void shouldHideFromNetworkWhenInactive( @Test void shouldNoLongerShowOnNetworkWhenRemoved( - @InjectNetworkStorageChannel final StorageChannel networkStorage, + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage, @InjectNetwork final Network network ) { // Arrange @@ -658,7 +658,7 @@ void shouldNoLongerShowOnNetworkWhenRemoved( } @Test - void shouldTrackChanges(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldTrackChanges(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L); provider.set(1, storage); @@ -674,7 +674,7 @@ void shouldTrackChanges(@InjectNetworkStorageChannel final StorageChannel networ @Test void shouldNotifyListenerWhenStateChanges( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final StateTrackedStorage.Listener listener = mock(StateTrackedStorage.Listener.class); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java index 506be8cb3..baf6d15f1 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/multistorage/PriorityMultiStorageNetworkNodeTest.java @@ -1,12 +1,12 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; @@ -14,7 +14,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; import static org.assertj.core.api.Assertions.assertThat; @NetworkTest @@ -37,7 +37,7 @@ void setUp() { @ValueSource(booleans = {true, false}) void shouldRespectPriority( final boolean multiStorageAHasPriority, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage1 = new LimitedStorageImpl(100); diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java new file mode 100644 index 000000000..60e88ae80 --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayEnergyNetworkNodeTest.java @@ -0,0 +1,106 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage2.network.test.InjectNetwork; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; +import com.refinedmods.refinedstorage2.network.test.NetworkTest; +import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addSecurityPolicy; +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addStorageSource; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +class RelayEnergyNetworkNodeTest { + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void shouldPassEnergyComponent( + @InjectNetworkEnergyComponent(networkId = "input") final EnergyNetworkComponent inputEnergy, + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + final long originalStored = inputEnergy.getStored(); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.ENERGY)); + final long extracted = output.extract(10); + + // Assert + assertThat(extracted).isEqualTo(10); + assertThat(outputEnergy.getCapacity()).isEqualTo(inputEnergy.getCapacity()); + assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 10); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(input.hasComponentType(RelayComponentType.ENERGY)).isTrue(); + assertThat(input.hasComponentType(RelayComponentType.SECURITY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.STORAGE)).isFalse(); + } + + @Test + @SetupNetwork(id = "cycle_input", energyStored = 1, energyCapacity = 2) + @SetupNetwork(id = "cycle_input_alt", energyStored = 3, energyCapacity = 4) + void shouldDetectEnergyCycles( + @InjectNetwork("cycle_input") final Network inputNetwork, + @InjectNetworkEnergyComponent(networkId = "cycle_input") final EnergyNetworkComponent inputEnergy, + @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, + @InjectNetworkEnergyComponent(networkId = "cycle_input_alt") final EnergyNetworkComponent inputAlternativeEnergy + ) { + // Arrange + final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); + cycleOutput.setEnergyDelegate(inputAlternativeEnergy); + cycleOutput.setNetwork(inputNetwork); + inputNetwork.addContainer(() -> cycleOutput); + + final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); + cycleOutputAlternative.setEnergyDelegate(inputEnergy); + cycleOutputAlternative.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + + // Assert + assertThat(inputEnergy.getStored()).isEqualTo(1); + assertThat(inputAlternativeEnergy.getStored()).isEqualTo(3); + + assertThat(inputEnergy.getCapacity()).isEqualTo(2); + assertThat(inputAlternativeEnergy.getCapacity()).isEqualTo(4); + + assertThat(inputEnergy.extract(10)).isEqualTo(1); + assertThat(inputAlternativeEnergy.extract(10)).isEqualTo(3); + } +} diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayNetworkNodeTest.java new file mode 100644 index 000000000..777be1c1e --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayNetworkNodeTest.java @@ -0,0 +1,405 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.security.SecurityDecisionProviderImpl; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage2.network.test.InjectNetwork; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; +import com.refinedmods.refinedstorage2.network.test.NetworkTest; +import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; + +import java.util.Set; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import static com.refinedmods.refinedstorage2.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode.activeSecurityDecisionProvider; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +class RelayNetworkNodeTest { + private static final long INPUT_ENERGY_USAGE = 5; + private static final long OUTPUT_ENERGY_USAGE = 5; + + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ENERGY_USAGE, longValue = INPUT_ENERGY_USAGE), + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ENERGY_USAGE, longValue = OUTPUT_ENERGY_USAGE) + }, networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void testInitialState() { + assertThat(input.getEnergyUsage()).isEqualTo(INPUT_ENERGY_USAGE); + assertThat(output.getEnergyUsage()).isZero(); + } + + @Test + void shouldNotPassComponentsIfOutputNodeIsNotSet( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + input.setAccessMode(AccessMode.INSERT_EXTRACT); + input.setPriority(5); + input.setFilters(Set.of(A, B, C)); + + // Act + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputEnergy.extract(1)).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); + } + + @Test + void shouldNotPassComponentsIfInactive( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setOutputNode(output); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + // Act + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputEnergy.extract(1)).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); + } + + @Test + void shouldNotPassComponentsIfNoNetworkIsSet( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setNetwork(null); + input.setOutputNode(output); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + // Act + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputEnergy.extract(1)).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); + } + + @Test + void shouldResetComponentsIfBecomingInactive( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + // Act + input.setActive(false); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputEnergy.extract(1)).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); + } + + @Test + void shouldResetComponentsIfNetworkIsRemoved( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + // Act + input.setNetwork(null); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputEnergy.extract(1)).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(output.getEnergyUsage()).isZero(); + } + + @Test + @SetupNetwork(id = "input_alt", energyStored = 123, energyCapacity = 456) + void shouldResetComponentsIfNetworkIsChanged( + @InjectNetwork("input") final Network inputNetwork, + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetwork("input_alt") final Network inputAlternativeNetwork, + @InjectNetworkEnergyComponent(networkId = "input_alt") final EnergyNetworkComponent inputAlternativeEnergy, + @InjectNetworkSecurityComponent(networkId = "input_alt") + final SecurityNetworkComponent inputAlternativeSecurity, + @InjectNetworkStorageComponent(networkId = "input_alt") final StorageNetworkComponent inputAlternativeStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of( + RelayComponentType.ENERGY, + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 5, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.extract(B, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + inputAlternativeStorage.addSource(new InMemoryStorageImpl()); + inputAlternativeStorage.insert(A, 33, Action.EXECUTE, EmptyActor.INSTANCE); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addSecurityPolicy(inputAlternativeSecurity, FakePermissions.OTHER2); + + // Act + inputNetwork.removeContainer(() -> input); + input.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> input); + + final long originalStored = inputAlternativeEnergy.getStored(); + final long extractedEnergy = output.extract(1); + + final long insertedStorage = outputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedStorage = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(extractedEnergy).isEqualTo(1); + assertThat(insertedStorage).isEqualTo(1); + assertThat(extractedStorage).isEqualTo(1); + + assertThat(outputEnergy.getCapacity()).isEqualTo(inputAlternativeEnergy.getCapacity()); + assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 1); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + assertThat(outputStorage.getStored()).isEqualTo(33); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 32), + new ResourceAmount(C, 1) + ); + assertThat(inputAlternativeStorage.getAll()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(new ResourceAmount(A, 32), new ResourceAmount(C, 1)); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(new ResourceAmount(A, 10), new ResourceAmount(B, 2)); + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); + } + + @Test + void shouldResetComponentsWhenComponentTypeIsEnabled( + @InjectNetworkEnergyComponent(networkId = "input") final EnergyNetworkComponent inputEnergy, + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of( + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + // Act + final long originalStored = inputEnergy.getStored(); + input.updateComponentType(RelayComponentType.ENERGY, true); + final long extracted = output.extract(10); + + // Assert + assertThat(outputEnergy.getCapacity()).isEqualTo(inputEnergy.getCapacity()); + assertThat(outputEnergy.getStored()).isEqualTo(originalStored - 10); + assertThat(extracted).isEqualTo(10); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); + } + + @Test + void shouldResetComponentsWhenComponentTypeIsDisabled( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of( + RelayComponentType.SECURITY, + RelayComponentType.STORAGE + )); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + addStorageSource(inputStorage); + + // Act + input.updateComponentType(RelayComponentType.ENERGY, false); + final long extracted = output.extract(10); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(extracted).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(1); + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); + } + + @ParameterizedTest + @EnumSource(RelayComponentType.class) + void shouldUseEnergyWhenAtLeastOneComponentIsActive(final RelayComponentType type) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + // Act + input.setComponentTypes(Set.of(type)); + + // Assert + assertThat(output.getEnergyUsage()).isEqualTo(OUTPUT_ENERGY_USAGE); + } + + static void addSecurityPolicy(final SecurityNetworkComponent security, final FakePermissions permission) { + security.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(permission)) + )); + } + + static void addStorageSource(final StorageNetworkComponent storage) { + storage.addSource(new InMemoryStorageImpl()); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + } +} diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java new file mode 100644 index 000000000..e2b61c35c --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelaySecurityNetworkNodeTest.java @@ -0,0 +1,165 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.impl.security.SecurityDecisionProviderImpl; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage2.network.test.InjectNetwork; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; +import com.refinedmods.refinedstorage2.network.test.NetworkTest; +import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addStorageSource; +import static com.refinedmods.refinedstorage2.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode.activeSecurityDecisionProvider; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +class RelaySecurityNetworkNodeTest { + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void shouldPassSecurityComponent( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( + new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) + .setPolicy(FakeSecurityActors.B, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + addStorageSource(inputStorage); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.SECURITY)); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputEnergy.extract(1)).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isTrue(); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(input.hasComponentType(RelayComponentType.ENERGY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.SECURITY)).isTrue(); + assertThat(input.hasComponentType(RelayComponentType.STORAGE)).isFalse(); + } + + @Test + void shouldNotActAsSecurityDecisionProviderIfOutputIsDisabled( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + input.setComponentTypes(Set.of(RelayComponentType.SECURITY)); + + // Act + output.setActive(false); + + // Assert + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + } + + @Test + void shouldNotActAsSecurityDecisionProviderIfSecurityIsNotPassed( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + // Act + input.setComponentTypes(Set.of()); + + // Assert + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + } + + @Test + @SetupNetwork(id = "cycle_input") + @SetupNetwork(id = "cycle_input_alt") + void shouldDetectSecurityCycles( + @InjectNetwork("cycle_input") final Network inputNetwork, + @InjectNetworkSecurityComponent(networkId = "cycle_input") final SecurityNetworkComponent inputSecurity, + @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, + @InjectNetworkSecurityComponent(networkId = "cycle_input_alt") + final SecurityNetworkComponent inputAlternativeSecurity + ) { + // Arrange + inputSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( + new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + )); + + inputAlternativeSecurity.onContainerAdded(() -> activeSecurityDecisionProvider( + new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER2)) + )); + + // Act + final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); + cycleOutput.setSecurityDelegate(inputAlternativeSecurity); + cycleOutput.setNetwork(inputNetwork); + inputNetwork.addContainer(() -> cycleOutput); + + final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); + cycleOutputAlternative.setSecurityDelegate(inputSecurity); + cycleOutputAlternative.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + + // Assert + assertThat(inputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(inputSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); + + assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(inputAlternativeSecurity.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); + } +} diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java new file mode 100644 index 000000000..5688f54e9 --- /dev/null +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java @@ -0,0 +1,634 @@ +package com.refinedmods.refinedstorage2.api.network.impl.node.relay; + +import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.Network; +import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; +import com.refinedmods.refinedstorage2.api.storage.Storage; +import com.refinedmods.refinedstorage2.api.storage.composite.PriorityStorage; +import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; +import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; +import com.refinedmods.refinedstorage2.network.test.InjectNetwork; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkEnergyComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkSecurityComponent; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; +import com.refinedmods.refinedstorage2.network.test.NetworkTest; +import com.refinedmods.refinedstorage2.network.test.SetupNetwork; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; + +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayNetworkNodeTest.addSecurityPolicy; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A_ALTERNATIVE; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; +import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ACTIVE; +import static org.assertj.core.api.Assertions.assertThat; + +@NetworkTest +@SetupNetwork(id = "input") +@SetupNetwork(id = "output", setupEnergy = false) +class RelayStorageNetworkNodeTest { + @AddNetworkNode(properties = { + @AddNetworkNode.Property(key = PROPERTY_ACTIVE, boolValue = false) + }, networkId = "input") + private RelayInputNetworkNode input; + + @AddNetworkNode(networkId = "output") + private RelayOutputNetworkNode output; + + @Test + void shouldPassStorageComponent( + @InjectNetworkSecurityComponent(networkId = "input") final SecurityNetworkComponent inputSecurity, + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkEnergyComponent(networkId = "output") final EnergyNetworkComponent outputEnergy, + @InjectNetworkSecurityComponent(networkId = "output") final SecurityNetworkComponent outputSecurity, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + addSecurityPolicy(inputSecurity, FakePermissions.OTHER); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.insert(B, 5, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.extract(B, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(outputEnergy.getCapacity()).isZero(); + assertThat(outputEnergy.getStored()).isZero(); + assertThat(outputSecurity.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(outputSecurity.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + assertThat(input.hasComponentType(RelayComponentType.ENERGY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.SECURITY)).isFalse(); + assertThat(input.hasComponentType(RelayComponentType.STORAGE)).isTrue(); + } + + @Test + void shouldRemoveStorageWhenNetworkIsRemoved( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.insert(B, 5, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.extract(B, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setNetwork(null); + + inputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2), + new ResourceAmount(C, 1) + ); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.getStored()).isZero(); + assertThat(outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + assertThat(outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + } + + @Test + @SetupNetwork(id = "output_alt") + void shouldNotNotifyOldOutputNetworkWhenOutputNetworkHasChanged( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetwork("output") final Network outputNetwork, + @InjectNetworkStorageComponent(networkId = "output_alt") final StorageNetworkComponent outputAlternativeStorage, + @InjectNetwork("output_alt") final Network outputAlternativeNetwork, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // Act + outputNetwork.removeContainer(() -> output); + outputAlternativeNetwork.addContainer(() -> output); + output.setNetwork(outputAlternativeNetwork); + + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(outputAlternativeStorage.getAll()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyInAnyOrder(new ResourceAmount(A, 11)); + assertThat(outputAlternativeStorage.getStored()).isEqualTo(11); + assertThat(outputStorage.getAll()).isEmpty(); + assertThat(outputStorage.getStored()).isZero(); + } + + @Test + void shouldInsertResourcesIntoInputStorageFromOutputStorage( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long inserted = outputStorage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(2); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(inputStorage.getStored()).isEqualTo(12); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + } + + @Test + void shouldExtractResourcesFromInputStorageIntoOutputStorage( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long extracted = outputStorage.extract(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(extracted).isEqualTo(2); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(8); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(outputStorage.getStored()).isEqualTo(8); + } + + @Test + void shouldNotInsertInExtractOnlyMode( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setAccessMode(AccessMode.EXTRACT); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long inserted = outputStorage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isZero(); + assertThat(extracted).isEqualTo(2); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(8); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 8) + ); + assertThat(outputStorage.getStored()).isEqualTo(8); + } + + @Test + void shouldNotExtractInInsertOnlyMode( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setAccessMode(AccessMode.INSERT); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + final long inserted = outputStorage.insert(B, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(2); + assertThat(extracted).isZero(); + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(inputStorage.getStored()).isEqualTo(12); + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 2) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + } + + @Test + void shouldRespectPriorityOfOutput( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setPriority(3); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + final Storage fallbackStorage1 = PriorityStorage.of(new InMemoryStorageImpl(), 2); + fallbackStorage1.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + outputStorage.addSource(fallbackStorage1); + + final Storage fallbackStorage2 = PriorityStorage.of(new InMemoryStorageImpl(), 1); + fallbackStorage2.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + outputStorage.addSource(fallbackStorage2); + + // Act + final long inserted = outputStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(2); + assertThat(extracted).isEqualTo(3); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 9) + ); + assertThat(fallbackStorage1.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + assertThat(fallbackStorage2.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + } + + @Test + void shouldModifyPriorityOfOutput( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setPriority(3); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.addSource(new LimitedStorageImpl(10)); + + final Storage fallbackStorage1 = PriorityStorage.of(new LimitedStorageImpl(5), 1); + outputStorage.addSource(fallbackStorage1); + + final Storage fallbackStorage2 = PriorityStorage.of(new LimitedStorageImpl(5), 3); + outputStorage.addSource(fallbackStorage2); + + // Act + input.setPriority(2); + + // Assert + final long inserted = outputStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted = outputStorage.extract(A, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + assertThat(inserted).isEqualTo(7); + assertThat(extracted).isEqualTo(3); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 2) + ); + assertThat(fallbackStorage1.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); + assertThat(fallbackStorage2.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 2) + ); + } + + @Test + void shouldRespectBlocklistFilter( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, B)); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // This update shouldn't arrive. + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + // This one should. + inputStorage.insert(C, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + final long insertedAllowed = outputStorage.insert(C, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedNotAllowed = outputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extractedAllowed = outputStorage.extract(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedNotAllowed = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(insertedAllowed).isEqualTo(2); + assertThat(insertedNotAllowed).isZero(); + + assertThat(extractedAllowed).isEqualTo(1); + assertThat(extractedNotAllowed).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 11), + new ResourceAmount(B, 9), + new ResourceAmount(C, 12) + ); + assertThat(inputStorage.getStored()).isEqualTo(11 + 9 + 12); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(C, 12) + ); + assertThat(outputStorage.getStored()).isEqualTo(12); + } + + @Test + void shouldRespectAllowlistFilter( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, B)); + input.setFilterMode(FilterMode.ALLOW); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // This update should arrive. + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + // This one shouldn't. + inputStorage.insert(C, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + final long insertedAllowed = outputStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedNotAllowed = outputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extractedAllowed = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedNotAllowed = outputStorage.extract(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(insertedAllowed).isEqualTo(2); + assertThat(insertedNotAllowed).isZero(); + + assertThat(extractedAllowed).isEqualTo(1); + assertThat(extractedNotAllowed).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(B, 9), + new ResourceAmount(C, 11) + ); + assertThat(inputStorage.getStored()).isEqualTo(12 + 9 + 11); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(B, 9) + ); + assertThat(outputStorage.getStored()).isEqualTo(12 + 9); + } + + @Test + void shouldRespectFilterNormalizer( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A, B)); + input.setFilterMode(FilterMode.ALLOW); + input.setFilterNormalizer(resource -> { + if (resource == A_ALTERNATIVE) { + return A; + } + return resource; + }); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(A_ALTERNATIVE, 3, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + + // These updates should arrive. + inputStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(A_ALTERNATIVE, 2, Action.EXECUTE, EmptyActor.INSTANCE); + // This one shouldn't. + inputStorage.insert(C, 3, Action.EXECUTE, EmptyActor.INSTANCE); + + final long insertedAllowed1 = outputStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedAllowed2 = outputStorage.insert(A_ALTERNATIVE, 3, Action.EXECUTE, EmptyActor.INSTANCE); + final long insertedNotAllowed = outputStorage.insert(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extractedAllowed = outputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedAllowed2 = outputStorage.extract(A_ALTERNATIVE, 2, Action.EXECUTE, EmptyActor.INSTANCE); + final long extractedNotAllowed = outputStorage.extract(C, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(insertedAllowed1).isEqualTo(2); + assertThat(insertedAllowed2).isEqualTo(3); + assertThat(insertedNotAllowed).isZero(); + + assertThat(extractedAllowed).isEqualTo(1); + assertThat(extractedAllowed2).isEqualTo(2); + assertThat(extractedNotAllowed).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(A_ALTERNATIVE, 6), + new ResourceAmount(B, 9), + new ResourceAmount(C, 11) + ); + assertThat(inputStorage.getStored()).isEqualTo(12 + 6 + 9 + 11); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 12), + new ResourceAmount(A_ALTERNATIVE, 6), + new ResourceAmount(B, 9) + ); + assertThat(outputStorage.getStored()).isEqualTo(12 + 6 + 9); + } + + @Test + void shouldUpdateOutputStorageWhenFiltersAreChanged( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A)); + input.setFilterMode(FilterMode.BLOCK); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + input.setFilters(Set.of(B)); + + // Assert + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 9), + new ResourceAmount(C, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(10 + 9 + 8); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(C, 8) + ); + assertThat(outputStorage.getStored()).isEqualTo(10 + 8); + } + + @Test + void shouldUpdateOutputStorageWhenFilterModeIsChanged( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setFilters(Set.of(A)); + input.setFilterMode(FilterMode.BLOCK); + + inputStorage.addSource(new InMemoryStorageImpl()); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(B, 9, Action.EXECUTE, EmptyActor.INSTANCE); + inputStorage.insert(C, 8, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + input.setFilterMode(FilterMode.ALLOW); + + // Assert + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10), + new ResourceAmount(B, 9), + new ResourceAmount(C, 8) + ); + assertThat(inputStorage.getStored()).isEqualTo(10 + 9 + 8); + + assertThat(outputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 10) + ); + assertThat(outputStorage.getStored()).isEqualTo(10); + } + + @Test + @SetupNetwork(id = "cycle_input", energyStored = 1, energyCapacity = 2) + @SetupNetwork(id = "cycle_input_alt", energyStored = 3, energyCapacity = 4) + void shouldDetectStorageCycles( + @InjectNetwork("cycle_input") final Network inputNetwork, + @InjectNetworkStorageComponent(networkId = "cycle_input") final StorageNetworkComponent inputStorage, + @InjectNetwork("cycle_input_alt") final Network inputAlternativeNetwork, + @InjectNetworkStorageComponent(networkId = "cycle_input_alt") + final StorageNetworkComponent inputAlternativeStorage + ) { + // Act + final RelayOutputNetworkNode cycleOutput = new RelayOutputNetworkNode(0); + cycleOutput.setStorageDelegate(inputAlternativeStorage); + cycleOutput.setNetwork(inputNetwork); + inputNetwork.addContainer(() -> cycleOutput); + + final RelayOutputNetworkNode cycleOutputAlternative = new RelayOutputNetworkNode(0); + cycleOutputAlternative.setStorageDelegate(inputStorage); + cycleOutputAlternative.setNetwork(inputAlternativeNetwork); + inputAlternativeNetwork.addContainer(() -> cycleOutputAlternative); + + inputStorage.addSource(new InMemoryStorageImpl()); + + // Assert + final long inserted1 = inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + final long inserted2 = inputAlternativeStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extracted1 = inputStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + final long extracted2 = inputAlternativeStorage.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + + assertThat(inserted1).isEqualTo(10); + assertThat(inserted2).isZero(); + + assertThat(extracted1).isEqualTo(1); + assertThat(extracted2).isZero(); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 9) + ); + assertThat(inputAlternativeStorage.getAll()).isEmpty(); + + assertThat(inputStorage.getStored()).isEqualTo(9); + assertThat(inputAlternativeStorage.getStored()).isZero(); + } +} diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java index fce1733f2..bb04a9e36 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/node/storage/StorageNetworkNodeTest.java @@ -1,20 +1,20 @@ package com.refinedmods.refinedstorage2.api.network.impl.node.storage; import com.refinedmods.refinedstorage2.api.core.Action; +import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; import com.refinedmods.refinedstorage2.api.storage.AccessMode; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannel; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorage; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.AddNetworkNode; -import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageChannel; +import com.refinedmods.refinedstorage2.network.test.InjectNetworkStorageComponent; import com.refinedmods.refinedstorage2.network.test.NetworkTest; import com.refinedmods.refinedstorage2.network.test.SetupNetwork; -import com.refinedmods.refinedstorage2.network.test.util.FakeActor; +import com.refinedmods.refinedstorage2.network.test.fake.FakeActor; import java.util.Collection; import java.util.Set; @@ -25,9 +25,9 @@ import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; -import static com.refinedmods.refinedstorage2.network.test.TestResource.C; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.C; import static com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory.PROPERTY_ENERGY_USAGE; import static org.assertj.core.api.Assertions.assertThat; @@ -42,7 +42,7 @@ class StorageNetworkNodeTest { StorageNetworkNode sut; @Test - void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void testInitialState(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Act final long inserted = networkStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); final long extracted = networkStorage.extract(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); @@ -61,7 +61,7 @@ void testInitialState(@InjectNetworkStorageChannel final StorageChannel networkS } @Test - void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInitialize(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final LimitedStorage limitedStorage = new LimitedStorageImpl(100); limitedStorage.insert(A, 50, Action.EXECUTE, EmptyActor.INSTANCE); @@ -78,7 +78,7 @@ void shouldInitialize(@InjectNetworkStorageChannel final StorageChannel networkS } @Test - void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldInsert(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -97,7 +97,7 @@ void shouldInsert(@InjectNetworkStorageChannel final StorageChannel networkStora } @Test - void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldExtract(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(200); storage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE); @@ -120,7 +120,8 @@ void shouldExtract(@InjectNetworkStorageChannel final StorageChannel networkStor } @Test - void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectAllowlistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of(A, B)); @@ -141,7 +142,7 @@ void shouldRespectAllowlistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyAllowlistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.ALLOW); sut.setFilters(Set.of()); @@ -161,7 +162,8 @@ void shouldRespectEmptyAllowlistWhenInserting( } @Test - void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldRespectBlocklistWhenInserting( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of(A, B)); @@ -182,7 +184,7 @@ void shouldRespectBlocklistWhenInserting(@InjectNetworkStorageChannel final Stor @Test void shouldRespectEmptyBlocklistWhenInserting( - @InjectNetworkStorageChannel final StorageChannel networkStorage) { + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange sut.setFilterMode(FilterMode.BLOCK); sut.setFilters(Set.of()); @@ -204,7 +206,8 @@ void shouldRespectEmptyBlocklistWhenInserting( @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -225,7 +228,8 @@ void shouldRespectAccessModeWhenInserting(final AccessMode accessMode, @ParameterizedTest @EnumSource(AccessMode.class) void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent + final StorageNetworkComponent networkStorage ) { // Arrange sut.setAccessMode(accessMode); @@ -245,7 +249,7 @@ void shouldRespectAccessModeWhenExtracting(final AccessMode accessMode, } @Test - void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotInsertWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -259,7 +263,7 @@ void shouldNotInsertWhenInactive(@InjectNetworkStorageChannel final StorageChann } @Test - void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotExtractWhenInactive(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); activateStorage(storage); @@ -275,7 +279,7 @@ void shouldNotExtractWhenInactive(@InjectNetworkStorageChannel final StorageChan @Test void shouldHideStorageContentsWhenInactive( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final Storage storage = new LimitedStorageImpl(100); @@ -291,7 +295,8 @@ void shouldHideStorageContentsWhenInactive( } @Test - void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldShowStorageContentsWhenActive( + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); storage.insert(A, 50, Action.EXECUTE, EmptyActor.INSTANCE); @@ -308,7 +313,7 @@ void shouldShowStorageContentsWhenActive(@InjectNetworkStorageChannel final Stor } @Test - void shouldNotInsertWhenFull(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldNotInsertWhenFull(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange final Storage storage = new LimitedStorageImpl(100); storage.insert(A, 95, Action.EXECUTE, EmptyActor.INSTANCE); @@ -334,7 +339,7 @@ void shouldNotInsertWhenFull(@InjectNetworkStorageChannel final StorageChannel n @Test void shouldNotInsertWhenFullWhenStorageVoidsExcessButIsNotInAllowlistMode( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage = new LimitedStorageImpl(100); @@ -355,7 +360,7 @@ void shouldNotInsertWhenFullWhenStorageVoidsExcessButIsNotInAllowlistMode( @Test void shouldNotInsertWhenStorageVoidsExcessAndInAllowlistModeWithoutConfiguredFilter( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage = new LimitedStorageImpl(100); @@ -374,7 +379,7 @@ void shouldNotInsertWhenStorageVoidsExcessAndInAllowlistModeWithoutConfiguredFil @Test void shouldInsertWhenFullWhenStorageVoidsExcessAndIsInAllowlistMode( - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage = new LimitedStorageImpl(100); @@ -400,7 +405,7 @@ void shouldInsertWhenFullWhenStorageVoidsExcessAndIsInAllowlistMode( } @Test - void shouldTrackChanges(@InjectNetworkStorageChannel final StorageChannel networkStorage) { + void shouldTrackChanges(@InjectNetworkStorageComponent final StorageNetworkComponent networkStorage) { // Arrange activateStorage(new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L)); @@ -426,7 +431,7 @@ class PriorityTest { @ValueSource(booleans = {true, false}) void shouldRespectPriority( final boolean oneHasPriority, - @InjectNetworkStorageChannel final StorageChannel networkStorage + @InjectNetworkStorageComponent final StorageNetworkComponent networkStorage ) { // Arrange final LimitedStorageImpl storage1 = new LimitedStorageImpl(100); 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 596534a0c..50494ba03 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,17 +1,15 @@ package com.refinedmods.refinedstorage2.api.network.impl.security; import com.refinedmods.refinedstorage2.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode; -import com.refinedmods.refinedstorage2.api.network.security.Permission; -import com.refinedmods.refinedstorage2.api.network.security.SecurityActor; -import com.refinedmods.refinedstorage2.api.network.security.SecurityDecisionProvider; import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.security.SecurityPolicy; - -import java.util.Set; +import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions; +import com.refinedmods.refinedstorage2.network.test.fake.FakeSecurityActors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static com.refinedmods.refinedstorage2.api.network.impl.node.security.SecurityDecisionProviderProxyNetworkNode.activeSecurityDecisionProvider; import static org.assertj.core.api.Assertions.assertThat; class SecurityNetworkComponentImplTest { @@ -21,21 +19,21 @@ class SecurityNetworkComponentImplTest { @BeforeEach void setUp() { - sut = new SecurityNetworkComponentImpl(policy(TestPermissions.ALLOW_BY_DEFAULT)); + sut = new SecurityNetworkComponentImpl(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)); securityDecisionProvider = new SecurityDecisionProviderImpl(); - node = createNode(securityDecisionProvider); + node = activeSecurityDecisionProvider(securityDecisionProvider); } @Test void shouldUseDefaultPolicyIfNoSecurityDecisionProvidersArePresent() { // Act & assert - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.A)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.B)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); } @Test @@ -44,161 +42,138 @@ void shouldDenyAllIfAtLeastOneSecurityDecisionProviderIsPresent() { sut.onContainerAdded(() -> node); // Act & assert - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); } @Test void shouldUseDefaultPolicyIfAllSecurityDecisionProvidersAreInactive() { // Arrange - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setDefaultPolicy(policy(TestPermissions.OTHER)), false)); + sut.onContainerAdded(() -> new SecurityDecisionProviderProxyNetworkNode(0, new SecurityDecisionProviderImpl() + .setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER)))); // Act & assert - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.A)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.B)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); } @Test void shouldAllowOrDeny() { // Arrange - securityDecisionProvider.setPolicy(TestActors.A, policy(TestPermissions.OTHER)); + securityDecisionProvider.setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)); sut.onContainerAdded(() -> node); // Act & assert - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.A)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); } @Test void shouldOnlyAllowIfAllSecurityDecisionProvidersAllow() { // Arrange - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setPolicy(TestActors.A, policy(TestPermissions.OTHER)) + sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) )); - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setPolicy(TestActors.A, policy(TestPermissions.OTHER2)) + sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER2)) )); - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setPolicy(TestActors.B, policy(TestPermissions.OTHER)) + sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.B, SecurityPolicy.of(FakePermissions.OTHER)) )); - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setPolicy(TestActors.A, policy(TestPermissions.ALLOW_BY_DEFAULT)) - .setDefaultPolicy(policy(TestPermissions.OTHER, TestPermissions.OTHER2)), false)); + sut.onContainerAdded(() -> new SecurityDecisionProviderProxyNetworkNode(0, new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) + .setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER, FakePermissions.OTHER2)))); // Act & assert - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.B)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.C)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.C)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.C)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.C)).isFalse(); } @Test void shouldUseDefaultPolicyOfSecurityDecisionProviderIfAllProvidersPassDecision() { // Arrange - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setPolicy(TestActors.A, policy(TestPermissions.OTHER)) - .setDefaultPolicy(policy(TestPermissions.ALLOW_BY_DEFAULT)) + sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + .setDefaultPolicy(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) )); - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setPolicy(TestActors.A, policy(TestPermissions.OTHER)) - .setDefaultPolicy(policy(TestPermissions.ALLOW_BY_DEFAULT, TestPermissions.OTHER2)) + sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)) + .setDefaultPolicy(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT, FakePermissions.OTHER2)) )); - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setPolicy(TestActors.C, policy(TestPermissions.OTHER)) + sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setPolicy(FakeSecurityActors.C, SecurityPolicy.of(FakePermissions.OTHER)) )); // Act & assert - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.A)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.B)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.B)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.B)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.B)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.C)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.C)).isTrue(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.C)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.C)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.C)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.C)).isFalse(); } @Test void shouldRemoveContainer() { // Arrange - sut.onContainerAdded(() -> createNode(new SecurityDecisionProviderImpl() - .setDefaultPolicy(policy(TestPermissions.ALLOW_BY_DEFAULT)) + sut.onContainerAdded(() -> activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setDefaultPolicy(SecurityPolicy.of(FakePermissions.ALLOW_BY_DEFAULT)) )); - final var removedNode = createNode(new SecurityDecisionProviderImpl() - .setDefaultPolicy(policy(TestPermissions.OTHER))); + final var removedNode = activeSecurityDecisionProvider(new SecurityDecisionProviderImpl() + .setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER))); sut.onContainerAdded(() -> removedNode); // Act sut.onContainerRemoved(() -> removedNode); // Assert - assertThat(sut.isAllowed(TestPermissions.ALLOW_BY_DEFAULT, TestActors.A)).isTrue(); + assertThat(sut.isAllowed(FakePermissions.ALLOW_BY_DEFAULT, FakeSecurityActors.A)).isTrue(); } @Test void shouldClearPolicies() { // Arrange sut.onContainerAdded(() -> node); - securityDecisionProvider.setPolicy(TestActors.A, policy(TestPermissions.OTHER)); - securityDecisionProvider.setDefaultPolicy(policy(TestPermissions.OTHER2)); + securityDecisionProvider.setPolicy(FakeSecurityActors.A, SecurityPolicy.of(FakePermissions.OTHER)); + securityDecisionProvider.setDefaultPolicy(SecurityPolicy.of(FakePermissions.OTHER2)); // Act securityDecisionProvider.clearPolicies(); // Assert - assertThat(sut.isAllowed(TestPermissions.OTHER, TestActors.A)).isFalse(); - assertThat(sut.isAllowed(TestPermissions.OTHER2, TestActors.A)).isTrue(); - } - - private static SecurityDecisionProviderProxyNetworkNode createNode(final SecurityDecisionProvider provider) { - return createNode(provider, true); - } - - private static SecurityDecisionProviderProxyNetworkNode createNode(final SecurityDecisionProvider provider, - final boolean active) { - final var node = new SecurityDecisionProviderProxyNetworkNode(0, provider); - node.setActive(active); - return node; - } - - enum TestPermissions implements Permission { - ALLOW_BY_DEFAULT, OTHER, OTHER2 - } - - enum TestActors implements SecurityActor { - A, B, C - } - - private SecurityPolicy policy(final Permission... permissions) { - return new SecurityPolicy(Set.of(permissions)); + assertThat(sut.isAllowed(FakePermissions.OTHER, FakeSecurityActors.A)).isFalse(); + assertThat(sut.isAllowed(FakePermissions.OTHER2, FakeSecurityActors.A)).isTrue(); } } diff --git a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java index 0e8246008..1c234496b 100644 --- a/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java +++ b/refinedstorage2-network/src/test/java/com/refinedmods/refinedstorage2/api/network/impl/storage/StorageNetworkComponentImplTest.java @@ -2,27 +2,40 @@ import com.refinedmods.refinedstorage2.api.core.Action; import com.refinedmods.refinedstorage2.api.network.impl.NetworkImpl; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; 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.network.storage.StorageProvider; import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; +import com.refinedmods.refinedstorage2.api.resource.list.listenable.ResourceListListener; +import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; +import com.refinedmods.refinedstorage2.api.storage.InMemoryStorageImpl; +import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.api.storage.TrackedResourceAmount; +import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild; +import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; import com.refinedmods.refinedstorage2.network.test.NetworkTestFixtures; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Set; +import javax.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static com.refinedmods.refinedstorage2.network.test.TestResource.A; -import static com.refinedmods.refinedstorage2.network.test.TestResource.B; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.A; +import static com.refinedmods.refinedstorage2.network.test.fake.FakeResources.B; import static org.assertj.core.api.Assertions.assertThat; class StorageNetworkComponentImplTest { @@ -131,4 +144,155 @@ void shouldRetrieveResources() { ) ); } + + @Test + void shouldDetectCycles() { + // Arrange + final StorageNetworkComponent a = new StorageNetworkComponentImpl(new ResourceListImpl()); + final InMemoryStorageImpl storage = new InMemoryStorageImpl(); + storage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + final StorageNetworkComponent b = new StorageNetworkComponentImpl(new ResourceListImpl()); + + final ProxyStorageProvider providerInB = proxyProvider(); + b.onContainerAdded(() -> providerInB); + providerInB.setDelegate(a); + + // Act + final ProxyStorageProvider providerInA = proxyProvider(); + a.onContainerAdded(() -> providerInA); + a.addSource(storage); + providerInA.setDelegate(b); + + // Assert + assertThat(a.getAll()).isNotEmpty(); + assertThat(b.getAll()).isNotEmpty(); + + assertThat(a.extract(A, 5, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(5); + assertThat(b.extract(A, 5, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + + assertThat(a.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE)).isEqualTo(5); + assertThat(b.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE)).isZero(); + } + + private ProxyStorageProvider proxyProvider() { + final ProxyStorageProvider node = new ProxyStorageProvider(); + node.setActive(true); + return node; + } + + private static class ProxyStorageProvider extends AbstractNetworkNode implements StorageProvider { + private final ProxyStorage proxyStorage = new ProxyStorage(); + + private ProxyStorageProvider setDelegate(final StorageNetworkComponent delegate) { + proxyStorage.setDelegate(delegate); + return this; + } + + @Override + public long getEnergyUsage() { + return 0; + } + + @Override + public Storage getStorage() { + return proxyStorage; + } + } + + private static class ProxyStorage implements Storage, CompositeAwareChild, ResourceListListener { + @Nullable + private StorageNetworkComponent delegate; + private final Set parentComposites = new HashSet<>(); + + private void setDelegate(final StorageNetworkComponent delegate) { + this.delegate = delegate; + delegate.addListener(this); + parentComposites.forEach(outerParentComposite -> + getAll().forEach(resourceAmount -> outerParentComposite.addToCache( + resourceAmount.getResource(), + resourceAmount.getAmount() + ))); + } + + @Override + public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { + if (delegate == null || delegate.contains(delegate)) { + return 0; + } + return delegate.extract(resource, amount, action, actor); + } + + @Override + public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { + if (delegate == null || delegate.contains(delegate)) { + return 0; + } + return delegate.insert(resource, amount, action, actor); + } + + @Override + public Collection getAll() { + if (delegate == null) { + return Collections.emptyList(); + } + return delegate.getAll(); + } + + @Override + public long getStored() { + if (delegate == null) { + return 0; + } + return delegate.getStored(); + } + + @Override + public void onAddedIntoComposite(final ParentComposite parentComposite) { + parentComposites.add(parentComposite); + } + + @Override + public void onRemovedFromComposite(final ParentComposite parentComposite) { + parentComposites.remove(parentComposite); + } + + @Override + public Amount compositeInsert(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + final long inserted = insert(resource, amount, action, actor); + return new Amount(inserted, inserted); + } + + @Override + public Amount compositeExtract(final ResourceKey resource, + final long amount, + final Action action, + final Actor actor) { + final long extracted = extract(resource, amount, action, actor); + return new Amount(extracted, extracted); + } + + @Override + public boolean contains(final Storage storage) { + return storage == delegate || (delegate != null && delegate.contains(storage)); + } + + @Override + public void onChanged(final ResourceList.OperationResult change) { + if (delegate != null && delegate.contains(delegate)) { + return; + } + parentComposites.forEach(parentComposite -> { + final ResourceKey resource = change.resourceAmount().getResource(); + if (change.change() > 0) { + parentComposite.addToCache(resource, change.change()); + } else if (change.change() < 0) { + parentComposite.removeFromCache(resource, Math.abs(change.change())); + } + }); + } + } } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformSecurityNetworkComponent.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformSecurityNetworkComponent.java index 3850fd466..6b70ea03d 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformSecurityNetworkComponent.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/security/PlatformSecurityNetworkComponent.java @@ -1,13 +1,12 @@ package com.refinedmods.refinedstorage2.platform.api.security; -import com.refinedmods.refinedstorage2.api.network.NetworkComponent; import com.refinedmods.refinedstorage2.api.network.security.Permission; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import net.minecraft.server.level.ServerPlayer; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.5") -@FunctionalInterface -public interface PlatformSecurityNetworkComponent extends NetworkComponent { +public interface PlatformSecurityNetworkComponent extends SecurityNetworkComponent { boolean isAllowed(Permission permission, ServerPlayer player); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java index c24e9a476..583a35c81 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/support/network/AbstractNetworkNodeContainerBlockEntity.java @@ -33,7 +33,7 @@ protected AbstractNetworkNodeContainerBlockEntity(final BlockEntityType type, final T mainNode) { super(type, pos, state); this.mainContainer = createMainContainer(mainNode); - this.containers.add(mainContainer); + addContainer(mainContainer); this.mainNode = mainNode; } @@ -48,6 +48,14 @@ protected InWorldNetworkNodeContainer createMainContainer(final T node) { ); } + protected final void addContainer(final InWorldNetworkNodeContainer container) { + containers.add(container); + } + + protected final void updateContainers() { + containers.forEach(container -> PlatformApi.INSTANCE.onNetworkNodeContainerUpdated(container, level)); + } + @Override public void addOutgoingConnections(final ConnectionSink sink) { for (final Direction direction : Direction.values()) { diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/black_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/black_relay.json new file mode 100644 index 000000000..cb770d118 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/black_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/black", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/black", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/black" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/black", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/black", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/black", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/blue_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/blue_relay.json new file mode 100644 index 000000000..795311c42 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/blue_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/blue", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/blue", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/blue" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/blue", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/blue", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/blue", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/brown_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/brown_relay.json new file mode 100644 index 000000000..749c6e38e --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/brown_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/brown", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/brown", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/brown" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/brown", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/brown", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/brown", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/cyan_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/cyan_relay.json new file mode 100644 index 000000000..a16b269c8 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/cyan_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/cyan", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/cyan", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/cyan" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/cyan", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/cyan", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/cyan", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/gray_relay.json new file mode 100644 index 000000000..be0738666 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/gray_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/gray", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/gray", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/gray" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/gray", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/gray", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/gray", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/green_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/green_relay.json new file mode 100644 index 000000000..89112dcdb --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/green_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/green", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/green", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/green" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/green", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/green", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/green", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/light_gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/light_gray_relay.json new file mode 100644 index 000000000..2f3e1c1f9 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/light_gray_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/light_gray", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/light_gray", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/light_gray" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/light_gray", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/light_gray", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/light_gray", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/lime_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/lime_relay.json new file mode 100644 index 000000000..468f24466 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/lime_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/lime", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/lime", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/lime" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/lime", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/lime", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/lime", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/magenta_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/magenta_relay.json new file mode 100644 index 000000000..abe6cac51 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/magenta_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/magenta", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/magenta", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/magenta" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/magenta", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/magenta", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/magenta", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/orange_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/orange_relay.json new file mode 100644 index 000000000..b88a78a2e --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/orange_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/orange", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/orange", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/orange" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/orange", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/orange", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/orange", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/pink_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/pink_relay.json new file mode 100644 index 000000000..fad05f6fd --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/pink_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/pink", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/pink", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/pink" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/pink", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/pink", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/pink", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/purple_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/purple_relay.json new file mode 100644 index 000000000..64092cee3 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/purple_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/purple", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/purple", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/purple" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/purple", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/purple", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/purple", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/red_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/red_relay.json new file mode 100644 index 000000000..d8d0481ff --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/red_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/red", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/red", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/red" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/red", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/red", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/red", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/relay.json new file mode 100644 index 000000000..81c13e2df --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/light_blue", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/light_blue", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/light_blue" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/light_blue", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/light_blue", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/light_blue", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/white_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/white_relay.json new file mode 100644 index 000000000..fc3ee23ce --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/white_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/white", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/white", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/white" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/white", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/white", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/white", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/yellow_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/yellow_relay.json new file mode 100644 index 000000000..335a4983f --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/blockstates/yellow_relay.json @@ -0,0 +1,52 @@ +{ + "variants": { + "active=false,direction=down": { + "model": "refinedstorage2:block/relay/inactive", + "x": 90 + }, + "active=false,direction=east": { + "model": "refinedstorage2:block/relay/inactive", + "y": 90 + }, + "active=false,direction=north": { + "model": "refinedstorage2:block/relay/inactive" + }, + "active=false,direction=south": { + "model": "refinedstorage2:block/relay/inactive", + "y": 180 + }, + "active=false,direction=up": { + "model": "refinedstorage2:block/relay/inactive", + "x": -90, + "y": 180 + }, + "active=false,direction=west": { + "model": "refinedstorage2:block/relay/inactive", + "y": 270 + }, + "active=true,direction=down": { + "model": "refinedstorage2:block/relay/yellow", + "x": 90 + }, + "active=true,direction=east": { + "model": "refinedstorage2:block/relay/yellow", + "y": 90 + }, + "active=true,direction=north": { + "model": "refinedstorage2:block/relay/yellow" + }, + "active=true,direction=south": { + "model": "refinedstorage2:block/relay/yellow", + "y": 180 + }, + "active=true,direction=up": { + "model": "refinedstorage2:block/relay/yellow", + "x": -90, + "y": 180 + }, + "active=true,direction=west": { + "model": "refinedstorage2:block/relay/yellow", + "y": 270 + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/black.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/black.json new file mode 100644 index 000000000..914e403fd --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/black.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/black", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/black", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/black", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/black", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/black", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/black", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/blue.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/blue.json new file mode 100644 index 000000000..93491c2d2 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/blue.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/blue", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/blue", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/blue", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/blue", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/blue", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/blue", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/brown.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/brown.json new file mode 100644 index 000000000..b4e379ea6 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/brown.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/brown", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/brown", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/brown", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/brown", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/brown", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/brown", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/cyan.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/cyan.json new file mode 100644 index 000000000..8487e8b95 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/cyan.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/cyan", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/cyan", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/cyan", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/cyan", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/cyan", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/cyan", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/gray.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/gray.json new file mode 100644 index 000000000..0cc0a2ace --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/gray.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/gray", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/gray", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/gray", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/gray", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/gray", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/gray", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/green.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/green.json new file mode 100644 index 000000000..f22c4d555 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/green.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/green", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/green", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/green", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/green", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/green", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/green", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/inactive.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/inactive.json new file mode 100644 index 000000000..c33e16f41 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/inactive.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/inactive", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/inactive", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/inactive", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/inactive", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/inactive", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/inactive", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/light_blue.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/light_blue.json new file mode 100644 index 000000000..b7509e1e4 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/light_blue.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/light_blue", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/light_blue", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/light_blue", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/light_blue", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/light_blue", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/light_blue", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/light_gray.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/light_gray.json new file mode 100644 index 000000000..cd4f2c280 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/light_gray.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/light_gray", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/light_gray", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/light_gray", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/light_gray", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/light_gray", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/light_gray", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/lime.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/lime.json new file mode 100644 index 000000000..a4a606c67 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/lime.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/lime", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/lime", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/lime", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/lime", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/lime", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/lime", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/magenta.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/magenta.json new file mode 100644 index 000000000..5d8aec8b0 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/magenta.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/magenta", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/magenta", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/magenta", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/magenta", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/magenta", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/magenta", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/orange.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/orange.json new file mode 100644 index 000000000..8b237cab8 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/orange.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/orange", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/orange", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/orange", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/orange", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/orange", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/orange", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/pink.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/pink.json new file mode 100644 index 000000000..89fbb71be --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/pink.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/pink", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/pink", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/pink", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/pink", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/pink", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/pink", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/purple.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/purple.json new file mode 100644 index 000000000..a2c080940 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/purple.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/purple", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/purple", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/purple", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/purple", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/purple", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/purple", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/red.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/red.json new file mode 100644 index 000000000..fb2aa93d2 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/red.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/red", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/red", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/red", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/red", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/red", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/red", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/white.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/white.json new file mode 100644 index 000000000..1adac00bc --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/white.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/white", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/white", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/white", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/white", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/white", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/white", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/yellow.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/yellow.json new file mode 100644 index 000000000..2096a76e2 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/block/relay/yellow.json @@ -0,0 +1,18 @@ +{ + "parent": "refinedstorage2:block/emissive_cutout", + "textures": { + "cutout_down": "refinedstorage2:block/relay/cutouts/in/yellow", + "cutout_east": "refinedstorage2:block/relay/cutouts/in/yellow", + "cutout_north": "refinedstorage2:block/relay/cutouts/out/yellow", + "cutout_south": "refinedstorage2:block/relay/cutouts/in/yellow", + "cutout_up": "refinedstorage2:block/relay/cutouts/in/yellow", + "cutout_west": "refinedstorage2:block/relay/cutouts/in/yellow", + "down": "refinedstorage2:block/relay/in", + "east": "refinedstorage2:block/relay/in", + "north": "refinedstorage2:block/relay/out", + "particle": "refinedstorage2:block/relay/in", + "south": "refinedstorage2:block/relay/in", + "up": "refinedstorage2:block/relay/in", + "west": "refinedstorage2:block/relay/in" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/black_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/black_relay.json new file mode 100644 index 000000000..b662ba05e --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/black_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/black" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/blue_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/blue_relay.json new file mode 100644 index 000000000..11ac25440 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/blue_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/blue" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/brown_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/brown_relay.json new file mode 100644 index 000000000..c2520d02c --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/brown_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/brown" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/cyan_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/cyan_relay.json new file mode 100644 index 000000000..fc8c86be2 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/cyan_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/cyan" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/gray_relay.json new file mode 100644 index 000000000..9d2c654e0 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/gray_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/gray" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/green_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/green_relay.json new file mode 100644 index 000000000..a50ef1165 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/green_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/green" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/light_gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/light_gray_relay.json new file mode 100644 index 000000000..51a372bad --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/light_gray_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/light_gray" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/lime_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/lime_relay.json new file mode 100644 index 000000000..0f12fad98 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/lime_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/lime" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/magenta_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/magenta_relay.json new file mode 100644 index 000000000..13c4bd8af --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/magenta_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/magenta" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/orange_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/orange_relay.json new file mode 100644 index 000000000..deaa01aca --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/orange_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/orange" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/pink_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/pink_relay.json new file mode 100644 index 000000000..7b56295eb --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/pink_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/pink" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/purple_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/purple_relay.json new file mode 100644 index 000000000..a51cd5fd7 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/purple_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/purple" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/red_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/red_relay.json new file mode 100644 index 000000000..7c94769ee --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/red_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/red" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/relay.json new file mode 100644 index 000000000..a6634495e --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/light_blue" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/white_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/white_relay.json new file mode 100644 index 000000000..b2badbd1e --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/white_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/white" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/yellow_relay.json b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/yellow_relay.json new file mode 100644 index 000000000..8486447ab --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/assets/refinedstorage2/models/item/yellow_relay.json @@ -0,0 +1,3 @@ +{ + "parent": "refinedstorage2:block/relay/yellow" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/black_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/black_relay.json new file mode 100644 index 000000000..3377dcb4c --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/black_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/black_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/black_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/blue_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/blue_relay.json new file mode 100644 index 000000000..15e6f885c --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/blue_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/blue_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/blue_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/brown_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/brown_relay.json new file mode 100644 index 000000000..cffbbfee1 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/brown_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/brown_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/brown_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/cyan_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/cyan_relay.json new file mode 100644 index 000000000..776a551b8 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/cyan_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/cyan_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/cyan_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/gray_relay.json new file mode 100644 index 000000000..eafcb62d5 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/gray_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/gray_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/gray_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/green_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/green_relay.json new file mode 100644 index 000000000..82699eef5 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/green_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/green_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/green_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/light_blue_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/light_blue_relay.json new file mode 100644 index 000000000..a59f37c02 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/light_blue_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/light_blue_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/light_blue_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/light_gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/light_gray_relay.json new file mode 100644 index 000000000..83690021d --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/light_gray_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/light_gray_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/light_gray_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/lime_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/lime_relay.json new file mode 100644 index 000000000..fb2918db3 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/lime_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/lime_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/lime_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/magenta_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/magenta_relay.json new file mode 100644 index 000000000..80665cba1 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/magenta_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/magenta_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/magenta_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/orange_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/orange_relay.json new file mode 100644 index 000000000..2e38b0954 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/orange_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/orange_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/orange_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/pink_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/pink_relay.json new file mode 100644 index 000000000..bce19fbb8 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/pink_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/pink_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/pink_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/purple_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/purple_relay.json new file mode 100644 index 000000000..8defcc832 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/purple_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/purple_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/purple_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/red_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/red_relay.json new file mode 100644 index 000000000..850719359 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/red_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/red_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/red_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/white_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/white_relay.json new file mode 100644 index 000000000..7260c1feb --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/white_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/white_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/white_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/yellow_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/yellow_relay.json new file mode 100644 index 000000000..bd7759ea9 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/advancements/recipes/misc/coloring/yellow_relay.json @@ -0,0 +1,32 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_relays": { + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "refinedstorage2:coloring/yellow_relay" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_relays" + ] + ], + "rewards": { + "recipes": [ + "refinedstorage2:coloring/yellow_relay" + ] + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/black_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/black_relay.json new file mode 100644 index 000000000..4936678f4 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/black_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:black_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/black_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/blue_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/blue_relay.json new file mode 100644 index 000000000..565c2fba3 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/blue_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:blue_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/blue_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/brown_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/brown_relay.json new file mode 100644 index 000000000..08d3ff147 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/brown_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:brown_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/brown_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/cyan_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/cyan_relay.json new file mode 100644 index 000000000..37304c1b4 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/cyan_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:cyan_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/cyan_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/gray_relay.json new file mode 100644 index 000000000..b14675039 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/gray_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:gray_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/gray_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/green_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/green_relay.json new file mode 100644 index 000000000..a25a064b2 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/green_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:green_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/green_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/light_gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/light_gray_relay.json new file mode 100644 index 000000000..10f10db8e --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/light_gray_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:light_gray_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/light_gray_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/lime_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/lime_relay.json new file mode 100644 index 000000000..7b4771a9f --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/lime_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:lime_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/lime_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/magenta_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/magenta_relay.json new file mode 100644 index 000000000..def0bf407 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/magenta_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:magenta_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/magenta_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/orange_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/orange_relay.json new file mode 100644 index 000000000..646af5e56 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/orange_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:orange_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/orange_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/pink_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/pink_relay.json new file mode 100644 index 000000000..6255d9b7d --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/pink_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:pink_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/pink_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/purple_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/purple_relay.json new file mode 100644 index 000000000..f92f4e4a8 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/purple_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:purple_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/purple_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/red_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/red_relay.json new file mode 100644 index 000000000..d050f5995 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/red_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:red_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/red_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/relay.json new file mode 100644 index 000000000..d79ebcf77 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/white_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/white_relay.json new file mode 100644 index 000000000..7e6246c65 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/white_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:white_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/white_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/yellow_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/yellow_relay.json new file mode 100644 index 000000000..3e2872c11 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/loot_tables/blocks/yellow_relay.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "refinedstorage2:yellow_relay" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "refinedstorage2:blocks/yellow_relay" +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/black_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/black_relay.json new file mode 100644 index 000000000..37ad99430 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/black_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:black_dye" + } + ], + "result": { + "item": "refinedstorage2:black_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/blue_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/blue_relay.json new file mode 100644 index 000000000..2c4374cd8 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/blue_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:blue_dye" + } + ], + "result": { + "item": "refinedstorage2:blue_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/brown_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/brown_relay.json new file mode 100644 index 000000000..49c08e3ae --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/brown_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:brown_dye" + } + ], + "result": { + "item": "refinedstorage2:brown_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/cyan_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/cyan_relay.json new file mode 100644 index 000000000..5e680e821 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/cyan_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:cyan_dye" + } + ], + "result": { + "item": "refinedstorage2:cyan_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/gray_relay.json new file mode 100644 index 000000000..c6676fcbf --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/gray_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:gray_dye" + } + ], + "result": { + "item": "refinedstorage2:gray_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/green_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/green_relay.json new file mode 100644 index 000000000..da3689085 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/green_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:green_dye" + } + ], + "result": { + "item": "refinedstorage2:green_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/light_blue_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/light_blue_relay.json new file mode 100644 index 000000000..37fb39142 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/light_blue_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:light_blue_dye" + } + ], + "result": { + "item": "refinedstorage2:relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/light_gray_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/light_gray_relay.json new file mode 100644 index 000000000..108d49c9f --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/light_gray_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:light_gray_dye" + } + ], + "result": { + "item": "refinedstorage2:light_gray_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/lime_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/lime_relay.json new file mode 100644 index 000000000..f327a70cd --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/lime_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:lime_dye" + } + ], + "result": { + "item": "refinedstorage2:lime_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/magenta_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/magenta_relay.json new file mode 100644 index 000000000..b20acee6f --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/magenta_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:magenta_dye" + } + ], + "result": { + "item": "refinedstorage2:magenta_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/orange_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/orange_relay.json new file mode 100644 index 000000000..383053a5b --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/orange_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:orange_dye" + } + ], + "result": { + "item": "refinedstorage2:orange_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/pink_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/pink_relay.json new file mode 100644 index 000000000..46eacad2d --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/pink_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:pink_dye" + } + ], + "result": { + "item": "refinedstorage2:pink_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/purple_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/purple_relay.json new file mode 100644 index 000000000..b069db8ad --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/purple_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:purple_dye" + } + ], + "result": { + "item": "refinedstorage2:purple_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/red_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/red_relay.json new file mode 100644 index 000000000..8f04b7e21 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/red_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:red_dye" + } + ], + "result": { + "item": "refinedstorage2:red_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/white_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/white_relay.json new file mode 100644 index 000000000..d58f4f5ed --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/white_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:white_dye" + } + ], + "result": { + "item": "refinedstorage2:white_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/yellow_relay.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/yellow_relay.json new file mode 100644 index 000000000..d2c04d4b0 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/recipes/coloring/yellow_relay.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "tag": "refinedstorage2:relays" + }, + { + "item": "minecraft:yellow_dye" + } + ], + "result": { + "item": "refinedstorage2:yellow_relay" + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/tags/items/relays.json b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/tags/items/relays.json new file mode 100644 index 000000000..d65c7afe7 --- /dev/null +++ b/refinedstorage2-platform-common/src/generated/resources/data/refinedstorage2/tags/items/relays.json @@ -0,0 +1,20 @@ +{ + "values": [ + "refinedstorage2:white_relay", + "refinedstorage2:orange_relay", + "refinedstorage2:magenta_relay", + "refinedstorage2:relay", + "refinedstorage2:yellow_relay", + "refinedstorage2:lime_relay", + "refinedstorage2:pink_relay", + "refinedstorage2:gray_relay", + "refinedstorage2:light_gray_relay", + "refinedstorage2:cyan_relay", + "refinedstorage2:purple_relay", + "refinedstorage2:blue_relay", + "refinedstorage2:brown_relay", + "refinedstorage2:green_relay", + "refinedstorage2:red_relay", + "refinedstorage2:black_relay" + ] +} \ No newline at end of file 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 8530d48e2..e73ce9111 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 @@ -18,6 +18,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.networking.RelayScreen; import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardScreen; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardScreen; import com.refinedmods.refinedstorage2.platform.common.security.SecurityManagerScreen; @@ -81,6 +82,7 @@ protected static void registerScreens(final ScreenRegistration registration) { registration.register(Menus.INSTANCE.getSecurityCard(), SecurityCardScreen::new); registration.register(Menus.INSTANCE.getFallbackSecurityCard(), FallbackSecurityCardScreen::new); registration.register(Menus.INSTANCE.getSecurityManager(), SecurityManagerScreen::new); + registration.register(Menus.INSTANCE.getRelay(), RelayScreen::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 7d8409d4c..82f97c96d 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 @@ -4,7 +4,9 @@ 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.impl.security.SecurityNetworkComponentImpl; import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent; +import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent; import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.PlatformApiProxy; @@ -55,6 +57,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.networking.RelayBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.networking.RelayContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.BuiltinPermission; import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.PlatformSecurityNetworkComponentImpl; @@ -158,6 +162,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.RELAY; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SECURITY_CARD; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SECURITY_MANAGER; import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SILICON; @@ -264,6 +269,10 @@ private void registerNetworkComponents() { PlatformSecurityNetworkComponent.class, network -> new PlatformSecurityNetworkComponentImpl(PlatformApi.INSTANCE.createDefaultSecurityPolicy()) ); + PlatformApi.INSTANCE.getNetworkComponentMapFactory().addFactory( + SecurityNetworkComponent.class, + network -> new SecurityNetworkComponentImpl(PlatformApi.INSTANCE.createDefaultSecurityPolicy()) + ); } private void registerWirelessTransmitterRangeModifiers() { @@ -328,6 +337,7 @@ protected final void registerBlocks( creativePortableGridBlockEntityFactory ))); Blocks.INSTANCE.getSecurityManager().registerBlocks(callback); + Blocks.INSTANCE.getRelay().registerBlocks(callback); } protected final void registerItems(final RegistryCallback callback) { @@ -347,6 +357,7 @@ protected final void registerItems(final RegistryCallback callback) { Blocks.INSTANCE.getNetworkReceiver().registerItems(callback, Items.INSTANCE::addNetworkReceiver); Blocks.INSTANCE.getNetworkTransmitter().registerItems(callback, Items.INSTANCE::addNetworkTransmitter); Blocks.INSTANCE.getSecurityManager().registerItems(callback, Items.INSTANCE::addSecurityManager); + Blocks.INSTANCE.getRelay().registerItems(callback, Items.INSTANCE::addRelay); registerStorageItems(callback); registerUpgrades(callback); } @@ -642,6 +653,10 @@ protected final void registerBlockEntities( Blocks.INSTANCE.getSecurityManager().toArray() ) )); + BlockEntities.INSTANCE.setRelay(callback.register( + RELAY, + () -> typeFactory.create(RelayBlockEntity::new, Blocks.INSTANCE.getRelay().toArray()) + )); } protected final void registerMenus(final RegistryCallback> callback, @@ -737,6 +752,10 @@ protected final void registerMenus(final RegistryCallback> callback, Menus.INSTANCE.setSecurityManager(callback.register(SECURITY_MANAGER, () -> menuTypeFactory.create( (syncId, playerInventory, buf) -> new SecurityManagerContainerMenu(syncId, playerInventory) ))); + Menus.INSTANCE.setRelay(callback.register( + RELAY, + () -> menuTypeFactory.create(RelayContainerMenu::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 0e9068ecf..1bdb808b2 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 @@ -66,6 +66,8 @@ public interface Config { SimpleEnergyUsageEntry getSecurityManager(); + RelayEntry getRelay(); + interface SimpleEnergyUsageEntry { long getEnergyUsage(); } @@ -185,4 +187,10 @@ interface PortableGridEntry { long getExtractEnergyUsage(); } + + interface RelayEntry { + long getInputNetworkEnergyUsage(); + + long getOutputNetworkEnergyUsage(); + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java index 3d8ccc2a5..cd94473b5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/BlockEntities.java @@ -12,6 +12,7 @@ import com.refinedmods.refinedstorage2.platform.common.importer.ImporterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlockEntity; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.networking.RelayBlockEntity; import com.refinedmods.refinedstorage2.platform.common.security.SecurityManagerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; @@ -80,6 +81,8 @@ public final class BlockEntities { private Supplier> creativePortableGrid; @Nullable private Supplier> securityManager; + @Nullable + private Supplier> relay; private BlockEntities() { } @@ -263,4 +266,12 @@ public BlockEntityType getSecurityManager() { public void setSecurityManager(final Supplier> supplier) { this.securityManager = supplier; } + + public BlockEntityType getRelay() { + return requireNonNull(relay).get(); + } + + public void setRelay(final Supplier> supplier) { + this.relay = supplier; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java index f393da0a5..c4814773d 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Blocks.java @@ -17,6 +17,7 @@ import com.refinedmods.refinedstorage2.platform.common.networking.CableBlock; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlock; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlock; +import com.refinedmods.refinedstorage2.platform.common.networking.RelayBlock; import com.refinedmods.refinedstorage2.platform.common.security.SecurityManagerBlock; import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType; @@ -144,6 +145,12 @@ public final class Blocks { ContentNames.SECURITY_MANAGER, COLOR ); + private final BlockColorMap relay = new BlockColorMap<>( + RelayBlock::new, + ContentIds.RELAY, + ContentNames.RELAY, + COLOR + ); @Nullable private Supplier quartzEnrichedIronBlock; @@ -301,4 +308,8 @@ public void setCreativePortableGrid(final Supplier supplier) public BlockColorMap getSecurityManager() { return securityManager; } + + public BlockColorMap getRelay() { + return relay; + } } 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 c1898295d..5d61fa250 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 @@ -57,6 +57,7 @@ public final class ContentIds { public static final ResourceLocation SECURITY_CARD = createIdentifier("security_card"); public static final ResourceLocation FALLBACK_SECURITY_CARD = createIdentifier("fallback_security_card"); public static final ResourceLocation SECURITY_MANAGER = createIdentifier("security_manager"); + public static final ResourceLocation RELAY = createIdentifier("relay"); 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 9a6ea25f5..6ce442caf 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 @@ -32,6 +32,7 @@ public final class ContentNames { public static final MutableComponent SECURITY_CARD = createTranslation("item", "security_card"); public static final MutableComponent FALLBACK_SECURITY_CARD = createTranslation("item", "fallback_security_card"); public static final MutableComponent SECURITY_MANAGER = name("security_manager"); + public static final MutableComponent RELAY = name("relay"); 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 fd43e703b..f79f0546b 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 @@ -54,6 +54,7 @@ private static void appendBlocks(final Consumer consumer) { Items.INSTANCE.getNetworkTransmitters().stream().map(Supplier::get).forEach(itemConsumer); Items.INSTANCE.getNetworkReceivers().stream().map(Supplier::get).forEach(itemConsumer); Items.INSTANCE.getSecurityManagers().stream().map(Supplier::get).forEach(itemConsumer); + Items.INSTANCE.getRelays().stream().map(Supplier::get).forEach(itemConsumer); } private static void appendBlockColors(final Consumer consumer, final BlockColorMap map) { diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java index d01592d55..cad36d18a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/DefaultEnergyUsage.java @@ -17,6 +17,8 @@ public final class DefaultEnergyUsage { public static final long NETWORK_RECEIVER = 8; public static final long NETWORK_TRANSMITTER = 32; public static final long SECURITY_MANAGER = 16; + public static final long RELAY_INPUT_NETWORK = 8; + public static final long RELAY_OUTPUT_NETWORK = 8; public static final long CONTROLLER_CAPACITY = 1000; 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 4d8dea711..07036ed8d 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 @@ -48,6 +48,7 @@ public final class Items { private final List> allNetworkReceivers = new ArrayList<>(); private final List> allNetworkTransmitters = new ArrayList<>(); private final List> allSecurityManagers = new ArrayList<>(); + private final List> allRelays = new ArrayList<>(); @Nullable private Supplier quartzEnrichedIron; @Nullable @@ -407,6 +408,14 @@ public List> getSecurityManagers() { return Collections.unmodifiableList(allSecurityManagers); } + public void addRelay(final Supplier supplier) { + allRelays.add(supplier); + } + + public List> getRelays() { + return Collections.unmodifiableList(allRelays); + } + public Item getNetworkCard() { return requireNonNull(networkCard).get(); } 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 197b59973..21c477e97 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.networking.RelayContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.FallbackSecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.SecurityCardContainerMenu; import com.refinedmods.refinedstorage2.platform.common.security.SecurityManagerContainerMenu; @@ -80,6 +81,8 @@ public final class Menus { private Supplier> fallbackSecurityCard; @Nullable private Supplier> securityManager; + @Nullable + private Supplier> relay; private Menus() { } @@ -269,4 +272,12 @@ public MenuType getSecurityManager() { public void setSecurityManager(final Supplier> securityManager) { this.securityManager = securityManager; } + + public MenuType getRelay() { + return requireNonNull(relay).get(); + } + + public void setRelay(final Supplier> relay) { + this.relay = relay; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Tags.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Tags.java index c46aeeb72..068fdd0de 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Tags.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/content/Tags.java @@ -24,6 +24,7 @@ public final class Tags { public static final TagKey NETWORK_RECEIVERS = createTag("network_receivers"); public static final TagKey NETWORK_TRANSMITTERS = createTag("network_transmitters"); public static final TagKey SECURITY_MANAGERS = createTag("security_managers"); + public static final TagKey RELAYS = createTag("relays"); private Tags() { } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java index 3f08564e9..24de98829 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/detector/DetectorBlock.java @@ -10,8 +10,8 @@ import com.refinedmods.refinedstorage2.platform.common.support.BlockItemProvider; import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; import com.refinedmods.refinedstorage2.platform.common.support.NetworkNodeBlockItem; +import com.refinedmods.refinedstorage2.platform.common.support.direction.DefaultDirectionType; import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionType; -import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionTypeImpl; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeBlockEntityTicker; import net.minecraft.core.BlockPos; @@ -65,7 +65,7 @@ public DetectorBlock(final DyeColor color, final MutableComponent name) { @Override protected DirectionType getDirectionType() { - return DirectionTypeImpl.INSTANCE; + return DefaultDirectionType.FACE_CLICKED; } @Override 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 4433c8323..004f4c99d 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 @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.network.Network; 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; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; @@ -68,7 +67,7 @@ public NetworkTransmitterBlockEntity(final BlockPos pos, final BlockState state) if (level != null) { LOGGER.debug("Network card was changed at {}, sending network update", worldPosition); setChanged(); - PlatformApi.INSTANCE.onNetworkNodeContainerUpdated(mainContainer, level); + updateContainers(); } }); } @@ -76,20 +75,20 @@ public NetworkTransmitterBlockEntity(final BlockPos pos, final BlockState state) @Override protected void activenessChanged(final boolean newActive) { super.activenessChanged(newActive); - PlatformApi.INSTANCE.onNetworkNodeContainerUpdated(mainContainer, level); + updateContainers(); } public void updateStateInLevel(final BlockState state) { final NetworkTransmitterState currentState = state.getValue(NetworkTransmitterBlock.STATE); - final NetworkTransmitterState newState = getState(); + final NetworkTransmitterState newState = calculateState(); if (currentState != newState && level != null && stateChangeRateLimiter.tryAcquire()) { LOGGER.debug("Updating network transmitter at {} from {} to {}", worldPosition, currentState, newState); level.setBlockAndUpdate(worldPosition, state.setValue(NetworkTransmitterBlock.STATE, newState)); } } - private NetworkTransmitterState getState() { - if (!isActive()) { + private NetworkTransmitterState calculateState() { + if (!mainNode.isActive()) { return NetworkTransmitterState.INACTIVE; } if (receiverKey == null) { @@ -105,7 +104,7 @@ private NetworkTransmitterState getState() { NetworkTransmitterStatus getStatus() { final Network network = mainNode.getNetwork(); - if (!isActive() || network == null || level == null) { + if (!mainNode.isActive() || network == null || level == null) { return INACTIVE; } if (receiverKey == null) { @@ -126,7 +125,7 @@ NetworkTransmitterStatus getStatus() { @Override public void doWork() { super.doWork(); - if (!isActive() || mainNode.getNetwork() == null || receiverKey == null) { + if (!mainNode.isActive() || mainNode.getNetwork() == null || receiverKey == null) { return; } final boolean receiverFound = isReceiverFoundInNetwork(mainNode.getNetwork(), receiverKey); @@ -141,7 +140,7 @@ private void tryReconnectingWithReceiver() { receiverKey, worldPosition ); - PlatformApi.INSTANCE.onNetworkNodeContainerUpdated(mainContainer, level); + updateContainers(); } private static boolean isReceiverFoundInNetwork(final Network network, final NetworkReceiverKey key) { @@ -197,7 +196,7 @@ public NonNullList getDrops() { @Override public void addOutgoingConnections(final ConnectionSink sink) { super.addOutgoingConnections(sink); - if (receiverKey != null && isActive()) { + if (receiverKey != null && mainNode.isActive()) { sink.tryConnect(receiverKey.pos()); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterContainerMenu.java index 812c6083b..83acf1856 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/NetworkTransmitterContainerMenu.java @@ -15,7 +15,6 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Container; -import net.minecraft.world.SimpleContainer; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; @@ -49,7 +48,7 @@ public NetworkTransmitterContainerMenu(final int syncId, this.blockEntity = null; this.player = playerInventory.player; this.status = new NetworkTransmitterStatus(buf.readBoolean(), buf.readComponent()); - addSlots(playerInventory, new SimpleContainer(1)); + addSlots(playerInventory, new NetworkCardInventory()); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlock.java new file mode 100644 index 000000000..b54b36db8 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlock.java @@ -0,0 +1,99 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.platform.common.content.BlockColorMap; +import com.refinedmods.refinedstorage2.platform.common.content.BlockConstants; +import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.Blocks; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractBlockEntityTicker; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractDirectionalBlock; +import com.refinedmods.refinedstorage2.platform.common.support.BaseBlockItem; +import com.refinedmods.refinedstorage2.platform.common.support.BlockItemProvider; +import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; +import com.refinedmods.refinedstorage2.platform.common.support.direction.DefaultDirectionType; +import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionType; +import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeBlockEntityTicker; + +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; + +public class RelayBlock extends AbstractDirectionalBlock + implements EntityBlock, ColorableBlock, BlockItemProvider { + public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); + + private static final AbstractBlockEntityTicker TICKER = new NetworkNodeBlockEntityTicker<>( + BlockEntities.INSTANCE::getRelay, + ACTIVE + ); + + private final MutableComponent name; + private final DyeColor color; + + public RelayBlock(final DyeColor color, final MutableComponent name) { + super(BlockConstants.PROPERTIES); + this.name = name; + this.color = color; + } + + @Override + protected BlockState getDefaultState() { + return super.getDefaultState().setValue(ACTIVE, false); + } + + @Override + protected void createBlockStateDefinition(final StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(ACTIVE); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(final BlockPos blockPos, final BlockState blockState) { + return new RelayBlockEntity(blockPos, blockState); + } + + @Nullable + @Override + public BlockEntityTicker getTicker(final Level level, + final BlockState blockState, + final BlockEntityType type) { + return TICKER.get(level, type); + } + + @Override + protected DirectionType getDirectionType() { + return DefaultDirectionType.FACE_PLAYER; + } + + @Override + public BaseBlockItem createBlockItem() { + return new BaseBlockItem(this); + } + + @Override + public BlockColorMap getBlockColorMap() { + return Blocks.INSTANCE.getRelay(); + } + + @Override + public MutableComponent getName() { + return name; + } + + @Override + public DyeColor getColor() { + return color; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlockEntity.java new file mode 100644 index 000000000..b2b093bf6 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayBlockEntity.java @@ -0,0 +1,246 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayComponentType; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayInputNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayOutputNetworkNode; +import com.refinedmods.refinedstorage2.api.resource.ResourceKey; +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.platform.api.support.network.InWorldNetworkNodeContainer; +import com.refinedmods.refinedstorage2.platform.common.Platform; +import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; +import com.refinedmods.refinedstorage2.platform.common.content.ContentNames; +import com.refinedmods.refinedstorage2.platform.common.storage.AccessModeSettings; +import com.refinedmods.refinedstorage2.platform.common.support.FilterModeSettings; +import com.refinedmods.refinedstorage2.platform.common.support.FilterWithFuzzyMode; +import com.refinedmods.refinedstorage2.platform.common.support.RedstoneMode; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.NetworkNodeMenuProvider; +import com.refinedmods.refinedstorage2.platform.common.support.network.AbstractRedstoneModeNetworkNodeContainerBlockEntity; +import com.refinedmods.refinedstorage2.platform.common.support.resource.ResourceContainerImpl; + +import java.util.HashSet; +import java.util.Set; +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +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; +import net.minecraft.world.level.block.state.BlockState; + +import static java.util.Objects.requireNonNull; + +public class RelayBlockEntity extends AbstractRedstoneModeNetworkNodeContainerBlockEntity + implements NetworkNodeMenuProvider { + private static final String TAG_PASS_THROUGH = "passthrough"; + private static final String TAG_PASS_ENERGY = "passenergy"; + private static final String TAG_PASS_SECURITY = "passsecurity"; + private static final String TAG_PASS_STORAGE = "passstorage"; + private static final String TAG_FILTER_MODE = "fim"; + private static final String TAG_ACCESS_MODE = "am"; + private static final String TAG_PRIORITY = "pri"; + + private final FilterWithFuzzyMode filter; + private final RelayOutputNetworkNode outputNode; + + private boolean passThrough = true; + private FilterMode filterMode = FilterMode.BLOCK; + private AccessMode accessMode = AccessMode.INSERT_EXTRACT; + private int priority = 0; + + public RelayBlockEntity(final BlockPos pos, final BlockState state) { + super(BlockEntities.INSTANCE.getRelay(), pos, state, new RelayInputNetworkNode( + Platform.INSTANCE.getConfig().getRelay().getInputNetworkEnergyUsage() + )); + this.outputNode = new RelayOutputNetworkNode( + Platform.INSTANCE.getConfig().getRelay().getOutputNetworkEnergyUsage() + ); + this.mainNode.setOutputNode(outputNode); + this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( + ResourceContainerImpl.createForFilter(), + this::setChanged, + this::filterContainerChanged + ); + this.mainNode.setFilterNormalizer(filter.createNormalizer()); + this.addContainer(new RelayOutputNetworkNodeContainer(this, outputNode)); + setRedstoneMode(RedstoneMode.LOW); + } + + boolean isFuzzyMode() { + return filter.isFuzzyMode(); + } + + void setFuzzyMode(final boolean fuzzyMode) { + final boolean wasActive = mainNode.isActive(); + // Updating fuzzy mode will call the filter's listener as the normalizer will yield different outputs. + // However, when updating a filter the storage resets and "self-removes". If the normalizer yields different + // outputs too early, the self-remove operation will partially fail as the expected resources will be different. + // Therefore, we need to deactivate the node, update the fuzzy mode, and then reinitialize the node (ugly hack). + mainNode.setActive(false); + filter.setFuzzyMode(fuzzyMode); + mainNode.setActive(wasActive); + } + + private void filterContainerChanged(final Set filters) { + mainNode.setFilters(filters); + setChanged(); + } + + int getPriority() { + return priority; + } + + void setPriority(final int priority) { + this.priority = priority; + this.mainNode.setPriority(priority); + setChanged(); + } + + AccessMode getAccessMode() { + return accessMode; + } + + void setAccessMode(final AccessMode accessMode) { + this.accessMode = accessMode; + mainNode.setAccessMode(accessMode); + setChanged(); + } + + FilterMode getFilterMode() { + return filterMode; + } + + void setFilterMode(final FilterMode filterMode) { + this.filterMode = filterMode; + mainNode.setFilterMode(filterMode); + setChanged(); + } + + boolean isPassEnergy() { + return mainNode.hasComponentType(RelayComponentType.ENERGY); + } + + void setPassEnergy(final boolean passEnergy) { + mainNode.updateComponentType(RelayComponentType.ENERGY, passEnergy); + setChanged(); + } + + boolean isPassStorage() { + return mainNode.hasComponentType(RelayComponentType.STORAGE); + } + + void setPassStorage(final boolean passStorage) { + mainNode.updateComponentType(RelayComponentType.STORAGE, passStorage); + setChanged(); + } + + boolean isPassSecurity() { + return mainNode.hasComponentType(RelayComponentType.SECURITY); + } + + void setPassSecurity(final boolean passSecurity) { + mainNode.updateComponentType(RelayComponentType.SECURITY, passSecurity); + setChanged(); + } + + boolean isPassThrough() { + return passThrough; + } + + void setPassThrough(final boolean passThrough) { + this.passThrough = passThrough; + this.mainNode.setComponentTypes(Set.of()); + setChanged(); + updateContainers(); + } + + boolean isActiveInternal() { + return mainNode.isActive(); + } + + Direction getDirectionInternal() { + return requireNonNull(getDirection()); + } + + @Override + protected void activenessChanged(final boolean newActive) { + super.activenessChanged(newActive); + outputNode.setActive(newActive); + updateContainers(); + } + + @Override + protected InWorldNetworkNodeContainer createMainContainer(final RelayInputNetworkNode node) { + return new RelayInputNetworkNodeContainer(this, node); + } + + @Override + public void writeScreenOpeningData(final ServerPlayer player, final FriendlyByteBuf buf) { + filter.getFilterContainer().writeToUpdatePacket(buf); + } + + @Override + public Component getDisplayName() { + return ContentNames.RELAY; + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(final int syncId, final Inventory inventory, final Player player) { + return new RelayContainerMenu(syncId, player, this, filter.getFilterContainer()); + } + + @Override + public void writeConfiguration(final CompoundTag tag) { + super.writeConfiguration(tag); + filter.save(tag); + tag.putInt(TAG_FILTER_MODE, FilterModeSettings.getFilterMode(filterMode)); + tag.putBoolean(TAG_PASS_THROUGH, passThrough); + tag.putBoolean(TAG_PASS_ENERGY, mainNode.hasComponentType(RelayComponentType.ENERGY)); + tag.putBoolean(TAG_PASS_STORAGE, mainNode.hasComponentType(RelayComponentType.STORAGE)); + tag.putBoolean(TAG_PASS_SECURITY, mainNode.hasComponentType(RelayComponentType.SECURITY)); + tag.putInt(TAG_ACCESS_MODE, AccessModeSettings.getAccessMode(accessMode)); + tag.putInt(TAG_PRIORITY, priority); + } + + @Override + public void readConfiguration(final CompoundTag tag) { + super.readConfiguration(tag); + filter.load(tag); + if (tag.contains(TAG_FILTER_MODE)) { + filterMode = FilterModeSettings.getFilterMode(tag.getInt(TAG_FILTER_MODE)); + } + mainNode.setFilterMode(filterMode); + if (tag.contains(TAG_PASS_THROUGH)) { + passThrough = tag.getBoolean(TAG_PASS_THROUGH); + } + mainNode.setComponentTypes(getComponentTypes(tag)); + if (tag.contains(TAG_ACCESS_MODE)) { + accessMode = AccessModeSettings.getAccessMode(tag.getInt(TAG_ACCESS_MODE)); + } + mainNode.setAccessMode(accessMode); + if (tag.contains(TAG_PRIORITY)) { + priority = tag.getInt(TAG_PRIORITY); + } + mainNode.setPriority(priority); + } + + private Set getComponentTypes(final CompoundTag tag) { + final Set types = new HashSet<>(); + if (tag.getBoolean(TAG_PASS_ENERGY)) { + types.add(RelayComponentType.ENERGY); + } + if (tag.getBoolean(TAG_PASS_SECURITY)) { + types.add(RelayComponentType.SECURITY); + } + if (tag.getBoolean(TAG_PASS_STORAGE)) { + types.add(RelayComponentType.STORAGE); + } + return types; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayContainerMenu.java new file mode 100644 index 000000000..86a6494e7 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayContainerMenu.java @@ -0,0 +1,154 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage2.api.storage.AccessMode; +import com.refinedmods.refinedstorage2.platform.api.support.resource.ResourceContainer; +import com.refinedmods.refinedstorage2.platform.common.content.Menus; +import com.refinedmods.refinedstorage2.platform.common.storage.StoragePropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.support.RedstoneMode; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.AbstractSimpleFilterContainerMenu; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ServerProperty; + +import javax.annotation.Nullable; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +public class RelayContainerMenu extends AbstractSimpleFilterContainerMenu { + private static final MutableComponent FILTER_HELP = createTranslation("gui", "relay.filter_help"); + + @Nullable + private PassThroughListener passThroughListener; + + public RelayContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { + super( + Menus.INSTANCE.getRelay(), + syncId, + playerInventory.player, + buf, + null, + FILTER_HELP + ); + } + + RelayContainerMenu(final int syncId, + final Player player, + final RelayBlockEntity relay, + final ResourceContainer resourceContainer) { + super( + Menus.INSTANCE.getRelay(), + syncId, + player, + resourceContainer, + null, + relay, + FILTER_HELP + ); + } + + @Override + protected void registerClientProperties() { + registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); + registerProperty(new ClientProperty<>(RelayPropertyTypes.PASS_THROUGH, true) { + @Override + protected void onChangedOnClient(final Boolean newValue) { + super.onChangedOnClient(newValue); + if (passThroughListener != null) { + passThroughListener.passThroughChanged( + Boolean.TRUE.equals(newValue), + Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_STORAGE).getValue()) + ); + } + } + }); + registerProperty(new ClientProperty<>(RelayPropertyTypes.PASS_ENERGY, false)); + registerProperty(new ClientProperty<>(RelayPropertyTypes.PASS_STORAGE, false) { + @Override + protected void onChangedOnClient(final Boolean newValue) { + super.onChangedOnClient(newValue); + if (passThroughListener != null) { + passThroughListener.passThroughChanged( + Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_THROUGH).getValue()), + Boolean.TRUE.equals(newValue) + ); + } + } + }); + registerProperty(new ClientProperty<>(RelayPropertyTypes.PASS_SECURITY, false)); + registerProperty(new ClientProperty<>(PropertyTypes.FILTER_MODE, FilterMode.BLOCK)); + registerProperty(new ClientProperty<>(StoragePropertyTypes.ACCESS_MODE, AccessMode.INSERT_EXTRACT)); + registerProperty(new ClientProperty<>(StoragePropertyTypes.PRIORITY, 0)); + registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); + } + + @Override + protected void registerServerProperties(final RelayBlockEntity blockEntity) { + registerProperty(new ServerProperty<>( + PropertyTypes.REDSTONE_MODE, + blockEntity::getRedstoneMode, + blockEntity::setRedstoneMode + )); + registerProperty(new ServerProperty<>( + RelayPropertyTypes.PASS_THROUGH, + blockEntity::isPassThrough, + blockEntity::setPassThrough + )); + registerProperty(new ServerProperty<>( + RelayPropertyTypes.PASS_ENERGY, + blockEntity::isPassEnergy, + blockEntity::setPassEnergy + )); + registerProperty(new ServerProperty<>( + RelayPropertyTypes.PASS_STORAGE, + blockEntity::isPassStorage, + blockEntity::setPassStorage + )); + registerProperty(new ServerProperty<>( + RelayPropertyTypes.PASS_SECURITY, + blockEntity::isPassSecurity, + blockEntity::setPassSecurity + )); + registerProperty(new ServerProperty<>( + PropertyTypes.FILTER_MODE, + blockEntity::getFilterMode, + blockEntity::setFilterMode + )); + registerProperty(new ServerProperty<>( + StoragePropertyTypes.ACCESS_MODE, + blockEntity::getAccessMode, + blockEntity::setAccessMode + )); + registerProperty(new ServerProperty<>( + StoragePropertyTypes.PRIORITY, + blockEntity::getPriority, + blockEntity::setPriority + )); + registerProperty(new ServerProperty<>( + PropertyTypes.FUZZY_MODE, + blockEntity::isFuzzyMode, + blockEntity::setFuzzyMode + )); + } + + boolean isPassThrough() { + return Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_THROUGH).getValue()); + } + + boolean isPassStorage() { + return Boolean.TRUE.equals(getProperty(RelayPropertyTypes.PASS_STORAGE).getValue()); + } + + void setPassThroughListener(final PassThroughListener passThroughListener) { + this.passThroughListener = passThroughListener; + } + + interface PassThroughListener { + void passThroughChanged(boolean passThrough, boolean passStorage); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayInputNetworkNodeContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayInputNetworkNodeContainer.java new file mode 100644 index 000000000..f20428859 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayInputNetworkNodeContainer.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.api.network.node.NetworkNode; +import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; +import com.refinedmods.refinedstorage2.platform.common.support.network.InWorldNetworkNodeContainerImpl; + +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.state.BlockState; + +class RelayInputNetworkNodeContainer extends InWorldNetworkNodeContainerImpl { + private final RelayBlockEntity blockEntity; + + RelayInputNetworkNodeContainer(final RelayBlockEntity blockEntity, final NetworkNode node) { + super(blockEntity, node, "input", 0, blockEntity, null); + this.blockEntity = blockEntity; + } + + @Override + public void addOutgoingConnections(final ConnectionSink sink) { + final Direction direction = blockEntity.getDirectionInternal(); + for (final Direction otherDirection : Direction.values()) { + if (otherDirection != direction || (blockEntity.isPassThrough() && blockEntity.isActiveInternal())) { + sink.tryConnectInSameDimension( + blockEntity.getBlockPos().relative(otherDirection), + otherDirection.getOpposite() + ); + } + } + } + + @Override + public boolean canAcceptIncomingConnection(final Direction incomingDirection, final BlockState connectingState) { + return incomingDirection != blockEntity.getDirectionInternal() + || (blockEntity.isPassThrough() && blockEntity.isActiveInternal()); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOutputNetworkNodeContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOutputNetworkNodeContainer.java new file mode 100644 index 000000000..0d45d4d91 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayOutputNetworkNodeContainer.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.api.network.impl.node.relay.RelayOutputNetworkNode; +import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; +import com.refinedmods.refinedstorage2.platform.common.support.network.InWorldNetworkNodeContainerImpl; + +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.state.BlockState; + +class RelayOutputNetworkNodeContainer extends InWorldNetworkNodeContainerImpl { + private final RelayBlockEntity blockEntity; + + RelayOutputNetworkNodeContainer(final RelayBlockEntity blockEntity, final RelayOutputNetworkNode node) { + super(blockEntity, node, "output", 0, blockEntity, null); + this.blockEntity = blockEntity; + } + + // The output network node container must always have an outgoing and incoming connection. + // If not, network node containers after the output network node container may end up without a network + // because the graph algorithm won't be able to work properly and won't be able to reassign a new network. + // The output network node container *never* provides a connection with the input network node container. + // The input network node container controls whether the output network node container is connected. + @Override + public void addOutgoingConnections(final ConnectionSink sink) { + final Direction direction = blockEntity.getDirectionInternal(); + sink.tryConnectInSameDimension( + blockEntity.getBlockPos().relative(direction), + direction.getOpposite() + ); + } + + @Override + public boolean canAcceptIncomingConnection(final Direction incomingDirection, final BlockState connectingState) { + return incomingDirection == blockEntity.getDirectionInternal(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassEnergySideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassEnergySideButtonWidget.java new file mode 100644 index 000000000..731881458 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassEnergySideButtonWidget.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractYesNoSideButtonWidget; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +class RelayPassEnergySideButtonWidget extends AbstractYesNoSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "relay.pass_energy"); + private static final MutableComponent HELP = createTranslation("gui", "relay.pass_energy.help"); + + RelayPassEnergySideButtonWidget(final ClientProperty property) { + super(property, TITLE); + } + + @Override + protected int getXTexture() { + return Boolean.TRUE.equals(property.getValue()) ? 128 : 144; + } + + @Override + protected int getYTexture() { + return 0; + } + + @Nullable + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassSecuritySideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassSecuritySideButtonWidget.java new file mode 100644 index 000000000..6e9271ac3 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassSecuritySideButtonWidget.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractYesNoSideButtonWidget; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +class RelayPassSecuritySideButtonWidget extends AbstractYesNoSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "relay.pass_security"); + private static final MutableComponent HELP = createTranslation("gui", "relay.pass_security.help"); + + RelayPassSecuritySideButtonWidget(final ClientProperty property) { + super(property, TITLE); + } + + @Override + protected int getXTexture() { + return Boolean.TRUE.equals(property.getValue()) ? 128 : 144; + } + + @Override + protected int getYTexture() { + return 32; + } + + @Nullable + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassStorageSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassStorageSideButtonWidget.java new file mode 100644 index 000000000..b6ec659fb --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassStorageSideButtonWidget.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractYesNoSideButtonWidget; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +class RelayPassStorageSideButtonWidget extends AbstractYesNoSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "relay.pass_storage"); + private static final MutableComponent HELP = createTranslation("gui", "relay.pass_storage.help"); + + RelayPassStorageSideButtonWidget(final ClientProperty property) { + super(property, TITLE); + } + + @Override + protected int getXTexture() { + return Boolean.TRUE.equals(property.getValue()) ? 128 : 144; + } + + @Override + protected int getYTexture() { + return 16; + } + + @Nullable + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassThroughSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassThroughSideButtonWidget.java new file mode 100644 index 000000000..654761ace --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPassThroughSideButtonWidget.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractYesNoSideButtonWidget; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +class RelayPassThroughSideButtonWidget extends AbstractYesNoSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "relay.pass_through"); + private static final MutableComponent HELP = createTranslation("gui", "relay.pass_through.help"); + + RelayPassThroughSideButtonWidget(final ClientProperty property) { + super(property, TITLE); + } + + @Override + protected int getXTexture() { + return Boolean.TRUE.equals(property.getValue()) ? 96 : 112; + } + + @Override + protected int getYTexture() { + return 0; + } + + @Nullable + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPropertyTypes.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPropertyTypes.java new file mode 100644 index 000000000..bb63de761 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayPropertyTypes.java @@ -0,0 +1,24 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyType; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createIdentifier; + +final class RelayPropertyTypes { + static final PropertyType PASS_THROUGH = PropertyTypes.createBooleanProperty( + createIdentifier("pass_through") + ); + static final PropertyType PASS_ENERGY = PropertyTypes.createBooleanProperty( + createIdentifier("pass_energy") + ); + static final PropertyType PASS_STORAGE = PropertyTypes.createBooleanProperty( + createIdentifier("pass_storage") + ); + static final PropertyType PASS_SECURITY = PropertyTypes.createBooleanProperty( + createIdentifier("pass_security") + ); + + private RelayPropertyTypes() { + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayScreen.java new file mode 100644 index 000000000..0192726f9 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/networking/RelayScreen.java @@ -0,0 +1,147 @@ +package com.refinedmods.refinedstorage2.platform.common.networking; + +import com.refinedmods.refinedstorage2.platform.common.storage.AccessModeSideButtonWidget; +import com.refinedmods.refinedstorage2.platform.common.storage.FilterModeSideButtonWidget; +import com.refinedmods.refinedstorage2.platform.common.storage.PrioritySideButtonWidget; +import com.refinedmods.refinedstorage2.platform.common.storage.StoragePropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.support.AbstractFilterScreen; +import com.refinedmods.refinedstorage2.platform.common.support.containermenu.PropertyTypes; +import com.refinedmods.refinedstorage2.platform.common.support.widget.AbstractSideButtonWidget; +import com.refinedmods.refinedstorage2.platform.common.support.widget.FuzzyModeSideButtonWidget; + +import javax.annotation.Nullable; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.world.entity.player.Inventory; + +import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; + +public class RelayScreen extends AbstractFilterScreen + implements RelayContainerMenu.PassThroughListener { + private static final MutableComponent ALLOW_FILTER_MODE_HELP = createTranslation( + "gui", + "relay.filter_mode.allow.help" + ); + private static final MutableComponent BLOCK_FILTER_MODE_HELP = createTranslation( + "gui", + "relay.filter_mode.block.help" + ); + + private final Inventory playerInventory; + + @Nullable + private AbstractSideButtonWidget passEnergyButton; + @Nullable + private AbstractSideButtonWidget passSecurityButton; + @Nullable + private AbstractSideButtonWidget passStorageButton; + @Nullable + private AbstractSideButtonWidget filterModeButton; + @Nullable + private AbstractSideButtonWidget fuzzyModeButton; + @Nullable + private AbstractSideButtonWidget accessModeButton; + @Nullable + private AbstractSideButtonWidget priorityButton; + + public RelayScreen(final RelayContainerMenu menu, final Inventory playerInventory, final Component text) { + super(menu, playerInventory, text); + this.playerInventory = playerInventory; + menu.setPassThroughListener(this); + } + + @Override + protected boolean hasUpgrades() { + return false; + } + + @Override + protected void init() { + super.init(); + addSideButton(new RelayPassThroughSideButtonWidget(getMenu().getProperty(RelayPropertyTypes.PASS_THROUGH))); + final boolean visible = !getMenu().isPassThrough(); + addPassButtons(visible); + addStorageButtons(visible && getMenu().isPassStorage()); + } + + private void addPassButtons(final boolean visible) { + passEnergyButton = new RelayPassEnergySideButtonWidget(getMenu().getProperty(RelayPropertyTypes.PASS_ENERGY)); + passEnergyButton.visible = visible; + addSideButton(passEnergyButton); + + passSecurityButton = new RelayPassSecuritySideButtonWidget( + getMenu().getProperty(RelayPropertyTypes.PASS_SECURITY) + ); + passSecurityButton.visible = visible; + addSideButton(passSecurityButton); + + passStorageButton = new RelayPassStorageSideButtonWidget( + getMenu().getProperty(RelayPropertyTypes.PASS_STORAGE) + ); + passStorageButton.visible = visible; + addSideButton(passStorageButton); + } + + private void addStorageButtons(final boolean visible) { + filterModeButton = new FilterModeSideButtonWidget( + getMenu().getProperty(PropertyTypes.FILTER_MODE), + ALLOW_FILTER_MODE_HELP, + BLOCK_FILTER_MODE_HELP + ); + filterModeButton.visible = visible; + addSideButton(filterModeButton); + + fuzzyModeButton = new FuzzyModeSideButtonWidget( + getMenu().getProperty(PropertyTypes.FUZZY_MODE), + FuzzyModeSideButtonWidget.Type.STORAGE + ); + fuzzyModeButton.visible = visible; + addSideButton(fuzzyModeButton); + + accessModeButton = new AccessModeSideButtonWidget(getMenu().getProperty(StoragePropertyTypes.ACCESS_MODE)); + accessModeButton.visible = visible; + addSideButton(accessModeButton); + + priorityButton = new PrioritySideButtonWidget( + getMenu().getProperty(StoragePropertyTypes.PRIORITY), + playerInventory, + this + ); + priorityButton.visible = visible; + addSideButton(priorityButton); + } + + @Override + public void passThroughChanged(final boolean passThrough, final boolean passStorage) { + updatePassButtons(passThrough); + updateStorageButtons(passThrough, passStorage); + } + + private void updatePassButtons(final boolean passThrough) { + if (passEnergyButton != null) { + passEnergyButton.visible = !passThrough; + } + if (passSecurityButton != null) { + passSecurityButton.visible = !passThrough; + } + if (passStorageButton != null) { + passStorageButton.visible = !passThrough; + } + } + + private void updateStorageButtons(final boolean passThrough, final boolean passStorage) { + if (filterModeButton != null) { + filterModeButton.visible = !passThrough && passStorage; + } + if (fuzzyModeButton != null) { + fuzzyModeButton.visible = !passThrough && passStorage; + } + if (accessModeButton != null) { + accessModeButton.visible = !passThrough && passStorage; + } + if (priorityButton != null) { + priorityButton.visible = !passThrough && passStorage; + } + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AccessModeSettings.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AccessModeSettings.java index 1672f1fe7..200ffa503 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AccessModeSettings.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/storage/AccessModeSettings.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage2.api.storage.AccessMode; -class AccessModeSettings { +public class AccessModeSettings { private static final int INSERT_EXTRACT = 0; private static final int INSERT = 1; private static final int EXTRACT = 2; @@ -10,7 +10,7 @@ class AccessModeSettings { private AccessModeSettings() { } - static AccessMode getAccessMode(final int accessMode) { + public static AccessMode getAccessMode(final int accessMode) { return switch (accessMode) { case INSERT_EXTRACT -> AccessMode.INSERT_EXTRACT; case INSERT -> AccessMode.INSERT; @@ -19,7 +19,7 @@ static AccessMode getAccessMode(final int accessMode) { }; } - static int getAccessMode(final AccessMode accessMode) { + public static int getAccessMode(final AccessMode accessMode) { return switch (accessMode) { case INSERT_EXTRACT -> INSERT_EXTRACT; case INSERT -> INSERT; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractDirectionalCableBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractDirectionalCableBlock.java index d75d8310e..f7651d654 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractDirectionalCableBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractDirectionalCableBlock.java @@ -1,8 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.support; import com.refinedmods.refinedstorage2.platform.common.content.BlockConstants; +import com.refinedmods.refinedstorage2.platform.common.support.direction.DefaultDirectionType; import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionType; -import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionTypeImpl; import java.util.Map; import java.util.Objects; @@ -38,7 +38,7 @@ protected AbstractDirectionalCableBlock(final Map getDirectionType() { - return DirectionTypeImpl.INSTANCE; + return DefaultDirectionType.FACE_CLICKED; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java index 86ea9e9c6..f188c0f38 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/AbstractFilterScreen.java @@ -17,10 +17,14 @@ protected AbstractFilterScreen(final T menu, final Component text) { super(menu, playerInventory, text); this.inventoryLabelY = 42; - this.imageWidth = 210; + this.imageWidth = hasUpgrades() ? 210 : 176; this.imageHeight = 137; } + protected boolean hasUpgrades() { + return true; + } + @Override protected void init() { super.init(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractSimpleFilterContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractSimpleFilterContainerMenu.java index abda2b6ec..385536763 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractSimpleFilterContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/AbstractSimpleFilterContainerMenu.java @@ -7,6 +7,8 @@ import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeDestinations; import com.refinedmods.refinedstorage2.platform.common.upgrade.UpgradeSlot; +import javax.annotation.Nullable; + import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; @@ -25,7 +27,7 @@ protected AbstractSimpleFilterContainerMenu(final MenuType type, final int syncId, final Player player, final ResourceContainer resourceContainer, - final UpgradeContainer upgradeContainer, + @Nullable final UpgradeContainer upgradeContainer, final T blockEntity, final Component filterHelp) { super(type, syncId, player); @@ -38,7 +40,7 @@ protected AbstractSimpleFilterContainerMenu(final MenuType type, final int syncId, final Player player, final FriendlyByteBuf buf, - final UpgradeDestinations upgradeDestination, + @Nullable final UpgradeDestinations upgradeDestination, final Component filterHelp) { super(type, syncId); this.filterHelp = filterHelp; @@ -46,7 +48,9 @@ protected AbstractSimpleFilterContainerMenu(final MenuType type, addSlots( player, ResourceContainerImpl.createForFilter(), - new UpgradeContainer(upgradeDestination, PlatformApi.INSTANCE.getUpgradeRegistry()) + upgradeDestination == null + ? null + : new UpgradeContainer(upgradeDestination, PlatformApi.INSTANCE.getUpgradeRegistry()) ); initializeResourceSlots(buf); } @@ -57,16 +61,20 @@ protected AbstractSimpleFilterContainerMenu(final MenuType type, private void addSlots(final Player player, final ResourceContainer resourceContainer, - final UpgradeContainer upgradeContainer) { + @Nullable final UpgradeContainer upgradeContainer) { for (int i = 0; i < resourceContainer.size(); ++i) { addSlot(createFilterSlot(resourceContainer, i)); } - for (int i = 0; i < upgradeContainer.getContainerSize(); ++i) { - addSlot(new UpgradeSlot(upgradeContainer, i, 187, 6 + (i * 18))); + if (upgradeContainer != null) { + for (int i = 0; i < upgradeContainer.getContainerSize(); ++i) { + addSlot(new UpgradeSlot(upgradeContainer, i, 187, 6 + (i * 18))); + } } addPlayerInventory(player.getInventory(), 8, 55); - transferManager.addBiTransfer(player.getInventory(), upgradeContainer); + if (upgradeContainer != null) { + transferManager.addBiTransfer(player.getInventory(), upgradeContainer); + } transferManager.addFilterTransfer(player.getInventory()); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ClientProperty.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ClientProperty.java index a22d53f7f..d78d56b35 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ClientProperty.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/containermenu/ClientProperty.java @@ -43,5 +43,10 @@ public int get() { public void set(final int newValue) { this.value = type.deserializer().apply(newValue); this.rawValue = newValue; + onChangedOnClient(value); + } + + protected void onChangedOnClient(final T newValue) { + // do nothing by default } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/direction/DirectionTypeImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/direction/DefaultDirectionType.java similarity index 61% rename from refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/direction/DirectionTypeImpl.java rename to refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/direction/DefaultDirectionType.java index 039d6941b..e2e003aed 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/direction/DirectionTypeImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/direction/DefaultDirectionType.java @@ -3,12 +3,16 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.properties.EnumProperty; -public class DirectionTypeImpl implements DirectionType { - public static final DirectionType INSTANCE = new DirectionTypeImpl(); +public class DefaultDirectionType implements DirectionType { + public static final DirectionType FACE_CLICKED = new DefaultDirectionType(false); + public static final DirectionType FACE_PLAYER = new DefaultDirectionType(true); private static final EnumProperty PROPERTY = EnumProperty.create("direction", Direction.class); - private DirectionTypeImpl() { + private final boolean facePlayer; + + private DefaultDirectionType(final boolean facePlayer) { + this.facePlayer = facePlayer; } @Override @@ -28,6 +32,14 @@ public Direction extractDirection(final Direction direction) { @Override public Direction getDirection(final Direction clickedFace, final Direction playerFacing, final float playerPitch) { + if (facePlayer) { + if (playerPitch > 65) { + return Direction.UP; + } else if (playerPitch < -65) { + return Direction.DOWN; + } + return playerFacing.getOpposite(); + } return clickedFace.getOpposite(); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java index ebffd0c75..e3c8f2bc5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractLevelInteractingNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java index f4393f4fa..e54dbc67a 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractRedstoneModeNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.configurationcard.ConfigurationCardTarget; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.support.PlayerAwareBlockEntity; @@ -35,8 +35,10 @@ protected AbstractRedstoneModeNetworkNodeContainerBlockEntity(final BlockEntityT } @Override - protected boolean isActive() { - return super.isActive() && level != null && redstoneMode.isActive(level.hasNeighborSignal(worldPosition)); + protected boolean calculateActive() { + return super.calculateActive() + && level != null + && redstoneMode.isActive(level.hasNeighborSignal(worldPosition)); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java index 6ca816d94..df09b565f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractSchedulingNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.api.network.node.task.TaskExecutor; import com.refinedmods.refinedstorage2.api.resource.ResourceKey; import com.refinedmods.refinedstorage2.platform.common.support.FilterWithFuzzyMode; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java index 69dc02d40..6939537ae 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/AbstractUpgradeableNetworkNodeContainerBlockEntity.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.content.Items; import com.refinedmods.refinedstorage2.platform.common.support.BlockEntityWithDrops; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/BaseNetworkNodeContainerBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/BaseNetworkNodeContainerBlockEntity.java index 25b5f6978..f995dcdb0 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/BaseNetworkNodeContainerBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/BaseNetworkNodeContainerBlockEntity.java @@ -2,8 +2,7 @@ import com.refinedmods.refinedstorage2.api.network.Network; 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.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.support.network.AbstractNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionLogic; import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionSink; @@ -36,7 +35,7 @@ public BaseNetworkNodeContainerBlockEntity(final BlockEntityType type, super(type, pos, state, networkNode); } - protected boolean isActive() { + protected boolean calculateActive() { final long energyUsage = mainNode.getEnergyUsage(); final boolean hasLevel = level != null && level.isLoaded(worldPosition); return hasLevel @@ -45,7 +44,7 @@ protected boolean isActive() { } public void updateActiveness(final BlockState state, @Nullable final BooleanProperty activenessProperty) { - final boolean newActive = isActive(); + final boolean newActive = calculateActive(); final boolean nodeActivenessNeedsUpdate = newActive != mainNode.isActive(); final boolean blockStateActivenessNeedsUpdate = activenessProperty != null && state.getValue(activenessProperty) != newActive; @@ -155,7 +154,7 @@ public void setBlockState(final BlockState newBlockState) { if (!doesBlockStateChangeWarrantNetworkNodeUpdate(oldBlockState, newBlockState)) { return; } - PlatformApi.INSTANCE.onNetworkNodeContainerUpdated(mainContainer, level); + updateContainers(); } @Nullable diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java index 9522e3acf..24eaa11d4 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/network/NetworkNodeBlockEntityTicker.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.support.network; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.common.support.AbstractBlockEntityTicker; import java.util.function.Supplier; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java index e4208b8fd..4aa279714 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/support/widget/AbstractSideButtonWidget.java @@ -50,7 +50,15 @@ public void setWarning(@Nullable final Component text) { @Override public void renderWidget(final GuiGraphics graphics, final int mouseX, final int mouseY, final float partialTicks) { graphics.blit(getTextureIdentifier(), getX(), getY(), 238, isHovered ? 35 : 16, WIDTH, HEIGHT); - graphics.blit(getTextureIdentifier(), getX() + 1, getY() + 1, getXTexture(), getYTexture(), WIDTH, HEIGHT); + graphics.blit( + getTextureIdentifier(), + getX() + 1, + getY() + 1, + getXTexture(), + getYTexture(), + WIDTH - 2, + HEIGHT - 2 + ); if (isHovered) { RenderSystem.enableBlend(); RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java index b45d2187c..c3fb469b9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterBlock.java @@ -10,8 +10,8 @@ import com.refinedmods.refinedstorage2.platform.common.support.BlockItemProvider; import com.refinedmods.refinedstorage2.platform.common.support.ColorableBlock; import com.refinedmods.refinedstorage2.platform.common.support.NetworkNodeBlockItem; +import com.refinedmods.refinedstorage2.platform.common.support.direction.DefaultDirectionType; import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionType; -import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionTypeImpl; import com.refinedmods.refinedstorage2.platform.common.support.network.NetworkNodeBlockEntityTicker; import javax.annotation.Nullable; @@ -75,7 +75,7 @@ protected void createBlockStateDefinition(final StateDefinition.Builder getDirectionType() { - return DirectionTypeImpl.INSTANCE; + return DefaultDirectionType.FACE_CLICKED; } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterNetworkNodeContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterNetworkNodeContainer.java index 35948cc97..dc65fa1e1 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterNetworkNodeContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/wirelesstransmitter/WirelessTransmitterNetworkNodeContainer.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter; -import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode; +import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode; import com.refinedmods.refinedstorage2.platform.api.support.network.ConnectionLogic; import com.refinedmods.refinedstorage2.platform.api.wirelesstransmitter.WirelessTransmitter; import com.refinedmods.refinedstorage2.platform.common.support.network.InWorldNetworkNodeContainerImpl; 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 36f89262b..6e06c5772 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 @@ -34,6 +34,8 @@ "block.refinedstorage2.creative_portable_grid": "Creative Portable Grid", "block.refinedstorage2.security_manager": "Security Manager", "block.refinedstorage2.security_manager.help": "When this device is active, will protect the network by default and block all operations. Start adding Security Cards to permit or deny specific operations for a player.", + "block.refinedstorage2.relay": "Relay", + "block.refinedstorage2.relay.help": "Turn entire sections of a storage network on or off and create new branches of your network with a Relay.", "gui.refinedstorage2.controller.redstone_mode_help": "When this device is inactive, the storage network will not be able to use this device as an energy source.", "gui.refinedstorage2.disk_drive.disks": "Disks", "gui.refinedstorage2.storage.redstone_mode_help": "When this device is inactive, the contained storage will no longer be accessible from within the storage network.", @@ -149,6 +151,17 @@ "gui.refinedstorage2.security_manager.redstone_mode_help": "When this device is inactive, the network will not be protected.", "gui.refinedstorage2.security_manager.fallback_security_card_slot_hint": "Slot for a Fallback Security Card.", "gui.refinedstorage2.security_manager.no_fallback_security_card_consequence": "Add a Fallback Security Card to this slot to set permissions for every player without a Security Card. By default, all actions are denied.", + "gui.refinedstorage2.relay.filter_help": "Resources which should be exposed from the input network to the output network if the Relay isn't in pass-through mode.", + "gui.refinedstorage2.relay.pass_through": "Pass-through", + "gui.refinedstorage2.relay.pass_through.help": "Whether this device should pass-through the entire input network signal as-is. Turn this off to selectively expose components to the output network.", + "gui.refinedstorage2.relay.pass_energy": "Pass energy", + "gui.refinedstorage2.relay.pass_energy.help": "Whether this device should pass the energy buffer from the input network to the output network.", + "gui.refinedstorage2.relay.pass_storage": "Pass storage", + "gui.refinedstorage2.relay.pass_storage.help": "Whether this device should pass the storage from the input network to the output network.", + "gui.refinedstorage2.relay.pass_security": "Pass security", + "gui.refinedstorage2.relay.pass_security.help": "Whether this device should pass the security settings from the input network to the output network.", + "gui.refinedstorage2.relay.filter_mode.allow.help": "Only expose resources from the input network to the output network that are configured in the filters.", + "gui.refinedstorage2.relay.filter_mode.block.help": "Don't expose resources from the input network to the output network that are configured in the filters.", "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.", @@ -367,6 +380,9 @@ "text.autoconfig.refinedstorage2.option.fallbackSecurityCard.energyUsage": "Energy usage", "text.autoconfig.refinedstorage2.option.securityManager": "Security Manager", "text.autoconfig.refinedstorage2.option.securityManager.energyUsage": "Energy usage", + "text.autoconfig.refinedstorage2.option.relay": "Relay", + "text.autoconfig.refinedstorage2.option.relay.inputNetworkEnergyUsage": "Input network energy usage", + "text.autoconfig.refinedstorage2.option.relay.outputNetworkEnergyUsage": "Output network energy usage (if not in pass through mode)", "advancements.refinedstorage2.root.description": "Use one or multiple Controllers in a storage network to provide your network with energy", "advancements.refinedstorage2.connecting": "Connecting", "advancements.refinedstorage2.connecting.description": "Use Cable to connect devices with each other, or place devices against each other", @@ -405,5 +421,7 @@ "advancements.refinedstorage2.portable_storage": "Portable storage", "advancements.refinedstorage2.portable_storage.description": "Craft a Portable Grid to access the content of disks without requiring a storage network", "advancements.refinedstorage2.security": "Security", - "advancements.refinedstorage2.security.description": "Secure your storage network with a Security Manager and a Security Card" + "advancements.refinedstorage2.security.description": "Secure your storage network with a Security Manager and a Security Card", + "advancements.refinedstorage2.conditional_connecting": "Conditional connecting", + "advancements.refinedstorage2.conditional_connecting.description": "Turn entire sections of a storage network on or off and create new branches of your network with a Relay" } diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/black.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/black.png new file mode 100644 index 000000000..af499530b Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/black.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/blue.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/blue.png new file mode 100644 index 000000000..46829ae7b Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/blue.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/brown.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/brown.png new file mode 100644 index 000000000..bf56d8d1a Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/brown.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/cyan.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/cyan.png new file mode 100644 index 000000000..fae40f424 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/cyan.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/gray.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/gray.png new file mode 100644 index 000000000..96e238a62 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/gray.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/green.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/green.png new file mode 100644 index 000000000..e267c752d Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/green.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/inactive.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/inactive.png new file mode 100644 index 000000000..b1bf0e090 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/inactive.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/light_blue.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/light_blue.png new file mode 100644 index 000000000..eb9f85c5c Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/light_blue.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/light_gray.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/light_gray.png new file mode 100644 index 000000000..726db1049 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/light_gray.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/lime.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/lime.png new file mode 100644 index 000000000..7256027cc Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/lime.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/magenta.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/magenta.png new file mode 100644 index 000000000..ff10df67c Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/magenta.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/orange.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/orange.png new file mode 100644 index 000000000..c7e7005be Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/orange.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/pink.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/pink.png new file mode 100644 index 000000000..6484c6abd Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/pink.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/purple.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/purple.png new file mode 100644 index 000000000..a5bbe779a Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/purple.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/red.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/red.png new file mode 100644 index 000000000..696340348 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/red.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/white.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/white.png new file mode 100644 index 000000000..77d9b52b7 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/white.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/yellow.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/yellow.png new file mode 100644 index 000000000..434b96252 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/in/yellow.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/black.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/black.png new file mode 100644 index 000000000..58f7b9244 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/black.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/blue.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/blue.png new file mode 100644 index 000000000..00d6eb6f0 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/blue.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/brown.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/brown.png new file mode 100644 index 000000000..63204a3af Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/brown.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/cyan.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/cyan.png new file mode 100644 index 000000000..dc7165708 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/cyan.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/gray.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/gray.png new file mode 100644 index 000000000..f529f259e Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/gray.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/green.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/green.png new file mode 100644 index 000000000..77523987d Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/green.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/inactive.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/inactive.png new file mode 100644 index 000000000..b5bc63f8f Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/inactive.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/light_blue.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/light_blue.png new file mode 100644 index 000000000..a6b017a44 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/light_blue.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/light_gray.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/light_gray.png new file mode 100644 index 000000000..fca72ba2e Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/light_gray.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/lime.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/lime.png new file mode 100644 index 000000000..d2dc60135 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/lime.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/magenta.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/magenta.png new file mode 100644 index 000000000..039d61ef9 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/magenta.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/orange.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/orange.png new file mode 100644 index 000000000..7389d27e3 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/orange.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/pink.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/pink.png new file mode 100644 index 000000000..7991ef0d9 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/pink.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/purple.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/purple.png new file mode 100644 index 000000000..204cbc55c Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/purple.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/red.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/red.png new file mode 100644 index 000000000..d4b83ce38 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/red.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/white.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/white.png new file mode 100644 index 000000000..ddbc7f2dd Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/white.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/yellow.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/yellow.png new file mode 100644 index 000000000..b6fcecf4b Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/cutouts/out/yellow.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/in.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/in.png new file mode 100644 index 000000000..11dd25763 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/in.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/out.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/out.png new file mode 100644 index 000000000..f0fdad1d7 Binary files /dev/null and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/block/relay/out.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png index 340761a2d..f6fd2d99e 100644 Binary files a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png and b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/textures/icons.png differ diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/conditional_connecting.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/conditional_connecting.json new file mode 100644 index 000000000..28a80e541 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/advancements/conditional_connecting.json @@ -0,0 +1,26 @@ +{ + "display": { + "icon": { + "item": "refinedstorage2:relay" + }, + "title": { + "translate": "advancements.refinedstorage2.conditional_connecting" + }, + "description": { + "translate": "advancements.refinedstorage2.conditional_connecting.description" + } + }, + "parent": "refinedstorage2:connecting", + "criteria": { + "relay_in_inventory": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "tag": "refinedstorage2:relays" + } + ] + } + } + } +} \ No newline at end of file diff --git a/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/relay.json b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/relay.json new file mode 100644 index 000000000..47503ccd9 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/resources/data/refinedstorage2/recipes/relay.json @@ -0,0 +1,20 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { + "item": "refinedstorage2:machine_casing" + }, + { + "item": "refinedstorage2:cable" + }, + { + "item": "refinedstorage2:advanced_processor" + }, + { + "item": "minecraft:redstone_torch" + } + ], + "result": { + "item": "refinedstorage2:relay" + } +} \ 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 7e8ead76a..44e702874 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 @@ -120,6 +120,7 @@ private void setRenderLayers() { setCutout(Blocks.INSTANCE.getPortableGrid()); setCutout(Blocks.INSTANCE.getCreativePortableGrid()); setCutout(Blocks.INSTANCE.getSecurityManager()); + setCutout(Blocks.INSTANCE.getRelay()); } private void setCutout(final BlockColorMap blockMap) { @@ -168,6 +169,9 @@ private void registerEmissiveModels() { Blocks.INSTANCE.getSecurityManager().forEach( (color, id, block) -> registerEmissiveSecurityManagerModels(color, id) ); + Blocks.INSTANCE.getRelay().forEach( + (color, id, block) -> registerEmissiveRelayModels(color, id) + ); } private void registerEmissiveControllerModels(final DyeColor color) { @@ -298,6 +302,21 @@ private void registerEmissiveSecurityManagerModels(final DyeColor color, final R ); } + private void registerEmissiveRelayModels(final DyeColor color, final ResourceLocation id) { + // Block + EmissiveModelRegistry.INSTANCE.register( + createIdentifier("block/relay/" + color.getName()), + createIdentifier("block/relay/cutouts/in/" + color.getName()), + createIdentifier("block/relay/cutouts/out/" + color.getName()) + ); + // Item + EmissiveModelRegistry.INSTANCE.register( + id, + createIdentifier("block/relay/cutouts/in/" + color.getName()), + createIdentifier("block/relay/cutouts/out/" + color.getName()) + ); + } + private void registerPackets() { ClientPlayNetworking.registerGlobalReceiver(PacketIds.STORAGE_INFO_RESPONSE, new StorageInfoResponsePacket()); ClientPlayNetworking.registerGlobalReceiver(PacketIds.GRID_UPDATE, new GridUpdatePacket()); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java index ce44228b7..8f788287e 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ConfigImpl.java @@ -102,12 +102,15 @@ public class ConfigImpl implements ConfigData, com.refinedmods.refinedstorage2.p private SimpleEnergyUsageEntryImpl fallbackSecurityCard = new SimpleEnergyUsageEntryImpl( DefaultEnergyUsage.FALLBACK_SECURITY_CARD ); - + @ConfigEntry.Gui.CollapsibleObject private SimpleEnergyUsageEntryImpl securityManager = new SimpleEnergyUsageEntryImpl( DefaultEnergyUsage.SECURITY_MANAGER ); + @ConfigEntry.Gui.CollapsibleObject + private RelayEntryImpl relay = new RelayEntryImpl(); + public static ConfigImpl get() { return AutoConfig.getConfigHolder(ConfigImpl.class).getConfig(); } @@ -253,6 +256,11 @@ public SimpleEnergyUsageEntry getSecurityManager() { return securityManager; } + @Override + public RelayEntry getRelay() { + return relay; + } + private static class GridEntryImpl implements GridEntry { private boolean largeFont = false; @@ -644,4 +652,20 @@ public long getExtractEnergyUsage() { return extractEnergyUsage; } } + + private static class RelayEntryImpl implements RelayEntry { + private long inputNetworkEnergyUsage = DefaultEnergyUsage.RELAY_INPUT_NETWORK; + + private long outputNetworkEnergyUsage = DefaultEnergyUsage.RELAY_OUTPUT_NETWORK; + + @Override + public long getInputNetworkEnergyUsage() { + return inputNetworkEnergyUsage; + } + + @Override + public long getOutputNetworkEnergyUsage() { + return outputNetworkEnergyUsage; + } + } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java index 3369fe363..a61e0be9f 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -101,6 +101,12 @@ public void registerCollapsibleEntries(final CollapsibleEntryRegistry registry) ContentIds.SECURITY_MANAGER, Tags.SECURITY_MANAGERS ); + groupItems( + registry, + Blocks.INSTANCE.getRelay(), + ContentIds.RELAY, + Tags.RELAYS + ); } @Override 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 549efa30c..2406e4068 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 @@ -46,6 +46,7 @@ public class ConfigImpl implements Config { private final SimpleEnergyUsageEntry securityCard; private final SimpleEnergyUsageEntry fallbackSecurityCard; private final SimpleEnergyUsageEntry securityManager; + private final RelayEntry relay; public ConfigImpl() { screenSize = builder @@ -109,6 +110,7 @@ public ConfigImpl() { "Security Manager", DefaultEnergyUsage.SECURITY_MANAGER ); + relay = new RelayEntryImpl(); spec = builder.build(); } @@ -256,6 +258,11 @@ public SimpleEnergyUsageEntry getSecurityManager() { return securityManager; } + @Override + public RelayEntry getRelay() { + return relay; + } + private class SimpleEnergyUsageEntryImpl implements SimpleEnergyUsageEntry { private final ModConfigSpec.LongValue energyUsage; @@ -807,4 +814,29 @@ public long getInsertEnergyUsage() { return insertEnergyUsage.get(); } } + + private class RelayEntryImpl implements RelayEntry { + private final ModConfigSpec.LongValue inputNetworkEnergyUsage; + private final ModConfigSpec.LongValue outputNetworkEnergyUsage; + + RelayEntryImpl() { + builder.push("relay"); + inputNetworkEnergyUsage = builder.comment("The energy used by the Relay in the input network") + .defineInRange(ENERGY_CAPACITY, DefaultEnergyUsage.RELAY_INPUT_NETWORK, 8, Long.MAX_VALUE); + outputNetworkEnergyUsage = builder.comment( + "The energy used by the Relay in the output network (if not in pass through mode)" + ).defineInRange(ENERGY_CAPACITY, DefaultEnergyUsage.RELAY_OUTPUT_NETWORK, 8, Long.MAX_VALUE); + builder.pop(); + } + + @Override + public long getInputNetworkEnergyUsage() { + return inputNetworkEnergyUsage.get(); + } + + @Override + public long getOutputNetworkEnergyUsage() { + return outputNetworkEnergyUsage.get(); + } + } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProviderImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProviderImpl.java index bf5080b64..17bb5bff8 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProviderImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockModelProviderImpl.java @@ -25,10 +25,20 @@ public class BlockModelProviderImpl extends BlockModelProvider { private static final ResourceLocation ALL_CUTOUT = createIdentifier("block/all_cutout"); private static final ResourceLocation NORTH_CUTOUT = createIdentifier("block/north_cutout"); + private static final ResourceLocation BOTTOM_TEXTURE = createIdentifier("block/bottom"); + + private static final String CUTOUT_NORTH = "cutout_north"; + private static final String CUTOUT_EAST = "cutout_east"; + private static final String CUTOUT_SOUTH = "cutout_south"; + private static final String CUTOUT_WEST = "cutout_west"; + private static final String CUTOUT_UP = "cutout_up"; + private static final String CUTOUT_DOWN = "cutout_down"; private static final String NORTH = "north"; + private static final String EAST = "east"; private static final String SOUTH = "south"; - - private static final ResourceLocation BOTTOM_TEXTURE = createIdentifier("block/bottom"); + private static final String WEST = "west"; + private static final String UP = "up"; + private static final String DOWN = "down"; public BlockModelProviderImpl(final PackOutput output, final ExistingFileHelper existingFileHelper) { super(output, MOD_ID, existingFileHelper); @@ -45,6 +55,7 @@ protected void registerModels() { registerNetworkReceivers(); registerNetworkTransmitters(); registerSecurityManagers(); + registerRelays(); } private void registerCables() { @@ -94,11 +105,11 @@ private void registerGrids(final String name, withExistingParent(BLOCK_PREFIX + "/" + name + "/" + variantName, baseModel) .texture(PARTICLE_TEXTURE, right) .texture(NORTH, front) - .texture("east", right) + .texture(EAST, right) .texture(SOUTH, back) - .texture("west", left) - .texture("up", top) - .texture("down", BOTTOM_TEXTURE) + .texture(WEST, left) + .texture(UP, top) + .texture(DOWN, BOTTOM_TEXTURE) .texture(CUTOUT_TEXTURE, cutout); } @@ -189,17 +200,17 @@ private void registerSecurityManagers() { withExistingParent("block/security_manager/" + color.getName(), EMISSIVE_CUTOUT) .texture(PARTICLE_TEXTURE, back) .texture(NORTH, front) - .texture("east", right) + .texture(EAST, right) .texture(SOUTH, back) - .texture("west", left) - .texture("up", top) - .texture("down", BOTTOM_TEXTURE) - .texture("cutout_north", cutoutFront) - .texture("cutout_east", cutoutRight) - .texture("cutout_south", cutoutBack) - .texture("cutout_west", cutoutLeft) - .texture("cutout_up", cutoutTop) - .texture("cutout_down", BOTTOM_TEXTURE); + .texture(WEST, left) + .texture(UP, top) + .texture(DOWN, BOTTOM_TEXTURE) + .texture(CUTOUT_NORTH, cutoutFront) + .texture(CUTOUT_EAST, cutoutRight) + .texture(CUTOUT_SOUTH, cutoutBack) + .texture(CUTOUT_WEST, cutoutLeft) + .texture(CUTOUT_UP, cutoutTop) + .texture(CUTOUT_DOWN, BOTTOM_TEXTURE); }); final ResourceLocation cutoutBack = createIdentifier("block/security_manager/cutouts/back/inactive"); final ResourceLocation cutoutFront = createIdentifier("block/security_manager/cutouts/front/inactive"); @@ -209,16 +220,55 @@ private void registerSecurityManagers() { withExistingParent("block/security_manager/inactive", CUTOUT) .texture(PARTICLE_TEXTURE, back) .texture(NORTH, front) - .texture("east", right) + .texture(EAST, right) .texture(SOUTH, back) - .texture("west", left) - .texture("up", top) - .texture("down", BOTTOM_TEXTURE) - .texture("cutout_north", cutoutFront) - .texture("cutout_east", cutoutRight) - .texture("cutout_south", cutoutBack) - .texture("cutout_west", cutoutLeft) - .texture("cutout_up", cutoutTop) - .texture("cutout_down", BOTTOM_TEXTURE); + .texture(WEST, left) + .texture(UP, top) + .texture(DOWN, BOTTOM_TEXTURE) + .texture(CUTOUT_NORTH, cutoutFront) + .texture(CUTOUT_EAST, cutoutRight) + .texture(CUTOUT_SOUTH, cutoutBack) + .texture(CUTOUT_WEST, cutoutLeft) + .texture(CUTOUT_UP, cutoutTop) + .texture(CUTOUT_DOWN, BOTTOM_TEXTURE); + } + + private void registerRelays() { + final ResourceLocation in = createIdentifier("block/relay/in"); + final ResourceLocation out = createIdentifier("block/relay/out"); + Blocks.INSTANCE.getNetworkTransmitter().forEach((color, id, receiver) -> { + final ResourceLocation cutoutIn = createIdentifier("block/relay/cutouts/in/" + color.getName()); + final ResourceLocation cutoutOut = createIdentifier("block/relay/cutouts/out/" + color.getName()); + withExistingParent("block/relay/" + color.getName(), EMISSIVE_CUTOUT) + .texture(PARTICLE_TEXTURE, in) + .texture(NORTH, out) + .texture(EAST, in) + .texture(SOUTH, in) + .texture(WEST, in) + .texture(UP, in) + .texture(DOWN, in) + .texture(CUTOUT_NORTH, cutoutOut) + .texture(CUTOUT_EAST, cutoutIn) + .texture(CUTOUT_SOUTH, cutoutIn) + .texture(CUTOUT_WEST, cutoutIn) + .texture(CUTOUT_UP, cutoutIn) + .texture(CUTOUT_DOWN, cutoutIn); + }); + final ResourceLocation cutoutIn = createIdentifier("block/relay/cutouts/in/inactive"); + final ResourceLocation cutoutOut = createIdentifier("block/relay/cutouts/out/inactive"); + withExistingParent("block/relay/inactive", CUTOUT) + .texture(PARTICLE_TEXTURE, in) + .texture(NORTH, out) + .texture(EAST, in) + .texture(SOUTH, in) + .texture(WEST, in) + .texture(UP, in) + .texture(DOWN, in) + .texture(CUTOUT_NORTH, cutoutOut) + .texture(CUTOUT_EAST, cutoutIn) + .texture(CUTOUT_SOUTH, cutoutIn) + .texture(CUTOUT_WEST, cutoutIn) + .texture(CUTOUT_UP, cutoutIn) + .texture(CUTOUT_DOWN, cutoutIn); } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProviderImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProviderImpl.java index e60050740..668da5c78 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProviderImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/BlockStateProviderImpl.java @@ -9,11 +9,12 @@ import com.refinedmods.refinedstorage2.platform.common.grid.AbstractGridBlock; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlock; import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlock; +import com.refinedmods.refinedstorage2.platform.common.networking.RelayBlock; import com.refinedmods.refinedstorage2.platform.common.security.SecurityManagerBlock; import com.refinedmods.refinedstorage2.platform.common.support.CableBlockSupport; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirection; import com.refinedmods.refinedstorage2.platform.common.support.direction.BiDirectionType; -import com.refinedmods.refinedstorage2.platform.common.support.direction.DirectionTypeImpl; +import com.refinedmods.refinedstorage2.platform.common.support.direction.DefaultDirectionType; import com.refinedmods.refinedstorage2.platform.common.support.direction.HorizontalDirectionType; import com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter.WirelessTransmitterBlock; @@ -71,6 +72,7 @@ protected void registerStatesAndModels() { registerNetworkReceivers(); registerNetworkTransmitters(); registerSecurityManagers(); + registerRelays(); } private void registerCables() { @@ -84,7 +86,8 @@ private void registerExporters() { PROPERTY_BY_DIRECTION.forEach((direction, property) -> { final var part = builder.part(); addDirectionalRotation(direction, part); - part.modelFile(exporterModel).addModel().condition(DirectionTypeImpl.INSTANCE.getProperty(), direction); + part.modelFile(exporterModel).addModel() + .condition(DefaultDirectionType.FACE_CLICKED.getProperty(), direction); }); }); } @@ -96,7 +99,8 @@ private void registerImporters() { PROPERTY_BY_DIRECTION.forEach((direction, property) -> { final var part = builder.part(); addDirectionalRotation(direction, part); - part.modelFile(importerModel).addModel().condition(DirectionTypeImpl.INSTANCE.getProperty(), direction); + part.modelFile(importerModel).addModel() + .condition(DefaultDirectionType.FACE_CLICKED.getProperty(), direction); }); }); } @@ -110,7 +114,7 @@ private void registerExternalStorages() { addDirectionalRotation(direction, part); part.modelFile(model) .addModel() - .condition(DirectionTypeImpl.INSTANCE.getProperty(), direction); + .condition(DefaultDirectionType.FACE_CLICKED.getProperty(), direction); }); }); } @@ -171,7 +175,7 @@ private void configureGridVariants(final DyeColor color, } else { model.modelFile(inactive); } - addRotation(model, blockState.getValue(BiDirectionType.INSTANCE.getProperty())); + addRotationFrontFacingNorth(model, blockState.getValue(BiDirectionType.INSTANCE.getProperty())); return model.build(); }); } @@ -227,7 +231,7 @@ private void registerWirelessTransmitters() { } else { model.modelFile(inactive); } - final Direction direction = blockState.getValue(DirectionTypeImpl.INSTANCE.getProperty()); + final Direction direction = blockState.getValue(DefaultDirectionType.FACE_CLICKED.getProperty()); addRotation(model, direction); return model.build(); }); @@ -244,12 +248,12 @@ private void registerConstructorDestructors(final BlockColorMap blockMap, addDirectionalRotation(direction, part); part.modelFile(activeModel) .addModel() - .condition(DirectionTypeImpl.INSTANCE.getProperty(), direction) + .condition(DefaultDirectionType.FACE_CLICKED.getProperty(), direction) .condition(AbstractConstructorDestructorBlock.ACTIVE, true) .end(); part.modelFile(inactiveModel) .addModel() - .condition(DirectionTypeImpl.INSTANCE.getProperty(), direction) + .condition(DefaultDirectionType.FACE_CLICKED.getProperty(), direction) .condition(AbstractConstructorDestructorBlock.ACTIVE, false) .end(); }); @@ -265,7 +269,7 @@ private ConfiguredModel[] registerDetector(final ModelFile unpowered, } else { model.modelFile(unpowered); } - final Direction direction = blockState.getValue(DirectionTypeImpl.INSTANCE.getProperty()); + final Direction direction = blockState.getValue(DefaultDirectionType.FACE_CLICKED.getProperty()); addRotation(model, direction); return model.build(); } @@ -319,7 +323,32 @@ private void registerSecurityManagers() { final Direction direction = HorizontalDirectionType.INSTANCE.extractDirection(blockState.getValue( HorizontalDirectionType.INSTANCE.getProperty() )); - addRotation(model, BiDirection.forHorizontal(direction)); + addRotationFrontFacingNorth(model, BiDirection.forHorizontal(direction)); + return model.build(); + }); + }); + } + + private void registerRelays() { + final ModelFile inactive = modelFile(createIdentifier("block/relay/inactive")); + Blocks.INSTANCE.getRelay().forEach((color, id, block) -> { + final ModelFile active = modelFile(createIdentifier("block/relay/" + color.getName())); + final var builder = getVariantBuilder(block.get()); + builder.forAllStates(blockState -> { + final ConfiguredModel.Builder model = ConfiguredModel.builder(); + if (Boolean.TRUE.equals(blockState.getValue(RelayBlock.ACTIVE))) { + model.modelFile(active); + } else { + model.modelFile(inactive); + } + final Direction direction = blockState.getValue(DefaultDirectionType.FACE_PLAYER.getProperty()); + final BiDirection biDirection; + if (direction.getAxis().isHorizontal()) { + biDirection = BiDirection.forHorizontal(direction); + } else { + biDirection = direction == Direction.UP ? BiDirection.UP_NORTH : BiDirection.DOWN_NORTH; + } + addRotationFrontFacingNorth(model, biDirection); return model.build(); }); }); @@ -337,7 +366,7 @@ private void addRotation(final ConfiguredModel.Builder model, final Direction model.rotationY(rotationY); } - private void addRotation(final ConfiguredModel.Builder model, final BiDirection direction) { + private void addRotationFrontFacingNorth(final ConfiguredModel.Builder model, final BiDirection direction) { final int x = (int) direction.getVec().x(); final int y = (int) direction.getVec().y(); final int z = (int) direction.getVec().z(); diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProviderImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProviderImpl.java index 07fc36159..9e48971b1 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProviderImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/ItemModelProviderImpl.java @@ -47,6 +47,7 @@ protected void registerModels() { registerNetworkReceivers(); registerNetworkTransmitters(); registerSecurityManagers(); + registerRelays(); } private void registerCables() { @@ -186,6 +187,14 @@ private void registerSecurityManagers() { )); } + private void registerRelays() { + final var blocks = Blocks.INSTANCE.getRelay(); + blocks.forEach((color, id, block) -> withExistingParent( + id.getPath(), + createIdentifier("block/relay/" + color.getName()) + )); + } + private ModelFile modelFile(final ResourceLocation location) { return new ModelFile.ExistingModelFile(location, existingFileHelper); } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/loot/BlockDropProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/loot/BlockDropProvider.java index b0a25b484..f0d9df1ba 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/loot/BlockDropProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/loot/BlockDropProvider.java @@ -33,6 +33,7 @@ protected void generate() { Blocks.INSTANCE.getNetworkReceiver().forEach((color, id, block) -> dropSelf(block.get())); Blocks.INSTANCE.getNetworkTransmitter().forEach((color, id, block) -> dropSelf(block.get())); Blocks.INSTANCE.getSecurityManager().forEach((color, id, block) -> dropSelf(block.get())); + Blocks.INSTANCE.getRelay().forEach((color, id, block) -> dropSelf(block.get())); } @Override @@ -50,6 +51,7 @@ protected Iterable getKnownBlocks() { blocks.addAll(Blocks.INSTANCE.getNetworkReceiver().values()); blocks.addAll(Blocks.INSTANCE.getNetworkTransmitter().values()); blocks.addAll(Blocks.INSTANCE.getSecurityManager().values()); + blocks.addAll(Blocks.INSTANCE.getRelay().values()); return blocks; } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java index 65e8bbb32..55386a36a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/recipe/RecoloringRecipeProvider.java @@ -65,6 +65,9 @@ protected void buildRecipes(final RecipeOutput output) { Blocks.INSTANCE.getSecurityManager().forEach((color, id, block) -> recipe(Tags.SECURITY_MANAGERS, block.get().asItem(), color) .save(output, recipeId(color, "security_manager"))); + Blocks.INSTANCE.getRelay().forEach((color, id, block) -> + recipe(Tags.RELAYS, block.get().asItem(), color) + .save(output, recipeId(color, "relay"))); } private ResourceLocation recipeId(final DyeColor color, final String suffix) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagsProviderImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagsProviderImpl.java index 6827cd5cb..5aee00d63 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagsProviderImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/datagen/tag/ItemTagsProviderImpl.java @@ -34,6 +34,7 @@ import static com.refinedmods.refinedstorage2.platform.common.content.Tags.IMPORTERS; import static com.refinedmods.refinedstorage2.platform.common.content.Tags.NETWORK_RECEIVERS; import static com.refinedmods.refinedstorage2.platform.common.content.Tags.NETWORK_TRANSMITTERS; +import static com.refinedmods.refinedstorage2.platform.common.content.Tags.RELAYS; import static com.refinedmods.refinedstorage2.platform.common.content.Tags.SECURITY_MANAGERS; import static com.refinedmods.refinedstorage2.platform.common.content.Tags.STORAGE_DISKS; import static com.refinedmods.refinedstorage2.platform.common.content.Tags.WIRELESS_TRANSMITTERS; @@ -115,6 +116,10 @@ protected void addTags(final HolderLookup.Provider provider) { Blocks.INSTANCE.getSecurityManager().values().stream() .map(block -> (Supplier) block::asItem) .toList()); + addAllToTag(RELAYS, + Blocks.INSTANCE.getRelay().values().stream() + .map(block -> (Supplier) block::asItem) + .toList()); } private void addAllToTag(final TagKey t, final Collection> items) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java index 37064bfa7..eee99d6e6 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/recipemod/rei/RefinedStorageREIClientPlugin.java @@ -99,6 +99,12 @@ public void registerCollapsibleEntries(final CollapsibleEntryRegistry registry) ContentIds.SECURITY_MANAGER, Tags.SECURITY_MANAGERS ); + groupItems( + registry, + Blocks.INSTANCE.getRelay(), + ContentIds.RELAY, + Tags.RELAYS + ); } @Override diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java index 29299d15c..55cf8eb60 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannel.java @@ -44,7 +44,7 @@ public interface StorageChannel extends Storage, TrackedStorage { void sortSources(); /** - * Adds a source to the channel. + * Adds a source to the channel and resorts all the sources. * * @param source the source */ diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImpl.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImpl.java index 6639d851d..da97fe035 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImpl.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImpl.java @@ -9,7 +9,6 @@ import com.refinedmods.refinedstorage2.api.resource.list.listenable.ResourceListListener; import com.refinedmods.refinedstorage2.api.storage.Actor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.composite.CompositeStorage; import com.refinedmods.refinedstorage2.api.storage.composite.CompositeStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; @@ -21,8 +20,8 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public class StorageChannelImpl implements StorageChannel { + protected final CompositeStorageImpl storage; private final ListenableResourceList list; - private final CompositeStorage storage; public StorageChannelImpl() { this(new ResourceListImpl()); diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java index 19f428e00..154d25fb8 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeAwareChild.java @@ -52,6 +52,10 @@ public interface CompositeAwareChild extends Storage { */ Amount compositeExtract(ResourceKey resource, long amount, Action action, Actor actor); + default boolean contains(Storage storage) { + return false; + } + /** * @param amount the amount * @param amountForList the amount to be modified in the parent composite cache list diff --git a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java index 21fe2ea9a..c0dc06497 100644 --- a/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImpl.java @@ -74,6 +74,16 @@ public void clearSources() { oldSources.forEach(this::removeSource); } + @Override + public boolean contains(final Storage storage) { + for (final Storage source : sources) { + if (source instanceof CompositeAwareChild compositeAwareChild && compositeAwareChild.contains(storage)) { + return true; + } + } + return false; + } + @Override public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { long remaining = amount; diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/PrioritizedStorage.java b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/PriorityStorage.java similarity index 53% rename from refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/PrioritizedStorage.java rename to refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/PriorityStorage.java index fafebcb41..034996742 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/PrioritizedStorage.java +++ b/refinedstorage2-storage-api/src/main/java/com/refinedmods/refinedstorage2/api/storage/composite/PriorityStorage.java @@ -3,14 +3,21 @@ import com.refinedmods.refinedstorage2.api.storage.AbstractProxyStorage; import com.refinedmods.refinedstorage2.api.storage.Storage; -public class PrioritizedStorage extends AbstractProxyStorage implements Priority { +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.6") +public class PriorityStorage extends AbstractProxyStorage implements Priority { private int priority; - public PrioritizedStorage(final int priority, final Storage delegate) { + private PriorityStorage(final int priority, final Storage delegate) { super(delegate); this.priority = priority; } + public static PriorityStorage of(final Storage delegate, final int priority) { + return new PriorityStorage(priority, delegate); + } + public void setPriority(final int priority) { this.priority = priority; } @@ -20,3 +27,4 @@ public int getPriority() { return priority; } } + diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java index 834f0c639..cf3f1c9cd 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/channel/StorageChannelImplTest.java @@ -6,7 +6,7 @@ import com.refinedmods.refinedstorage2.api.resource.list.listenable.ResourceListListener; import com.refinedmods.refinedstorage2.api.storage.EmptyActor; import com.refinedmods.refinedstorage2.api.storage.Storage; -import com.refinedmods.refinedstorage2.api.storage.composite.PrioritizedStorage; +import com.refinedmods.refinedstorage2.api.storage.composite.PriorityStorage; import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorageImpl; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedStorageImpl; @@ -266,9 +266,9 @@ void shouldNotBeAbleToRetrieveNonExistentResource() { @Test void shouldSortSources() { // Arrange - final PrioritizedStorage storage1 = new PrioritizedStorage(0, new LimitedStorageImpl(10)); - final PrioritizedStorage storage2 = new PrioritizedStorage(0, new LimitedStorageImpl(10)); - final PrioritizedStorage storage3 = new PrioritizedStorage(0, new LimitedStorageImpl(10)); + final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 0); + final PriorityStorage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 0); + final PriorityStorage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 0); sut.addSource(storage1); sut.addSource(storage2); diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java index 92d37d937..f8ccd870a 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/CompositeStorageImplTest.java @@ -129,9 +129,9 @@ void shouldClearSources() { @Test void shouldRespectPriorityWhenAddingNewSources() { // Arrange - final Storage storage1 = new PrioritizedStorage(20, new LimitedStorageImpl(10)); - final Storage storage2 = new PrioritizedStorage(10, new LimitedStorageImpl(10)); - final Storage storage3 = new PrioritizedStorage(30, new LimitedStorageImpl(10)); + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30); // Act sut.addSource(storage1); @@ -154,9 +154,9 @@ void shouldRespectPriorityWhenAddingNewSources() { @Test void shouldRespectPriorityWhenRemovingSources() { // Arrange - final Storage storage1 = new PrioritizedStorage(20, new LimitedStorageImpl(10)); - final Storage storage2 = new PrioritizedStorage(10, new LimitedStorageImpl(10)); - final Storage storage3 = new PrioritizedStorage(30, new LimitedStorageImpl(10)); + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30); sut.addSource(storage1); sut.addSource(storage2); @@ -180,8 +180,8 @@ void shouldRespectPriorityWhenRemovingSources() { @Test void shouldOnlyRespectPriorityWhenSortingSourcesExplicitlyWhenChangingPriorityAfterAddingSource() { // Arrange - final PrioritizedStorage storage1 = new PrioritizedStorage(1, new LimitedStorageImpl(10)); - final Storage storage2 = new PrioritizedStorage(2, new LimitedStorageImpl(10)); + final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 1); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 2); sut.addSource(storage1); sut.addSource(storage2); diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java index 28e9d0343..17aff9ed1 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/ExtractCompositeStorageImplTest.java @@ -281,8 +281,8 @@ void shouldNotExtractWithoutAnySourcesPresent() { @Test void shouldRespectPriorityWhenExtracting() { // Arrange - final PrioritizedStorage lowestPriority = new PrioritizedStorage(5, new LimitedStorageImpl(10)); - final PrioritizedStorage highestPriority = new PrioritizedStorage(10, new LimitedStorageImpl(10)); + final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5); + final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10); lowestPriority.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); highestPriority.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); diff --git a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java index 4f882bcb2..361c86d0e 100644 --- a/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java +++ b/refinedstorage2-storage-api/src/test/java/com/refinedmods/refinedstorage2/api/storage/composite/InsertCompositeStorageImplTest.java @@ -185,8 +185,8 @@ void shouldNotInsertWithoutAnySourcesPresent() { @Test void shouldRespectPriorityWhenInserting() { // Arrange - final PrioritizedStorage lowestPriority = new PrioritizedStorage(5, new LimitedStorageImpl(10)); - final PrioritizedStorage highestPriority = new PrioritizedStorage(10, new LimitedStorageImpl(10)); + final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5); + final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10); sut.addSource(lowestPriority); sut.addSource(highestPriority);