From 1b820de08a05070909a267e17f033fcf58ac8710 Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Mon, 2 Sep 2024 23:17:17 +0200 Subject: The Great Renaming (#3014) * move kekztech to a single root dir * move detrav to a single root dir * move gtnh-lanthanides to a single root dir * move tectech and delete some gross reflection in gt++ * remove more reflection inside gt5u * delete more reflection in gt++ * fix imports * move bartworks and bwcrossmod * fix proxies * move galactigreg and ggfab * move gtneioreplugin * try to fix gt++ bee loader * apply the rename rules to BW * apply rename rules to bwcrossmod * apply rename rules to detrav scanner mod * apply rename rules to galacticgreg * apply rename rules to ggfab * apply rename rules to goodgenerator * apply rename rules to gtnh-lanthanides * apply rename rules to gt++ * apply rename rules to kekztech * apply rename rules to kubatech * apply rename rules to tectech * apply rename rules to gt apply the rename rules to gt * fix tt import * fix mui hopefully * fix coremod except intergalactic * rename assline recipe class * fix a class name i stumbled on * rename StructureUtility to GTStructureUtility to prevent conflict with structurelib * temporary rename of GTTooltipDataCache to old name * fix gt client/server proxy names --- src/main/java/ggfab/util/GGUtils.java | 78 +++++++++++++++++++++++++++ src/main/java/ggfab/util/OverclockHelper.java | 75 ++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/main/java/ggfab/util/GGUtils.java create mode 100644 src/main/java/ggfab/util/OverclockHelper.java (limited to 'src/main/java/ggfab/util') diff --git a/src/main/java/ggfab/util/GGUtils.java b/src/main/java/ggfab/util/GGUtils.java new file mode 100644 index 0000000000..7dd70ed759 --- /dev/null +++ b/src/main/java/ggfab/util/GGUtils.java @@ -0,0 +1,78 @@ +package ggfab.util; + +import java.util.StringJoiner; + +import net.minecraft.util.ChunkCoordinates; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public class GGUtils { + + public static boolean isValidTile(IGregTechTileEntity tile) { + return tile != null && !tile.isDead() + && tile.getMetaTileEntity() != null + && tile.getMetaTileEntity() + .getBaseMetaTileEntity() == tile; + } + + public static boolean isValidTile(IMetaTileEntity mte) { + return mte != null && mte.getBaseMetaTileEntity() != null + && mte.getBaseMetaTileEntity() + .getMetaTileEntity() == mte + && !mte.getBaseMetaTileEntity() + .isDead(); + } + + public static ChunkCoordinates translate(ChunkCoordinates origin, ForgeDirection direction) { + return new ChunkCoordinates( + origin.posX + direction.offsetX, + origin.posY + direction.offsetY, + origin.posZ + direction.offsetZ); + } + + public static String formatTileInfo(String prefix, IMetaTileEntity mte, String delimiter, String suffix) { + if (!isValidTile(mte)) return prefix + "N/A" + suffix; + StringJoiner sj = new StringJoiner(delimiter, prefix, suffix); + IGregTechTileEntity til = mte.getBaseMetaTileEntity(); + sj.add(String.valueOf(til.getXCoord())); + sj.add(String.valueOf(til.getYCoord())); + sj.add(String.valueOf(til.getZCoord())); + return sj.toString(); + } + + public static String formatTileInfo(String prefix, IGregTechTileEntity tile, String delimiter, String suffix) { + if (!isValidTile(tile)) return prefix + "N/A" + suffix; + StringJoiner sj = new StringJoiner(delimiter, prefix, suffix); + sj.add(String.valueOf(tile.getXCoord())); + sj.add(String.valueOf(tile.getYCoord())); + sj.add(String.valueOf(tile.getZCoord())); + return sj.toString(); + } + + /** + * convert lowerCamelCase to any of snake case or normal sentence + */ + public static String processSentence(String src, Character separator, boolean capitalize, boolean firstCapitalize) { + if (src == null) throw new IllegalArgumentException(); + if (src.isEmpty()) return ""; + StringBuilder out = new StringBuilder(src.length()); + if (firstCapitalize) out.append(Character.toUpperCase(src.charAt(0))); + else out.append(src.charAt(0)); + for (int i = 1; i < src.length(); i++) { + char ch = src.charAt(i); + if (Character.isUpperCase(ch)) { + if (separator != null) out.append(separator.charValue()); + if (capitalize) { + out.append(ch); + } else { + out.append(Character.toLowerCase(ch)); + } + } else { + out.append(ch); + } + } + return out.toString(); + } +} diff --git a/src/main/java/ggfab/util/OverclockHelper.java b/src/main/java/ggfab/util/OverclockHelper.java new file mode 100644 index 0000000000..b0e42930e8 --- /dev/null +++ b/src/main/java/ggfab/util/OverclockHelper.java @@ -0,0 +1,75 @@ +package ggfab.util; + +import gregtech.api.util.GTUtility; + +public class OverclockHelper { + + public static OverclockOutput normalOverclock(long recipeEUt, int duration, long inputVoltage, boolean perfectOC) { + if (recipeEUt > inputVoltage) return null; + int recipeTier = Math.max(1, GTUtility.getTier(recipeEUt)); // ULV no overclock + int machineTier = GTUtility.getTier(inputVoltage); + int shift = perfectOC ? 2 : 1; + while (recipeTier < machineTier && duration > 1) { + duration >>= shift; + recipeEUt <<= 2; + recipeTier++; + } + return new OverclockOutput(recipeEUt, duration); + } + + public static OverclockOutput laserOverclock(long recipeEUt, int duration, long inputEUt, + float penaltyIncreaseFactor) { + if (recipeEUt > inputEUt) return null; + float currentPenalty = 4 + penaltyIncreaseFactor; + // 2/(n+k) overclock until energy hatch is crying + // must ensure it doesn't go to negative after overclock + while (recipeEUt * currentPenalty > 0 && recipeEUt * currentPenalty < inputEUt && duration > 1) { + duration >>= 1; + recipeEUt *= currentPenalty; + currentPenalty += penaltyIncreaseFactor; + } + return new OverclockOutput(recipeEUt, duration); + } + + public static final class OverclockOutput { + + private final long mEUt; + private final int mDuration; + + public OverclockOutput(long aEUt, int aDuration) { + this.mEUt = aEUt; + this.mDuration = aDuration; + } + + public long getEUt() { + return mEUt; + } + + public int getDuration() { + return mDuration; + } + + @Override + public String toString() { + return mEUt + "@" + mDuration + "ticks"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof OverclockOutput)) return false; + + OverclockOutput that = (OverclockOutput) o; + + if (mEUt != that.mEUt) return false; + return mDuration == that.mDuration; + } + + @Override + public int hashCode() { + int result = (int) (mEUt ^ (mEUt >>> 32)); + result = 31 * result + mDuration; + return result; + } + } +} -- cgit