aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/bscv/patches/PortalGuiPatch.java
blob: 7a36e8e12c7887efc8c0b3103b769c768f07b8e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ftbsc.bscv.patches;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodNode;

import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.tools.PatternMatcher;
import net.minecraft.client.entity.player.ClientPlayerEntity;

@Patch(value = ClientPlayerEntity.class, reason = "prevent minecraft from force closing guis when entering portals")
public abstract class PortalGuiPatch implements Opcodes {
   @Target
   abstract void handleNetherPortalClient();

   @Injector
   public void inject(ClassNode clazz, MethodNode main) {
      LabelNode skip = new LabelNode();

      AbstractInsnNode found = PatternMatcher.builder()
         .opcodes(ALOAD, GETFIELD, IFEQ)
         .ignoreFrames()
         .ignoreLabels()
         .ignoreLineNumbers()
         .build()
         .find(main)
         .getLast();

      AbstractInsnNode after = PatternMatcher.builder()
         .opcodes(GETFIELD, ACONST_NULL, CHECKCAST, INVOKEVIRTUAL)
         .ignoreFrames()
         .ignoreLabels()
         .ignoreLineNumbers()
         .build()
         .find(main)
         .getLast();

      main.instructions.insert(found, new JumpInsnNode(GOTO, skip));
      main.instructions.insert(after, skip);
   }
}