Skip to content

Commit

Permalink
Use single instance of base-tier EMC key
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Apr 30, 2024
1 parent b70a7ca commit 49c7abc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private boolean tryUsePlan(int slot, AEKey what, int amount) {
}

energy.extractAEPower(energyToExpend, Actionable.MODULATE, PowerMultiplier.CONFIG);
knowledge.getStorage().insert(EMCKey.base(), toDeposit, Actionable.MODULATE, requestSource);
knowledge.getStorage().insert(EMCKey.BASE, toDeposit, Actionable.MODULATE, requestSource);

var deposited = BigInteger.valueOf(toDeposit);
insertedItems += (int) deposited.divide(itemEmc).longValue();
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/gripe/_90/appliede/key/EMCKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
import gripe._90.appliede.AppliedE;

public final class EMCKey extends AEKey {
public static final EMCKey BASE = new EMCKey(1);

private final int tier;

private EMCKey(int tier) {
if (tier <= 0) {
throw new IllegalArgumentException("Tier must be positive");
throw new IllegalArgumentException("Tier must be non-negative");
}

this.tier = tier;
}

public static EMCKey tier(int tier) {
return new EMCKey(tier);
}

public static EMCKey base() {
return tier(1);
return tier == 1 ? BASE : new EMCKey(tier);
}

public int getTier() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gripe/_90/appliede/key/EMCKeyType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import gripe._90.appliede.AppliedE;

public final class EMCKeyType extends AEKeyType {
static final Component EMC = Component.translatable("key." + AppliedE.MODID + ".emc");
public static final EMCKeyType TYPE = new EMCKeyType();
private static final Component EMC = Component.translatable("key." + AppliedE.MODID + ".emc");

private EMCKeyType() {
super(AppliedE.id("emc"), EMCKey.class, EMC);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gripe/_90/appliede/service/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSou

while (totalEmc.compareTo(BigInteger.ZERO) > 0) {
var toWithdraw = AppliedE.clampedLong(totalEmc);
var canWithdraw = extract(EMCKey.base(), toWithdraw, Actionable.SIMULATE, source);
var canWithdraw = extract(EMCKey.BASE, toWithdraw, Actionable.SIMULATE, source);

if (canWithdraw < toWithdraw) {
break;
Expand All @@ -159,7 +159,7 @@ public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSou
}

energy.extractAEPower(energyToExpend, Actionable.MODULATE, PowerMultiplier.CONFIG);
extract(EMCKey.base(), toWithdraw, Actionable.MODULATE, source);
extract(EMCKey.BASE, toWithdraw, Actionable.MODULATE, source);
}

var withdrawn = BigInteger.valueOf(toWithdraw);
Expand Down

0 comments on commit 49c7abc

Please sign in to comment.