|
| 1 | +package club.sk1er.items.asm; |
| 2 | + |
| 3 | +import club.sk1er.items.tweaker.transform.ItemTransformer; |
| 4 | +import org.objectweb.asm.Opcodes; |
| 5 | +import org.objectweb.asm.tree.ClassNode; |
| 6 | +import org.objectweb.asm.tree.FieldInsnNode; |
| 7 | +import org.objectweb.asm.tree.InsnList; |
| 8 | +import org.objectweb.asm.tree.InsnNode; |
| 9 | +import org.objectweb.asm.tree.JumpInsnNode; |
| 10 | +import org.objectweb.asm.tree.LabelNode; |
| 11 | +import org.objectweb.asm.tree.MethodInsnNode; |
| 12 | +import org.objectweb.asm.tree.MethodNode; |
| 13 | +import org.objectweb.asm.tree.VarInsnNode; |
| 14 | + |
| 15 | +public class EntityItemTransformer implements ItemTransformer { |
| 16 | + @Override |
| 17 | + public String[] getClassNames() { |
| 18 | + return new String[]{"net.minecraft.entity.item.EntityItem"}; |
| 19 | + } |
| 20 | + |
| 21 | + @Override |
| 22 | + public void transform(ClassNode classNode, String name) { |
| 23 | + for (MethodNode methodNode : classNode.methods) { |
| 24 | + String methodName = mapMethodName(classNode, methodNode); |
| 25 | + |
| 26 | + if (methodName.equals("searchForOtherItemsNearby") || methodName.equals("func_85054_d")) { |
| 27 | + methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), stopSearch()); |
| 28 | + } |
| 29 | + |
| 30 | + if (methodName.equals("combineItems") || methodName.equals("func_70289_a")) { |
| 31 | + methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), stopSearchBoolean()); |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + private InsnList stopSearch() { |
| 37 | + InsnList list = new InsnList(); |
| 38 | + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); |
| 39 | + list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "net/minecraft/entity/item/EntityItem", "func_92059_d", |
| 40 | + "()Lnet/minecraft/item/ItemStack;", false)); |
| 41 | + list.add(new VarInsnNode(Opcodes.ASTORE, 1)); |
| 42 | + list.add(new VarInsnNode(Opcodes.ALOAD, 1)); |
| 43 | + list.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/item/ItemStack", "field_77994_a", "I")); |
| 44 | + list.add(new VarInsnNode(Opcodes.ALOAD, 1)); |
| 45 | + list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/item/ItemStack", "func_77976_d", "()I", false)); |
| 46 | + LabelNode ificmplt = new LabelNode(); |
| 47 | + list.add(new JumpInsnNode(Opcodes.IF_ICMPLT, ificmplt)); |
| 48 | + list.add(new InsnNode(Opcodes.RETURN)); |
| 49 | + list.add(ificmplt); |
| 50 | + return list; |
| 51 | + } |
| 52 | + |
| 53 | + private InsnList stopSearchBoolean() { |
| 54 | + InsnList list = new InsnList(); |
| 55 | + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); |
| 56 | + list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "net/minecraft/entity/item/EntityItem", "func_92059_d", |
| 57 | + "()Lnet/minecraft/item/ItemStack;", false)); |
| 58 | + list.add(new VarInsnNode(Opcodes.ASTORE, 2)); |
| 59 | + list.add(new VarInsnNode(Opcodes.ALOAD, 2)); |
| 60 | + list.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/item/ItemStack", "field_77994_a", "I")); |
| 61 | + list.add(new VarInsnNode(Opcodes.ALOAD, 2)); |
| 62 | + list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/item/ItemStack", "func_77976_d", "()I", false)); |
| 63 | + LabelNode labelNode = new LabelNode(); |
| 64 | + list.add(new JumpInsnNode(Opcodes.IF_ICMPLT, labelNode)); |
| 65 | + list.add(new InsnNode(Opcodes.ICONST_0)); |
| 66 | + list.add(new InsnNode(Opcodes.IRETURN)); |
| 67 | + list.add(labelNode); |
| 68 | + return list; |
| 69 | + } |
| 70 | +} |
0 commit comments