tutorial:command_redirects
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:command_redirects [2022/08/08 02:39] – solidblock | tutorial:command_redirects [2024/04/15 06:46] (current) – [Chainable Commands] solidblock | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| <code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
| public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
| - | | + | |
| public void onInitialize() { | public void onInitialize() { | ||
| CommandRegistrationCallback.EVENT.register((dispatcher, | CommandRegistrationCallback.EVENT.register((dispatcher, | ||
| final LiteralCommandNode< | final LiteralCommandNode< | ||
| .executes(context -> { | .executes(context -> { | ||
| - | | + | context.getSource().sendFeedback(() -> Text.literal(" |
| - | | + | |
| return 1; | return 1; | ||
| Line 26: | Line 25: | ||
| </ | </ | ||
| - | 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 ''/ | + | Let's first consider the vanilla ''/ |
| Below is an example of a chainable command: | Below is an example of a chainable command: | ||
| Line 38: | Line 39: | ||
| 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 46: | 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.1659926374.txt.gz · Last modified: 2022/08/08 02:39 by solidblock