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 6554ad2
Showing 1 changed file with 16 additions and 11 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.upgrades.IUpgradeableItem;

import gripe._90.appliede.AppliedE;

Expand All @@ -25,7 +25,7 @@ public String getName() {

@Override
public String getDescription() {
return "Calculates EMC value of Applied Energistics 2 storage cells.";
return "Calculates EMC value of Applied Energistics 2 storage cells (and terminals).";
}

@Override
Expand All @@ -35,25 +35,30 @@ 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 IUpgradeableItem upgradeable)) {
return currentEmc;
}

var stack = itemInfo.createStack();
var bigEmc = BigInteger.valueOf(currentEmc);

for (var upgrade : upgradeable.getUpgrades(stack)) {
bigEmc = bigEmc.add(BigInteger.valueOf(IEMCProxy.INSTANCE.getValue(upgrade)));
}

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

if (cell == null) {
return AppliedE.clampedLong(bigEmc);
}

for (var key : cell.getAvailableStacks()) {
if (key.getKey() instanceof AEItemKey item) {
var keyEmc = IEMCProxy.INSTANCE.getValue(item.getItem());
bigEmc = bigEmc.add(BigInteger.valueOf(keyEmc).multiply(BigInteger.valueOf(key.getLongValue())));
}
}

// 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)));
}
}

return AppliedE.clampedLong(bigEmc);
}
}

0 comments on commit 6554ad2

Please sign in to comment.