From fcd5e94d630bc8d22175f516e7d8629609fbaa51 Mon Sep 17 00:00:00 2001 From: 90 Date: Sat, 18 Jan 2025 16:27:56 +0000 Subject: [PATCH] Do not void items not already stored on a cell using a void card Closes #8292 --- .../appeng/me/cells/BasicCellInventory.java | 9 +++++- .../appeng/me/cells/BasicInventoryTest.java | 28 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/appeng/me/cells/BasicCellInventory.java b/src/main/java/appeng/me/cells/BasicCellInventory.java index ad34b820953..43c3bf11578 100644 --- a/src/main/java/appeng/me/cells/BasicCellInventory.java +++ b/src/main/java/appeng/me/cells/BasicCellInventory.java @@ -348,7 +348,14 @@ public long insert(AEKey what, long amount, Actionable mode, IActionSource sourc // Run regular insert logic and then apply void upgrade to the returned value. long inserted = innerInsert(what, amount, mode); - return this.hasVoidUpgrade ? amount : inserted; + + // In the event that a void card is being used on a (full) unformatted cell, ensure it doesn't void any items + // that the cell isn't even storing and cannot store to begin with + if (!isPreformatted() && hasVoidUpgrade && !canHoldNewItem()) { + return getCellItems().containsKey(what) ? amount : inserted; + } + + return hasVoidUpgrade ? amount : inserted; } // Inner insert for items that pass the filter. diff --git a/src/test/java/appeng/me/cells/BasicInventoryTest.java b/src/test/java/appeng/me/cells/BasicInventoryTest.java index 4937e9ef413..3d7b5b0b1ef 100644 --- a/src/test/java/appeng/me/cells/BasicInventoryTest.java +++ b/src/test/java/appeng/me/cells/BasicInventoryTest.java @@ -29,7 +29,7 @@ public class BasicInventoryTest { /** * Check that we can extract more than MAX_INT fluid at once from a cell. Regression test for - * https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/6794 + * #6794 */ @Test void testFluidExtract() { @@ -135,6 +135,32 @@ void testVoidUpgrade() { assertThat(cell.insert(rejected, Long.MAX_VALUE, Actionable.MODULATE, SRC)).isZero(); } + @Test + void testVoidUpgradeUnformatted() { + var item = AEItems.ITEM_CELL_1K.get(); + var stack = new ItemStack(item); + item.getUpgrades(stack).addItems(AEItems.EQUAL_DISTRIBUTION_CARD.stack()); + + var cell = StorageCells.getCellInventory(stack, null); + Objects.requireNonNull(cell); + + var maxTypes = item.getTotalTypes(stack); + var keys = generateDifferentKeys(128); + + for (int i = 0; i < maxTypes; ++i) { + cell.insert(keys[i], Long.MAX_VALUE, Actionable.MODULATE, SRC); + } + + item.getUpgrades(stack).addItems(AEItems.VOID_CARD.stack()); + cell = StorageCells.getCellInventory(stack, null); + Objects.requireNonNull(cell); + + // Ensure that inserting an already-stored item voids. + assertThat(cell.insert(keys[0], Long.MAX_VALUE, Actionable.MODULATE, SRC)).isEqualTo(Long.MAX_VALUE); + // Ensure that items that aren't on the cell don't get voided. + assertThat(cell.insert(AEItemKey.of(Items.STICK), Long.MAX_VALUE, Actionable.MODULATE, SRC)).isZero(); + } + private static AEItemKey[] generateDifferentKeys(int count) { var out = new AEItemKey[count]; for (int i = 0; i < count; ++i) {