Skip to content

Commit

Permalink
Make the P2P power ratios configurable for energy / transport (#8281)
Browse files Browse the repository at this point in the history
Fixes #8280

(cherry picked from commit 5b884a3)
  • Loading branch information
shartte committed Dec 13, 2024
1 parent 2af0c64 commit 8ad3db1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion guidebook/items-blocks-machines/p2p_tunnels.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ P2P tunnels with certain items:
- Light P2P tunnels are selected by right-clicking with a torch or glowstone

Some tunnel types have quirks. For instance, ME P2P tunnels' channels cannot pass through other ME P2P tunnels, and
Energy P2P tunnels indirectly extract a 5% tax on FE or E flowing through themselves by increasing their
Energy P2P tunnels indirectly extract a 2.5% tax on FE flowing through themselves by increasing their
[energy](../ae2-mechanics/energy.md) draw.

## The Most-Used Form of P2P
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/appeng/core/AEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ private static void makeBackupAndReset(Path configFolder, String configFile) {
private double wirelessHighWirelessCount;

// Tunnels
public static final double TUNNEL_POWER_LOSS = 0.05;
public double getP2PTunnelEnergyTax() {
return COMMON.p2pTunnelEnergyTax.get();
}

public double getP2PTunnelTransportTax() {
return COMMON.p2pTunnelTransportTax.get();
}

private void syncClientConfig() {
this.disableColoredCableRecipesInJEI = CLIENT.disableColoredCableRecipesInJEI.get();
Expand Down Expand Up @@ -682,6 +688,8 @@ private static class CommonConfig {
public final DoubleOption powerUsageMultiplier;
public final DoubleOption gridEnergyStoragePerNode;
public final DoubleOption crystalResonanceGeneratorRate;
public final DoubleOption p2pTunnelEnergyTax;
public final DoubleOption p2pTunnelTransportTax;

// Vibration Chamber
public final DoubleOption vibrationChamberBaseEnergyPerFuelTick;
Expand Down Expand Up @@ -778,6 +786,10 @@ public CommonConfig(ConfigSection root) {
"How much energy can the internal grid buffer storage per node attached to the grid.");
crystalResonanceGeneratorRate = PowerRatios.addDouble("CrystalResonanceGeneratorRate", 20, 0, 1000000,
"How much energy a crystal resonance generator generates per tick.");
p2pTunnelEnergyTax = PowerRatios.addDouble("p2pTunnelEnergyTax", 0.025, 0.0, 1.0,
"The cost to transport energy through an energy P2P tunnel expressed as a factor of the transported energy.");
p2pTunnelTransportTax = PowerRatios.addDouble("p2pTunnelTransportTax", 0.025, 0.0, 1.0,
"The cost to transport items/fluids/etc. through P2P tunnels, expressed in AE energy per equivalent I/O bus operation for the transported object type (i.e. items=per 1 item, fluids=per 125mb).");

ConfigSection Condenser = root.subsection("Condenser");
condenserMatterBallsPower = Condenser.addInt("MatterBalls", 256);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/parts/p2p/FEP2PTunnelPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public int receiveEnergy(int maxReceive, boolean simulate) {
}

if (!simulate) {
FEP2PTunnelPart.this.queueTunnelDrain(PowerUnits.FE, total);
deductEnergyCost(total, PowerUnits.FE);
}

return total;
Expand Down Expand Up @@ -131,7 +131,7 @@ public int extractEnergy(int maxExtract, boolean simulate) {
final int total = input.get().extractEnergy(maxExtract, simulate);

if (!simulate) {
FEP2PTunnelPart.this.queueTunnelDrain(PowerUnits.FE, total);
deductEnergyCost(total, PowerUnits.FE);
}

return total;
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;

import appeng.api.config.PowerUnits;
import appeng.api.parts.IPartItem;
import appeng.api.parts.IPartModel;
import appeng.api.stacks.AEKeyType;
Expand Down Expand Up @@ -105,8 +104,7 @@ public int fill(FluidStack resource, FluidAction action) {
}

if (action == FluidAction.EXECUTE) {
FluidP2PTunnelPart.this.queueTunnelDrain(PowerUnits.FE,
(double) total / AEKeyType.fluids().getAmountPerOperation());
deductTransportCost(total, AEKeyType.fluids());
}

return total;
Expand Down Expand Up @@ -164,8 +162,7 @@ public FluidStack drain(FluidStack resource, FluidAction action) {
FluidStack result = input.get().drain(resource, action);

if (action.execute()) {
queueTunnelDrain(PowerUnits.FE,
(double) result.getAmount() / AEKeyType.fluids().getAmountPerOperation());
deductTransportCost(result.getAmount(), AEKeyType.fluids());
}

return result;
Expand All @@ -178,8 +175,7 @@ public FluidStack drain(int maxDrain, FluidAction action) {
FluidStack result = input.get().drain(maxDrain, action);

if (action.execute()) {
queueTunnelDrain(PowerUnits.FE,
(double) result.getAmount() / AEKeyType.fluids().getAmountPerOperation());
deductTransportCost(result.getAmount(), AEKeyType.fluids());
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;

import appeng.api.config.PowerUnits;
import appeng.api.parts.IPartItem;
import appeng.api.parts.IPartModel;
import appeng.api.stacks.AEKeyType;
import appeng.core.AppEng;
import appeng.items.parts.PartModels;

Expand Down Expand Up @@ -103,7 +103,7 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
}

if (!simulate) {
ItemP2PTunnelPart.this.queueTunnelDrain(PowerUnits.FE, amount - remainder);
deductTransportCost(amount - remainder, AEKeyType.items());
}

if (remainder == stack.getCount()) {
Expand Down Expand Up @@ -160,7 +160,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
ItemStack result = input.get().extractItem(slot, amount, simulate);

if (!simulate) {
queueTunnelDrain(PowerUnits.FE, result.getCount());
deductTransportCost(result.getCount(), AEKeyType.items());
}

return result;
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/appeng/parts/p2p/P2PTunnelPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartItem;
import appeng.api.stacks.AEKeyType;
import appeng.api.util.AECableType;
import appeng.client.render.cablebus.P2PTunnelFrequencyModelData;
import appeng.core.AEConfig;
Expand Down Expand Up @@ -294,14 +295,42 @@ public void onTunnelConfigChange() {
}

public void onTunnelNetworkChange() {
}

protected void deductEnergyCost(double energyTransported, PowerUnits typeTransported) {
var costFactor = AEConfig.instance().getP2PTunnelEnergyTax();
if (costFactor <= 0) {
return;
}

getMainNode().ifPresent(grid -> {
var tax = typeTransported.convertTo(PowerUnits.AE, energyTransported * costFactor);
grid.getEnergyService().extractAEPower(tax, Actionable.MODULATE, PowerMultiplier.CONFIG);
});
}

protected void deductTransportCost(long amountTransported, AEKeyType typeTransported) {
var costFactor = AEConfig.instance().getP2PTunnelTransportTax();
if (costFactor <= 0) {
return;
}

getMainNode().ifPresent(grid -> {
double operations = amountTransported / (double) typeTransported.getAmountPerOperation();
double tax = operations * costFactor;
grid.getEnergyService().extractAEPower(tax, Actionable.MODULATE, PowerMultiplier.CONFIG);
});
}

/**
* Use {@link #deductEnergyCost} or {@link #deductTransportCost}.
*/
@Deprecated(forRemoval = true, since = "1.21.1")
protected void queueTunnelDrain(PowerUnits unit, double f) {
final double ae_to_tax = unit.convertTo(PowerUnits.AE, f * AEConfig.TUNNEL_POWER_LOSS);
final double ae_to_tax = unit.convertTo(PowerUnits.AE, f * 0.05);

getMainNode().ifPresent(grid -> {
grid.getEnergyService().extractAEPower(ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE);
grid.getEnergyService().extractAEPower(ae_to_tax, Actionable.MODULATE, PowerMultiplier.CONFIG);
});
}

Expand Down

0 comments on commit 8ad3db1

Please sign in to comment.