Skip to content

Commit

Permalink
feat: regulator upgrade gametest
Browse files Browse the repository at this point in the history
  • Loading branch information
starforcraft committed Sep 14, 2024
1 parent 91a274f commit c7f0339
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Optional<TooltipComponent> getTooltipImage(final ItemStack stack) {
return Optional.of(new RegulatorTooltipComponent(getDestinations(), HELP, getConfiguredResource(stack)));
}

private void setAmount(final ItemStack stack, final double amount) {
public void setAmount(final ItemStack stack, final double amount) {
final RegulatorUpgradeState state = stack.getOrDefault(
DataComponents.INSTANCE.getRegulatorUpgradeState(),
RegulatorUpgradeState.EMPTY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.Platform;
import com.refinedmods.refinedstorage.common.api.upgrade.AbstractUpgradeItem;
import com.refinedmods.refinedstorage.common.upgrade.RegulatorUpgradeItem;
import com.refinedmods.refinedstorage.common.util.IdentifierUtil;

import java.util.List;
Expand Down Expand Up @@ -112,6 +114,41 @@ 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) -> {
// Arrange
sequence.thenWaitUntil(networkIsAvailable(helper, pos, network -> {
insert(helper, network, DIRT, 15);
insert(helper, network, STONE, 15);
}));

// Act
final AbstractUpgradeItem upgrade = RSITEMS.getRegulatorUpgrade();
if (upgrade instanceof RegulatorUpgradeItem regulatorUpgrade) {
regulatorUpgrade.setAmount(DIRT.getDefaultInstance(), 10);
}

exporter.setFilters(List.of(asResource(DIRT)));
exporter.addUpgradeItem(upgrade);

// Assert
sequence
.thenWaitUntil(containerContainsExactly(
helper,
pos.east(),
new ResourceAmount(asResource(DIRT), 10)
))
.thenExecute(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 5),
new ResourceAmount(asResource(STONE), 15)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldExportItemFuzzy(final GameTestHelper helper) {
ExporterTestPlots.preparePlot(helper, Blocks.CHEST, Direction.EAST, (exporter, pos, sequence) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.filter.FilterMode;
import com.refinedmods.refinedstorage.common.Platform;
import com.refinedmods.refinedstorage.common.api.upgrade.AbstractUpgradeItem;
import com.refinedmods.refinedstorage.common.upgrade.RegulatorUpgradeItem;
import com.refinedmods.refinedstorage.common.util.IdentifierUtil;

import java.util.Set;
Expand Down Expand Up @@ -93,7 +95,7 @@ public static void shouldImportItemWithStackUpgrade(final GameTestHelper helper)

// Assert
sequence
.thenExecute(() -> containerContainsExactly(
.thenExecute(containerContainsExactly(
helper,
pos.east(),
new ResourceAmount(asResource(DIRT), 1)
Expand All @@ -118,6 +120,47 @@ public static void shouldImportItemWithStackUpgrade(final GameTestHelper helper)
});
}

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

// Act
prepareChest(
helper,
pos.east(),
COBBLESTONE.getDefaultInstance(),
DIRT.getDefaultInstance().copyWithCount(15)
);

final AbstractUpgradeItem upgrade = RSITEMS.getRegulatorUpgrade();
if (upgrade instanceof RegulatorUpgradeItem regulatorUpgrade) {
regulatorUpgrade.setAmount(DIRT.getDefaultInstance(), 10);
}
importer.addUpgradeItem(upgrade);

// Assert
sequence
.thenWaitUntil(containerContainsExactly(
helper,
pos.east(),
new ResourceAmount(asResource(DIRT), 10)
))
.thenWaitUntil(storageContainsExactly(
helper,
pos,
new ResourceAmount(asResource(DIRT), 15),
new ResourceAmount(asResource(STONE), 15),
new ResourceAmount(asResource(COBBLESTONE), 1)
))
.thenSucceed();
});
}

@GameTest(template = "empty_15x15")
public static void shouldImportItemBlocklist(final GameTestHelper helper) {
preparePlot(helper, Direction.EAST, (importer, pos, sequence) -> {
Expand Down

0 comments on commit c7f0339

Please sign in to comment.