User Tools

Site Tools


zh_cn:tutorial:command_redirects

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revisionBoth sides next revision
zh_cn:tutorial:command_redirects [2023/04/20 10:30] – created solidblockzh_cn:tutorial:command_redirects [2023/04/20 10:36] – [Chainable Commands] solidblock
Line 28: Line 28:
 ''redirect'' 会告诉 birgadier,在另一个命令节点之后解析命令。 ''redirect'' 会告诉 birgadier,在另一个命令节点之后解析命令。
  
-===== Chainable Commands ====== +===== 可串联的命令 ====== 
-Commands such as ''/execute as @e[type=player] in the_end run tp ~ ~ ~'' are also possible because of redirects.+像 ''/execute as @e[type=player] in the_end run tp ~ ~ ~'' 这样的命令形式也是可行的,因为也使用了重定向。
  
-Let's first consider the vanilla ''/execute'' command. There is a node after the ''%%literal("execute")%%''. After dispatching subcommands, the dispatcher is redirected to that node (with some modifiers), making you possible to, after completing sub-command arguments, type whatever can be typed directly after ''/execute''. In the sub-command ''run'', the dispatcher is redirected to the root node (''dispatcher.getRoot()''), allowing you to type another complete command after the word "''run''".+首先考虑原版的 ''/execute'' 命令。这是 ''%%literal("execute")%%'' 后的一个节点。在分发子命令之后,分发器会重定向到那个节点(并带有一些修饰),让你能够在输入完子命令的参数之后,输入可以在 ''/execute'' 之后输入的任何内容。在子命令 ''run'' 中,分发器会重定向到根节点(''dispatcher.getRoot()''),允许你在输入完 ''run'' 后输入另一个完整的命令。
  
-Below is an example of a chainable command:+下面是一个可串联的命令的例子:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 LiteralCommandNode<ServerCommandSource> rootNode = dispatcher.register(literal("fabric_test")); LiteralCommandNode<ServerCommandSource> rootNode = dispatcher.register(literal("fabric_test"));
 LiteralCommandNode<ServerCommandSource> root1 = dispatcher.register(literal("fabric_test" LiteralCommandNode<ServerCommandSource> root1 = dispatcher.register(literal("fabric_test"
-    // 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("extra")     .then(literal("extra")
         .then(literal("long")         .then(literal("long")
-            .redirect(rootNode, this::lengthen)) // Return to root for chaining+            .redirect(rootNode, this::lengthen)) // 返回串联的根节点
         .then(literal("short")         .then(literal("short")
-            .redirect(rootNode, this::shorten))) // Return to root for chaining+            .redirect(rootNode, this::shorten))) // 返回串联的根节点
         .then(literal("command")         .then(literal("command")
             .executes(ctx -> {             .executes(ctx -> {
-                ctx.getSource().sendFeedback(Text.literal("Chainable Command"), false);+                ctx.getSource().sendFeedback(Text.literal("可串联的命令"), false);
                 return Command.SINGLE_SUCCESS;                 return Command.SINGLE_SUCCESS;
 }))); })));
 </code> </code>
  
-The ''redirect'' can also modify the ''CommandSource'' by use of a "redirect modifier" (''SingleRedirectModifier<S>''), which is used as a lambda.+''redirect'' 方法还可以修改 ''CommandSource'',方法就是使用“redirect modifier”(''SingleRedirectModifier<S>''),它是一个 lambda
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 .redirect(rootNode, context -> { .redirect(rootNode, context -> {
-    // When redirecting, modify the looking direction of the command source.+    // 重定向时,修改命令源的视线方向。
     return ((ServerCommandSource) context.getSource()).withLookingAt(Vec3ArgumentType.getVec3(context, "pos"));     return ((ServerCommandSource) context.getSource()).withLookingAt(Vec3ArgumentType.getVec3(context, "pos"));
 }) })
 </code> </code>
  
zh_cn/tutorial/command_redirects.txt · Last modified: 2024/04/15 06:46 by solidblock