From 5b884a34e067408fea2f0847340ff260a3622152 Mon Sep 17 00:00:00 2001 From: shartte Date: Sat, 14 Dec 2024 00:03:23 +0100 Subject: [PATCH] Make the P2P power ratios configurable for energy / transport (#8281) Fixes #8280 --- .../items-blocks-machines/p2p_tunnels.md | 2 +- src/main/java/appeng/core/AEConfig.java | 18 ++++++++-- .../appeng/parts/p2p/FEP2PTunnelPart.java | 4 +-- .../appeng/parts/p2p/FluidP2PTunnelPart.java | 10 ++---- .../appeng/parts/p2p/ItemP2PTunnelPart.java | 6 ++-- .../java/appeng/parts/p2p/P2PTunnelPart.java | 33 +++++++++++++++++-- 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/guidebook/items-blocks-machines/p2p_tunnels.md b/guidebook/items-blocks-machines/p2p_tunnels.md index 66f76f4f66e..f600d527a19 100644 --- a/guidebook/items-blocks-machines/p2p_tunnels.md +++ b/guidebook/items-blocks-machines/p2p_tunnels.md @@ -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 diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 94b1c34137b..53421b9621b 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -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; } @@ -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; @@ -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"); diff --git a/src/main/java/appeng/parts/p2p/FEP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/FEP2PTunnelPart.java index 0f29b7a45c7..adbe52c40ba 100644 --- a/src/main/java/appeng/parts/p2p/FEP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/FEP2PTunnelPart.java @@ -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; @@ -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; diff --git a/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java index 8c0f09fe75e..8496a25c8bc 100644 --- a/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java index d5ba64c12f9..2cc4abd91a0 100644 --- a/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java @@ -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; @@ -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()) { @@ -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; diff --git a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java index 84df6c5c591..d017d250b4a 100644 --- a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java @@ -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; @@ -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); }); }