Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1.    private static void transformBlockCactus(ClassNode blockCactusClass, boolean isObfuscated) {
  2.  
  3.  
  4.         final String ENTITY_COLLIDE = isObfuscated ? "a" : "onEntityCollidedWithBlock";
  5.         final String ENTITY_COLLIDE_DESC = isObfuscated ? "(Lajq;Lco;Latj;Lsm;)V" : "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/entity/Entity;)V";
  6.  
  7.  
  8.         for (MethodNode method : blockCactusClass.methods) {
  9.             if (method.name.equals(ENTITY_COLLIDE) && method.desc.equals(ENTITY_COLLIDE_DESC)) {
  10.                 AbstractInsnNode targetNode = null;
  11.                 for (AbstractInsnNode instruction : method.instructions.toArray()) {
  12.                     if (instruction.getOpcode() == ALOAD) {
  13.                         if (((VarInsnNode) instruction).var == 4 && instruction.getNext().getOpcode() == GETSTATIC) {
  14.                             targetNode = instruction;
  15.                             break;
  16.                         }
  17.                     }
  18.                 }
  19.                 if (targetNode != null && isBadMethod) {
  20.  
  21.  
  22.                     for (int i = 0; i < 5; i++) {
  23.                         targetNode = targetNode.getNext();
  24.                         method.instructions.remove(targetNode.getPrevious());
  25.                     }
  26.  
  27.  
  28.                 } else if (targetNode != null) {
  29.  
  30.                     AbstractInsnNode popNode = targetNode;
  31.                     for (int i = 0; i < 4; i++) {
  32.                         popNode = popNode.getNext();
  33.                     }
  34.  
  35.                     LabelNode newLabelNode = new LabelNode();
  36.  
  37.                     InsnList toInsert = new InsnList();
  38.                     toInsert.add(new VarInsnNode(ALOAD, 4));
  39.                     toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Hooks.class), "cactusDoesDamage", isObfuscated ? "(Lsm;)Z" : "(Lnet/minecraft/entity/Entity;)Z", false));
  40.                     toInsert.add(new JumpInsnNode(IFEQ, newLabelNode));
  41.  
  42.                     method.instructions.insertBefore(targetNode, toInsert);
  43.                     method.instructions.insert(popNode, newLabelNode);
  44.                     File classDump = new File("classDumb.class");
  45.                     try {
  46.                         ASMHelper.writeClassToFile(blockCactusClass, classDump);
  47.                         System.out.println(classDump.getAbsolutePath());
  48.                     } catch (IOException e) {
  49.                         e.printStackTrace();
  50.                     }
  51.                 } else {
  52.                     System.out.println("Something went wrong transforming BlockCactus!");
  53.                 }
  54.             }
  55.         }
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement