diff options
| author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2024-09-21 01:38:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-21 01:38:28 +0200 |
| commit | c10272e0e358a233ed0ce7d591e9e43ca7ffa26c (patch) | |
| tree | a097f2307d43a5c3d77a698b3c01eae801d35c6c /src/main/java/gtPlusPlus/core | |
| parent | e567c18792be9fe623ec777b40f3cbc36572b78e (diff) | |
| download | GT5-Unofficial-c10272e0e358a233ed0ce7d591e9e43ca7ffa26c.tar.gz GT5-Unofficial-c10272e0e358a233ed0ce7d591e9e43ca7ffa26c.tar.bz2 GT5-Unofficial-c10272e0e358a233ed0ce7d591e9e43ca7ffa26c.zip | |
Delete more reflection (#3233)
Diffstat (limited to 'src/main/java/gtPlusPlus/core')
7 files changed, 52 insertions, 251 deletions
diff --git a/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java b/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java index 13dc18c4b1..51780fd030 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java @@ -13,36 +13,23 @@ import com.kuba6000.mobsinfo.api.MobRecipe; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.api.util.ReflectionUtil; import gtPlusPlus.core.material.MaterialsElements; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; @Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") public class EnderDragonDeathHandler implements IMobExtraInfoProvider { - private static final String mDragonClassName = "chylex.hee.entity.boss.EntityBossDragon"; - private static final boolean mHEE; - private static final Class mHardcoreDragonClass; - - private static final String mChaosDragonClassName = "com.brandon3055.draconicevolution.common.entity.EntityCustomDragon"; - private static final boolean mDE; - private static final Class mChaoseDragonClass; - - static { - mHEE = ReflectionUtils.doesClassExist(mDragonClassName); - mHardcoreDragonClass = (mHEE ? ReflectionUtils.getClass(mDragonClassName) : null); - mDE = ReflectionUtils.doesClassExist(mChaosDragonClassName); - mChaoseDragonClass = (mDE ? ReflectionUtils.getClass(mChaosDragonClassName) : null); - } + private static final Class<?> mHardcoreDragonClass = ReflectionUtil + .getClass("chylex.hee.entity.boss.EntityBossDragon"); + private static final Class<?> mChaoseDragonClass = ReflectionUtil + .getClass("com.brandon3055.draconicevolution.common.entity.EntityCustomDragon"); @SubscribeEvent public void onEntityDrop(LivingDropsEvent event) { - // - int aCountTotal = 0; - - if (mHEE && mHardcoreDragonClass != null && mHardcoreDragonClass.isInstance(event.entityLiving)) { + if (mHardcoreDragonClass != null && mHardcoreDragonClass.isInstance(event.entityLiving)) { for (int y = 0; y < MathUtils.randInt(100, 250); y++) { int aAmount = MathUtils.randInt(5, 25); event.entityLiving.entityDropItem( @@ -50,7 +37,7 @@ public class EnderDragonDeathHandler implements IMobExtraInfoProvider { MathUtils.randFloat(0, 1)); aCountTotal = +aAmount; } - } else if (mDE && mChaoseDragonClass != null && mChaoseDragonClass.isInstance(event.entityLiving)) { + } else if (mChaoseDragonClass != null && mChaoseDragonClass.isInstance(event.entityLiving)) { for (int y = 0; y < MathUtils.randInt(100, 200); y++) { int aAmount = MathUtils.randInt(1, 5); event.entityLiving.entityDropItem( @@ -69,7 +56,7 @@ public class EnderDragonDeathHandler implements IMobExtraInfoProvider { } if (aCountTotal > 0) { PlayerUtils - .messageAllPlayers(aCountTotal + " Shards of Dragons Blood have crystalized into a metallic form."); + .messageAllPlayers(aCountTotal + " Shards of Dragons Blood have crystallized into a metallic form."); } } @@ -77,7 +64,7 @@ public class EnderDragonDeathHandler implements IMobExtraInfoProvider { @Override public void provideExtraDropsInformation(@NotNull String entityString, @NotNull ArrayList<MobDrop> drops, @NotNull MobRecipe recipe) { - if (mHEE && mHardcoreDragonClass != null && mHardcoreDragonClass.isInstance(recipe.entity)) { + if (mHardcoreDragonClass != null && mHardcoreDragonClass.isInstance(recipe.entity)) { MobDrop drop = new MobDrop( MaterialsElements.STANDALONE.DRAGON_METAL.getNugget(1), MobDrop.DropType.Normal, @@ -90,7 +77,7 @@ public class EnderDragonDeathHandler implements IMobExtraInfoProvider { drop.clampChance(); drops.add(drop); - } else if (mDE && mChaoseDragonClass != null && mChaoseDragonClass.isInstance(recipe.entity)) { + } else if (mChaoseDragonClass != null && mChaoseDragonClass.isInstance(recipe.entity)) { MobDrop drop = new MobDrop( MaterialsElements.STANDALONE.DRAGON_METAL.getIngot(1), MobDrop.DropType.Normal, diff --git a/src/main/java/gtPlusPlus/core/item/ModItems.java b/src/main/java/gtPlusPlus/core/item/ModItems.java index 67ff8034dc..014b399044 100644 --- a/src/main/java/gtPlusPlus/core/item/ModItems.java +++ b/src/main/java/gtPlusPlus/core/item/ModItems.java @@ -1,5 +1,6 @@ package gtPlusPlus.core.item; +import static gregtech.api.enums.Mods.Baubles; import static gregtech.api.enums.Mods.Forestry; import static gregtech.api.enums.Mods.GTPlusPlus; import static gregtech.api.enums.Mods.GregTech; @@ -80,7 +81,6 @@ import gtPlusPlus.core.util.data.StringUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.everglades.GTPPEverglades; import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import gtPlusPlus.xmod.gregtech.common.helpers.VolumetricFlaskHelper; @@ -784,19 +784,9 @@ public final class ModItems { // Milled Ore Processing new MilledOreProcessing(); - // IC2 Exp - Logger.INFO("IndustrialCraft2 Found - Loading Resources."); - - // Baubles Mod Test - try { - final Class<?> baublesTest = ReflectionUtils.getClass("baubles.api.IBauble"); - if (baublesTest != null) { - CompatBaubles.run(); - } else { - Logger.INFO("Baubles Not Found - Skipping Resources."); - } - } catch (final Throwable T) { - Logger.INFO("Baubles Not Found - Skipping Resources."); + // Baubles + if (Baubles.isModLoaded()) { + CompatBaubles.run(); } // Buffer Cores! diff --git a/src/main/java/gtPlusPlus/core/item/bauble/FireProtectionBauble.java b/src/main/java/gtPlusPlus/core/item/bauble/FireProtectionBauble.java index 35adc35e96..89ddb241ed 100644 --- a/src/main/java/gtPlusPlus/core/item/bauble/FireProtectionBauble.java +++ b/src/main/java/gtPlusPlus/core/item/bauble/FireProtectionBauble.java @@ -22,7 +22,7 @@ import gtPlusPlus.preloader.PreloaderCore; public class FireProtectionBauble extends BaseBauble { - private static Field isImmuneToFire; + private static final Field isImmuneToFire; static { isImmuneToFire = ReflectionUtils diff --git a/src/main/java/gtPlusPlus/core/item/wearable/armour/tinfoil/ItemArmourTinFoilHat.java b/src/main/java/gtPlusPlus/core/item/wearable/armour/tinfoil/ItemArmourTinFoilHat.java index 7df52a176a..94b33a270e 100644 --- a/src/main/java/gtPlusPlus/core/item/wearable/armour/tinfoil/ItemArmourTinFoilHat.java +++ b/src/main/java/gtPlusPlus/core/item/wearable/armour/tinfoil/ItemArmourTinFoilHat.java @@ -28,7 +28,6 @@ import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.util.GTUtility; import gtPlusPlus.core.item.wearable.armour.ArmourLoader; import gtPlusPlus.core.item.wearable.armour.base.BaseArmourHelm; @@ -120,55 +119,41 @@ public class ItemArmourTinFoilHat extends BaseArmourHelm { public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) { if (itemStack != null && player != null && world != null && !world.isRemote) { if (player instanceof EntityPlayer) { - // Apply Slow - if (!GTUtility.getPotion(player, Potion.moveSlowdown.id)) { + if (!player.isPotionActive(Potion.moveSlowdown.id)) { player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 2, 1, true)); } - // Move Xp orbs away - try { - AxisAlignedBB box = player.boundingBox; - box.maxX = player.posX + 5; - box.maxY = player.posY + 5; - box.maxZ = player.posZ + 5; - box.minX = player.posX - 5; - box.minY = player.posY - 5; - box.minZ = player.posZ - 5; - @SuppressWarnings("unchecked") - List<Entity> g = world.getEntitiesWithinAABBExcludingEntity(player, box); - if (g.size() > 0) { - for (Entity e : g) { - if (e != null) { - if (!EntityXPOrb.class.isInstance(e) && !EntityBoat.class.isInstance(e) - && !EntitySnowball.class.isInstance(e) - && !EntityFireball.class.isInstance(e) - && !EntityEgg.class.isInstance(e) - && !EntityExpBottle.class.isInstance(e) - && !EntityEnderEye.class.isInstance(e) - && !EntityEnderPearl.class.isInstance(e)) { - continue; - } else { - // Logger.INFO("Found "+e.getClass().getName()); - double distX = player.posX - e.posX; - double distZ = player.posZ - e.posZ; - double distY = e.posY + 1.5D - player.posY; - double dir = Math.atan2(distZ, distX); - double speed = 1F / e.getDistanceToEntity(player) * 0.5; - speed = -speed; - if (distY < 0) { - e.motionY += speed; - } - e.motionX = Math.cos(dir) * speed; - e.motionZ = Math.sin(dir) * speed; - } - } + final AxisAlignedBB box = player.getBoundingBox(); + if (box != null) { + List<Entity> list = world.getEntitiesWithinAABBExcludingEntity( + player, + box.expand(5, 5, 5), + e -> e instanceof EntityXPOrb || e instanceof EntityBoat + || e instanceof EntitySnowball + || e instanceof EntityFireball + || e instanceof EntityEgg + || e instanceof EntityExpBottle + || e instanceof EntityEnderEye + || e instanceof EntityEnderPearl); + for (Entity e : list) { + final float dist = e.getDistanceToEntity(player); + if (dist == 0) continue; + double distX = player.posX - e.posX; + double distZ = player.posZ - e.posZ; + double distY = e.posY + 1.5D - player.posY; + double dir = Math.atan2(distZ, distX); + double speed = 1F / dist * 0.5; + speed = -speed; + if (distY < 0) { + e.motionY += speed; } + e.motionX = Math.cos(dir) * speed; + e.motionZ = Math.sin(dir) * speed; } - } catch (Throwable t) {} + } } } - super.onArmorTick(world, player, itemStack); } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 3565b1c14d..c64686a151 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -72,16 +72,16 @@ public class ItemUtils { return simpleMetaStack(Item.getItemFromBlock(x), meta, i); } - public static ItemStack getSimpleStack(final Item x, final int i) { - return new ItemStack(x, i); + public static ItemStack getSimpleStack(final Item item, final int stackSize) { + return new ItemStack(item, stackSize); } - public static ItemStack getSimpleStack(final ItemStack x, final int i) { - if (x == null) { + public static ItemStack getSimpleStack(final ItemStack stack, final int stackSize) { + if (stack == null) { return null; } - final ItemStack r = x.copy(); - r.stackSize = i; + final ItemStack r = stack.copy(); + r.stackSize = stackSize; return r; } diff --git a/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java b/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java index 7ea6af4a23..6f50da5eb2 100644 --- a/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java +++ b/src/main/java/gtPlusPlus/core/util/minecraft/PlayerUtils.java @@ -19,21 +19,14 @@ import net.minecraftforge.common.util.FakePlayer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.util.GTUtility; +import gregtech.api.util.ReflectionUtil; import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; public class PlayerUtils { public static final Map<String, EntityPlayer> mCachedFakePlayers = new WeakHashMap<>(); - private static final Class mThaumcraftFakePlayer; - - static { - if (ReflectionUtils.doesClassExist("thaumcraft.common.lib.FakeThaumcraftPlayer")) { - mThaumcraftFakePlayer = ReflectionUtils.getClass("thaumcraft.common.lib.FakeThaumcraftPlayer"); - } else { - mThaumcraftFakePlayer = null; - } - } + private static final Class<?> mThaumcraftFakePlayer = ReflectionUtil + .getClass("thaumcraft.common.lib.FakeThaumcraftPlayer"); public static List<EntityPlayerMP> getOnlinePlayers() { final List<EntityPlayerMP> onlinePlayers = MinecraftServer.getServer() diff --git a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index 576c236de6..40b32fed86 100644 --- a/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -20,7 +20,6 @@ import gtPlusPlus.core.util.data.StringUtils; @SuppressWarnings({ "unchecked", "rawtypes" }) public class ReflectionUtils { - public static Map<String, Class<?>> mCachedClasses = new LinkedHashMap<>(); public static Map<String, CachedMethod> mCachedMethods = new LinkedHashMap<>(); public static Map<String, CachedField> mCachedFields = new LinkedHashMap<>(); public static Map<String, CachedConstructor> mCachedConstructors = new LinkedHashMap<>(); @@ -74,18 +73,6 @@ public class ReflectionUtils { .getUntypedField(Fields.LookupType.DECLARED_IN_HIERARCHY, field.getName())); } - private static boolean cacheClass(Class<?> aClass) { - if (aClass == null) { - return false; - } - Class<?> y = mCachedClasses.get(aClass.getCanonicalName()); - if (y == null) { - mCachedClasses.put(aClass.getCanonicalName(), aClass); - return true; - } - return false; - } - private static boolean cacheMethod(Class<?> aClass, Method aMethod) { if (aMethod == null) { return false; @@ -154,27 +141,6 @@ public class ReflectionUtils { } /** - * Returns a cached {@link Class} object. - * - * @param aClassCanonicalName - The canonical name of the underlying class. - * @return - Valid, {@link Class} object, or {@link null}. - */ - public static Class<?> getClass(String aClassCanonicalName) { - if (aClassCanonicalName == null || aClassCanonicalName.length() <= 0) { - return null; - } - Class<?> y = mCachedClasses.get(aClassCanonicalName); - if (y == null) { - y = getClass_Internal(aClassCanonicalName); - if (y != null) { - Logger.REFLECTION("Caching Class: " + aClassCanonicalName); - cacheClass(y); - } - } - return y; - } - - /** * Returns a cached {@link Method} object. Wraps {@link #getMethod(Class, String, Class...)}. * * @param aObject - Object containing the Method. @@ -263,10 +229,6 @@ public class ReflectionUtils { * Utility Functions */ - public static boolean doesClassExist(final String classname) { - return isClassPresent(classname); - } - public static void makeFieldAccessible(final Field field) { if (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic( field.getDeclaringClass() @@ -445,20 +407,6 @@ public class ReflectionUtils { } } - /** - * if (isPresent("com.optionaldependency.DependencyClass")) || This block will never execute when the dependency is - * not present. There is therefore no more risk of code throwing NoClassDefFoundException. - */ - private static boolean isClassPresent(final String className) { - try { - Class.forName(className); - return true; - } catch (final Throwable ex) { - // Class or one of its dependencies is not present... - return false; - } - } - private static Method getMethod_Internal(Class<?> aClass, String aMethodName, Class<?>... aTypes) { Method m = null; try { @@ -561,106 +509,6 @@ public class ReflectionUtils { } } - private static Class<?> getNonPublicClass(final String className) { - Class<?> c = null; - try { - c = Class.forName(className); - } catch (final ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // full package name --------^^^^^^^^^^ - // or simpler without Class.forName: - // Class<package1.A> c = package1.A.class; - - if (null != c) { - // In our case we need to use - Constructor<?> constructor = null; - try { - constructor = c.getDeclaredConstructor(); - } catch (NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // note: getConstructor() can return only public constructors - // so we needed to search for any Declared constructor - - // now we need to make this constructor accessible - if (null != constructor) { - constructor.setAccessible(true); // ABRACADABRA! - - try { - final Object o = constructor.newInstance(); - return (Class<?>) o; - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - return null; - } - - private static Class<?> getClass_Internal(String string) { - Class<?> aClass = null; - if (ReflectionUtils.doesClassExist(string)) { - try { - aClass = Class.forName(string); - } catch (ClassNotFoundException e) { - aClass = getNonPublicClass(string); - } - } - - if (aClass == null) { - String aClassName = ""; - Logger.REFLECTION("Splitting " + string + " to try look for hidden classes."); - String[] aData = string.split("\\."); - Logger.REFLECTION("Obtained " + aData.length + " pieces."); - for (int i = 0; i < (aData.length - 1); i++) { - aClassName += (i > 0) ? "." + aData[i] : "" + aData[i]; - Logger.REFLECTION("Building: " + aClassName); - } - if (aClassName != null && aClassName.length() > 0) { - Logger.REFLECTION("Trying to search '" + aClassName + "' for inner classes."); - Class<?> clazz = ReflectionUtils.getClass(aClassName); - if (clazz != null) { - Class[] y = clazz.getDeclaredClasses(); - if (y == null || y.length <= 0) { - Logger.REFLECTION("No hidden inner classes found."); - return null; - } else { - boolean found = false; - for (Class<?> h : y) { - Logger.REFLECTION("Found hidden inner class: " + h.getCanonicalName()); - if (h.getSimpleName() - .toLowerCase() - .equals(aData[aData.length - 1].toLowerCase())) { - Logger.REFLECTION( - "Found correct class. [" + aData[aData.length - 1] - + "] Caching at correct location: " - + string); - Logger.REFLECTION("Found at location: " + h.getCanonicalName()); - ReflectionUtils.mCachedClasses.put(string, h); - aClass = h; - found = true; - break; - } - } - if (!found) { - return null; - } - } - } else { - return null; - } - } else { - return null; - } - } - return aClass; - } - /** * * Set the value of a field reflectively. @@ -693,9 +541,7 @@ public class ReflectionUtils { T aInstance; try { aInstance = (T) aConstructor.newInstance(aArgs); - if (aInstance != null) { - return aInstance; - } + return aInstance; } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); |
