Skip to content

Commit

Permalink
Remember that sometimes what you're asking for already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Apr 30, 2024
1 parent 143e60f commit 1fba8d8
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import appeng.api.stacks.AEItemKey;
import appeng.api.storage.StorageCells;
import appeng.me.cells.BasicCellInventory;
import appeng.api.storage.cells.ICellWorkbenchItem;

import gripe._90.appliede.AppliedE;

Expand Down Expand Up @@ -35,8 +35,16 @@ public boolean isAvailable() {

@Override
public long recalculateEMC(@NotNull ItemInfo itemInfo, long currentEmc) throws ArithmeticException {
var cell = StorageCells.getCellInventory(itemInfo.createStack(), null);
if (cell == null) return currentEmc;
if (!(itemInfo.getItem() instanceof ICellWorkbenchItem cellItem)) {
return currentEmc;
}

var stack = itemInfo.createStack();
var cell = StorageCells.getCellInventory(stack, null);

if (cell == null) {
return currentEmc;
}

var bigEmc = BigInteger.valueOf(currentEmc);

Expand All @@ -47,11 +55,8 @@ public long recalculateEMC(@NotNull ItemInfo itemInfo, long currentEmc) throws A
}
}

// TODO: See about adding upgrade inventories to the StorageCell interface
if (cell instanceof BasicCellInventory basicCell) {
for (var upgrade : basicCell.getUpgradesInventory()) {
bigEmc = bigEmc.add(BigInteger.valueOf(IEMCProxy.INSTANCE.getValue(upgrade)));
}
for (var upgrade : cellItem.getUpgrades(stack)) {
bigEmc = bigEmc.add(BigInteger.valueOf(IEMCProxy.INSTANCE.getValue(upgrade)));
}

return AppliedE.clampedLong(bigEmc);
Expand Down

0 comments on commit 1fba8d8

Please sign in to comment.