User Tools

Site Tools


tutorial:commands

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:commands [2024/02/23 14:22] – Documenting and first draft allen1210tutorial:commands [2025/07/06 07:10] (current) – [Register a basic command] solidblock
Line 3: Line 3:
 ====== Creating Commands ====== ====== Creating Commands ======
  
-Creating commands can allow a mod developer to add functionality that can used through a command. This tutorial will teach you how to register commands, and the general command structure of Brigadier.+Creating commands can allow a mod developer to add functionality that can be used through a command. This tutorial will teach you how to register commands, and the general command structure of Brigadier.
  
 ===== What is Brigadier? ===== ===== What is Brigadier? =====
Line 105: Line 105:
 </code> </code>
  
-**Please ensure you import the correct static method.** The method ''literal'' is ''CommandManager.literal''. You can also alternatively explicitly write ''CommandManager.literal'' instead of using static imports. ''CommandManager.literal("foo")'' tells brigadier this command has one node, a **literal** called ''foo''.+**Please ensure you import the correct static method.** The method ''literal'' is ''CommandManager.literal''. You can also alternatively explicitly write ''CommandManager.literal'' instead of using static imports. ''%%CommandManager.literal("foo")%%'' tells brigadier this command has one node, a **literal** called ''foo''.
  
 In the ''sendFeedback'' method, the first parameter is the text to be sent, which is a ''Text'' in versions below 1.20, or a ''Supplier<Text>'' in 1.20 and above (this is used to avoid instantiating ''Text'' objects when not needed, so please do not use ''Suppliers.ofInstance'' or smiliar methods). The second parameter determines whether to broadcast the feedback to other operators. If the command is to //query// something without actually affecting the world, such as query the current time or some player's score, it should be ''false''. If the command actually //does// something, such as changing the time or modifying someone's score, it should be ''true''. If game rule ''sendCommandFeedback'' is false, you will not accept any feedback. If the sender is modifed through ''/execute as ...'', the feedback is sent to the original sender. In the ''sendFeedback'' method, the first parameter is the text to be sent, which is a ''Text'' in versions below 1.20, or a ''Supplier<Text>'' in 1.20 and above (this is used to avoid instantiating ''Text'' objects when not needed, so please do not use ''Suppliers.ofInstance'' or smiliar methods). The second parameter determines whether to broadcast the feedback to other operators. If the command is to //query// something without actually affecting the world, such as query the current time or some player's score, it should be ''false''. If the command actually //does// something, such as changing the time or modifying someone's score, it should be ''true''. If game rule ''sendCommandFeedback'' is false, you will not accept any feedback. If the sender is modifed through ''/execute as ...'', the feedback is sent to the original sender.
Line 130: Line 130:
  
 ===== Static Imports ===== ===== Static Imports =====
-In the example above, the use of static imports is used for code simplifying. For a literal this would shorten the statement to ''literal("foo")''. This also works for getting the value of an argument. This shortens ''StringArgumentType.getString(ctx, "string")'' to ''getString(ctx, "string")''. This also works for Minecraft's own argument types.+In the example above, the use of static imports is used for code simplifying. For a literal this would shorten the statement to ''%%literal("foo")%%''. This also works for getting the value of an argument. This shortens ''%%StringArgumentType.getString(ctx, "string")%%'' to ''%%getString(ctx, "string")%%''. This also works for Minecraft's own argument types.
  
 Below is an example of some static imports: Below is an example of some static imports:
tutorial/commands.1708698170.txt.gz · Last modified: 2024/02/23 14:22 by allen1210