Skip to content

Commit

Permalink
feat: relay gametest
Browse files Browse the repository at this point in the history
  • Loading branch information
starforcraft committed Dec 11, 2024
1 parent 26b7632 commit f2a25c5
Showing 1 changed file with 153 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.filter.FilterMode;
import com.refinedmods.refinedstorage.api.storage.AccessMode;
import com.refinedmods.refinedstorage.common.util.IdentifierUtil;

import java.util.Set;
Expand All @@ -15,6 +16,7 @@

import static com.refinedmods.refinedstorage.common.GameTestUtil.asResource;
import static com.refinedmods.refinedstorage.common.GameTestUtil.checkBlockEntityActiveness;
import static com.refinedmods.refinedstorage.common.GameTestUtil.extract;
import static com.refinedmods.refinedstorage.common.GameTestUtil.getItemAsDamaged;
import static com.refinedmods.refinedstorage.common.GameTestUtil.insert;
import static com.refinedmods.refinedstorage.common.GameTestUtil.networkIsAvailable;
Expand Down Expand Up @@ -301,4 +303,155 @@ public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper h
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> {
// Arrange
final BlockPos pos2 = pos.above();
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
insert(helper, network, STONE, 15);
}));

// Act
relay.setPassThrough(false);
relay.setPassEnergy(true);
relay.setPassStorage(true);
relay.setAccessMode(AccessMode.INSERT_EXTRACT);

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true))
.thenWaitUntil(networkIsAvailable(helper, pos2, network ->
insert(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
pos2,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(networkIsAvailable(helper, pos2, network ->
extract(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
pos2,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> {
// Arrange
final BlockPos pos2 = pos.above();
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
insert(helper, network, STONE, 15);
}));

// Act
relay.setPassThrough(false);
relay.setPassEnergy(true);
relay.setPassStorage(true);
relay.setAccessMode(AccessMode.INSERT);

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true))
.thenWaitUntil(networkIsAvailable(helper, pos2, network ->
insert(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
pos2,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(networkIsAvailable(helper, pos2, network ->
extract(helper, network, DIRT, 10, false)))
.thenWaitUntil(storageContainsExactly(
helper,
pos2,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 20),
new ResourceAmount(asResource(STONE), 15)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldPassThroughStorageAndExtract(final GameTestHelper helper) {
RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> {
// Arrange
final BlockPos pos2 = pos.above();
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
insert(helper, network, STONE, 15);
}));

// Act
relay.setPassThrough(false);
relay.setPassEnergy(true);
relay.setPassStorage(true);
relay.setAccessMode(AccessMode.EXTRACT);

// Assert
sequence
.thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true))
.thenWaitUntil(networkIsAvailable(helper, pos2, network ->
insert(helper, network, DIRT, 10, false)))
.thenWaitUntil(storageContainsExactly(
helper,
pos2,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(networkIsAvailable(helper, pos2, network ->
extract(helper, network, DIRT, 10)))
.thenWaitUntil(storageContainsExactly(
helper,
pos2,
new ResourceAmount(asResource(STONE), 15)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(STONE), 15)
))
.thenSucceed();
});
}
}

0 comments on commit f2a25c5

Please sign in to comment.