Skip to content

Commit

Permalink
Merge pull request #524 from refinedmods/release/2.0.0-milestone.3.6
Browse files Browse the repository at this point in the history
Release v2.0.0-milestone.3.6
  • Loading branch information
raoulvdberge authored May 18, 2024
2 parents 697fb12 + b212d5a commit d1b7e72
Show file tree
Hide file tree
Showing 342 changed files with 8,242 additions and 2,269 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.0.0-milestone.3.6] - 2024-05-18

### 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

- Double slot highlighting in the Grid.
- Improved data corruption protection for storages.

## [2.0.0-milestone.3.5] - 2024-04-04

### Added
Expand Down Expand Up @@ -554,7 +572,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- The Grid can now use smooth scrolling.
- The Grid now has syntax highlighting for the search query.

[Unreleased]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-milestone.3.5...HEAD
[Unreleased]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-milestone.3.6...HEAD

[2.0.0-milestone.3.6]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-milestone.3.5...v2.0.0-milestone.3.6

[2.0.0-milestone.3.5]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-milestone.3.4...v2.0.0-milestone.3.5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ public ComponentMapFactory<C, X> copy() {
return new ComponentMapFactory<>(new LinkedHashMap<>(factories));
}

@SuppressWarnings("unchecked")
public ComponentMap<C> buildComponentMap(final X context) {
final Map<Class<? extends C>, 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.1.1")
public interface EnergyNetworkComponent extends NetworkComponent {
long getStored();

long getCapacity();

long extract(long amount);
public interface EnergyNetworkComponent extends NetworkComponent, EnergyProvider {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.refinedmods.refinedstorage2.api.network.energy;

import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.6")
public interface EnergyProvider {
long getStored();

long getCapacity();

long extract(long amount);

default boolean contains(EnergyProvider energyProvider) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.refinedmods.refinedstorage2.api.network.node.container;

import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.NetworkNode;

import javax.annotation.Nullable;
Expand All @@ -18,7 +17,8 @@ public interface NetworkNodeContainer {
* The key must be kept stable, and must stay the same for the lifetime of the container.
* If it changes after adding it into the graph, the container would not be removed from the key index when the
* container is removed!
* The container can be queried by {@link GraphNetworkComponent#getContainer(Object)}.
* The container can be queried by
* {@link com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent#getContainer(Object)}.
*
* @return the key, or null if indexing is not required
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
public record SecurityPolicy(Set<Permission> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -12,4 +13,6 @@
@API(status = API.Status.STABLE, since = "2.0.0-milestone.1.1")
public interface StorageNetworkComponent extends NetworkComponent, StorageChannel {
List<TrackedResourceAmount> getResources(Class<? extends Actor> actorType);

boolean contains(Storage storage);
}
Original file line number Diff line number Diff line change
@@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface InjectNetworkStorageChannel {
public @interface InjectNetworkStorageComponent {
String networkId() default "default";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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 <A extends Annotation> List<A> getAnnotations(final Object testInstance, final Class<A> annotationType) {
Expand Down Expand Up @@ -173,35 +191,39 @@ 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);
}

@Override
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkComponent, Network> NETWORK_COMPONENT_MAP_FACTORY =
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit d1b7e72

Please sign in to comment.