diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-14 15:19:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-14 15:19:13 +0200 |
commit | 6d436a2c6a5d9b51070b8399c4fdb196603a8e82 (patch) | |
tree | 0ac08abe69626ad89e25eb9b0c7aadb7e5243dac /src/main/java/kubatech/api | |
parent | d8d8a462a25a29a9640f6c038ced50a570255e6e (diff) | |
download | GT5-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')
-rw-r--r-- | src/main/java/kubatech/api/LoaderReference.java | 12 | ||||
-rw-r--r-- | src/main/java/kubatech/api/Variables.java | 26 | ||||
-rw-r--r-- | src/main/java/kubatech/api/enums/ItemList.java | 167 | ||||
-rw-r--r-- | src/main/java/kubatech/api/utils/FastRandom.java | 27 | ||||
-rw-r--r-- | src/main/java/kubatech/api/utils/InfernalHelper.java | 226 | ||||
-rw-r--r-- | src/main/java/kubatech/api/utils/ModUtils.java | 50 | ||||
-rw-r--r-- | src/main/java/kubatech/api/utils/ReflectionHelper.java | 62 |
7 files changed, 570 insertions, 0 deletions
diff --git a/src/main/java/kubatech/api/LoaderReference.java b/src/main/java/kubatech/api/LoaderReference.java new file mode 100644 index 0000000000..aef8930905 --- /dev/null +++ b/src/main/java/kubatech/api/LoaderReference.java @@ -0,0 +1,12 @@ +package kubatech.api; + +import cpw.mods.fml.common.Loader; + +public class LoaderReference { + public static final boolean BloodMagic = Loader.isModLoaded("AWWayofTime"); + public static final boolean EnderIO = Loader.isModLoaded("EnderIO"); + public static final boolean ExtraUtilities = Loader.isModLoaded("ExtraUtilities"); + public static final boolean InfernalMobs = Loader.isModLoaded("InfernalMobs"); + public static final boolean Thaumcraft = Loader.isModLoaded("Thaumcraft"); + public static final boolean MineTweaker = Loader.isModLoaded("MineTweaker3"); +} diff --git a/src/main/java/kubatech/api/Variables.java b/src/main/java/kubatech/api/Variables.java new file mode 100644 index 0000000000..c989b45f6f --- /dev/null +++ b/src/main/java/kubatech/api/Variables.java @@ -0,0 +1,26 @@ +/* + * 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; + +import net.minecraft.util.EnumChatFormatting; + +public class Variables { + public static final String Author = "Author: " + EnumChatFormatting.GOLD + "kuba6000"; +} diff --git a/src/main/java/kubatech/api/enums/ItemList.java b/src/main/java/kubatech/api/enums/ItemList.java new file mode 100644 index 0000000000..b0cf3289b6 --- /dev/null +++ b/src/main/java/kubatech/api/enums/ItemList.java @@ -0,0 +1,167 @@ +package kubatech.api.enums; + +import static gregtech.api.enums.GT_Values.NI; +import static gregtech.api.enums.GT_Values.W; + +import gregtech.api.interfaces.IItemContainer; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import java.util.Locale; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public enum ItemList implements IItemContainer { + ExtremeExterminationChamber; + + private ItemStack mStack; + private boolean mHasNotBeenSet = true; + + @Override + public IItemContainer set(Item aItem) { + mHasNotBeenSet = false; + if (aItem == null) return this; + ItemStack aStack = new ItemStack(aItem, 1, 0); + mStack = GT_Utility.copyAmount(1, aStack); + return this; + } + + @Override + public IItemContainer set(ItemStack aStack) { + mHasNotBeenSet = false; + mStack = GT_Utility.copyAmount(1, aStack); + return this; + } + + @Override + public Item getItem() { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + if (GT_Utility.isStackInvalid(mStack)) return null; + return mStack.getItem(); + } + + @Override + public Block getBlock() { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + return GT_Utility.getBlockFromItem(getItem()); + } + + @Override + public final boolean hasBeenSet() { + return !mHasNotBeenSet; + } + + @Override + public boolean isStackEqual(Object aStack) { + return isStackEqual(aStack, false, false); + } + + @Override + public boolean isStackEqual(Object aStack, boolean aWildcard, boolean aIgnoreNBT) { + if (GT_Utility.isStackInvalid(aStack)) return false; + return GT_Utility.areUnificationsEqual((ItemStack) aStack, aWildcard ? getWildcard(1) : get(1), aIgnoreNBT); + } + + @Override + public ItemStack get(long aAmount, Object... aReplacements) { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements); + return GT_Utility.copyAmount(aAmount, GT_OreDictUnificator.get(mStack)); + } + + @Override + public ItemStack getWildcard(long aAmount, Object... aReplacements) { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements); + return GT_Utility.copyAmountAndMetaData(aAmount, W, GT_OreDictUnificator.get(mStack)); + } + + @Override + public ItemStack getUndamaged(long aAmount, Object... aReplacements) { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements); + return GT_Utility.copyAmountAndMetaData(aAmount, 0, GT_OreDictUnificator.get(mStack)); + } + + @Override + public ItemStack getAlmostBroken(long aAmount, Object... aReplacements) { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements); + return GT_Utility.copyAmountAndMetaData(aAmount, mStack.getMaxDamage() - 1, GT_OreDictUnificator.get(mStack)); + } + + @Override + public ItemStack getWithName(long aAmount, String aDisplayName, Object... aReplacements) { + ItemStack rStack = get(1, aReplacements); + if (GT_Utility.isStackInvalid(rStack)) return NI; + + // CamelCase alphanumeric words from aDisplayName + StringBuilder tCamelCasedDisplayNameBuilder = new StringBuilder(); + final String[] tDisplayNameWords = aDisplayName.split("\\W"); + for (String tWord : tDisplayNameWords) { + if (tWord.length() > 0) + tCamelCasedDisplayNameBuilder.append(tWord.substring(0, 1).toUpperCase(Locale.US)); + if (tWord.length() > 1) + tCamelCasedDisplayNameBuilder.append(tWord.substring(1).toLowerCase(Locale.US)); + } + if (tCamelCasedDisplayNameBuilder.length() == 0) { + // CamelCased DisplayName is empty, so use hash of aDisplayName + tCamelCasedDisplayNameBuilder.append(((Long) (long) aDisplayName.hashCode())); + } + + // Construct a translation key from UnlocalizedName and CamelCased DisplayName + final String tKey = rStack.getUnlocalizedName() + ".with." + tCamelCasedDisplayNameBuilder + ".name"; + + rStack.setStackDisplayName(GT_LanguageManager.addStringLocalization(tKey, aDisplayName)); + return GT_Utility.copyAmount(aAmount, rStack); + } + + @Override + public ItemStack getWithCharge(long aAmount, int aEnergy, Object... aReplacements) { + ItemStack rStack = get(1, aReplacements); + if (GT_Utility.isStackInvalid(rStack)) return null; + GT_ModHandler.chargeElectricItem(rStack, aEnergy, Integer.MAX_VALUE, true, false); + return GT_Utility.copyAmount(aAmount, rStack); + } + + @Override + public ItemStack getWithDamage(long aAmount, long aMetaValue, Object... aReplacements) { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements); + return GT_Utility.copyAmountAndMetaData(aAmount, aMetaValue, GT_OreDictUnificator.get(mStack)); + } + + @Override + public IItemContainer registerOre(Object... aOreNames) { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + for (Object tOreName : aOreNames) GT_OreDictUnificator.registerOre(tOreName, get(1)); + return this; + } + + @Override + public IItemContainer registerWildcardAsOre(Object... aOreNames) { + if (mHasNotBeenSet) + throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!"); + for (Object tOreName : aOreNames) GT_OreDictUnificator.registerOre(tOreName, getWildcard(1)); + return this; + } + + /** + * Returns the internal stack. + * This method is unsafe. It's here only for quick operations. + * DON'T CHANGE THE RETURNED VALUE! + */ + public ItemStack getInternalStack_unsafe() { + return mStack; + } +} 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); + } +} |