Skip to content

Commit

Permalink
Merge pull request #580 from refinedmods/release/2.0.0-milestone.3.14
Browse files Browse the repository at this point in the history
Release v2.0.0-milestone.3.14
  • Loading branch information
raoulvdberge authored Jun 28, 2024
2 parents bbc9f96 + 91560ff commit 83684c8
Show file tree
Hide file tree
Showing 294 changed files with 6,360 additions and 2,296 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.0.0-milestone.3.14] - 2024-06-28

### Added

- Disk Interface (formerly known as the "Disk Manipulator").
- Item tag translations.

### Fixed

- Relay having no help tooltip.
- Fixed bug where adding more Speed Upgrades would actually slow down the device even more.
- Fixed missing textures for scheduling mode side button.

## [2.0.0-milestone.3.13] - 2024-06-16

## [2.0.0-milestone.3.12] - 2024-06-16
Expand Down Expand Up @@ -606,7 +619,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.13...HEAD
[Unreleased]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-milestone.3.14...HEAD

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

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

Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="FileLength">
<property name="max" value="700"/>
<property name="max" value="750"/>
</module>
<module name="NewlineAtEndOfFile"/>
<module name="JavadocPackage"/>
Expand Down
2 changes: 2 additions & 0 deletions config/intellij-code-style.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<code_scheme name="Refined Mods" version="173">
<JavaCodeStyleSettings>
<option name="GENERATE_FINAL_LOCALS" value="true" />
<option name="GENERATE_FINAL_PARAMETERS" value="true" />
<option name="SPACE_INSIDE_ONE_LINE_ENUM_BRACES" value="true" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode;
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.api.network.impl.node.storagetransfer.StorageTransferNetworkNode;
import com.refinedmods.refinedstorage2.network.test.nodefactory.ControllerNetworkNodeFactory;
import com.refinedmods.refinedstorage2.network.test.nodefactory.DetectorNetworkNodeFactory;
import com.refinedmods.refinedstorage2.network.test.nodefactory.ExporterNetworkNodeFactory;
import com.refinedmods.refinedstorage2.network.test.nodefactory.ExternalStorageNetworkNodeFactory;
import com.refinedmods.refinedstorage2.network.test.nodefactory.GridNetworkNodeFactory;
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;
import com.refinedmods.refinedstorage2.network.test.nodefactory.StorageTransferNetworkNodeFactory;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -36,16 +36,16 @@
@Target(ElementType.TYPE)
@ExtendWith(NetworkTestExtension.class)
@RegisterNetworkNode(value = ControllerNetworkNodeFactory.class, clazz = ControllerNetworkNode.class)
@RegisterNetworkNode(value = MultiStorageNetworkNodeFactory.class, clazz = MultiStorageNetworkNode.class)
@RegisterNetworkNode(value = StorageNetworkNodeFactory.class, clazz = StorageNetworkNode.class)
@RegisterNetworkNode(value = ExporterNetworkNodeFactory.class, clazz = ExporterNetworkNode.class)
@RegisterNetworkNode(value = GridNetworkNodeFactory.class, clazz = GridNetworkNode.class)
@RegisterNetworkNode(value = ImporterNetworkNodeFactory.class, clazz = ImporterNetworkNode.class)
@RegisterNetworkNode(value = SimpleNetworkNodeFactory.class, clazz = SimpleNetworkNode.class)
@RegisterNetworkNode(value = StorageNetworkNodeFactory.class, clazz = StorageNetworkNode.class)
@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)
@RegisterNetworkNode(value = StorageTransferNetworkNodeFactory.class, clazz = StorageTransferNetworkNode.class)
public @interface NetworkTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl;
import com.refinedmods.refinedstorage2.network.test.fake.FakePermissions;

import java.util.LinkedHashMap;

public final class NetworkTestFixtures {
public static final ComponentMapFactory<NetworkComponent, Network> NETWORK_COMPONENT_MAP_FACTORY =
new ComponentMapFactory<>();
Expand All @@ -30,7 +32,7 @@ public final class NetworkTestFixtures {
);
NETWORK_COMPONENT_MAP_FACTORY.addFactory(
StorageNetworkComponent.class,
network -> new StorageNetworkComponentImpl(new ResourceListImpl())
network -> new StorageNetworkComponentImpl(new ResourceListImpl(new LinkedHashMap<>()))
);
NETWORK_COMPONENT_MAP_FACTORY.addFactory(
SecurityNetworkComponent.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@
import java.util.Map;

public class StorageNetworkNodeFactory extends AbstractNetworkNodeFactory {
public static final String PROPERTY_ENERGY_USAGE_PER_STORAGE = "energy_usage_per_storage";
public static final String PROPERTY_SIZE = "size";

@Override
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
return new StorageNetworkNode(getEnergyUsage(properties));
final long energyUsagePerStorage = (long) properties.getOrDefault(PROPERTY_ENERGY_USAGE_PER_STORAGE, 0L);
final int size = (int) properties.getOrDefault(PROPERTY_SIZE, 9);
return new StorageNetworkNode(
getEnergyUsage(properties),
energyUsagePerStorage,
size
);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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.node.storagetransfer.StorageTransferNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;

public class MultiStorageNetworkNodeFactory extends AbstractNetworkNodeFactory {
public class StorageTransferNetworkNodeFactory extends AbstractNetworkNodeFactory {
public static final String PROPERTY_ENERGY_USAGE_PER_STORAGE = "energy_usage_per_storage";
public static final String PROPERTY_SIZE = "size";

@Override
protected AbstractNetworkNode innerCreate(final AddNetworkNode ctx, final Map<String, Object> properties) {
final long energyUsagePerStorage = (long) properties.getOrDefault(PROPERTY_ENERGY_USAGE_PER_STORAGE, 0L);
final int size = (int) properties.getOrDefault(PROPERTY_SIZE, 9);
return new MultiStorageNetworkNode(
final int size = (int) properties.getOrDefault(PROPERTY_SIZE, 6);
return new StorageTransferNetworkNode(
getEnergyUsage(properties),
energyUsagePerStorage,
size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode;
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.api.network.impl.node.storagetransfer.StorageTransferNetworkNode;

import org.junit.jupiter.api.Test;

Expand All @@ -21,8 +23,6 @@ class NetworkNodeFactoryTest {
@AddNetworkNode
ControllerNetworkNode controller;
@AddNetworkNode
MultiStorageNetworkNode multiStorage;
@AddNetworkNode
ExporterNetworkNode exporter;
@AddNetworkNode
GridNetworkNode grid;
Expand All @@ -38,6 +38,12 @@ class NetworkNodeFactoryTest {
ExternalStorageNetworkNode externalStorage;
@AddNetworkNode
DetectorNetworkNode detector;
@AddNetworkNode
RelayInputNetworkNode relayInput;
@AddNetworkNode
RelayOutputNetworkNode relayOutput;
@AddNetworkNode
StorageTransferNetworkNode storageTransfer;

@Test
void testInitialization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.energy.EnergyNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.GraphNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;
import com.refinedmods.refinedstorage2.api.network.security.SecurityNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.storage.StorageNetworkComponent;
import com.refinedmods.refinedstorage2.network.test.nodefactory.AbstractNetworkNodeFactory;
import com.refinedmods.refinedstorage2.network.test.nodefactory.MultiStorageNetworkNodeFactory;
import com.refinedmods.refinedstorage2.network.test.nodefactory.SimpleNetworkNodeFactory;
import com.refinedmods.refinedstorage2.network.test.nodefactory.StorageNetworkNodeFactory;

Expand All @@ -23,7 +21,7 @@
@ExtendWith({NetworkTestExtension.class})
@SetupNetwork(id = "a", energyCapacity = 100, energyStored = 50)
@SetupNetwork(id = "b")
@RegisterNetworkNode(value = MultiStorageNetworkNodeFactory.class, clazz = MultiStorageNetworkNode.class)
@RegisterNetworkNode(value = StorageNetworkNodeFactory.class, clazz = StorageNetworkNode.class)
@RegisterNetworkNode(value = StorageNetworkNodeFactory.class, clazz = StorageNetworkNode.class)
@RegisterNetworkNode(value = SimpleNetworkNodeFactory.class, clazz = SimpleNetworkNode.class)
class NetworkTestExtensionTest {
Expand All @@ -41,7 +39,7 @@ class NetworkTestExtensionTest {
@AddNetworkNode(networkId = "b", properties = {
@AddNetworkNode.Property(key = AbstractNetworkNodeFactory.PROPERTY_ACTIVE, boolValue = false)
})
MultiStorageNetworkNode storageInB;
StorageNetworkNode storageInB;

@AddNetworkNode(networkId = "nonexistent")
SimpleNetworkNode nonexistentNetworkNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.refinedmods.refinedstorage2.api.network.impl.node;

import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage;
import com.refinedmods.refinedstorage2.api.storage.Storage;
import com.refinedmods.refinedstorage2.api.storage.StorageState;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;

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

public abstract class AbstractStorageContainerNetworkNode extends AbstractNetworkNode {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractStorageContainerNetworkNode.class);

protected final StateTrackedStorage[] storages;

private long energyUsage;
private final long energyUsagePerStorage;

@Nullable
private Provider provider;
@Nullable
private StateTrackedStorage.Listener listener;
private int activeStorages;

protected AbstractStorageContainerNetworkNode(final long energyUsage,
final long energyUsagePerStorage,
final int size) {
this.energyUsage = energyUsage;
this.energyUsagePerStorage = energyUsagePerStorage;
this.storages = new StateTrackedStorage[size];
}

public void setListener(final StateTrackedStorage.Listener listener) {
this.listener = listener;
}

public void setProvider(final Provider provider) {
this.provider = provider;
final List<StorageChange> changes = new ArrayList<>();
for (int i = 0; i < storages.length; ++i) {
changes.addAll(initializeStorage(i));
}
// If we are already initialized, update all the storages to keep the exposed storages in sync.
// If we are not initialized, update nothing as we have to wait for an activeness update.
if (activeStorages > 0) {
changes.forEach(this::onStorageChange);
}
updateActiveStorageCount();
}

public void onStorageChanged(final int index) {
if (index < 0 || index >= storages.length) {
LOGGER.warn("Invalid index {}", index);
return;
}
initializeStorage(index).forEach(this::onStorageChange);
updateActiveStorageCount();
}

protected void onStorageChange(final StorageChange change) {
// no op
}

private Set<StorageChange> initializeStorage(final int index) {
final Set<StorageChange> results = new HashSet<>();
if (storages[index] != null) {
results.add(new StorageChange(true, storages[index]));
}
if (provider != null) {
provider.resolve(index).ifPresentOrElse(resolved -> {
final StateTrackedStorage newStorage = new StateTrackedStorage(resolved, listener);
storages[index] = newStorage;
results.add(new StorageChange(false, newStorage));
}, () -> storages[index] = null);
}
return results;
}

private void updateActiveStorageCount() {
this.activeStorages = (int) Arrays.stream(storages).filter(Objects::nonNull).count();
}

public void setEnergyUsage(final long energyUsage) {
this.energyUsage = energyUsage;
}

@Override
public long getEnergyUsage() {
return energyUsage + (energyUsagePerStorage * activeStorages);
}

public int getSize() {
return storages.length;
}

public StorageState getState(final int index) {
final var storage = storages[index];
if (storage == null) {
return StorageState.NONE;
}
if (!isActive()) {
return StorageState.INACTIVE;
}
return storage.getState();
}

protected record StorageChange(boolean removed, StateTrackedStorage storage) {
}

@FunctionalInterface
public interface Provider {
Optional<Storage> resolve(int index);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage;

import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.NetworkNodeStorageConfiguration;
import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.network.node.externalstorage.ExternalStorageProviderFactory;
import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider;
import com.refinedmods.refinedstorage2.api.storage.Storage;
Expand All @@ -10,15 +12,21 @@
import java.util.function.LongSupplier;
import javax.annotation.Nullable;

public class ExternalStorageNetworkNode extends AbstractStorageNetworkNode implements StorageProvider {
public class ExternalStorageNetworkNode extends AbstractNetworkNode implements StorageProvider {
private final long energyUsage;
private final StorageConfiguration storageConfiguration;
private final ExposedExternalStorage storage;
@Nullable
private ExternalStorage externalStorage;

public ExternalStorageNetworkNode(final long energyUsage, final LongSupplier clock) {
this.energyUsage = energyUsage;
this.storage = new ExposedExternalStorage(this, clock);
this.storageConfiguration = new NetworkNodeStorageConfiguration(this);
this.storage = new ExposedExternalStorage(storageConfiguration, clock);
}

public StorageConfiguration getStorageConfiguration() {
return storageConfiguration;
}

public void setTrackingRepository(final TrackedStorageRepository trackingRepository) {
Expand Down
Loading

0 comments on commit 83684c8

Please sign in to comment.