Skip to main content

Creating Commands

Commands can be created using a dedicated Command Class and the @Command Annotation.

@Command("foo")
public static class TestCommand {
@Execute
public boolean runsWhenCommandIsExecuted(@Sender CommandSourceStack sender) {
sender.sendSystemMessage(RESPONSE);
return true;
}
}

Registration

Every command classes must then be registered using the CommandRegistry.registerCommand method.

CommandRegistry.registerCommand(TestCommand.class);

This should be done in the common package at entrypoint invocation (In fabric the ModInitializer#onInitialize and on NeoForge the mod constructor).