From 1f2b1b614b64936e451a22c0da442f076cf3dad9 Mon Sep 17 00:00:00 2001 From: Starforcraft Date: Wed, 11 Dec 2024 16:47:51 +0100 Subject: [PATCH] feat: relay gametest --- .../common/networking/RelayBlockEntity.java | 4 +- .../refinedstorage/common/GameTestUtil.java | 45 +- .../common/controller/ControllerTest.java | 14 +- .../common/networking/RelayConsumer.java | 12 + .../common/networking/RelayTest.java | 447 ++++++++++++++++++ .../common/networking/RelayTestPlots.java | 39 ++ 6 files changed, 543 insertions(+), 18 deletions(-) create mode 100644 refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayConsumer.java create mode 100644 refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.java create mode 100644 refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTestPlots.java diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java index 2898b7ab3..768fa7b96 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java @@ -71,7 +71,7 @@ public RelayBlockEntity(final BlockPos pos, final BlockState state) { this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( ResourceContainerImpl.createForFilter(), this::setChanged, - this::filterContainerChanged + this::setFilters ); this.mainNetworkNode.setFilterNormalizer(filter.createNormalizer()); this.containers.addContainer( @@ -98,7 +98,7 @@ void setFuzzyMode(final boolean fuzzyMode) { mainNetworkNode.setActive(wasActive); } - private void filterContainerChanged(final Set filters) { + void setFilters(final Set filters) { mainNetworkNode.setFilters(filters); setChanged(); } diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/GameTestUtil.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/GameTestUtil.java index de0a09336..0422a6dda 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/GameTestUtil.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/GameTestUtil.java @@ -2,7 +2,7 @@ import com.refinedmods.refinedstorage.api.core.Action; import com.refinedmods.refinedstorage.api.network.Network; -import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage; +import com.refinedmods.refinedstorage.api.network.energy.EnergyNetworkComponent; import com.refinedmods.refinedstorage.api.network.node.NetworkNode; import com.refinedmods.refinedstorage.api.network.storage.StorageNetworkComponent; import com.refinedmods.refinedstorage.api.resource.ResourceAmount; @@ -17,6 +17,8 @@ import com.refinedmods.refinedstorage.common.content.Items; import com.refinedmods.refinedstorage.common.iface.ExportedResourcesContainer; import com.refinedmods.refinedstorage.common.iface.InterfaceBlockEntity; +import com.refinedmods.refinedstorage.common.support.AbstractActiveColoredDirectionalBlock; +import com.refinedmods.refinedstorage.common.support.network.AbstractBaseNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage.common.support.resource.FluidResource; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; @@ -24,6 +26,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.function.Consumer; +import java.util.function.Function; import javax.annotation.Nullable; import net.minecraft.core.BlockPos; @@ -71,6 +74,19 @@ public static Runnable networkIsAvailable(final GameTestHelper helper, }; } + public static void checkBlockEntityActiveness(final GameTestHelper helper, + final BlockPos pos, + final boolean expectedActive) { + final var blockEntity = requireBlockEntity( + helper, + pos, + AbstractBaseNetworkNodeContainerBlockEntity.class + ); + final boolean actualActive = blockEntity.getBlockState().getValue(AbstractActiveColoredDirectionalBlock.ACTIVE); + helper.assertTrue(actualActive == expectedActive, "Activeness of Block Entity should be " + expectedActive + + " but is " + actualActive); + } + public static void insert(final GameTestHelper helper, final Network network, final Item resource, @@ -229,14 +245,25 @@ private static Runnable assertResourceContainerEmpty(final Component displayName }; } - public static Runnable energyStoredExactly(final EnergyStorage storage, - final long energyAmount) { - return () -> { - if (storage.getStored() != energyAmount) { - throw new GameTestAssertException("Energy stored should be: " + energyAmount - + " but is " + storage.getStored()); - } - }; + public static Runnable checkEnergyInNetwork(final GameTestHelper helper, + final BlockPos pos, + final Function storedConsumer) { + return networkIsAvailable(helper, pos, network -> { + final EnergyNetworkComponent energyComponent = network.getComponent(EnergyNetworkComponent.class); + + long storedEnergy = energyComponent.getStored(); + storedEnergy = storedConsumer.apply(storedEnergy); + + energyStoredExactly(storedEnergy, energyComponent.getCapacity()); + }); + } + + public static void energyStoredExactly(final long storedEnergy, + final long energyAmount) { + if (storedEnergy != energyAmount) { + throw new GameTestAssertException("Energy stored should be: " + energyAmount + + " but is " + storedEnergy); + } } public static Runnable interfaceContainsExactly(final GameTestHelper helper, diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/controller/ControllerTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/controller/ControllerTest.java index 2af8892d9..af85e631d 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/controller/ControllerTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/controller/ControllerTest.java @@ -34,16 +34,16 @@ public static void shouldConsumeEnergy(final GameTestHelper helper) { // Assert sequence .thenIdle(20) - .thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity())) + .thenExecute(() -> energyStoredExactly(energyStorage.getStored(), energyStorage.getCapacity())) .thenWaitUntil(() -> helper.setBlock(pos.above(), RSBLOCKS.getGrid().getDefault())) .thenIdle(1) - .thenExecute(energyStoredExactly( - energyStorage, + .thenExecute(() -> energyStoredExactly( + energyStorage.getStored(), energyStorage.getCapacity() - Platform.INSTANCE.getConfig().getGrid().getEnergyUsage() )) .thenIdle(9) - .thenExecute(energyStoredExactly( - energyStorage, + .thenExecute(() -> energyStoredExactly( + energyStorage.getStored(), energyStorage.getCapacity() - Platform.INSTANCE.getConfig().getGrid().getEnergyUsage() * 10 )) .thenSucceed(); @@ -62,10 +62,10 @@ public static void shouldNotConsumeEnergy(final GameTestHelper helper) { // Assert sequence .thenIdle(20) - .thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity())) + .thenExecute(() -> energyStoredExactly(energyStorage.getStored(), energyStorage.getCapacity())) .thenWaitUntil(() -> helper.setBlock(pos.above(), RSBLOCKS.getGrid().getDefault())) .thenIdle(20) - .thenExecute(energyStoredExactly(energyStorage, energyStorage.getCapacity())) + .thenExecute(() -> energyStoredExactly(energyStorage.getStored(), energyStorage.getCapacity())) .thenSucceed(); }); } diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayConsumer.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayConsumer.java new file mode 100644 index 000000000..8576b787c --- /dev/null +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayConsumer.java @@ -0,0 +1,12 @@ +package com.refinedmods.refinedstorage.common.networking; + +import net.minecraft.core.BlockPos; +import net.minecraft.gametest.framework.GameTestSequence; + +@FunctionalInterface +public interface RelayConsumer { + void accept(RelayBlockEntity relayBlockEntity, + BlockPos pos, + BlockPos subnetworkPos, + GameTestSequence gameTestSequence); +} 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 new file mode 100644 index 000000000..808d172c5 --- /dev/null +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.java @@ -0,0 +1,447 @@ +package com.refinedmods.refinedstorage.common.networking; + +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; + +import net.minecraft.gametest.framework.GameTest; +import net.minecraft.gametest.framework.GameTestHelper; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.gametest.GameTestHolder; +import net.neoforged.neoforge.gametest.PrefixGameTestTemplate; + +import static com.refinedmods.refinedstorage.common.GameTestUtil.asResource; +import static com.refinedmods.refinedstorage.common.GameTestUtil.checkBlockEntityActiveness; +import static com.refinedmods.refinedstorage.common.GameTestUtil.checkEnergyInNetwork; +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; +import static com.refinedmods.refinedstorage.common.GameTestUtil.storageContainsExactly; +import static net.minecraft.world.item.Items.DIAMOND_CHESTPLATE; +import static net.minecraft.world.item.Items.DIRT; +import static net.minecraft.world.item.Items.STONE; + +@GameTestHolder(IdentifierUtil.MOD_ID) +@PrefixGameTestTemplate(false) +public final class RelayTest { + private RelayTest() { + } + + @GameTest(template = "empty_15x15") + public static void shouldPassThrough(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); + })); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true)) + .thenWaitUntil(checkEnergyInNetwork(helper, subnetworkPos, stored -> stored)) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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 shouldNotPassThrough(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); + })); + + // Act + relay.setPassThrough(false); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, false)) + .thenWaitUntil(checkEnergyInNetwork(helper, subnetworkPos, stored -> 0L)) + .thenWaitUntil(storageContainsExactly(helper, subnetworkPos)) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(DIRT), 10), + new ResourceAmount(asResource(STONE), 15) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldPassThroughEnergy(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); + })); + + // Act + relay.setPassThrough(false); + relay.setPassEnergy(true); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true)) + .thenWaitUntil(checkEnergyInNetwork(helper, subnetworkPos, stored -> stored)) + .thenWaitUntil(storageContainsExactly(helper, subnetworkPos)) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(DIRT), 10), + new ResourceAmount(asResource(STONE), 15) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldPassThroughStorage(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + 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); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true)) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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 shouldPassThroughStorageBlocklist(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + 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.setFilters(Set.of(asResource(DIRT))); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true)) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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 shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); + insert(helper, network, DIAMOND_CHESTPLATE, 1); + insert(helper, network, asResource(damagedDiamondChestplate), 1); + })); + + // Act + relay.setPassThrough(false); + relay.setPassEnergy(true); + relay.setPassStorage(true); + relay.setFuzzyMode(true); + relay.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()))); + relay.setFilterMode(FilterMode.BLOCK); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true)) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + new ResourceAmount(asResource(DIRT), 10), + new ResourceAmount(asResource(STONE), 15) + )) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(DIRT), 10), + new ResourceAmount(asResource(STONE), 15), + new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), + new ResourceAmount(asResource(damagedDiamondChestplate), 1) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + 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.setFilters(Set.of(asResource(DIRT))); + relay.setFilterMode(FilterMode.ALLOW); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true)) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + new ResourceAmount(asResource(DIRT), 10) + )) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(DIRT), 10), + new ResourceAmount(asResource(STONE), 15) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, DIRT, 10); + insert(helper, network, STONE, 15); + insert(helper, network, DIAMOND_CHESTPLATE, 1); + insert(helper, network, asResource(damagedDiamondChestplate), 1); + })); + + // Act + relay.setPassThrough(false); + relay.setPassEnergy(true); + relay.setPassStorage(true); + relay.setFuzzyMode(true); + relay.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()))); + relay.setFilterMode(FilterMode.ALLOW); + + // Assert + sequence + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, subnetworkPos, true)) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), + new ResourceAmount(asResource(damagedDiamondChestplate), 1) + )) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(DIRT), 10), + new ResourceAmount(asResource(STONE), 15), + new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), + new ResourceAmount(asResource(damagedDiamondChestplate), 1) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper helper) { + RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + // Arrange + 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, subnetworkPos, true)) + .thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network -> + insert(helper, network, DIRT, 10))) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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, subnetworkPos, network -> + extract(helper, network, DIRT, 10))) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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, subnetworkPos, sequence) -> { + // Arrange + 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, subnetworkPos, true)) + .thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network -> + insert(helper, network, DIRT, 10))) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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, subnetworkPos, network -> + extract(helper, network, DIRT, 10, false))) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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, subnetworkPos, sequence) -> { + // Arrange + 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, subnetworkPos, true)) + .thenWaitUntil(networkIsAvailable(helper, subnetworkPos, network -> + insert(helper, network, DIRT, 10, false))) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + 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, subnetworkPos, network -> + extract(helper, network, DIRT, 10))) + .thenWaitUntil(storageContainsExactly( + helper, + subnetworkPos, + new ResourceAmount(asResource(STONE), 15) + )) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 15) + )) + .thenSucceed(); + }); + } +} diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTestPlots.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTestPlots.java new file mode 100644 index 000000000..22a91c089 --- /dev/null +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTestPlots.java @@ -0,0 +1,39 @@ +package com.refinedmods.refinedstorage.common.networking; + +import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; +import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.gametest.framework.GameTestHelper; + +import static com.refinedmods.refinedstorage.common.GameTestUtil.RSBLOCKS; +import static com.refinedmods.refinedstorage.common.GameTestUtil.requireBlockEntity; +import static net.minecraft.core.BlockPos.ZERO; + +final class RelayTestPlots { + private RelayTestPlots() { + } + + static void preparePlot(final GameTestHelper helper, + final RelayConsumer consumer) { + helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); + helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageVariant.ONE_K)); + helper.setBlock( + ZERO.above().above().north(), + RSBLOCKS.getFluidStorageBlock(FluidStorageVariant.SIXTY_FOUR_B) + ); + final BlockPos relayPos = ZERO.above().above().above(); + helper.setBlock(relayPos, RSBLOCKS.getRelay().getDefault().rotated(Direction.UP)); + + final BlockPos subnetworkPos = relayPos.above(); + helper.setBlock(subnetworkPos, RSBLOCKS.getGrid().getDefault()); + + consumer.accept( + requireBlockEntity(helper, relayPos, RelayBlockEntity.class), + relayPos, + subnetworkPos, + helper.startSequence() + ); + } +}