Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/ingame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ The runner (`tools/ingame-test`):
(17 for 1.20.x, 21 for 1.21.x, 25 for 26.x): `JAVA_HOME_<major>` if set,
else `JAVA_HOME`, else `java` on `PATH`. A newer Java runs older servers.
3. Runs a debug client per script, joining as that version, then resets the
player for the next one.
player for the next one, and the world to noon in clear weather with time
ticking.

With `--jobs N`, N workers per version each start their own server and world
under `target/ingame/workers/<version>/<n>/` and take scripts from a shared
Expand Down
23 changes: 19 additions & 4 deletions tools/ingame-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,8 @@ impl Server {
// out of the reset's reach; keep the area around spawn loaded.
server.command("forceload add -48 -48 47 47");
// Mobs spawning at night attack and push the test player mid-script.
// 26.x renamed the rule; each version rejects the name it lacks.
for rule in ["spawn_mobs", "doMobSpawning"] {
server.command(&format!("gamerule {rule} false"));
}
server.gamerule(["spawn_mobs", "doMobSpawning"], false);
server.reset_world();
Ok(server)
}

Expand All @@ -656,6 +654,14 @@ impl Server {
let _ = writeln!(self.stdin, "{command}");
}

/// Sets a game rule by its 26.x and older names; each version rejects
/// the name it lacks.
fn gamerule(&mut self, names: [&str; 2], value: bool) {
for name in names {
self.command(&format!("gamerule {name} {value}"));
}
}

/// Clears what a script left behind. Once the player has left and the
/// world is saved, their data is deleted so the next join starts fresh.
fn reset_player(&mut self) -> Result<(), String> {
Expand All @@ -678,9 +684,18 @@ impl Server {
for _ in 0..2 {
self.command("kill @e[type=!player]");
}
self.reset_world();
Ok(())
}

/// Noon, clear and ticking, so a script that doesn't set the time or
/// weather sees the same sky whether it runs first or after others.
fn reset_world(&mut self) {
self.gamerule(["advance_time", "doDaylightCycle"], true);
self.command("time set 6000");
self.command("weather clear");
}

/// Blocks until the server exits (Ctrl+C or `stop`).
fn wait(&mut self) {
let _ = self.child.wait();
Expand Down
Loading