From 7832b6223896af1b1435cdfeb52ce0210bfd2203 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Wed, 30 Jan 2019 02:18:50 +0000 Subject: $ Fixed 'bug' where GT wooden Pipes/Frames would require an Axe to harvest. They now require a wrench, freeing up 4 MetaIDs on BlockMachines for myself to use. $ Fixed handling of custom BaseMetaTileEntity implementations. Meta 12-15 is now used by GT++ to deploy custom without requiring any outside items or blocks. $ Fixed IC2 items requiring a pickaxe to mine and shitty wrench handling. You can now just mine them as usual with a wrench. $ Fixed ALL GT/GT++ Tile Entity Tooltips. Formatted some things slighty, added additional information and additional custom tooltip support. --- ...ransformer_GT_BlockMachines_MetaPipeEntity.java | 266 +++++++++++++++++++++ .../ClassTransformer_IC2_GetHarvestTool.java | 206 ++++++++++++++++ .../Preloader_Transformer_Handler.java | 66 ++++- 3 files changed, 532 insertions(+), 6 deletions(-) create mode 100644 src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GT_BlockMachines_MetaPipeEntity.java create mode 100644 src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java (limited to 'src/Java/gtPlusPlus/preloader/asm/transformers') diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GT_BlockMachines_MetaPipeEntity.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GT_BlockMachines_MetaPipeEntity.java new file mode 100644 index 0000000000..39cd8c248e --- /dev/null +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_GT_BlockMachines_MetaPipeEntity.java @@ -0,0 +1,266 @@ +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 gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.SubTag; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.preloader.DevHelper; +import gtPlusPlus.preloader.asm.AsmConfig; +import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class ClassTransformer_GT_BlockMachines_MetaPipeEntity { + + //The qualified name of the class we plan to transform. + //gregtech/common/blocks/GT_Block_Machines + + private final boolean isValid; + private final ClassReader reader; + private final ClassWriter writer; + + /** + * Utility Functions + */ + + public static String getHarvestTool(int aMeta) { + //FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Attempting to call getHarvestTool. Meta: "+aMeta); + if (aMeta >= 8 && aMeta <= 11) { + return "cutter"; + } + return "wrench"; + } + + /** + * This determines the BaseMetaTileEntity belonging to this MetaTileEntity by using the Meta ID of the Block itself. + *

+ * 0 = BaseMetaTileEntity, Wrench lvl 0 to dismantle + * 1 = BaseMetaTileEntity, Wrench lvl 1 to dismantle + *

+ * 2 = BaseMetaTileEntity, Wrench lvl 2 to dismantle + * 3 = BaseMetaTileEntity, Wrench lvl 3 to dismantle + *

+ * 4 = BaseMetaPipeEntity, Wrench lvl 0 to dismantle + * 5 = BaseMetaPipeEntity, Wrench lvl 1 to dismantle + *

+ * 6 = BaseMetaPipeEntity, Wrench lvl 2 to dismantle + * 7 = BaseMetaPipeEntity, Wrench lvl 3 to dismantle + *

+ * 8 = BaseMetaPipeEntity, Cutter lvl 0 to dismantle + * 9 = BaseMetaPipeEntity, Cutter lvl 1 to dismantle + *

+ * 10 = BaseMetaPipeEntity, Cutter lvl 2 to dismantle + * 11 = BaseMetaPipeEntity, Cutter lvl 3 to dismantle + *

+ * == Reserved For Alkalus (Was previously used to allow axes on wooden blocks, but that's fucking stupid.) + *

+ * 12 = BaseMetaTileEntity, Wrench lvl 0 to dismantle + * 13 = BaseMetaTileEntity, Wrench lvl 1 to dismantle + *

+ * 14 = BaseMetaTileEntity, Wrench lvl 2 to dismantle + * 15 = BaseMetaTileEntity, Wrench lvl 3 to dismantle + */ + public static byte getTileEntityBaseType(Materials mMaterial) { + //FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Attempting to call getTileEntityBaseType."); + return (byte) (mMaterial == null ? 4 : (byte) (4) + Math.max(0, Math.min(3, mMaterial.mToolQuality))); + } + + + + /** + * This determines the BaseMetaTileEntity belonging to this MetaTileEntity by using the Meta ID of the Block itself. + *

+ * 0 = BaseMetaTileEntity, Wrench lvl 0 to dismantle + * 1 = BaseMetaTileEntity, Wrench lvl 1 to dismantle + *

+ * 2 = BaseMetaTileEntity, Wrench lvl 2 to dismantle + * 3 = BaseMetaTileEntity, Wrench lvl 3 to dismantle + *

+ * 4 = BaseMetaPipeEntity, Wrench lvl 0 to dismantle + * 5 = BaseMetaPipeEntity, Wrench lvl 1 to dismantle + *

+ * 6 = BaseMetaPipeEntity, Wrench lvl 2 to dismantle + * 7 = BaseMetaPipeEntity, Wrench lvl 3 to dismantle + *

+ * 8 = BaseMetaPipeEntity, Cutter lvl 0 to dismantle + * 9 = BaseMetaPipeEntity, Cutter lvl 1 to dismantle + *

+ * 10 = BaseMetaPipeEntity, Cutter lvl 2 to dismantle + * 11 = BaseMetaPipeEntity, Cutter lvl 3 to dismantle + *

+ * == Reserved For Alkalus (Was previously used to allow axes on wooden blocks, but that's fucking stupid.) + *

+ * 12 = BaseMetaTileEntity, Wrench lvl 2 to dismantle + * 13 = BaseMetaTileEntity, Wrench lvl 2 to dismantle + *

+ * 14 = BaseMetaTileEntity, Wrench lvl 3 to dismantle + * 15 = BaseMetaTileEntity, Wrench lvl 3 to dismantle + */ + public static TileEntity createTileEntity(World aWorld, int aMeta) { + Logger.INFO("Creating Tile Entity with Meta of "+aMeta); + if (aMeta < 4) { + return GregTech_API.constructBaseMetaTileEntity(); + } else if (aMeta < 12) { + return new BaseMetaPipeEntity(); + } else { + return Meta_GT_Proxy.constructCustomGregtechMetaTileEntityByMeta(aMeta); + } + } + + + + String aEntityPlayer; + String aEntityPlayerMP; + String aWorld; + int mMode; + + public ClassTransformer_GT_BlockMachines_MetaPipeEntity(byte[] basicClass, boolean obfuscated, int aMode) { + mMode = aMode; + ClassReader aTempReader = null; + ClassWriter aTempWriter = null; + + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Attempting to patch in mode "+aMode+"."); + + aTempReader = new ClassReader(basicClass); + aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES); + aTempReader.accept(new localClassVisitor(aTempWriter), 0); + + if (aTempReader != null && aTempWriter != null) { + isValid = true; + } + else { + isValid = false; + } + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Valid patch? "+isValid+"."); + reader = aTempReader; + writer = aTempWriter; + + + if (reader != null && writer != null) { + aEntityPlayer = obfuscated ? DevHelper.getObfuscated("net/minecraft/entity/player/EntityPlayer") : "net/minecraft/entity/player/EntityPlayer"; + aEntityPlayerMP = obfuscated ? DevHelper.getObfuscated("net/minecraft/entity/player/EntityPlayerMP") : "net/minecraft/entity/player/EntityPlayerMP"; + aWorld = obfuscated ? DevHelper.getObfuscated("net/minecraft/world/World") : "net/minecraft/world/World"; + + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Attempting Method Injection."); + if (aMode == 0) { + injectMethod("getHarvestTool"); + injectMethod("createTileEntity"); + } + else { + injectMethod("getTileEntityBaseType"); + } + } + + } + + public boolean isValidTransformer() { + return isValid; + } + + public ClassReader getReader() { + return reader; + } + + public ClassWriter getWriter() { + return writer; + } + + public boolean injectMethod(String aMethodName) { + MethodVisitor mv; + boolean didInject = false; + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Injecting "+aMethodName+"."); + if (aMethodName.equals("getHarvestTool")) { + mv = getWriter().visitMethod(ACC_PUBLIC, "getHarvestTool", "(I)Ljava/lang/String;", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(63, l0); + mv.visitVarInsn(ILOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/preloader/asm/transformers/ClassTransformer_GT_BlockMachines_MetaPipeEntity", "getHarvestTool", "(I)Ljava/lang/String;", false); + mv.visitInsn(ARETURN); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLocalVariable("this", "Lgregtech/common/blocks/GT_Block_Machines;", null, l0, l1, 0); + mv.visitLocalVariable("aMeta", "I", null, l0, l1, 1); + mv.visitMaxs(1, 2); + mv.visitEnd(); + didInject = true; + } + else if (aMethodName.equals("createTileEntity")) { + mv = getWriter().visitMethod(ACC_PUBLIC, "createTileEntity", "(Lnet/minecraft/world/World;I)Lnet/minecraft/tileentity/TileEntity;", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(442, l0); + mv.visitVarInsn(ALOAD, 1); + mv.visitVarInsn(ILOAD, 2); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/preloader/asm/transformers/ClassTransformer_GT_BlockMachines_MetaPipeEntity", "createTileEntity", "(Lnet/minecraft/world/World;I)Lnet/minecraft/tileentity/TileEntity;", false); + mv.visitInsn(ARETURN); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLocalVariable("this", "Lgregtech/common/blocks/GT_Block_Machines;", null, l0, l1, 0); + mv.visitLocalVariable("aWorld", "Lnet/minecraft/world/World;", null, l0, l1, 1); + mv.visitLocalVariable("aMeta", "I", null, l0, l1, 2); + mv.visitMaxs(2, 3); + mv.visitEnd(); + didInject = true; + + } + else if (aMethodName.equals("getTileEntityBaseType")) { + + String aClassName = mMode == 1 ? "gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Item" : mMode == 2 ? "gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Frame" : "gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid"; + mv = getWriter().visitMethod(ACC_PUBLIC, "getTileEntityBaseType", "()B", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(37, l0); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, ""+aClassName+"", "mMaterial", "Lgregtech/api/enums/Materials;"); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/preloader/asm/transformers/ClassTransformer_GT_BlockMachines_MetaPipeEntity", "getTileEntityBaseType", "(Lgregtech/api/enums/Materials;)B", false); + mv.visitInsn(IRETURN); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLocalVariable("this", "L"+aClassName+";", null, l0, l1, 0); + mv.visitMaxs(1, 1); + mv.visitEnd(); + didInject = true; + + } + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Method injection complete."); + return didInject; + } + + 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) { + MethodVisitor methodVisitor; + if (name.equals("getHarvestTool") || name.equals("createTileEntity") || name.equals("getTileEntityBaseType")) { + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Found method "+name+", removing."); + methodVisitor = null; + } + else { + methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); + } + return methodVisitor; + } + } + +} diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java new file mode 100644 index 0000000000..1e67619337 --- /dev/null +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java @@ -0,0 +1,206 @@ +package gtPlusPlus.preloader.asm.transformers; + +import static org.objectweb.asm.Opcodes.*; + +import java.util.Random; + +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 net.minecraft.block.Block; +import net.minecraft.item.Item; + +public class ClassTransformer_IC2_GetHarvestTool { + + private final boolean isValid; + private final ClassReader reader; + private final ClassWriter writer; + private final String className; + + public static String getHarvestTool(int aMeta) { + return "wrench"; + } + + public static Item getItemDropped(Block aBlock, int meta, Random random, int fortune) { + return Item.getItemFromBlock(aBlock); + } + + public static int damageDropped(int aMeta) { + return aMeta; + } + + public ClassTransformer_IC2_GetHarvestTool(byte[] basicClass, boolean obfuscated, String aClassName) { + className = aClassName; + ClassReader aTempReader = null; + ClassWriter aTempWriter = null; + + FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, + "Attempting to patch in mode " + className + "."); + + aTempReader = new ClassReader(basicClass); + aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES); + aTempReader.accept(new localClassVisitor(aTempWriter, className), 0); + + if (aTempReader != null && aTempWriter != null) { + isValid = true; + } else { + isValid = false; + } + FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Valid patch? " + isValid + "."); + reader = aTempReader; + writer = aTempWriter; + + if (reader != null && writer != null) { + FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Attempting Method Injection."); + injectMethod("getHarvestTool"); + + if (aClassName.equals("ic2.core.block.machine.BlockMachine2") + || aClassName.equals("ic2.core.block.machine.BlockMachine3")) { + injectMethod("getItemDropped"); + injectMethod("damageDropped"); + } + else if (aClassName.equals("ic2.core.block.generator.block.BlockGenerator") + || aClassName.equals("ic2.core.block.machine.BlockMachine")) { + injectMethod("damageDropped"); + } + } + + } + + public boolean isValidTransformer() { + return isValid; + } + + public ClassReader getReader() { + return reader; + } + + public ClassWriter getWriter() { + return writer; + } + + public boolean injectMethod(String aMethodName) { + MethodVisitor mv; + boolean didInject = false; + String aFormattedClassName = className.replace('.', '/'); + ClassWriter cw = getWriter(); + + + FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Injecting " + aMethodName + "."); + if (aMethodName.equals("getHarvestTool")) { + mv = getWriter().visitMethod(ACC_PUBLIC, "getHarvestTool", "(I)Ljava/lang/String;", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(63, l0); + mv.visitVarInsn(ILOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, + "gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool", "getHarvestTool", + "(I)Ljava/lang/String;", false); + mv.visitInsn(ARETURN); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLocalVariable("this", "L" + aFormattedClassName + ";", null, l0, l1, 0); + mv.visitLocalVariable("aMeta", "I", null, l0, l1, 1); + mv.visitMaxs(1, 2); + mv.visitEnd(); + didInject = true; + } + else if (aMethodName.equals("getItemDropped")) { + mv = cw.visitMethod(ACC_PUBLIC, "getItemDropped", "(ILjava/util/Random;I)Lnet/minecraft/item/Item;", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(44, l0); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ILOAD, 1); + mv.visitVarInsn(ALOAD, 2); + mv.visitVarInsn(ILOAD, 3); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool", "getItemDropped", "(Lnet/minecraft/block/Block;ILjava/util/Random;I)Lnet/minecraft/item/Item;", false); + mv.visitInsn(ARETURN); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLocalVariable("this", "L"+aFormattedClassName+";", null, l0, l1, 0); + mv.visitLocalVariable("meta", "I", null, l0, l1, 1); + mv.visitLocalVariable("random", "Ljava/util/Random;", null, l0, l1, 2); + mv.visitLocalVariable("fortune", "I", null, l0, l1, 3); + mv.visitMaxs(4, 4); + mv.visitEnd(); + didInject = true; + } + else if (aMethodName.equals("damageDropped")) { + mv = cw.visitMethod(ACC_PUBLIC, "damageDropped", "(I)I", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(48, l0); + mv.visitVarInsn(ILOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool", "damageDropped", "(I)I", false); + mv.visitInsn(IRETURN); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLocalVariable("this", "L"+aFormattedClassName+";", null, l0, l1, 0); + mv.visitLocalVariable("meta", "I", null, l0, l1, 1); + mv.visitMaxs(1, 2); + mv.visitEnd(); + didInject = true; + } + FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Method injection complete."); + return didInject; + } + + public final class localClassVisitor extends ClassVisitor { + + String aClassName; + + public localClassVisitor(ClassVisitor cv, String aName) { + super(ASM5, cv); + aClassName = aName; + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + MethodVisitor methodVisitor; + if (aClassName.equals("ic2.core.block.machine.BlockMachine2") + || aClassName.equals("ic2.core.block.machine.BlockMachine3")) { + if (name.equals("getItemDropped")) { + methodVisitor = null; + } else if (name.equals("damageDropped")) { + methodVisitor = null; + } else if (name.equals("getHarvestTool")) { + methodVisitor = null; + } else { + methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); + } + } + else if (aClassName.equals("ic2.core.block.generator.block.BlockGenerator") + || aClassName.equals("ic2.core.block.machine.BlockMachine")) { + if (name.equals("damageDropped")) { + methodVisitor = null; + } else if (name.equals("getHarvestTool")) { + methodVisitor = null; + } else { + methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); + } + } + else { + if (name.equals("getHarvestTool")) { + methodVisitor = null; + } else { + methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); + } + } + if (methodVisitor == null) { + FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, + "Found method " + name + ", removing."); + } + return methodVisitor; + } + } + +} 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 8a8f0d86db..df9cd658be 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java @@ -2,6 +2,8 @@ package gtPlusPlus.preloader.asm.transformers; import java.io.File; import java.io.IOException; +import java.util.Random; + import org.apache.logging.log4j.Level; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; @@ -10,16 +12,24 @@ import cpw.mods.fml.relauncher.CoreModManager; import cpw.mods.fml.relauncher.FMLRelaunchLog; import cpw.mods.fml.relauncher.ReflectionHelper; import galaxyspace.SolarSystem.core.configs.GSConfigDimensions; +import net.minecraft.block.Block; +import net.minecraft.item.Item; import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.Launch; import gtPlusPlus.core.util.Utils; import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.preloader.asm.transformers.Preloader_ClassTransformer.OreDictionaryVisitor; +@SuppressWarnings("static-access") public class Preloader_Transformer_Handler implements IClassTransformer { private final boolean mEnabled = false; - public static final AsmConfig mConfig; + public static final AsmConfig mConfig; + + private static final String class_Block_Machines = "gregtech.common.blocks.GT_Block_Machines"; + private static final String class_GT_MetaPipeEntity_Item = "gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Item"; + private static final String class_GT_MetaPipeEntity_Frame = "gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame"; + private static final String class_GT_MetaPipeEntity_Fluid = "gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Fluid"; static { mConfig = new AsmConfig(new File("config/GTplusplus/asm.cfg")); @@ -27,6 +37,7 @@ public class Preloader_Transformer_Handler implements IClassTransformer { System.out.println("[GT++ ASM] Is DevHelper Valid? "+gtPlusPlus.preloader.DevHelper.mIsValidHelper); } + @SuppressWarnings("static-access") public byte[] transform(String name, String transformedName, byte[] basicClass) { @@ -93,11 +104,6 @@ public class Preloader_Transformer_Handler implements IClassTransformer { } } - //Fix GT NBT Persistency issue - if (transformedName.equals("gregtech.common.blocks.GT_Block_Machines")) { - FMLRelaunchLog.log("[GT++ ASM] Gregtech NBT Persistency Patch", Level.INFO, "Transforming %s", transformedName); - return new ClassTransformer_GT_BlockMachines_NBT(basicClass, probablyShouldBeFalse).getWriter().toByteArray(); - } //Patching Meta Tile Tooltips if (transformedName.equals("gregtech.common.blocks.GT_Item_Machines") && mConfig.enableGtTooltipFix) { FMLRelaunchLog.log("[GT++ ASM] Gregtech Tooltip Patch", Level.INFO, "Transforming %s", transformedName); @@ -105,7 +111,55 @@ public class Preloader_Transformer_Handler implements IClassTransformer { } + if (transformedName.equals(class_Block_Machines)) { + //Fix GT NBT Persistency issue + FMLRelaunchLog.log("[GT++ ASM] Gregtech NBT Persistency Patch", Level.INFO, "Transforming %s", transformedName); + byte[] g = new ClassTransformer_GT_BlockMachines_NBT(basicClass, probablyShouldBeFalse).getWriter().toByteArray(); + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Transforming %s", transformedName); + return new ClassTransformer_GT_BlockMachines_MetaPipeEntity(g, probablyShouldBeFalse, 0).getWriter().toByteArray(); + } + if (transformedName.equals(class_GT_MetaPipeEntity_Item) || transformedName.equals(class_GT_MetaPipeEntity_Frame) || transformedName.equals(class_GT_MetaPipeEntity_Fluid)) { + FMLRelaunchLog.log("[GT++ ASM] Gregtech getTileEntityBaseType Patch", Level.INFO, "Transforming %s", transformedName); + int mode = 0; + if (transformedName.equals(class_GT_MetaPipeEntity_Item)) { + mode = 1; + } + else if (transformedName.equals(class_GT_MetaPipeEntity_Frame)) { + mode = 2; + } + else { + mode = 3; + } + return new ClassTransformer_GT_BlockMachines_MetaPipeEntity(basicClass, probablyShouldBeFalse, mode).getWriter().toByteArray(); + } + + String[] aIC2ClassNames = new String[] { + "ic2.core.block.BlockTileEntity", + "ic2.core.block.machine.BlockMachine", + "ic2.core.block.machine.BlockMachine2", + "ic2.core.block.machine.BlockMachine3", + "ic2.core.block.kineticgenerator.block.BlockKineticGenerator", + "ic2.core.block.heatgenerator.block.BlockHeatGenerator", + "ic2.core.block.generator.block.BlockGenerator", + "ic2.core.block.reactor.block.BlockReactorAccessHatch", + "ic2.core.block.reactor.block.BlockReactorChamber", + "ic2.core.block.reactor.block.BlockReactorFluidPort", + "ic2.core.block.reactor.block.BlockReactorRedstonePort", + "ic2.core.block.reactor.block.BlockReactorVessel", + }; + + //Fix IC2 Shit + for (String y : aIC2ClassNames) { + if (transformedName.equals(y)) { + //Fix GT NBT Persistency issue + FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Transforming %s", transformedName); + return new ClassTransformer_IC2_GetHarvestTool(basicClass, probablyShouldBeFalse, transformedName).getWriter().toByteArray(); + } + } + return basicClass; } + + } -- cgit