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

Regulator upgrade gametest #690

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 @@ -6,6 +6,7 @@
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.apiguardian.api.API;

/**
Expand All @@ -21,7 +22,7 @@ default List<Item> getUpgradeItems() {
return Collections.emptyList();
}

default boolean addUpgradeItem(Item upgradeItem) {
default boolean addUpgradeItem(ItemStack upgradeStack) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ public List<Item> getUpgradeItems() {
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return upgradeContainer.addUpgradeItem(upgradeStack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ private void tryTransferUpgrades(final Player player,
final ConfigurationCardTarget target,
final List<Item> upgradeItems) {
for (final Item upgradeItem : upgradeItems) {
final int upgradeIndexInPlayerInventory = player.getInventory().findSlotMatchingItem(
new ItemStack(upgradeItem)
);
if (upgradeIndexInPlayerInventory >= 0 && target.addUpgradeItem(upgradeItem)) {
final ItemStack upgradeStack = new ItemStack(upgradeItem);
final int upgradeIndexInPlayerInventory = player.getInventory().findSlotMatchingItem(upgradeStack);
if (upgradeIndexInPlayerInventory >= 0 && target.addUpgradeItem(upgradeStack)) {
player.getInventory().removeItem(upgradeIndexInPlayerInventory, 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public List<Item> getUpgradeItems() {
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return upgradeContainer.addUpgradeItem(upgradeStack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public List<Item> getUpgradeItems() {
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return upgradeContainer.addUpgradeItem(upgradeStack);
}

public boolean isPickupItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public List<Item> getUpgradeItems() {
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return upgradeContainer.addUpgradeItem(upgradeStack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public List<Item> getUpgradeItems() {
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return upgradeContainer.addUpgradeItem(upgradeStack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public List<Item> getUpgradeItems() {
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return upgradeContainer.addUpgradeItem(upgradeStack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public List<Item> getUpgradeItems() {
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return upgradeContainer.addUpgradeItem(upgradeStack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ private void setAmount(final ItemStack stack, final double amount) {
stack.set(DataComponents.INSTANCE.getRegulatorUpgradeState(), state.withAmount(amount));
}

public void setAmount(final ItemStack regulatorStack, final PlatformResourceKey resource, final double amount) {
final RegulatorUpgradeState state = regulatorStack.getOrDefault(
DataComponents.INSTANCE.getRegulatorUpgradeState(),
new RegulatorUpgradeState(amount, Optional.of(resource))
);
regulatorStack.set(DataComponents.INSTANCE.getRegulatorUpgradeState(), state);
}

@Override
public long getEnergyUsage() {
return Platform.INSTANCE.getConfig().getUpgrade().getRegulatorUpgradeEnergyUsage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public List<Item> getUpgradeItems() {
return upgradeItems;
}

public boolean addUpgradeItem(final Item upgradeItem) {
return addItem(new ItemStack(upgradeItem)).isEmpty();
public boolean addUpgradeItem(final ItemStack upgradeStack) {
return addItem(upgradeStack).isEmpty();
}

public NonNullList<ItemStack> getDrops() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void shouldDropItemWithStackUpgrade(final GameTestHelper helper) {
// Act
constructor.setDropItems(true);
constructor.setFilters(List.of(asResource(DIRT)));
constructor.addUpgradeItem(RSITEMS.getStackUpgrade());
constructor.addUpgradeItem(RSITEMS.getStackUpgrade().getDefaultInstance());

// Assert
sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static void shouldBreakBlockWithSilkTouchUpgrade(final GameTestHelper hel

// Act
helper.setBlock(pos.east(), Blocks.DIAMOND_ORE);
destructor.addUpgradeItem(RSITEMS.getSilkTouchUpgrade());
destructor.addUpgradeItem(RSITEMS.getSilkTouchUpgrade().getDefaultInstance());

// Assert
sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import java.util.List;
Expand Down Expand Up @@ -79,7 +80,7 @@ public static void shouldExportItemWithStackUpgrade(final GameTestHelper helper)

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

// Assert
sequence
Expand Down Expand Up @@ -112,6 +113,42 @@ 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
exporter.setFilters(List.of(asResource(DIRT.getDefaultInstance())));

final ItemStack upgrade = RSITEMS.getRegulatorUpgrade().getDefaultInstance();
if (upgrade.getItem() instanceof RegulatorUpgradeItem upgradeItem) {
upgradeItem.setAmount(upgrade, asResource(DIRT.getDefaultInstance()), 10);
}
exporter.addUpgradeItem(upgrade);

// Assert
sequence
.thenIdle(95)
.thenExecute(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 Expand Up @@ -187,7 +224,7 @@ public static void shouldExportFluidWithStackUpgrade(final GameTestHelper helper

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

// Assert
sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.upgrade.RegulatorUpgradeItem;
import com.refinedmods.refinedstorage.common.util.IdentifierUtil;

import java.util.Set;
Expand Down Expand Up @@ -89,11 +90,11 @@ public static void shouldImportItemWithStackUpgrade(final GameTestHelper helper)
DIRT.getDefaultInstance()
);

importer.addUpgradeItem(RSITEMS.getStackUpgrade());
importer.addUpgradeItem(RSITEMS.getStackUpgrade().getDefaultInstance());

// Assert
sequence
.thenExecute(() -> containerContainsExactly(
.thenExecute(containerContainsExactly(
helper,
pos.east(),
new ResourceAmount(asResource(DIRT), 1)
Expand All @@ -118,6 +119,48 @@ 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 ItemStack upgrade = RSITEMS.getRegulatorUpgrade().getDefaultInstance();
if (upgrade.getItem() instanceof RegulatorUpgradeItem upgradeItem) {
upgradeItem.setAmount(upgrade, asResource(DIRT.getDefaultInstance()), 10);
}
importer.addUpgradeItem(upgrade);

// Assert
sequence
.thenIdle(95)
.thenExecute(containerContainsExactly(
helper,
pos.east(),
new ResourceAmount(asResource(DIRT), 10)
))
.thenExecute(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 Expand Up @@ -328,7 +371,7 @@ public static void shouldImportFluidWithStackUpgrade(final GameTestHelper helper
new ResourceAmount(asResource(WATER), Platform.INSTANCE.getBucketAmount() * 15),
new ResourceAmount(asResource(LAVA), Platform.INSTANCE.getBucketAmount())
);
importer.addUpgradeItem(RSITEMS.getStackUpgrade());
importer.addUpgradeItem(RSITEMS.getStackUpgrade().getDefaultInstance());

// Assert
sequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static void shouldInsertItemsIntoNetworkWithStackUpgrade(final GameTestHe

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

// Assert
sequence
Expand Down Expand Up @@ -217,7 +217,7 @@ public static void shouldExtractItemsFromNetworkWithStackUpgrade(final GameTestH

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

// Assert
sequence
Expand Down
Loading