Skip to content

Commit

Permalink
Merge pull request #577 from refinedmods/feat/GH-91/disk-interface
Browse files Browse the repository at this point in the history
feat: disk interface content
  • Loading branch information
raoulvdberge authored Jun 26, 2024
2 parents 79ae178 + b8b69b5 commit a8dfcb1
Show file tree
Hide file tree
Showing 140 changed files with 2,644 additions and 438 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

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

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

## [2.0.0-milestone.3.12] - 2024-06-16
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
@@ -1,6 +1,5 @@
package com.refinedmods.refinedstorage2.api.network.impl.node;

import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage;
import com.refinedmods.refinedstorage2.api.storage.Storage;
import com.refinedmods.refinedstorage2.api.storage.StorageState;
Expand All @@ -17,12 +16,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

protected final StateTrackedStorage[] storages;

private final long energyUsage;
private long energyUsage;
private final long energyUsagePerStorage;

@Nullable
Expand Down Expand Up @@ -89,6 +88,10 @@ 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);
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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 com.refinedmods.refinedstorage2.api.storage.composite.PriorityProvider;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -22,7 +22,7 @@
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;

class RelayOutputStorage implements CompositeAwareChild, ResourceListListener, Priority {
class RelayOutputStorage implements CompositeAwareChild, ResourceListListener, PriorityProvider {
private final Set<ParentComposite> parentComposites = new HashSet<>();
private final Filter filter = new Filter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.storage;

import com.refinedmods.refinedstorage2.api.network.impl.node.AbstractStorageContainerNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.NetworkNodeStorageConfiguration;
import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.network.storage.StorageProvider;
import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage;
import com.refinedmods.refinedstorage2.api.storage.Storage;
Expand All @@ -11,11 +13,13 @@
public class StorageNetworkNode extends AbstractStorageContainerNetworkNode implements StorageProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(StorageNetworkNode.class);

private final StorageConfiguration storageConfiguration;
private final ExposedStorage storage;

public StorageNetworkNode(final long energyUsage, final long energyUsagePerStorage, final int size) {
super(energyUsage, energyUsagePerStorage, size);
this.storage = new ExposedStorage(this);
this.storageConfiguration = new NetworkNodeStorageConfiguration(this);
this.storage = new ExposedStorage(storageConfiguration);
}

@Override
Expand Down Expand Up @@ -56,6 +60,10 @@ private void disableAllStorages() {
storage.clearSources();
}

public StorageConfiguration getStorageConfiguration() {
return storageConfiguration;
}

public long getStored() {
return storage.getStored();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.storagetransfer;

public enum StorageTransferMode {
INSERT,
EXTRACT
INSERT_INTO_NETWORK,
EXTRACT_FROM_NETWORK
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
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.storage.Actor;
import com.refinedmods.refinedstorage2.api.storage.StateTrackedStorage;
import com.refinedmods.refinedstorage2.api.storage.Storage;
import com.refinedmods.refinedstorage2.api.storage.TransferHelper;
import com.refinedmods.refinedstorage2.api.storage.limited.LimitedStorage;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.function.ToLongFunction;
import java.util.function.UnaryOperator;
import javax.annotation.Nullable;

public class StorageTransferNetworkNode extends AbstractStorageContainerNetworkNode {
private final Actor actor = new NetworkNodeActor(this);
private final Filter filter = new Filter();

private StorageTransferMode mode = StorageTransferMode.INSERT;
private StorageTransferMode mode = StorageTransferMode.INSERT_INTO_NETWORK;
@Nullable
private ToLongFunction<Storage> transferQuotaProvider;
@Nullable
Expand All @@ -33,6 +39,10 @@ public void setMode(final StorageTransferMode mode) {
this.mode = mode;
}

public StorageTransferMode getMode() {
return mode;
}

public void setTransferQuotaProvider(final ToLongFunction<Storage> transferQuotaProvider) {
this.transferQuotaProvider = transferQuotaProvider;
}
Expand All @@ -41,6 +51,22 @@ public void setListener(@Nullable final StorageTransferListener listener) {
this.listener = listener;
}

public FilterMode getFilterMode() {
return filter.getMode();
}

public void setFilterMode(final FilterMode filterMode) {
filter.setMode(filterMode);
}

public void setFilters(final Set<ResourceKey> filters) {
filter.setFilters(filters);
}

public void setNormalizer(final UnaryOperator<ResourceKey> normalizer) {
filter.setNormalizer(normalizer);
}

@Override
public void doWork() {
super.doWork();
Expand All @@ -49,7 +75,7 @@ public void doWork() {
}
final StorageNetworkComponent networkStorage = network.getComponent(StorageNetworkComponent.class);
for (int i = 0; i < storages.length / 2; ++i) {
final Storage storage = storages[i];
final StateTrackedStorage storage = storages[i];
if (storage == null) {
continue;
}
Expand All @@ -60,12 +86,12 @@ public void doWork() {
}
}

private Result transfer(final Storage storage, final StorageNetworkComponent networkStorage) {
private Result transfer(final StateTrackedStorage storage, final StorageNetworkComponent networkStorage) {
if (transferQuotaProvider == null) {
return Result.FAILURE;
}
final long transferQuota = transferQuotaProvider.applyAsLong(storage);
if (mode == StorageTransferMode.INSERT) {
final long transferQuota = transferQuotaProvider.applyAsLong(storage.getDelegate());
if (mode == StorageTransferMode.INSERT_INTO_NETWORK) {
return transfer(storage, networkStorage, transferQuota, this::hasNoExtractableResources);
}
return transfer(
Expand Down Expand Up @@ -96,7 +122,7 @@ private boolean transfer(final Storage source, final Storage destination, final
final Collection<ResourceAmount> sourceContents = new LinkedHashSet<>(source.getAll());
for (final ResourceAmount resourceAmount : sourceContents) {
final ResourceKey resource = resourceAmount.getResource();
if (!isAllowed(resource)) {
if (!filter.isAllowed(resource)) {
continue;
}
final long amount = Math.min(remainder, resourceAmount.getAmount());
Expand All @@ -110,7 +136,7 @@ private boolean transfer(final Storage source, final Storage destination, final
}

private boolean hasNoExtractableResources(final Storage source) {
return source.getAll().stream().noneMatch(resourceAmount -> isAllowed(resourceAmount.getResource()));
return source.getAll().stream().noneMatch(resourceAmount -> filter.isAllowed(resourceAmount.getResource()));
}

private boolean storageIsFull(final Storage storage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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.Priority;
import com.refinedmods.refinedstorage2.api.storage.composite.PriorityProvider;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -18,7 +18,8 @@
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4")
public abstract class AbstractConfiguredProxyStorage<S extends Storage> implements CompositeAwareChild, Priority {
public abstract class AbstractConfiguredProxyStorage<S extends Storage>
implements CompositeAwareChild, PriorityProvider {
@Nullable
private S delegate;
private final StorageConfiguration config;
Expand Down Expand Up @@ -47,7 +48,10 @@ public Amount compositeInsert(final ResourceKey resource,
final long amount,
final Action action,
final Actor actor) {
if (delegate == null || config.isExtractOnly() || !config.isActive() || !config.isAllowed(resource)) {
if (delegate == null
|| config.getAccessMode().isExtractOnly()
|| !config.isActive()
|| !config.isAllowed(resource)) {
return Amount.ZERO;
}
final long inserted = delegate.insert(resource, amount, action, actor);
Expand All @@ -62,7 +66,7 @@ public Amount compositeExtract(final ResourceKey resource,
final long amount,
final Action action,
final Actor actor) {
if (delegate == null || config.isInsertOnly() || !config.isActive()) {
if (delegate == null || config.getAccessMode().isInsertOnly() || !config.isActive()) {
return Amount.ZERO;
}
final long extracted = delegate.extract(resource, amount, action, actor);
Expand Down
Loading

0 comments on commit a8dfcb1

Please sign in to comment.