aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kubatech/api/utils
diff options
context:
space:
mode:
authorJakub <53441451+kuba6000@users.noreply.github.com>2022-08-14 15:19:13 +0200
committerGitHub <noreply@github.com>2022-08-14 15:19:13 +0200
commit6d436a2c6a5d9b51070b8399c4fdb196603a8e82 (patch)
tree0ac08abe69626ad89e25eb9b0c7aadb7e5243dac /src/main/java/kubatech/api/utils
parentd8d8a462a25a29a9640f6c038ced50a570255e6e (diff)
downloadGT5-Unofficial-6d436a2c6a5d9b51070b8399c4fdb196603a8e82.tar.gz
GT5-Unofficial-6d436a2c6a5d9b51070b8399c4fdb196603a8e82.tar.bz2
GT5-Unofficial-6d436a2c6a5d9b51070b8399c4fdb196603a8e82.zip
Add "Mob Drops" NEI page + Extreme Extermination Chamber (#1)
* First commit * Mixins * Merge the same items with diffrent damage * Faster random in NEI * More accuracy ? * Update ClientProxy.java * Renaming * Update buildscript * Use reserved MTE ID's * EEC work * Rework NEI page * Fix inaccurate chances * Basic equipment spawn * Add config options * Translations * Add infernal drops * Witchery fix * Forestry fixes * More fixes * Default blacklist * NEI sorting * Comment out testing deps * Clientsided check * Blood Magic support * LoaderReference * Check if peacefull is allowed * Add some XP output * Add recipe * Send Server config to Client * Add command to reload config * Translations * Process MT additions
Diffstat (limited to 'src/main/java/kubatech/api/utils')
-rw-r--r--src/main/java/kubatech/api/utils/FastRandom.java27
-rw-r--r--src/main/java/kubatech/api/utils/InfernalHelper.java226
-rw-r--r--src/main/java/kubatech/api/utils/ModUtils.java50
-rw-r--r--src/main/java/kubatech/api/utils/ReflectionHelper.java62
4 files changed, 365 insertions, 0 deletions
diff --git a/src/main/java/kubatech/api/utils/FastRandom.java b/src/main/java/kubatech/api/utils/FastRandom.java
new file mode 100644
index 0000000000..c0fb1ec9d5
--- /dev/null
+++ b/src/main/java/kubatech/api/utils/FastRandom.java
@@ -0,0 +1,27 @@
+package kubatech.api.utils;
+
+import java.util.Random;
+import java.util.SplittableRandom;
+
+public class FastRandom extends Random {
+
+ private SplittableRandom realRandom;
+
+ public FastRandom() {
+ realRandom = new SplittableRandom();
+ }
+
+ public FastRandom(long seed) {
+ realRandom = new SplittableRandom(seed);
+ }
+
+ @Override
+ public synchronized void setSeed(long seed) {
+ realRandom = new SplittableRandom(seed);
+ }
+
+ @Override
+ protected int next(int bits) {
+ return (realRandom.nextInt() >>> (32 - bits));
+ }
+}
diff --git a/src/main/java/kubatech/api/utils/InfernalHelper.java b/src/main/java/kubatech/api/utils/InfernalHelper.java
new file mode 100644
index 0000000000..d4e416e9a5
--- /dev/null
+++ b/src/main/java/kubatech/api/utils/InfernalHelper.java
@@ -0,0 +1,226 @@
+/*
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 kuba6000
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+package kubatech.api.utils;
+
+import atomicstryker.infernalmobs.common.InfernalMobsCore;
+import atomicstryker.infernalmobs.common.mods.api.ModifierLoader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.item.ItemStack;
+
+public class InfernalHelper {
+ private static Method isClassAllowed = null;
+
+ public static boolean isClassAllowed(EntityLivingBase e) {
+ try {
+ if (isClassAllowed == null) {
+ isClassAllowed = InfernalMobsCore.class.getDeclaredMethod("isClassAllowed", EntityLivingBase.class);
+ isClassAllowed.setAccessible(true);
+ }
+ return (boolean) isClassAllowed.invoke(InfernalMobsCore.instance(), e);
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return false;
+ }
+
+ private static Method checkEntityClassForced = null;
+
+ public static boolean checkEntityClassForced(EntityLivingBase e) {
+ try {
+ if (checkEntityClassForced == null) {
+ checkEntityClassForced =
+ InfernalMobsCore.class.getDeclaredMethod("checkEntityClassForced", EntityLivingBase.class);
+ checkEntityClassForced.setAccessible(true);
+ }
+ return (boolean) checkEntityClassForced.invoke(InfernalMobsCore.instance(), e);
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return false;
+ }
+
+ private static Field modifierLoaders = null;
+
+ public static ArrayList<ModifierLoader<?>> getModifierLoaders() {
+ try {
+ if (modifierLoaders == null) {
+ modifierLoaders = InfernalMobsCore.class.getDeclaredField("modifierLoaders");
+ modifierLoaders.setAccessible(true);
+ }
+ return (ArrayList<ModifierLoader<?>>) modifierLoaders.get(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return new ArrayList<>();
+ }
+
+ private static Field eliteRarity;
+
+ public static int getEliteRarity() {
+ try {
+ if (eliteRarity == null) {
+ eliteRarity = InfernalMobsCore.class.getDeclaredField("eliteRarity");
+ eliteRarity.setAccessible(true);
+ }
+ return eliteRarity.getInt(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return 15;
+ }
+
+ private static Field ultraRarity;
+
+ public static int getUltraRarity() {
+ try {
+ if (ultraRarity == null) {
+ ultraRarity = InfernalMobsCore.class.getDeclaredField("ultraRarity");
+ ultraRarity.setAccessible(true);
+ }
+ return ultraRarity.getInt(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return 15;
+ }
+
+ private static Field infernoRarity;
+
+ public static int getInfernoRarity() {
+ try {
+ if (infernoRarity == null) {
+ infernoRarity = InfernalMobsCore.class.getDeclaredField("infernoRarity");
+ infernoRarity.setAccessible(true);
+ }
+ return infernoRarity.getInt(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return 15;
+ }
+
+ private static Field minEliteModifiers;
+
+ public static int getMinEliteModifiers() {
+ try {
+ if (minEliteModifiers == null) {
+ minEliteModifiers = InfernalMobsCore.class.getDeclaredField("minEliteModifiers");
+ minEliteModifiers.setAccessible(true);
+ }
+ return minEliteModifiers.getInt(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return 15;
+ }
+
+ private static Field minUltraModifiers;
+
+ public static int getMinUltraModifiers() {
+ try {
+ if (minUltraModifiers == null) {
+ minUltraModifiers = InfernalMobsCore.class.getDeclaredField("minUltraModifiers");
+ minUltraModifiers.setAccessible(true);
+ }
+ return minUltraModifiers.getInt(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return 15;
+ }
+
+ private static Field minInfernoModifiers;
+
+ public static int getMinInfernoModifiers() {
+ try {
+ if (minInfernoModifiers == null) {
+ minInfernoModifiers = InfernalMobsCore.class.getDeclaredField("minInfernoModifiers");
+ minInfernoModifiers.setAccessible(true);
+ }
+ return minInfernoModifiers.getInt(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return 15;
+ }
+
+ private static Field dimensionBlackList;
+
+ public static ArrayList<Integer> getDimensionBlackList() {
+ try {
+ if (dimensionBlackList == null) {
+ dimensionBlackList = InfernalMobsCore.class.getDeclaredField("dimensionBlackList");
+ dimensionBlackList.setAccessible(true);
+ }
+ return (ArrayList<Integer>) dimensionBlackList.get(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return new ArrayList<>();
+ }
+
+ private static Field dropIdListElite;
+
+ public static ArrayList<ItemStack> getDropIdListElite() {
+ try {
+ if (dropIdListElite == null) {
+ dropIdListElite = InfernalMobsCore.class.getDeclaredField("dropIdListElite");
+ dropIdListElite.setAccessible(true);
+ }
+ return (ArrayList<ItemStack>) dropIdListElite.get(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return new ArrayList<>();
+ }
+
+ private static Field dropIdListUltra;
+
+ public static ArrayList<ItemStack> getDropIdListUltra() {
+ try {
+ if (dropIdListUltra == null) {
+ dropIdListUltra = InfernalMobsCore.class.getDeclaredField("dropIdListUltra");
+ dropIdListUltra.setAccessible(true);
+ }
+ return (ArrayList<ItemStack>) dropIdListUltra.get(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return new ArrayList<>();
+ }
+
+ private static Field dropIdListInfernal;
+
+ public static ArrayList<ItemStack> getDropIdListInfernal() {
+ try {
+ if (dropIdListInfernal == null) {
+ dropIdListInfernal = InfernalMobsCore.class.getDeclaredField("dropIdListInfernal");
+ dropIdListInfernal.setAccessible(true);
+ }
+ return (ArrayList<ItemStack>) dropIdListInfernal.get(InfernalMobsCore.instance());
+ } catch (Throwable exception) {
+ exception.printStackTrace();
+ }
+ return new ArrayList<>();
+ }
+}
diff --git a/src/main/java/kubatech/api/utils/ModUtils.java b/src/main/java/kubatech/api/utils/ModUtils.java
new file mode 100644
index 0000000000..0802294974
--- /dev/null
+++ b/src/main/java/kubatech/api/utils/ModUtils.java
@@ -0,0 +1,50 @@
+/*
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 kuba6000
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+package kubatech.api.utils;
+
+import cpw.mods.fml.common.Loader;
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.Map;
+import net.minecraft.launchwrapper.Launch;
+
+public class ModUtils {
+ public static final boolean isDeobfuscatedEnvironment =
+ (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
+ public static boolean isClientSided = false;
+ private static final HashMap<String, String> classNamesToModIDs = new HashMap<>();
+ private static final Map.Entry<String, String> emptyEntry = new AbstractMap.SimpleEntry<>("", "");
+
+ public static String getModNameFromClassName(String classname) {
+ if (classNamesToModIDs.size() == 0) {
+ classNamesToModIDs.put("net.minecraft", "Minecraft");
+ Loader.instance().getActiveModList().forEach(m -> {
+ Object Mod = m.getMod();
+ if (Mod != null)
+ classNamesToModIDs.put(Mod.getClass().getPackage().getName(), m.getName());
+ });
+ }
+ return classNamesToModIDs.entrySet().stream()
+ .filter(e -> classname.startsWith(e.getKey()))
+ .findAny()
+ .orElse(emptyEntry)
+ .getValue();
+ }
+}
diff --git a/src/main/java/kubatech/api/utils/ReflectionHelper.java b/src/main/java/kubatech/api/utils/ReflectionHelper.java
new file mode 100644
index 0000000000..0e5d40e245
--- /dev/null
+++ b/src/main/java/kubatech/api/utils/ReflectionHelper.java
@@ -0,0 +1,62 @@
+/*
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 kuba6000
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+package kubatech.api.utils;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+
+public class ReflectionHelper {
+ private static final HashMap<String, HashMap<String, Field>> fields = new HashMap<>();
+
+ public static <T> T getField(Object obj, String fieldName, boolean useBasicTypes, T defaultvalue) {
+ Class<?> cl = obj.getClass();
+ String clName = cl.getName();
+ HashMap<String, Field> classmap = fields.computeIfAbsent(clName, s -> new HashMap<>());
+ try {
+ if (classmap.containsKey(fieldName)) {
+ return (T) classmap.get(fieldName).get(obj);
+ }
+ boolean exceptionDetected = false;
+ Field f = null;
+ do {
+ try {
+ f = cl.getDeclaredField(fieldName);
+ f.setAccessible(true);
+ } catch (Exception ex) {
+ exceptionDetected = true;
+ cl = cl.getSuperclass();
+ }
+ } while (exceptionDetected && !cl.equals(Object.class));
+ if (f == null) return defaultvalue;
+ classmap.put(fieldName, f);
+ return (T) f.get(obj);
+ } catch (Exception ex) {
+ return defaultvalue;
+ }
+ }
+
+ public static <T> T getField(Object obj, String fieldName, boolean useBasicTypes) {
+ return getField(obj, fieldName, useBasicTypes, null);
+ }
+
+ public static <T> T getField(Object obj, String fieldName) {
+ return getField(obj, fieldName, true, null);
+ }
+}