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

Do not void items not already stored on a cell using an Overflow Destruction Card #8336

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
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
43 changes: 42 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,47 @@ 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.VOID_CARD.stack());

var cell = StorageCells.getCellInventory(stack, null);
Objects.requireNonNull(cell);

// Ensure that the first insert of a single type voids only excess.
var filler = AEItemKey.of(Items.DIAMOND);
assertThat(cell.insert(filler, Long.MAX_VALUE, Actionable.MODULATE, SRC)).isEqualTo(Long.MAX_VALUE);
assertThat(cell.getAvailableStacks().get(filler)).isNotZero();
// Ensure that new item types that the cell cannot store don't get voided.
var rejected = AEItemKey.of(Items.STICK);
assertThat(cell.insert(rejected, Long.MAX_VALUE, Actionable.MODULATE, SRC)).isZero();

// Part two, fill cell with 63 different types this time.
cell.extract(filler, Long.MAX_VALUE, Actionable.MODULATE, SRC);
item.getUpgrades(stack).removeItems(1, AEItems.VOID_CARD.stack(), null);
item.getUpgrades(stack).addItems(AEItems.EQUAL_DISTRIBUTION_CARD.stack());
cell = StorageCells.getCellInventory(stack, null);
Objects.requireNonNull(cell);

var maxTypes = item.getTotalTypes(stack);
var keys = generateDifferentKeys(maxTypes);

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(rejected, 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
Loading