Skip to content

Commit 7e5c879

Browse files
committed
Convert to java
1 parent 141b166 commit 7e5c879

File tree

4 files changed

+43
-41
lines changed

4 files changed

+43
-41
lines changed

build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
kotlin("jvm") version "1.8.0"
2+
java
33
}
44

55
group = "com.example"
@@ -11,7 +11,11 @@ repositories {
1111
}
1212

1313
dependencies {
14-
implementation("com.github.Weave-MC:Weave-Loader:f8caa7184e")
14+
implementation("com.github.Weave-MC:Weave-Loader:6015cdb81f")
15+
}
16+
17+
tasks.compileJava {
18+
options.release.set(11)
1519
}
1620

1721
tasks.jar {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

src/main/kotlin/com/example/mod/ExampleMod.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/kotlin/com/example/mod/hooks/MinecraftHook.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)