55import club .maxstats .weave .loader .api .HookManager ;
66import club .maxstats .weave .loader .api .event .*;
77import com .example .mod .command .TestCommand ;
8- import com .example .mod .listener .RenderGameOverlayListener ;
9- import kotlin .Unit ;
8+ import com .example .mod .hook .MinecraftHook ;
109import net .minecraft .client .Minecraft ;
1110import net .minecraft .util .ChatComponentText ;
1211import org .lwjgl .input .Keyboard ;
13- import org .lwjgl .input .Mouse ;
14- import org .objectweb .asm .Opcodes ;
15- import org .objectweb .asm .Type ;
16- import org .objectweb .asm .tree .MethodInsnNode ;
1712
1813public class ExampleMod implements ModInitializer {
1914 @ Override
2015 public void preInit (HookManager hookManager ) {
21- hookManager .register ("net/minecraft/client/Minecraft" , cn -> {
22- cn .methods .stream ()
23- .filter (m -> m .name .equals ("startGame" ))
24- .findFirst ().orElseThrow ()
25- .instructions .insert (
26- new MethodInsnNode (
27- Opcodes .INVOKESTATIC ,
28- Type .getInternalName (this .getClass ()),
29- "onStart" ,
30- "()V"
31- )
32- );
33- });
16+ System .out .println ("Initializing ExampleMod!" );
3417
35- EventBus .INSTANCE .subscribe (KeyboardEvent .class , e -> {
36- Minecraft .getMinecraft ().thePlayer .addChatMessage (
37- new ChatComponentText ("Key Pressed: " + Keyboard .getKeyName (e .getKeyCode ()))
38- );
39- });
18+ hookManager .register (new MinecraftHook ());
19+ CommandBus .INSTANCE .register (new TestCommand ());
4020
41- EventBus .INSTANCE .subscribe (MouseEvent .class , e -> {
42- if (e . getButton () >= 0 ) {
21+ EventBus .INSTANCE .subscribe (KeyboardEvent .class , e -> {
22+ if (Minecraft . getMinecraft (). currentScreen == null && e . getKeyState () ) {
4323 Minecraft .getMinecraft ().thePlayer .addChatMessage (
44- new ChatComponentText ("Mouse Pressed: " + Mouse . getButtonName (e .getButton ()))
24+ new ChatComponentText ("Key Pressed: " + Keyboard . getKeyName (e .getKeyCode ()))
4525 );
4626 }
4727 });
4828
49- EventBus .INSTANCE .subscribe (ShutdownEvent .class , e -> System .out .println ("Shutdown Event" ));
50- EventBus .INSTANCE .subscribe (ChatSentEvent .class , e -> {
51- if (e .getMessage ().equals ("Test" )) {
52- e .setCancelled (true );
53- Minecraft .getMinecraft ().thePlayer .addChatMessage (new ChatComponentText ("Cancelled 'Test' Message" ));
54- }
29+ EventBus .INSTANCE .subscribe (RenderHandEvent .class , e -> {
30+ e .setCancelled (true );
5531 });
56-
57- EventBus .INSTANCE .subscribe (new RenderGameOverlayListener ());
58- EventBus .INSTANCE .subscribe (StartGameEvent .Pre .class , e -> System .out .println ("Pre StartGame" ));
59- EventBus .INSTANCE .subscribe (StartGameEvent .Post .class , e -> System .out .println ("Post StartGame" ));
60-
61- CommandBus .INSTANCE .register (new TestCommand ());
62- }
63-
64- public static void onStart () {
65- System .out .println ("Hello World from Minecraft#startGame" );
6632 }
6733}
0 commit comments