Skip to content

Commit

Permalink
Merge pull request #452 from refinedmods/release/2.0.0-milestone.3.2
Browse files Browse the repository at this point in the history
Release v2.0.0-milestone.3.2
  • Loading branch information
raoulvdberge authored Nov 3, 2023
2 parents 05f3170 + 5a696e6 commit 4c0ac38
Show file tree
Hide file tree
Showing 1,090 changed files with 9,864 additions and 4,460 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.0.0-milestone.3.2] - 2023-11-03

### Added

- Configuration Card. It copies device configurations and can transfer upgrades.
- Network Receiver
- Network Card
- Network Transmitter

### Changed

- The Network Transmitter now goes into an "errored" state if there is no connection (anymore) with the Network Receiver (due to chunk unloading for example).
- The Network Transmitter will actively try to reconnect with the Network Receiver if connection is lost.

### Fixed

- Inactive Wireless Transmitter model being emissive.
- Unneeded network graph updating after placing a network device.
- Cable blocks not updating connections properly when using wrench.

## [2.0.0-milestone.3.1] - 2023-10-30

### Added
Expand Down Expand Up @@ -477,7 +497,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.1...HEAD
[Unreleased]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-milestone.3.2...HEAD

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.refinedmods.refinedstorage2.api.network.component;

import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;

import java.util.Set;
import javax.annotation.Nullable;

import org.apiguardian.api.API;

/**
* Responsible for managing the connected network nodes in a network.
*/
@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.2")
public interface GraphNetworkComponent extends NetworkComponent {
/**
* @return all the containers currently present in this graph
*/
Set<NetworkNodeContainer> getContainers();

/**
* Retrieves containers by container type.
* It can be queried by exact class type or by interface type.
*
* @param clazz the container class type
* @param <T> the container class type
* @return the containers matching the type
*/
<T> Set<T> getContainers(Class<T> clazz);

/**
* Retrieves a container by key, defined in {@link NetworkNodeContainer#createKey()}.
*
* @param key the key
* @return the container, or null if not found
*/
@Nullable
NetworkNodeContainer getContainer(Object key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@

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

import javax.annotation.Nullable;

import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0")
@FunctionalInterface
public interface NetworkNodeContainer {
NetworkNode getNode();

/**
* If this container needs to be indexed by the network graph, so it can be queried quickly (by key),
* you can return a key here.
* 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 com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent#getContainer(Object)}.
*
* @return the key, or null if indexing is not required
*/
@Nullable
default Object createKey() {
return null;
}

/**
* The container priority determines the order in which the remainder containers as the result of a network split
* are re-initialized with a new network.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.refinedmods.refinedstorage2.api.core.component.ComponentMapFactory;
import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.impl.component.EnergyNetworkComponentImpl;
import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponentImpl;
import com.refinedmods.refinedstorage2.api.network.impl.component.StorageNetworkComponentImpl;
import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelImpl;
import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType;
Expand All @@ -26,7 +27,7 @@ public final class NetworkTestFixtures {
);
NETWORK_COMPONENT_MAP_FACTORY.addFactory(
GraphNetworkComponent.class,
GraphNetworkComponent::new
GraphNetworkComponentImpl::new
);
NETWORK_COMPONENT_MAP_FACTORY.addFactory(
StorageNetworkComponent.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.component.EnergyNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.refinedmods.refinedstorage2.api.network.Connections;
import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.NetworkBuilder;
import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
package com.refinedmods.refinedstorage2.api.network.impl.component;

import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GraphNetworkComponent implements NetworkComponent {
private static final Logger LOGGER = LoggerFactory.getLogger(GraphNetworkComponent.class);
public class GraphNetworkComponentImpl implements GraphNetworkComponent {
private static final Logger LOGGER = LoggerFactory.getLogger(GraphNetworkComponentImpl.class);

private final Network network;
private final Set<NetworkNodeContainer> containers = new HashSet<>();
private final Map<Class<?>, Set<NetworkNodeContainer>> containerIndex = new HashMap<>();
private final Map<Class<?>, Set<NetworkNodeContainer>> byClassIndex = new HashMap<>();
private final Map<Object, NetworkNodeContainer> byKeyIndex = new HashMap<>();

public GraphNetworkComponent(final Network network) {
public GraphNetworkComponentImpl(final Network network) {
this.network = network;
}

@Override
public Set<NetworkNodeContainer> getContainers() {
return Collections.unmodifiableSet(containers);
}

@Override
@SuppressWarnings("unchecked")
public <T> Set<T> getContainers(final Class<T> clazz) {
return (Set<T>) Collections.unmodifiableSet(containerIndex.getOrDefault(clazz, Collections.emptySet()));
return (Set<T>) Collections.unmodifiableSet(byClassIndex.getOrDefault(clazz, Collections.emptySet()));
}

@Override
@Nullable
public NetworkNodeContainer getContainer(final Object key) {
return byKeyIndex.get(key);
}

@Override
Expand All @@ -44,10 +54,14 @@ public void onContainerAdded(final NetworkNodeContainer container) {
public void onContainerRemoved(final NetworkNodeContainer container) {
LOGGER.debug("Container {} removed from network {}", container, network.hashCode());
containers.remove(container);
deleteFromIndex(container);
removeFromIndex(container);
}

private void addToIndex(final NetworkNodeContainer container) {
final Object key = container.createKey();
if (key != null) {
byKeyIndex.put(key, container);
}
final Class<? extends NetworkNodeContainer> clazz = container.getClass();
addToIndex(clazz, container);
for (final Class<?> iface : clazz.getInterfaces()) {
Expand All @@ -56,23 +70,27 @@ private void addToIndex(final NetworkNodeContainer container) {
}

private void addToIndex(final Class<?> indexKey, final NetworkNodeContainer container) {
containerIndex.computeIfAbsent(indexKey, k -> new HashSet<>()).add(container);
byClassIndex.computeIfAbsent(indexKey, k -> new HashSet<>()).add(container);
}

private void deleteFromIndex(final NetworkNodeContainer container) {
private void removeFromIndex(final NetworkNodeContainer container) {
final Object key = container.createKey();
if (key != null) {
byKeyIndex.remove(key);
}
final Class<? extends NetworkNodeContainer> clazz = container.getClass();
deleteFromIndex(clazz, container);
removeFromIndex(clazz, container);
for (final Class<?> iface : clazz.getInterfaces()) {
deleteFromIndex(iface, container);
removeFromIndex(iface, container);
}
}

private void deleteFromIndex(final Class<?> indexKey, final NetworkNodeContainer container) {
final Set<? extends NetworkNodeContainer> index = containerIndex.get(indexKey);
private void removeFromIndex(final Class<?> indexKey, final NetworkNodeContainer container) {
final Set<? extends NetworkNodeContainer> index = byClassIndex.get(indexKey);
if (index != null) {
index.remove(container);
if (index.isEmpty()) {
containerIndex.remove(indexKey);
byClassIndex.remove(indexKey);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable;

import org.junit.jupiter.api.BeforeEach;

import static java.util.Objects.requireNonNull;

abstract class AbstractNetworkBuilderImplTest {
protected NetworkBuilder sut;
private ComponentMapFactory<NetworkComponent, Network> componentMapFactory;
Expand All @@ -30,10 +32,8 @@ void setUp() {
sut = new NetworkBuilderImpl(new NetworkFactory(componentMapFactory));
}

protected void clearTracking(final Network network) {
Objects.requireNonNull(network)
.getComponent(InterceptingNetworkComponent.class)
.clear();
protected void clearTracking(@Nullable final Network network) {
requireNonNull(network).getComponent(InterceptingNetworkComponent.class).clear();
}

protected NetworkNodeContainer createContainerWithNetwork() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.api.network.impl;

import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -50,7 +50,8 @@ void shouldFormNetwork() {
assertThat(unrelatedContainer.getNode().getNetwork())
.isNotNull()
.isNotEqualTo(container.getNode().getNetwork());
assertThat(unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
assertThat(
unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
.containsExactly(unrelatedContainer);
}

Expand Down Expand Up @@ -85,7 +86,8 @@ void shouldJoinExistingNetwork() {
assertThat(existingContainer1.getNode().getNetwork()).isEqualTo(expectedNetwork);
assertThat(existingContainer2.getNode().getNetwork()).isEqualTo(expectedNetwork);
assertThat(newContainer.getNode().getNetwork()).isEqualTo(expectedNetwork);
assertThat(expectedNetwork.getComponent(GraphNetworkComponent.class).getContainers()).containsExactlyInAnyOrder(
assertThat(
expectedNetwork.getComponent(GraphNetworkComponent.class).getContainers()).containsExactlyInAnyOrder(
existingContainer1,
existingContainer2,
newContainer
Expand All @@ -101,7 +103,8 @@ void shouldJoinExistingNetwork() {
assertThat(getNetworkMerges(expectedNetwork)).isEmpty();

assertThat(unrelatedContainer.getNode().getNetwork()).isNotNull().isNotEqualTo(expectedNetwork);
assertThat(unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
assertThat(
unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
.containsExactly(unrelatedContainer);
}

Expand Down Expand Up @@ -140,7 +143,8 @@ void shouldMergeWithExistingNetworks() {
assertThat(existingContainer2.getNode().getNetwork()).isEqualTo(expectedNetwork);
assertThat(existingContainer0.getNode().getNetwork()).isEqualTo(expectedNetwork);
assertThat(newContainer.getNode().getNetwork()).isEqualTo(expectedNetwork);
assertThat(expectedNetwork.getComponent(GraphNetworkComponent.class).getContainers()).containsExactlyInAnyOrder(
assertThat(
expectedNetwork.getComponent(GraphNetworkComponent.class).getContainers()).containsExactlyInAnyOrder(
existingContainer1,
existingContainer2,
existingContainer0,
Expand All @@ -154,7 +158,8 @@ void shouldMergeWithExistingNetworks() {
assertThat(getNetworkMerges(expectedNetwork)).isEmpty();

assertThat(unrelatedContainer.getNode().getNetwork()).isNotNull().isNotEqualTo(expectedNetwork);
assertThat(unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
assertThat(
unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
.containsExactly(unrelatedContainer);
}

Expand Down Expand Up @@ -190,7 +195,8 @@ void shouldFormNetworkIfThereAreNeighborsWithoutNetwork() {
assertThat(container2.getNode().getNetwork()).isEqualTo(expectedNetwork);
assertThat(container3.getNode().getNetwork()).isEqualTo(expectedNetwork);

assertThat(expectedNetwork.getComponent(GraphNetworkComponent.class).getContainers()).containsExactlyInAnyOrder(
assertThat(
expectedNetwork.getComponent(GraphNetworkComponent.class).getContainers()).containsExactlyInAnyOrder(
container1,
container2,
container3
Expand All @@ -202,7 +208,8 @@ void shouldFormNetworkIfThereAreNeighborsWithoutNetwork() {
assertThat(getAmountRemoved(expectedNetwork)).isZero();

assertThat(unrelatedContainer.getNode().getNetwork()).isNotNull().isNotEqualTo(expectedNetwork);
assertThat(unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
assertThat(
unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
.containsExactly(unrelatedContainer);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.api.network.impl;

import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;

import java.util.List;
Expand Down Expand Up @@ -235,7 +235,8 @@ void shouldRemoveNetwork() {
assertThat(container.getNode().getNetwork()).isNull();

assertThat(unrelatedContainer.getNode().getNetwork()).isNotNull();
assertThat(unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
assertThat(
unrelatedContainer.getNode().getNetwork().getComponent(GraphNetworkComponent.class).getContainers())
.containsExactlyInAnyOrder(unrelatedContainer);

assertThat(network).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.api.network.impl;

import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.impl.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.component.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;

import java.util.Set;
Expand Down
Loading

0 comments on commit 4c0ac38

Please sign in to comment.