tutorial:command_redirects
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tutorial:command_redirects [2022/08/08 02:19] – created (migrated from [[tutorial:commands]]) solidblock | tutorial:command_redirects [2024/04/15 06:46] (current) – [Chainable Commands] solidblock | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ======= Command Redirects ======= | ======= Command Redirects ======= | ||
| - | Redirects are Brigadier' | + | Redirects are Brigadier' |
| ===== Aliases ===== | ===== Aliases ===== | ||
| - | Below is how Minecraft | + | In vanilla |
| + | |||
| + | The example shows how ''/ | ||
| <code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
| - | public | + | public |
| - | LiteralCommandNode | + | @Override |
| - | | + | public |
| - | .then(argument(" | + | CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, |
| - | | + | |
| - | .executes(context | + | .executes(context -> { |
| - | | + | context.getSource().sendFeedback(() -> Text.literal(" |
| - | | + | |
| - | | + | return 1; |
| - | | + | })); |
| - | | + | dispatcher.register(literal(" |
| + | | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
| - | The '' | + | The '' |
| + | |||
| + | The redirection target may not always be the root node. Commans can be redirected to sub-nodes, including arguments. | ||
| ===== Chainable Commands ====== | ===== Chainable Commands ====== | ||
| - | Commands such as ''/ | + | Commands such as ''/ |
| + | |||
| + | Let's first consider the vanilla ''/ | ||
| + | |||
| + | Below is an example of a chainable command: | ||
| <code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
| LiteralCommandNode< | LiteralCommandNode< | ||
| LiteralCommandNode< | LiteralCommandNode< | ||
| - | // You can register under the same literal more than once, it will just register new parts of the branch as shown below if you register a duplicate branch an error will popup in console warning of conflicting commands but one will still work. | + | // You can register under the same literal more than once, it will just register new parts |
| + | // of the branch as shown below if you register a duplicate branch an error will popup in | ||
| + | // console warning of conflicting commands but one will still work. | ||
| .then(literal(" | .then(literal(" | ||
| .then(literal(" | .then(literal(" | ||
| Line 37: | Line 49: | ||
| .then(literal(" | .then(literal(" | ||
| .executes(ctx -> { | .executes(ctx -> { | ||
| - | ctx.getSource().sendFeedback(Text.literal(" | + | ctx.getSource().sendFeedback(() -> Text.literal(" |
| return Command.SINGLE_SUCCESS; | return Command.SINGLE_SUCCESS; | ||
| - | }))); | + | |
| </ | </ | ||
| - | The '' | + | The '' |
| <code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
| - | .redirect(rootNode, | + | |
| - | // When redirecting, | + | // When redirecting, |
| - | return | + | return context.getSource().withLookingAt(Vec3ArgumentType.getVec3(context, |
| - | }) | + | }) |
| </ | </ | ||
| + | :!: In the redirect modifier, only arguments after the redirected nodes can be used. Meanwhile, arguments before the redirect modifier cannot be used in subsequent redirections (if any) or the final execution. | ||
tutorial/command_redirects.1659925157.txt.gz · Last modified: 2022/08/08 02:19 by solidblock