diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerBlockEntity.java index 7fed80dc0..fdcb2634c 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerBlockEntity.java @@ -68,7 +68,7 @@ protected boolean doesBlockStateChangeWarrantNetworkNodeUpdate(final BlockState public AutocrafterManagerData getMenuData() { return new AutocrafterManagerData( getGroups().stream().map(AutocrafterManagerData.Group::of).toList(), - mainNetworkNode.isActive() + isActive() ); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java index 402e57252..5cfdda7b3 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/AutocraftingMonitorBlockEntity.java @@ -120,6 +120,6 @@ public void removeWatcher(final AutocraftingMonitorWatcher watcher) { @Override public boolean isAutocraftingMonitorActive() { - return mainNetworkNode.isActive(); + return isActive(); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorBlockEntity.java index 210638c00..fc2ea0767 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorBlockEntity.java @@ -168,7 +168,7 @@ public AbstractContainerMenu createMenu(final int syncId, final Inventory invent @Override public void updateActiveness(final BlockState state, @Nullable final BooleanProperty activenessProperty) { super.updateActiveness(state, activenessProperty); - final boolean powered = mainNetworkNode.isActive() && mainNetworkNode.isActivated(); + final boolean powered = isActive() && mainNetworkNode.isActivated(); final boolean needToUpdatePowered = state.getValue(DetectorBlock.POWERED) != powered; if (level != null && needToUpdatePowered && poweredChangeTicks++ % POWERED_CHANGE_TICK_RATE == 0) { level.setBlockAndUpdate(getBlockPos(), state.setValue(DetectorBlock.POWERED, powered)); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java index bb1180725..3751140c9 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridBlockEntity.java @@ -82,7 +82,7 @@ public GridOperations createOperations(final ResourceType resourceType, final Se @Override public boolean isGridActive() { - return mainNetworkNode.isActive(); + return isActive(); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridBlockEntity.java index 411fa2ce8..559b797f8 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/CraftingGridBlockEntity.java @@ -171,7 +171,7 @@ public final NonNullList getDrops() { } private Optional getNetwork() { - if (!mainNetworkNode.isActive()) { + if (!isActive()) { return Optional.empty(); } return Optional.ofNullable(mainNetworkNode.getNetwork()); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/NetworkTransmitterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/NetworkTransmitterBlockEntity.java index c61345e41..1463a1010 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/NetworkTransmitterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/NetworkTransmitterBlockEntity.java @@ -84,7 +84,7 @@ protected InWorldNetworkNodeContainer createMainContainer(final SimpleNetworkNod @Override public void addOutgoingConnections(final ConnectionSink sink) { super.addOutgoingConnections(sink); - if (receiverKey != null && NetworkTransmitterBlockEntity.this.mainNetworkNode.isActive()) { + if (receiverKey != null && NetworkTransmitterBlockEntity.this.isActive()) { sink.tryConnect(receiverKey.pos()); } } @@ -108,7 +108,7 @@ public void updateStateInLevel(final BlockState state) { } private NetworkTransmitterState calculateState() { - if (!mainNetworkNode.isActive()) { + if (!isActive()) { return NetworkTransmitterState.INACTIVE; } if (receiverKey == null) { @@ -124,7 +124,7 @@ private NetworkTransmitterState calculateState() { NetworkTransmitterData getStatus() { final Network network = mainNetworkNode.getNetwork(); - if (!mainNetworkNode.isActive() || network == null || level == null) { + if (!isActive() || network == null || level == null) { return INACTIVE; } if (receiverKey == null) { @@ -145,7 +145,7 @@ NetworkTransmitterData getStatus() { @Override public void doWork() { super.doWork(); - if (!mainNetworkNode.isActive() || mainNetworkNode.getNetwork() == null || receiverKey == null) { + if (!isActive() || mainNetworkNode.getNetwork() == null || receiverKey == null) { return; } final boolean receiverFound = isReceiverFoundInNetwork(mainNetworkNode.getNetwork(), receiverKey); 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 768fa7b96..8b49960f2 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 @@ -88,7 +88,7 @@ boolean isFuzzyMode() { } void setFuzzyMode(final boolean fuzzyMode) { - final boolean wasActive = mainNetworkNode.isActive(); + final boolean wasActive = isActive(); // Updating fuzzy mode will call the filter's listener as the normalizer will yield different outputs. // However, when updating a filter the storage resets and "self-removes". If the normalizer yields different // outputs too early, the self-remove operation will partially fail as the expected resources will be different. @@ -191,7 +191,7 @@ void setPassThrough(final boolean passThrough) { } boolean isActiveInternal() { - return mainNetworkNode.isActive(); + return isActive(); } Direction getDirectionInternal() { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java index 30a76f32f..0d2d83e8c 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java @@ -121,8 +121,4 @@ protected boolean doesBlockStateChangeWarrantNetworkNodeUpdate(final BlockState final BlockState newBlockState) { return AbstractDirectionalBlock.didDirectionChange(oldBlockState, newBlockState); } - - boolean isActive() { - return mainNetworkNode.isActive(); - } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java index d3b078ab7..58f1cf118 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storagemonitor/StorageMonitorBlockEntity.java @@ -87,7 +87,7 @@ public void doWork() { private void trySendDisplayUpdate(final Level level) { final long amount = getAmount(); - final boolean active = mainNetworkNode.isActive(); + final boolean active = isActive(); if ((amount != currentAmount || active != currentlyActive) && displayUpdateRateLimiter.tryAcquire()) { sendDisplayUpdate(level, amount, active); } @@ -350,7 +350,7 @@ private void sendDisplayUpdate() { if (level == null) { return; } - sendDisplayUpdate(level, getAmount(), mainNetworkNode.isActive()); + sendDisplayUpdate(level, getAmount(), isActive()); } private void sendDisplayUpdate(final Level level, final long amount, final boolean active) { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/network/AbstractBaseNetworkNodeContainerBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/network/AbstractBaseNetworkNodeContainerBlockEntity.java index c1466c893..6a649273d 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/network/AbstractBaseNetworkNodeContainerBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/network/AbstractBaseNetworkNodeContainerBlockEntity.java @@ -71,7 +71,7 @@ protected InWorldNetworkNodeContainer createMainContainer(final T networkNode) { .build(); } - public boolean calculateActive() { + protected boolean calculateActive() { final long energyUsage = mainNetworkNode.getEnergyUsage(); final boolean hasLevel = level != null && level.isLoaded(worldPosition); final boolean redstoneModeActive = !hasRedstoneMode() @@ -82,9 +82,13 @@ public boolean calculateActive() { && mainNetworkNode.getNetwork().getComponent(EnergyNetworkComponent.class).getStored() >= energyUsage; } + public boolean isActive() { + return mainNetworkNode.isActive(); + } + public void updateActiveness(final BlockState state, @Nullable final BooleanProperty activenessProperty) { final boolean newActive = calculateActive(); - final boolean nodeActivenessNeedsUpdate = newActive != mainNetworkNode.isActive(); + final boolean nodeActivenessNeedsUpdate = newActive != isActive(); final boolean blockStateActivenessNeedsUpdate = activenessProperty != null && state.getValue(activenessProperty) != newActive; final boolean activenessNeedsUpdate = nodeActivenessNeedsUpdate || blockStateActivenessNeedsUpdate; @@ -102,7 +106,7 @@ protected void activenessChanged(final boolean newActive) { LOGGER.debug( "Activeness change for node at {}: {} -> {}", getBlockPos(), - mainNetworkNode.isActive(), + isActive(), newActive ); mainNetworkNode.setActive(newActive); 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 92190071c..8b02bf950 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; @@ -25,6 +25,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; @@ -80,7 +81,7 @@ public static void checkBlockEntityActiveness(final GameTestHelper helper, pos, AbstractBaseNetworkNodeContainerBlockEntity.class ); - final boolean actualActive = blockEntity.calculateActive(); + final boolean actualActive = blockEntity.isActive(); helper.assertTrue(actualActive == expectedActive, "Activeness of Block Entity should be " + expectedActive + " but is " + actualActive); } @@ -243,14 +244,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/QuadConsumer.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/QuadConsumer.java new file mode 100644 index 000000000..b08945b87 --- /dev/null +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/QuadConsumer.java @@ -0,0 +1,6 @@ +package com.refinedmods.refinedstorage.common; + +@FunctionalInterface +public interface QuadConsumer { + void accept(T t, U u, V v, W w); +} 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/RelayTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/networking/RelayTest.java index b0180ce75..537741208 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 @@ -7,7 +7,6 @@ import java.util.Set; -import net.minecraft.core.BlockPos; import net.minecraft.gametest.framework.GameTest; import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.world.item.ItemStack; @@ -16,6 +15,7 @@ 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; @@ -33,23 +33,20 @@ private RelayTest() { @GameTest(template = "empty_15x15") public static void shouldPassThrough(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, 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(true); - // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) + .thenWaitUntil(checkEnergyInNetwork(helper, gridPos, stored -> stored)) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 10), new ResourceAmount(asResource(STONE), 15) )) @@ -65,9 +62,8 @@ public static void shouldPassThrough(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldNotPassThrough(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -78,7 +74,9 @@ public static void shouldNotPassThrough(final GameTestHelper helper) { // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, false)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, false)) + .thenWaitUntil(checkEnergyInNetwork(helper, gridPos, stored -> 0L)) + .thenWaitUntil(storageContainsExactly(helper, gridPos)) .thenWaitUntil(storageContainsExactly( helper, pos, @@ -91,9 +89,8 @@ public static void shouldNotPassThrough(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPassThroughEnergy(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -105,8 +102,9 @@ public static void shouldPassThroughEnergy(final GameTestHelper helper) { // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) - .thenWaitUntil(storageContainsExactly(helper, pos2)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) + .thenWaitUntil(checkEnergyInNetwork(helper, gridPos, stored -> stored)) + .thenWaitUntil(storageContainsExactly(helper, gridPos)) .thenWaitUntil(storageContainsExactly( helper, pos, @@ -119,9 +117,8 @@ public static void shouldPassThroughEnergy(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPassThroughStorage(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -134,10 +131,10 @@ public static void shouldPassThroughStorage(final GameTestHelper helper) { // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 10), new ResourceAmount(asResource(STONE), 15) )) @@ -153,9 +150,8 @@ public static void shouldPassThroughStorage(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -169,10 +165,10 @@ public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(STONE), 15) )) .thenWaitUntil(storageContainsExactly( @@ -187,9 +183,8 @@ public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -208,10 +203,10 @@ public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper h // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 10), new ResourceAmount(asResource(STONE), 15) )) @@ -229,9 +224,8 @@ public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper h @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -246,10 +240,10 @@ public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 10) )) .thenWaitUntil(storageContainsExactly( @@ -264,9 +258,8 @@ public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -285,10 +278,10 @@ public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper h // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), new ResourceAmount(asResource(damagedDiamondChestplate), 1) )) @@ -306,9 +299,8 @@ public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper h @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -322,12 +314,12 @@ public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) - .thenWaitUntil(networkIsAvailable(helper, pos2, network -> + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) + .thenWaitUntil(networkIsAvailable(helper, gridPos, network -> insert(helper, network, DIRT, 10))) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 20), new ResourceAmount(asResource(STONE), 15) )) @@ -337,11 +329,11 @@ public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper new ResourceAmount(asResource(DIRT), 20), new ResourceAmount(asResource(STONE), 15) )) - .thenWaitUntil(networkIsAvailable(helper, pos2, network -> + .thenWaitUntil(networkIsAvailable(helper, gridPos, network -> extract(helper, network, DIRT, 10))) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 10), new ResourceAmount(asResource(STONE), 15) )) @@ -357,9 +349,8 @@ public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -373,12 +364,12 @@ public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) - .thenWaitUntil(networkIsAvailable(helper, pos2, network -> + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) + .thenWaitUntil(networkIsAvailable(helper, gridPos, network -> insert(helper, network, DIRT, 10))) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 20), new ResourceAmount(asResource(STONE), 15) )) @@ -388,11 +379,11 @@ public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper new ResourceAmount(asResource(DIRT), 20), new ResourceAmount(asResource(STONE), 15) )) - .thenWaitUntil(networkIsAvailable(helper, pos2, network -> + .thenWaitUntil(networkIsAvailable(helper, gridPos, network -> extract(helper, network, DIRT, 10, false))) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 20), new ResourceAmount(asResource(STONE), 15) )) @@ -408,9 +399,8 @@ public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAndExtract(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, sequence) -> { + RelayTestPlots.preparePlot(helper, (relay, pos, gridPos, sequence) -> { // Arrange - final BlockPos pos2 = pos.above(); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); insert(helper, network, STONE, 15); @@ -424,12 +414,12 @@ public static void shouldPassThroughStorageAndExtract(final GameTestHelper helpe // Assert sequence - .thenWaitUntil(() -> checkBlockEntityActiveness(helper, pos2, true)) - .thenWaitUntil(networkIsAvailable(helper, pos2, network -> + .thenWaitUntil(() -> checkBlockEntityActiveness(helper, gridPos, true)) + .thenWaitUntil(networkIsAvailable(helper, gridPos, network -> insert(helper, network, DIRT, 10, false))) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(DIRT), 10), new ResourceAmount(asResource(STONE), 15) )) @@ -439,11 +429,11 @@ public static void shouldPassThroughStorageAndExtract(final GameTestHelper helpe new ResourceAmount(asResource(DIRT), 10), new ResourceAmount(asResource(STONE), 15) )) - .thenWaitUntil(networkIsAvailable(helper, pos2, network -> + .thenWaitUntil(networkIsAvailable(helper, gridPos, network -> extract(helper, network, DIRT, 10))) .thenWaitUntil(storageContainsExactly( helper, - pos2, + gridPos, new ResourceAmount(asResource(STONE), 15) )) .thenWaitUntil(storageContainsExactly( 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 index 0a906137d..bf41c6431 100644 --- 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 @@ -1,5 +1,6 @@ package com.refinedmods.refinedstorage.common.networking; +import com.refinedmods.refinedstorage.common.QuadConsumer; import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; @@ -7,7 +8,6 @@ import net.minecraft.core.Direction; import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.gametest.framework.GameTestSequence; -import org.apache.commons.lang3.function.TriConsumer; import static com.refinedmods.refinedstorage.common.GameTestUtil.RSBLOCKS; import static com.refinedmods.refinedstorage.common.GameTestUtil.requireBlockEntity; @@ -18,7 +18,7 @@ private RelayTestPlots() { } static void preparePlot(final GameTestHelper helper, - final TriConsumer consumer) { + final QuadConsumer consumer) { helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageVariant.ONE_K)); helper.setBlock( @@ -27,10 +27,14 @@ static void preparePlot(final GameTestHelper helper, ); final BlockPos relayPos = ZERO.above().above().above(); helper.setBlock(relayPos, RSBLOCKS.getRelay().getDefault().rotated(Direction.UP)); - helper.setBlock(relayPos.above(), RSBLOCKS.getGrid().getDefault()); + + final BlockPos gridPos = relayPos.above(); + helper.setBlock(gridPos, RSBLOCKS.getGrid().getDefault()); + consumer.accept( requireBlockEntity(helper, relayPos, RelayBlockEntity.class), relayPos, + gridPos, helper.startSequence() ); }