package mcjty.rftools.blocks.screens.modules;

public class ScreenModuleHelper {
    private boolean showdiff = false;
    private long prevMillis = 0;
    private long prevContents = 0;

    public Object[] getContentsValue(long millis, long contents, long maxContents) {
        if (showdiff) {
            if (prevMillis == 0 || millis <= prevMillis) {
                prevMillis = millis;
                prevContents = contents;
                return new Object[] { contents, maxContents, 0L };
            } else {
                long diff = millis - prevMillis;
                int ticks = (int) (diff * 20 / 1000);
                if (ticks == 0) {
                    ticks = 1;
                }
                long diffEnergy = contents - prevContents;
                prevMillis = millis;
                prevContents = contents;
                return new Object[] { contents, maxContents, diffEnergy / ticks };
            }
        } else {
            return new Object[] { contents, maxContents, 0L };
        }
    }

    public void setShowdiff(boolean showdiff) {
        this.showdiff = showdiff;
    }
}

@@ -179,16 +179,50 @@
 nts = 0;
+%0A    private long lastPerTick = 0;
 %0A%0A    pu
@@ -379,19 +379,114 @@
 evMillis
-) %7B
+ + 100) %7B        // %3C= prevMillis + 100 to make sure we show last value if the timing is too short
 %0A       
@@ -609,34 +609,43 @@
 s, maxContents, 
-0L
+lastPerTick
  %7D;%0A            
@@ -968,32 +968,82 @@
 nts = contents;%0A
+                lastPerTick = diffEnergy / ticks;%0A
                 
@@ -1087,34 +1087,27 @@
 ntents, 
-diffEnergy / t
+lastPerT
 ick
-s
  %7D;%0A    

Fix a bug where multiple people looking at the same RF/t energy module in a screen would not see the same thing.