Skip to content

Commit

Permalink
Merge pull request #490 from refinedmods/feat/GH-120/void-excess
Browse files Browse the repository at this point in the history
feat: void excess mode
  • Loading branch information
raoulvdberge authored Mar 10, 2024
2 parents f07c45c + 20bf875 commit 303cb25
Show file tree
Hide file tree
Showing 74 changed files with 511 additions and 333 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Void excess mode to storages.

### Fixed

- Fixed losing disk when using Wrench dismantling on the Portable Grid.
Expand Down
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ subprojects {

ext {
apis = [
':refinedstorage2-core-api',
':refinedstorage2-resource-api',
':refinedstorage2-storage-api',
':refinedstorage2-network-api',
':refinedstorage2-network',
':refinedstorage2-grid-api',
':refinedstorage2-query-parser'
':refinedstorage2-core-api',
':refinedstorage2-resource-api',
':refinedstorage2-storage-api',
':refinedstorage2-network-api',
':refinedstorage2-network',
':refinedstorage2-grid-api',
':refinedstorage2-query-parser'
]
compileApis = [':refinedstorage2-platform-api']
}
Expand All @@ -22,7 +22,6 @@ enableSonarQube("refinedmods_refinedstorage2")
sonarqube {
properties {
property "sonar.coverage.exclusions", "refinedstorage2-platform-forge/**/*,refinedstorage2-platform-fabric/**/*,refinedstorage2-platform-common/**/*,refinedstorage2-platform-api/**/*"
// TODO: REI code is duplicated as reusing it in a common module isn't possible/too difficult. Fix this.
property "sonar.cpd.exclusions", "refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/integration/recipemod/rei/*,refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/integration/recipemod/rei/*"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.controller.ControllerNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.detector.DetectorNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.exporter.ExporterNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage.ExternalStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.storage.tracked.InMemoryTrackedStorageRepository;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.grid.GridNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.importer.ImporterNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.iface.InterfaceNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.multistorage.MultiStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.SimpleNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.network.test.nodefactory;

import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.network.test.AddNetworkNode;

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

import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;

public class SimpleNetworkNode extends AbstractNetworkNode {
private long energyUsage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.refinedmods.refinedstorage2.api.core.Action;
import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;

import javax.annotation.Nullable;

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

import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage;

import com.refinedmods.refinedstorage2.api.network.node.AbstractConfiguredProxyStorage;
import com.refinedmods.refinedstorage2.api.network.node.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.core.Action;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractConfiguredProxyStorage;
import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
import com.refinedmods.refinedstorage2.api.storage.Actor;
import com.refinedmods.refinedstorage2.api.storage.composite.CompositeAwareChild;
import com.refinedmods.refinedstorage2.api.storage.composite.ConsumingStorage;
import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite;
import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorage;
import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorageListener;
Expand All @@ -21,7 +20,7 @@
import javax.annotation.Nullable;

public class ExposedExternalStorage extends AbstractConfiguredProxyStorage<ExternalStorage>
implements ConsumingStorage, CompositeAwareChild, TrackedStorage, ExternalStorageListener {
implements TrackedStorage, ExternalStorageListener {
private final Set<ParentComposite> parents = new HashSet<>();
private final LongSupplier clock;
@Nullable
Expand Down Expand Up @@ -63,6 +62,24 @@ public void onRemovedFromComposite(final ParentComposite parentComposite) {
}
}

@Override
public Amount compositeInsert(final ResourceKey resource,
final long amount,
final Action action,
final Actor actor) {
final Amount inserted = super.compositeInsert(resource, amount, action, actor);
return inserted.withoutNotifyingList();
}

@Override
public Amount compositeExtract(final ResourceKey resource,
final long amount,
final Action action,
final Actor actor) {
final Amount extracted = super.compositeExtract(resource, amount, action, actor);
return extracted.withoutNotifyingList();
}

@Override
public void setDelegate(final ExternalStorage newDelegate) {
super.setDelegate(newDelegate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.externalstorage;

import com.refinedmods.refinedstorage2.api.network.component.StorageProvider;
import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.externalstorage.ExternalStorageProviderFactory;
import com.refinedmods.refinedstorage2.api.storage.Storage;
import com.refinedmods.refinedstorage2.api.storage.external.ExternalStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.refinedmods.refinedstorage2.api.grid.watcher.GridWatcherManagerImpl;
import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent;
import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.storage.Actor;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.refinedmods.refinedstorage2.api.network.component.StorageNetworkComponent;
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.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.node.NetworkNodeActor;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
import com.refinedmods.refinedstorage2.api.storage.Actor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.importer;

import com.refinedmods.refinedstorage2.api.network.node.AbstractNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage;

import com.refinedmods.refinedstorage2.api.network.node.AbstractImmutableConfiguredProxyStorage;
import com.refinedmods.refinedstorage2.api.network.node.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractImmutableConfiguredProxyStorage;
import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl;
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.CompositeStorage;
import com.refinedmods.refinedstorage2.api.storage.composite.CompositeStorageImpl;
import com.refinedmods.refinedstorage2.api.storage.composite.ParentComposite;
Expand All @@ -16,7 +15,7 @@
import java.util.Optional;

class ExposedMultiStorage extends AbstractImmutableConfiguredProxyStorage<CompositeStorageImpl>
implements CompositeStorage, CompositeAwareChild {
implements CompositeStorage {
protected ExposedMultiStorage(final StorageConfiguration config) {
super(config, new CompositeStorageImpl(new ResourceListImpl()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.multistorage;

import com.refinedmods.refinedstorage2.api.network.component.StorageProvider;
import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode;
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 Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.storage;

import com.refinedmods.refinedstorage2.api.network.node.AbstractConfiguredProxyStorage;
import com.refinedmods.refinedstorage2.api.network.node.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractConfiguredProxyStorage;
import com.refinedmods.refinedstorage2.api.network.impl.storage.StorageConfiguration;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
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.limited.LimitedStorage;
import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource;
Expand All @@ -15,8 +14,7 @@
import java.util.Optional;
import java.util.Set;

class ExposedStorage extends AbstractConfiguredProxyStorage<Storage>
implements TrackedStorage, CompositeAwareChild {
class ExposedStorage extends AbstractConfiguredProxyStorage<Storage> implements TrackedStorage {
private final Set<ParentComposite> parents = new HashSet<>();

ExposedStorage(final StorageConfiguration config) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage2.api.network.impl.node.storage;

import com.refinedmods.refinedstorage2.api.network.component.StorageProvider;
import com.refinedmods.refinedstorage2.api.network.node.AbstractStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.network.impl.storage.AbstractStorageNetworkNode;
import com.refinedmods.refinedstorage2.api.storage.Storage;

import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.refinedmods.refinedstorage2.api.network.node;
package com.refinedmods.refinedstorage2.api.network.impl.storage;

import com.refinedmods.refinedstorage2.api.core.Action;
import com.refinedmods.refinedstorage2.api.core.CoreValidations;
import com.refinedmods.refinedstorage2.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
import com.refinedmods.refinedstorage2.api.storage.AccessMode;
import com.refinedmods.refinedstorage2.api.resource.filter.FilterMode;
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 java.util.Collection;
Expand All @@ -17,7 +18,7 @@
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 Storage, Priority {
public abstract class AbstractConfiguredProxyStorage<S extends Storage> implements CompositeAwareChild, Priority {
@Nullable
private S delegate;
private final StorageConfiguration config;
Expand All @@ -33,21 +34,39 @@ protected AbstractConfiguredProxyStorage(final StorageConfiguration config, fina

@Override
public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) {
if (delegate == null || config.getAccessMode() == AccessMode.INSERT || !config.isActive()) {
return 0;
}
return delegate.extract(resource, amount, action, actor);
throw new UnsupportedOperationException("Immediate extract is not allowed");
}

@Override
public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) {
if (delegate == null
|| config.getAccessMode() == AccessMode.EXTRACT
|| !config.isActive()
|| !config.isAllowed(resource)) {
return 0;
throw new UnsupportedOperationException("Immediate insert is not allowed");
}

@Override
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)) {
return Amount.ZERO;
}
final long inserted = delegate.insert(resource, amount, action, actor);
if ((config.isVoidExcess() && config.getFilterMode() == FilterMode.ALLOW) && inserted < amount) {
return new Amount(amount, inserted);
}
return new Amount(inserted, inserted);
}

@Override
public Amount compositeExtract(final ResourceKey resource,
final long amount,
final Action action,
final Actor actor) {
if (delegate == null || config.isInsertOnly() || !config.isActive()) {
return Amount.ZERO;
}
return delegate.insert(resource, amount, action, actor);
final long extracted = delegate.extract(resource, amount, action, actor);
return new Amount(extracted, extracted);
}

@Override
Expand Down
Loading

0 comments on commit 303cb25

Please sign in to comment.