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

Interface gametest #687

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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.refinedmods.refinedstorage.api.network.impl.node.iface.InterfaceNetworkNode;
import com.refinedmods.refinedstorage.api.network.impl.node.iface.externalstorage.InterfaceExternalStorageProvider;
import com.refinedmods.refinedstorage.api.network.impl.node.iface.externalstorage.InterfaceExternalStorageProviderImpl;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.Platform;
import com.refinedmods.refinedstorage.common.api.RefinedStorageApi;
Expand All @@ -17,6 +18,7 @@
import com.refinedmods.refinedstorage.common.support.resource.ResourceContainerData;
import com.refinedmods.refinedstorage.common.support.resource.ResourceContainerImpl;

import java.util.List;
import javax.annotation.Nullable;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -137,6 +139,16 @@ void setFuzzyMode(final boolean fuzzyMode) {
filter.setFuzzyMode(fuzzyMode);
}

void clearFilters() {
filter.getFilterContainer().clear();
}

void setFilters(final List<ResourceAmount> filters) {
for (int i = 0; i < filters.size(); i++) {
filter.getFilterContainer().set(i, filters.get(i));
}
}

public ExportedResourcesContainer getExportedResources() {
return exportedResources;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
package com.refinedmods.refinedstorage.common.iface;

import com.refinedmods.refinedstorage.api.core.Action;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.Platform;
import com.refinedmods.refinedstorage.common.util.IdentifierUtil;

import java.util.List;

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.assertInterfaceEmpty;
import static com.refinedmods.refinedstorage.common.GameTestUtil.getItemAsDamaged;
import static com.refinedmods.refinedstorage.common.GameTestUtil.insert;
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.iface.InterfaceTestPlots.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;
import static net.minecraft.world.level.material.Fluids.WATER;

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

@GameTest(template = "empty_15x15")
public static void shouldExportItem(final GameTestHelper helper) {
preparePlot(helper, (iface, pos, sequence) -> {
// Arrange
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);

sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
insert(helper, network, STONE, 15);
insert(helper, network, asResource(damagedDiamondChestplate), 1);
}));

// Act
iface.setFuzzyMode(false);
iface.setFilters(List.of(
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1)
));

// Assert
sequence
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 10)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(STONE), 15),
new ResourceAmount(asResource(damagedDiamondChestplate), 1)
))
.thenExecute(() -> {
iface.clearFilters();
iface.setFilters(List.of(
new ResourceAmount(asResource(DIRT), 5)
));
})
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(STONE), 15),
new ResourceAmount(asResource(damagedDiamondChestplate), 1)
))
.thenExecute(() -> iface.setFilters(List.of(
new ResourceAmount(asResource(DIRT), 7)
)))
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 7)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 3),
new ResourceAmount(asResource(STONE), 15),
new ResourceAmount(asResource(damagedDiamondChestplate), 1)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldExportItemFuzzy(final GameTestHelper helper) {
preparePlot(helper, (iface, pos, sequence) -> {
// Arrange
final ItemStack damagedDiamondChestplate = getItemAsDamaged(DIAMOND_CHESTPLATE.getDefaultInstance(), 500);

sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 10);
insert(helper, network, STONE, 15);
insert(helper, network, asResource(damagedDiamondChestplate), 1);
insert(helper, network, DIAMOND_CHESTPLATE, 1);
}));

// Act
iface.setFuzzyMode(true);
iface.setFilters(List.of(
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1)
));

// Assert
sequence
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(damagedDiamondChestplate), 1),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(STONE), 15)
))
.thenExecute(() -> {
iface.clearFilters();
iface.setFilters(List.of(
new ResourceAmount(asResource(DIRT), 10))
);
})
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 10)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(STONE), 15),
new ResourceAmount(asResource(damagedDiamondChestplate), 1),
new ResourceAmount(asResource(DIAMOND_CHESTPLATE), 1)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldExportFluid(final GameTestHelper helper) {
preparePlot(helper, (iface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 10);
insert(helper, network, STONE, 15);
}));

// Act
iface.setFilters(List.of(new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 10)));

// Assert
sequence
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 10)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(STONE), 15)
))
.thenExecute(() -> iface.setFilters(List.of(
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5))
))
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5),
new ResourceAmount(asResource(STONE), 15)
))
.thenExecute(() -> iface.setFilters(List.of(
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 7))
))
.thenWaitUntil(interfaceContainsExactly(
helper,
pos,
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 7)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 3),
new ResourceAmount(asResource(STONE), 15)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldImportItem(final GameTestHelper helper) {
preparePlot(helper, (iface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 5);
insert(helper, network, STONE, 15);
}));

// Assert
sequence
.thenWaitUntil(assertInterfaceEmpty(helper, pos))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(STONE), 15)
))
.thenExecute(() -> iface.getExportedResources().insert(asResource(DIRT), 5, Action.EXECUTE))
.thenWaitUntil(assertInterfaceEmpty(helper, pos))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 10),
new ResourceAmount(asResource(STONE), 15)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldImportFluid(final GameTestHelper helper) {
preparePlot(helper, (iface, pos, sequence) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, WATER, Platform.INSTANCE.getBucketAmount() * 5);
insert(helper, network, STONE, 15);
}));

// Assert
sequence
.thenWaitUntil(assertInterfaceEmpty(helper, pos))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5),
new ResourceAmount(asResource(STONE), 15)
))
.thenExecute(() -> iface.getExportedResources().insert(
asResource(WATER), Platform.INSTANCE.getBucketAmount() * 5, Action.EXECUTE
))
.thenWaitUntil(assertInterfaceEmpty(helper, pos))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 10),
new ResourceAmount(asResource(STONE), 15)
))
.thenSucceed();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.refinedmods.refinedstorage.common.iface;

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 InterfaceTestPlots {
private InterfaceTestPlots() {
}

static void preparePlot(final GameTestHelper helper,
final TriConsumer<InterfaceBlockEntity, BlockPos, GameTestSequence> consumer) {
helper.setBlock(ZERO.above(), RSBLOCKS.getCreativeController().getDefault());
helper.setBlock(ZERO.above().above(), RSBLOCKS.getItemStorageBlock(ItemStorageVariant.ONE_K));
helper.setBlock(
ZERO.above().above().north(),
RSBLOCKS.getFluidStorageBlock(FluidStorageVariant.SIXTY_FOUR_B)
);
final BlockPos interfacePos = ZERO.above().above().above();
helper.setBlock(interfacePos, RSBLOCKS.getInterface());
consumer.accept(
requireBlockEntity(helper, interfacePos, InterfaceBlockEntity.class),
interfacePos,
helper.startSequence()
);
}
}
Loading