aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java
diff options
context:
space:
mode:
authorRoman / Nea <roman.graef@gmail.com>2022-04-18 17:33:32 +0200
committerGitHub <noreply@github.com>2022-04-18 17:33:32 +0200
commit2692193e54e4dd6c0117dcdb85368dc83bb04f1a (patch)
tree96f01454c404ac04a46ea0d9bf684c7dc5619a57 /src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java
parent9fe86ccb4d30b78826e513a6576027ca6e4c1600 (diff)
downloadnotenoughupdates-2692193e54e4dd6c0117dcdb85368dc83bb04f1a.tar.gz
notenoughupdates-2692193e54e4dd6c0117dcdb85368dc83bb04f1a.tar.bz2
notenoughupdates-2692193e54e4dd6c0117dcdb85368dc83bb04f1a.zip
Mob loot recipe PR (#81)
* entity renderer (somewhat functionaL) * more modifiers and entities * Fix cookie fuckup * add neu repo as resource pack, cause why not at this point * add tabs, because i can * add extra skin parts and make less tabs * hot tall men * fix texture offsets and also parts:true * some untested changes * still broken, but better (just like me (stop being edgy nea ( no u )))) * stuff (with er skeletons * niceities * skytils interop * horseys * horseys ouch * panos * stupid tests :angery: * NPE * add drop chance * colored leather armo * finish off * move shit into hover cause items look pretty terrible * Update 2.1.md * better recipe display name * always show mobs toggle * moving parts
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java82
1 files changed, 82 insertions, 0 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
new file mode 100644
index 00000000..193f6133
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SkytilsCompat.java
@@ -0,0 +1,82 @@
+package io.github.moulberry.notenoughupdates.util;
+
+import net.minecraft.item.ItemStack;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+
+public class SkytilsCompat {
+ // Defer static initialization
+ private static class Holder {
+ // Skytils is present in some capacity
+ static boolean isSkytilsPresent = false;
+ // All classes successfully loaded
+ static boolean isSkytilsFullyPresent = false;
+
+ static Class<?> skytilsClass = null;
+ static Method renderRarityMethod = null;
+ static Class<?> renderUtilClass = null;
+
+ static Object skytilsCompanionObject = null;
+
+ static Class<?> skytilsConfigClass = null;
+
+ static Object skytilsConfigObject = null;
+ static Method skytilsGetShowItemRarity = null;
+
+ static {
+ try {
+ skytilsClass = Class.forName("skytils.skytilsmod.Skytils");
+ isSkytilsPresent = true;
+ } catch (ClassNotFoundException ignored) {
+ }
+ try {
+ Class<?> skytilsCompanionClass = Class.forName("skytils.skytilsmod.Skytils$Companion");
+ skytilsConfigClass = Class.forName("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("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();
+ }
+ }
+
+ }
+
+ public static boolean isSkytilsFullyLoaded() {
+ return Holder.isSkytilsFullyPresent;
+ }
+
+ public static boolean isSkytilsPresent() {
+ return Holder.isSkytilsPresent;
+ }
+ public static void renderSkytilsRarity(ItemStack stack, int x, int y) {
+ renderSkytilsRarity(stack, x, y, false);
+ }
+
+ public static void renderSkytilsRarity(ItemStack stack, int x, int y, boolean force) {
+ if (Holder.isSkytilsFullyPresent) {
+ try {
+ if (force || (boolean) Holder.skytilsGetShowItemRarity.invoke(Holder.skytilsConfigObject))
+ Holder.renderRarityMethod.invoke(null, stack, x, y);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+}