Skip to content

Commit e2679ff

Browse files
Add example command
1 parent 7c17b12 commit e2679ff

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repositories {
1313
}
1414

1515
dependencies {
16-
compileOnly("com.github.Weave-MC:Weave-Loader:f736ac0323")
16+
compileOnly("com.github.Weave-MC:Weave-Loader:0c09d7496f")
1717
}
1818

1919
tasks.compileJava {

src/main/java/com/example/mod/ExampleMod.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.example.mod;
22

3+
import club.maxstats.weave.loader.api.CommandBus;
34
import club.maxstats.weave.loader.api.ModInitializer;
45
import club.maxstats.weave.loader.api.HookManager;
56
import club.maxstats.weave.loader.api.event.*;
7+
import com.example.mod.command.TestCommand;
68
import com.example.mod.listener.RenderGameOverlayListener;
9+
import kotlin.Unit;
710
import net.minecraft.client.Minecraft;
811
import net.minecraft.util.ChatComponentText;
912
import org.lwjgl.input.Keyboard;
@@ -43,10 +46,7 @@ public void preInit(HookManager hookManager) {
4346
}
4447
});
4548

46-
EventBus.INSTANCE.subscribe(ShutdownEvent.class, e-> {
47-
System.out.println("Shutdown Event");
48-
});
49-
49+
EventBus.INSTANCE.subscribe(ShutdownEvent.class, e -> System.out.println("Shutdown Event"));
5050
EventBus.INSTANCE.subscribe(ChatSentEvent.class, e -> {
5151
if (e.getMessage().equals("Test")) {
5252
e.setCancelled(true);
@@ -55,15 +55,12 @@ public void preInit(HookManager hookManager) {
5555
});
5656

5757
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"));
5860

59-
EventBus.INSTANCE.subscribe(StartGameEvent.Pre.class, e -> {
60-
System.out.println("Pre StartGame");
61-
});
62-
63-
EventBus.INSTANCE.subscribe(StartGameEvent.Post.class, e -> {
64-
System.out.println("Post StartGame");
65-
});
61+
CommandBus.INSTANCE.register(new TestCommand());
6662
}
63+
6764
public static void onStart() {
6865
System.out.println("Hello World from Minecraft#startGame");
6966
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.mod.command;
2+
3+
import club.maxstats.weave.loader.api.Command;
4+
import net.minecraft.client.Minecraft;
5+
import net.minecraft.util.ChatComponentText;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
public class TestCommand extends Command {
12+
@NotNull
13+
@Override
14+
public String getName() {
15+
return "test";
16+
}
17+
18+
@NotNull
19+
@Override
20+
public List<String> getAliases() {
21+
return Arrays.asList("sometest", "somealias", "t");
22+
}
23+
24+
@NotNull
25+
@Override
26+
public String getUsage() {
27+
return "<arg1> <arg2> [arg3]";
28+
}
29+
30+
@Override
31+
public void handle(@NotNull List<String> args) {
32+
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("This is a command!"));
33+
}
34+
}

0 commit comments

Comments
 (0)