From 820ebd76016b69a0346588bcdc90a53f251e5b4c Mon Sep 17 00:00:00 2001 From: iamblackornot Date: Thu, 12 Oct 2023 14:38:45 +0300 Subject: average per tick counter for cable voltage and amperage (#2321) * - a workaround fix to https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/14431 - code clean-up of unused variables related to the issue - portable scanner infodata is cleaned too since some of the data is related to mentioned before "ghost" variables * - PR review changes * "Current Amperage" -> "Amperage" * - updated gradle build script * - sync fork * added AveragePerTickCounter class, which helps getting [current tick] value and [average] value for Amperage and Voltage of energy cable blocks updated cable scanner info to show these values * - lowercase the first letter of new methods to follow the guidelines - added one comment to explain code segment's logic --------- Co-authored-by: iamblackornot --- .../gregtech/api/graphs/paths/PowerNodePath.java | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/main/java/gregtech/api/graphs') diff --git a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java index a232822b26..8a869c333e 100644 --- a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java +++ b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java @@ -2,9 +2,11 @@ package gregtech.api.graphs.paths; import net.minecraft.server.MinecraftServer; +import gregtech.api.enums.TickTime; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable; +import gregtech.api.util.AveragePerTickCounter; // path for cables // all calculations like amp and voltage happens here @@ -18,6 +20,9 @@ public class PowerNodePath extends NodePath { int mTick = 0; boolean mCountUp = true; + private AveragePerTickCounter avgAmperageCounter = new AveragePerTickCounter(TickTime.SECOND); + private AveragePerTickCounter avgVoltageCounter = new AveragePerTickCounter(TickTime.SECOND); + public PowerNodePath(MetaPipeEntity[] aCables) { super(aCables); } @@ -27,6 +32,9 @@ public class PowerNodePath extends NodePath { } public void applyVoltage(long aVoltage, boolean aCountUp) { + + avgVoltageCounter.addValue(Math.max(aVoltage - mLoss, 0)); + int tNewTime = MinecraftServer.getServer() .getTickCounter(); if (mTick != tNewTime) { @@ -60,6 +68,9 @@ public class PowerNodePath extends NodePath { } public void addAmps(long aAmps) { + + avgAmperageCounter.addValue(aAmps); + this.mAmps += aAmps; if (this.mAmps > mMaxAmps * 40) { lock.addTileEntity(null); @@ -76,6 +87,7 @@ public class PowerNodePath extends NodePath { // if no amps pass through for more than 0.5 second reduce them to minimize wrong results // but still allow the player to see if activity is happening + @Deprecated public long getAmps() { int tTime = MinecraftServer.getServer() .getTickCounter() - 10; @@ -86,6 +98,7 @@ public class PowerNodePath extends NodePath { return mAmps; } + @Deprecated public long getVoltage(MetaPipeEntity aCable) { int tLoss = 0; if (mCountUp) { @@ -108,6 +121,22 @@ public class PowerNodePath extends NodePath { return -1; } + public long getAmperage() { + return avgAmperageCounter.getLast(); + } + + public double getAvgAmperage() { + return avgAmperageCounter.getAverage(); + } + + public long getVoltage() { + return avgVoltageCounter.getLast(); + } + + public double getAvgVoltage() { + return avgVoltageCounter.getAverage(); + } + @Override protected void processPipes() { super.processPipes(); -- cgit