Skip to content

Commit

Permalink
Add OCing past MAX and fix multi Laser and Substation Hatch support (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
IncandescenceSy authored Sep 8, 2024
1 parent cc0e414 commit 00034fb
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 14 deletions.
20 changes: 18 additions & 2 deletions src/main/java/gregtech/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 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 };

public static final int ULV = 0;
public static final int LV = 1;
public static final int MV = 2;
Expand All @@ -90,22 +99,29 @@ 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;

/**
* The short names for the voltages, used for registration primarily
*/
public static final String[] VN = new String[] { "ULV", "LV", "MV", "HV", "EV", "IV", "LuV", "ZPM", "UV", "UHV",
"UEV", "UIV", "UXV", "OpV", "MAX" };
"UEV", "UIV", "UXV", "OpV", "MAX", "MAX+" };

/**
* The short names for the voltages, formatted for text
*/
public static final String MAX_PLUS = RED.toString() + BOLD + "M" + YELLOW + BOLD + "A" + GREEN + BOLD + "X" +
AQUA + BOLD + "+" + LIGHT_PURPLE + BOLD;
public static final String[] VNF = new String[] {
DARK_GRAY + "ULV", GRAY + "LV", AQUA + "MV",
GOLD + "HV", DARK_PURPLE + "EV", DARK_BLUE + "IV",
LIGHT_PURPLE + "LuV", RED + "ZPM", DARK_AQUA + "UV",
DARK_RED + "UHV", GREEN + "UEV", DARK_GREEN + "UIV",
YELLOW + "UXV", BLUE + "OpV", RED.toString() + BOLD + "MAX" };
YELLOW + "UXV", BLUE + "OpV", RED.toString() + BOLD + "MAX",
MAX_PLUS + "1", MAX_PLUS + "2", MAX_PLUS + "3", MAX_PLUS + "4",
MAX_PLUS + "5", MAX_PLUS + "6", MAX_PLUS + "7", MAX_PLUS + "8",
MAX_PLUS + "9", MAX_PLUS + "10", MAX_PLUS + "11", MAX_PLUS + "12",
MAX_PLUS + "13", MAX_PLUS + "14", MAX_PLUS + "15", MAX_PLUS + "16", };

/**
* Color values for the voltages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ protected void performOverclocking(@NotNull Recipe recipe, @NotNull OCParams ocP
protected int getNumberOfOCs(long recipeEUt) {
if (!isAllowOverclocking()) return 0;

int recipeTier = GTUtility.getTierByVoltage(recipeEUt);
int recipeTier = GTUtility.getOCTierByVoltage(recipeEUt);
int maximumTier = getOverclockForTier(getMaximumOverclockVoltage());
if (maximumTier <= GTValues.LV) return 0;

Expand Down Expand Up @@ -911,7 +911,7 @@ protected double getOverclockingVoltageFactor() {
* @return the highest voltage tier the machine should use to overclock with
*/
protected int getOverclockForTier(long voltage) {
return GTUtility.getTierByVoltage(voltage);
return GTUtility.getOCTierByVoltage(voltage);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public long getMaximumOverclockVoltage() {
// 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
return GTValues.V[GTUtility.getFloorTierByVoltage(voltage)];
return GTValues.VOC[GTUtility.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 Expand Up @@ -420,7 +420,7 @@ public long getMaxVoltage() {
// The voltage for recipe search is always on tier, so take the closest lower tier.
// List check is done because single hatches will always be a "clean voltage," no need
// for any additional checks.
return GTValues.V[GTUtility.getFloorTierByVoltage(voltage)];
return GTValues.VOC[GTUtility.getFloorTierByVoltage(voltage)];
}
return voltage;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public FuelMultiblockController(ResourceLocation metaTileEntityId, RecipeMap<?>
@Override
protected void initializeAbilities() {
super.initializeAbilities();
this.energyContainer = new EnergyContainerList(getAbilities(MultiblockAbility.OUTPUT_ENERGY));
List<IEnergyContainer> outputEnergy = new ArrayList<>(getAbilities(MultiblockAbility.OUTPUT_ENERGY));
outputEnergy.addAll(getAbilities(MultiblockAbility.SUBSTATION_OUTPUT_ENERGY));
outputEnergy.addAll(getAbilities(MultiblockAbility.OUTPUT_LASER));
this.energyContainer = new EnergyContainerList(outputEnergy);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Builder addEnergyUsageExactLine(long energyUsage) {
String energyFormatted = TextFormattingUtil.formatNumbers(energyUsage);
// wrap in text component to keep it from being formatted
ITextComponent voltageName = new TextComponentString(
GTValues.VNF[GTUtility.getTierByVoltage(energyUsage)]);
GTValues.VNF[GTUtility.getOCTierByVoltage(energyUsage)]);

textList.add(TextComponentUtil.translationWithColor(
TextFormatting.GRAY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ protected void initializeAbilities() {
this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS));
this.outputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(),
getAbilities(MultiblockAbility.EXPORT_FLUIDS));
this.energyContainer = new EnergyContainerList(getAbilities(MultiblockAbility.INPUT_ENERGY));

List<IEnergyContainer> inputEnergy = new ArrayList<>(getAbilities(MultiblockAbility.INPUT_ENERGY));
inputEnergy.addAll(getAbilities(MultiblockAbility.SUBSTATION_INPUT_ENERGY));
inputEnergy.addAll(getAbilities(MultiblockAbility.INPUT_LASER));
this.energyContainer = new EnergyContainerList(inputEnergy);
}

private void resetTileAbilities() {
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.function.Predicate;

import static gregtech.api.GTValues.V;
import static gregtech.api.GTValues.VOC;

public class GTUtility {

Expand Down Expand Up @@ -259,14 +260,23 @@ public static byte getTierByVoltage(long voltage) {
return (byte) Math.min(GTValues.MAX, nearestLesser(V, voltage) + 1);
}

/**
* @return Lowest tier of the voltage that can handle {@code voltage}, extended up to max long value; that is,
* a voltage with value greater than equal than {@code voltage}. If there's no
* 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);
}

/**
* Ex: This method turns both 1024 and 512 into HV.
*
* @return the highest voltage tier with value below or equal to {@code voltage}, or
* {@code ULV} if there's no tier below
*/
public static byte getFloorTierByVoltage(long voltage) {
return (byte) Math.max(GTValues.ULV, nearestLesserOrEqual(V, voltage));
return (byte) Math.max(GTValues.ULV, nearestLesserOrEqual(VOC, voltage));
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ public int getProgressPercent() {
@Override
public int getEnergyTier() {
if (energyContainer == null) return GTValues.LV;
return Math.max(GTValues.LV, GTUtility.getFloorTierByVoltage(energyContainer.getInputVoltage()));
return Math.min(GTValues.MAX,
Math.max(GTValues.LV, GTUtility.getFloorTierByVoltage(energyContainer.getInputVoltage())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWai
}
if (endText == null) {
endText = ": " + TextFormattingUtil.formatNumbers(eut) + TextFormatting.RESET + " EU/t (" +
GTValues.VNF[GTUtility.getTierByVoltage(eut)] + TextFormatting.RESET + ")";
GTValues.VNF[GTUtility.getOCTierByVoltage(eut)] + TextFormatting.RESET + ")";
}

if (eut == 0) return tooltip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void addProbeInfo(@NotNull AbstractRecipeLogic capability, @NotNull IP
// IGregTechTileEntity...)
text = TextFormatting.RED + TextFormattingUtil.formatNumbers(eut) + TextStyleClass.INFO +
" EU/t" + TextFormatting.GREEN +
" (" + GTValues.VNF[GTUtility.getTierByVoltage(eut)] + TextFormatting.GREEN + ")";
" (" + GTValues.VNF[GTUtility.getOCTierByVoltage(eut)] + TextFormatting.GREEN + ")";
}

if (eut == 0) return; // do not display 0 eut
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/gregtech/api/util/TierByVoltageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void testVSpecialCases() {
expectTier(0L, ULV, ULV);
expectTier(2L, ULV, ULV);
expectTier(Integer.MAX_VALUE + 1L, MAX, MAX);
expectTier(Long.MAX_VALUE, MAX, MAX);
expectTier(Long.MAX_VALUE, MAX, MAX_TRUE);
expectTier(-1L, ULV, ULV);
}

Expand Down

0 comments on commit 00034fb

Please sign in to comment.