Skip to content

Commit

Permalink
Do not void items not already stored on a cell using a void card
Browse files Browse the repository at this point in the history
Closes #8292
  • Loading branch information
62832 committed Jan 18, 2025
1 parent 27ae40d commit fcd5e94
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/java/appeng/me/cells/BasicCellInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 27 additions & 1 deletion src/test/java/appeng/me/cells/BasicInventoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <a href="https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/6794">#6794</a>
*/
@Test
void testFluidExtract() {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fcd5e94

Please sign in to comment.