Skip to content

Commit

Permalink
Do not consume extra power when reinserting leftover EMC-exported items
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jun 25, 2024
1 parent a918fe3 commit b179f9d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void handle(Supplier<NetworkEvent.Context> context) {
Actionable.MODULATE,
IActionSource.ofPlayer(sender),
true,
true,
menu::showLearned);

var me = storage.getInventory();
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/gripe/_90/appliede/me/service/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ public long extract(AEKey what, long amount, Actionable mode, IActionSource sour
}

public long insertItem(
AEItemKey what, long amount, Actionable mode, IActionSource source, boolean mayLearn, Runnable onLearn) {
AEItemKey what,
long amount,
Actionable mode,
IActionSource source,
boolean mayLearn,
boolean consumePower,
Runnable onLearn) {
if (amount <= 0 || service.getProviders().isEmpty()) {
return 0;
}
Expand Down Expand Up @@ -175,7 +181,9 @@ public long insertItem(
var itemEmc = BigInteger.valueOf(IEMCProxy.INSTANCE.getSellValue(what.toStack()));
var totalEmc = itemEmc.multiply(BigInteger.valueOf(amount));

amount = getAmountAfterPowerExpenditure(totalEmc, itemEmc);
if (consumePower) {
amount = getAmountAfterPowerExpenditure(totalEmc, itemEmc);
}

if (amount == 0) {
return 0;
Expand Down Expand Up @@ -205,7 +213,7 @@ public long insertItem(
}

public long insertItem(AEItemKey what, long amount, Actionable mode, IActionSource source, boolean mayLearn) {
return insertItem(what, amount, mode, source, mayLearn, () -> {});
return insertItem(what, amount, mode, source, mayLearn, true, () -> {});
}

public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSource source, boolean skipStored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private int transmuteItem(ItemStack stack, boolean singleItem, Player player) {
Actionable.MODULATE,
IActionSource.ofPlayer(player),
true,
true,
this::showLearned);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gripe/_90/appliede/part/EMCExportBusPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ protected boolean doBusWork(IGrid grid) {

if (wasInserted < extracted) {
var leftover = extracted - wasInserted;
leftover -= networkEmc.insertItem(item, leftover, Actionable.MODULATE, source, false);
leftover -= networkEmc.insertItem(
item, leftover, Actionable.MODULATE, source, false, false, () -> {});

if (leftover > 0) {
LOGGER.error(
Expand Down

0 comments on commit b179f9d

Please sign in to comment.