diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockBlockEntity.java index 33c3d811d..39a198cca 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockBlockEntity.java @@ -2,6 +2,9 @@ import com.refinedmods.refinedstorage.api.network.impl.node.AbstractStorageContainerNetworkNode; import com.refinedmods.refinedstorage.api.network.impl.node.storage.StorageNetworkNode; +import com.refinedmods.refinedstorage.api.resource.ResourceKey; +import com.refinedmods.refinedstorage.api.resource.filter.FilterMode; +import com.refinedmods.refinedstorage.api.storage.AccessMode; import com.refinedmods.refinedstorage.api.storage.Storage; import com.refinedmods.refinedstorage.common.api.RefinedStorageApi; import com.refinedmods.refinedstorage.common.api.storage.SerializableStorage; @@ -18,6 +21,7 @@ import com.refinedmods.refinedstorage.common.support.resource.ResourceContainerImpl; import java.util.Optional; +import java.util.Set; import java.util.UUID; import javax.annotation.Nullable; @@ -57,7 +61,7 @@ public StorageBlockBlockEntity(final BlockPos pos, this.filter = FilterWithFuzzyMode.createAndListenForUniqueFilters( ResourceContainerImpl.createForFilter(provider.getResourceFactory()), this::setChanged, - mainNetworkNode.getStorageConfiguration()::setFilters + this::setFilters ); this.configContainer = new StorageConfigurationContainerImpl( mainNetworkNode.getStorageConfiguration(), @@ -144,6 +148,27 @@ private void tryRemoveCurrentStorage(final UUID newStorageId) { ); } + void setFilters(final Set filters) { + mainNetworkNode.getStorageConfiguration().setFilters(filters); + } + + void setFilterMode(final FilterMode mode) { + mainNetworkNode.getStorageConfiguration().setFilterMode(mode); + setChanged(); + } + + void setFuzzyMode(final boolean fuzzyMode) { + filter.setFuzzyMode(fuzzyMode); + } + + void setAccessMode(final AccessMode accessMode) { + mainNetworkNode.getStorageConfiguration().setAccessMode(accessMode); + } + + void setVoidExcess(final boolean voidExcess) { + mainNetworkNode.getStorageConfiguration().setVoidExcess(voidExcess); + } + @Override @Nullable public UUID getStorageId() { diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/ConstructorTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/ConstructorTest.java index dc4850830..811fe85e2 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/ConstructorTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/ConstructorTest.java @@ -22,6 +22,7 @@ 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 com.refinedmods.refinedstorage.common.constructordestructor.ConstructorTestPlots.preparePlot; import static net.minecraft.world.item.Items.DIRT; import static net.minecraft.world.item.Items.FIREWORK_ROCKET; import static net.minecraft.world.item.Items.STONE; @@ -35,7 +36,7 @@ private ConstructorTest() { @GameTest(template = "empty_15x15") public static void shouldPlaceBlock(final GameTestHelper helper) { - ConstructorTestPlots.preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -60,7 +61,7 @@ public static void shouldPlaceBlock(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPlaceWater(final GameTestHelper helper) { - ConstructorTestPlots.preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -87,7 +88,7 @@ public static void shouldPlaceWater(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldDropItem(final GameTestHelper helper) { - ConstructorTestPlots.preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -119,7 +120,7 @@ public static void shouldDropItem(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldDropItemWithStackUpgrade(final GameTestHelper helper) { - ConstructorTestPlots.preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 65); @@ -159,7 +160,7 @@ public static void shouldDropItemWithStackUpgrade(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPlaceFireworks(final GameTestHelper helper) { - ConstructorTestPlots.preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (constructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/DestructorTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/DestructorTest.java index 0b7d8d6cf..6b021ad1e 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/DestructorTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/constructordestructor/DestructorTest.java @@ -19,6 +19,7 @@ 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 com.refinedmods.refinedstorage.common.constructordestructor.DestructorTestPlots.preparePlot; import static net.minecraft.world.item.Items.DIAMOND; import static net.minecraft.world.item.Items.DIAMOND_ORE; import static net.minecraft.world.item.Items.DIRT; @@ -34,7 +35,7 @@ private DestructorTest() { @GameTest(template = "empty_15x15") public static void shouldBreakBlock(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -68,7 +69,7 @@ public static void shouldBreakBlock(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldBreakBlockAllowlist(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -99,7 +100,7 @@ public static void shouldBreakBlockAllowlist(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldBreakBlockBlocklist(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -130,7 +131,7 @@ public static void shouldBreakBlockBlocklist(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldBreakBlockWithSilkTouchUpgrade(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -157,7 +158,7 @@ public static void shouldBreakBlockWithSilkTouchUpgrade(final GameTestHelper hel @GameTest(template = "empty_15x15") public static void shouldPickupItemAllowlist(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -189,7 +190,7 @@ public static void shouldPickupItemAllowlist(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPickupItemBlocklist(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -221,7 +222,7 @@ public static void shouldPickupItemBlocklist(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldDrainFluidAllowlist(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -253,7 +254,7 @@ public static void shouldDrainFluidAllowlist(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldDrainFluidBlocklist(final GameTestHelper helper) { - DestructorTestPlots.preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { + preparePlot(helper, Direction.EAST, (destructor, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); 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 af85e631d..25916adde 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 @@ -13,6 +13,7 @@ import static com.refinedmods.refinedstorage.common.GameTestUtil.RSBLOCKS; import static com.refinedmods.refinedstorage.common.GameTestUtil.energyStoredExactly; import static com.refinedmods.refinedstorage.common.GameTestUtil.networkIsAvailable; +import static com.refinedmods.refinedstorage.common.controller.ControllerTestPlots.preparePlot; @GameTestHolder(IdentifierUtil.MOD_ID) @PrefixGameTestTemplate(false) @@ -22,7 +23,7 @@ private ControllerTest() { @GameTest(template = "empty_15x15") public static void shouldConsumeEnergy(final GameTestHelper helper) { - ControllerTestPlots.preparePlot(helper, false, (controller, pos, sequence) -> { + preparePlot(helper, false, (controller, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { })); @@ -52,7 +53,7 @@ public static void shouldConsumeEnergy(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldNotConsumeEnergy(final GameTestHelper helper) { - ControllerTestPlots.preparePlot(helper, true, (controller, pos, sequence) -> { + preparePlot(helper, true, (controller, pos, sequence) -> { // Arrange final EnergyStorage energyStorage = controller.getEnergyStorage(); diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java index fa0298721..af5b2f689 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/exporter/ExporterTest.java @@ -25,6 +25,7 @@ import static com.refinedmods.refinedstorage.common.GameTestUtil.interfaceContainsExactly; import static com.refinedmods.refinedstorage.common.GameTestUtil.networkIsAvailable; import static com.refinedmods.refinedstorage.common.GameTestUtil.storageContainsExactly; +import static com.refinedmods.refinedstorage.common.exporter.ExporterTestPlots.preparePlot; 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; @@ -38,7 +39,7 @@ private ExporterTest() { @GameTest(template = "empty_15x15") public static void shouldExportItem(final GameTestHelper helper) { - ExporterTestPlots.preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { + preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { // Arrange final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); @@ -71,7 +72,7 @@ public static void shouldExportItem(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldExportItemWithStackUpgrade(final GameTestHelper helper) { - ExporterTestPlots.preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { + preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 65); @@ -115,7 +116,7 @@ public static void shouldExportItemWithStackUpgrade(final GameTestHelper helper) @GameTest(template = "empty_15x15") public static void shouldExportItemWithRegulatorUpgrade(final GameTestHelper helper) { - ExporterTestPlots.preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { + preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 15); @@ -151,7 +152,7 @@ public static void shouldExportItemWithRegulatorUpgrade(final GameTestHelper hel @GameTest(template = "empty_15x15") public static void shouldExportItemFuzzy(final GameTestHelper helper) { - ExporterTestPlots.preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { + preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> { // Arrange final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); @@ -186,7 +187,7 @@ public static void shouldExportItemFuzzy(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldExportFluid(final GameTestHelper helper) { - ExporterTestPlots.preparePlot(helper, Blocks.CAULDRON, Direction.EAST, (exporter, pos, sequence) -> { + preparePlot(helper, Blocks.CAULDRON, Direction.EAST, (exporter, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -214,7 +215,7 @@ public static void shouldExportFluid(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldExportFluidWithStackUpgrade(final GameTestHelper helper) { - ExporterTestPlots.preparePlot(helper, RSBLOCKS.getInterface(), Direction.EAST, (exporter, pos, sequence) -> { + preparePlot(helper, RSBLOCKS.getInterface(), Direction.EAST, (exporter, pos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); 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 808d172c5..20c563812 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 @@ -21,6 +21,7 @@ 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 com.refinedmods.refinedstorage.common.networking.RelayTestPlots.preparePlot; 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; @@ -33,7 +34,7 @@ private RelayTest() { @GameTest(template = "empty_15x15") public static void shouldPassThrough(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -62,7 +63,7 @@ public static void shouldPassThrough(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldNotPassThrough(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -89,7 +90,7 @@ public static void shouldNotPassThrough(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPassThroughEnergy(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -117,7 +118,7 @@ public static void shouldPassThroughEnergy(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPassThroughStorage(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -150,7 +151,7 @@ public static void shouldPassThroughStorage(final GameTestHelper helper) { @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -183,7 +184,7 @@ public static void shouldPassThroughStorageBlocklist(final GameTestHelper helper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { @@ -224,7 +225,7 @@ public static void shouldPassThroughStorageFuzzyBlocklist(final GameTestHelper h @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -258,7 +259,7 @@ public static void shouldPassThroughStorageAllowlist(final GameTestHelper helper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { @@ -299,7 +300,7 @@ public static void shouldPassThroughStorageFuzzyAllowlist(final GameTestHelper h @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -349,7 +350,7 @@ public static void shouldPassThroughStorageAndInsertExtract(final GameTestHelper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); @@ -399,7 +400,7 @@ public static void shouldPassThroughStorageAndInsert(final GameTestHelper helper @GameTest(template = "empty_15x15") public static void shouldPassThroughStorageAndExtract(final GameTestHelper helper) { - RelayTestPlots.preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { + preparePlot(helper, (relay, pos, subnetworkPos, sequence) -> { // Arrange sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { insert(helper, network, DIRT, 10); diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockFluidTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockFluidTest.java new file mode 100644 index 000000000..b36da2066 --- /dev/null +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockFluidTest.java @@ -0,0 +1,320 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +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.Platform; +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.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.extract; +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 com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockTestPlots.preparePlot; +import static net.minecraft.world.level.material.Fluids.LAVA; +import static net.minecraft.world.level.material.Fluids.WATER; + +@GameTestHolder(IdentifierUtil.MOD_ID) +@PrefixGameTestTemplate(false) +public final class StorageBlockFluidTest { + private StorageBlockFluidTest() { + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertFluids(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 2))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 2) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 14); + insert(helper, network, LAVA, Platform.INSTANCE.getBucketAmount() * 16); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16), + new ResourceAmount(asResource(LAVA), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertFluidAllowlist(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16))); + + // Act + storageBlock.setFilterMode(FilterMode.ALLOW); + storageBlock.setFilters(Set.of(asResource(WATER))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16); + insert(helper, network, LAVA, Platform.INSTANCE.getBucketAmount(), false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 32) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertFluidBlocklist(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16))); + + // Act + storageBlock.setFilterMode(FilterMode.BLOCK); + storageBlock.setFilters(Set.of(asResource(LAVA))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16); + insert(helper, network, LAVA, Platform.INSTANCE.getBucketAmount(), false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 32) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldExtractFluids(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16); + insert(helper, network, LAVA, Platform.INSTANCE.getBucketAmount()); + })); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16), + new ResourceAmount(asResource(LAVA), Platform.INSTANCE.getBucketAmount()) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + extract(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 10); + extract(helper, network, LAVA, Platform.INSTANCE.getBucketAmount()); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 6) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldExtractFluidAllowlist(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16); + })); + + // Act + storageBlock.setFilterMode(FilterMode.ALLOW); + storageBlock.setFilters(Set.of(asResource(WATER))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + extract(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 8); + extract(helper, network, LAVA, Platform.INSTANCE.getBucketAmount(), false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 8) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldExtractFluidBlocklist(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16); + })); + + // Act + storageBlock.setFilterMode(FilterMode.BLOCK); + storageBlock.setFilters(Set.of(asResource(LAVA))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + extract(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 8); + extract(helper, network, LAVA, Platform.INSTANCE.getBucketAmount(), false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 8) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldVoidFluids(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 64))); + + // Act + storageBlock.setFilterMode(FilterMode.ALLOW); + storageBlock.setFilters(Set.of(asResource(WATER))); + storageBlock.setVoidExcess(true); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 2); + insert(helper, network, LAVA, Platform.INSTANCE.getBucketAmount(), false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 64) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldRespectFluidInsertAccessMode(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16))); + + // Act + storageBlock.setAccessMode(AccessMode.INSERT); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16); + insert(helper, network, LAVA, Platform.INSTANCE.getBucketAmount()); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 32), + new ResourceAmount(asResource(LAVA), Platform.INSTANCE.getBucketAmount()) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> + extract(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16, false))) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 32), + new ResourceAmount(asResource(LAVA), Platform.INSTANCE.getBucketAmount()) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldRespectFluidExtractAccessMode(final GameTestHelper helper) { + preparePlot(helper, false, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16))); + + // Assert + sequence + .thenExecute(() -> storageBlock.setAccessMode(AccessMode.EXTRACT)) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 16, false); + insert(helper, network, LAVA, Platform.INSTANCE.getBucketAmount(), false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 16) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> + extract(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 8))) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 8) + )) + .thenSucceed(); + }); + } +} diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockItemTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockItemTest.java new file mode 100644 index 000000000..611396f98 --- /dev/null +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockItemTest.java @@ -0,0 +1,373 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +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.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 com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockTestPlots.preparePlot; +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 StorageBlockItemTest { + private StorageBlockItemTest() { + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertItems(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> insert(helper, network, STONE, 2))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 2) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 62); + insert(helper, network, DIRT, 12); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64), + new ResourceAmount(asResource(DIRT), 12) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertItemAllowlist(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> insert(helper, network, STONE, 64))); + + // Act + storageBlock.setFilterMode(FilterMode.ALLOW); + storageBlock.setFilters(Set.of(asResource(STONE))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 64); + insert(helper, network, DIRT, 12, false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 128) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertItemFuzzyAllowlist(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { })); + + // Act + final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); + + storageBlock.setFuzzyMode(true); + storageBlock.setFilterMode(FilterMode.ALLOW); + storageBlock.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly(helper, pos)) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 12, false); + insert(helper, network, DIAMOND_CHESTPLATE, 1); + insert(helper, network, asResource(damagedDiamondChestplate), 1); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1), + new ResourceAmount(asResource(damagedDiamondChestplate), 1) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertItemBlocklist(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> insert(helper, network, STONE, 64))); + + // Act + storageBlock.setFilterMode(FilterMode.BLOCK); + storageBlock.setFilters(Set.of(asResource(DIRT))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 64); + insert(helper, network, DIRT, 12, false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 128) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldInsertItemFuzzyBlocklist(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { })); + + // Act + final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500); + + storageBlock.setFuzzyMode(true); + storageBlock.setFilterMode(FilterMode.BLOCK); + storageBlock.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly(helper, pos)) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 12); + insert(helper, network, DIAMOND_CHESTPLATE, 1, false); + insert(helper, network, asResource(damagedDiamondChestplate), 1, false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 12) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldExtractItems(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 64); + insert(helper, network, DIRT, 12); + })); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64), + new ResourceAmount(asResource(DIRT), 12) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + extract(helper, network, STONE, 62); + extract(helper, network, DIRT, 12); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 2) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldExtractItemAllowlist(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 64); + })); + + // Act + storageBlock.setFilterMode(FilterMode.ALLOW); + storageBlock.setFilters(Set.of(asResource(STONE))); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + extract(helper, network, STONE, 32); + extract(helper, network, DIRT, 12, false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 32) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldExtractItemBlocklist(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> insert(helper, network, STONE, 64))); + + // Act + storageBlock.setFilterMode(FilterMode.BLOCK); + + // Assert + sequence + .thenExecute(() -> storageBlock.setFilters(Set.of(asResource(DIRT)))) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + extract(helper, network, STONE, 32); + extract(helper, network, DIRT, 12, false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 32) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldVoidItems(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> insert(helper, network, STONE, 1024))); + + // Act + storageBlock.setFilterMode(FilterMode.ALLOW); + storageBlock.setFilters(Set.of(asResource(STONE))); + storageBlock.setVoidExcess(true); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 1024) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 2); + insert(helper, network, DIRT, 2, false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 1024) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldRespectItemInsertAccessMode(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> insert(helper, network, STONE, 64))); + + // Act + storageBlock.setAccessMode(AccessMode.INSERT); + + // Assert + sequence + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 64); + insert(helper, network, DIRT, 12); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 128), + new ResourceAmount(asResource(DIRT), 12) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> extract(helper, network, STONE, 32, false))) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 128), + new ResourceAmount(asResource(DIRT), 12) + )) + .thenSucceed(); + }); + } + + @GameTest(template = "empty_15x15") + public static void shouldRespectItemExtractAccessMode(final GameTestHelper helper) { + preparePlot(helper, true, (storageBlock, pos, sequence) -> { + // Arrange + sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> insert(helper, network, STONE, 64))); + + // Assert + sequence + .thenExecute(() -> storageBlock.setAccessMode(AccessMode.EXTRACT)) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> { + insert(helper, network, STONE, 64, false); + insert(helper, network, DIRT, 12, false); + })) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 64) + )) + .thenExecute(networkIsAvailable(helper, pos, network -> extract(helper, network, STONE, 32))) + .thenWaitUntil(storageContainsExactly( + helper, + pos, + new ResourceAmount(asResource(STONE), 32) + )) + .thenSucceed(); + }); + } +} diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockTestPlots.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockTestPlots.java new file mode 100644 index 000000000..599e68445 --- /dev/null +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/storageblock/StorageBlockTestPlots.java @@ -0,0 +1,35 @@ +package com.refinedmods.refinedstorage.common.storage.storageblock; + +import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant; +import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant; + +import net.minecraft.core.BlockPos; +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; +import static net.minecraft.core.BlockPos.ZERO; + +final class StorageBlockTestPlots { + private StorageBlockTestPlots() { + } + + static void preparePlot(final GameTestHelper helper, + final boolean itemStorage, + final TriConsumer consumer) { + helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault()); + final BlockPos storagePos = ZERO.above().above(); + if (itemStorage) { + helper.setBlock(storagePos, RSBLOCKS.getItemStorageBlock(ItemStorageVariant.ONE_K)); + } else { + helper.setBlock(storagePos, RSBLOCKS.getFluidStorageBlock(FluidStorageVariant.SIXTY_FOUR_B)); + } + consumer.accept( + requireBlockEntity(helper, storagePos, StorageBlockBlockEntity.class), + storagePos, + helper.startSequence() + ); + } +}