Keep errors inside forked execute chains silent, as vanilla
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -98,9 +98,17 @@ impl Game<'_> {
|
||||
}
|
||||
"tick" => {
|
||||
self.chat_capture = Some(Vec::new());
|
||||
// The oracle's player has no client moving it: hold the
|
||||
// player where commands put it while the game ticks.
|
||||
let held = self.player.as_ref().map(|p| p.position);
|
||||
for _ in 0..op["n"].as_u64().unwrap_or(1) {
|
||||
self.update_world();
|
||||
self.tick()?;
|
||||
if let (Some(p), Some(at)) = (self.player.as_mut(), held) {
|
||||
p.position = at;
|
||||
p.velocity = horizon_core::geometry::Vec3::new(0.0, 0.0, 0.0);
|
||||
p.fall_distance = 0.0;
|
||||
}
|
||||
}
|
||||
let messages = self.chat_capture.take().unwrap_or_default();
|
||||
if op["record"].as_bool() == Some(true) {
|
||||
|
||||
@@ -251,6 +251,10 @@ impl Game<'_> {
|
||||
pub(in crate::game) fn run_execute(&mut self, ctx: &Context) -> R<i32> {
|
||||
let mut sources = vec![self.command_source.unwrap_or_else(|| self.player_source())];
|
||||
let mut c = ctx;
|
||||
// A fork modifier (as, at, positioned as, rotated as, facing entity,
|
||||
// on, a non-terminal if/unless) makes later errors silent
|
||||
// (CommandSourceStack.handleError with `forked`).
|
||||
let mut forked = false;
|
||||
loop {
|
||||
let word = c
|
||||
.literals
|
||||
@@ -273,7 +277,8 @@ impl Game<'_> {
|
||||
for s in sources {
|
||||
match self.with_source(s, |g| g.run_chain(command, last)) {
|
||||
Ok(n) => total += n,
|
||||
// Forked executions report failures and carry on.
|
||||
Err(_) if forked => {}
|
||||
// Several sources: report each failure and carry on.
|
||||
Err(e) if many => self.command_failure(e.message),
|
||||
Err(e) => failure = Some(e),
|
||||
}
|
||||
@@ -291,6 +296,7 @@ impl Game<'_> {
|
||||
if c.child.is_none() {
|
||||
return self.run_conditional_terminal(c, sources, want);
|
||||
}
|
||||
forked = true;
|
||||
let mut kept = Vec::new();
|
||||
for s in sources {
|
||||
let (keep, _) = self.with_source(s, |g| g.condition(c, want))?;
|
||||
@@ -301,6 +307,12 @@ impl Game<'_> {
|
||||
sources = kept;
|
||||
}
|
||||
_ => {
|
||||
forked |= match word {
|
||||
"as" | "at" | "on" => true,
|
||||
"positioned" | "rotated" => c.has("as"),
|
||||
"facing" => c.has("entity"),
|
||||
_ => false,
|
||||
};
|
||||
let mut next = Vec::new();
|
||||
for s in sources {
|
||||
next.extend(self.with_source(s, |g| g.modify(word, c, s))?);
|
||||
|
||||
@@ -860,7 +860,13 @@ def test_command():
|
||||
cmd('/test locate *'),
|
||||
cmd('/test run minecraft:nothing*'),
|
||||
cmd('/test locate nothing'),
|
||||
cmd('/execute as @e[type=!minecraft:player,limit=1] run test pos'),
|
||||
*setup('/summon minecraft:marker 8 230 8 {Tags:["tp"]}'),
|
||||
cmd('/execute as @e[tag=tp] run test pos'),
|
||||
cmd('/execute positioned 0 230 0 run test pos'),
|
||||
cmd('/execute as @e[tag=tp] run kill @e[tag=nothing]'),
|
||||
cmd('/execute as @e[tag=tp] at @s run kill @e[tag=nothing]'),
|
||||
cmd('/execute positioned 1 2 3 run kill @e[tag=nothing]'),
|
||||
*setup('/kill @e[tag=tp]'),
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user