tutorial:commands
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
tutorial:commands [2019/11/16 17:01] – Line numbers i509vcb | tutorial:commands [2020/05/07 20:12] – Amend to use new API i509vcb | ||
---|---|---|---|
Line 8: | Line 8: | ||
If you just want to see how to register commands you've come to the right place here. | If you just want to see how to register commands you've come to the right place here. | ||
- | Registering commands is done through '' | + | Registering commands is done by registering a new listener in the '' |
- | + | The event should be registered | |
- | The '' | + | |
- | + | ||
- | The dedicated flag if set to true will tell Fabric to only register the command on a '' | + | |
+ | The dedicated parameter if true will tell event listeners that the server commands are being registered on is a '' | ||
Below are a few examples of how the commands can be registered. | Below are a few examples of how the commands can be registered. | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | CommandRegistry.INSTANCE.register(false, dispatcher -> TutorialCommands.register(dispatcher)); // All commands are registered in a single class that references | + | // The actual registration of commands can be delegated to another class via a method reference |
- | + | CommandRegistrationCallback.EVENT.register(TutorialCommands::register); | |
- | CommandRegistry.INSTANCE.register(false, | + | |
- | | + | // Or you can define |
- | | + | CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) |
+ | TutorialCommand.register(dispatcher); | ||
+ | | ||
+ | TutorialHelpCommand.register(dispatcher); | ||
+ | | ||
+ | IntegratedTutorialHelpCommand.register(dispatcher); | ||
+ | } | ||
}); | }); | ||
- | CommandRegistry.INSTANCE.register(true, dispatcher -> { // Or directly registering the command to the dispatcher. | + | CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) |
dispatcher.register(LiteralArgumentBuilder.literal(" | dispatcher.register(LiteralArgumentBuilder.literal(" | ||
}); | }); |
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210