diff --git a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/configurationcard/ConfigurationCardTarget.java b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/configurationcard/ConfigurationCardTarget.java index efdacae3c..5d246efaf 100644 --- a/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/configurationcard/ConfigurationCardTarget.java +++ b/refinedstorage-common-api/src/main/java/com/refinedmods/refinedstorage/common/api/configurationcard/ConfigurationCardTarget.java @@ -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; /** @@ -21,7 +22,7 @@ default List getUpgradeItems() { return Collections.emptyList(); } - default boolean addUpgradeItem(Item upgradeItem) { + default boolean addUpgradeItem(ItemStack upgradeStack) { return false; } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java index 2bc3d18c5..df3cadde9 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/AutocrafterBlockEntity.java @@ -235,8 +235,8 @@ public List getUpgradeItems() { } @Override - public boolean addUpgradeItem(final Item upgradeItem) { - return upgradeContainer.addUpgradeItem(upgradeItem); + public boolean addUpgradeItem(final ItemStack upgradeStack) { + return upgradeContainer.addUpgradeItem(upgradeStack); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/configurationcard/ConfigurationCardItem.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/configurationcard/ConfigurationCardItem.java index d34df1ed5..7b78ff02f 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/configurationcard/ConfigurationCardItem.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/configurationcard/ConfigurationCardItem.java @@ -84,10 +84,9 @@ private void tryTransferUpgrades(final Player player, final ConfigurationCardTarget target, final List 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); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java index 4a8272858..75c15737e 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractConstructorBlockEntity.java @@ -89,8 +89,8 @@ public List getUpgradeItems() { } @Override - public boolean addUpgradeItem(final Item upgradeItem) { - return upgradeContainer.addUpgradeItem(upgradeItem); + public boolean addUpgradeItem(final ItemStack upgradeStack) { + return upgradeContainer.addUpgradeItem(upgradeStack); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractDestructorBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractDestructorBlockEntity.java index 6a8cb2814..d94e3709b 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractDestructorBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/constructordestructor/AbstractDestructorBlockEntity.java @@ -80,8 +80,8 @@ public List 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() { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java index 437f5f4b9..628263c20 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/exporter/AbstractExporterBlockEntity.java @@ -92,8 +92,8 @@ public List getUpgradeItems() { } @Override - public boolean addUpgradeItem(final Item upgradeItem) { - return upgradeContainer.addUpgradeItem(upgradeItem); + public boolean addUpgradeItem(final ItemStack upgradeStack) { + return upgradeContainer.addUpgradeItem(upgradeStack); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java index 66962b3d7..a19995600 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/importer/AbstractImporterBlockEntity.java @@ -86,8 +86,8 @@ public List getUpgradeItems() { } @Override - public boolean addUpgradeItem(final Item upgradeItem) { - return upgradeContainer.addUpgradeItem(upgradeItem); + public boolean addUpgradeItem(final ItemStack upgradeStack) { + return upgradeContainer.addUpgradeItem(upgradeStack); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java index 8384ebe92..199d7649f 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/WirelessTransmitterBlockEntity.java @@ -79,8 +79,8 @@ public List getUpgradeItems() { } @Override - public boolean addUpgradeItem(final Item upgradeItem) { - return upgradeContainer.addUpgradeItem(upgradeItem); + public boolean addUpgradeItem(final ItemStack upgradeStack) { + return upgradeContainer.addUpgradeItem(upgradeStack); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java index 3329c13b1..792f0751a 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/AbstractDiskInterfaceBlockEntity.java @@ -114,8 +114,8 @@ public List getUpgradeItems() { } @Override - public boolean addUpgradeItem(final Item upgradeItem) { - return upgradeContainer.addUpgradeItem(upgradeItem); + public boolean addUpgradeItem(final ItemStack upgradeStack) { + return upgradeContainer.addUpgradeItem(upgradeStack); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/RegulatorUpgradeItem.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/RegulatorUpgradeItem.java index 029860f71..1e7aa6657 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/RegulatorUpgradeItem.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/RegulatorUpgradeItem.java @@ -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(); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/UpgradeContainer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/UpgradeContainer.java index 24c8c6d68..671a654aa 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/UpgradeContainer.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/upgrade/UpgradeContainer.java @@ -157,8 +157,8 @@ public List 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 getDrops() { 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 50ce50207..b51cb42c3 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 @@ -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 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 4db21526c..a1eb71777 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 @@ -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 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 db7a2808c..b8d3d7e7c 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 @@ -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; @@ -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 @@ -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) -> { @@ -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 diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java index f620e86e2..a6eefe1a1 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/importer/ImporterTest.java @@ -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; @@ -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) @@ -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) -> { @@ -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 diff --git a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/diskinterface/DiskInterfaceTest.java b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/diskinterface/DiskInterfaceTest.java index 4618f6bd4..1b89c4589 100644 --- a/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/diskinterface/DiskInterfaceTest.java +++ b/refinedstorage-neoforge/src/test/java/com/refinedmods/refinedstorage/common/storage/diskinterface/DiskInterfaceTest.java @@ -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 @@ -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