Data on /give

This commit is contained in:
2026-10-25 15:42:20 -03:00
parent 583cce88c1
commit feb1ddd1f7
7 changed files with 121 additions and 25 deletions
+18
View File
@@ -333,6 +333,20 @@ export function greedy_string(): ArgumentType<string> {
return { greedy: true, parse: (text) => text };
}
// a json value, the rest of the line so it can have spaces, like an item's data
export function json(): ArgumentType<unknown> {
return {
greedy: true,
parse(text) {
try {
return JSON.parse(text);
} catch {
throw new CommandError(`${text} isn't JSON`);
}
},
};
}
// one of a few words, suggested
export function choice<T extends string>(options: readonly T[]): ArgumentType<T> {
return {
@@ -376,3 +390,7 @@ export function item(): ArgumentType<string> {
export function block(): ArgumentType<string> {
return registry_id("blocks", "block");
}
export function fluid(): ArgumentType<string> {
return registry_id("fluids", "fluid");
}
+4 -1
View File
@@ -176,10 +176,13 @@ export interface CommandRegistry {
boolean(): ArgumentType<boolean, CommandSource>;
word(): ArgumentType<string, CommandSource>;
greedy_string(): ArgumentType<string, CommandSource>;
// a json value, the rest of the line like greedy_string
json(): ArgumentType<unknown, CommandSource>;
choice<T extends string>(options: readonly T[]): ArgumentType<T, CommandSource>;
// an item or block id. without a namespace, whichever has that name
// an item, block or fluid id. without a namespace, whichever has that name
item(): ArgumentType<Id, CommandSource>;
block(): ArgumentType<Id, CommandSource>;
fluid(): ArgumentType<Id, CommandSource>;
// an online player's name
player(): ArgumentType<Player, CommandSource>;
};