Skip to content

Commit

Permalink
Merge cell/upgraded/inventory item processing into one processor
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed May 2, 2024
1 parent 15197b4 commit e27f279
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import appeng.api.stacks.AEItemKey;
import appeng.api.storage.StorageCells;
import appeng.api.upgrades.IUpgradeableItem;
import appeng.items.contents.NetworkToolMenuHost;
import appeng.items.tools.NetworkToolItem;

import gripe._90.appliede.AppliedE;

Expand All @@ -16,27 +19,49 @@

@SuppressWarnings("unused")
@NBTProcessor
public class StorageCellProcessor implements INBTProcessor {
public class InventoryItemProcessor implements INBTProcessor {
@Override
public String getName() {
return "AE2CellProcessor";
return "AE2InventoryItemProcessor";
}

@Override
public String getDescription() {
return "(AppliedE) Calculates EMC value of Applied Energistics 2 item cells depending on contents.";
return "(AppliedE) Calculates EMC value of Applied Energistics 2 inventory items such as cells and wireless terminals.";
}

@Override
public long recalculateEMC(@NotNull ItemInfo itemInfo, long currentEmc) throws ArithmeticException {
var cell = StorageCells.getCellInventory(itemInfo.createStack(), null);
if (itemInfo.getItem() instanceof NetworkToolItem) {
var stack = itemInfo.createStack();
var bigEmc = BigInteger.valueOf(currentEmc);
var inventory = new NetworkToolMenuHost(null, -1, stack, null).getInventory();

if (cell == null) {
for (var item : inventory) {
var itemEmc = IEMCProxy.INSTANCE.getValue(item);
bigEmc = bigEmc.add(BigInteger.valueOf(itemEmc).multiply(BigInteger.valueOf(item.getCount())));
}

return AppliedE.clampedLong(bigEmc);
}

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(itemInfo.createStack(), 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.toStack());
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/gripe/_90/appliede/emc/NetworkToolProcessor.java

This file was deleted.

44 changes: 0 additions & 44 deletions src/main/java/gripe/_90/appliede/emc/UpgradedItemProcessor.java

This file was deleted.

0 comments on commit e27f279

Please sign in to comment.