From 6d436a2c6a5d9b51070b8399c4fdb196603a8e82 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Sun, 14 Aug 2022 15:19:13 +0200 Subject: 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 --- src/main/java/kubatech/api/LoaderReference.java | 12 ++ src/main/java/kubatech/api/Variables.java | 26 +++ src/main/java/kubatech/api/enums/ItemList.java | 167 +++++++++++++++ src/main/java/kubatech/api/utils/FastRandom.java | 27 +++ .../java/kubatech/api/utils/InfernalHelper.java | 226 +++++++++++++++++++++ src/main/java/kubatech/api/utils/ModUtils.java | 50 +++++ .../java/kubatech/api/utils/ReflectionHelper.java | 62 ++++++ 7 files changed, 570 insertions(+) create mode 100644 src/main/java/kubatech/api/LoaderReference.java create mode 100644 src/main/java/kubatech/api/Variables.java create mode 100644 src/main/java/kubatech/api/enums/ItemList.java create mode 100644 src/main/java/kubatech/api/utils/FastRandom.java create mode 100644 src/main/java/kubatech/api/utils/InfernalHelper.java create mode 100644 src/main/java/kubatech/api/utils/ModUtils.java create mode 100644 src/main/java/kubatech/api/utils/ReflectionHelper.java (limited to 'src/main/java/kubatech/api') 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 . + * + */ + +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 . + * + */ + +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> getModifierLoaders() { + try { + if (modifierLoaders == null) { + modifierLoaders = InfernalMobsCore.class.getDeclaredField("modifierLoaders"); + modifierLoaders.setAccessible(true); + } + return (ArrayList>) 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 getDimensionBlackList() { + try { + if (dimensionBlackList == null) { + dimensionBlackList = InfernalMobsCore.class.getDeclaredField("dimensionBlackList"); + dimensionBlackList.setAccessible(true); + } + return (ArrayList) dimensionBlackList.get(InfernalMobsCore.instance()); + } catch (Throwable exception) { + exception.printStackTrace(); + } + return new ArrayList<>(); + } + + private static Field dropIdListElite; + + public static ArrayList getDropIdListElite() { + try { + if (dropIdListElite == null) { + dropIdListElite = InfernalMobsCore.class.getDeclaredField("dropIdListElite"); + dropIdListElite.setAccessible(true); + } + return (ArrayList) dropIdListElite.get(InfernalMobsCore.instance()); + } catch (Throwable exception) { + exception.printStackTrace(); + } + return new ArrayList<>(); + } + + private static Field dropIdListUltra; + + public static ArrayList getDropIdListUltra() { + try { + if (dropIdListUltra == null) { + dropIdListUltra = InfernalMobsCore.class.getDeclaredField("dropIdListUltra"); + dropIdListUltra.setAccessible(true); + } + return (ArrayList) dropIdListUltra.get(InfernalMobsCore.instance()); + } catch (Throwable exception) { + exception.printStackTrace(); + } + return new ArrayList<>(); + } + + private static Field dropIdListInfernal; + + public static ArrayList getDropIdListInfernal() { + try { + if (dropIdListInfernal == null) { + dropIdListInfernal = InfernalMobsCore.class.getDeclaredField("dropIdListInfernal"); + dropIdListInfernal.setAccessible(true); + } + return (ArrayList) 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 . + * + */ + +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 classNamesToModIDs = new HashMap<>(); + private static final Map.Entry 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 . + * + */ + +package kubatech.api.utils; + +import java.lang.reflect.Field; +import java.util.HashMap; + +public class ReflectionHelper { + private static final HashMap> fields = new HashMap<>(); + + public static T getField(Object obj, String fieldName, boolean useBasicTypes, T defaultvalue) { + Class cl = obj.getClass(); + String clName = cl.getName(); + HashMap 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 getField(Object obj, String fieldName, boolean useBasicTypes) { + return getField(obj, fieldName, useBasicTypes, null); + } + + public static T getField(Object obj, String fieldName) { + return getField(obj, fieldName, true, null); + } +} -- cgit From 4ad580a05e475a912ff9964cdd09d5ff666b98e8 Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Sun, 14 Aug 2022 21:46:59 +0200 Subject: LGPL 3.0 --- src/main/java/kubatech/api/Variables.java | 18 +++++++++--------- src/main/java/kubatech/api/utils/InfernalHelper.java | 18 +++++++++--------- src/main/java/kubatech/api/utils/ModUtils.java | 18 +++++++++--------- src/main/java/kubatech/api/utils/ReflectionHelper.java | 18 +++++++++--------- 4 files changed, 36 insertions(+), 36 deletions(-) (limited to 'src/main/java/kubatech/api') diff --git a/src/main/java/kubatech/api/Variables.java b/src/main/java/kubatech/api/Variables.java index c989b45f6f..9dba10f6a6 100644 --- a/src/main/java/kubatech/api/Variables.java +++ b/src/main/java/kubatech/api/Variables.java @@ -2,18 +2,18 @@ * 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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 . + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . * */ diff --git a/src/main/java/kubatech/api/utils/InfernalHelper.java b/src/main/java/kubatech/api/utils/InfernalHelper.java index d4e416e9a5..60263b0a17 100644 --- a/src/main/java/kubatech/api/utils/InfernalHelper.java +++ b/src/main/java/kubatech/api/utils/InfernalHelper.java @@ -2,18 +2,18 @@ * 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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 . + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . * */ diff --git a/src/main/java/kubatech/api/utils/ModUtils.java b/src/main/java/kubatech/api/utils/ModUtils.java index 0802294974..0f598dcfa8 100644 --- a/src/main/java/kubatech/api/utils/ModUtils.java +++ b/src/main/java/kubatech/api/utils/ModUtils.java @@ -2,18 +2,18 @@ * 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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 . + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . * */ diff --git a/src/main/java/kubatech/api/utils/ReflectionHelper.java b/src/main/java/kubatech/api/utils/ReflectionHelper.java index 0e5d40e245..7c7301c1c8 100644 --- a/src/main/java/kubatech/api/utils/ReflectionHelper.java +++ b/src/main/java/kubatech/api/utils/ReflectionHelper.java @@ -2,18 +2,18 @@ * 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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 . + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . * */ -- cgit From 76a2834cedfa4f3916d07e2893fc54121268489e Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Wed, 17 Aug 2022 05:01:16 +0200 Subject: Structure --- src/main/java/kubatech/api/LoaderReference.java | 1 + .../api/network/CustomTileEntityPacket.java | 119 +++++++++++++++++++++ .../kubatech/api/network/LoadConfigPacket.java | 74 +++++++++++++ .../tileentity/CustomTileEntityPacketHandler.java | 7 ++ .../java/kubatech/api/utils/InfernalHelper.java | 1 + src/main/java/kubatech/api/utils/MobUtils.java | 57 ++++++++++ .../java/kubatech/api/utils/ReflectionHelper.java | 9 +- 7 files changed, 262 insertions(+), 6 deletions(-) create mode 100644 src/main/java/kubatech/api/network/CustomTileEntityPacket.java create mode 100644 src/main/java/kubatech/api/network/LoadConfigPacket.java create mode 100644 src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java create mode 100644 src/main/java/kubatech/api/utils/MobUtils.java (limited to 'src/main/java/kubatech/api') diff --git a/src/main/java/kubatech/api/LoaderReference.java b/src/main/java/kubatech/api/LoaderReference.java index aef8930905..418fe4a7ab 100644 --- a/src/main/java/kubatech/api/LoaderReference.java +++ b/src/main/java/kubatech/api/LoaderReference.java @@ -9,4 +9,5 @@ public class LoaderReference { public static final boolean InfernalMobs = Loader.isModLoaded("InfernalMobs"); public static final boolean Thaumcraft = Loader.isModLoaded("Thaumcraft"); public static final boolean MineTweaker = Loader.isModLoaded("MineTweaker3"); + public static final boolean Bartworks = Loader.isModLoaded("bartworks"); } diff --git a/src/main/java/kubatech/api/network/CustomTileEntityPacket.java b/src/main/java/kubatech/api/network/CustomTileEntityPacket.java new file mode 100644 index 0000000000..9236594647 --- /dev/null +++ b/src/main/java/kubatech/api/network/CustomTileEntityPacket.java @@ -0,0 +1,119 @@ +package kubatech.api.network; + +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.nio.charset.StandardCharsets; +import kubatech.api.tileentity.CustomTileEntityPacketHandler; +import kubatech.api.utils.ModUtils; +import kubatech.kubatech; +import net.minecraft.client.Minecraft; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class CustomTileEntityPacket implements IMessage { + public int w, x, y, z; + public ByteBuf customdata = Unpooled.buffer(); + + @SuppressWarnings("unused") + public CustomTileEntityPacket() {} + + public CustomTileEntityPacket(TileEntity te, byte[] customdata) { + this.w = te.getWorldObj().provider.dimensionId; + this.x = te.xCoord; + this.y = te.yCoord; + this.z = te.zCoord; + if (customdata != null && customdata.length > 0) this.customdata.writeBytes(customdata); + } + + public void sendToAllAround(int range) { + kubatech.NETWORK.sendToAllAround(this, new NetworkRegistry.TargetPoint(w, x, y, z, range)); + } + + // Helper methods + + public void resetHelperData() { + customdata.clear(); + } + + public void addData(byte[] data) { + customdata.writeBytes(data); + } + + public void addData(byte data) { + customdata.writeByte(data); + } + + public void addData(int data) { + customdata.writeInt(data); + } + + public void addData(String data) { + byte[] bytes = data.getBytes(StandardCharsets.UTF_8); + addData(bytes.length); + addData(bytes); + } + + public void getData(byte[] bytes) { + customdata.readBytes(bytes); + } + + public byte[] getData(int len) { + byte[] bytes = new byte[len]; + getData(bytes); + return bytes; + } + + public int getDataInt() { + return customdata.readInt(); + } + + public String getDataString() { + return new String(getData(getDataInt()), StandardCharsets.UTF_8); + } + + @Override + public void fromBytes(ByteBuf buf) { + w = buf.readInt(); + x = buf.readInt(); + y = buf.readInt(); + z = buf.readInt(); + customdata.clear(); + buf.readBytes(customdata, buf.readInt()); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(w); + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + buf.writeInt(customdata.readableBytes()); + buf.writeBytes(customdata); + } + + public static class Handler implements IMessageHandler { + @Override + public IMessage onMessage(CustomTileEntityPacket message, MessageContext ctx) { + if (!ModUtils.isClientSided) return null; + World w = Minecraft.getMinecraft().thePlayer.getEntityWorld(); + if (message.w != w.provider.dimensionId) return null; + TileEntity e = w.getTileEntity(message.x, message.y, message.z); + if (e == null || e.isInvalid()) return null; + if (e instanceof IGregTechTileEntity && !((IGregTechTileEntity) e).isInvalidTileEntity()) { + IMetaTileEntity mte = ((IGregTechTileEntity) e).getMetaTileEntity(); + if (mte == null) return null; + if (!(mte instanceof CustomTileEntityPacketHandler)) return null; + ((CustomTileEntityPacketHandler) mte).HandleCustomPacket(message); + return null; + } else if (!(e instanceof CustomTileEntityPacketHandler)) return null; + ((CustomTileEntityPacketHandler) e).HandleCustomPacket(message); + return null; + } + } +} diff --git a/src/main/java/kubatech/api/network/LoadConfigPacket.java b/src/main/java/kubatech/api/network/LoadConfigPacket.java new file mode 100644 index 0000000000..f38293642e --- /dev/null +++ b/src/main/java/kubatech/api/network/LoadConfigPacket.java @@ -0,0 +1,74 @@ +/* + * KubaTech - Gregtech Addon + * Copyright (C) 2022 kuba6000 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + * + */ + +package kubatech.api.network; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import java.nio.charset.StandardCharsets; +import java.util.HashSet; +import kubatech.Config; +import kubatech.kubatech; +import kubatech.loaders.MobRecipeLoader; + +public class LoadConfigPacket implements IMessage { + + public static final LoadConfigPacket instance = new LoadConfigPacket(); + + public final HashSet mobsToLoad = new HashSet<>(); + + @Override + public void fromBytes(ByteBuf buf) { + if (!buf.readBoolean()) mobsToLoad.clear(); + else { + mobsToLoad.clear(); + int mobssize = buf.readInt(); + for (int i = 0; i < mobssize; i++) { + byte[] sbytes = new byte[buf.readInt()]; + buf.readBytes(sbytes); + mobsToLoad.add(new String(sbytes, StandardCharsets.UTF_8)); + } + } + } + + @Override + public void toBytes(ByteBuf buf) { + if (!Config.mobHandlerEnabled) buf.writeBoolean(false); + else { + buf.writeBoolean(true); + buf.writeInt(mobsToLoad.size()); + mobsToLoad.forEach(s -> { + byte[] sbytes = s.getBytes(StandardCharsets.UTF_8); + buf.writeInt(sbytes.length); + buf.writeBytes(sbytes); + }); + } + } + + public static class Handler implements IMessageHandler { + @Override + public IMessage onMessage(LoadConfigPacket message, MessageContext ctx) { + kubatech.info("Received Mob Handler config, parsing"); + MobRecipeLoader.processMobRecipeMap(message.mobsToLoad); + return null; + } + } +} diff --git a/src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java b/src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java new file mode 100644 index 0000000000..643ca70d0f --- /dev/null +++ b/src/main/java/kubatech/api/tileentity/CustomTileEntityPacketHandler.java @@ -0,0 +1,7 @@ +package kubatech.api.tileentity; + +import kubatech.api.network.CustomTileEntityPacket; + +public interface CustomTileEntityPacketHandler { + void HandleCustomPacket(CustomTileEntityPacket customdata); +} diff --git a/src/main/java/kubatech/api/utils/InfernalHelper.java b/src/main/java/kubatech/api/utils/InfernalHelper.java index 60263b0a17..4bd48274f3 100644 --- a/src/main/java/kubatech/api/utils/InfernalHelper.java +++ b/src/main/java/kubatech/api/utils/InfernalHelper.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +@SuppressWarnings("unchecked") public class InfernalHelper { private static Method isClassAllowed = null; diff --git a/src/main/java/kubatech/api/utils/MobUtils.java b/src/main/java/kubatech/api/utils/MobUtils.java new file mode 100644 index 0000000000..3e20adac1c --- /dev/null +++ b/src/main/java/kubatech/api/utils/MobUtils.java @@ -0,0 +1,57 @@ +package kubatech.api.utils; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.lang.reflect.Field; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelBox; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.entity.RendererLivingEntity; +import net.minecraft.entity.EntityLiving; + +public class MobUtils { + + private static Field mainmodelfield = null; + + @SideOnly(Side.CLIENT) + public static float getDesiredScale(EntityLiving e, float desiredHeight) { + try { + if (mainmodelfield == null) { + mainmodelfield = RendererLivingEntity.class.getDeclaredField( + ModUtils.isDeobfuscatedEnvironment ? "mainModel" : "field_77045_g"); + mainmodelfield.setAccessible(true); + } + float eheight = e.height; + float ewidth = e.width; + Render r = RenderManager.instance.getEntityRenderObject(e); + if (r instanceof RendererLivingEntity && mainmodelfield != null) { + ModelBase mainmodel = (ModelBase) mainmodelfield.get(r); + for (Object box : mainmodel.boxList) { + if (box instanceof ModelRenderer) { + float minY = 999f; + float minX = 999f; + float maxY = -999f; + float maxX = -999f; + for (Object cube : ((ModelRenderer) box).cubeList) { + if (cube instanceof ModelBox) { + if (minY > ((ModelBox) cube).posY1) minY = ((ModelBox) cube).posY1; + if (minX > ((ModelBox) cube).posX1) minX = ((ModelBox) cube).posX1; + if (maxY < ((ModelBox) cube).posY2) maxY = ((ModelBox) cube).posY2; + if (maxX < ((ModelBox) cube).posX2) maxX = ((ModelBox) cube).posX2; + } + } + float cubeheight = (maxY - minY) / 10f; + float cubewidth = (maxX - minX) / 10f; + if (eheight < cubeheight) eheight = cubeheight; + if (ewidth < cubewidth) ewidth = cubewidth; + } + } + } + return desiredHeight / eheight; + } catch (Exception ex) { + return 1f; + } + } +} diff --git a/src/main/java/kubatech/api/utils/ReflectionHelper.java b/src/main/java/kubatech/api/utils/ReflectionHelper.java index 7c7301c1c8..48d07c6eee 100644 --- a/src/main/java/kubatech/api/utils/ReflectionHelper.java +++ b/src/main/java/kubatech/api/utils/ReflectionHelper.java @@ -25,7 +25,8 @@ import java.util.HashMap; public class ReflectionHelper { private static final HashMap> fields = new HashMap<>(); - public static T getField(Object obj, String fieldName, boolean useBasicTypes, T defaultvalue) { + @SuppressWarnings("unchecked") + public static T getField(Object obj, String fieldName, T defaultvalue) { Class cl = obj.getClass(); String clName = cl.getName(); HashMap classmap = fields.computeIfAbsent(clName, s -> new HashMap<>()); @@ -52,11 +53,7 @@ public class ReflectionHelper { } } - public static T getField(Object obj, String fieldName, boolean useBasicTypes) { - return getField(obj, fieldName, useBasicTypes, null); - } - public static T getField(Object obj, String fieldName) { - return getField(obj, fieldName, true, null); + return getField(obj, fieldName, null); } } -- cgit From a78966a1dd5c638cdb27a7bddf009cd4cec51758 Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Wed, 17 Aug 2022 20:26:14 +0200 Subject: Glass is optional --- .../java/kubatech/api/network/CustomTileEntityPacket.java | 8 ++++++++ src/main/java/kubatech/api/utils/MobUtils.java | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/main/java/kubatech/api') diff --git a/src/main/java/kubatech/api/network/CustomTileEntityPacket.java b/src/main/java/kubatech/api/network/CustomTileEntityPacket.java index 9236594647..cd7bfd3389 100644 --- a/src/main/java/kubatech/api/network/CustomTileEntityPacket.java +++ b/src/main/java/kubatech/api/network/CustomTileEntityPacket.java @@ -59,6 +59,10 @@ public class CustomTileEntityPacket implements IMessage { addData(bytes); } + public void addData(boolean data) { + customdata.writeBoolean(data); + } + public void getData(byte[] bytes) { customdata.readBytes(bytes); } @@ -77,6 +81,10 @@ public class CustomTileEntityPacket implements IMessage { return new String(getData(getDataInt()), StandardCharsets.UTF_8); } + public boolean getDataBoolean() { + return customdata.readBoolean(); + } + @Override public void fromBytes(ByteBuf buf) { w = buf.readInt(); diff --git a/src/main/java/kubatech/api/utils/MobUtils.java b/src/main/java/kubatech/api/utils/MobUtils.java index 3e20adac1c..0b20364484 100644 --- a/src/main/java/kubatech/api/utils/MobUtils.java +++ b/src/main/java/kubatech/api/utils/MobUtils.java @@ -17,6 +17,16 @@ public class MobUtils { @SideOnly(Side.CLIENT) public static float getDesiredScale(EntityLiving e, float desiredHeight) { + return getDesiredScale(getMobHeight(e), desiredHeight); + } + + @SideOnly(Side.CLIENT) + public static float getDesiredScale(float entityHeight, float desiredHeight) { + return desiredHeight / entityHeight; + } + + @SideOnly(Side.CLIENT) + public static float getMobHeight(EntityLiving e) { try { if (mainmodelfield == null) { mainmodelfield = RendererLivingEntity.class.getDeclaredField( @@ -49,7 +59,7 @@ public class MobUtils { } } } - return desiredHeight / eheight; + return eheight; } catch (Exception ex) { return 1f; } -- cgit From 243045a91ef156d83c534ab4f4a7bef1b6029f98 Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Wed, 17 Aug 2022 21:00:04 +0200 Subject: Glass is not optional, you can disable animations with soldering iron --- src/main/java/kubatech/api/Variables.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main/java/kubatech/api') diff --git a/src/main/java/kubatech/api/Variables.java b/src/main/java/kubatech/api/Variables.java index 9dba10f6a6..c8d551a44e 100644 --- a/src/main/java/kubatech/api/Variables.java +++ b/src/main/java/kubatech/api/Variables.java @@ -23,4 +23,8 @@ import net.minecraft.util.EnumChatFormatting; public class Variables { public static final String Author = "Author: " + EnumChatFormatting.GOLD + "kuba6000"; + public static final String StructureHologram = + "To see the structure, use a " + EnumChatFormatting.BLUE + "Tec" + EnumChatFormatting.DARK_BLUE + "Tech" + + EnumChatFormatting.RESET + "" + EnumChatFormatting.GRAY + " Blueprint on the Controller!"; + ; } -- cgit From 01d91c0acd0e8b494578d63683088e6f1d67509f Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Thu, 18 Aug 2022 00:12:14 +0200 Subject: Cache Mob Handler map --- src/main/java/kubatech/api/utils/GSONUtils.java | 70 +++++++++++++++++++++++++ src/main/java/kubatech/api/utils/ModUtils.java | 29 ++++++++-- 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 src/main/java/kubatech/api/utils/GSONUtils.java (limited to 'src/main/java/kubatech/api') diff --git a/src/main/java/kubatech/api/utils/GSONUtils.java b/src/main/java/kubatech/api/utils/GSONUtils.java new file mode 100644 index 0000000000..1c0e7ec3f4 --- /dev/null +++ b/src/main/java/kubatech/api/utils/GSONUtils.java @@ -0,0 +1,70 @@ +package kubatech.api.utils; + +import com.google.gson.*; +import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Type; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTSizeTracker; +import net.minecraft.nbt.NBTTagCompound; + +public class GSONUtils { + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.FIELD) + public @interface SkipGSON {} + + private static final ExclusionStrategy GSONStrategy = new ExclusionStrategy() { + @Override + public boolean shouldSkipField(FieldAttributes f) { + return f.getAnnotation(SkipGSON.class) != null; + } + + @Override + public boolean shouldSkipClass(Class clazz) { + return false; + } + }; + + private static final JsonSerializer NBTTagCompoundSerializer = + new JsonSerializer() { + + @Override + public JsonElement serialize(NBTTagCompound src, Type typeOfSrc, JsonSerializationContext context) { + try { + JsonArray array = new JsonArray(); + for (byte b : CompressedStreamTools.compress(src)) { + array.add(new JsonPrimitive(b)); + } + return array; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; + + private static final JsonDeserializer NBTTagCompoundDeserializer = + new JsonDeserializer() { + @Override + public NBTTagCompound deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + try { + if (!(json instanceof JsonArray)) return null; + byte[] bytes = new byte[((JsonArray) json).size()]; + for (int i = 0; i < bytes.length; i++) + bytes[i] = ((JsonArray) json).get(i).getAsByte(); + return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; + + public static final GsonBuilder GSON_BUILDER = new GsonBuilder() + .addSerializationExclusionStrategy(GSONStrategy) + .addDeserializationExclusionStrategy(GSONStrategy) + .registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundDeserializer) + .registerTypeAdapter(NBTTagCompound.class, NBTTagCompoundSerializer); +} diff --git a/src/main/java/kubatech/api/utils/ModUtils.java b/src/main/java/kubatech/api/utils/ModUtils.java index 0f598dcfa8..447796ddbf 100644 --- a/src/main/java/kubatech/api/utils/ModUtils.java +++ b/src/main/java/kubatech/api/utils/ModUtils.java @@ -20,9 +20,11 @@ package kubatech.api.utils; import cpw.mods.fml.common.Loader; -import java.util.AbstractMap; -import java.util.HashMap; -import java.util.Map; +import cpw.mods.fml.common.ModContainer; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.util.*; +import javax.xml.bind.DatatypeConverter; import net.minecraft.launchwrapper.Launch; public class ModUtils { @@ -47,4 +49,25 @@ public class ModUtils { .orElse(emptyEntry) .getValue(); } + + private static String modListVersion = null; + + public static String getModListVersion() { + if (modListVersion != null) return modListVersion; + ArrayList modlist = (ArrayList) + ((ArrayList) Loader.instance().getActiveModList()).clone(); + String sortedList = modlist.stream() + .filter(m -> m.getMod() != null) + .sorted(Comparator.comparing(ModContainer::getModId)) + .collect(String::new, (a, b) -> a += b.getModId() + b.getVersion(), (a, b) -> a += ", " + b); + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + modListVersion = DatatypeConverter.printHexBinary(md.digest(sortedList.getBytes(StandardCharsets.UTF_8))) + .toUpperCase(); + return modListVersion; + } catch (Exception e) { + modListVersion = sortedList; + return sortedList; + } + } } -- cgit From 32f6632ffc1ed4c91a02146e5653a28089a33556 Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Thu, 18 Aug 2022 00:52:22 +0200 Subject: Fix --- src/main/java/kubatech/api/utils/ModUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/main/java/kubatech/api') diff --git a/src/main/java/kubatech/api/utils/ModUtils.java b/src/main/java/kubatech/api/utils/ModUtils.java index 447796ddbf..53f0086e25 100644 --- a/src/main/java/kubatech/api/utils/ModUtils.java +++ b/src/main/java/kubatech/api/utils/ModUtils.java @@ -59,7 +59,11 @@ public class ModUtils { String sortedList = modlist.stream() .filter(m -> m.getMod() != null) .sorted(Comparator.comparing(ModContainer::getModId)) - .collect(String::new, (a, b) -> a += b.getModId() + b.getVersion(), (a, b) -> a += ", " + b); + .collect( + StringBuilder::new, + (a, b) -> a.append(b.getModId()).append(b.getVersion()), + (a, b) -> a.append(", ").append(b)) + .toString(); try { MessageDigest md = MessageDigest.getInstance("MD5"); modListVersion = DatatypeConverter.printHexBinary(md.digest(sortedList.getBytes(StandardCharsets.UTF_8))) -- cgit From 5d1286092eac1545f819babbee27244504a212f0 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Tue, 23 Aug 2022 00:17:48 +0200 Subject: Add Config to override mob drops + some fixes (#8) * Add overrides * GTNHCoreMod custom drops integration * Update buildscript * Bump * EEC blacklist * NEI info * Loops optimization * Warn when 0% loots are detected * Detect looting drops * No * Super rare drops * Keep the same naming * Crash * Fix meta * maybe * Run at least twice * Fix stupid TF Lich boss * Comments * Fix EEC blacklist --- .../java/kubatech/api/ConstructableItemStack.java | 97 +++++++++++++++++++++ src/main/java/kubatech/api/LoaderReference.java | 1 + src/main/java/kubatech/api/mobhandler/MobDrop.java | 99 ++++++++++++++++++++++ .../kubatech/api/network/LoadConfigPacket.java | 21 ++++- src/main/java/kubatech/api/utils/GSONUtils.java | 33 +++++++- 5 files changed, 248 insertions(+), 3 deletions(-) create mode 100644 src/main/java/kubatech/api/ConstructableItemStack.java create mode 100644 src/main/java/kubatech/api/mobhandler/MobDrop.java (limited to 'src/main/java/kubatech/api') diff --git a/src/main/java/kubatech/api/ConstructableItemStack.java b/src/main/java/kubatech/api/ConstructableItemStack.java new file mode 100644 index 0000000000..668d21d803 --- /dev/null +++ b/src/main/java/kubatech/api/ConstructableItemStack.java @@ -0,0 +1,97 @@ +package kubatech.api; + +import cpw.mods.fml.common.registry.GameRegistry; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.nio.charset.StandardCharsets; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTSizeTracker; +import net.minecraft.nbt.NBTTagCompound; + +public class ConstructableItemStack { + public final GameRegistry.UniqueIdentifier itemIdentifier; + public final int meta; + public final int size; + public final NBTTagCompound tagCompound; + + private ConstructableItemStack( + GameRegistry.UniqueIdentifier itemIdentifier, int meta, int size, NBTTagCompound tagCompound) { + this.itemIdentifier = itemIdentifier; + this.meta = meta; + this.size = size; + this.tagCompound = tagCompound; + } + + public ConstructableItemStack(ItemStack stack) { + itemIdentifier = GameRegistry.findUniqueIdentifierFor(stack.getItem()); + meta = stack.getItemDamage(); + size = stack.stackSize; + tagCompound = stack.stackTagCompound; + } + + public ItemStack construct() { + if (itemIdentifier == null) return null; + Item it = GameRegistry.findItem(itemIdentifier.modId, itemIdentifier.name); + if (it == null) return null; + ItemStack stack = new ItemStack(it, size, meta); + stack.stackTagCompound = tagCompound; + return stack; + } + + public boolean isSame(ConstructableItemStack stack, boolean ignoreSize) { + if (!stack.itemIdentifier.modId.equals(itemIdentifier.modId)) return false; + if (!stack.itemIdentifier.name.equals(itemIdentifier.name)) return false; + return ignoreSize || stack.size == size; + } + + private static final ByteBuf BufHelper = Unpooled.buffer(); + + public void writeToByteBuf(ByteBuf byteBuf) { + BufHelper.clear(); + byte[] bytes = itemIdentifier.modId.getBytes(StandardCharsets.UTF_8); + BufHelper.writeInt(bytes.length); + BufHelper.writeBytes(bytes); + bytes = itemIdentifier.name.getBytes(StandardCharsets.UTF_8); + BufHelper.writeInt(bytes.length); + BufHelper.writeBytes(bytes); + BufHelper.writeInt(meta); + BufHelper.writeInt(size); + BufHelper.writeBoolean(tagCompound != null); + if (tagCompound != null) { + try { + bytes = CompressedStreamTools.compress(tagCompound); + } catch (Exception ignored) { + bytes = new byte[0]; + } + BufHelper.writeInt(bytes.length); + BufHelper.writeBytes(bytes); + } + byteBuf.writeInt(BufHelper.readableBytes()); + byteBuf.writeBytes(BufHelper); + } + + public static ConstructableItemStack readFromByteBuf(ByteBuf byteBuf) { + int size = byteBuf.readInt(); + byte[] bytes = new byte[byteBuf.readInt()]; + byteBuf.readBytes(bytes); + String modid = new String(bytes, StandardCharsets.UTF_8); + bytes = new byte[byteBuf.readInt()]; + byteBuf.readBytes(bytes); + String name = new String(bytes, StandardCharsets.UTF_8); + int meta = byteBuf.readInt(); + int stacksize = byteBuf.readInt(); + NBTTagCompound nbtTagCompound = null; + if (byteBuf.readBoolean()) { + bytes = new byte[byteBuf.readInt()]; + byteBuf.readBytes(bytes); + try { + nbtTagCompound = CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L)); + } catch (Exception ignored) { + } + } + return new ConstructableItemStack( + new GameRegistry.UniqueIdentifier(modid + ":" + name), meta, stacksize, nbtTagCompound); + } +} diff --git a/src/main/java/kubatech/api/LoaderReference.java b/src/main/java/kubatech/api/LoaderReference.java index 418fe4a7ab..b41db59904 100644 --- a/src/main/java/kubatech/api/LoaderReference.java +++ b/src/main/java/kubatech/api/LoaderReference.java @@ -10,4 +10,5 @@ public class LoaderReference { public static final boolean Thaumcraft = Loader.isModLoaded("Thaumcraft"); public static final boolean MineTweaker = Loader.isModLoaded("MineTweaker3"); public static final boolean Bartworks = Loader.isModLoaded("bartworks"); + public static final boolean GTNHCoreMod = Loader.isModLoaded("dreamcraft"); } diff --git a/src/main/java/kubatech/api/mobhandler/MobDrop.java b/src/main/java/kubatech/api/mobhandler/MobDrop.java new file mode 100644 index 0000000000..76942b3148 --- /dev/null +++ b/src/main/java/kubatech/api/mobhandler/MobDrop.java @@ -0,0 +1,99 @@ +package kubatech.api.mobhandler; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.HashMap; +import kubatech.api.ConstructableItemStack; +import kubatech.api.utils.GSONUtils; +import net.minecraft.item.ItemStack; + +public class MobDrop { + public enum DropType { + Normal, + Rare, + Additional, + Infernal; + private static final DropType[] values = values(); + + public static DropType get(int ordinal) { + return values[ordinal]; + } + } + + @GSONUtils.SkipGSON + public ItemStack stack; + + public ConstructableItemStack reconstructableStack; + public DropType type; + public int chance; + public Integer enchantable; + public HashMap damages; + public boolean lootable = false; + public boolean playerOnly = false; + + private MobDrop() {} + + public MobDrop( + ItemStack stack, + DropType type, + int chance, + Integer enchantable, + HashMap damages, + boolean lootable, + boolean playerOnly) { + this.stack = stack; + this.reconstructableStack = new ConstructableItemStack(stack); + this.type = type; + this.chance = chance; + this.enchantable = enchantable; + this.damages = damages; + this.lootable = lootable; + this.playerOnly = playerOnly; + } + + public void reconstructStack() { + this.stack = reconstructableStack.construct(); + } + + private static final ByteBuf BufHelper = Unpooled.buffer(); + + public void writeToByteBuf(ByteBuf byteBuf) { + BufHelper.clear(); + reconstr