aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java
diff options
context:
space:
mode:
authoriamblackornot <nkzshinnik@gmail.com>2023-10-12 14:38:45 +0300
committerGitHub <noreply@github.com>2023-10-12 13:38:45 +0200
commit820ebd76016b69a0346588bcdc90a53f251e5b4c (patch)
tree00c83d3b750119ef63909204941bcec883f08019 /src/main/java/gregtech/api/graphs/paths/PowerNodePath.java
parent0f1df8bb1de3ab5567e6b38e2d8c59edf6be12d8 (diff)
downloadGT5-Unofficial-820ebd76016b69a0346588bcdc90a53f251e5b4c.tar.gz
GT5-Unofficial-820ebd76016b69a0346588bcdc90a53f251e5b4c.tar.bz2
GT5-Unofficial-820ebd76016b69a0346588bcdc90a53f251e5b4c.zip
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 <nkzshinnnik@gmail.com>
Diffstat (limited to 'src/main/java/gregtech/api/graphs/paths/PowerNodePath.java')
-rw-r--r--src/main/java/gregtech/api/graphs/paths/PowerNodePath.java29
1 files changed, 29 insertions, 0 deletions
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();