Skip to content

Commit

Permalink
Re-add power consumption for inserted/extracted EMC items
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jun 7, 2024
1 parent c268a0d commit c3d2a73
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/main/java/gripe/_90/appliede/me/service/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public long insertItem(
var itemEmc = BigInteger.valueOf(IEMCProxy.INSTANCE.getSellValue(what.toStack()));
var totalEmc = itemEmc.multiply(BigInteger.valueOf(amount));

amount = getAmountAfterPowerExpenditure(totalEmc, itemEmc);

if (amount == 0) {
return 0;
}

var providers = new ArrayList<>(service.getProviders());
Collections.shuffle(providers);
distributeEmc(totalEmc, providers);
Expand Down Expand Up @@ -221,13 +227,20 @@ public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSou
var itemEmc = BigInteger.valueOf(IEMCProxy.INSTANCE.getValue(what.toStack()));
var totalEmc = itemEmc.multiply(BigInteger.valueOf(amount));

var providers = getProvidersForExtraction(source);
var availableEmc = totalEmc.min(
providers.equals(service.getProviders())
? service.getEmc()
: providers.get(0).getEmc());

amount = availableEmc.divide(itemEmc).longValue();

if (amount == 0) {
return 0;
}

if (mode == Actionable.MODULATE) {
var providers = getProvidersForExtraction(source);
var availableEmc = totalEmc.min(
providers.equals(service.getProviders())
? service.getEmc()
: providers.get(0).getEmc());
amount = availableEmc.divide(itemEmc).longValue();
amount = getAmountAfterPowerExpenditure(availableEmc, itemEmc);

if (amount == 0) {
return 0;
Expand Down Expand Up @@ -292,7 +305,6 @@ private List<IKnowledgeProvider> getProvidersForExtraction(IActionSource source)
return providers;
}

// FIXME
private long getAmountAfterPowerExpenditure(BigInteger maxEmc, BigInteger itemEmc) {
var energyService = service.getGrid().getEnergyService();
var multiplier = BigDecimal.valueOf(PowerMultiplier.CONFIG.multiplier);
Expand Down

0 comments on commit c3d2a73

Please sign in to comment.