diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-10-03 16:47:35 +0100 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-10-03 16:47:35 +0100 |
commit | 734e7a1498ef6ca48f95f075aaa66372639c9618 (patch) | |
tree | e18d6ec9acaf4aee2d85155d03a91df9769fe9be /src | |
parent | a5d2b84eabdd5b75d409d8519b7831ecfd0061b9 (diff) | |
download | GT5-Unofficial-734e7a1498ef6ca48f95f075aaa66372639c9618.tar.gz GT5-Unofficial-734e7a1498ef6ca48f95f075aaa66372639c9618.tar.bz2 GT5-Unofficial-734e7a1498ef6ca48f95f075aaa66372639c9618.zip |
$ Fixed COFH OreDictionaryArbiter via ASM.
$ Cleaned up GC Fuel ASM, Rockets are now tiered.
% Added ability for Rover to use Diesel still.
% Added Tooltip to the GC Fuel Loader, showing what Tier requires which fuel.
> Bug still exists on sending packets, which may cause the client to boot the player back to the menu.
Diffstat (limited to 'src')
10 files changed, 1051 insertions, 127 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java index 634035d712..8c940baba3 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -4,6 +4,7 @@ import java.io.Serializable; import java.util.HashSet; import java.util.Set; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; import net.minecraft.world.World; @@ -44,6 +45,10 @@ public class BlockPos implements Serializable{ this.world = dim; } + public BlockPos(IGregTechTileEntity b) { + this (b.getXCoord(), b.getYCoord(), b.getZCoord(), b.getWorld()); + } + public String getLocationString() { return "[X: "+this.xPos+"][Y: "+this.yPos+"][Z: "+this.zPos+"][Dim: "+this.dim+"]"; } diff --git a/src/Java/gtPlusPlus/core/common/CommonProxy.java b/src/Java/gtPlusPlus/core/common/CommonProxy.java index bea8633a88..c9ea0f3e5b 100644 --- a/src/Java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/Java/gtPlusPlus/core/common/CommonProxy.java @@ -25,7 +25,6 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.CORE.ConfigSwitches; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.Material; -import gtPlusPlus.core.recipe.RECIPES_Old_Circuits; import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.tileentities.ModTileEntities; import gtPlusPlus.core.util.Utils; @@ -33,6 +32,7 @@ import gtPlusPlus.core.util.debug.DEBUG_INIT; import gtPlusPlus.core.util.player.PlayerCache; import gtPlusPlus.plugin.villagers.block.BlockGenericSpawner; import gtPlusPlus.xmod.eio.handler.HandlerTooltip_EIO; +import gtPlusPlus.xmod.galacticraft.handler.HandlerTooltip_GC; import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; import net.minecraftforge.common.ForgeChunkManager; @@ -138,6 +138,8 @@ public class CommonProxy { Utils.registerEvent(new GeneralTooltipEventHandler()); //Handles Custom tooltips for EIO. Utils.registerEvent(new HandlerTooltip_EIO()); + //Handles Custom Tooltips for GC + Utils.registerEvent(new HandlerTooltip_GC()); //Register Chunkloader ForgeChunkManager.setForcedChunkLoadingCallback(GTplusplus.instance, ChunkManager.getInstance()); diff --git a/src/Java/gtPlusPlus/core/item/chemistry/RocketFuels.java b/src/Java/gtPlusPlus/core/item/chemistry/RocketFuels.java index b886d780a9..6b1a006098 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/RocketFuels.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/RocketFuels.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.HashSet; import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; import gregtech.api.util.Recipe_GT; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.item.ModItems; @@ -309,11 +310,11 @@ public class RocketFuels { new ItemStack[] {}, null, new int[] {}, - new FluidStack[] {FluidUtils.getFluidStack(Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 1000)}, + new FluidStack[] {FluidUtils.getFluidStack(Dense_Hydrazine_Mix, 1000)}, new FluidStack[] {}, 0, 0, - 1024)); //Fuel Value + 512)); //Fuel Value mRocketFuels.put(new Recipe_GT( true, @@ -321,11 +322,11 @@ public class RocketFuels { new ItemStack[] {}, null, new int[] {}, - new FluidStack[] {FluidUtils.getFluidStack(Dense_Hydrazine_Mix, 1000)}, + new FluidStack[] {FluidUtils.getFluidStack(Monomethylhydrazine_Plus_Nitric_Acid, 1000)}, new FluidStack[] {}, 0, 0, - 512)); //Fuel Value + 768)); //Fuel Value mRocketFuels.put(new Recipe_GT( true, @@ -333,11 +334,16 @@ public class RocketFuels { new ItemStack[] {}, null, new int[] {}, - new FluidStack[] {FluidUtils.getFluidStack(Monomethylhydrazine_Plus_Nitric_Acid, 1000)}, + new FluidStack[] {FluidUtils.getFluidStack(Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 1000)}, new FluidStack[] {}, 0, 0, - 768)); //Fuel Value + 1024)); //Fuel Value + + + //Add in default Diesel for the Buggy + mValidRocketFuelNames.add(Materials.Fuel.getFluid(1).getFluid().getName()); + mValidRocketFuels.put(-1, Materials.Fuel.getFluid(1).getFluid()); int mID = 0; for (Recipe_GT r : mRocketFuels) { diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter.java new file mode 100644 index 0000000000..9443da2ccc --- /dev/null +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter.java @@ -0,0 +1,177 @@ +package gtPlusPlus.preloader.asm.transformers; + +import static org.objectweb.asm.Opcodes.*; + +import java.io.IOException; +import java.util.ArrayList; + +import org.apache.logging.log4j.Level; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; + +import com.google.common.base.Strings; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +import cofh.core.util.oredict.OreDictionaryArbiter; +import cofh.lib.util.ItemWrapper; +import cpw.mods.fml.relauncher.FMLRelaunchLog; +import gnu.trove.map.TMap; +import gnu.trove.map.hash.THashMap; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.preloader.DevHelper; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +public class ClassTransformer_COFH_OreDictionaryArbiter { + + //The qualified name of the class we plan to transform. + private static final String className = "cofh.core.util.oredict.OreDictionaryArbiter"; + //cofh/core/util/oredict/OreDictionaryArbiter + + private final boolean isValid; + private final ClassReader reader; + private final ClassWriter writer; + private final boolean isObfuscated; + + public ClassTransformer_COFH_OreDictionaryArbiter(byte[] basicClass, boolean obfuscated) { + ClassReader aTempReader = null; + ClassWriter aTempWriter = null; + isObfuscated = obfuscated; + try { + aTempReader = new ClassReader(className); + aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES); + new ClassReader(basicClass).accept(new localClassVisitor(aTempWriter), 0); + } catch (IOException e) {} + if (aTempReader != null && aTempWriter != null) { + isValid = true; + } + else { + isValid = false; + } + reader = aTempReader; + writer = aTempWriter; + + if (reader != null && writer != null) { + injectMethod("registerOreDictionaryEntry"); + } + + } + + public boolean isValidTransformer() { + return isValid; + } + + public ClassReader getReader() { + return reader; + } + + public ClassWriter getWriter() { + return writer; + } + + public void injectMethod(String aMethodName) { + String aItemStack = isObfuscated ? DevHelper.getObfuscated("net/minecraft/item/ItemStack") : "net/minecraft/item/ItemStack"; + MethodVisitor mv; + if (aMethodName.equals("registerOreDictionaryEntry")) { + FMLRelaunchLog.log("[GT++ ASM] COFH OreDictionaryArbiter Patch", Level.INFO, "Injecting "+aMethodName+" into "+className+"."); + mv = getWriter().visitMethod(ACC_PUBLIC + ACC_STATIC, "registerOreDictionaryEntry", "(L"+aItemStack+";Ljava/lang/String;)V", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(61, l0); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter$FixCOFH", "registerOreDictionaryEntry", "(L"+aItemStack+";Ljava/lang/String;)V", false); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLineNumber(62, l1); + mv.visitInsn(RETURN); + Label l2 = new Label(); + mv.visitLabel(l2); + mv.visitLocalVariable("arg", "L"+aItemStack+";", null, l0, l2, 0); + mv.visitLocalVariable("arg0", "Ljava/lang/String;", null, l0, l2, 1); + mv.visitMaxs(2, 2); + mv.visitEnd(); + } + FMLRelaunchLog.log("[GT++ ASM] COFH OreDictionaryArbiter Patch", Level.INFO, "Method injection complete."); + + } + + public static final class localClassVisitor extends ClassVisitor { + + public localClassVisitor(ClassVisitor cv) { + super(ASM5, cv); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + if (name.equals("registerOreDictionaryEntry")) { + FMLRelaunchLog.log("[GT++ ASM] COFH OreDictionaryArbiter Patch", Level.INFO, "Removing method "+name); + return null; + } + MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); + return methodVisitor; + } + } + + + + + @SuppressWarnings("unchecked") + public static class FixCOFH{ + + private static BiMap<String, Integer> oreIDs; + private static TMap<Integer, ArrayList<ItemStack>> oreStacks; + private static TMap<ItemWrapper, ArrayList<Integer>> stackIDs; + private static TMap<ItemWrapper, ArrayList<String>> stackNames; + + static { + try { + oreIDs = (BiMap<String, Integer>) ReflectionUtils.getField(OreDictionaryArbiter.class, "oreIDs").get(null); + oreStacks = (TMap<Integer, ArrayList<ItemStack>>) ReflectionUtils.getField(OreDictionaryArbiter.class, "oreStacks").get(null); + stackIDs = (TMap<ItemWrapper, ArrayList<Integer>>) ReflectionUtils.getField(OreDictionaryArbiter.class, "stackIDs").get(null); + stackNames = (TMap<ItemWrapper, ArrayList<String>>) ReflectionUtils.getField(OreDictionaryArbiter.class, "stackNames").get(null); + } + catch (Throwable t) { + oreIDs = HashBiMap.create(); + oreStacks = new THashMap<Integer, ArrayList<ItemStack>>(); + stackIDs = new THashMap<ItemWrapper, ArrayList<Integer>>(); + stackNames = new THashMap<ItemWrapper, ArrayList<String>>(); + } + } + + public static void registerOreDictionaryEntry(ItemStack arg, String arg0) { + try { + if (arg == null) { + return; + } + if (arg.getItem() != null && !Strings.isNullOrEmpty(arg0)) { + int arg1 = OreDictionary.getOreID(arg0); + oreIDs.put(arg0, Integer.valueOf(arg1)); + if (!oreStacks.containsKey(Integer.valueOf(arg1))) { + oreStacks.put(Integer.valueOf(arg1), new ArrayList<ItemStack>()); + } + ((ArrayList<ItemStack>) oreStacks.get(Integer.valueOf(arg1))).add(arg); + ItemWrapper arg2 = ItemWrapper.fromItemStack(arg); + if (!stackIDs.containsKey(arg2)) { + stackIDs.put(arg2, new ArrayList<Integer>()); + stackNames.put(arg2, new ArrayList<String>()); + } + ((ArrayList<Integer>) stackIDs.get(arg2)).add(Integer.valueOf(arg1)); + ((ArrayList<String>) stackNames.get(arg2)).add(arg0); + } + } + catch (Throwable t) { + return; + } + } + } + + + + +} diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_EntityAutoRocket.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_EntityAutoRocket.java new file mode 100644 index 0000000000..0e43d8a1b9 --- /dev/null +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_EntityAutoRocket.java @@ -0,0 +1,508 @@ +package gtPlusPlus.preloader.asm.transformers; + +import static org.objectweb.asm.Opcodes.*; + +import java.io.IOException; +import org.apache.logging.log4j.Level; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; + +import cpw.mods.fml.relauncher.FMLRelaunchLog; +import gtPlusPlus.preloader.DevHelper; + + +public class ClassTransformer_GC_EntityAutoRocket { + + //The qualified name of the class we plan to transform. + private static final String className = "micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket"; + //micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket + + private final boolean isValid; + private final ClassReader reader; + private final ClassWriter writer; + private final boolean isObfuscated; + + public ClassTransformer_GC_EntityAutoRocket(byte[] basicClass, boolean obfuscated) { + ClassReader aTempReader = null; + ClassWriter aTempWriter = null; + isObfuscated = obfuscated; + try { + aTempReader = new ClassReader(className); + aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES); + new ClassReader(basicClass).accept(new localClassVisitor(aTempWriter), 0); + } catch (IOException e) { + e.printStackTrace(); + } + if (aTempReader != null && aTempWriter != null) { + isValid = true; + } + else { + isValid = false; + } + reader = aTempReader; + writer = aTempWriter; + + if (reader != null && writer != null) { + injectMethod(); + } + else { + FMLRelaunchLog.log("[GT++ ASM] Galacticraft EntityAutoRocket Patch", Level.INFO, "Failed to Inject new code."); + } + + } + + public boolean isValidTransformer() { + return isValid; + } + + public ClassReader getReader() { + return reader; + } + + public ClassWriter getWriter() { + return writer; + } + + public void injectMethod() { + + String aEntityPlayer = isObfuscated ? DevHelper.getObfuscated("net/minecraft/entity/player/EntityPlayer") : "net/minecraft/entity/player/EntityPlayer"; + String aEntityPlayerMP = isObfuscated ? DevHelper.getObfuscated("net/minecraft/entity/player/EntityPlayerMP") : "net/minecraft/entity/player/EntityPlayerMP"; + String aWorld = isObfuscated ? DevHelper.getObfuscated("net/minecraft/world/World") : "net/minecraft/world/World"; + String aItemStack = isObfuscated ? DevHelper.getObfuscated("net/minecraft/item/ItemStack") : "net/minecraft/item/ItemStack"; + String aEntity = isObfuscated ? DevHelper.getObfuscated("net/minecraft/entity/Entity") : "net/minecraft/entity/Entity"; + String aWorldClient = isObfuscated ? DevHelper.getObfuscated("net/minecraft/client/multiplayer/WorldClient") : "net/minecraft/client/multiplayer/WorldClient"; + String aDifficultyEnum = isObfuscated ? DevHelper.getObfuscated("net/minecraft/world/EnumDifficulty") : "net/minecraft/world/EnumDifficulty"; + String aWorldInfo = isObfuscated ? DevHelper.getObfuscated("net/minecraft/world/storage/WorldInfo") : "net/minecraft/world/storage/WorldInfo"; + String aItemInWorldManager = isObfuscated ? DevHelper.getObfuscated("net/minecraft/server/management/ItemInWorldManager") : "net/minecraft/server/management/ItemInWorldManager"; + + if (isValidTransformer()) { + FMLRelaunchLog.log("[GT++ ASM] Galacticraft EntityAutoRocket Patch", Level.INFO, "Injecting decodePacketdata into "+className+"."); + MethodVisitor mv = getWriter().visitMethod(ACC_PUBLIC, "decodePacketdata", "(Lio/netty/buffer/ByteBuf;)V", null, null); + + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(1027, l0); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKESPECIAL, "micdoodle8/mods/galacticraft/api/prefab/entity/EntitySpaceshipBase", "decodePacketdata", "(Lio/netty/buffer/ByteBuf;)V", false); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLineNumber(1028, l1); + mv.visitTypeInsn(NEW, "net/minecraftforge/fluids/FluidStack"); + mv.visitInsn(DUP); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/xmod/galacticraft/util/GalacticUtils", "getValidFuelForTier", "(L"+aEntity+";)Lnet/minecraftforge/fluids/FluidStack;", false); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitMethodInsn(INVOKESPECIAL, "net/minecraftforge/fluids/FluidStack", "<init>", "(Lnet/minecraftforge/fluids/FluidStack;I)V", false); + mv.visitVarInsn(ASTORE, 2); + Label l2 = new Label(); + mv.visitLabel(l2); + mv.visitLineNumber(1029, l2); + mv.visitVarInsn(ALOAD, 2); + Label l3 = new Label(); + mv.visitJumpInsn(IFNULL, l3); + Label l4 = new Label(); + mv.visitLabel(l4); + mv.visitLineNumber(1030, l4); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); + mv.visitVarInsn(ALOAD, 2); + mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraftforge/fluids/FluidTank", "setFluid", "(Lnet/minecraftforge/fluids/FluidStack;)V", false); + mv.visitLabel(l3); + mv.visitLineNumber(1032, l3); + mv.visitFrame(F_APPEND,1, new Object[] {"net/minecraftforge/fluids/FluidStack"}, 0, null); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readBoolean", "()Z", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "landing", "Z"); + Label l5 = new Label(); + mv.visitLabel(l5); + mv.visitLineNumber(1033, l5); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "destinationFrequency", "I"); + Label l6 = new Label(); + mv.visitLabel(l6); + mv.visitLineNumber(1035, l6); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readBoolean", "()Z", false); + Label l7 = new Label(); + mv.visitJumpInsn(IFEQ, l7); + Label l8 = new Label(); + mv.visitLabel(l8); + mv.visitLineNumber(1037, l8); + mv.visitVarInsn(ALOAD, 0); + mv.visitTypeInsn(NEW, "micdoodle8/mods/galacticraft/api/vector/BlockVec3"); + mv.visitInsn(DUP); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitMethodInsn(INVOKESPECIAL, "micdoodle8/mods/galacticraft/api/vector/BlockVec3", "<init>", "(III)V", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "targetVec", "Lmicdoodle8/mods/galacticraft/api/vector/BlockVec3;"); + mv.visitLabel(l7); + mv.visitLineNumber(1040, l7); + mv.visitFrame(F_SAME, 0, null, 0, null); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readDouble", "()D", false); + mv.visitLdcInsn(new Double("8000.0")); + mv.visitInsn(DDIV); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "motionX", "D"); + Label l9 = new Label(); + mv.visitLabel(l9); + mv.visitLineNumber(1041, l9); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readDouble", "()D", false); + mv.visitLdcInsn(new Double("8000.0")); + mv.visitInsn(DDIV); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "motionY", "D"); + Label l10 = new Label(); + mv.visitLabel(l10); + mv.visitLineNumber(1042, l10); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readDouble", "()D", false); + mv.visitLdcInsn(new Double("8000.0")); + mv.visitInsn(DDIV); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "motionZ", "D"); + Label l11 = new Label(); + mv.visitLabel(l11); + mv.visitLineNumber(1043, l11); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readDouble", "()D", false); + mv.visitLdcInsn(new Double("8000.0")); + mv.visitInsn(DDIV); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "lastMotionY", "D"); + Label l12 = new Label(); + mv.visitLabel(l12); + mv.visitLineNumber(1044, l12); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readDouble", "()D", false); + mv.visitLdcInsn(new Double("8000.0")); + mv.visitInsn(DDIV); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "lastLastMotionY", "D"); + Label l13 = new Label(); + mv.visitLabel(l13); + mv.visitLineNumber(1046, l13); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "cargoItems", "[L"+aItemStack+";"); + Label l14 = new Label(); + mv.visitJumpInsn(IFNONNULL, l14); + Label l15 = new Label(); + mv.visitLabel(l15); + mv.visitLineNumber(1048, l15); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKEVIRTUAL, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "getSizeInventory", "()I", false); + mv.visitTypeInsn(ANEWARRAY, ""+aItemStack+""); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "cargoItems", "[L"+aItemStack+";"); + mv.visitLabel(l14); + mv.visitLineNumber(1051, l14); + mv.visitFrame(F_SAME, 0, null, 0, null); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readBoolean", "()Z", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "setWaitForPlayer", "(Z)V", false); + Label l16 = new Label(); + mv.visitLabel(l16); + mv.visitLineNumber(1053, l16); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, "cpw/mods/fml/common/network/ByteBufUtils", "readUTF8String", "(Lio/netty/buffer/ByteBuf;)Ljava/lang/String;", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusMessage", "Ljava/lang/String;"); + Label l17 = new Label(); + mv.visitLabel(l17); + mv.visitLineNumber(1054, l17); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusMessage", "Ljava/lang/String;"); + mv.visitLdcInsn(""); + mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); + Label l18 = new Label(); + mv.visitJumpInsn(IFEQ, l18); + mv.visitInsn(ACONST_NULL); + Label l19 = new Label(); + mv.visitJumpInsn(GOTO, l19); + mv.visitLabel(l18); + mv.visitFrame(F_SAME1, 0, null, 1, new Object[] {"micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket"}); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusMessage", "Ljava/lang/String;"); + mv.visitLabel(l19); + mv.visitFrame(F_FULL, 3, new Object[] {"micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "io/netty/buffer/ByteBuf", "net/minecraftforge/fluids/FluidStack"}, 2, new Object[] {"micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "java/lang/String"}); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusMessage", "Ljava/lang/String;"); + Label l20 = new Label(); + mv.visitLabel(l20); + mv.visitLineNumber(1055, l20); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusMessageCooldown", "I"); + Label l21 = new Label(); + mv.visitLabel(l21); + mv.visitLineNumber(1056, l21); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "lastStatusMessageCooldown", "I"); + Label l22 = new Label(); + mv.visitLabel(l22); + mv.visitLineNumber(1057, l22); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readBoolean", "()Z", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusValid", "Z"); + Label l23 = new Label(); + mv.visitLabel(l23); + mv.visitLineNumber(1060, l23); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "worldObj", "L"+aWorld+";"); + mv.visitFieldInsn(GETFIELD, ""+aWorld+"", "isRemote", "Z"); + Label l24 = new Label(); + mv.visitJumpInsn(IFEQ, l24); + Label l25 = new Label(); + mv.visitLabel(l25); + mv.visitLineNumber(1062, l25); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKEVIRTUAL, "io/netty/buffer/ByteBuf", "readInt", "()I", false); + mv.visitVarInsn(ISTORE, 3); + Label l26 = new Label(); + mv.visitLabel(l26); + mv.visitLineNumber(1063, l26); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "riddenByEntity", "L"+aEntity+";"); + Label l27 = new Label(); + mv.visitJumpInsn(IFNONNULL, l27); + Label l28 = new Label(); + mv.visitLabel(l28); + mv.visitLineNumber(1065, l28); + mv.visitVarInsn(ILOAD, 3); + mv.visitInsn(ICONST_M1); + mv.visitJumpInsn(IF_ICMPLE, l24); + Label l29 = new Label(); + mv.visitLabel(l29); + mv.visitLineNumber(1067, l29); + mv.visitMethodInsn(INVOKESTATIC, "cpw/mods/fml/client/FMLClientHandler", "instance", "()Lcpw/mods/fml/client/FMLClientHandler;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "cpw/mods/fml/client/FMLClientHandler", "getWorldClient", "()L"+aWorldClient+";", false); + mv.visitVarInsn(ILOAD, 3); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorldClient+"", "getEntityByID", "(I)L"+aEntity+";", false); + mv.visitVarInsn(ASTORE, 4); + Label l30 = new Label(); + mv.visitLabel(l30); + mv.visitLineNumber(1068, l30); + mv.visitVarInsn(ALOAD, 4); + mv.visitJumpInsn(IFNULL, l24); + Label l31 = new Label(); + mv.visitLabel(l31); + mv.visitLineNumber(1070, l31); + mv.visitVarInsn(ALOAD, 4); + mv.visitFieldInsn(GETFIELD, ""+aEntity+"", "dimension", "I"); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "dimension", "I"); + Label l32 = new Label(); + mv.visitJumpInsn(IF_ICMPEQ, l32); + Label l33 = new Label(); + mv.visitLabel(l33); + mv.visitLineNumber(1072, l33); + mv.visitVarInsn(ALOAD, 4); + mv.visitTypeInsn(INSTANCEOF, ""+aEntityPlayer+""); + mv.visitJumpInsn(IFEQ, l24); + Label l34 = new Label(); + mv.visitLabel(l34); + mv.visitLineNumber(1074, l34); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "dimension", "I"); + mv.visitVarInsn(ALOAD, 4); + mv.visitFieldInsn(GETFIELD, ""+aEntity+"", "worldObj", "L"+aWorld+";"); + mv.visitFieldInsn(GETFIELD, ""+aWorld+"", "difficultySetting", "L"+aDifficultyEnum+";"); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aDifficultyEnum+"", "getDifficultyId", "()I", false); + mv.visitVarInsn(ALOAD, 4); + mv.visitFieldInsn(GETFIELD, ""+aEntity+"", "worldObj", "L"+aWorld+";"); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorld+"", "getWorldInfo", "()L"+aWorldInfo+";", false); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorldInfo+"", "getTerrainType", "()L"+aWorld+"Type;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorld+"Type", "getWorldTypeName", "()Ljava/lang/String;", false); + mv.visitVarInsn(ALOAD, 4); + mv.visitTypeInsn(CHECKCAST, ""+aEntityPlayerMP+""); + mv.visitFieldInsn(GETFIELD, ""+aEntityPlayerMP+"", "theItemInWorldManager", "L"+aItemInWorldManager+";"); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aItemInWorldManager+"", "getGameType", "()L"+aWorld+"Settings$GameType;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorld+"Settings$GameType", "getID", "()I", false); + mv.visitMethodInsn(INVOKESTATIC, "micdoodle8/mods/galacticraft/core/util/WorldUtil", "forceRespawnClient", "(IILjava/lang/String;I)L"+aEntityPlayer+";", false); + mv.visitVarInsn(ASTORE, 4); + Label l35 = new Label(); + mv.visitLabel(l35); + mv.visitLineNumber(1075, l35); + mv.visitVarInsn(ALOAD, 4); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aEntity+"", "mountEntity", "(L"+aEntity+";)V", false); + Label l36 = new Label(); + mv.visitLabel(l36); + mv.visitLineNumber(1077, l36); + mv.visitJumpInsn(GOTO, l24); + mv.visitLabel(l32); + mv.visitLineNumber(1079, l32); + mv.visitFrame(F_APPEND,2, new Object[] {INTEGER, ""+aEntity+""}, 0, null); + mv.visitVarInsn(ALOAD, 4); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aEntity+"", "mountEntity", "(L"+aEntity+";)V", false); + Label l37 = new Label(); + mv.visitLabel(l37); + mv.visitLineNumber(1082, l37); + mv.visitJumpInsn(GOTO, l24); + mv.visitLabel(l27); + mv.visitLineNumber(1083, l27); + mv.visitFrame(F_CHOP,1, null, 0, null); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "riddenByEntity", "L"+aEntity+";"); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aEntity+"", "getEntityId", "()I", false); + mv.visitVarInsn(ILOAD, 3); + mv.visitJumpInsn(IF_ICMPEQ, l24); + Label l38 = new Label(); + mv.visitLabel(l38); + mv.visitLineNumber(1085, l38); + mv.visitVarInsn(ILOAD, 3); + mv.visitInsn(ICONST_M1); + Label l39 = new Label(); + mv.visitJumpInsn(IF_ICMPNE, l39); + Label l40 = new Label(); + mv.visitLabel(l40); + mv.visitLineNumber(1087, l40); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "riddenByEntity", "L"+aEntity+";"); + mv.visitInsn(ACONST_NULL); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aEntity+"", "mountEntity", "(L"+aEntity+";)V", false); + Label l41 = new Label(); + mv.visitLabel(l41); + mv.visitLineNumber(1088, l41); + mv.visitJumpInsn(GOTO, l24); + mv.visitLabel(l39); + mv.visitLineNumber(1091, l39); + mv.visitFrame(F_SAME, 0, null, 0, null); + mv.visitMethodInsn(INVOKESTATIC, "cpw/mods/fml/client/FMLClientHandler", "instance", "()Lcpw/mods/fml/client/FMLClientHandler;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "cpw/mods/fml/client/FMLClientHandler", "getWorldClient", "()L"+aWorldClient+";", false); + mv.visitVarInsn(ILOAD, 3); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorldClient+"", "getEntityByID", "(I)L"+aEntity+";", false); + mv.visitVarInsn(ASTORE, 4); + Label l42 = new Label(); + mv.visitLabel(l42); + mv.visitLineNumber(1092, l42); + mv.visitVarInsn(ALOAD, 4); + mv.visitJumpInsn(IFNULL, l24); + Label l43 = new Label(); + mv.visitLabel(l43); + mv.visitLineNumber(1094, l43); + mv.visitVarInsn(ALOAD, 4); + mv.visitFieldInsn(GETFIELD, ""+aEntity+"", "dimension", "I"); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "dimension", "I"); + Label l44 = new Label(); + mv.visitJumpInsn(IF_ICMPEQ, l44); + Label l45 = new Label(); + mv.visitLabel(l45); + mv.visitLineNumber(1096, l45); + mv.visitVarInsn(ALOAD, 4); + mv.visitTypeInsn(INSTANCEOF, ""+aEntityPlayer+""); + mv.visitJumpInsn(IFEQ, l24); + Label l46 = new Label(); + mv.visitLabel(l46); + mv.visitLineNumber(1098, l46); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "dimension", "I"); + mv.visitVarInsn(ALOAD, 4); + mv.visitFieldInsn(GETFIELD, ""+aEntity+"", "worldObj", "L"+aWorld+";"); + mv.visitFieldInsn(GETFIELD, ""+aWorld+"", "difficultySetting", "L"+aDifficultyEnum+";"); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aDifficultyEnum+"", "getDifficultyId", "()I", false); + mv.visitVarInsn(ALOAD, 4); + mv.visitFieldInsn(GETFIELD, ""+aEntity+"", "worldObj", "L"+aWorld+";"); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorld+"", "getWorldInfo", "()L"+aWorldInfo+";", false); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorldInfo+"", "getTerrainType", "()L"+aWorld+"Type;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorld+"Type", "getWorldTypeName", "()Ljava/lang/String;", false); + mv.visitVarInsn(ALOAD, 4); + mv.visitTypeInsn(CHECKCAST, ""+aEntityPlayerMP+""); + mv.visitFieldInsn(GETFIELD, ""+aEntityPlayerMP+"", "theItemInWorldManager", "L"+aItemInWorldManager+";"); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aItemInWorldManager+"", "getGameType", "()L"+aWorld+"Settings$GameType;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aWorld+"Settings$GameType", "getID", "()I", false); + mv.visitMethodInsn(INVOKESTATIC, "micdoodle8/mods/galacticraft/core/util/WorldUtil", "forceRespawnClient", "(IILjava/lang/String;I)L"+aEntityPlayer+";", false); + mv.visitVarInsn(ASTORE, 4); + Label l47 = new Label(); + mv.visitLabel(l47); + mv.visitLineNumber(1099, l47); + mv.visitVarInsn(ALOAD, 4); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aEntity+"", "mountEntity", "(L"+aEntity+";)V", false); + Label l48 = new Label(); + mv.visitLabel(l48); + mv.visitLineNumber(1101, l48); + mv.visitJumpInsn(GOTO, l24); + mv.visitLabel(l44); + mv.visitLineNumber(1103, l44); + mv.visitFrame(F_APPEND,1, new Object[] {""+aEntity+""}, 0, null); + mv.visitVarInsn(ALOAD, 4); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKEVIRTUAL, ""+aEntity+"", "mountEntity", "(L"+aEntity+";)V", false); + mv.visitLabel(l24); + mv.visitLineNumber(1108, l24); + mv.visitFrame(F_CHOP,2, null, 0, null); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, "cpw/mods/fml/common/network/ByteBufUtils", "readUTF8String", "(Lio/netty/buffer/ByteBuf;)Ljava/lang/String;", false); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusColour", "Ljava/lang/String;"); + Label l49 = new Label(); + mv.visitLabel(l49); + mv.visitLineNumber(1109, l49); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusColour", "Ljava/lang/String;"); + mv.visitLdcInsn(""); + mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false); + Label l50 = new Label(); + mv.visitJumpInsn(IFEQ, l50); + mv.visitVarInsn(ALOAD, 0); + mv.visitInsn(ACONST_NULL); + mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket", "statusColour", "Ljava/lang/String;"); + mv.visitLabel(l50); + mv.visitLineNumber(1110, l50); + mv.visitFrame(F_SAME, 0, null, 0, null); + mv.visitInsn(RETURN); + Label l51 = new Label(); + mv.visitLabel(l51); + mv.visitLocalVariable("this", "Lmicdoodle8/mods/galacticraft/api/prefab/entity/EntityAutoRocket;", null, l0, l51, 0); + mv.visitLocalVariable("buffer", "Lio/netty/buffer/ByteBuf;", null, l0, l51, 1); + mv.visitLocalVariable("s", "Lnet/minecraftforge/fluids/FluidStack;", null, l2, l51, 2); + mv.visitLocalVariable("shouldBeMountedId", "I", null, l26, l24, 3); + mv.visitLocalVariable("e", "L"+aEntity+";", null, l30, l37, 4); + mv.visitLocalVariable("e", "L"+aEntity+";", null, l42, l24, 4); + mv.visitMaxs(6, 5); + mv.visitEnd(); + + } + } + + public static final class localClassVisitor extends ClassVisitor { + + public localClassVisitor(ClassVisitor cv) { + super(ASM5, cv); + FMLRelaunchLog.log("[GT++ ASM] Galacticraft EntityAutoRocket Patch", Level.INFO, "Inspecting Class "+className); + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + if (name.equals("decodePacketdata")) { + FMLRelaunchLog.log("[GT++ ASM] Galacticraft EntityAutoRocket Patch", Level.INFO, "Removing method "+name); + return null; + } + MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); + return methodVisitor; + } + } + +} diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FluidUtil.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FluidUtil.java index d3c20f4b4a..a54ed79e35 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FluidUtil.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FluidUtil.java @@ -23,9 +23,9 @@ public class ClassTransformer_GC_FluidUtil { private final ClassReader reader; private final ClassWriter writer; - public ClassTransformer_GC_FluidUtil(byte[] basicClass) { + public ClassTransformer_GC_FluidUtil(byte[] basicClass, boolean obfuscated) { ClassReader aTempReader = null; - ClassWriter aTempWriter = null; + ClassWriter aTempWriter = null; try { aTempReader = new ClassReader(className); aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES); @@ -60,10 +60,6 @@ public class ClassTransformer_GC_FluidUtil { } public void injectMethod(String aMethodName) { - /*String aConstructorTypes = (aMethodName.equals("testFuel") ? "(Ljava/lang/String;)Z" : (aMethodName.equals("fillWithGCFuel") ? "(Lnet/minecraftforge/fluids/FluidTank;Lnet/minecraftforge/fluids/FluidStack;Z)I\"" : "error")); - if (aConstructorTypes.equals("error")) { - return; - } */ MethodVisitor mv; if (aMethodName.equals("testFuel")) { FMLRelaunchLog.log("[GT++ ASM] Galacticraft FluidUtils Patch", Level.INFO, "Injecting "+aMethodName+" into "+className+"."); diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FuelLoader.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FuelLoader.java index 7e58cecce3..ae24546f0a 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FuelLoader.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GC_FuelLoader.java @@ -11,6 +11,7 @@ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import cpw.mods.fml.relauncher.FMLRelaunchLog; +import gtPlusPlus.preloader.DevHelper; public class ClassTransformer_GC_FuelLoader { @@ -22,10 +23,12 @@ public class ClassTransformer_GC_FuelLoader { private final boolean isValid; private final ClassReader reader; private final ClassWriter writer; + private final boolean isObfuscated; - public ClassTransformer_GC_FuelLoader(byte[] basicClass) { + public ClassTransformer_GC_FuelLoader(byte[] basicClass, boolean obfuscated) { ClassReader aTempReader = null; ClassWriter aTempWriter = null; + isObfuscated = obfuscated; try { aTempReader = new ClassReader(className); aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES); @@ -64,69 +67,71 @@ public class ClassTransformer_GC_FuelLoader { } public void injectMethod() { + String aWorld = isObfuscated ? DevHelper.getObfuscated("net/minecraft/world/World") : "net/minecraft/world/World"; + String aItemStack = isObfuscated ? DevHelper.getObfuscated("net/minecraft/item/ItemStack") : "net/minecraft/item/ItemStack"; + String aTileEntity = isObfuscated ? DevHelper.getObfuscated("net/minecraft/tileentity/TileEntity") : "net/minecraft/tileentity/TileEntity"; + if (isValidTransformer()) { FMLRelaunchLog.log("[GT++ ASM] Galacticraft Fuel_Loader Patch", Level.INFO, "Injecting updateEntity into "+className+"."); MethodVisitor mv = getWriter().visitMethod(ACC_PUBLIC, "updateEntity", "()V", null, null); - - if (true) { mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); - mv.visitLineNumber(59, l0); + mv.visitLineNumber(60, l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "micdoodle8/mods/galacticraft/core/energy/tile/TileBaseElectricBlockWithInventory", "updateEntity", "()V", false); Label l1 = new Label(); mv.visitLabel(l1); - mv.visitLineNumber(60, l1); + mv.visitLineNumber(61, l1); mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "worldObj", "Lnet/minecraft/world/World;"); - mv.visitFieldInsn(GETFIELD, "net/minecraft/world/World", "isRemote", "Z"); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "worldObj", "L"+aWorld+";"); + mv.visitFieldInsn(GETFIELD, ""+aWorld+"", "isRemote", "Z"); Label l2 = new Label(); mv.visitJumpInsn(IFNE, l2); Label l3 = new Label(); mv.visitLabel(l3); - mv.visitLineNumber(61, l3); + mv.visitLineNumber(62, l3); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_0); mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "loadedFuelLastTick", "Z"); Label l4 = new Label(); mv.visitLabel(l4); - mv.visitLineNumber(62, l4); + mv.visitLineNumber(63, l4); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ASTORE, 1); Label l5 = new Label(); mv.visitLabel(l5); - mv.visitLineNumber(65, l5); + mv.visitLineNumber(66, l5); mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[Lnet/minecraft/item/ItemStack;"); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[L"+aItemStack+";"); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); Label l6 = new Label(); mv.visitJumpInsn(IFNULL, l6); Label l7 = new Label(); mv.visitLabel(l7); - mv.visitLineNumber(66, l7); + mv.visitLineNumber(67, l7); mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[Lnet/minecraft/item/ItemStack;"); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[L"+aItemStack+";"); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); - mv.visitMethodInsn(INVOKESTATIC, "net/minecraftforge/fluids/FluidContainerRegistry", "getFluidForFilledItem", "(Lnet/minecraft/item/ItemStack;)Lnet/minecraftforge/fluids/FluidStack;", false); + mv.visitMethodInsn(INVOKESTATIC, "net/minecraftforge/fluids/FluidContainerRegistry", "getFluidForFilledItem", "(L"+aItemStack+";)Lnet/minecraftforge/fluids/FluidStack;", false); mv.visitVarInsn(ASTORE, 1); Label l8 = new Label(); mv.visitLabel(l8); - mv.visitLineNumber(67, l8); + mv.visitLineNumber(68, l8); mv.visitVarInsn(ALOAD, 1); mv.visitJumpInsn(IFNULL, l6); Label l9 = new Label(); mv.visitLabel(l9); - mv.visitLineNumber(68, l9); + mv.visitLineNumber(69, l9); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "net/minecraftforge/fluids/FluidRegistry", "getFluidName", "(Lnet/minecraftforge/fluids/FluidStack;)Ljava/lang/String;", false); mv.visitMethodInsn(INVOKESTATIC, "micdoodle8/mods/galacticraft/core/util/FluidUtil", "testFuel", "(Ljava/lang/String;)Z", false); mv.visitVarInsn(ISTORE, 4); Label l10 = new Label(); mv.visitLabel(l10); - mv.visitLineNumber(69, l10); + mv.visitLineNumber(70, l10); mv.visitVarInsn(ILOAD, 4); mv.visitJumpInsn(IFEQ, l6); mv.visitVarInsn(ALOAD, 0); @@ -136,7 +141,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(IFNULL, l11); Label l12 = new Label(); mv.visitLabel(l12); - mv.visitLineNumber(70, l12); + mv.visitLineNumber(71, l12); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraftforge/fluids/FluidTank", "getFluid", "()Lnet/minecraftforge/fluids/FluidStack;", false); @@ -149,7 +154,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraftforge/fluids/FluidTank", "getCapacity", "()I", false); mv.visitJumpInsn(IF_ICMPGT, l6); mv.visitLabel(l11); - mv.visitLineNumber(72, l11); + mv.visitLineNumber(73, l11); mv.visitFrame(F_FULL, 5, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, TOP, INTEGER}, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); @@ -157,22 +162,22 @@ public class ClassTransformer_GC_FuelLoader { mv.visitVarInsn(ASTORE, 5); Label l13 = new Label(); mv.visitLabel(l13); - mv.visitLineNumber(73, l13); + mv.visitLineNumber(74, l13); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 6); Label l14 = new Label(); mv.visitLabel(l14); - mv.visitLineNumber(74, l14); + mv.visitLineNumber(75, l14); mv.visitVarInsn(ALOAD, 5); Label l15 = new Label(); mv.visitJumpInsn(IFNONNULL, l15); Label l16 = new Label(); mv.visitLabel(l16); - mv.visitLineNumber(75, l16); + mv.visitLineNumber(76, l16); mv.visitFieldInsn(GETSTATIC, "gtPlusPlus/core/item/chemistry/RocketFuels", "mValidRocketFuels", "Ljava/util/HashMap;"); Label l17 = new Label(); mv.visitLabel(l17); - mv.visitLineNumber(76, l17); + mv.visitLineNumber(77, l17); mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "values", "()Ljava/util/Collection;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Collection", "iterator", "()Ljava/util/Iterator;", true); mv.visitVarInsn(ASTORE, 8); @@ -187,14 +192,14 @@ public class ClassTransformer_GC_FuelLoader { mv.visitVarInsn(ASTORE, 7); Label l20 = new Label(); mv.visitLabel(l20); - mv.visitLineNumber(77, l20); + mv.visitLineNumber(78, l20); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraftforge/fluids/FluidStack", "getFluid", "()Lnet/minecraftforge/fluids/Fluid;", false); mv.visitVarInsn(ALOAD, 7); mv.visitJumpInsn(IF_ACMPNE, l18); Label l21 = new Label(); mv.visitLabel(l21); - mv.visitLineNumber(78, l21); + mv.visitLineNumber(79, l21); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); mv.visitTypeInsn(NEW, "net/minecraftforge/fluids/FluidStack"); @@ -217,18 +222,18 @@ public class ClassTransformer_GC_FuelLoader { mv.visitFrame(F_SAME1, 0, null, 1, new Object[] {INTEGER}); mv.visitVarInsn(ISTORE, 6); mv.visitLabel(l18); - mv.visitLineNumber(75, l18); + mv.visitLineNumber(76, l18); mv.visitFrame(F_FULL, 9, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, TOP, INTEGER, "net/minecraftforge/fluids/FluidStack", INTEGER, TOP, "java/util/Iterator"}, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 8); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true); mv.visitJumpInsn(IFNE, l19); Label l24 = new Label(); mv.visitLabel(l24); - mv.visitLineNumber(81, l24); + mv.visitLineNumber(82, l24); Label l25 = new Label(); mv.visitJumpInsn(GOTO, l25); mv.visitLabel(l15); - mv.visitLineNumber(83, l15); + mv.visitLineNumber(84, l15); mv.visitFrame(F_FULL, 7, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, TOP, INTEGER, "net/minecraftforge/fluids/FluidStack", INTEGER}, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 5); mv.visitFieldInsn(GETFIELD, "net/minecraftforge/fluids/FluidStack", "amount", "I"); @@ -242,7 +247,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(IFEQ, l25); Label l26 = new Label(); mv.visitLabel(l26); - mv.visitLineNumber(84, l26); + mv.visitLineNumber(85, l26); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); mv.visitTypeInsn(NEW, "net/minecraftforge/fluids/FluidStack"); @@ -265,41 +270,41 @@ public class ClassTransformer_GC_FuelLoader { mv.visitFrame(F_SAME1, 0, null, 1, new Object[] {INTEGER}); mv.visitVarInsn(ISTORE, 6); mv.visitLabel(l25); - mv.visitLineNumber(87, l25); + mv.visitLineNumber(88, l25); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, 6); mv.visitJumpInsn(IFEQ, l6); Label l29 = new Label(); mv.visitLabel(l29); - mv.visitLineNumber(88, l29); + mv.visitLineNumber(89, l29); mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[Lnet/minecraft/item/ItemStack;"); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[L"+aItemStack+";"); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitInsn(DUP); - mv.visitFieldInsn(GETFIELD, "net/minecraft/item/ItemStack", "stackSize", "I"); + mv.visitFieldInsn(GETFIELD, ""+aItemStack+"", "stackSize", "I"); mv.visitInsn(ICONST_1); mv.visitInsn(ISUB); - mv.visitFieldInsn(PUTFIELD, "net/minecraft/item/ItemStack", "stackSize", "I"); + mv.visitFieldInsn(PUTFIELD, ""+aItemStack+"", "stackSize", "I"); Label l30 = new Label(); mv.visitLabel(l30); - mv.visitLineNumber(89, l30); + mv.visitLineNumber(90, l30); mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[Lnet/minecraft/item/ItemStack;"); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[L"+aItemStack+";"); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); - mv.visitFieldInsn(GETFIELD, "net/minecraft/item/ItemStack", "stackSize", "I"); + mv.visitFieldInsn(GETFIELD, ""+aItemStack+"", "stackSize", "I"); mv.visitJumpInsn(IFNE, l6); Label l31 = new Label(); mv.visitLabel(l31); - mv.visitLineNumber(90, l31); + mv.visitLineNumber(91, l31); mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[Lnet/minecraft/item/ItemStack;"); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "containingItems", "[L"+aItemStack+";"); mv.visitInsn(ICONST_1); mv.visitInsn(ACONST_NULL); mv.visitInsn(AASTORE); mv.visitLabel(l6); - mv.visitLineNumber(96, l6); + mv.visitLineNumber(97, l6); mv.visitFrame(F_FULL, 2, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack"}, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "ticks", "I"); @@ -309,24 +314,24 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(IFNE, l32); Label l33 = new Label(); mv.visitLabel(l33); - mv.visitLineNumber(97, l33); + mv.visitLineNumber(98, l33); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ACONST_NULL); mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "attachedFuelable", "Lmicdoodle8/mods/galacticraft/api/entity/IFuelable;"); Label l34 = new Label(); mv.visitLabel(l34); - mv.visitLineNumber(98, l34); + mv.visitLineNumber(99, l34); mv.visitFieldInsn(GETSTATIC, "net/minecraftforge/common/util/ForgeDirection", "VALID_DIRECTIONS", "[Lnet/minecraftforge/common/util/ForgeDirection;"); mv.visitVarInsn(ASTORE, 4); Label l35 = new Label(); mv.visitLabel(l35); - mv.visitLineNumber(99, l35); + mv.visitLineNumber(100, l35); mv.visitVarInsn(ALOAD, 4); mv.visitInsn(ARRAYLENGTH); mv.visitVarInsn(ISTORE, 3); Label l36 = new Label(); mv.visitLabel(l36); - mv.visitLineNumber(101, l36); + mv.visitLineNumber(102, l36); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 2); Label l37 = new Label(); @@ -335,7 +340,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(GOTO, l38); Label l39 = new Label(); mv.visitLabel(l39); - mv.visitLineNumber(102, l39); + mv.visitLineNumber(103, l39); mv.visitFrame(F_APPEND,3, new Object[] {INTEGER, INTEGER, "[Lnet/minecraftforge/common/util/ForgeDirection;"}, 0, null); mv.visitVarInsn(ALOAD, 4); mv.visitVarInsn(ILOAD, 2); @@ -343,67 +348,67 @@ public class ClassTransformer_GC_FuelLoader { mv.visitVarInsn(ASTORE, 5); Label l40 = new Label(); mv.visitLabel(l40); - mv.visitLineNumber(103, l40); + mv.visitLineNumber(104, l40); mv.visitTypeInsn(NEW, "micdoodle8/mods/galacticraft/api/vector/BlockVec3"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); - mv.visitMethodInsn(INVOKESPECIAL, "micdoodle8/mods/galacticraft/api/vector/BlockVec3", "<init>", "(Lnet/minecraft/tileentity/TileEntity;)V", false); + mv.visitMethodInsn(INVOKESPECIAL, "micdoodle8/mods/galacticraft/api/vector/BlockVec3", "<init>", "(L"+aTileEntity+";)V", false); mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "worldObj", "Lnet/minecraft/world/World;"); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "worldObj", "L"+aWorld+";"); mv.visitVarInsn(ALOAD, 5); - mv.visitMethodInsn(INVOKEVIRTUAL, "micdoodle8/mods/galacticraft/api/vector/BlockVec3", "getTileEntityOnSide", "(Lnet/minecraft/world/World;Lnet/minecraftforge/common/util/ForgeDirection;)Lnet/minecraft/tileentity/TileEntity;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "micdoodle8/mods/galacticraft/api/vector/BlockVec3", "getTileEntityOnSide", "(L"+aWorld+";Lnet/minecraftforge/common/util/ForgeDirection;)L"+aTileEntity+";", false); mv.visitVarInsn(ASTORE, 6); Label l41 = new Label(); mv.visitLabel(l41); - mv.visitLineNumber(104, l41); + mv.visitLineNumber(105, l41); mv.visitVarInsn(ALOAD, 6); mv.visitTypeInsn(INSTANCEOF, "micdoodle8/mods/galacticraft/core/tile/TileEntityMulti"); Label l42 = new Label(); mv.visitJumpInsn(IFEQ, l42); Label l43 = new Label(); mv.visitLabel(l43); - mv.visitLineNumber(105, l43); + mv.visitLineNumber(106, l43); mv.visitVarInsn(ALOAD, 6); mv.visitTypeInsn(CHECKCAST, "micdoodle8/mods/galacticraft/core/tile/TileEntityMulti"); - mv.visitMethodInsn(INVOKEVIRTUAL, "micdoodle8/mods/galacticraft/core/tile/TileEntityMulti", "getMainBlockTile", "()Lnet/minecraft/tileentity/TileEntity;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "micdoodle8/mods/galacticraft/core/tile/TileEntityMulti", "getMainBlockTile", "()L"+aTileEntity+";", false); mv.visitVarInsn(ASTORE, 7); Label l44 = new Label(); mv.visitLabel(l44); - mv.visitLineNumber(106, l44); + mv.visitLineNumber(107, l44); mv.visitVarInsn(ALOAD, 7); mv.visitTypeInsn(INSTANCEOF, "micdoodle8/mods/galacticraft/api/entity/IFuelable"); Label l45 = new Label(); mv.visitJumpInsn(IFEQ, l45); Label l46 = new Label(); mv.visitLabel(l46); - mv.visitLineNumber(107, l46); + mv.visitLineNumber(108, l46); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 7); mv.visitTypeInsn(CHECKCAST, "micdoodle8/mods/galacticraft/api/entity/IFuelable"); mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "attachedFuelable", "Lmicdoodle8/mods/galacticraft/api/entity/IFuelable;"); Label l47 = new Label(); mv.visitLabel(l47); - mv.visitLineNumber(108, l47); + mv.visitLineNumber(109, l47); mv.visitJumpInsn(GOTO, l32); mv.visitLabel(l42); - mv.visitLineNumber(110, l42); - mv.visitFrame(F_APPEND,2, new Object[] {"net/minecraftforge/common/util/ForgeDirection", "net/minecraft/tileentity/TileEntity"}, 0, null); + mv.visitLineNumber(111, l42); + mv.visitFrame(F_APPEND,2, new Object[] {"net/minecraftforge/common/util/ForgeDirection", ""+aTileEntity+""}, 0, null); mv.visitVarInsn(ALOAD, 6); mv.visitTypeInsn(INSTANCEOF, "micdoodle8/mods/galacticraft/api/entity/IFuelable"); mv.visitJumpInsn(IFEQ, l45); Label l48 = new Label(); mv.visitLabel(l48); - mv.visitLineNumber(111, l48); + mv.visitLineNumber(112, l48); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 6); mv.visitTypeInsn(CHECKCAST, "micdoodle8/mods/galacticraft/api/entity/IFuelable"); mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "attachedFuelable", "Lmicdoodle8/mods/galacticraft/api/entity/IFuelable;"); Label l49 = new Label(); mv.visitLabel(l49); - mv.visitLineNumber(112, l49); + mv.visitLineNumber(113, l49); mv.visitJumpInsn(GOTO, l32); mv.visitLabel(l45); - mv.visitLineNumber(101, l45); + mv.visitLineNumber(102, l45); mv.visitFrame(F_CHOP,2, null, 0, null); mv.visitIincInsn(2, 1); mv.visitLabel(l38); @@ -412,7 +417,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitVarInsn(ILOAD, 3); mv.visitJumpInsn(IF_ICMPLT, l39); mv.visitLabel(l32); - mv.visitLineNumber(116, l32); + mv.visitLineNumber(117, l32); mv.visitFrame(F_CHOP,3, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); @@ -428,20 +433,20 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(IFLE, l2); Label l50 = new Label(); mv.visitLabel(l50); - mv.visitLineNumber(117, l50); + mv.visitLineNumber(118, l50); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraftforge/fluids/FluidTank", "getFluid", "()Lnet/minecraftforge/fluids/FluidStack;", false); mv.visitVarInsn(ASTORE, 4); Label l51 = new Label(); mv.visitLabel(l51); - mv.visitLineNumber(118, l51); + mv.visitLineNumber(119, l51); mv.visitVarInsn(ALOAD, 4); Label l52 = new Label(); mv.visitJumpInsn(IFNONNULL, l52); Label l53 = new Label(); mv.visitLabel(l53); - mv.visitLineNumber(119, l53); + mv.visitLineNumber(120, l53); mv.visitFieldInsn(GETSTATIC, "gtPlusPlus/core/item/chemistry/RocketFuels", "mValidRocketFuels", "Ljava/util/HashMap;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/HashMap", "values", "()Ljava/util/Collection;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Collection", "iterator", "()Ljava/util/Iterator;", true); @@ -457,7 +462,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitVarInsn(ASTORE, 5); Label l56 = new Label(); mv.visitLabel(l56); - mv.visitLineNumber(120, l56); + mv.visitLineNumber(121, l56); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraftforge/fluids/FluidTank", "getFluid", "()Lnet/minecraftforge/fluids/FluidStack;", false); @@ -466,7 +471,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(IF_ACMPNE, l54); Label l57 = new Label(); mv.visitLabel(l57); - mv.visitLineNumber(121, l57); + mv.visitLineNumber(122, l57); mv.visitTypeInsn(NEW, "net/minecraftforge/fluids/FluidStack"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 5); @@ -474,13 +479,13 @@ public class ClassTransformer_GC_FuelLoader { mv.visitMethodInsn(INVOKESPECIAL, "net/minecraftforge/fluids/FluidStack", "<init>", "(Lnet/minecraftforge/fluids/Fluid;I)V", false); mv.visitVarInsn(ASTORE, 1); mv.visitLabel(l54); - mv.visitLineNumber(119, l54); + mv.visitLineNumber(120, l54); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 6); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true); mv.visitJumpInsn(IFNE, l55); mv.visitLabel(l52); - mv.visitLineNumber(125, l52); + mv.visitLineNumber(126, l52); mv.visitFrame(F_FULL, 5, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, TOP, "net/minecraftforge/fluids/FluidStack"}, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 4); mv.visitFieldInsn(GETFIELD, "net/minecraftforge/fluids/FluidStack", "amount", "I"); @@ -491,7 +496,7 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(IF_ICMPGE, l58); Label l59 = new Label(); mv.visitLabel(l59); - mv.visitLineNumber(126, l59); + mv.visitLineNumber(127, l59); mv.visitTypeInsn(NEW, "net/minecraftforge/fluids/FluidStack"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 4); @@ -499,13 +504,13 @@ public class ClassTransformer_GC_FuelLoader { mv.visitMethodInsn(INVOKESPECIAL, "net/minecraftforge/fluids/FluidStack", "<init>", "(Lnet/minecraftforge/fluids/FluidStack;I)V", false); mv.visitVarInsn(ASTORE, 1); mv.visitLabel(l58); - mv.visitLineNumber(129, l58); + mv.visitLineNumber(130, l58); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitJumpInsn(IFNULL, l2); Label l60 = new Label(); mv.visitLabel(l60); - mv.visitLineNumber(130, l60); + mv.visitLineNumber(131, l60); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "attachedFuelable", "Lmicdoodle8/mods/galacticraft/api/entity/IFuelable;"); mv.visitJumpInsn(IFNULL, l2); @@ -517,32 +522,51 @@ public class ClassTransformer_GC_FuelLoader { mv.visitJumpInsn(IFNE, l2); Label l61 = new Label(); mv.visitLabel(l61); - mv.visitLineNumber(131, l61); + mv.visitLineNumber(132, l61); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "attachedFuelable", "Lmicdoodle8/mods/galacticraft/api/entity/IFuelable;"); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/xmod/galacticraft/util/GalacticUtils", "getRocketTier", "(Ljava/lang/Object;)I", false); + mv.visitVarInsn(ISTORE, 5); + Label l62 = new Label(); + mv.visitLabel(l62); + mv.visitLineNumber(133, l62); + mv.visitVarInsn(ILOAD, 5); + mv.visitJumpInsn(IFLE, l2); + Label l63 = new Label(); + mv.visitLabel(l63); + mv.visitLineNumber(134, l63); + mv.visitVarInsn(ILOAD, 5); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/xmod/galacticraft/util/GalacticUtils", "isFuelValidForTier", "(ILnet/minecraftforge/fluids/FluidStack;)Z", false); + mv.visitJumpInsn(IFEQ, l2); + Label l64 = new Label(); + mv.visitLabel(l64); + mv.visitLineNumber(135, l64); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "attachedFuelable", "Lmicdoodle8/mods/galacticraft/api/entity/IFuelable;"); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKEINTERFACE, "micdoodle8/mods/galacticraft/api/entity/IFuelable", "addFuel", "(Lnet/minecraftforge/fluids/FluidStack;Z)I", true); mv.visitVarInsn(ISTORE, 3); - Label l62 = new Label(); - mv.visitLabel(l62); - mv.visitLineNumber(132, l62); + Label l65 = new Label(); + mv.visitLabel(l65); + mv.visitLineNumber(136, l65); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 3); - Label l63 = new Label(); - mv.visitJumpInsn(IFLE, l63); + Label l66 = new Label(); + mv.visitJumpInsn(IFLE, l66); mv.visitInsn(ICONST_1); - Label l64 = new Label(); - mv.visitJumpInsn(GOTO, l64); - mv.visitLabel(l63); - mv.visitFrame(F_FULL, 5, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, INTEGER, "net/minecraftforge/fluids/FluidStack"}, 1, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader"}); + Label l67 = new Label(); + mv.visitJumpInsn(GOTO, l67); + mv.visitLabel(l66); + mv.visitFrame(F_FULL, 6, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, INTEGER, "net/minecraftforge/fluids/FluidStack", INTEGER}, 1, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader"}); mv.visitInsn(ICONST_0); - mv.visitLabel(l64); - mv.visitFrame(F_FULL, 5, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, INTEGER, "net/minecraftforge/fluids/FluidStack"}, 2, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", INTEGER}); + mv.visitLabel(l67); + mv.visitFrame(F_FULL, 6, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "net/minecraftforge/fluids/FluidStack", TOP, INTEGER, "net/minecraftforge/fluids/FluidStack", INTEGER}, 2, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", INTEGER}); mv.visitFieldInsn(PUTFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "loadedFuelLastTick", "Z"); - Label l65 = new Label(); - mv.visitLabel(l65); - mv.visitLineNumber(133, l65); + Label l68 = new Label(); + mv.visitLabel(l68); + mv.visitLineNumber(137, l68); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader", "fuelTank", "Lnet/minecraftforge/fluids/FluidTank;"); mv.visitVarInsn(ILOAD, 3); @@ -550,33 +574,30 @@ public class ClassTransformer_GC_FuelLoader { mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraftforge/fluids/FluidTank", "drain", "(IZ)Lnet/minecraftforge/fluids/FluidStack;", false); mv.visitInsn(POP); mv.visitLabel(l2); - mv.visitLineNumber(138, l2); + mv.visitLineNumber(144, l2); mv.visitFrame(F_FULL, 1, new Object[] {"micdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader"}, 0, new Object[] {}); mv.visitInsn(RETURN); - Label l66 = new Label(); - mv.visitLabel(l66); - mv.visitLocalVariable("this", "Lmicdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader;", null, l0, l66, 0); + Label l69 = new Label(); + mv.visitLabel(l69); + mv.visitLocalVariable("this", "Lmicdoodle8/mods/galacticraft/core/tile/TileEntityFuelLoader;", null, l0, l69, 0); mv.visitLocalVariable("liquid", "Lnet/minecraftforge/fluids/FluidStack;", null, l5, l2, 1); mv.visitLocalVariable("amount", "I", null, l37, l32, 2); mv.visitLocalVariable("filled", "I", null, l36, l32, 3); - mv.visitLocalVariable("filled", "I", null, l62, l2, 3); + mv.visitLocalVariable("filled", "I", null, l65, l2, 3); mv.visitLocalVariable("isFuel", "Z", null, l10, l6, 4); mv.visitLocalVariable("liquidInTank", "Lnet/minecraftforge/fluids/FluidStack;", null, l13, l6, 5); mv.visitLocalVariable("didFill", "Z", null, l14, l6, 6); mv.visitLocalVariable("aFuelType", "Lnet/minecraftforge/fluids/Fluid;", null, l20, l18, 7); mv.visitLocalVariable("var8", "[Lnet/minecraftforge/common/util/ForgeDirection;", null, l35, l32, 4); mv.visitLocalVariable("dir", "Lnet/minecraftforge/common/util/ForgeDirection;", null, l40, l45, 5); - mv.visitLocalVariable("pad", "Lnet/minecraft/tileentity/TileEntity;", null, l41, l45, 6); - mv.visitLocalVariable("mainTile", "Lnet/minecraft/tileentity/TileEntity;", null, l44, l42, 7); + mv.visitLocalVariable("pad", "L"+aTileEntity+";", null, l41, l45, 6); + mv.visitLocalVariable("mainTile", "L"+aTileEntity+";", null, l44, l42, 7); mv.visitLocalVariable("liquidInTank", "Lnet/minecraftforge/fluids/FluidStack;", null, l51, l2, 4); mv.visitLocalVariable("aFuelType", "Lnet/minecraftforge/fluids/Fluid;", null, l56, l54, 5); + mv.visitLocalVariable("aTier", "I", null, l62, l2, 5); mv.visitMaxs(5, 9); mv.visitEnd(); } - - - FMLRelaunchLog.log("[GT++ ASM] Galacticraft Fuel_Loader Patch", Level.INFO, "Method injection complete."); - } } public static final class localClassVisitor extends ClassVisitor { diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java index ea08c07f48..700fa09047 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java @@ -1,15 +1,6 @@ package gtPlusPlus.preloader.asm.transformers; -import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; -import java.io.ObjectOutputStream; -import java.lang.instrument.ClassFileTransformer; -import java.lang.instrument.IllegalClassFormatException; -import java.lang.instrument.Instrumentation; -import java.lang.instrument.UnmodifiableClassException; -import java.security.ProtectionDomain; - import org.apache.logging.log4j.Level; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; @@ -19,7 +10,6 @@ import cpw.mods.fml.relauncher.FMLRelaunchLog; import cpw.mods.fml.relauncher.ReflectionHelper; import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.Launch; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.preloader.asm.transformers.Preloader_ClassTransformer.OreDictionaryVisitor; import gtPlusPlus.preloader.asm.transformers.Preloader_ClassTransformer2.GT_MetaTile_Visitor; @@ -50,13 +40,18 @@ public class Preloader_Transformer_Handler implements IClassTransformer { } } - // Fix the OreDictionary + // Fix the OreDictionary - Forge if (transformedName.equals("net.minecraftforge.oredict.OreDictionary")) { FMLRelaunchLog.log("[GT++ ASM] OreDictTransformer", Level.INFO, "Transforming %s", transformedName); ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); new ClassReader(basicClass).accept(new OreDictionaryVisitor(classWriter), 0); return classWriter.toByteArray(); } + // Fix the OreDictionary COFH + if (transformedName.equals("cofh.core.util.oredict.OreDictionaryArbiter")) { + FMLRelaunchLog.log("[GT++ ASM] COFH", Level.INFO, "Transforming %s", transformedName); + return new ClassTransformer_COFH_OreDictionaryArbiter(basicClass, obfuscated).getWriter().toByteArray(); + } // Fix Tinkers Fluids if (transformedName.equals("tconstruct.smeltery.blocks.TConstructFluid")) { @@ -67,11 +62,15 @@ public class Preloader_Transformer_Handler implements IClassTransformer { //Fix GC stuff if (transformedName.equals("micdoodle8.mods.galacticraft.core.util.FluidUtil")) { FMLRelaunchLog.log("[GT++ ASM] Galacticraft FluidUtils Patch", Level.INFO, "Transforming %s", transformedName); - return new ClassTransformer_GC_FluidUtil(basicClass).getWriter().toByteArray(); + return new ClassTransformer_GC_FluidUtil(basicClass, obfuscated).getWriter().toByteArray(); } if (transformedName.equals("micdoodle8.mods.galacticraft.core.tile.TileEntityFuelLoader")) { FMLRelaunchLog.log("[GT++ ASM] Galacticraft Fuel_Loader Patch", Level.INFO, "Transforming %s", transformedName); - return new ClassTransformer_GC_FuelLoader(basicClass).getWriter().toByteArray(); + return new ClassTransformer_GC_FuelLoader(basicClass, obfuscated).getWriter().toByteArray(); + } + if (transformedName.equals("micdoodle8.mods.galacticraft.api.prefab.entity.EntityAutoRocket")) { + FMLRelaunchLog.log("[GT++ ASM] Galacticraft EntityAutoRocket Patch", Level.INFO, "Transforming %s", transformedName); + return new ClassTransformer_GC_EntityAutoRocket(basicClass, obfuscated).getWriter().toByteArray(); } @@ -92,9 +91,9 @@ public class Preloader_Transformer_Handler implements IClassTransformer { } //Improve OB Sprinklers - if (transformedName.equals("openblocks.common.tileentity.TileEntitySprinkler")) { + /*if (transformedName.equals("openblocks.common.tileentity.TileEntitySprinkler")) { FMLRelaunchLog.log("[GT++ ASM] OpenBlocks Sprinkler Patch", Level.INFO, "Transforming %s", transformedName); - /*try { + try { ClassLoader aCustom = new gtPlusPlus.preloader.CustomClassLoader(); Class aCustomClass = aCustom.loadClass(gtPlusPlus.xmod.ob.TileEntitySprinkler_ASM.class.getName()); if (aCustomClass == null) { @@ -113,9 +112,9 @@ public class Preloader_Transformer_Handler implements IClassTransformer { } catch (ClassNotFoundException | UnmodifiableClassException e) { e.printStackTrace(); - }*/ + } return new ClassTransformer_OB_Sprinkler(obfuscated, basicClass).getWriter().toByteArray(); - } + }*/ } return basicClass; } diff --git a/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java b/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java new file mode 100644 index 0000000000..9075666b8b --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java @@ -0,0 +1,73 @@ +package gtPlusPlus.xmod.galacticraft.handler; + +import java.lang.reflect.Field; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import gtPlusPlus.core.item.chemistry.RocketFuels; +import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fluids.Fluid; + +public class HandlerTooltip_GC { + + private static Item mItemBlock; + private static Block mBlock; + private static Class<?> oMainClass; + private static Class<?> oFuelLoaderClass; + private static String[] mFuelNames; + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if (LoadedMods.GalacticraftCore) { + + if (mBlock == null) { + try { + Class<?> GCBlocks = Class.forName("micdoodle8.mods.galacticraft.core.blocks.GCBlocks"); + if (GCBlocks != null) { + oMainClass = GCBlocks; + + Class<?> GCFuelLoader = Class + .forName("micdoodle8.mods.galacticraft.core.blocks.BlockFuelLoader"); + + if (GCFuelLoader != null) { + oFuelLoaderClass = GCFuelLoader; + } + + Field aField = ReflectionUtils.getField(GCBlocks, "fuelLoader"); + if (aField != null) { + Block aBlock = (Block) aField.get(null); + if (aBlock != null) { + mBlock = aBlock; + mItemBlock = Item.getItemFromBlock(mBlock); + } + } + } + } catch (Throwable t) { + } + } + if (mFuelNames == null || mFuelNames.length == 0) { + mFuelNames = new String[RocketFuels.mValidRocketFuels.size()]; + int slot = 0; + for (Fluid f : RocketFuels.mValidRocketFuels.values()) { + mFuelNames[slot++] = f.getLocalizedName(); + } + } + if (mItemBlock != null) { + Item aTempItem = event.itemStack.getItem(); + Block aTempBlock = Block.getBlockFromItem(aTempItem); + if (aTempItem == mItemBlock || oFuelLoaderClass.isInstance(aTempBlock) + || event.itemStack.getUnlocalizedName().toLowerCase().contains("fuelloader")) { + int aTier = 0; + for (String s : mFuelNames) { + if (s != null) { + event.toolTip.add("Tier "+aTier+": "+s); + } + } + } + } + } + } +} diff --git a/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java b/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java new file mode 100644 index 0000000000..df8521be9d --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java @@ -0,0 +1,137 @@ +package gtPlusPlus.xmod.galacticraft.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import gregtech.api.enums.Materials; +import gtPlusPlus.core.item.chemistry.RocketFuels; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.entity.Entity; +import net.minecraftforge.fluids.FluidStack; + +public class GalacticUtils { + + static final private Class<?> aTieredRocket; + static final private Class<?> aLandingPad; + static final private Class<?> aBuggyPad; + static final private Class<?> aIDockable; + static final private Class<?> aIFuelable; + static final private Method getRocketTier; + static final private Method getRocket; + static final private Method getBuggy; + + static { + Class<?> a1, a2, a3, a4, a5; + Method m1, m2, m3; + try { + a1 = Class.forName("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket"); + a2 = Class.forName("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad"); + a3 = Class.forName("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler"); + a4 = Class.forName("micdoodle8.mods.galacticraft.api.entity.IDockable"); + a5 = Class.forName("micdoodle8.mods.galacticraft.api.entity.IFuelable"); + m1 = ReflectionUtils.getMethod(a1, "getRocketTier"); + m2 = ReflectionUtils.getMethod(a2, "getDockedEntity"); + m3 = ReflectionUtils.getMethod(a3, "getDockedEntity"); + } + catch (Throwable t) { + a1 = null; + a2 = null; + a3 = null; + a4 = null; + a5 = null; + m1 = null; + m2 = null; + m3 = null; + } + aTieredRocket = a1; + aLandingPad = a2; + aBuggyPad = a3; + aIDockable = a4; + aIFuelable = a5; + getRocketTier = m1; + getRocket = m2; + getBuggy = m3; + } + + + public static int getRocketTier(Entity aEntity) { + if (aTieredRocket.isInstance(aEntity)) { + if (getRocketTier != null) { + try { + return (int) getRocketTier.invoke(aEntity, new Object[] {}); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + } + return -1; + } + + public static int getRocketTier(Object aEntity) { + if (aIFuelable.isInstance(aEntity)) { + if (aLandingPad.isInstance(aEntity)) { + Object rocket; + try { + rocket = getRocket.invoke(aLandingPad, new Object[] {}); + if (aIDockable.isInstance(rocket) && rocket != null) { + return getRocketTier((Entity) rocket); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + else if (aBuggyPad.isInstance(aEntity)) { + Object buggy; + try { + buggy = getBuggy.invoke(aBuggyPad, new Object[] {}); + if (aIDockable.isInstance(buggy) && buggy != null) { + return 0; + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + } + return -1; + } + + public static boolean isFuelValidForTier(int aTier, FluidStack aFuel) { + FluidStack aValidForThisTier = getValidFuelForTier(aTier); + if (aFuel.isFluidEqual(aValidForThisTier)) { + return true; + } + return false; + } + + + + public static FluidStack getValidFuelForTier(Entity aEntity) { + if (aTieredRocket.isInstance(aEntity)) { + return getValidFuelForTier(getRocketTier(aEntity)); + } + else { + return null; + } + } + + public static FluidStack getValidFuelForTier(int aTier) { + if (aTier > 0 && aTier <= 2) { + return FluidUtils.getFluidStack(RocketFuels.RP1_Plus_Liquid_Oxygen, 1000); + } + else if (aTier >= 3 && aTier <= 5) { + return FluidUtils.getFluidStack(RocketFuels.Dense_Hydrazine_Mix, 1000); + } + else if (aTier >= 6 && aTier <= 7) { + return FluidUtils.getFluidStack(RocketFuels.Monomethylhydrazine_Plus_Nitric_Acid, 1000); + } + else if (aTier >= 8 && aTier <= 10) { + return FluidUtils.getFluidStack(RocketFuels.Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 1000); + } + else { + if (aTier == 0) { + return Materials.Fuel.getFluid(1000); + } + return null; + } + + } + +} |