Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port of 1.12#2617 #2007

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/com/gregtechceu/gtceu/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class GTValues {
* The Voltage Tiers. Use this Array instead of the old named Voltage Variables
*/
public static final long[] V = new long[] { 8, 32, 128, 512, 2048, 8192, 32768, 131072, 524288, 2097152, 8388608,
33554432, 134217728, 536870912, Integer.MAX_VALUE };
33554432, 134217728, 536870912, 2147483648L };

/**
* The Voltage Tiers divided by 2.
Expand All @@ -75,6 +75,15 @@ public class GTValues {
public static final int[] VHA = { 7, 16, 60, 240, 960, 3840, 15360, 61440, 245760, 983040, 3932160, 15728640,
62914560, 251658240, 1006632960 };

/**
* The Voltage Tiers. Use this Array instead of the old named Voltage Variables
*/
public static final long[] VEX = new long[] { 8, 32, 128, 512, 2048, 8192, 32768, 131072, 524288, 2097152, 8388608,
33554432, 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;
public static final int MV = 2;
Expand All @@ -90,6 +99,7 @@ public class GTValues {
public static final int UXV = 12;
public static final int OpV = 13;
public static final int MAX = 14;
public static final int MAX_TRUE = 30;

public static final int[] ALL_TIERS = new int[] { ULV, LV, MV, HV, EV, IV, LuV, ZPM, UV, UHV, UEV, UIV, UXV, OpV,
MAX };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ public long getOverclockVoltage() {
if (amperage == 1) {
// amperage is 1 when the energy is not exactly on a tier
// the voltage for recipe search is always on tier, so take the closest lower tier
if (voltage > Integer.MAX_VALUE) return GTUtil.getVoltageFromFakeTier(GTUtil.getFakeVoltageTier(voltage));
return GTValues.V[GTUtil.getFloorTierByVoltage(voltage)];
return GTValues.VEX[GTUtil.getFloorTierByVoltage(voltage)];
} else {
// amperage != 1 means the voltage is exactly on a tier
// ignore amperage, since only the voltage is relevant for recipe search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ public static GTRecipe applyOverclock(OverclockingLogic logic, @NotNull GTRecipe
* Then performs overclocking on the Recipe.
*
* @param recipe the recipe to overclock
* @return an int array of {OverclockedEUt, OverclockedDuration}
*/
public static void performOverclocking(OverclockingLogic logic, @NotNull GTRecipe recipe, long EUt,
long maxOverclockVoltage,
@NotNull OCParams params, @NotNull OCResult result) {
int recipeTier = GTUtil.getTierByVoltage(EUt);
int maximumTier = maxOverclockVoltage < Integer.MAX_VALUE ? logic.getOverclockForTier(maxOverclockVoltage) :
GTUtil.getFakeVoltageTier(maxOverclockVoltage);
int maximumTier = logic.getOverclockForTier(maxOverclockVoltage);
// The maximum number of overclocks is determined by the difference between the tier the recipe is running at,
// and the maximum tier that the machine can overclock to.
int numberOfOCs = maximumTier - recipeTier;
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.Tags;

import com.google.common.math.LongMath;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.datafixers.util.Pair;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -197,22 +196,17 @@ public static int nearestLesser(@NotNull long[] array, long value) {
* tier that can handle it, {@code MAX} is returned.
*/
public static byte getTierByVoltage(long voltage) {
// Yes, yes we do need UHV+.
return (byte) Math.min(GTValues.MAX, nearestLesser(GTValues.V, voltage) + 1);
}

public static int getFakeVoltageTier(long voltage) {
long a = voltage;
int b = 0;
while (a / 4L >= 8L) {
b++;
a /= 4L;
if (voltage > Integer.MAX_VALUE) {
return GTValues.MAX;
}
return b;
return getOCTierByVoltage(voltage);
}

public static long getVoltageFromFakeTier(int tier) {
return LongMath.pow(4L, tier + 1) * 2;
public static byte getOCTierByVoltage(long voltage) {
if (voltage <= GTValues.V[GTValues.ULV]) {
return GTValues.ULV;
}
return (byte) ((62 - Long.numberOfLeadingZeros(voltage - 1)) >> 1);
}

/**
Expand All @@ -222,7 +216,14 @@ public static long getVoltageFromFakeTier(int tier) {
* {@code ULV} if there's no tier below
*/
public static byte getFloorTierByVoltage(long voltage) {
return (byte) Math.max(GTValues.ULV, nearestLesserOrEqual(GTValues.V, voltage));
if (voltage < GTValues.V[GTValues.ULV]) {
return GTValues.ULV;
}
if (voltage == GTValues.VEX[GTValues.MAX_TRUE]) {
return GTValues.MAX_TRUE;
}

return (byte) ((60 - Long.numberOfLeadingZeros(voltage - 1)) >> 1);
}

public static ItemStack copy(ItemStack... stacks) {
Expand Down