aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bartworks/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/bartworks/util')
-rw-r--r--src/main/java/bartworks/util/BWColorUtil.java216
-rw-r--r--src/main/java/bartworks/util/BWRecipes.java71
-rw-r--r--src/main/java/bartworks/util/BWTooltipReference.java45
-rw-r--r--src/main/java/bartworks/util/BWUtil.java784
-rw-r--r--src/main/java/bartworks/util/BioCulture.java253
-rw-r--r--src/main/java/bartworks/util/BioDNA.java51
-rw-r--r--src/main/java/bartworks/util/BioData.java173
-rw-r--r--src/main/java/bartworks/util/BioPlasmid.java51
-rw-r--r--src/main/java/bartworks/util/CachedReflectionUtils.java31
-rw-r--r--src/main/java/bartworks/util/ConnectedBlocksChecker.java187
-rw-r--r--src/main/java/bartworks/util/ConnectedBlocksCheckerIteration.java146
-rw-r--r--src/main/java/bartworks/util/Coords.java79
-rw-r--r--src/main/java/bartworks/util/EnumUtils.java50
-rw-r--r--src/main/java/bartworks/util/MathUtils.java116
-rw-r--r--src/main/java/bartworks/util/MurmurHash3.java306
-rw-r--r--src/main/java/bartworks/util/NoiseUtil/BartsNoise.java171
-rw-r--r--src/main/java/bartworks/util/NoiseUtil/SimplexNoise.java396
-rw-r--r--src/main/java/bartworks/util/NonNullWrappedHashMap.java56
-rw-r--r--src/main/java/bartworks/util/NonNullWrappedHashSet.java51
-rw-r--r--src/main/java/bartworks/util/Pair.java81
-rw-r--r--src/main/java/bartworks/util/ResultWrongSievert.java97
-rw-r--r--src/main/java/bartworks/util/StreamUtils.java38
-rw-r--r--src/main/java/bartworks/util/accessprioritylist/AccessPriorityList.java388
-rw-r--r--src/main/java/bartworks/util/accessprioritylist/AccessPriorityListIterators.java163
-rw-r--r--src/main/java/bartworks/util/accessprioritylist/AccessPriorityListNode.java72
-rw-r--r--src/main/java/bartworks/util/flowerset/FlowerSet.java146
-rw-r--r--src/main/java/bartworks/util/log/DebugLog.java65
27 files changed, 4283 insertions, 0 deletions
diff --git a/src/main/java/bartworks/util/BWColorUtil.java b/src/main/java/bartworks/util/BWColorUtil.java
new file mode 100644
index 0000000000..b9453b9963
--- /dev/null
+++ b/src/main/java/bartworks/util/BWColorUtil.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2018-2019 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package bartworks.util;
+
+import java.util.Arrays;
+
+import gregtech.api.enums.Dyes;
+
+@SuppressWarnings("unused")
+public class BWColorUtil {
+
+ private BWColorUtil() {}
+
+ public static byte getDarknessFromColor(short[] rgba, int index) {
+ int g = rgba[index];
+ if (g >= 0 && g < 64) return 0;
+ if (g >= 64 && g < 160) return 1;
+ else if (g >= 160 && g < 223) return 2;
+ else if (g >= 233 && g <= 255) return 3;
+ return 4;
+ }
+
+ public static Dyes getDyeFromColor(short[] rgba) {
+ rgba = correctCorlorArray(rgba);
+ if (isGrayScale(rgba, 2)) {
+ switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ return Dyes.dyeBlack;
+ case 1:
+ return Dyes.dyeGray;
+ case 2:
+ return Dyes.dyeLightGray;
+ case 3:
+ return Dyes.dyeWhite;
+ }
+ } else {
+ short[] tmp = roundColor(rgba, 2);
+ if (isRedScale(tmp)) {
+ if (isPurpleScale(tmp)) {
+ switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ case 1:
+ if (rgba[3] - 50 > rgba[0]) return Dyes.dyePurple;
+ else return Dyes.dyeRed;
+ case 2:
+ case 3:
+ if (rgba[3] - 50 > rgba[0]) return Dyes.dyeMagenta;
+ else if (rgba[0] > 200 && rgba[2] > 140) return Dyes.dyePink;
+ else if (rgba[0] > rgba[1] + rgba[1] / 10 && rgba[0] > rgba[2] + rgba[2] / 10
+ && rgba[1] >> 4 == rgba[2] >> 4
+ && rgba[1] + 50 > rgba[0]) {
+ return Dyes.dyeBrown;
+ } else return Dyes.dyeRed;
+ case 4:
+ return Dyes._NULL;
+ }
+ }
+ if (isYellowScale(tmp)) switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ case 1:
+ return Dyes.dyeBrown;
+ case 2:
+ case 3: {
+ if (rgba[0] >> 5 > rgba[1] >> 5) return Dyes.dyeOrange;
+ else return Dyes.dyeYellow;
+ }
+ case 4:
+ return Dyes._NULL;
+ }
+ return Dyes.dyePink;
+ }
+ if (isGrenScale(tmp)) {
+ if (isCyanScale(tmp)) {
+ if (rgba[2] + 40 < rgba[1]) switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ case 1:
+ return Dyes.dyeGreen;
+ case 2:
+ case 3:
+ return Dyes.dyeLime;
+ }
+ return Dyes.dyeCyan;
+ }
+ if (isYellowScale(tmp)) switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ case 1:
+ return Dyes.dyeBrown;
+ case 2:
+ case 3: {
+ if (rgba[0] >> 5 > rgba[1] >> 5) return Dyes.dyeOrange;
+ else return Dyes.dyeYellow;
+ }
+ }
+ switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ case 1:
+ return Dyes.dyeGreen;
+ case 2:
+ case 3:
+ return Dyes.dyeLime;
+ }
+ } else if (isBlueScale(tmp)) {
+ if (isPurpleScale(tmp)) {
+ switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ case 1:
+ return Dyes.dyePurple;
+ case 2:
+ case 3:
+ return Dyes.dyeMagenta;
+ }
+ } else if (isCyanScale(tmp)) {
+ return Dyes.dyeCyan;
+ }
+ switch (getDarknessFromColor(rgba, 0)) {
+ case 0:
+ case 1:
+ return Dyes.dyeBlue;
+ case 2:
+ case 3:
+ return Dyes.dyeLightBlue;
+ }
+ }
+ }
+ return Dyes._NULL;
+ }
+
+ public static boolean isCyanScale(short[] rgba) {
+ return !isRedScale(rgba);
+ }
+
+ public static boolean isPurpleScale(short[] rgba) {
+ return !isGrenScale(rgba);
+ }
+
+ public static boolean isYellowScale(short[] rgba) {
+ return !isBlueScale(rgba);
+ }
+
+ public static boolean isBlueScale(short[] rgba) {
+ rgba = correctCorlorArray(rgba);
+ return rgba[2] * 2 >= rgba[1] + rgba[0];
+ }
+
+ public static boolean isGrenScale(short[] rgba) {
+ rgba = correctCorlorArray(rgba);
+ return rgba[1] * 2 >= rgba[0] + rgba[2];
+ }
+
+ public static boolean isRedScale(short[] rgba) {
+ rgba = correctCorlorArray(rgba);
+ return rgba[0] * 2 >= rgba[1] + rgba[2];
+ }
+
+ public static boolean isGrayScale(short[] rgba, int magin) {
+ rgba = correctCorlorArray(rgba);
+ return rgba[0] >> magin == rgba[1] >> magin && rgba[1] >> magin == rgba[2] >> magin;
+ }
+
+ public static short[] roundColor(short[] rgba, int magin) {
+ short[] tmp = Arrays.copyOf(rgba, 4);
+ tmp[0] = (short) (rgba[0] >> magin);
+ tmp[1] = (short) (rgba[1] >> magin);
+ tmp[2] = (short) (rgba[2] >> magin);
+ return tmp;
+ }
+
+ public static boolean isGrayScale(short[] rgba) {
+ rgba = correctCorlorArray(rgba);
+ return rgba[0] == rgba[1] && rgba[1] == rgba[2];
+ }
+
+ public static short[] correctCorlorArray(short[] rgba) {
+ if (rgba.length > 4) {
+ rgba = Arrays.copyOfRange(rgba, 0, 4);
+ }
+ if (rgba.length < 4) {
+ short[] tmp = Arrays.copyOf(rgba, 4);
+ Arrays.fill(tmp, rgba.length, 4, (short) 0);
+ rgba = tmp;
+ }
+ if (rgba[0] > 255) rgba[0] = 255;
+ if (rgba[1] > 255) rgba[1] = 255;
+ if (rgba[2] > 255) rgba[2] = 255;
+ if (rgba[3] > 255) rgba[3] = 255;
+ if (rgba[0] < 0) rgba[0] = 0;
+ if (rgba[1] < 0) rgba[1] = 0;
+ if (rgba[2] < 0) rgba[2] = 0;
+ if (rgba[3] < 0) rgba[3] = 0;
+ return rgba;
+ }
+
+ public static short[] splitColorToRBGArray(int rgb) {
+ return new short[] { (short) (rgb >> 16 & 0xFF), (short) (rgb >> 8 & 0xFF), (short) (rgb & 0xFF) };
+ }
+
+ public static int getColorFromRGBArray(short[] color) {
+ return (color[0] & 0x0ff) << 16 | (color[1] & 0x0ff) << 8 | color[2] & 0x0ff;
+ }
+
+ public static int getColorFromRGBArray(int[] color) {
+ return (color[0] & 0x0ff) << 16 | (color[1] & 0x0ff) << 8 | color[2] & 0x0ff;
+ }
+
+}
diff --git a/src/main/java/bartworks/util/BWRecipes.java b/src/main/java/bartworks/util/BWRecipes.java
new file mode 100644
index 0000000000..1d6cd56c00
--- /dev/null
+++ b/src/main/java/bartworks/util/BWRecipes.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package bartworks.util;
+
+import gregtech.api.enums.Materials;
+
+public class BWRecipes {
+
+ public static long calcDecayTicks(int x) {
+ long ret;
+ if (x == 43) ret = 5000;
+ else if (x == 61) ret = 4500;
+ else if (x <= 100) ret = MathUtils.ceilLong((8000D * Math.tanh(-x / 20D) + 8000D) * 1000D);
+ else ret = MathUtils.ceilLong(8000D * Math.tanh(-x / 65D) + 8000D);
+ return ret;
+ }
+
+ public static int computeSieverts(int givenSievert, int glassTier, boolean requiresExactSieverts, boolean cleanroom,
+ boolean lowGravity) {
+ byte specialValue = 0;
+ if (cleanroom && lowGravity) {
+ specialValue = 3;
+ } else if (cleanroom) {
+ specialValue = 2;
+ } else if (lowGravity) {
+ specialValue = 1;
+ }
+ int sievertValue = 0;
+ if (givenSievert >= 83 || givenSievert == 61 || givenSievert == 43) sievertValue += givenSievert;
+ sievertValue = sievertValue << 1;
+ sievertValue = sievertValue | (requiresExactSieverts ? 1 : 0);
+ sievertValue = sievertValue << 2;
+ sievertValue = sievertValue | specialValue;
+ sievertValue = sievertValue << 4;
+ sievertValue = sievertValue | glassTier;
+ return sievertValue;
+ }
+
+ public static int computeSieverts(Materials material, int glassTier, boolean requiresExactSieverts,
+ boolean cleanroom, boolean lowGravity) {
+ byte specialValue = 0;
+ if (cleanroom && lowGravity) {
+ specialValue = 3;
+ } else if (cleanroom) {
+ specialValue = 2;
+ } else if (lowGravity) {
+ specialValue = 1;
+ }
+ int aSievert = 0;
+ if (material.getProtons() >= 83 || material.getProtons() == 61 || material.getProtons() == 43)
+ aSievert += BWUtil.calculateSv(material);
+ aSievert = aSievert << 1;
+ aSievert = aSievert | (requiresExactSieverts ? 1 : 0);
+ aSievert = aSievert << 2;
+ aSievert = aSievert | specialValue;
+ aSievert = aSievert << 4;
+ aSievert = aSievert | glassTier;
+ return aSievert;
+ }
+}
diff --git a/src/main/java/bartworks/util/BWTooltipReference.java b/src/main/java/bartworks/util/BWTooltipReference.java
new file mode 100644
index 0000000000..1c9e32e5e6
--- /dev/null
+++ b/src/main/java/bartworks/util/BWTooltipReference.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package bartworks.util;
+
+import static net.minecraft.util.EnumChatFormatting.BLUE;
+import static net.minecraft.util.EnumChatFormatting.DARK_BLUE;
+import static net.minecraft.util.EnumChatFormatting.GRAY;
+import static net.minecraft.util.EnumChatFormatting.GREEN;
+
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
+
+public class BWTooltipReference {
+
+ public static final String BW_NO_RESET = EnumChatFormatting.DARK_GREEN + "BartWorks";
+ public static final String TT_NO_RESET = BLUE + "Tec" + DARK_BLUE + "Tech";
+ public static final String BW = BW_NO_RESET + GRAY;
+ public static final String TT = TT_NO_RESET + GRAY;
+
+ public static final Supplier<String> ADDED_BY_BARTIMAEUSNEK_VIA_BARTWORKS = () -> StatCollector.translateToLocal(
+ "tooltip.bw.1.name") + " " + BW;
+
+ public static final String MULTIBLOCK_ADDED_BY_BARTWORKS = BW;
+ public static final Function<String, String> MULTIBLOCK_ADDED_VIA_BARTWORKS = owner -> String
+ .format(StatCollector.translateToLocal("tooltip.bw.mb_via.name"), owner);
+ public static final String MULTIBLOCK_ADDED_BY_BARTIMAEUSNEK_VIA_BARTWORKS = MULTIBLOCK_ADDED_VIA_BARTWORKS
+ .apply(GREEN + "bartimaeusnek");
+
+ public static final String TT_BLUEPRINT = "To see the structure, use a " + TT + " Blueprint on the Controller!";
+
+}
diff --git a/src/main/java/bartworks/util/BWUtil.java b/src/main/java/bartworks/util/BWUtil.java
new file mode 100644
index 0000000000..5f740af40f
--- /dev/null
+++ b/src/main/java/bartworks/util/BWUtil.java
@@ -0,0 +1,784 @@
+/*
+ * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial
+ * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package bartworks.util;
+
+import static gregtech.api.enums.GTValues.D1;
+import static gregtech.api.enums.GTValues.E;
+import static gregtech.api.enums.GTValues.M;
+import static gregtech.api.enums.GTValues.VN;
+import static gregtech.api.enums.GTValues.W;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import net.minecraft.block.Block;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.init.Items;
+import net.minecraft.item.EnumRarity;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.CraftingManager;
+import net.minecraft.item.crafting.IRecipe;
+import net.minecraft.world.World;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.oredict.OreDictionary;
+import net.minecraftforge.oredict.ShapedOreRecipe;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
+import com.gtnewhorizon.structurelib.structure.IStructureElement;
+
+import bartworks.API.BioVatLogicAdder;
+import bartworks.API.BorosilicateGlass;
+import bartworks.API.GlassTier;
+import bartworks.MainMod;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OreDictNames;
+import gregtech.api.enums.ToolDictNames;
+import gregtech.api.interfaces.IItemContainer;
+import gregtech.api.objects.ItemData;
+import gregtech.api.util.GTLanguageManager;
+import gregtech.api.util.GTLog;
+import gregtech.api.util.GTModHandler;
+import gregtech.api.util.GTOreDictUnificator;
+import gregtech.api.util.GTRecipe;
+import gregtech.api.util.GTShapedRecipe;
+import gregtech.api.util.GTUtility;
+
+public class BWUtil {
+
+ @Deprecated
+ public static final int STANDART = 0;
+ @Deprecated
+ public static final int LOWGRAVITY = -100;
+ @Deprecated
+ public static final int CLEANROOM = -200;
+
+ public static String translateGTItemStack(ItemStack itemStack) {
+ if (!GTUtility.isStackValid(itemStack)) return "Not a Valid ItemStack:" + itemStack;
+ String ret = GTLanguageManager.getTranslation(GTLanguageManager.getTranslateableItemStackName(itemStack));
+ if (!ret.contains("%material")) return ret;
+ String matname = "";
+ if (BWUtil.checkStackAndPrefix(itemStack))
+ matname = GTOreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial.mDefaultLocalName;
+ return ret.replace("%material", matname);
+ }
+
+ public static void set2DCoordTo1DArray(int indexX, int indexY, int sizeY, Object value, Object[] array) {
+ int index = indexX * sizeY + indexY;
+ array[index] = value;
+ }
+
+ public static Object get2DCoordFrom1DArray(int indexX, int indexY, int sizeY, Object[] array) {
+ int index = indexX * sizeY + indexY;
+ return array[index];
+ }
+
+ public static GTRecipe copyAndSetTierToNewRecipe(GTRecipe recipe, byte tier) {
+ byte oldTier = GTUtility.getTier(recipe.mEUt);
+ int newTime = recipe.mDuration;
+ int newVoltage = recipe.mEUt;
+ if (tier < oldTier) {
+ newTime <<= oldTier - tier;
+ newVoltage >>= 2 * (oldTier - tier);
+ } else {
+ newTime >>= tier - oldTier;
+ newVoltage <<= 2 * (tier - oldTier);
+ }
+ recipe.mEUt = newVoltage;
+ recipe.mDuration = newTime;
+ return recipe;
+ }
+
+ public static String subscriptNumbers(String b) {
+ char[] chars = b.toCharArray();
+ char[] nu = new char[chars.length];
+ for (int i = 0; i < chars.length; i++) {
+ nu[i] = switch (chars[i]) {
+ case '0' -> '\u2080';
+ case '1' -> '\u2081';
+ case '2' -> '\u2082';
+ case '3' -> '\u2083';
+ case '4' -> '\u2084';
+ case '5' -> '\u2085';
+ case '6' -> '\u2086';
+ case '7' -> '\u2087';
+ case '8' -> '\u2088';
+ case '9' -> '\u2089';
+ default -> chars[i];
+ };
+ }
+ return new String(nu);
+ }
+
+ public static String subscriptNumber(Number b) {
+ char[] chars = Long.toString(b.longValue())
+ .toCharArray();
+ char[] nu = new char[chars.length];
+ for (int i = 0; i < chars.length; i++) {
+ nu[i] = switch (chars[i]) {
+ case '0' -> '\u2080';
+ case '1' -> '\u2081';
+ case '2' -> '\u2082';
+ case '3' -> '\u2083';
+ case '4' -> '\u2084';
+ case '5' -> '\u2085';
+ case '6' -> '\u2086';
+ case '7' -> '\u2087';
+ case '8' -> '\u2088';
+ case '9' -> '\u2089';
+ default -> chars[i];
+ };
+ }
+ return new String(nu);
+ }
+
+ public static String superscriptNumbers(String b) {
+ char[] chars = b.toCharArray();
+ char[] nu = new char[chars.length];
+ for (int i = 0; i < chars.length; i++) {
+ nu[i] = switch (chars[i]) {
+ case '0' -> '\u2070';
+ case '1' -> '\u2071';
+ case '2' -> '\u00B2';
+ case '3' -> '\u00B3';
+ case '4' -> '\u2074';
+ case '5' -> '\u2075';
+ case '6' -> '\u2076';
+ case '7' -> '\u2077';
+ case '8' -> '\u2078';
+ case '9' -> '\u2079';
+ default -> chars[i];
+ };
+ }
+ return new String(nu);
+ }
+
+ public static String superscriptNumber(Number b) {
+ char[] chars = Long.toString(b.longValue())
+ .toCharArray();
+ char[] nu = new char[chars.length];
+ for (int i = 0; i < chars.length; i++) {
+ nu[i] = switch (chars[i]) {
+ case '0' -> '\u2070';
+ case '1' -> '\u2071';
+ case '2' -> '\u00B2';
+ case '3' -> '\u00B3';
+ case '4' -> '\u2074';
+ case '5' -> '\u2075';
+ case '6' -> '\u2076';
+ case '7' -> '\u2077';
+ case '8' -> '\u2078';
+ case '9' -> '\u2079';
+ default -> chars[i];
+ };
+ }
+ return new String(nu);
+ }
+
+ public static byte specialToByte(int aSpecialValue) {
+ byte special = 0;
+ switch (aSpecialValue) {
+ case LOWGRAVITY:
+ special = 1;
+ break;
+ case CLEANROOM:
+ special = 2;
+ break;
+ case LOWGRAVITY | CLEANROOM:
+ special = 3;
+ break;
+ default:
+ break;
+ }
+ return special;
+ }
+
+ public static int calculateSv(Materials materials) {
+ for (BioVatLogicAdder.MaterialSvPair pair : BioVatLogicAdder.RadioHatch.getMaSv()) {
+ if (pair.getMaterials()
+ .equals(materials)) return pair.getSievert();
+ }
+ return (int) (materials.getProtons() == 43L
+ ? materials.equals(Materials.NaquadahEnriched) ? 140
+ : materials.equals(Materials.Naquadria) ? 150 : materials.equals(Materials.Naquadah) ? 130 : 43
+ : materials.getProtons());
+ }
+
+ public static ItemStack setStackSize(ItemStack stack, int size) {
+ if (stack != null) stack.stackSize = size;
+ return stack;
+ }
+
+ public static boolean checkStackAndPrefix(ItemStack itemStack) {
+ return itemStack != null && GTOreDictUnificator.getAssociation(itemStack) != null
+ && GTOreDictUnificator.getAssociation(itemStack).mPrefix != null
+ && GTOreDictUnificator.getAssociation(itemStack).mMaterial != null
+ && GTOreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial != null;
+ }
+
+ public static int abstractHashGTRecipe(GTRecipe recipe) {
+ int hash = 31;
+ hash += recipe.mDuration / 20 * 31;
+ hash += GTUtility.getTier(recipe.mEUt) * 31;
+ hash += BWUtil.specialToByte(recipe.mSpecialValue) * 31;
+ hash += recipe.mInputs.length * 31;
+ for (ItemStack mInput : recipe.mInputs) {
+ if (mInput != null) {
+ hash += mInput.stackSize * 31;
+ hash += Item.getIdFromItem(mInput.getItem()) * 31;
+ }
+ }
+ hash += recipe.mOutputs.length * 31;
+ for (ItemStack mOutput : recipe.mOutputs) {
+ if (mOutput != null) {
+ hash += mOutput.stackSize * 31;
+ hash += Item.getIdFromItem(mOutput.getItem()) * 31;
+ }
+ }
+ hash += recipe.mFluidInputs.length * 31;
+ for (FluidStack mInput : recipe.mFluidInputs) {
+ if (mInput != null) {
+ hash += mInput.amount * 31;
+ hash += mInput.getFluidID() * 31;
+ }
+ }
+ hash += recipe.mFluidOutputs.length * 31;
+ for (FluidStack mOutput : recipe.mFluidOutputs) {
+ if (mOutput != null) {
+ hash += mOutput.amount * 31;
+ hash += mOutput.getFluidID() * 31;
+ }
+ }
+ return hash;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public static <T> T[] copyAndRemoveNulls(T[] input, Class<T> clazz) {
+ List<T> ret = Arrays.stream(input)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+
+ if (ret.size() <= 0) return (T[]) Array.newInstance(clazz, 0);
+
+ T[] retArr = (T[]) Array.newInstance(clazz, ret.size());
+
+ for (int i = 0; i < ret.size(); i++) retArr[i] = ret.get(i);
+
+ return retArr;
+ }
+
+ @Deprecated
+ public static int getMachineVoltageFromTier(int tier) {
+ return (int) (30 * Math.pow(4, tier - 1));
+ }
+
+ public static long getTierVoltage(int tier) {
+ return getTierVoltage((byte) tier);
+ }
+
+ public static long getTierVoltage(byte tier) {
+ return 8L << 2 * tier;
+ }
+
+ public static byte getTier(long voltage) {
+ if (voltage <= Integer.MAX_VALUE - 7) return GTUtility.getTier(voltage);
+ byte t = 0;
+ while (voltage > 8L) {
+ voltage >>= 2;
+ t++;
+ }
+ return t;
+ }
+
+ public static String getTierName(byte tier) {
+ if (VN.length - 1 <= tier) return "MAX+";
+ return VN[tier];
+ }
+
+ public static String getTierNameFromVoltage(long voltage) {
+ return getTierName(getTier(voltage));
+ }
+
+ public static boolean areStacksEqualOrNull(ItemStack aStack1, ItemStack aStack2) {
+ return aStack1 == null && aStack2 == null || GTUtility.areStacksEqual(aStack1, aStack2);
+ }
+
+ public static boolean areStacksEqualOrEachNull(ItemStack aStack1, ItemStack aStack2) {
+ return aStack1 == null || aStack2 == null || GTUtility.areStacksEqual(aStack1, aStack2);
+ }
+
+ public static byte getByteFromRarity(EnumRarity rarity) {
+ if (EnumRarity.uncommon.equals(rarity)) return 1;
+ if (EnumRarity.epic.equals(rarity)) return 2;
+ else if (EnumRarity.rare.equals(rarity)) return 3;
+ return 0;
+ }
+
+ /**
+ * @deprecated Use stuff in {@link BorosilicateGlass} instead
+ */
+ @Deprecated
+ public static byte getTierFromGlasMeta(int meta) {
+ return switch (meta) {
+ case 1 -> 4;
+ case 2, 12 -> 5;
+ case 3 -> 6;
+ case 4 -> 7;
+ case 5 -> 8;
+ case 13 -> 9;
+ case 14 -> 10;
+ default -> 3;
+ };
+ }
+
+ public static EnumRarity getRarityFromByte(byte b) {
+ return switch (b) {
+ case 1 -> EnumRarity.uncommon;
+ case 2 -> EnumRarity.rare;
+ case 3 -> EnumRarity.epic;
+ default -> EnumRarity.common;
+ };
+ }
+
+ public static byte getCircuitTierFromOreDictName(String name) {
+ return switch (name) {
+ case "circuitPrimitive" -> 0;
+ case "circuitBasic" -> 1;
+ case "circuitGood" -> 2;
+ case "circuitAdvanced" -> 3;
+ case "circuitData" -> 4;
+ case "circuitElite" -> 5;
+ case "circuitMaster" -> 6;
+ case "circuitUltimate" -> 7;
+ case "circuitSuperconductor" -> 8;
+ case "circuitInfinite" -> 9;
+ case "circuitBio" -> 10;
+ case "circuitNano", "circuitOptical" -> 11;
+ case "circuitPiko", "circuitExotic" -> 12;
+ case "circuitQuantum", "circuitCosmic" -> 13;
+ case "circuitTranscendent" -> 14;
+ default -> -1;
+ };
+ }
+
+ public static byte getCircuitTierFromItemStack(ItemStack stack) {
+ for (String oreName : getOreNames(stack)) {
+ byte tier = getCircuitTierFromOreDictName(oreName);
+ if (tier != -1) {
+ return tier;
+ }
+ }
+ return -1;