From f2a25c561c9ddb97a78b8ba0b4a7822ac4969718 Mon Sep 17 00:00:00 2001 From: Starforcraft Date: Wed, 11 Dec 2024 17:00:43 +0100 Subject: [PATCH] feat: relay gametest --- .../common/networking/RelayTest.java | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.java index 0f74ab150..b0180ce75 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.java @@ -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; @@ -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; @@ -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(); + }); + } }