aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-07-31 14:05:08 +0200
committerGitHub <noreply@github.com>2022-07-31 14:05:08 +0200
commitd15348fe2682af83a253198af1925309224dfe8c (patch)
tree44e8d883645503401d21132ee4266d93225c0500 /src/main/java/io
parent872c522def2a301ac09c0e784dc640ba023c26a1 (diff)
downloadNotEnoughUpdates-d15348fe2682af83a253198af1925309224dfe8c.tar.gz
NotEnoughUpdates-d15348fe2682af83a253198af1925309224dfe8c.tar.bz2
NotEnoughUpdates-d15348fe2682af83a253198af1925309224dfe8c.zip
Support for older skytils versions (#199)
* rarity coloring support for older skytils versions * fixed hiding stack trace when skytils is not found (only showing when refactor logic itself fails)
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java64
1 files changed, 39 insertions, 25 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java
index 97c11fe2..f0cb5732 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java
@@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
public class SkytilsCompat {
// Defer static initialization
@@ -45,34 +46,47 @@ public class SkytilsCompat {
static Method skytilsGetShowItemRarity = null;
static {
- try {
- skytilsClass = Class.forName("gg.skytils.skytilsmod.Skytils");
- isSkytilsPresent = true;
- } catch (ClassNotFoundException ignored) {
+ Exception exception = null;
+ for (String packageStart : Arrays.asList("gg.skytils", "skytils")) {
+ isSkytilsPresent = false;
+ try {
+ skytilsClass = Class.forName(packageStart + ".skytilsmod.Skytils");
+ isSkytilsPresent = true;
+ } catch (ClassNotFoundException ignored) {
+ }
+
+ if (isSkytilsPresent) {
+ try {
+ Class<?> skytilsCompanionClass = Class.forName(packageStart + ".skytilsmod.Skytils$Companion");
+ skytilsConfigClass = Class.forName(packageStart + ".skytilsmod.core.Config");
+ Field skytilsCompanionField = skytilsClass.getField("Companion");
+ skytilsCompanionObject = skytilsCompanionField.get(null);
+ Method skytilsGetConfigMethod = skytilsCompanionClass.getMethod("getConfig");
+ skytilsConfigObject = skytilsGetConfigMethod.invoke(skytilsCompanionObject);
+ skytilsGetShowItemRarity = skytilsConfigClass.getMethod("getShowItemRarity");
+ renderUtilClass = Class.forName(packageStart + ".skytilsmod.utils.RenderUtil");
+ renderRarityMethod = renderUtilClass.getDeclaredMethod(
+ "renderRarity",
+ ItemStack.class,
+ Integer.TYPE,
+ Integer.TYPE
+ );
+ isSkytilsFullyPresent = true;
+ break;
+ } catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException |
+ InvocationTargetException e) {
+ exception = e;
+ }
+ }
}
- try {
- Class<?> skytilsCompanionClass = Class.forName("gg.skytils.skytilsmod.Skytils$Companion");
- skytilsConfigClass = Class.forName("gg.skytils.skytilsmod.core.Config");
- Field skytilsCompanionField = skytilsClass.getField("Companion");
- skytilsCompanionObject = skytilsCompanionField.get(null);
- Method skytilsGetConfigMethod = skytilsCompanionClass.getMethod("getConfig");
- skytilsConfigObject = skytilsGetConfigMethod.invoke(skytilsCompanionObject);
- skytilsGetShowItemRarity = skytilsConfigClass.getMethod("getShowItemRarity");
- renderUtilClass = Class.forName("gg.skytils.skytilsmod.utils.RenderUtil");
- renderRarityMethod = renderUtilClass.getDeclaredMethod(
- "renderRarity",
- ItemStack.class,
- Integer.TYPE,
- Integer.TYPE
- );
- isSkytilsFullyPresent = true;
- } catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException |
- InvocationTargetException e) {
- System.err.println("Failed to get Skytils class even tho Skytils mod is present. This is (probably) a NEU bug");
- e.printStackTrace();
+
+ if (!isSkytilsFullyPresent) {
+ if (exception != null) {
+ System.err.println("Failed to get Skytils class even tho Skytils mod is present. This is (probably) a NEU bug");
+ exception.printStackTrace();
+ }
}
}
-
}
public static boolean isSkytilsFullyLoaded() {