Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void transformBlockCactus(ClassNode blockCactusClass, boolean isObfuscated) {
- final String ENTITY_COLLIDE = isObfuscated ? "a" : "onEntityCollidedWithBlock";
- 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";
- for (MethodNode method : blockCactusClass.methods) {
- if (method.name.equals(ENTITY_COLLIDE) && method.desc.equals(ENTITY_COLLIDE_DESC)) {
- AbstractInsnNode targetNode = null;
- for (AbstractInsnNode instruction : method.instructions.toArray()) {
- if (instruction.getOpcode() == ALOAD) {
- if (((VarInsnNode) instruction).var == 4 && instruction.getNext().getOpcode() == GETSTATIC) {
- targetNode = instruction;
- break;
- }
- }
- }
- if (targetNode != null && isBadMethod) {
- for (int i = 0; i < 5; i++) {
- targetNode = targetNode.getNext();
- method.instructions.remove(targetNode.getPrevious());
- }
- } else if (targetNode != null) {
- AbstractInsnNode popNode = targetNode;
- for (int i = 0; i < 4; i++) {
- popNode = popNode.getNext();
- }
- LabelNode newLabelNode = new LabelNode();
- InsnList toInsert = new InsnList();
- toInsert.add(new VarInsnNode(ALOAD, 4));
- toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Hooks.class), "cactusDoesDamage", isObfuscated ? "(Lsm;)Z" : "(Lnet/minecraft/entity/Entity;)Z", false));
- toInsert.add(new JumpInsnNode(IFEQ, newLabelNode));
- method.instructions.insertBefore(targetNode, toInsert);
- method.instructions.insert(popNode, newLabelNode);
- File classDump = new File("classDumb.class");
- try {
- ASMHelper.writeClassToFile(blockCactusClass, classDump);
- System.out.println(classDump.getAbsolutePath());
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- System.out.println("Something went wrong transforming BlockCactus!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement