Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disk Interface gametest #682

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions refinedstorage-neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ val commonResources by configurations.existing

dependencies {
testCompileOnly(libs.apiguardian)
testCompileOnly(project(":refinedstorage-common"))

compileOnly(project(":refinedstorage-common"))
compileOnly(project(":refinedstorage-common-api"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ public static Runnable storageContainsExactly(final GameTestHelper helper,
});
}

public static Runnable storageIsEmpty(final GameTestHelper helper,
final BlockPos networkPos) {
return networkIsAvailable(helper, networkPos, network -> {
final StorageNetworkComponent storage = network.getComponent(StorageNetworkComponent.class);
helper.assertTrue(storage.getStored() == 0, "Storage is not empty");
});
}

private static ResourceList toResourceList(final ResourceAmount... resources) {
return toResourceList(Arrays.asList(resources));
}
Expand Down Expand Up @@ -343,13 +351,13 @@ public static void removeItemFromChest(final GameTestHelper helper,

public static void prepareInterface(final GameTestHelper helper,
final BlockPos pos,
final ResourceAmount... resource) {
final ResourceAmount... resources) {
helper.setBlock(pos, RSBLOCKS.getInterface());
final var interfaceBlockEntity = requireBlockEntity(helper, pos, InterfaceBlockEntity.class);
final ExportedResourcesContainer exportedResources = interfaceBlockEntity.getExportedResources();

for (int i = 0; i < resource.length; i++) {
exportedResources.set(i, resource[i]);
for (int i = 0; i < resources.length; i++) {
exportedResources.set(i, resources[i]);
}
}

Expand All @@ -362,9 +370,9 @@ public static void addFluidToInterface(final GameTestHelper helper,
exportedResources.insert(resource.resource(), resource.amount(), Action.EXECUTE);
}

public static void removeFluidToInterface(final GameTestHelper helper,
final BlockPos pos,
final ResourceAmount resource) {
public static void removeFluidFromInterface(final GameTestHelper helper,
final BlockPos pos,
final ResourceAmount resource) {
final var interfaceBlockEntity = requireBlockEntity(helper, pos, InterfaceBlockEntity.class);
final ExportedResourcesContainer exportedResources = interfaceBlockEntity.getExportedResources();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public static void shouldExportFluidWithStackUpgrade(final GameTestHelper helper
}));

// Act
exporter.addUpgradeItem(RSITEMS.getStackUpgrade());
exporter.setFilters(List.of(asResource(WATER)));
exporter.addUpgradeItem(RSITEMS.getStackUpgrade());

// Assert
sequence
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
package com.refinedmods.refinedstorage.common.storage.diskinterface;

import com.refinedmods.refinedstorage.api.network.impl.node.storagetransfer.StorageTransferMode;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.filter.FilterMode;
import com.refinedmods.refinedstorage.common.util.IdentifierUtil;

import java.util.Set;

import net.minecraft.core.Direction;
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.RSITEMS;
import static com.refinedmods.refinedstorage.common.GameTestUtil.asResource;
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.GameTestUtil.storageIsEmpty;
import static com.refinedmods.refinedstorage.common.storage.diskinterface.DiskInterfaceTestPlots.addDiskToDiskInterface;
import static com.refinedmods.refinedstorage.common.storage.diskinterface.DiskInterfaceTestPlots.isDiskInOutputWithAmount;
import static com.refinedmods.refinedstorage.common.storage.diskinterface.DiskInterfaceTestPlots.preparePlot;
import static net.minecraft.world.item.Items.DIAMOND_CHESTPLATE;
import static net.minecraft.world.item.Items.DIRT;

@GameTestHolder(IdentifierUtil.MOD_ID)
@PrefixGameTestTemplate(false)
public final class DiskInterfaceTest {
private DiskInterfaceTest() {
}

@GameTest(template = "empty_15x15")
public static void shouldInsertItemsIntoNetwork(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 64);
}));

// Act
diskInterface.setTransferMode(StorageTransferMode.INSERT_INTO_NETWORK);

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 64)
))
.thenExecute(() -> addDiskToDiskInterface(
helper,
pos,
new ResourceAmount(asResource(DIRT), 10)))
.thenIdle(9 * 10)
.thenExecute(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 74)
))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 0))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldInsertItemsIntoNetworkWithStackUpgrade(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 64);
}));

// Act
diskInterface.setTransferMode(StorageTransferMode.INSERT_INTO_NETWORK);
diskInterface.addUpgradeItem(RSITEMS.getStackUpgrade());

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 64)
))
.thenExecute(() -> addDiskToDiskInterface(
helper,
pos,
new ResourceAmount(asResource(DIRT), 64)))
.thenIdle(9)
.thenExecute(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 128)
))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 0))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldInsertItemsIntoNetworkBlocklist(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 64);
}));

// Act
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);

diskInterface.setTransferMode(StorageTransferMode.INSERT_INTO_NETWORK);
diskInterface.setFuzzyMode(false);
diskInterface.setFilters(Set.of(asResource(damagedDiamondChestplate)));
diskInterface.setFilterMode(FilterMode.BLOCK);

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 64)
))
.thenExecute(() -> addDiskToDiskInterface(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(damagedDiamondChestplate), 1)
))
.thenIdle(9 * 6)
.thenExecute(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 69)
))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 1))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldInsertItemsIntoNetworkFuzzyBlocklist(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 64);
}));

// Act
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);

diskInterface.setTransferMode(StorageTransferMode.INSERT_INTO_NETWORK);
diskInterface.setFuzzyMode(true);
diskInterface.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance())));
diskInterface.setFilterMode(FilterMode.BLOCK);

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 64)
))
.thenExecute(() -> addDiskToDiskInterface(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(damagedDiamondChestplate), 1),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE.getDefaultInstance()), 1)
))
.thenIdle(9 * 7)
.thenExecute(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 69)
))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 2))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldExtractItemsFromNetwork(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
}));

// Act
diskInterface.setTransferMode(StorageTransferMode.EXTRACT_FROM_NETWORK);

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 10)
))
.thenExecute(() -> addDiskToDiskInterface(helper, pos))
.thenIdle(9 * 10)
.thenExecute(storageIsEmpty(helper, pos))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 10))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldExtractItemsFromNetworkWithStackUpgrade(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 64);
}));

// Act
diskInterface.setTransferMode(StorageTransferMode.EXTRACT_FROM_NETWORK);
diskInterface.addUpgradeItem(RSITEMS.getStackUpgrade());

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 64)
))
.thenExecute(() -> addDiskToDiskInterface(helper, pos))
.thenIdle(9)
.thenExecute(storageIsEmpty(helper, pos))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 64))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldExtractItemsFromNetworkBlocklist(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);

// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 5);
insert(helper, network, asResource(damagedDiamondChestplate), 1);
}));

// Act
diskInterface.setTransferMode(StorageTransferMode.EXTRACT_FROM_NETWORK);
diskInterface.setFuzzyMode(false);
diskInterface.setFilters(Set.of(asResource(damagedDiamondChestplate)));
diskInterface.setFilterMode(FilterMode.BLOCK);

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(damagedDiamondChestplate), 1)
))
.thenExecute(() -> addDiskToDiskInterface(helper, pos))
.thenIdle(9 * 6)
.thenExecute(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(damagedDiamondChestplate), 1)
))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 5))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldExtractItemsFromNetworkFuzzyBlocklist(final GameTestHelper helper) {
preparePlot(helper, Direction.NORTH, (diskInterface, pos, sequence) -> {
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);

// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 5);
insert(helper, network, asResource(damagedDiamondChestplate), 1);
insert(helper, network, DIAMOND_CHESTPLATE, 1);
}));

// Act
diskInterface.setTransferMode(StorageTransferMode.EXTRACT_FROM_NETWORK);
diskInterface.setFuzzyMode(true);
diskInterface.setFilters(Set.of(asResource(DIAMOND_CHESTPLATE.getDefaultInstance())));
diskInterface.setFilterMode(FilterMode.BLOCK);

// Assert
sequence
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(damagedDiamondChestplate), 1),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1)
))
.thenExecute(() -> addDiskToDiskInterface(helper, pos))
.thenIdle(9 * 7)
.thenExecute(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(damagedDiamondChestplate), 1),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1)
))
.thenExecute(() -> isDiskInOutputWithAmount(helper, pos, 5))
.thenSucceed();
});
}
}
Loading
Loading