Add stopwatch command and execute if stopwatch
Adds the stopwatches store saved in data/minecraft/stopwatches.dat, the /stopwatch create, query, restart and remove commands, and the execute if stopwatch condition, with the parse tree and parse fixture updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,7 @@ pub struct Registries {
|
||||
pub bossbars: Vec<String>,
|
||||
pub predicates: Vec<String>,
|
||||
pub schedules: Vec<String>,
|
||||
pub stopwatches: Vec<String>,
|
||||
pub recipes: Vec<String>,
|
||||
pub sounds: Vec<String>,
|
||||
pub damage_types: Vec<String>,
|
||||
@@ -156,6 +157,7 @@ pub enum ArgType {
|
||||
TeamColor,
|
||||
/// RangeArgument.Ints (`1`, `1..`, `..5`, `1..5`).
|
||||
IntRange,
|
||||
FloatRange,
|
||||
/// NbtPathArgument (kept as text).
|
||||
NbtPath,
|
||||
/// NbtTagArgument: any SNBT value (kept as text).
|
||||
@@ -426,6 +428,7 @@ pub enum Arg {
|
||||
Anchor(bool),
|
||||
ScoreHolder(ScoreHolderArg),
|
||||
IntRange(IntRange),
|
||||
DoubleRange(DoubleRange),
|
||||
}
|
||||
|
||||
fn is_id_char(c: char) -> bool {
|
||||
@@ -1750,6 +1753,7 @@ impl ArgType {
|
||||
Arg::Str(name.to_owned())
|
||||
}
|
||||
ArgType::IntRange => Arg::IntRange(range_int(reader)?),
|
||||
ArgType::FloatRange => Arg::DoubleRange(range_double(reader)?),
|
||||
ArgType::Name(_) => Arg::Str(reader.read_string()?),
|
||||
ArgType::Vec2 | ArgType::ColumnPos => {
|
||||
let block = matches!(self, ArgType::ColumnPos);
|
||||
@@ -1923,6 +1927,7 @@ impl ArgType {
|
||||
"storages" => reg.storages.clone(),
|
||||
"bossbars" => reg.bossbars.clone(),
|
||||
"schedules" => reg.schedules.clone(),
|
||||
"stopwatches" => reg.stopwatches.clone(),
|
||||
"recipes" => reg.recipes.clone(),
|
||||
"sounds" => reg.sounds.clone(),
|
||||
"damage_types" => reg.damage_types.clone(),
|
||||
|
||||
@@ -180,6 +180,11 @@ fn conditionals(d: &mut Dispatcher, m: usize, ex: usize) {
|
||||
let p = d.argument(predicate, "predicate", ArgType::Id("predicates"));
|
||||
conditional(d, p, ex);
|
||||
|
||||
let stopwatch = d.literal(m, "stopwatch");
|
||||
let id = d.argument(stopwatch, "id", ArgType::Id("stopwatches"));
|
||||
let range = d.argument(id, "range", ArgType::FloatRange);
|
||||
conditional(d, range, ex);
|
||||
|
||||
let function = d.literal(m, "function");
|
||||
let name = d.argument(function, "name", ArgType::Function);
|
||||
conditional(d, name, ex);
|
||||
|
||||
@@ -21,6 +21,7 @@ pub fn register(d: &mut Dispatcher, root: usize) {
|
||||
item(d, root);
|
||||
bossbar(d, root);
|
||||
function(d, root);
|
||||
stopwatch(d, root);
|
||||
|
||||
// return <value> | fail | run <command>
|
||||
let ret = d.literal(root, "return");
|
||||
@@ -255,3 +256,32 @@ fn function(d: &mut Dispatcher, root: usize) {
|
||||
d.executes(path, "function");
|
||||
}
|
||||
}
|
||||
|
||||
/// stopwatch create <id> | query <id> [<scale>] | restart <id> | remove <id>
|
||||
fn stopwatch(d: &mut Dispatcher, root: usize) {
|
||||
let sw = d.literal(root, "stopwatch");
|
||||
d.requires(sw, GAMEMASTERS);
|
||||
let create = d.literal(sw, "create");
|
||||
let id = d.argument(create, "id", ArgType::Id("none"));
|
||||
d.executes(id, "stopwatch.create");
|
||||
let query = d.literal(sw, "query");
|
||||
let id = d.argument(query, "id", ArgType::Id("stopwatches"));
|
||||
d.executes(id, "stopwatch.query");
|
||||
let scale = d.argument(
|
||||
id,
|
||||
"scale",
|
||||
ArgType::Double {
|
||||
min: f64::MIN,
|
||||
max: f64::MAX,
|
||||
},
|
||||
);
|
||||
d.executes(scale, "stopwatch.query");
|
||||
for (name, command) in [
|
||||
("restart", "stopwatch.restart"),
|
||||
("remove", "stopwatch.remove"),
|
||||
] {
|
||||
let l = d.literal(sw, name);
|
||||
let id = d.argument(l, "id", ArgType::Id("stopwatches"));
|
||||
d.executes(id, command);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user