diff --git a/guidebook/items-blocks-machines/p2p_tunnels.md b/guidebook/items-blocks-machines/p2p_tunnels.md index 2ade9d9c0ac..c31f5c7ad3b 100644 --- a/guidebook/items-blocks-machines/p2p_tunnels.md +++ b/guidebook/items-blocks-machines/p2p_tunnels.md @@ -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 diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 96ff22d93a1..6e2661ac3a0 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -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(); @@ -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; @@ -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); diff --git a/src/main/java/appeng/parts/p2p/FEP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/FEP2PTunnelPart.java index 28d8a9a88bc..22cfc312605 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(PowerUnits.FE, total); + deductEnergyCost(total, PowerUnits.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(PowerUnits.FE, total); + deductEnergyCost(total, PowerUnits.FE); } return total; diff --git a/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java index 34e5d409990..6b783c2674d 100644 --- a/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/FluidP2PTunnelPart.java @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java b/src/main/java/appeng/parts/p2p/ItemP2PTunnelPart.java index 548f5b745fa..f69ed91fb39 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.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; @@ -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()) { @@ -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; diff --git a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java index 78127d9efb9..e661376da5d 100644 --- a/src/main/java/appeng/parts/p2p/P2PTunnelPart.java +++ b/src/main/java/appeng/parts/p2p/P2PTunnelPart.java @@ -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; @@ -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); }); }