aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/power/BasicMachineEUPower.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/common/power/BasicMachineEUPower.java')
-rw-r--r--src/main/java/gregtech/common/power/BasicMachineEUPower.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/gregtech/common/power/BasicMachineEUPower.java b/src/main/java/gregtech/common/power/BasicMachineEUPower.java
new file mode 100644
index 0000000000..12691ac6d9
--- /dev/null
+++ b/src/main/java/gregtech/common/power/BasicMachineEUPower.java
@@ -0,0 +1,72 @@
+package gregtech.common.power;
+
+import gregtech.api.util.GT_Utility;
+
+import static gregtech.api.enums.GT_Values.V;
+
+public class BasicMachineEUPower extends EUPower{
+ private static final String OC = " (OC)";
+ private 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());
+ }
+
+ private String decorateWithOverclockLabel(String s) {
+ if (wasOverclocked) {
+ s += OC;
+ }
+ return s;
+ }
+
+ private boolean checkIfOverclocked() {
+ return originalVoltage != computeVoltageForEuRate(recipeEuPerTick);
+ }
+}