Argument Types
Contains the various built-in argument types Grenadier has.
Most argument types have a vanilla counterpart that the API types are mapped to. Grenadier does also feature several argument types that have no vanilla counterpart and have more general use cases.
General use argument types
Argument type | Description | Example |
---|---|---|
OptionsArgument | Parse a list of pre-set options and flags | key=value -flag |
MapArgument | Takes a string-object map and parses a map value via its string key | a_value |
EnumArgument | Parses an enum constant from it’s Enum.name() | red |
ArrayArgument | Parses a list of a specified type of arguments | minecraft:stone,minecraft:oak_log |
LocalDateArgument | Parses a LocalDate object from the ISO-8601 format | 12-12-2023 |
TimeArgument | Parses a Duration | 3s, 3seconds, 5m, 5minutes, 3m+2s, 4h-23m |
Minecraft argument types
Argument type | Description | Example |
---|---|---|
BlockArgument | Parses a block state and optionally NBT data that can be applied to a block | minecraft:chest[facing=west]{dataKey:1b} |
BlockFilterArgument | Parses a block or block tag that can be used to as a predicate for blocks | #minecraft:buttons[face=ceiling] |
ComponentArgument | Parses a text component from a JSON format | {"text":"Some text","color":"red"} |
EntityArgument | Parses an entity selector that returns 1 or more entities/players | @e[limit=1,distance=..2] |
GameModeArgument | Game mode value from a non-vanilla set of labels | creative, survival, c, s |
ItemArgument | Parses an itemstack along with item NBT data | minecraft:stone{nbtKey:1b} |
ItemFilterArgument | Parses an item or itemtag along with NBT data that will be used as a predicate against other items | #minecraft:flowers{nbtKey:1b} |
KeyArgument | Parses a namespaced key | minecraft:stone |
NbtArgument | Parses NBT data in the SNBT format | {foo:'bar',abc:1b} |
ObjectiveArgument | Parses a scoreboard objective from its name | deaths, noClip |
ParticleArgument | Parses a particle by its key | minecraft:explosion_emitter |
PositionArgument | Parses a relative/local/absolute 2D or 3D position | ~ ~ ~ |
TagPathArgument | Parses an NBT path | key1.key2[] |
TeamArgument | Parses a scoreboard team from its name | team1, Team2 |
UuidArgument | Parses a UUID by its hexadecimal value | 21290ce5-679c-4917-b30e-168c0d450c72 |
WorldArgument | Parses a world by its name | world, world_the_end |
DoubleRangeArgument | Parses an inclusive range of double values | 1..2, 1.., ..3 |
IntRangeArgument | Parses an inclusive range of integer values | 1..2, 1.., ..3 |
Using argument types
Argument types can be used very simply, for example:
command.then(argument("local date", ArgumentTypes.localDate())
.executes(context -> {
LocalDate date = context.getArgument("local date", LocalDate.class);
context.getSource().sendMessage(date.toString());
return 0;
}
);