|
| 1 | +package com.example.mod; |
| 2 | + |
| 3 | +import club.maxstats.weave.loader.api.HookManager; |
| 4 | +import club.maxstats.weave.loader.api.ModInitializer; |
| 5 | +import club.maxstats.weave.loader.api.event.EventBus; |
| 6 | +import club.maxstats.weave.loader.api.event.annotation.SubscribeEvent; |
| 7 | +import club.maxstats.weave.loader.api.event.impl.InputEvent; |
| 8 | +import org.jetbrains.annotations.NotNull; |
| 9 | +import org.objectweb.asm.Opcodes; |
| 10 | +import org.objectweb.asm.Type; |
| 11 | +import org.objectweb.asm.tree.FieldInsnNode; |
| 12 | +import org.objectweb.asm.tree.InsnList; |
| 13 | +import org.objectweb.asm.tree.LdcInsnNode; |
| 14 | +import org.objectweb.asm.tree.MethodInsnNode; |
| 15 | + |
| 16 | +public class ExampleMod implements ModInitializer { |
| 17 | + @Override |
| 18 | + public void preinit(@NotNull HookManager hookManager) { |
| 19 | + hookManager.register("net/minecraft/client/Minecraft", cn -> { |
| 20 | + cn.methods.stream() |
| 21 | + .filter(m -> m.name.equals("startGame")) |
| 22 | + .findFirst().orElseThrow() |
| 23 | + .instructions.insert(new InsnList() {{ |
| 24 | + add(new FieldInsnNode(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;")); |
| 25 | + add(new LdcInsnNode("Hello World from Minecraft#startGame")); |
| 26 | + add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V")); |
| 27 | + }}); |
| 28 | + }); |
| 29 | + |
| 30 | + EventBus.INSTANCE.subscribe(this); |
| 31 | + } |
| 32 | + |
| 33 | + @SubscribeEvent |
| 34 | + public void onInput(InputEvent e) { |
| 35 | + System.out.println("Pressed: " + e.getKeycode()); |
| 36 | + } |
| 37 | +} |
0 commit comments