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
  • Loading branch information
shartte authored Dec 13, 2024
1 parent 3555f55 commit 5b884a3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 18 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 @@ -74,7 +74,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
18 changes: 15 additions & 3 deletions src/main/java/appeng/core/AEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,19 @@ public static void register(ModContainer container) {
instance = new AEConfig(container);
}

// Tunnels
public static final double TUNNEL_POWER_LOSS = 0.05;

public static AEConfig instance() {
return instance;
}

// Tunnels
public double getP2PTunnelEnergyTax() {
return common.p2pTunnelEnergyTax.get();
}

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

public double wireless_getDrainRate(double range) {
return common.wirelessTerminalDrainMultiplier.get() * range;
}
Expand Down Expand Up @@ -569,6 +575,8 @@ private static class CommonConfig {
public final DoubleValue powerUsageMultiplier;
public final DoubleValue gridEnergyStoragePerNode;
public final DoubleValue crystalResonanceGeneratorRate;
public final DoubleValue p2pTunnelEnergyTax;
public final DoubleValue p2pTunnelTransportTax;

// Vibration Chamber
public final DoubleValue vibrationChamberBaseEnergyPerFuelTick;
Expand Down Expand Up @@ -663,6 +671,10 @@ public CommonConfig() {
"How much energy can the internal grid buffer storage per node attached to the grid.");
crystalResonanceGeneratorRate = define(builder, "crystalResonanceGeneratorRate", 20.0, 0.0, 1000000.0,
"How much energy a crystal resonance generator generates per tick.");
p2pTunnelEnergyTax = define(builder, "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 = define(builder, "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).");
builder.pop();

builder.push("condenser");
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(PowerUnit.FE, total);
deductEnergyCost(total, PowerUnit.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(PowerUnit.FE, total);
deductEnergyCost(total, PowerUnit.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 @@ -24,7 +24,6 @@
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;

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

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

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

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

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

if (action.execute()) {
queueTunnelDrain(PowerUnit.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.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.ItemHandlerHelper;

import appeng.api.config.PowerUnit;
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(PowerUnit.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(PowerUnit.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 @@ -45,6 +45,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 @@ -278,14 +279,42 @@ public void onTunnelConfigChange() {
}

public void onTunnelNetworkChange() {
}

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

getMainNode().ifPresent(grid -> {
var tax = typeTransported.convertTo(PowerUnit.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(PowerUnit unit, double f) {
final double ae_to_tax = unit.convertTo(PowerUnit.AE, f * AEConfig.TUNNEL_POWER_LOSS);
final double ae_to_tax = unit.convertTo(PowerUnit.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 5b884a3

Please sign in to comment.