aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/power/BasicMachineEUPower.java
blob: aad3a72718e5aecc0a081c4b5267984d68f1a85d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package gregtech.common.power;

import static gregtech.api.enums.GT_Values.V;

public class BasicMachineEUPower extends EUPower {
    protected static final String OC = " (OC)";
    protected boolean wasOverclocked;

    public BasicMachineEUPower(byte tier, int amperage) {
        super(tier, amperage);
    }

    @Override
    public void computePowerUsageAndDuration(int euPerTick, int duration) {
        super.computePowerUsageAndDuration(euPerTick, duration);
        if (tier == 0) {
            //Long time calculation
            long xMaxProgresstime = ((long) duration) << 1;
            if (xMaxProgresstime > Integer.MAX_VALUE - 1) {
                //make impossible if too long
                recipeEuPerTick = Integer.MAX_VALUE - 1;
                recipeDuration = Integer.MAX_VALUE - 1;
            } else {
                recipeEuPerTick = euPerTick >> 2;
                recipeDuration = (int) xMaxProgresstime;
            }
        } else {
            //Long EUt calculation
            long xEUt = euPerTick;
            //Isnt too low EUt check?
            long tempEUt = Math.max(xEUt, V[1]);

            recipeDuration = duration;

            while (tempEUt <= V[tier - 1] * (long) amperage) {
                tempEUt <<= 2;//this actually controls overclocking
                //xEUt *= 4;//this is effect of everclocking
                recipeDuration >>= 1;//this is effect of overclocking
                xEUt = recipeDuration == 0 ? xEUt >> 1 : xEUt << 2;//U know, if the time is less than 1 tick make the machine use 2x less power
            }
            if (xEUt > Integer.MAX_VALUE - 1) {
                recipeEuPerTick = Integer.MAX_VALUE - 1;
                recipeDuration = Integer.MAX_VALUE - 1;
            } else {
                recipeEuPerTick = (int) xEUt;
                if (recipeEuPerTick == 0)
                    recipeEuPerTick = 1;
                if (recipeDuration == 0)
                    recipeDuration = 1;//set time to 1 tick
            }
        }
        wasOverclocked = checkIfOverclocked();
    }

    @Override
    public String getPowerUsageString() {
        return decorateWithOverclockLabel(super.getPowerUsageString());
    }

    protected String decorateWithOverclockLabel(String s) {
        if (wasOverclocked) {
            s += OC;
        }
        return s;
    }

    protected boolean checkIfOverclocked() {
        return originalVoltage != computeVoltageForEuRate(recipeEuPerTick);
    }
}