Skip to content

Commit

Permalink
Reorganise EMC mapper classes, add network tool NBT processor
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Apr 30, 2024
1 parent dda6ae9 commit b8936a7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gripe._90.appliede.mappers;
package gripe._90.appliede.emc.mappers;

import net.minecraft.world.item.crafting.RecipeType;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gripe._90.appliede.mappers;
package gripe._90.appliede.emc.mappers;

import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gripe._90.appliede.mappers;
package gripe._90.appliede.emc.mappers;

import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package gripe._90.appliede.emc.nbt;

import java.math.BigInteger;

import org.jetbrains.annotations.NotNull;

import appeng.items.contents.NetworkToolMenuHost;
import appeng.items.tools.NetworkToolItem;

import gripe._90.appliede.AppliedE;

import moze_intel.projecte.api.ItemInfo;
import moze_intel.projecte.api.nbt.INBTProcessor;
import moze_intel.projecte.api.nbt.NBTProcessor;
import moze_intel.projecte.api.proxy.IEMCProxy;

@SuppressWarnings("unused")
@NBTProcessor
public class NetworkToolNBTProcessor implements INBTProcessor {
@Override
public String getName() {
return "AE2NetworkToolProcessor";
}

@Override
public String getDescription() {
return "Calculates EMC value of the Applied Energistics 2 network tool.";
}

@Override
public long recalculateEMC(@NotNull ItemInfo itemInfo, long currentEmc) throws ArithmeticException {
if (!(itemInfo.getItem() instanceof NetworkToolItem)) {
return currentEmc;
}

var stack = itemInfo.createStack();
var bigEmc = BigInteger.valueOf(currentEmc);
var inventory = new NetworkToolMenuHost(null, -1, stack, null).getInventory();

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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gripe._90.appliede.mappers;
package gripe._90.appliede.emc.nbt;

import java.math.BigInteger;

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

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

@Override
public boolean isAvailable() {
return AppliedE.useCustomMapper();
return "Calculates EMC value of Applied Energistics 2 storage cells (and anything else that's upgradeable)";
}

@Override
Expand Down

0 comments on commit b8936a7

Please sign in to comment.