diff --git a/src/main/java/gregtech/api/GTValues.java b/src/main/java/gregtech/api/GTValues.java index 3ec0fcaa5e0..44545152acb 100644 --- a/src/main/java/gregtech/api/GTValues.java +++ b/src/main/java/gregtech/api/GTValues.java @@ -54,7 +54,7 @@ public class GTValues { * The Voltage Tiers. Use this Array instead of the old named Voltage Variables */ public static final long[] V = { 8, 32, 128, 512, 2048, 8192, 32768, 131072, 524288, 2097152, 8388608, 33554432, - 134217728, 536870912, Integer.MAX_VALUE }; + 134217728, 536870912, 2147483648L }; /** * The Voltage Tiers divided by 2. @@ -78,10 +78,10 @@ public class GTValues { * The Voltage Tiers extended all the way to max Long value for overclocking */ public static final long[] VOC = { 8, 32, 128, 512, 2048, 8192, 32768, 131072, 524288, 2097152, 8388608, 33554432, - 134217728, 536870912, Integer.MAX_VALUE, 8589934592L, 34359738368L, 137438953472L, 549755813888L, - 2199023255552L, - 8796093022208L, 35184372088832L, 140737488355328L, 562949953421312L, 2251799813685248L, 9007199254740992L, - 36028797018963968L, 144115188075855872L, 576460752303423488L, 2305843009213693952L, Long.MAX_VALUE }; + 134217728, 536870912, 2147483648L, 8589934592L, 34359738368L, 137438953472L, 549755813888L, + 2199023255552L, 8796093022208L, 35184372088832L, 140737488355328L, 562949953421312L, 2251799813685248L, + 9007199254740992L, 36028797018963968L, 144115188075855872L, 576460752303423488L, 2305843009213693952L, + Long.MAX_VALUE }; public static final int ULV = 0; public static final int LV = 1; diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 729898ff65c..3f533b898c3 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -75,9 +75,6 @@ import java.util.function.Function; import java.util.function.Predicate; -import static gregtech.api.GTValues.V; -import static gregtech.api.GTValues.VOC; - public class GTUtility { public static String[] mapToString(T[] array, Function mapper) { @@ -257,7 +254,10 @@ public static int nearestLesser(@NotNull long[] array, long value) { * tier that can handle it, {@code MAX} is returned. */ public static byte getTierByVoltage(long voltage) { - return (byte) Math.min(GTValues.MAX, nearestLesser(V, voltage) + 1); + if (voltage >= Integer.MAX_VALUE) { + return GTValues.MAX; + } + return getOCTierByVoltage(voltage); } /** @@ -266,7 +266,10 @@ public static byte getTierByVoltage(long voltage) { * tier that can handle it, {@code MAX_TRUE} is returned. */ public static byte getOCTierByVoltage(long voltage) { - return (byte) Math.min(GTValues.MAX_TRUE, nearestLesser(VOC, voltage) + 1); + if (voltage <= GTValues.V[GTValues.ULV]) { + return GTValues.ULV; + } + return (byte) ((62 - Long.numberOfLeadingZeros(voltage - 1)) >> 1); } /** @@ -276,7 +279,14 @@ public static byte getOCTierByVoltage(long voltage) { * {@code ULV} if there's no tier below */ public static byte getFloorTierByVoltage(long voltage) { - return (byte) Math.max(GTValues.ULV, nearestLesserOrEqual(VOC, voltage)); + if (voltage < GTValues.V[GTValues.LV]) { + return GTValues.ULV; + } + if (voltage == GTValues.VOC[GTValues.MAX_TRUE]) { + return GTValues.MAX_TRUE; + } + + return (byte) ((60 - Long.numberOfLeadingZeros(voltage)) >> 1); } @SuppressWarnings("deprecation")