Add simple commands docs - #363
Conversation
IchHabeHunger54
left a comment
There was a problem hiding this comment.
Hello and thanks for the contribution! This is a good PR, most things I noticed are typos or formatting issues.
|
@IchHabeHunger54 Hi, I just tweaked based on your comments and added the custom argument type as well. I did end up putting it into the top-level document page, which IMO I think is fine. Let me know if you think otherwise :D |
IchHabeHunger54
left a comment
There was a problem hiding this comment.
Looking good, a few requests for changes and some info I noticed to be missing by looking at my own modded commands:
- In the
#executeslambda, please explain what the return value means. In many vanilla instances, this returns the amount of players affected. (See e.g. the/teleportcommand). - Permissions should be touched upon shortly. Something like
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))being mentioned somewhere would be good. - Commands currently have their own docs folder. Since they are a single article, please move them into the Misc section and undo the changing of the
_category_.jsonfiles.
|
|
||
| ## Custom Argument Types | ||
|
|
||
| A value that none of the existing types can parse is handled by implementing a custom argument type via. `ArgumentType<T>`, which reads the raw command text from a `StringReader` and returns a value of type `T`. |
There was a problem hiding this comment.
| A value that none of the existing types can parse is handled by implementing a custom argument type via. `ArgumentType<T>`, which reads the raw command text from a `StringReader` and returns a value of type `T`. | |
| A value that none of the existing types can parse is handled by implementing a custom argument type via `ArgumentType<T>`, which reads the raw command text from a `StringReader` and returns a value of type `T`. |
| A value that none of the existing types can parse is handled by implementing a custom argument type via. `ArgumentType<T>`, which reads the raw command text from a `StringReader` and returns a value of type `T`. | ||
|
|
||
| ```java | ||
| public class SpellArgument implements ArgumentType<Spell> { |
There was a problem hiding this comment.
Mention that Spell is a custom type for the sake of example, e.g. in a comment above the class.
Deploying with Cloudflare Pages
|
| { | ||
| "label": "Commands", | ||
| "position": 13 | ||
| } No newline at end of file |
There was a problem hiding this comment.
I don't see why this needs to be it's own section instead of something under misc.
| @Override | ||
| public Spell parse(StringReader reader) throws CommandSyntaxException { | ||
| String name = reader.readUnquotedString(); | ||
| // Look up the spell, throwing ERROR_UNKNOWN_SPELL#createWithContext if there is none |
There was a problem hiding this comment.
I would rephrase this to use the word 'validate' since that's functionally what it's supposed to do.
| // Suggest the names of the available spells or none | ||
| return Suggestions.empty(); |
There was a problem hiding this comment.
This should elaborated on as the suggestions are obtained based on the sided context, meaning that if you plan to use data on the server, it may not show up if queried in a client context unless synced and referenced.
|
|
||
| An argument is used in two places. It is **declared** while building the tree, by supplying a name and an `ArgumentType`, and its parsed value is **accessed** inside the execution logic from the `CommandContext`, using that same name. The name is the contract between the two. The sections below cover each half in turn. | ||
|
|
||
| ## Registering Commands |
There was a problem hiding this comment.
I wonder if there should be a minor note here for registering a command that's only available on the client. The process is exactly the same via RegisterClientCommandsEvent.
Hey 👋 First time contributor here.
I wanted to try and take a crack at adding some simple documentation for commands. Should resolve #299 if found satisfactory enough, my plan is to come with a follow-up PR for how to create a custom argument type.
Let me know if modifying the other category indicies is incorrect and should be reverted.
Please suggest as many changes as needed to the wording, it's my first time trying to contribute more than typos to public documentation, as I'm hoping to improve.
Preview URL: https://pr-363.neoforged-docs-previews.pages.dev