From 0b21f0e0ebae09898d1ba455a4d56e0fdf0b4071 Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Tue, 20 Sep 2022 21:47:41 +0200 Subject: Show is mob can be captured in soul vial --- .../java/kubatech/api/helpers/EnderIOHelper.java | 20 ++ .../java/kubatech/api/helpers/InfernalHelper.java | 227 +++++++++++++++++++++ .../kubatech/api/helpers/ReflectionHelper.java | 105 ++++++++++ 3 files changed, 352 insertions(+) create mode 100644 src/main/java/kubatech/api/helpers/EnderIOHelper.java create mode 100644 src/main/java/kubatech/api/helpers/InfernalHelper.java create mode 100644 src/main/java/kubatech/api/helpers/ReflectionHelper.java (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/EnderIOHelper.java b/src/main/java/kubatech/api/helpers/EnderIOHelper.java new file mode 100644 index 0000000000..b6c01c9741 --- /dev/null +++ b/src/main/java/kubatech/api/helpers/EnderIOHelper.java @@ -0,0 +1,20 @@ +package kubatech.api.helpers; + +import crazypants.enderio.EnderIO; +import kubatech.api.LoaderReference; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.boss.IBossDisplayData; + +public class EnderIOHelper { + public static boolean canEntityBeCapturedWithSoulVial(Entity entity, String entityID) { + if (!LoaderReference.EnderIO) return true; + if (ReflectionHelper.callMethod(EnderIO.itemSoulVessel, "isBlackListed", false, entityID)) + return false; + return crazypants.enderio.config.Config.soulVesselCapturesBosses || !(entity instanceof IBossDisplayData); + } + + public static boolean canEntityBeCapturedWithSoulVial(Entity entity) { + return canEntityBeCapturedWithSoulVial(entity, EntityList.getEntityString(entity)); + } +} diff --git a/src/main/java/kubatech/api/helpers/InfernalHelper.java b/src/main/java/kubatech/api/helpers/InfernalHelper.java new file mode 100644 index 0000000000..1eadb42a8f --- /dev/null +++ b/src/main/java/kubatech/api/helpers/InfernalHelper.java @@ -0,0 +1,227 @@ +/* + * 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.helpers; + +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; + +@SuppressWarnings("unchecked") +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/helpers/ReflectionHelper.java b/src/main/java/kubatech/api/helpers/ReflectionHelper.java new file mode 100644 index 0000000000..1d7449afc4 --- /dev/null +++ b/src/main/java/kubatech/api/helpers/ReflectionHelper.java @@ -0,0 +1,105 @@ +/* + * 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.helpers; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; + +public class ReflectionHelper { + private static class _FieldsMethods { + HashMap fields = new HashMap<>(); + HashMap methods = new HashMap<>(); + } + + private static final HashMap classes = new HashMap<>(); + + @SuppressWarnings("unchecked") + public static T getField(Object obj, String fieldName, T defaultvalue) { + Class cl = obj.getClass(); + String clName = cl.getName(); + HashMap classmap = classes.computeIfAbsent(clName, s -> new _FieldsMethods()).fields; + try { + if (classmap.containsKey(fieldName)) { + Field f = classmap.get(fieldName); + if (f == null) return defaultvalue; + return (T) f.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)); + classmap.put(fieldName, f); + if (f == null) return defaultvalue; + return (T) f.get(obj); + } catch (Exception ex) { + return defaultvalue; + } + } + + public static T getField(Object obj, String fieldName) { + return getField(obj, fieldName, null); + } + + @SuppressWarnings("unchecked") + public static T callMethod(Object obj, String methodName, T defaultValue, Object... args) { + Class cl = obj.getClass(); + String clName = cl.getName(); + HashMap classmap = classes.computeIfAbsent(clName, s -> new _FieldsMethods()).methods; + StringBuilder builder = new StringBuilder(methodName); + Class[] argsTypes = new Class[args.length]; + for (int i = 0; i < args.length; i++) { + Class arg = args[i].getClass(); + builder.append(";").append(arg.getSimpleName()); + argsTypes[i] = arg; + } + String methodNameUnique = builder.toString(); + try { + if (classmap.containsKey(methodNameUnique)) { + Method m = classmap.get(methodNameUnique); + if (m == null) return defaultValue; + return (T) m.invoke(obj, args); + } + boolean exceptionDetected = false; + Method m = null; + do { + try { + m = cl.getDeclaredMethod(methodName, argsTypes); + m.setAccessible(true); + } catch (Exception ex) { + exceptionDetected = true; + cl = cl.getSuperclass(); + } + } while (exceptionDetected && !cl.equals(Object.class)); + classmap.put(methodNameUnique, m); + if (m == null) return defaultValue; + return (T) m.invoke(obj, args); + } catch (Exception ex) { + return defaultValue; + } + } +} -- cgit From 4bd636dcb73cd9269e451010ef5b9cc0d1944167 Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Tue, 20 Sep 2022 21:53:57 +0200 Subject: Update EnderIOHelper.java --- src/main/java/kubatech/api/helpers/EnderIOHelper.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/EnderIOHelper.java b/src/main/java/kubatech/api/helpers/EnderIOHelper.java index b6c01c9741..6e85507398 100644 --- a/src/main/java/kubatech/api/helpers/EnderIOHelper.java +++ b/src/main/java/kubatech/api/helpers/EnderIOHelper.java @@ -1,3 +1,22 @@ +/* + * 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.helpers; import crazypants.enderio.EnderIO; -- cgit From 89eccf0728b9b2175c68036ead3408b359c2981c Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Sun, 2 Oct 2022 19:51:28 +0200 Subject: Allow Extreme Extermination Chamber to overclock past 1 tick (#25) * Revert "Shift outputs when needed" This reverts commit e476c41e8956a61de6e1d962c9bb40948db8c2b5. * OC past 1 tick * Fix * ok * Ye * info --- src/main/java/kubatech/api/helpers/GTHelper.java | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/java/kubatech/api/helpers/GTHelper.java (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/GTHelper.java b/src/main/java/kubatech/api/helpers/GTHelper.java new file mode 100644 index 0000000000..bf2b28ff79 --- /dev/null +++ b/src/main/java/kubatech/api/helpers/GTHelper.java @@ -0,0 +1,53 @@ +package kubatech.api.helpers; + +import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity; + +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import java.util.ArrayList; +import java.util.Arrays; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GTHelper { + + private static final double ln4 = Math.log(4d); + + public static int calculateOverclockedNessMulti( + GT_MetaTileEntity_MultiBlockBase mte, long aEUt, int aDuration, boolean perfect) { + final long maxInputVoltage = getMaxInputEU(mte); + final int tiers = (int) (Math.log((double) maxInputVoltage / (double) aEUt) / ln4); + if (tiers <= 0) { + mte.mEUt = (int) aEUt; + mte.mMaxProgresstime = aDuration; + return 0; + } + mte.mEUt = (int) (aEUt << (tiers << 1)); + int dMulti = 1; + final int aDurationModifier = perfect ? 2 : 1; + for (int i = 0; i < tiers; i++) + if (aDuration > 1) aDuration >>= aDurationModifier; + else dMulti <<= aDurationModifier; + if (dMulti > 1) { + final ArrayList stacks = new ArrayList<>(Arrays.asList(mte.mOutputItems)); + for (ItemStack mOutputItem : mte.mOutputItems) { + mOutputItem.stackSize *= dMulti; + int maxSize = mOutputItem.getMaxStackSize(); + while (mOutputItem.stackSize > maxSize) + stacks.add(mOutputItem.splitStack(Math.min(mOutputItem.stackSize - maxSize, maxSize))); + } + if (stacks.size() != mte.mOutputItems.length) mte.mOutputItems = stacks.toArray(new ItemStack[0]); + for (FluidStack mOutputFluid : mte.mOutputFluids) mOutputFluid.amount *= dMulti; + } + if (aDuration <= 0) aDuration = 1; + mte.mMaxProgresstime = aDuration; + return tiers; + } + + public static long getMaxInputEU(GT_MetaTileEntity_MultiBlockBase mte) { + long rEU = 0; + for (GT_MetaTileEntity_Hatch_Energy tHatch : mte.mEnergyHatches) + if (isValidMetaTileEntity(tHatch)) rEU += tHatch.maxEUInput() * tHatch.maxAmperesIn(); + return rEU; + } +} -- cgit From 8a581938862a4d612f510a8afed88727a34c3916 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Thu, 15 Dec 2022 16:53:12 +0100 Subject: MODULAR UI (#34) * MODULAR UUUUUUUUIIIIIIIIIII * Tea * Add recipe to ULTIMATE TEA * Stupid MT Scripts. I hate it * Yeet * More TEA * Add blocks * More Modular UIs * Textures * Fix custom UI containers * Texture, tooltip * UI with tabs * ButtonWidget * fix * Fix * Texture * Color is fixed * More UI work * Modular UI is hard dependency now * Spotless * Simplify * Format numbers * A * Update TeaAcceptorTile.java * Shadow is fixed, lets gooooo * hardness * Mixins mixins mixins * Tab icons * Fix crash * Shop concept * Bump ModularUI * Bump Modular UI * Nooooooooooo * GREY -> GRAY * Bump ModularUI * Bump GT5 * EEC with MUI test * Include incomplete structure * REFLECTIONS !! * Just use slot filter * Update pos when needed * Update GT_MetaTileEntity_ExtremeExterminationChamber.java * Spawner status * Nice toggle button * Send messages * Next toggle button * Start work on IAADDS * Scrollable inventory test * Draw queen slots * Fix * Update dependencies.gradle * Use sync widget * Add button to enable/disable working * Configuration in Mega Apiary * Refactor a bit * Update ModularUI * Bump ModularUI * Bump GT5 * Fix build * Update dependencies.gradle * Update build.gradle * Update dependencies.gradle * spotless * Begin working on configuration window * Update dependencies.gradle * Deprecated * Update dependencies.gradle * Optimize bee storage rendering (2 fps -> 100 fps) * Make Mega Apiary storage GUI usable * Configuration window looks ok * Color is fixed * TC research * Disable for now * Finish tea command * ok * Fix * Update en_US.lang * ZzZ * Stuff changed --- .../kubatech/api/helpers/ReflectionHelper.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/ReflectionHelper.java b/src/main/java/kubatech/api/helpers/ReflectionHelper.java index 1d7449afc4..7b02fe6c82 100644 --- a/src/main/java/kubatech/api/helpers/ReflectionHelper.java +++ b/src/main/java/kubatech/api/helpers/ReflectionHelper.java @@ -45,6 +45,7 @@ public class ReflectionHelper { boolean exceptionDetected = false; Field f = null; do { + exceptionDetected = false; try { f = cl.getDeclaredField(fieldName); f.setAccessible(true); @@ -61,6 +62,38 @@ public class ReflectionHelper { } } + public static boolean setField(Object obj, String fieldName, T value) { + Class cl = obj.getClass(); + String clName = cl.getName(); + HashMap classmap = classes.computeIfAbsent(clName, s -> new _FieldsMethods()).fields; + try { + if (classmap.containsKey(fieldName)) { + Field f = classmap.get(fieldName); + if (f == null) return false; + f.set(obj, value); + return true; + } + boolean exceptionDetected = false; + Field f = null; + do { + exceptionDetected = false; + try { + f = cl.getDeclaredField(fieldName); + f.setAccessible(true); + } catch (Exception ex) { + exceptionDetected = true; + cl = cl.getSuperclass(); + } + } while (exceptionDetected && !cl.equals(Object.class)); + classmap.put(fieldName, f); + if (f == null) return false; + f.set(obj, value); + return true; + } catch (Exception ex) { + return false; + } + } + public static T getField(Object obj, String fieldName) { return getField(obj, fieldName, null); } @@ -87,6 +120,7 @@ public class ReflectionHelper { boolean exceptionDetected = false; Method m = null; do { + exceptionDetected = false; try { m = cl.getDeclaredMethod(methodName, argsTypes); m.setAccessible(true); -- cgit From 867280556692363d6ec183ac9838ab3c7769cf1c Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Mon, 9 Jan 2023 17:50:36 +0100 Subject: Fix voltage variable in comb chance calculation in Mega Apiary + some tweaks (#43) * Always use full potential power * Fix voltage variable (t) in comb chance calculation * Fix already existing apiaries --- src/main/java/kubatech/api/helpers/GTHelper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/GTHelper.java b/src/main/java/kubatech/api/helpers/GTHelper.java index bf2b28ff79..05d8bfb919 100644 --- a/src/main/java/kubatech/api/helpers/GTHelper.java +++ b/src/main/java/kubatech/api/helpers/GTHelper.java @@ -50,4 +50,20 @@ public class GTHelper { if (isValidMetaTileEntity(tHatch)) rEU += tHatch.maxEUInput() * tHatch.maxAmperesIn(); return rEU; } + + public static double getVoltageTierD(long voltage) { + return Math.log((double) voltage / 8L) / ln4; + } + + public static double getVoltageTierD(GT_MetaTileEntity_MultiBlockBase mte) { + return Math.log((double) getMaxInputEU(mte) / 8L) / ln4; + } + + public static int getVoltageTier(long voltage) { + return (int) getVoltageTierD(voltage); + } + + public static int getVoltageTier(GT_MetaTileEntity_MultiBlockBase mte) { + return (int) getVoltageTierD(mte); + } } -- cgit From 570f3ab14be37436205ea865ecfc2df4e966d491 Mon Sep 17 00:00:00 2001 From: kuba6000 Date: Tue, 17 Jan 2023 17:36:37 +0100 Subject: New year --- src/main/java/kubatech/api/helpers/EnderIOHelper.java | 2 +- src/main/java/kubatech/api/helpers/InfernalHelper.java | 2 +- src/main/java/kubatech/api/helpers/ReflectionHelper.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/EnderIOHelper.java b/src/main/java/kubatech/api/helpers/EnderIOHelper.java index 6e85507398..c5bb281b7e 100644 --- a/src/main/java/kubatech/api/helpers/EnderIOHelper.java +++ b/src/main/java/kubatech/api/helpers/EnderIOHelper.java @@ -1,6 +1,6 @@ /* * KubaTech - Gregtech Addon - * Copyright (C) 2022 kuba6000 + * Copyright (C) 2022 - 2023 kuba6000 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/main/java/kubatech/api/helpers/InfernalHelper.java b/src/main/java/kubatech/api/helpers/InfernalHelper.java index 1eadb42a8f..dcfd87daad 100644 --- a/src/main/java/kubatech/api/helpers/InfernalHelper.java +++ b/src/main/java/kubatech/api/helpers/InfernalHelper.java @@ -1,6 +1,6 @@ /* * KubaTech - Gregtech Addon - * Copyright (C) 2022 kuba6000 + * Copyright (C) 2022 - 2023 kuba6000 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/main/java/kubatech/api/helpers/ReflectionHelper.java b/src/main/java/kubatech/api/helpers/ReflectionHelper.java index 7b02fe6c82..03fc9f45d9 100644 --- a/src/main/java/kubatech/api/helpers/ReflectionHelper.java +++ b/src/main/java/kubatech/api/helpers/ReflectionHelper.java @@ -1,6 +1,6 @@ /* * KubaTech - Gregtech Addon - * Copyright (C) 2022 kuba6000 + * Copyright (C) 2022 - 2023 kuba6000 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public -- cgit From c5a027d991c59184984d1dd7b119429700834959 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:20:20 +0100 Subject: Move to long power base (#47) * Move to long power base * fix * More moving * Fix math * Why am I soooo blind * Fix 1 ticking * More fixes * Save some tick time * Fix Swarmer mode power drain * Dont need it anymore --- src/main/java/kubatech/api/helpers/GTHelper.java | 40 ++---------------------- 1 file changed, 3 insertions(+), 37 deletions(-) (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/GTHelper.java b/src/main/java/kubatech/api/helpers/GTHelper.java index 05d8bfb919..782c697232 100644 --- a/src/main/java/kubatech/api/helpers/GTHelper.java +++ b/src/main/java/kubatech/api/helpers/GTHelper.java @@ -1,50 +1,16 @@ package kubatech.api.helpers; import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity; +import static kubatech.api.Variables.ln4; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; -import java.util.ArrayList; -import java.util.Arrays; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; +import kubatech.api.implementations.KubaTechGTMultiBlockBase; public class GTHelper { - private static final double ln4 = Math.log(4d); - - public static int calculateOverclockedNessMulti( - GT_MetaTileEntity_MultiBlockBase mte, long aEUt, int aDuration, boolean perfect) { - final long maxInputVoltage = getMaxInputEU(mte); - final int tiers = (int) (Math.log((double) maxInputVoltage / (double) aEUt) / ln4); - if (tiers <= 0) { - mte.mEUt = (int) aEUt; - mte.mMaxProgresstime = aDuration; - return 0; - } - mte.mEUt = (int) (aEUt << (tiers << 1)); - int dMulti = 1; - final int aDurationModifier = perfect ? 2 : 1; - for (int i = 0; i < tiers; i++) - if (aDuration > 1) aDuration >>= aDurationModifier; - else dMulti <<= aDurationModifier; - if (dMulti > 1) { - final ArrayList stacks = new ArrayList<>(Arrays.asList(mte.mOutputItems)); - for (ItemStack mOutputItem : mte.mOutputItems) { - mOutputItem.stackSize *= dMulti; - int maxSize = mOutputItem.getMaxStackSize(); - while (mOutputItem.stackSize > maxSize) - stacks.add(mOutputItem.splitStack(Math.min(mOutputItem.stackSize - maxSize, maxSize))); - } - if (stacks.size() != mte.mOutputItems.length) mte.mOutputItems = stacks.toArray(new ItemStack[0]); - for (FluidStack mOutputFluid : mte.mOutputFluids) mOutputFluid.amount *= dMulti; - } - if (aDuration <= 0) aDuration = 1; - mte.mMaxProgresstime = aDuration; - return tiers; - } - public static long getMaxInputEU(GT_MetaTileEntity_MultiBlockBase mte) { + if (mte instanceof KubaTechGTMultiBlockBase) return ((KubaTechGTMultiBlockBase) mte).getMaxInputEu(); long rEU = 0; for (GT_MetaTileEntity_Hatch_Energy tHatch : mte.mEnergyHatches) if (isValidMetaTileEntity(tHatch)) rEU += tHatch.maxEUInput() * tHatch.maxAmperesIn(); -- cgit From f51616bda220887fdd45c4bc951ff59e3398213a Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sat, 28 Jan 2023 19:03:53 -0800 Subject: [ci skip] spotlessApply with the new settings --- .../java/kubatech/api/helpers/EnderIOHelper.java | 28 +++++++----------- src/main/java/kubatech/api/helpers/GTHelper.java | 2 +- .../java/kubatech/api/helpers/InfernalHelper.java | 34 +++++++++------------- .../kubatech/api/helpers/ReflectionHelper.java | 25 ++++++---------- 4 files changed, 35 insertions(+), 54 deletions(-) (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/EnderIOHelper.java b/src/main/java/kubatech/api/helpers/EnderIOHelper.java index c5bb281b7e..30158500c7 100644 --- a/src/main/java/kubatech/api/helpers/EnderIOHelper.java +++ b/src/main/java/kubatech/api/helpers/EnderIOHelper.java @@ -1,31 +1,25 @@ /* - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 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 . - * + * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 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.helpers; -import crazypants.enderio.EnderIO; import kubatech.api.LoaderReference; + import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.boss.IBossDisplayData; +import crazypants.enderio.EnderIO; + public class EnderIOHelper { + public static boolean canEntityBeCapturedWithSoulVial(Entity entity, String entityID) { if (!LoaderReference.EnderIO) return true; if (ReflectionHelper.callMethod(EnderIO.itemSoulVessel, "isBlackListed", false, entityID)) diff --git a/src/main/java/kubatech/api/helpers/GTHelper.java b/src/main/java/kubatech/api/helpers/GTHelper.java index 782c697232..16abbe348c 100644 --- a/src/main/java/kubatech/api/helpers/GTHelper.java +++ b/src/main/java/kubatech/api/helpers/GTHelper.java @@ -3,9 +3,9 @@ package kubatech.api.helpers; import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase.isValidMetaTileEntity; import static kubatech.api.Variables.ln4; +import kubatech.api.implementations.KubaTechGTMultiBlockBase; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; -import kubatech.api.implementations.KubaTechGTMultiBlockBase; public class GTHelper { diff --git a/src/main/java/kubatech/api/helpers/InfernalHelper.java b/src/main/java/kubatech/api/helpers/InfernalHelper.java index dcfd87daad..a2842d66a7 100644 --- a/src/main/java/kubatech/api/helpers/InfernalHelper.java +++ b/src/main/java/kubatech/api/helpers/InfernalHelper.java @@ -1,34 +1,28 @@ /* - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 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 . - * + * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 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.helpers; -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; +import atomicstryker.infernalmobs.common.InfernalMobsCore; +import atomicstryker.infernalmobs.common.mods.api.ModifierLoader; + @SuppressWarnings("unchecked") public class InfernalHelper { + private static Method isClassAllowed = null; public static boolean isClassAllowed(EntityLivingBase e) { @@ -49,8 +43,8 @@ public class InfernalHelper { public static boolean checkEntityClassForced(EntityLivingBase e) { try { if (checkEntityClassForced == null) { - checkEntityClassForced = - InfernalMobsCore.class.getDeclaredMethod("checkEntityClassForced", EntityLivingBase.class); + checkEntityClassForced = InfernalMobsCore.class + .getDeclaredMethod("checkEntityClassForced", EntityLivingBase.class); checkEntityClassForced.setAccessible(true); } return (boolean) checkEntityClassForced.invoke(InfernalMobsCore.instance(), e); diff --git a/src/main/java/kubatech/api/helpers/ReflectionHelper.java b/src/main/java/kubatech/api/helpers/ReflectionHelper.java index 03fc9f45d9..404d1de5f9 100644 --- a/src/main/java/kubatech/api/helpers/ReflectionHelper.java +++ b/src/main/java/kubatech/api/helpers/ReflectionHelper.java @@ -1,20 +1,11 @@ /* - * KubaTech - Gregtech Addon - * Copyright (C) 2022 - 2023 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 . - * + * KubaTech - Gregtech Addon Copyright (C) 2022 - 2023 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.helpers; @@ -24,7 +15,9 @@ import java.lang.reflect.Method; import java.util.HashMap; public class ReflectionHelper { + private static class _FieldsMethods { + HashMap fields = new HashMap<>(); HashMap methods = new HashMap<>(); } -- cgit From 86a5a3a88c2530ca1354c3a978e60c4b0670a3b4 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Sun, 12 Mar 2023 11:16:05 +0100 Subject: Mega Apiary GUI improvements (#58) * Mega apiary GUI improvements * forgot * buildscript * Fixed on ModularUI * Test scrollable fix * Simplify * Inspection * Fixed in ModularUI --- src/main/java/kubatech/api/helpers/ReflectionHelper.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/ReflectionHelper.java b/src/main/java/kubatech/api/helpers/ReflectionHelper.java index 404d1de5f9..19b8ecd026 100644 --- a/src/main/java/kubatech/api/helpers/ReflectionHelper.java +++ b/src/main/java/kubatech/api/helpers/ReflectionHelper.java @@ -18,8 +18,8 @@ public class ReflectionHelper { private static class _FieldsMethods { - HashMap fields = new HashMap<>(); - HashMap methods = new HashMap<>(); + final HashMap fields = new HashMap<>(); + final HashMap methods = new HashMap<>(); } private static final HashMap classes = new HashMap<>(); @@ -35,7 +35,7 @@ public class ReflectionHelper { if (f == null) return defaultvalue; return (T) f.get(obj); } - boolean exceptionDetected = false; + boolean exceptionDetected; Field f = null; do { exceptionDetected = false; @@ -66,7 +66,7 @@ public class ReflectionHelper { f.set(obj, value); return true; } - boolean exceptionDetected = false; + boolean exceptionDetected; Field f = null; do { exceptionDetected = false; @@ -110,7 +110,7 @@ public class ReflectionHelper { if (m == null) return defaultValue; return (T) m.invoke(obj, args); } - boolean exceptionDetected = false; + boolean exceptionDetected; Method m = null; do { exceptionDetected = false; -- cgit From a12768cd189fcbca175295a948291a81f8c4d350 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Fri, 17 Mar 2023 18:53:13 +0100 Subject: Show progress bar when generating mob recipe map (#59) * Show progress bar when generating mob recipe map * test * Check for BLS * Process on server start * Buildscript --- .../kubatech/api/helpers/ProgressBarWrapper.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/kubatech/api/helpers/ProgressBarWrapper.java (limited to 'src/main/java/kubatech/api/helpers') diff --git a/src/main/java/kubatech/api/helpers/ProgressBarWrapper.java b/src/main/java/kubatech/api/helpers/ProgressBarWrapper.java new file mode 100644 index 0000000000..f1243c4d46 --- /dev/null +++ b/src/main/java/kubatech/api/helpers/ProgressBarWrapper.java @@ -0,0 +1,55 @@ +package kubatech.api.helpers; + +import static kubatech.api.utils.ModUtils.isClientSided; + +import java.io.IOException; + +import kubatech.Tags; +import kubatech.api.LoaderReference; +import alexiil.mods.load.ProgressDisplayer; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.ProgressManager; + +@SuppressWarnings("deprecation") +public class ProgressBarWrapper { + + ProgressManager.ProgressBar internalFMLBar; + boolean isFMLBar; + String name; + int maxSteps; + int steps = 0; + + public ProgressBarWrapper(String name, int steps) { + if (!isClientSided) return; + maxSteps = steps; + this.name = name; + if (!LoaderReference.BetterLoadingScreen) { + internalFMLBar = ProgressManager.push(name, steps); + isFMLBar = true; + return; + } + isFMLBar = false; + } + + public void step(String message) { + if (!isClientSided) return; + if (isFMLBar) internalFMLBar.step(message); + else { + steps++; + try { + ProgressDisplayer.displayProgress( + Tags.MODNAME + ": " + name + " -> " + message, + (float) steps / (float) maxSteps); + } catch (IOException e) { + throw new RuntimeException(e); + } + // Prevent game freeze + FMLCommonHandler.instance().processWindowMessages(); + } + } + + public void end() { + if (!isClientSided) return; + if (isFMLBar) ProgressManager.pop(internalFMLBar); + } +} -- cgit