Skip to content

Commit

Permalink
refactor: remove empty actor class, replace it with empty constant on…
Browse files Browse the repository at this point in the history
… actor
  • Loading branch information
raoulvdberge committed Dec 28, 2024
1 parent ecc8811 commit 873c474
Show file tree
Hide file tree
Showing 45 changed files with 587 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.StorageImpl;
import com.refinedmods.refinedstorage.api.storage.root.RootStorage;
import com.refinedmods.refinedstorage.api.storage.root.RootStorageImpl;
Expand All @@ -15,7 +15,7 @@ public static RootStorage storage(final ResourceAmount... resourceAmounts) {
final RootStorage storage = new RootStorageImpl();
storage.addSource(new StorageImpl());
for (final ResourceAmount resourceAmount : resourceAmounts) {
storage.insert(resourceAmount.resource(), resourceAmount.amount(), Action.EXECUTE, EmptyActor.INSTANCE);
storage.insert(resourceAmount.resource(), resourceAmount.amount(), Action.EXECUTE, Actor.EMPTY);
}
return storage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.AbstractProxyStorage;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Storage;
import com.refinedmods.refinedstorage.api.storage.tracked.TrackedResource;
import com.refinedmods.refinedstorage.api.storage.tracked.TrackedStorage;
Expand Down Expand Up @@ -35,7 +34,7 @@ void load(final StorageCodecs.StorageResource<? extends ResourceKey> storageReso
if (!type.isAllowed(resource)) {
return;
}
super.insert(resource, storageResource.amount(), Action.EXECUTE, EmptyActor.INSTANCE);
super.insert(resource, storageResource.amount(), Action.EXECUTE, Actor.EMPTY);
storageResource.changed().ifPresent(
changed -> trackingRepository.update(resource, new PlayerActor(changed.changedBy()), changed.changedAt())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.grid.operations.GridExtractMode;
import com.refinedmods.refinedstorage.api.grid.operations.GridOperations;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.Storage;
import com.refinedmods.refinedstorage.common.api.grid.Grid;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy;
Expand Down Expand Up @@ -201,6 +201,6 @@ private boolean hasBucketInInventory() {
}

private boolean hasBucketInStorage() {
return itemStorage.extract(BUCKET_ITEM_RESOURCE, 1, Action.SIMULATE, EmptyActor.INSTANCE) == 1;
return itemStorage.extract(BUCKET_ITEM_RESOURCE, 1, Action.SIMULATE, Actor.EMPTY) == 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Storage;
import com.refinedmods.refinedstorage.api.storage.limited.LimitedStorageImpl;
import com.refinedmods.refinedstorage.api.storage.root.RootStorage;
Expand Down Expand Up @@ -45,7 +44,7 @@ class InsertTest {
void shouldInsertIntoDestination(final GridInsertMode insertMode) {
// Arrange
final Storage source = new LimitedStorageImpl(100);
source.insert(A, MAX_COUNT * 3, Action.EXECUTE, EmptyActor.INSTANCE);
source.insert(A, MAX_COUNT * 3, Action.EXECUTE, Actor.EMPTY);

final Storage destination = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(destination);
Expand Down Expand Up @@ -97,11 +96,11 @@ void shouldNotInsertIntoDestinationWhenResourceIsNotPresentInSource(final GridIn
void shouldNotInsertIntoDestinationWhenNoSpaceIsPresentInDestination(final GridInsertMode insertMode) {
// Arrange
final Storage source = new LimitedStorageImpl(100);
source.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE);
source.insert(A, 100, Action.EXECUTE, Actor.EMPTY);

final Storage destination = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(destination);
rootStorage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 100, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.insert(A, insertMode, source);
Expand All @@ -125,11 +124,11 @@ class InsertEntireResourceTest {
void shouldInsertIntoDestinationWithRemainder() {
// Arrange
final Storage source = new LimitedStorageImpl(100);
source.insert(A, MAX_COUNT, Action.EXECUTE, EmptyActor.INSTANCE);
source.insert(A, MAX_COUNT, Action.EXECUTE, Actor.EMPTY);

final Storage destination = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(destination);
rootStorage.insert(A, 100 - MAX_COUNT + 1, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 100 - MAX_COUNT + 1, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.insert(A, GridInsertMode.ENTIRE_RESOURCE, source);
Expand Down Expand Up @@ -169,11 +168,11 @@ public long extract(final ResourceKey resource,
return super.extract(resource, amount, action, source);
}
};
source.insert(A, MAX_COUNT, Action.EXECUTE, EmptyActor.INSTANCE);
source.insert(A, MAX_COUNT, Action.EXECUTE, Actor.EMPTY);

final Storage destination = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(destination);
rootStorage.insert(A, 100 - MAX_COUNT + 1, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 100 - MAX_COUNT + 1, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.insert(A, GridInsertMode.ENTIRE_RESOURCE, source);
Expand Down Expand Up @@ -201,7 +200,7 @@ void shouldExtractFromSourceToDestination(final GridExtractMode extractMode) {

final Storage source = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(source);
rootStorage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 100, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.extract(A, extractMode, destination);
Expand Down Expand Up @@ -251,11 +250,11 @@ void shouldNotExtractFromSourceWhenResourceIsNotPresentInSource(final GridExtrac
void shouldNotExtractFromSourceIfThereIsNoSpaceInDestination(final GridExtractMode extractMode) {
// Arrange
final Storage destination = new LimitedStorageImpl(100);
destination.insert(B, 100, Action.EXECUTE, EmptyActor.INSTANCE);
destination.insert(B, 100, Action.EXECUTE, Actor.EMPTY);

final Storage source = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(source);
rootStorage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 100, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.extract(A, extractMode, destination);
Expand All @@ -282,7 +281,7 @@ void shouldExtractEntireResourceFromSourceToDestinationIfResourceIsLessThanMaxCo

final Storage source = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(source);
rootStorage.insert(A, MAX_COUNT - 1, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, MAX_COUNT - 1, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.extract(A, GridExtractMode.ENTIRE_RESOURCE, destination);
Expand All @@ -307,7 +306,7 @@ void shouldExtractEntireResourceWithRemainderFromSourceToDestinationIfThereIsNot

final Storage source = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(source);
rootStorage.insert(A, 100, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 100, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.extract(A, GridExtractMode.ENTIRE_RESOURCE, destination);
Expand Down Expand Up @@ -337,7 +336,7 @@ void shouldExtractSingleAmountIfResourceHasSingleAmountWhenExtractingHalfResourc

final Storage source = new TrackedStorageImpl(new LimitedStorageImpl(100), () -> 0L);
rootStorage.addSource(source);
rootStorage.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 1, Action.EXECUTE, Actor.EMPTY);

// Act
final boolean success = sut.extract(A, GridExtractMode.HALF_RESOURCE, destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.refinedmods.refinedstorage.api.grid.operations.GridExtractMode;
import com.refinedmods.refinedstorage.api.grid.operations.GridOperations;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Storage;
import com.refinedmods.refinedstorage.common.api.grid.Grid;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy;
Expand Down Expand Up @@ -147,7 +146,7 @@ private boolean isFluidContainerOnCursor() {
}

private boolean hasBucketInStorage() {
return itemStorage.extract(BUCKET_ITEM_RESOURCE, 1, Action.SIMULATE, EmptyActor.INSTANCE) == 1;
return itemStorage.extract(BUCKET_ITEM_RESOURCE, 1, Action.SIMULATE, Actor.EMPTY) == 1;
}

private boolean hasBucketInInventory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.refinedmods.refinedstorage.api.resource.list.MutableResourceList;
import com.refinedmods.refinedstorage.api.resource.list.MutableResourceListImpl;
import com.refinedmods.refinedstorage.api.resource.list.ResourceList;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.common.api.support.network.AbstractNetworkNodeContainerBlockEntity;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainer;
import com.refinedmods.refinedstorage.common.content.Blocks;
Expand Down Expand Up @@ -130,7 +130,7 @@ public static void insert(final GameTestHelper helper,
final long amount,
final boolean shouldSucceed) {
final StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class);
final long inserted = storage.insert(resource, amount, Action.EXECUTE, EmptyActor.INSTANCE);
final long inserted = storage.insert(resource, amount, Action.EXECUTE, Actor.EMPTY);
if (shouldSucceed) {
helper.assertTrue(inserted == amount, "Resource couldn't be inserted");
} else {
Expand Down Expand Up @@ -174,7 +174,7 @@ public static void extract(final GameTestHelper helper,
final long amount,
final boolean shouldSucceed) {
final StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class);
final long extracted = storage.extract(resource, amount, Action.EXECUTE, EmptyActor.INSTANCE);
final long extracted = storage.extract(resource, amount, Action.EXECUTE, Actor.EMPTY);
if (shouldSucceed) {
helper.assertTrue(extracted == amount, "Resource couldn't be extracted");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.refinedmods.refinedstorage.api.network.impl.node.storage.StorageNetworkNode;
import com.refinedmods.refinedstorage.api.network.node.container.NetworkNodeContainer;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.StorageImpl;
import com.refinedmods.refinedstorage.network.test.fixtures.ActorFixture;

Expand Down Expand Up @@ -134,7 +134,7 @@ private NetworkSide createNetworkSide(final MasterSlave side,
);
final GridWatcher watcher = mock(GridWatcher.class, "watcher for " + side.name());
nodeB.setActive(true);
nodeB.addWatcher(watcher, EmptyActor.class);
nodeB.addWatcher(watcher, Actor.EMPTY.getClass());
return new NetworkSide(a, nodeA, b, nodeB, watcher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.refinedmods.refinedstorage.api.network.impl.node.patternprovider.PatternProviderNetworkNode;
import com.refinedmods.refinedstorage.api.network.node.container.NetworkNodeContainer;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.StorageImpl;
import com.refinedmods.refinedstorage.api.storage.root.RootStorage;
import com.refinedmods.refinedstorage.api.storage.root.RootStorageImpl;
Expand Down Expand Up @@ -149,14 +149,14 @@ void shouldRemovePatternManually() {

@Test
void shouldStartTask() {
sut.startTask(A, 10, EmptyActor.INSTANCE, true);
sut.startTask(A, 10, Actor.EMPTY, true);
}

@Test
void shouldGetPreview() throws ExecutionException, InterruptedException {
// Arrange
rootStorage.addSource(new StorageImpl());
rootStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE);
rootStorage.insert(A, 10, Action.EXECUTE, Actor.EMPTY);

sut.add(new PatternImpl(
List.of(new Ingredient(3, List.of(A))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent;
import com.refinedmods.refinedstorage.api.storage.EmptyActor;
import com.refinedmods.refinedstorage.api.storage.Actor;
import com.refinedmods.refinedstorage.api.storage.StorageImpl;
import com.refinedmods.refinedstorage.network.test.AddNetworkNode;
import com.refinedmods.refinedstorage.network.test.InjectNetworkStorageComponent;
Expand Down Expand Up @@ -125,7 +125,7 @@ void testModes(final DetectorMode mode,
sut.setAmount(comparisonAmount);

if (amountInNetwork > 0) {
storage.insert(A, amountInNetwork, Action.EXECUTE, EmptyActor.INSTANCE);
storage.insert(A, amountInNetwork, Action.EXECUTE, Actor.EMPTY);
}

// Act
Expand Down
Loading

0 comments on commit 873c474

Please sign in to comment.