diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml
index 2ab491207..c902acf32 100644
--- a/.github/workflows/launcher.yml
+++ b/.github/workflows/launcher.yml
@@ -1,7 +1,6 @@
name: launcher
# Builds the launcher on Linux, macOS and Windows, and releases it by itself (docs/release-flow.md): after a
-# push to main that changes the launcher or what it builds in (crates/horizon-prepare, crates/horizon-theme,
-# crates/horizon-telemetry),
+# push to main that changes the launcher or a crate it builds in (the paths below),
# every 10 minutes (a release waiting for merges to settle goes out) and by hand, tools/release_train.py decides as
# for the game.
# A release is launcher-vX.Y.Z: the patch after the last launcher tag, or the next minor when a merged pull
@@ -14,10 +13,15 @@ on:
push:
branches: [main, launcher, 'launcher-*']
paths:
+ # Every crate the launcher builds in, as tools/release_train.py's LAUNCHER_PATHS.
- 'launcher/**'
+ - 'crates/horizon-bench/**'
+ - 'crates/horizon-friends/**'
+ - 'crates/horizon-mods/**'
+ - 'crates/horizon-port-pack/**'
- 'crates/horizon-prepare/**'
- - 'crates/horizon-theme/**'
- 'crates/horizon-telemetry/**'
+ - 'crates/horizon-theme/**'
- '.github/workflows/launcher.yml'
schedule:
- cron: '7-59/10 * * * *'
@@ -138,7 +142,8 @@ jobs:
echo "::notice::No Metal toolchain on this runner: GPUI compiles its shaders at run time"
echo "LAUNCHER_FEATURES=gpui/runtime_shaders" >> "$GITHUB_ENV"
fi
- - run: cargo test --release --locked --lib ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"}
+ # Every test target (the library, the binary, tests/), on each system the launcher ships for.
+ - run: cargo test --release --locked ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"}
- run: cargo build --release --locked ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"}
- name: The version is the release's
run: |
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 27636b0eb..a4780c85b 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -174,7 +174,14 @@ jobs:
case "${{ matrix.asset }}" in
*.tar.gz) tar czf "${{ matrix.asset }}" "${{ matrix.dir }}" ;;
*) if [[ "$RUNNER_OS" == Windows ]]; then 7z a -tzip "${{ matrix.asset }}" "${{ matrix.dir }}" > /dev/null
- else ditto -c -k --keepParent "${{ matrix.dir }}" "${{ matrix.asset }}"; fi ;;
+ else
+ # Without resource forks and extended attributes: plain ditto adds an
+ # AppleDouble `._` file beside every file that has any.
+ ditto -c -k --norsrc --noextattr --noqtn --keepParent "${{ matrix.dir }}" "${{ matrix.asset }}"
+ if unzip -Z1 "${{ matrix.asset }}" | grep -E '(^|/)(\._|__MACOSX/)'; then
+ echo "::error::macOS metadata files in ${{ matrix.asset }}"; exit 1
+ fi
+ fi ;;
esac
ls -l "${{ matrix.asset }}"
- uses: actions/upload-artifact@v4
diff --git a/Cargo.lock b/Cargo.lock
index ea6681a2c..b4081e7af 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1539,6 +1539,7 @@ dependencies = [
"horizon-world",
"serde_json",
"sha1",
+ "sha2",
]
[[package]]
@@ -1569,10 +1570,12 @@ dependencies = [
name = "horizon-server-files"
version = "0.1.0"
dependencies = [
+ "base64",
"horizon-core",
"horizon-protocol",
"horizon-world",
"log",
+ "ureq",
]
[[package]]
diff --git a/README.md b/README.md
index f4f3094ae..0efae1088 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ Captured in the Rust client itself, with vanilla assets and no mods or shaders.
-
+
@@ -79,17 +79,17 @@ The vanilla menus are one setting away: Options → Interface → Menu style →
-
-
+
+
-
+
- Vanilla world generation ported to Rust (terrain, aquifers, carvers, features, villages and the Nether), every block model with smooth lighting and biome tints, the vanilla sky and fog, mobs, the HUD, chat and advancements: everything in these frames is drawn by Horizon.
+ Vanilla world generation ported to Rust (terrain, aquifers, carvers, features, villages and the Nether), every block model with smooth lighting and biome tints, the vanilla sky and fog, mobs and the HUD: everything in these frames is drawn by Horizon.
diff --git a/benchmarks/server-2026-10-17/README.md b/benchmarks/server-2026-10-17/README.md
new file mode 100644
index 000000000..4a3cd3dcc
--- /dev/null
+++ b/benchmarks/server-2026-10-17/README.md
@@ -0,0 +1,174 @@
+# Dedicated server against vanilla 26.3, with bots (2026-10-17)
+
+`horizon-client --dedicated` (run by `horizon-server`) against the pinned vanilla 26.3 `server.jar`, on `main`
+at `7bbbf6e9` (in release v2026.10.17.17). That build has the movement checks and chunk pacing of #586, the
+equal-work method of #670, and the server performance PRs #701–#707 and #713.
+
+This replaces the data first published here, which came from a Mac mini overloaded by other work (load 55–141 on
+14 threads). An earlier run of this method, on `main` at `002f14ce`, is kept in `earlier-002f14ce/` and compared
+at the end.
+
+## Setup
+
+- **Server machine:** ThinkPad, Intel i7-7500U (2 cores, 4 threads), 32 GB, NixOS. Nothing else heavy ran on it:
+ its load average was 0.4 when idle. Both servers ran under `nice -n 19`.
+- **Bots:** `horizon-bots` on another machine (Mac mini M4 Pro), over the tailnet. That machine was shared with
+ other work (load 36–170 on 14 threads, mean 78). The bots need little CPU, but a busy bot host can answer later.
+ Both servers saw the same conditions, since they took turns at each bot count.
+- **Horizon:** release build of `7bbbf6e9` (`horizon-server`, `horizon-client`).
+- **Vanilla:** the pinned 26.3 `server.jar` on OpenJDK 25.0.4.1, with `-Xms4g -Xmx4g`.
+- **Properties:**
+ - `level-seed=12345`, view and simulation distance 10, creative (forced);
+ - `online-mode=false`, `difficulty=easy`, `max-players=200`;
+ - default game rules on both (the locator bar is on).
+- **Each run:** a fresh server, bots joining one per second, a 60 s warm-up, then 180 s measured.
+- **Commands** (on the server machine):
+ ```
+ python3 tools/server_bench.py --servers horizon,vanilla --nice 19 --warmup 60 --seconds 180 \
+ --bots-via "ssh " --bots-bin --connect \
+ --bots 1,10,25,50,100 --behaviour walk,explore
+ python3 tools/server_bench.py ...same... --bots 1,10,25,50 --behaviour explore --explore-speed 0.8
+ ```
+- **Columns:**
+ - **MSPT** (mean) and **P95** come from `/tick query`, in ms. **TPS** is the tick rate.
+ - **RSS** is the mean over the run. **CPU** is the whole process tree, as a percentage of one core.
+ - **Chunks/s** is what the bots received. **New chunks/s** counts each chunk once per bot.
+ - **Pulled back** counts the times the server moved a bot back (vanilla's "moved too quickly" and similar).
+ - **Load** is the mean load average during that run: the server machine (which includes the server's own
+ threads) and the bot host.
+
+## Results
+
+### Equal work: bots explore at the same pace (`--explore-speed 0.8`)
+
+Each bot flies outwards at 0.8 blocks a second, which both servers keep up with. They send the same chunks, so
+the tick times compare the same work.
+
+| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s | Pulled back | Load (server / bots) |
+|---:|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
+| 1 | Horizon | 3.16 | 5.78 | 20.0 | 0.76 GB | 22 % | 2 | 1.27 | 0 | 2.8 / 63 |
+| 1 | Vanilla | 16.82 | 27.3 | 20.0 | 3.37 GB | 69 % | 2 | 1.35 | 0 | 1.8 / 94 |
+| 10 | Horizon | 9.83 | 19.01 | 20.0 | 0.86 GB | 77 % | 14 | 12.31 | 1051 | 2.2 / 74 |
+| 10 | Vanilla | 24.38 | 39.58 | 20.0 | 3.57 GB | 132 % | 14 | 12.32 | 1027 | 2.5 / 64 |
+| 25 | Horizon | 16.87 | 30.88 | 20.0 | 0.89 GB | 111 % | 34 | 29.92 | 3770 | 5.1 / 51 |
+| 25 | Vanilla | 30.29 | 43.47 | 20.0 | 3.61 GB | 176 % | 33 | 29.29 | 5139 | 5.2 / 55 |
+| 50 | Horizon | 23.57 | 47.53 | 20.0 | 0.92 GB | 127 % | 67 | 59.42 | 7434 | 8.5 / 64 |
+| 50 | Vanilla | 42.44 | 54.84 | 20.0 | 3.67 GB | 201 % | 65 | 58.11 | 10604 | 5.1 / 59 |
+
+### `walk`: bots walk around the spawn
+
+| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s | Pulled back | Load (server / bots) |
+|---:|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
+| 1 | Horizon | 4.01 | 8.19 | 20.0 | 0.78 GB | 59 % | 10 | 0.43 | 0 | 1.4 / 70 |
+| 1 | Vanilla | 18.22 | 29.34 | 20.0 | 3.43 GB | 69 % | 10 | 0.47 | 0 | 1.9 / 63 |
+| 10 | Horizon | 8.79 | 17.35 | 20.0 | 0.78 GB | 119 % | 95 | 3.58 | 0 | 2.9 / 69 |
+| 10 | Vanilla | 18.67 | 38.26 | 20.0 | 3.50 GB | 101 % | 101 | 4.38 | 5 | 3.2 / 59 |
+| 25 | Horizon | 15.01 | 31.12 | 20.0 | 0.80 GB | 161 % | 234 | 8.49 | 0 | 6.3 / 43 |
+| 25 | Vanilla | 18.78 | 28.16 | 20.0 | 3.52 GB | 155 % | 252 | 11.89 | 10 | 6.7 / 57 |
+| 50 | Horizon | 22.72 | 60.19 | 20.0 | 0.81 GB | 180 % | 465 | 16.94 | 0 | 14.7 / 50 |
+| 50 | Vanilla | 34.3 | 55.55 | 20.0 | 3.58 GB | 267 % | 497 | 26.74 | 39 | 9.5 / 56 |
+| 100 | Horizon | 63.33 | 125.04 | 15.79 | 0.87 GB | 246 % | 678 | 31.8 | 0 | 32.9 / 95 |
+| 100 | Vanilla | stopped by its watchdog (a 60 s tick) | | | | | | | | 15.1 / 120 |
+
+Both servers sent each walking bot the same number of distinct chunks over the whole run (680–690). Horizon's
+"new chunks/s" inside the measured window is lower, so compare the totals, not that column.
+
+### `explore` at full speed: unequal work
+
+Bots fly outwards as fast as chunks arrive (`horizon-bots`' default, up to 22 blocks a second). Both servers now pull them back ("moved too quickly"), but Horizon sends
+more new terrain, so this pass doesn't compare equal work. The server-machine load of Horizon's 1-bot run is
+estimated from the time between the runs around it: its log was overwritten before it was read.
+
+| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s | Pulled back | Load (server / bots) |
+|---:|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
+| 1 | Horizon | 9.73 | 20.99 | 20.0 | 0.84 GB | 330 % | 41 | 35.96 | 0 | 4.7 / 129 |
+| 1 | Vanilla | 9.71 | 20.37 | 20.0 | 3.61 GB | 247 % | 35 | 33.61 | 0 | 4.3 / 156 |
+| 10 | Horizon | 21.27 | 39.15 | 20.0 | 1.18 GB | 322 % | 46 | 46.11 | 9856 | 5.0 / 114 |
+| 10 | Vanilla | 16.94 | 30.28 | 20.0 | 3.95 GB | 254 % | 25 | 25.01 | 11123 | 5.5 / 89 |
+| 25 | Horizon | 25.76 | 45.01 | 20.0 | 1.17 GB | 314 % | 61 | 60.7 | 31264 | 6.6 / 82 |
+| 25 | Vanilla | 24.93 | 37.09 | 20.0 | 4.04 GB | 305 % | 38 | 37.84 | 33467 | 6.1 / 91 |
+| 50 | Horizon | 39.31 | 65.33 | 20.0 | 1.25 GB | 325 % | 115 | 112.25 | 64163 | 6.9 / 95 |
+| 50 | Vanilla | stopped by its watchdog (a 60 s tick) | | | | | | | | 7.7 / 86 |
+| 100 | Horizon | 52.7 | 85.73 | 18.97 | 1.36 GB | 328 % | 154 | 151.83 | 116161 | 13.4 / 79 |
+| 100 | Vanilla | stopped by its watchdog (a 60 s tick) | | | | | | | | 10.0 / 72 |
+
+Vanilla's watchdog stopped it after a 60-second tick in three runs (walk 100, explore 50 and 100). Each time its
+server thread was in entity tracking (`ChunkMap$TrackedEntity.updatePlayer`).
+
+## What it shows
+
+- **Same work, 1 to 50 players:** Horizon's mean tick is 44–81 % shorter than vanilla's, its 95th percentile is
+ lower, and its process uses 32–63 % of vanilla's CPU.
+- **Walking, 1 to 50 players:** Horizon's mean tick is shorter at every count (4.0 against 18.2 ms with 1 bot,
+ 22.7 against 34.3 ms with 50).
+- **Where vanilla wins:**
+ - With 25 and 50 walking bots, vanilla's 95th percentile is lower (28.2 against 31.1 ms, 55.6 against
+ 60.2 ms). Horizon's slow ticks are spikier.
+ - In the full-speed explore pass, vanilla's mean tick is shorter with 10 and 25 bots (16.9 against 21.3 ms,
+ 24.9 against 25.8 ms), while Horizon sends 1.6–1.8 times as many new chunks.
+ - With 50 walking bots, Horizon makes the server machine busier (load 14.7 against 9.5). Its connection
+ writer threads compress every packet (below).
+- **100 players:** Horizon keeps 15.8 TPS walking and 19.0 TPS exploring at full speed. Vanilla's watchdog
+ stopped it in both.
+- **Memory:** Horizon used 0.76–0.92 GB in every walk and equal-work run, and 1.36 GB at most when 100 bots
+ explored at full speed. Vanilla used 3.4–4.0 GB with its 4 GB heap.
+- **Start:** Horizon's fresh world was ready in 9.2–9.9 s, vanilla's in 14.9–17.2 s.
+
+## Where Horizon's time goes (50 walking bots)
+
+`perf record -e cycles:u --call-graph lbr` on the engine for 30 s, during a separate 50-bot `walk` run on the same
+build and machine (MSPT 21.7 ms, 178 % CPU). Shares of all the engine's CPU samples:
+
+| Thread | Share | Mostly |
+|---|---:|---|
+| Connection writers (`horizon-lan-out`) | 55 % | 53 % in `miniz_oxide` deflate, from `horizon_protocol::frame::encode` |
+| World generation workers | 33 % | noise, surface rules, aquifers |
+| Server thread (the tick) | 12 % | see below |
+
+Inside the tick:
+- the locator bar (`Waypoints::tick`): a third of the tick;
+- `Hub::tick`: a quarter;
+- block entities, creatures, chunk encoding (`ChunkEncoder::encode_in`) and `Streaming::update`: 7–10 % each;
+- SipHash of `u128` keys (the default `HashMap` hasher): about 10 % of the tick.
+
+**The next biggest cost is compressing packets.** Every chunk packet is compressed again for each player who gets
+it, with `flate2`'s default `miniz_oxide` backend at level 6. On this 4-thread CPU that competes with the tick
+and with world generation. Two fixes, which can be combined:
+- the `zlib-rs` backend for `flate2`: 2.2–10 times faster than `miniz_oxide` at level 6 in a quick test, with
+ output about 3 % larger;
+- compressing a chunk packet once and sending the same bytes to every player who needs it.
+
+## Before and after the performance PRs
+
+The earlier run, on `main` at `002f14ce` with #670's bench changes (build `a9ee56a8`), before #586, #701–#707 and
+#713. Same machines and settings. MSPT mean / P95, in ms:
+
+Walk:
+
+| Bots | Horizon before | Horizon now | Vanilla before | Vanilla now |
+|---:|---|---|---|---|
+| 1 | 5.77 / 11.04 | 4.01 / 8.19 | 18.84 / 29.55 | 18.22 / 29.34 |
+| 10 | 16.23 / 29.32 | 8.79 / 17.35 | 18.02 / 37.62 | 18.67 / 38.26 |
+| 25 | 23.98 / 49.18 | 15.01 / 31.12 | 19.19 / 33.84 | 18.78 / 28.16 |
+| 50 | 35.07 / 73.24 | 22.72 / 60.19 | 35.23 / 60.87 | 34.3 / 55.55 |
+| 100 | 104.8 / 158.8 | 63.33 / 125.04 | watchdog | watchdog |
+
+Equal work:
+
+| Bots | Horizon before | Horizon now | Vanilla before | Vanilla now |
+|---:|---|---|---|---|
+| 1 | 4.78 / 7.3 | 3.16 / 5.78 | 16.63 / 26.23 | 16.82 / 27.3 |
+| 10 | 15.19 / 25.66 | 9.83 / 19.01 | 24.65 / 40.81 | 24.38 / 39.58 |
+| 25 | 23.37 / 42.59 | 16.87 / 30.88 | 30.28 / 44.81 | 30.29 / 43.47 |
+| 50 | 30.59 / 67.94 | 23.57 / 47.53 | 43.52 / 56.18 | 42.44 / 54.84 |
+
+Vanilla's numbers repeat within a few percent, so the runs are comparable. In the earlier run, 25 walking bots
+were faster on vanilla (19.2 against 24.0 ms). A profile then put a third of the tick in advancement updates,
+which #701 fixed.
+
+## Files
+
+- `walk-explore.json`: the `walk` and full-speed `explore` passes. `explore-equal-rate.json`: the equal-work pass.
+- `load.txt`: both machines' load averages every 30 s during the runs.
+- `earlier-002f14ce/`: the same files for the earlier run.
+- The server's tailnet address is replaced by `` in the JSON.
diff --git a/benchmarks/server-2026-10-17/earlier-002f14ce/explore-equal-rate.json b/benchmarks/server-2026-10-17/earlier-002f14ce/explore-equal-rate.json
new file mode 100644
index 000000000..404f8d032
--- /dev/null
+++ b/benchmarks/server-2026-10-17/earlier-002f14ce/explore-equal-rate.json
@@ -0,0 +1,341 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T15:37:03+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "a9ee56a8b143999c9bc7056850ffcd622a9214aa",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon,vanilla",
+ "bots": "1,10,25,50",
+ "behaviour": "explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 180,
+ "seed": 12345,
+ "explore_speed": 0.8,
+ "gamerule": "",
+ "heap": "4g",
+ "out": "/home/ludovic/code/horizon/.claude/worktrees/server-host-4/.local/bench-out/explore-equal-rate.json",
+ "nice": 19,
+ "bots_via": "ssh macmini",
+ "bots_bin": "/Users/ludovicmarie/code/horizon/.claude/worktrees/server-host-4/target/release/horizon-bots",
+ "connect": "",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 9.21,
+ "mspt": {
+ "average": 4.78,
+ "p50": 4.59,
+ "p95": 7.3,
+ "p99": 13.53
+ },
+ "mspt_worst_p99": 36.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 759.91,
+ "max": 771.3
+ },
+ "cpu_percent": 24.49,
+ "chunks_per_second": 1.64,
+ "unique_per_second": 1.27,
+ "forgotten_per_second": 1.54,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 841,
+ "chunks_per_bot": {
+ "explore": 841.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 781.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 14.35,
+ "mspt": {
+ "average": 16.63,
+ "p50": 16.73,
+ "p95": 26.23,
+ "p99": 35.39
+ },
+ "mspt_worst_p99": 68.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3431.12,
+ "max": 3459.2
+ },
+ "cpu_percent": 69.76,
+ "chunks_per_second": 1.66,
+ "unique_per_second": 1.37,
+ "forgotten_per_second": 1.67,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 840,
+ "chunks_per_bot": {
+ "explore": 840.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 780.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 9.31,
+ "mspt": {
+ "average": 15.19,
+ "p50": 14.45,
+ "p95": 25.66,
+ "p99": 38.89
+ },
+ "mspt_worst_p99": 57.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 859.86,
+ "max": 920.2
+ },
+ "cpu_percent": 84.95,
+ "chunks_per_second": 14.22,
+ "unique_per_second": 12.7,
+ "forgotten_per_second": 14.11,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 7962,
+ "chunks_per_bot": {
+ "explore": 796.2
+ },
+ "unique_chunks_per_bot": {
+ "explore": 768.2
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 14.74,
+ "mspt": {
+ "average": 24.65,
+ "p50": 21.82,
+ "p95": 40.81,
+ "p99": 70.23
+ },
+ "mspt_worst_p99": 119.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3528.77,
+ "max": 3643.2
+ },
+ "cpu_percent": 133.1,
+ "chunks_per_second": 13.62,
+ "unique_per_second": 12.32,
+ "forgotten_per_second": 13.62,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 7746,
+ "chunks_per_bot": {
+ "explore": 774.6
+ },
+ "unique_chunks_per_bot": {
+ "explore": 748.7
+ },
+ "resent": 0,
+ "pulled_back": 1150,
+ "moved_too_quickly": 5,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 9.42,
+ "mspt": {
+ "average": 23.37,
+ "p50": 21.61,
+ "p95": 42.59,
+ "p99": 60.21
+ },
+ "mspt_worst_p99": 102.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 889.21,
+ "max": 950.7
+ },
+ "cpu_percent": 117.59,
+ "chunks_per_second": 35.34,
+ "unique_per_second": 31.62,
+ "forgotten_per_second": 35.12,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 20137,
+ "chunks_per_bot": {
+ "explore": 805.48
+ },
+ "unique_chunks_per_bot": {
+ "explore": 774.52
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 15.14,
+ "mspt": {
+ "average": 30.28,
+ "p50": 28.17,
+ "p95": 44.81,
+ "p99": 71.77
+ },
+ "mspt_worst_p99": 158.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3574.32,
+ "max": 3692.7
+ },
+ "cpu_percent": 173.43,
+ "chunks_per_second": 32.76,
+ "unique_per_second": 29.38,
+ "forgotten_per_second": 33.02,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 19417,
+ "chunks_per_bot": {
+ "explore": 776.68
+ },
+ "unique_chunks_per_bot": {
+ "explore": 747.36
+ },
+ "resent": 0,
+ "pulled_back": 4728,
+ "moved_too_quickly": 15,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 9.11,
+ "mspt": {
+ "average": 30.59,
+ "p50": 25.19,
+ "p95": 67.94,
+ "p99": 90.77
+ },
+ "mspt_worst_p99": 122.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 915.93,
+ "max": 978.0
+ },
+ "cpu_percent": 132.13,
+ "chunks_per_second": 71.31,
+ "unique_per_second": 63.56,
+ "forgotten_per_second": 71.19,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 41365,
+ "chunks_per_bot": {
+ "explore": 827.3
+ },
+ "unique_chunks_per_bot": {
+ "explore": 793.14
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 15.35,
+ "mspt": {
+ "average": 43.52,
+ "p50": 41.69,
+ "p95": 56.18,
+ "p99": 84.55
+ },
+ "mspt_worst_p99": 155.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3801.29,
+ "max": 3920.7
+ },
+ "cpu_percent": 198.97,
+ "chunks_per_second": 65.86,
+ "unique_per_second": 58.63,
+ "forgotten_per_second": 66.12,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 39790,
+ "chunks_per_bot": {
+ "explore": 795.8
+ },
+ "unique_chunks_per_bot": {
+ "explore": 764.48
+ },
+ "resent": 0,
+ "pulled_back": 8392,
+ "moved_too_quickly": 38,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ }
+ ]
+}
diff --git a/benchmarks/server-2026-10-17/earlier-002f14ce/load.txt b/benchmarks/server-2026-10-17/earlier-002f14ce/load.txt
new file mode 100644
index 000000000..853252809
--- /dev/null
+++ b/benchmarks/server-2026-10-17/earlier-002f14ce/load.txt
@@ -0,0 +1,278 @@
+2026-10-17T13:17:13Z thinkpad: 2.76 2.26 2.04 | macmini (bots): { 73.08 70.73 75.98 }
+2026-10-17T13:17:43Z thinkpad: 2.90 2.33 2.07 | macmini (bots): { 75.66 71.62 76.12 }
+2026-10-17T13:18:13Z thinkpad: 3.02 2.43 2.11 | macmini (bots): { 65.77 69.61 75.24 }
+2026-10-17T13:18:44Z thinkpad: 2.15 2.27 2.07 | macmini (bots): { 59.85 67.75 74.37 }
+2026-10-17T13:19:14Z thinkpad: 1.45 2.09 2.02 | macmini (bots): { 63.86 67.87 74.17 }
+2026-10-17T13:19:44Z thinkpad: 1.28 1.98 1.98 | macmini (bots): { 63.51 67.54 73.84 }
+2026-10-17T13:20:14Z thinkpad: 1.14 1.89 1.95 | macmini (bots): { 65.82 67.85 73.71 }
+2026-10-17T13:20:45Z thinkpad: 0.90 1.77 1.91 | macmini (bots): { 63.62 67.08 73.22 }
+2026-10-17T13:21:15Z thinkpad: 0.55 1.60 1.85 | macmini (bots): { 62.45 66.37 72.75 }
+2026-10-17T13:21:45Z thinkpad: 0.79 1.54 1.82 | macmini (bots): { 67.04 67.04 72.76 }
+2026-10-17T13:22:15Z thinkpad: 1.96 1.75 1.88 | macmini (bots): { 65.53 66.60 72.40 }
+2026-10-17T13:22:46Z thinkpad: 1.82 1.75 1.88 | macmini (bots): { 61.52 65.55 71.82 }
+2026-10-17T13:23:16Z thinkpad: 1.29 1.63 1.83 | macmini (bots): { 62.36 65.36 71.53 }
+2026-10-17T13:23:46Z thinkpad: 0.86 1.49 1.78 | macmini (bots): { 68.76 66.51 71.73 }
+2026-10-17T13:24:16Z thinkpad: 1.29 1.52 1.78 | macmini (bots): { 77.68 68.77 72.36 }
+2026-10-17T13:24:46Z thinkpad: 1.82 1.62 1.80 | macmini (bots): { 74.03 68.88 72.28 }
+2026-10-17T13:25:17Z thinkpad: 1.50 1.56 1.78 | macmini (bots): { 71.53 68.76 72.12 }
+2026-10-17T13:25:47Z thinkpad: 0.96 1.42 1.72 | macmini (bots): { 74.46 69.85 72.40 }
+2026-10-17T13:26:17Z thinkpad: 0.87 1.35 1.69 | macmini (bots): { 80.85 71.79 73.01 }
+2026-10-17T13:26:47Z thinkpad: 3.95 2.02 1.90 | macmini (bots): { 74.77 71.31 72.81 }
+2026-10-17T13:27:18Z thinkpad: 2.98 1.97 1.89 | macmini (bots): { 70.52 70.52 72.46 }
+2026-10-17T13:27:48Z thinkpad: 3.78 2.26 1.99 | macmini (bots): { 67.62 69.91 72.18 }
+2026-10-17T13:28:18Z thinkpad: 3.05 2.23 1.99 | macmini (bots): { 72.51 70.83 72.43 }
+2026-10-17T13:28:48Z thinkpad: 2.05 2.07 1.94 | macmini (bots): { 79.07 72.64 73.03 }
+2026-10-17T13:29:19Z thinkpad: 2.09 2.11 1.96 | macmini (bots): { 90.42 75.94 74.21 }
+2026-10-17T13:29:49Z thinkpad: 1.61 1.99 1.93 | macmini (bots): { 102.68 80.15 75.78 }
+2026-10-17T13:30:19Z thinkpad: 2.31 2.12 1.97 | macmini (bots): { 111.15 84.19 77.39 }
+2026-10-17T13:30:49Z thinkpad: 4.14 2.61 2.14 | macmini (bots): { 115.67 87.82 78.94 }
+2026-10-17T13:31:20Z thinkpad: 4.84 2.92 2.26 | macmini (bots): { 122.95 92.31 80.88 }
+2026-10-17T13:31:50Z thinkpad: 6.84 3.60 2.51 | macmini (bots): { 136.25 98.41 83.48 }
+2026-10-17T13:32:20Z thinkpad: 4.85 3.43 2.49 | macmini (bots): { 128.59 100.39 84.73 }
+2026-10-17T13:32:50Z thinkpad: 3.48 3.25 2.46 | macmini (bots): { 111.05 98.73 84.66 }
+2026-10-17T13:33:20Z thinkpad: 3.09 3.15 2.45 | macmini (bots): { 102.40 98.03 84.98 }
+2026-10-17T13:33:51Z thinkpad: 2.47 2.99 2.42 | macmini (bots): { 94.57 96.54 84.89 }
+2026-10-17T13:34:21Z thinkpad: 2.42 2.94 2.42 | macmini (bots): { 86.26 94.36 84.50 }
+2026-10-17T13:34:51Z thinkpad: 2.95 3.04 2.47 | macmini (bots): { 76.90 91.56 83.84 }
+2026-10-17T13:35:21Z thinkpad: 2.66 2.96 2.46 | macmini (bots): { 65.57 87.42 82.61 }
+2026-10-17T13:35:52Z thinkpad: 2.47 2.88 2.45 | macmini (bots): { 64.13 85.05 81.92 }
+2026-10-17T13:36:22Z thinkpad: 3.89 3.17 2.56 | macmini (bots): { 58.65 81.74 80.83 }
+2026-10-17T13:36:52Z thinkpad: 6.43 3.83 2.80 | macmini (bots): { 66.32 81.32 80.71 }
+2026-10-17T13:37:22Z thinkpad: 8.73 4.60 3.09 | macmini (bots): { 67.30 80.14 80.30 }
+2026-10-17T13:37:53Z thinkpad: 9.03 5.10 3.30 | macmini (bots): { 63.66 78.24 79.62 }
+2026-10-17T13:38:23Z thinkpad: 9.49 5.57 3.52 | macmini (bots): { 61.25 76.23 78.84 }
+2026-10-17T13:38:53Z thinkpad: 7.55 5.50 3.56 | macmini (bots): { 62.30 74.88 78.25 }
+2026-10-17T13:39:23Z thinkpad: 8.62 5.99 3.79 | macmini (bots): { 57.34 72.56 77.29 }
+2026-10-17T13:39:53Z thinkpad: 6.65 5.81 3.80 | macmini (bots): { 51.24 69.62 76.06 }
+2026-10-17T13:40:24Z thinkpad: 5.55 5.62 3.80 | macmini (bots): { 48.87 67.26 74.98 }
+2026-10-17T13:40:54Z thinkpad: 6.11 5.71 3.89 | macmini (bots): { 51.16 66.08 74.29 }
+2026-10-17T13:41:24Z thinkpad: 8.93 6.43 4.19 | macmini (bots): { 48.67 64.00 73.24 }
+2026-10-17T13:41:54Z thinkpad: 9.05 6.74 4.36 | macmini (bots): { 46.47 61.96 72.18 }
+2026-10-17T13:42:25Z thinkpad: 7.70 6.65 4.41 | macmini (bots): { 44.24 60.05 71.14 }
+2026-10-17T13:42:55Z thinkpad: 5.64 6.24 4.34 | macmini (bots): { 49.30 59.83 70.68 }
+2026-10-17T13:43:25Z thinkpad: 4.83 6.02 4.33 | macmini (bots): { 47.39 58.24 69.72 }
+2026-10-17T13:43:55Z thinkpad: 3.57 5.61 4.25 | macmini (bots): { 47.32 57.23 68.96 }
+2026-10-17T13:44:25Z thinkpad: 3.41 5.40 4.23 | macmini (bots): { 47.86 56.49 68.28 }
+2026-10-17T13:44:55Z thinkpad: 3.37 5.21 4.20 | macmini (bots): { 50.10 56.19 67.77 }
+2026-10-17T13:45:26Z thinkpad: 3.78 5.16 4.22 | macmini (bots): { 51.91 55.98 67.28 }
+2026-10-17T13:45:56Z thinkpad: 4.34 5.12 4.23 | macmini (bots): { 49.16 54.85 66.42 }
+2026-10-17T13:46:26Z thinkpad: 10.04 6.46 4.71 | macmini (bots): { 45.01 53.33 65.47 }
+2026-10-17T13:46:56Z thinkpad: 18.10 8.73 5.52 | macmini (bots): { 46.41 52.87 64.88 }
+2026-10-17T13:47:27Z thinkpad: 14.99 8.91 5.68 | macmini (bots): { 51.12 53.21 64.57 }
+2026-10-17T13:47:57Z thinkpad: 13.46 9.27 5.92 | macmini (bots): { 53.84 53.81 64.40 }
+2026-10-17T13:48:27Z thinkpad: 12.76 9.41 6.07 | macmini (bots): { 51.94 53.27 63.84 }
+2026-10-17T13:48:58Z thinkpad: 10.20 9.11 6.08 | macmini (bots): { 50.70 52.83 63.31 }
+2026-10-17T13:49:28Z thinkpad: 9.95 9.25 6.23 | macmini (bots): { 51.51 52.89 62.97 }
+2026-10-17T13:49:58Z thinkpad: 11.98 9.87 6.53 | macmini (bots): { 50.98 52.73 62.57 }
+2026-10-17T13:50:29Z thinkpad: 14.96 10.76 6.94 | macmini (bots): { 49.68 52.31 62.08 }
+2026-10-17T13:50:59Z thinkpad: 10.54 10.09 6.83 | macmini (bots): { 53.34 53.01 62.00 }
+2026-10-17T13:51:29Z thinkpad: 10.21 10.01 6.91 | macmini (bots): { 51.61 52.69 61.57 }
+2026-10-17T13:52:00Z thinkpad: 11.86 10.42 7.14 | macmini (bots): { 48.94 51.89 60.97 }
+2026-10-17T13:52:30Z thinkpad: 10.88 10.33 7.22 | macmini (bots): { 48.46 51.44 60.49 }
+2026-10-17T13:53:01Z thinkpad: 10.94 10.41 7.35 | macmini (bots): { 54.27 52.41 60.47 }
+2026-10-17T13:53:31Z thinkpad: 10.77 10.42 7.45 | macmini (bots): { 57.13 53.30 60.51 }
+2026-10-17T13:54:02Z thinkpad: 10.62 10.40 7.53 | macmini (bots): { 53.78 52.84 60.09 }
+2026-10-17T13:54:32Z thinkpad: 10.85 10.48 7.66 | macmini (bots): { 52.01 52.51 59.73 }
+2026-10-17T13:55:02Z thinkpad: 10.36 10.39 7.73 | macmini (bots): { 53.44 52.83 59.59 }
+2026-10-17T13:55:32Z thinkpad: 8.58 9.95 7.67 | macmini (bots): { 58.66 54.12 59.82 }
+2026-10-17T13:56:03Z thinkpad: 7.29 9.52 7.60 | macmini (bots): { 60.98 55.05 59.96 }
+2026-10-17T13:56:33Z thinkpad: 5.02 8.75 7.40 | macmini (bots): { 65.14 56.71 60.39 }
+2026-10-17T13:57:03Z thinkpad: 5.03 8.38 7.32 | macmini (bots): { 57.51 55.73 59.91 }
+2026-10-17T13:57:34Z thinkpad: 7.39 8.66 7.45 | macmini (bots): { 52.57 54.73 59.41 }
+2026-10-17T13:58:04Z thinkpad: 10.56 9.45 7.76 | macmini (bots): { 53.11 54.60 59.20 }
+2026-10-17T13:58:34Z thinkpad: 28.87 14.20 9.41 | macmini (bots): { 54.53 54.93 59.16 }
+2026-10-17T13:59:05Z thinkpad: 39.33 17.79 10.73 | macmini (bots): { 62.67 56.86 59.71 }
+2026-10-17T13:59:35Z thinkpad: 34.07 18.33 11.12 | macmini (bots): { 61.78 57.22 59.75 }
+2026-10-17T14:00:06Z thinkpad: 34.42 19.72 11.80 | macmini (bots): { 53.10 55.55 59.03 }
+2026-10-17T14:00:36Z thinkpad: 33.60 20.94 12.46 | macmini (bots): { 48.70 54.23 58.43 }
+2026-10-17T14:01:07Z thinkpad: 29.29 20.99 12.74 | macmini (bots): { 50.25 54.00 58.20 }
+2026-10-17T14:01:37Z thinkpad: 20.83 19.79 12.61 | macmini (bots): { 50.48 53.74 57.96 }
+2026-10-17T14:02:08Z thinkpad: 21.74 20.44 13.11 | macmini (bots): { 48.65 53.04 57.56 }
+2026-10-17T14:02:38Z thinkpad: 17.68 19.67 13.09 | macmini (bots): { 54.17 53.85 57.69 }
+2026-10-17T14:03:08Z thinkpad: 13.97 18.55 12.93 | macmini (bots): { 53.39 53.84 57.56 }
+2026-10-17T14:03:39Z thinkpad: 14.10 18.17 12.98 | macmini (bots): { 50.71 53.09 57.16 }
+2026-10-17T14:04:09Z thinkpad: 13.60 17.65 12.97 | macmini (bots): { 52.30 53.28 57.08 }
+2026-10-17T14:04:39Z thinkpad: 12.09 16.91 12.88 | macmini (bots): { 51.52 53.03 56.87 }
+2026-10-17T14:05:10Z thinkpad: 10.15 15.98 12.69 | macmini (bots): { 54.53 53.57 56.91 }
+2026-10-17T14:05:42Z thinkpad: 7.77 14.86 12.42 | macmini (bots): { 63.58 55.55 57.49 }
+2026-10-17T14:06:12Z thinkpad: 6.58 13.89 12.18 | macmini (bots): { 75.29 59.41 58.84 }
+2026-10-17T14:06:42Z thinkpad: 5.96 13.02 11.94 | macmini (bots): { 78.06 61.64 59.67 }
+2026-10-17T14:07:12Z thinkpad: 4.86 12.08 11.66 | macmini (bots): { 72.26 61.85 59.81 }
+2026-10-17T14:07:42Z thinkpad: 4.49 11.18 11.38 | macmini (bots): { 67.84 61.73 59.84 }
+2026-10-17T14:08:13Z thinkpad: 4.37 10.51 11.15 | macmini (bots): { 64.25 61.45 59.80 }
+2026-10-17T14:08:43Z thinkpad: 4.57 9.97 10.94 | macmini (bots): { 57.86 60.14 59.38 }
+2026-10-17T14:09:13Z thinkpad: 4.60 9.46 10.74 | macmini (bots): { 60.21 60.39 59.49 }
+2026-10-17T14:09:43Z thinkpad: 4.20 8.89 10.51 | macmini (bots): { 57.11 59.57 59.22 }
+2026-10-17T14:10:14Z thinkpad: 3.80 8.36 10.28 | macmini (bots): { 66.05 61.48 59.92 }
+2026-10-17T14:10:44Z thinkpad: 4.19 8.00 10.10 | macmini (bots): { 78.51 64.91 61.22 }
+2026-10-17T14:11:14Z thinkpad: 4.27 7.65 9.92 | macmini (bots): { 74.15 65.33 61.51 }
+2026-10-17T14:11:44Z thinkpad: 4.35 7.35 9.74 | macmini (bots): { 62.47 63.48 60.98 }
+2026-10-17T14:12:14Z thinkpad: 4.98 7.22 9.62 | macmini (bots): { 56.73 61.86 60.46 }
+2026-10-17T14:12:45Z thinkpad: 4.60 6.91 9.44 | macmini (bots): { 57.78 61.49 60.37 }
+2026-10-17T14:13:15Z thinkpad: 4.15 6.57 9.25 | macmini (bots): { 56.21 60.71 60.12 }
+2026-10-17T14:13:45Z thinkpad: 3.87 6.25 9.05 | macmini (bots): { 54.75 60.00 59.89 }
+2026-10-17T14:14:15Z thinkpad: 3.86 6.02 8.89 | macmini (bots): { 52.21 58.88 59.49 }
+2026-10-17T14:14:46Z thinkpad: 3.14 5.64 8.67 | macmini (bots): { 58.81 59.59 59.71 }
+2026-10-17T14:15:16Z thinkpad: 3.76 5.54 8.54 | macmini (bots): { 64.13 60.86 60.16 }
+2026-10-17T14:15:46Z thinkpad: 3.91 5.41 8.40 | macmini (bots): { 59.02 59.97 59.87 }
+2026-10-17T14:16:16Z thinkpad: 4.33 5.35 8.28 | macmini (bots): { 64.48 60.97 60.22 }
+2026-10-17T14:16:46Z thinkpad: 5.20 5.44 8.21 | macmini (bots): { 79.56 64.98 61.70 }
+2026-10-17T14:17:17Z thinkpad: 4.88 5.36 8.10 | macmini (bots): { 94.21 69.99 63.63 }
+2026-10-17T14:17:47Z thinkpad: 4.80 5.30 8.00 | macmini (bots): { 85.75 70.51 64.08 }
+2026-10-17T14:18:17Z thinkpad: 4.82 5.25 7.89 | macmini (bots): { 82.33 71.25 64.57 }
+2026-10-17T14:18:48Z thinkpad: 4.50 5.12 7.75 | macmini (bots): { 77.67 71.11 64.75 }
+2026-10-17T14:19:18Z thinkpad: 3.76 4.88 7.58 | macmini (bots): { 77.29 71.67 65.17 }
+2026-10-17T14:19:48Z thinkpad: 3.68 4.75 7.45 | macmini (bots): { 71.16 70.71 65.05 }
+2026-10-17T14:20:18Z thinkpad: 4.25 4.82 7.39 | macmini (bots): { 66.97 69.63 64.85 }
+2026-10-17T14:20:49Z thinkpad: 4.72 4.89 7.33 | macmini (bots): { 59.23 67.50 64.24 }
+2026-10-17T14:21:19Z thinkpad: 5.12 4.98 7.28 | macmini (bots): { 52.38 65.10 63.48 }
+2026-10-17T14:21:49Z thinkpad: 5.69 5.13 7.26 | macmini (bots): { 59.43 65.53 63.69 }
+2026-10-17T14:22:19Z thinkpad: 5.78 5.19 7.21 | macmini (bots): { 62.28 65.65 63.80 }
+2026-10-17T14:22:50Z thinkpad: 5.34 5.14 7.13 | macmini (bots): { 57.40 64.12 63.30 }
+2026-10-17T14:23:20Z thinkpad: 4.89 5.04 7.03 | macmini (bots): { 58.39 63.61 63.14 }
+2026-10-17T14:23:50Z thinkpad: 5.00 5.07 6.98 | macmini (bots): { 64.88 64.63 63.52 }
+2026-10-17T14:24:20Z thinkpad: 3.88 4.80 6.83 | macmini (bots): { 80.70 68.30 64.88 }
+2026-10-17T14:24:51Z thinkpad: 2.90 4.47 6.65 | macmini (bots): { 94.09 72.75 66.61 }
+2026-10-17T14:25:21Z thinkpad: 2.63 4.25 6.51 | macmini (bots): { 93.13 74.91 67.63 }
+2026-10-17T14:25:51Z thinkpad: 6.66 5.07 6.71 | macmini (bots): { 72.87 71.72 66.72 }
+2026-10-17T14:26:21Z thinkpad: 7.15 5.34 6.74 | macmini (bots): { 67.03 70.37 66.40 }
+2026-10-17T14:26:51Z thinkpad: 6.20 5.29 6.68 | macmini (bots): { 58.68 68.08 65.71 }
+2026-10-17T14:27:22Z thinkpad: 6.11 5.35 6.66 | macmini (bots): { 55.26 66.28 65.14 }
+2026-10-17T14:27:52Z thinkpad: 5.45 5.26 6.59 | macmini (bots): { 56.51 65.74 64.99 }
+2026-10-17T14:28:22Z thinkpad: 6.11 5.45 6.61 | macmini (bots): { 52.24 63.77 64.30 }
+2026-10-17T14:28:52Z thinkpad: 6.06 5.50 6.59 | macmini (bots): { 55.56 63.38 64.13 }
+2026-10-17T14:29:23Z thinkpad: 6.11 5.58 6.58 | macmini (bots): { 59.66 63.63 64.20 }
+2026-10-17T14:29:53Z thinkpad: 5.52 5.54 6.53 | macmini (bots): { 63.71 64.30 64.42 }
+2026-10-17T14:30:23Z thinkpad: 4.79 5.35 6.43 | macmini (bots): { 69.84 65.61 64.89 }
+2026-10-17T14:30:53Z thinkpad: 6.21 5.63 6.49 | macmini (bots): { 62.76 64.46 64.50 }
+2026-10-17T14:31:23Z thinkpad: 8.36 6.21 6.66 | macmini (bots): { 53.51 62.09 63.64 }
+2026-10-17T14:31:54Z thinkpad: 8.49 6.45 6.72 | macmini (bots): { 52.80 60.98 63.18 }
+2026-10-17T14:32:24Z thinkpad: 8.28 6.59 6.77 | macmini (bots): { 48.98 59.20 62.45 }
+2026-10-17T14:32:54Z thinkpad: 8.02 6.70 6.79 | macmini (bots): { 48.95 58.30 62.02 }
+2026-10-17T14:33:25Z thinkpad: 7.02 6.59 6.76 | macmini (bots): { 51.06 57.70 61.66 }
+2026-10-17T14:33:55Z thinkpad: 7.09 6.62 6.76 | macmini (bots): { 70.89 61.81 63.00 }
+2026-10-17T14:34:25Z thinkpad: 6.18 6.44 6.69 | macmini (bots): { 69.38 62.46 63.21 }
+2026-10-17T14:34:55Z thinkpad: 6.67 6.52 6.72 | macmini (bots): { 76.87 64.84 64.04 }
+2026-10-17T14:35:25Z thinkpad: 4.76 6.08 6.56 | macmini (bots): { 86.19 68.04 65.21 }
+2026-10-17T14:35:56Z thinkpad: 3.47 5.64 6.40 | macmini (bots): { 101.03 73.28 67.21 }
+2026-10-17T14:36:26Z thinkpad: 2.68 5.24 6.24 | macmini (bots): { 106.05 77.09 68.79 }
+2026-10-17T14:36:56Z thinkpad: 2.41 4.91 6.10 | macmini (bots): { 107.57 80.20 70.20 }
+2026-10-17T14:37:26Z thinkpad: 3.74 4.99 6.08 | macmini (bots): { 101.16 81.38 70.98 }
+2026-10-17T14:37:57Z thinkpad: 5.96 5.39 6.18 | macmini (bots): { 86.51 79.61 70.70 }
+2026-10-17T14:38:27Z thinkpad: 7.91 5.98 6.35 | macmini (bots): { 81.13 79.06 70.81 }
+2026-10-17T14:38:57Z thinkpad: 8.45 6.25 6.43 | macmini (bots): { 79.56 79.01 71.08 }
+2026-10-17T14:39:27Z thinkpad: 8.75 6.52 6.52 | macmini (bots): { 71.92 77.22 70.71 }
+2026-10-17T14:39:58Z thinkpad: 8.86 6.76 6.60 | macmini (bots): { 71.38 76.58 70.70 }
+2026-10-17T14:40:28Z thinkpad: 8.74 6.98 6.68 | macmini (bots): { 71.25 76.12 70.74 }
+2026-10-17T14:40:58Z thinkpad: 7.99 6.96 6.68 | macmini (bots): { 70.49 75.51 70.71 }
+2026-10-17T14:41:28Z thinkpad: 7.64 7.01 6.70 | macmini (bots): { 68.93 74.58 70.56 }
+2026-10-17T14:41:59Z thinkpad: 6.57 6.84 6.66 | macmini (bots): { 68.35 73.75 70.39 }
+2026-10-17T14:42:29Z thinkpad: 5.83 6.62 6.59 | macmini (bots): { 63.57 72.20 69.95 }
+2026-10-17T14:42:59Z thinkpad: 7.40 6.91 6.69 | macmini (bots): { 56.77 69.69 69.12 }
+2026-10-17T14:43:29Z thinkpad: 9.07 7.37 6.85 | macmini (bots): { 49.53 66.71 68.06 }
+2026-10-17T14:44:00Z thinkpad: 9.39 7.63 6.96 | macmini (bots): { 43.53 63.68 66.91 }
+2026-10-17T14:44:30Z thinkpad: 9.16 7.73 7.01 | macmini (bots): { 41.12 61.23 65.92 }
+2026-10-17T14:45:00Z thinkpad: 7.96 7.57 6.98 | macmini (bots): { 40.62 59.23 65.03 }
+2026-10-17T14:45:30Z thinkpad: 6.34 7.24 6.89 | macmini (bots): { 38.17 56.80 63.94 }
+2026-10-17T14:46:01Z thinkpad: 6.39 7.18 6.88 | macmini (bots): { 40.35 55.54 63.24 }
+2026-10-17T14:46:31Z thinkpad: 5.63 6.95 6.82 | macmini (bots): { 48.66 56.25 63.24 }
+2026-10-17T14:47:01Z thinkpad: 4.73 6.60 6.70 | macmini (bots): { 46.68 55.20 62.62 }
+2026-10-17T14:47:31Z thinkpad: 9.18 7.55 7.02 | macmini (bots): { 41.45 53.19 61.64 }
+2026-10-17T14:48:01Z thinkpad: 10.40 8.02 7.19 | macmini (bots): { 40.76 51.87 60.87 }
+2026-10-17T14:48:32Z thinkpad: 8.24 7.73 7.12 | macmini (bots): { 44.46 51.67 60.48 }
+2026-10-17T14:49:02Z thinkpad: 9.60 8.09 7.26 | macmini (bots): { 38.75 49.66 59.45 }
+2026-10-17T14:49:32Z thinkpad: 8.90 8.10 7.29 | macmini (bots): { 34.93 47.72 58.41 }
+2026-10-17T14:50:02Z thinkpad: 11.17 8.66 7.50 | macmini (bots): { 35.70 46.68 57.66 }
+2026-10-17T14:50:33Z thinkpad: 12.06 9.19 7.72 | macmini (bots): { 43.94 47.43 57.54 }
+2026-10-17T14:51:03Z thinkpad: 12.50 9.49 7.87 | macmini (bots): { 40.76 46.36 56.80 }
+2026-10-17T14:51:33Z thinkpad: 10.35 9.24 7.83 | macmini (bots): { 44.81 46.69 56.55 }
+2026-10-17T14:52:03Z thinkpad: 9.32 9.09 7.83 | macmini (bots): { 54.94 48.97 57.04 }
+2026-10-17T14:52:34Z thinkpad: 7.07 8.58 7.70 | macmini (bots): { 54.59 49.54 56.92 }
+2026-10-17T14:53:04Z thinkpad: 5.33 8.01 7.54 | macmini (bots): { 67.48 53.27 58.02 }
+2026-10-17T14:53:34Z thinkpad: 7.22 8.20 7.62 | macmini (bots): { 57.82 52.33 57.52 }
+2026-10-17T14:54:04Z thinkpad: 9.69 8.73 7.81 | macmini (bots): { 46.67 50.20 56.57 }
+2026-10-17T14:54:35Z thinkpad: 9.14 8.66 7.82 | macmini (bots): { 49.88 50.61 56.49 }
+2026-10-17T14:55:05Z thinkpad: 9.75 8.87 7.91 | macmini (bots): { 46.88 49.95 56.06 }
+2026-10-17T14:55:35Z thinkpad: 8.51 8.67 7.88 | macmini (bots): { 42.90 48.80 55.43 }
+2026-10-17T14:56:06Z thinkpad: 8.46 8.62 7.89 | macmini (bots): { 49.23 49.72 55.53 }
+2026-10-17T14:56:36Z thinkpad: 6.19 8.07 7.73 | macmini (bots): { 54.41 50.86 55.74 }
+2026-10-17T14:57:06Z thinkpad: 4.69 7.53 7.56 | macmini (bots): { 60.26 52.69 56.24 }
+2026-10-17T14:57:36Z thinkpad: 3.21 6.90 7.35 | macmini (bots): { 67.66 55.21 57.03 }
+2026-10-17T14:58:06Z thinkpad: 1.94 6.24 7.11 | macmini (bots): { 75.73 58.41 58.13 }
+2026-10-17T14:58:37Z thinkpad: 1.18 5.64 6.89 | macmini (bots): { 74.69 59.90 58.68 }
+2026-10-17T14:59:07Z thinkpad: 0.78 5.12 6.67 | macmini (bots): { 77.10 61.82 59.42 }
+2026-10-17T14:59:37Z thinkpad: 0.88 4.72 6.49 | macmini (bots): { 87.05 65.59 60.86 }
+2026-10-17T15:00:07Z thinkpad: 0.53 4.27 6.28 | macmini (bots): { 78.18 65.51 60.99 }
+2026-10-17T15:00:38Z thinkpad: 0.38 3.88 6.09 | macmini (bots): { 79.38 67.00 61.69 }
+2026-10-17T15:01:08Z thinkpad: 1.50 3.80 5.99 | macmini (bots): { 78.36 67.86 62.18 }
+2026-10-17T15:01:38Z thinkpad: 2.97 3.93 5.95 | macmini (bots): { 74.18 67.90 62.39 }
+2026-10-17T15:02:08Z thinkpad: 2.61 3.77 5.83 | macmini (bots): { 68.63 67.00 62.25 }
+2026-10-17T15:02:39Z thinkpad: 2.10 3.55 5.69 | macmini (bots): { 69.84 67.50 62.60 }
+2026-10-17T15:03:09Z thinkpad: 1.44 3.25 5.53 | macmini (bots): { 67.10 67.06 62.61 }
+2026-10-17T15:03:39Z thinkpad: 1.39 3.08 5.40 | macmini (bots): { 60.83 65.50 62.19 }
+2026-10-17T15:04:09Z thinkpad: 1.28 2.88 5.26 | macmini (bots): { 75.40 68.61 63.46 }
+2026-10-17T15:04:40Z thinkpad: 2.30 2.99 5.22 | macmini (bots): { 106.08 76.54 66.50 }
+2026-10-17T15:05:10Z thinkpad: 2.65 3.02 5.15 | macmini (bots): { 111.96 81.09 68.52 }
+2026-10-17T15:05:40Z thinkpad: 2.41 2.92 5.05 | macmini (bots): { 104.19 82.08 69.31 }
+2026-10-17T15:06:10Z thinkpad: 2.71 2.95 4.99 | macmini (bots): { 116.20 87.04 71.54 }
+2026-10-17T15:06:40Z thinkpad: 2.51 2.87 4.90 | macmini (bots): { 136.68 94.24 74.66 }
+2026-10-17T15:07:11Z thinkpad: 3.68 3.11 4.91 | macmini (bots): { 132.76 97.43 76.50 }
+2026-10-17T15:07:41Z thinkpad: 3.77 3.19 4.88 | macmini (bots): { 132.73 100.97 78.51 }
+2026-10-17T15:08:11Z thinkpad: 3.00 3.06 4.79 | macmini (bots): { 116.92 100.33 79.07 }
+2026-10-17T15:08:41Z thinkpad: 2.40 2.91 4.68 | macmini (bots): { 109.83 100.07 79.70 }
+2026-10-17T15:09:12Z thinkpad: 2.18 2.81 4.59 | macmini (bots): { 113.21 101.71 81.00 }
+2026-10-17T15:09:42Z thinkpad: 1.67 2.62 4.47 | macmini (bots): { 131.87 107.11 83.66 }
+2026-10-17T15:10:12Z thinkpad: 1.90 2.58 4.39 | macmini (bots): { 133.45 109.92 85.49 }
+2026-10-17T15:10:42Z thinkpad: 4.00 3.02 4.48 | macmini (bots): { 130.14 111.67 86.99 }
+2026-10-17T15:11:13Z thinkpad: 4.77 3.32 4.54 | macmini (bots): { 118.78 110.28 87.32 }
+2026-10-17T15:11:43Z thinkpad: 3.86 3.24 4.47 | macmini (bots): { 124.01 112.36 88.87 }
+2026-10-17T15:12:13Z thinkpad: 3.61 3.26 4.44 | macmini (bots): { 122.21 112.94 89.88 }
+2026-10-17T15:12:43Z thinkpad: 3.12 3.17 4.36 | macmini (bots): { 111.62 111.10 90.00 }
+2026-10-17T15:13:14Z thinkpad: 3.07 3.14 4.31 | macmini (bots): { 122.97 113.95 91.77 }
+2026-10-17T15:13:44Z thinkpad: 3.33 3.20 4.30 | macmini (bots): { 102.64 109.89 91.07 }
+2026-10-17T15:14:14Z thinkpad: 2.85 3.10 4.23 | macmini (bots): { 94.46 107.15 90.72 }
+2026-10-17T15:14:44Z thinkpad: 2.66 3.03 4.17 | macmini (bots): { 94.94 106.07 90.90 }
+2026-10-17T15:15:14Z thinkpad: 2.54 2.96 4.11 | macmini (bots): { 94.52 104.93 91.01 }
+2026-10-17T15:15:45Z thinkpad: 3.20 3.08 4.11 | macmini (bots): { 84.00 101.47 90.25 }
+2026-10-17T15:16:15Z thinkpad: 5.56 3.61 4.25 | macmini (bots): { 83.16 99.76 90.02 }
+2026-10-17T15:16:45Z thinkpad: 5.66 3.84 4.30 | macmini (bots): { 69.71 94.66 88.56 }
+2026-10-17T15:17:15Z thinkpad: 5.04 3.90 4.31 | macmini (bots): { 59.31 89.78 87.00 }
+2026-10-17T15:17:46Z thinkpad: 4.29 3.87 4.29 | macmini (bots): { 58.57 86.47 85.89 }
+2026-10-17T15:18:16Z thinkpad: 4.16 3.91 4.29 | macmini (bots): { 56.43 83.29 84.75 }
+2026-10-17T15:18:46Z thinkpad: 2.80 3.60 4.18 | macmini (bots): { 50.60 79.22 83.22 }
+2026-10-17T15:19:16Z thinkpad: 1.85 3.28 4.05 | macmini (bots): { 54.97 77.50 82.46 }
+2026-10-17T15:19:47Z thinkpad: 1.82 3.14 3.98 | macmini (bots): { 56.82 75.80 81.67 }
+2026-10-17T15:20:17Z thinkpad: 2.19 3.10 3.94 | macmini (bots): { 59.30 74.46 80.97 }
+2026-10-17T15:20:47Z thinkpad: 4.44 3.54 4.06 | macmini (bots): { 55.22 72.11 79.90 }
+2026-10-17T15:21:17Z thinkpad: 5.99 4.03 4.21 | macmini (bots): { 49.41 69.01 78.50 }
+2026-10-17T15:21:48Z thinkpad: 4.85 3.95 4.18 | macmini (bots): { 46.89 66.58 77.29 }
+2026-10-17T15:22:18Z thinkpad: 4.31 3.92 4.16 | macmini (bots): { 45.13 64.31 76.10 }
+2026-10-17T15:22:48Z thinkpad: 4.28 3.95 4.16 | macmini (bots): { 51.82 63.98 75.56 }
+2026-10-17T15:23:18Z thinkpad: 4.75 4.11 4.21 | macmini (bots): { 50.35 62.51 74.63 }
+2026-10-17T15:23:48Z thinkpad: 4.08 4.02 4.17 | macmini (bots): { 44.62 60.01 73.31 }
+2026-10-17T15:24:19Z thinkpad: 3.93 4.00 4.16 | macmini (bots): { 46.02 58.72 72.37 }
+2026-10-17T15:24:49Z thinkpad: 3.67 3.92 4.13 | macmini (bots): { 47.23 57.90 71.60 }
+2026-10-17T15:25:19Z thinkpad: 2.79 3.68 4.04 | macmini (bots): { 50.80 57.78 71.09 }
+2026-10-17T15:25:49Z thinkpad: 2.79 3.58 3.99 | macmini (bots): { 47.66 56.35 70.11 }
+2026-10-17T15:26:19Z thinkpad: 5.04 3.97 4.11 | macmini (bots): { 45.15 54.84 69.08 }
+2026-10-17T15:26:50Z thinkpad: 8.46 4.86 4.40 | macmini (bots): { 43.59 53.51 68.10 }
+2026-10-17T15:27:20Z thinkpad: 6.84 4.81 4.39 | macmini (bots): { 42.38 52.39 67.19 }
+2026-10-17T15:27:50Z thinkpad: 8.24 5.33 4.58 | macmini (bots): { 49.87 53.02 66.82 }
+2026-10-17T15:28:21Z thinkpad: 7.11 5.34 4.61 | macmini (bots): { 61.30 55.60 67.28 }
+2026-10-17T15:28:51Z thinkpad: 6.11 5.27 4.61 | macmini (bots): { 67.60 57.74 67.66 }
+2026-10-17T15:29:21Z thinkpad: 5.33 5.17 4.59 | macmini (bots): { 63.72 57.79 67.33 }
+2026-10-17T15:29:51Z thinkpad: 3.57 4.75 4.47 | macmini (bots): { 60.80 57.62 66.94 }
+2026-10-17T15:30:22Z thinkpad: 4.74 4.88 4.52 | macmini (bots): { 59.69 57.64 66.62 }
+2026-10-17T15:30:52Z thinkpad: 3.44 4.54 4.42 | macmini (bots): { 66.89 59.49 66.97 }
+2026-10-17T15:31:22Z thinkpad: 4.57 4.69 4.47 | macmini (bots): { 83.43 64.16 68.40 }
+2026-10-17T15:31:52Z thinkpad: 7.17 5.30 4.68 | macmini (bots): { 77.62 64.77 68.49 }
+2026-10-17T15:32:23Z thinkpad: 8.55 5.82 4.88 | macmini (bots): { 74.20 65.09 68.47 }
+2026-10-17T15:32:53Z thinkpad: 7.49 5.85 4.92 | macmini (bots): { 82.07 67.70 69.29 }
+2026-10-17T15:33:23Z thinkpad: 5.65 5.59 4.86 | macmini (bots): { 79.44 68.47 69.51 }
+2026-10-17T15:33:54Z thinkpad: 5.73 5.64 4.91 | macmini (bots): { 78.94 69.26 69.76 }
+2026-10-17T15:34:24Z thinkpad: 6.84 5.92 5.02 | macmini (bots): { 76.33 69.71 69.91 }
+2026-10-17T15:34:54Z thinkpad: 5.11 5.59 4.94 | macmini (bots): { 86.09 72.63 70.95 }
+2026-10-17T15:35:24Z thinkpad: 6.68 5.93 5.08 | macmini (bots): { 72.77 70.70 70.31 }
+2026-10-17T15:35:55Z thinkpad: 5.75 5.75 5.04 | macmini (bots): { 71.50 70.49 70.24 }
+2026-10-17T15:36:25Z thinkpad: 4.31 5.41 4.95 | macmini (bots): { 80.75 72.67 71.03 }
+2026-10-17T15:36:55Z thinkpad: 3.15 5.02 4.83 | macmini (bots): { 89.83 75.59 72.14 }
diff --git a/benchmarks/server-2026-10-17/earlier-002f14ce/walk-explore.json b/benchmarks/server-2026-10-17/earlier-002f14ce/walk-explore.json
new file mode 100644
index 000000000..39dcd268c
--- /dev/null
+++ b/benchmarks/server-2026-10-17/earlier-002f14ce/walk-explore.json
@@ -0,0 +1,695 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T14:56:24+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "a9ee56a8b143999c9bc7056850ffcd622a9214aa",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon,vanilla",
+ "bots": "1,10,25,50,100",
+ "behaviour": "walk,explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 180,
+ "seed": 12345,
+ "explore_speed": 0,
+ "gamerule": "",
+ "heap": "4g",
+ "out": "/home/ludovic/code/horizon/.claude/worktrees/server-host-4/.local/bench-out/walk-explore.json",
+ "nice": 19,
+ "bots_via": "ssh macmini",
+ "bots_bin": "/Users/ludovicmarie/code/horizon/.claude/worktrees/server-host-4/target/release/horizon-bots",
+ "connect": "",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 9.51,
+ "mspt": {
+ "average": 5.77,
+ "p50": 5.15,
+ "p95": 11.04,
+ "p99": 28.99
+ },
+ "mspt_worst_p99": 45.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 777.78,
+ "max": 779.8
+ },
+ "cpu_percent": 59.02,
+ "chunks_per_second": 9.94,
+ "unique_per_second": 0.45,
+ "forgotten_per_second": 9.99,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 2763,
+ "chunks_per_bot": {
+ "walk": 2763.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 697.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 15.35,
+ "mspt": {
+ "average": 18.84,
+ "p50": 18.87,
+ "p95": 29.55,
+ "p99": 51.32
+ },
+ "mspt_worst_p99": 456.4,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3442.06,
+ "max": 3462.1
+ },
+ "cpu_percent": 70.63,
+ "chunks_per_second": 10.47,
+ "unique_per_second": 0.47,
+ "forgotten_per_second": 10.53,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 2763,
+ "chunks_per_bot": {
+ "walk": 2763.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 697.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 9.31,
+ "mspt": {
+ "average": 16.23,
+ "p50": 15.6,
+ "p95": 29.32,
+ "p99": 44.43
+ },
+ "mspt_worst_p99": 100.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 781.84,
+ "max": 782.6
+ },
+ "cpu_percent": 136.59,
+ "chunks_per_second": 93.82,
+ "unique_per_second": 3.33,
+ "forgotten_per_second": 93.61,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 26481,
+ "chunks_per_bot": {
+ "walk": 2648.1
+ },
+ "unique_chunks_per_bot": {
+ "walk": 679.5
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 14.65,
+ "mspt": {
+ "average": 18.02,
+ "p50": 15.22,
+ "p95": 37.62,
+ "p99": 54.5
+ },
+ "mspt_worst_p99": 73.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3408.62,
+ "max": 3423.6
+ },
+ "cpu_percent": 100.57,
+ "chunks_per_second": 101.12,
+ "unique_per_second": 4.25,
+ "forgotten_per_second": 101.17,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 26763,
+ "chunks_per_bot": {
+ "walk": 2676.3
+ },
+ "unique_chunks_per_bot": {
+ "walk": 687.8
+ },
+ "resent": 0,
+ "pulled_back": 7,
+ "moved_too_quickly": 7,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 9.31,
+ "mspt": {
+ "average": 23.98,
+ "p50": 20.89,
+ "p95": 49.18,
+ "p99": 65.87
+ },
+ "mspt_worst_p99": 109.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 786.18,
+ "max": 786.5
+ },
+ "cpu_percent": 159.81,
+ "chunks_per_second": 235.75,
+ "unique_per_second": 7.84,
+ "forgotten_per_second": 235.72,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 67251,
+ "chunks_per_bot": {
+ "walk": 2690.04
+ },
+ "unique_chunks_per_bot": {
+ "walk": 683.92
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 14.95,
+ "mspt": {
+ "average": 19.19,
+ "p50": 17.34,
+ "p95": 33.84,
+ "p99": 56.21
+ },
+ "mspt_worst_p99": 79.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3531.46,
+ "max": 3582.1
+ },
+ "cpu_percent": 153.78,
+ "chunks_per_second": 252.35,
+ "unique_per_second": 11.73,
+ "forgotten_per_second": 251.58,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 66759,
+ "chunks_per_bot": {
+ "walk": 2670.36
+ },
+ "unique_chunks_per_bot": {
+ "walk": 689.76
+ },
+ "resent": 0,
+ "pulled_back": 12,
+ "moved_too_quickly": 12,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 9.21,
+ "mspt": {
+ "average": 35.07,
+ "p50": 30.55,
+ "p95": 73.24,
+ "p99": 99.38
+ },
+ "mspt_worst_p99": 117.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 816.58,
+ "max": 818.5
+ },
+ "cpu_percent": 187.42,
+ "chunks_per_second": 469.11,
+ "unique_per_second": 15.92,
+ "forgotten_per_second": 468.62,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 136962,
+ "chunks_per_bot": {
+ "walk": 2739.24
+ },
+ "unique_chunks_per_bot": {
+ "walk": 685.68
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 15.95,
+ "mspt": {
+ "average": 35.23,
+ "p50": 31.39,
+ "p95": 60.87,
+ "p99": 104.2
+ },
+ "mspt_worst_p99": 443.7,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3562.57,
+ "max": 3598.9
+ },
+ "cpu_percent": 263.27,
+ "chunks_per_second": 497.51,
+ "unique_per_second": 30.67,
+ "forgotten_per_second": 495.7,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 131116,
+ "chunks_per_bot": {
+ "walk": 2622.32
+ },
+ "unique_chunks_per_bot": {
+ "walk": 687.78
+ },
+ "resent": 0,
+ "pulled_back": 96,
+ "moved_too_quickly": 96,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 9.21,
+ "mspt": {
+ "average": 104.8,
+ "p50": 100.6,
+ "p95": 158.8,
+ "p99": 198.61
+ },
+ "mspt_worst_p99": 259.8,
+ "tps": 9.54,
+ "rss_mb": {
+ "mean": 850.05,
+ "max": 851.2
+ },
+ "cpu_percent": 198.95,
+ "chunks_per_second": 371.72,
+ "unique_per_second": 26.27,
+ "forgotten_per_second": 365.57,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 144465,
+ "chunks_per_bot": {
+ "walk": 1444.65
+ },
+ "unique_chunks_per_bot": {
+ "walk": 571.76
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 34
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 15.25,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 9.41,
+ "mspt": {
+ "average": 11.42,
+ "p50": 10.15,
+ "p95": 24.66,
+ "p99": 37.27
+ },
+ "mspt_worst_p99": 60.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 838.61,
+ "max": 888.0
+ },
+ "cpu_percent": 326.85,
+ "chunks_per_second": 41.83,
+ "unique_per_second": 36.39,
+ "forgotten_per_second": 41.75,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 9845,
+ "chunks_per_bot": {
+ "explore": 9845.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 8718.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 15.44,
+ "mspt": {
+ "average": 9.83,
+ "p50": 7.72,
+ "p95": 20.36,
+ "p99": 84.65
+ },
+ "mspt_worst_p99": 385.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3598.02,
+ "max": 3658.9
+ },
+ "cpu_percent": 244.86,
+ "chunks_per_second": 35.28,
+ "unique_per_second": 33.34,
+ "forgotten_per_second": 35.13,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 7881,
+ "chunks_per_bot": {
+ "explore": 7881.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 7540.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 9.52,
+ "mspt": {
+ "average": 23.54,
+ "p50": 21.18,
+ "p95": 43.4,
+ "p99": 60.85
+ },
+ "mspt_worst_p99": 109.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1139.51,
+ "max": 1301.0
+ },
+ "cpu_percent": 331.74,
+ "chunks_per_second": 43.86,
+ "unique_per_second": 43.09,
+ "forgotten_per_second": 43.82,
+ "waited_ticks_per_second": 172.35,
+ "chunks_total": 14140,
+ "chunks_per_bot": {
+ "explore": 1414.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1395.9
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 15.78,
+ "mspt": {
+ "average": 16.42,
+ "p50": 14.01,
+ "p95": 30.29,
+ "p99": 96.17
+ },
+ "mspt_worst_p99": 1144.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3964.49,
+ "max": 4248.3
+ },
+ "cpu_percent": 256.86,
+ "chunks_per_second": 25.43,
+ "unique_per_second": 25.33,
+ "forgotten_per_second": 25.96,
+ "waited_ticks_per_second": 76.05,
+ "chunks_total": 7991,
+ "chunks_per_bot": {
+ "explore": 799.1
+ },
+ "unique_chunks_per_bot": {
+ "explore": 797.7
+ },
+ "resent": 0,
+ "pulled_back": 11028,
+ "moved_too_quickly": 17,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 9.31,
+ "mspt": {
+ "average": 36.87,
+ "p50": 33.92,
+ "p95": 63.19,
+ "p99": 84.17
+ },
+ "mspt_worst_p99": 124.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1236.2,
+ "max": 1438.4
+ },
+ "cpu_percent": 345.03,
+ "chunks_per_second": 91.07,
+ "unique_per_second": 88.7,
+ "forgotten_per_second": 92.51,
+ "waited_ticks_per_second": 443.88,
+ "chunks_total": 30035,
+ "chunks_per_bot": {
+ "explore": 1201.4
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1176.84
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 14.55,
+ "mspt": {
+ "average": 24.31,
+ "p50": 21.76,
+ "p95": 36.55,
+ "p99": 155.88
+ },
+ "mspt_worst_p99": 1535.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 4047.76,
+ "max": 4459.2
+ },
+ "cpu_percent": 305.24,
+ "chunks_per_second": 37.94,
+ "unique_per_second": 37.82,
+ "forgotten_per_second": 38.87,
+ "waited_ticks_per_second": 261.79,
+ "chunks_total": 16604,
+ "chunks_per_bot": {
+ "explore": 664.16
+ },
+ "unique_chunks_per_bot": {
+ "explore": 660.92
+ },
+ "resent": 0,
+ "pulled_back": 33246,
+ "moved_too_quickly": 20,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 9.21,
+ "mspt": {
+ "average": 60.06,
+ "p50": 57.31,
+ "p95": 88.38,
+ "p99": 112.89
+ },
+ "mspt_worst_p99": 172.4,
+ "tps": 16.65,
+ "rss_mb": {
+ "mean": 1192.47,
+ "max": 1372.5
+ },
+ "cpu_percent": 362.42,
+ "chunks_per_second": 157.28,
+ "unique_per_second": 154.2,
+ "forgotten_per_second": 156.07,
+ "waited_ticks_per_second": 890.09,
+ "chunks_total": 54551,
+ "chunks_per_bot": {
+ "explore": 1091.02
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1078.5
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 15.64,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 9.21,
+ "mspt": {
+ "average": 124.25,
+ "p50": 120.1,
+ "p95": 168.33,
+ "p99": 204.64
+ },
+ "mspt_worst_p99": 262.2,
+ "tps": 8.05,
+ "rss_mb": {
+ "mean": 1283.26,
+ "max": 1418.6
+ },
+ "cpu_percent": 334.14,
+ "chunks_per_second": 185.47,
+ "unique_per_second": 184.54,
+ "forgotten_per_second": 179.79,
+ "waited_ticks_per_second": 1864.45,
+ "chunks_total": 78556,
+ "chunks_per_bot": {
+ "explore": 785.56
+ },
+ "unique_chunks_per_bot": {
+ "explore": 784.88
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 15.44,
+ "error": "[Errno 32] Broken pipe"
+ }
+ ]
+}
diff --git a/benchmarks/server-2026-10-17/explore-equal-rate.json b/benchmarks/server-2026-10-17/explore-equal-rate.json
new file mode 100644
index 000000000..1356529e3
--- /dev/null
+++ b/benchmarks/server-2026-10-17/explore-equal-rate.json
@@ -0,0 +1,341 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T18:12:19+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "7bbbf6e97fb53683eae0a01ce2c134e53cb649a7",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon,vanilla",
+ "bots": "1,10,25,50",
+ "behaviour": "explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 180,
+ "seed": 12345,
+ "explore_speed": 0.8,
+ "gamerule": "",
+ "heap": "4g",
+ "out": "/home/ludovic/code/horizon/.claude/worktrees/server-host-4/.local/bench-out/explore-equal-rate.json",
+ "nice": 19,
+ "bots_via": "ssh macmini",
+ "bots_bin": "/Users/ludovicmarie/code/horizon/.claude/worktrees/server-host-4/target/release/horizon-bots",
+ "connect": "",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 9.42,
+ "mspt": {
+ "average": 3.16,
+ "p50": 2.98,
+ "p95": 5.78,
+ "p99": 12.17
+ },
+ "mspt_worst_p99": 38.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 759.26,
+ "max": 769.5
+ },
+ "cpu_percent": 21.74,
+ "chunks_per_second": 1.64,
+ "unique_per_second": 1.27,
+ "forgotten_per_second": 1.54,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 841,
+ "chunks_per_bot": {
+ "explore": 841.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 781.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 17.17,
+ "mspt": {
+ "average": 16.82,
+ "p50": 16.67,
+ "p95": 27.3,
+ "p99": 52.16
+ },
+ "mspt_worst_p99": 453.4,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3373.16,
+ "max": 3405.9
+ },
+ "cpu_percent": 69.22,
+ "chunks_per_second": 1.66,
+ "unique_per_second": 1.35,
+ "forgotten_per_second": 1.54,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 838,
+ "chunks_per_bot": {
+ "explore": 838.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 779.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 9.82,
+ "mspt": {
+ "average": 9.83,
+ "p50": 8.65,
+ "p95": 19.01,
+ "p99": 32.9
+ },
+ "mspt_worst_p99": 64.0,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 861.49,
+ "max": 922.2
+ },
+ "cpu_percent": 77.43,
+ "chunks_per_second": 13.71,
+ "unique_per_second": 12.31,
+ "forgotten_per_second": 13.59,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 7831,
+ "chunks_per_bot": {
+ "explore": 783.1
+ },
+ "unique_chunks_per_bot": {
+ "explore": 757.1
+ },
+ "resent": 0,
+ "pulled_back": 1051,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 15.06,
+ "mspt": {
+ "average": 24.38,
+ "p50": 21.55,
+ "p95": 39.58,
+ "p99": 66.64
+ },
+ "mspt_worst_p99": 107.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3569.41,
+ "max": 3685.1
+ },
+ "cpu_percent": 132.09,
+ "chunks_per_second": 13.54,
+ "unique_per_second": 12.32,
+ "forgotten_per_second": 13.62,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 7753,
+ "chunks_per_bot": {
+ "explore": 775.3
+ },
+ "unique_chunks_per_bot": {
+ "explore": 749.2
+ },
+ "resent": 0,
+ "pulled_back": 1027,
+ "moved_too_quickly": 6,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 9.31,
+ "mspt": {
+ "average": 16.87,
+ "p50": 15.4,
+ "p95": 30.88,
+ "p99": 46.73
+ },
+ "mspt_worst_p99": 84.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 887.11,
+ "max": 945.5
+ },
+ "cpu_percent": 111.2,
+ "chunks_per_second": 33.51,
+ "unique_per_second": 29.92,
+ "forgotten_per_second": 33.33,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 19718,
+ "chunks_per_bot": {
+ "explore": 788.72
+ },
+ "unique_chunks_per_bot": {
+ "explore": 759.08
+ },
+ "resent": 0,
+ "pulled_back": 3770,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 14.94,
+ "mspt": {
+ "average": 30.29,
+ "p50": 28.25,
+ "p95": 43.47,
+ "p99": 68.56
+ },
+ "mspt_worst_p99": 165.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3608.97,
+ "max": 3732.0
+ },
+ "cpu_percent": 176.28,
+ "chunks_per_second": 32.98,
+ "unique_per_second": 29.29,
+ "forgotten_per_second": 32.84,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 19442,
+ "chunks_per_bot": {
+ "explore": 777.68
+ },
+ "unique_chunks_per_bot": {
+ "explore": 748.24
+ },
+ "resent": 0,
+ "pulled_back": 5139,
+ "moved_too_quickly": 11,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 9.41,
+ "mspt": {
+ "average": 23.57,
+ "p50": 20.43,
+ "p95": 47.53,
+ "p99": 67.23
+ },
+ "mspt_worst_p99": 106.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 924.41,
+ "max": 984.3
+ },
+ "cpu_percent": 127.14,
+ "chunks_per_second": 66.56,
+ "unique_per_second": 59.42,
+ "forgotten_per_second": 66.43,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 39950,
+ "chunks_per_bot": {
+ "explore": 799.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 767.56
+ },
+ "resent": 0,
+ "pulled_back": 7434,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 15.04,
+ "mspt": {
+ "average": 42.44,
+ "p50": 40.71,
+ "p95": 54.84,
+ "p99": 94.23
+ },
+ "mspt_worst_p99": 212.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3667.85,
+ "max": 3780.8
+ },
+ "cpu_percent": 200.85,
+ "chunks_per_second": 65.17,
+ "unique_per_second": 58.11,
+ "forgotten_per_second": 65.22,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 39772,
+ "chunks_per_bot": {
+ "explore": 795.44
+ },
+ "unique_chunks_per_bot": {
+ "explore": 764.02
+ },
+ "resent": 0,
+ "pulled_back": 10604,
+ "moved_too_quickly": 38,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ }
+ ]
+}
diff --git a/benchmarks/server-2026-10-17/load.txt b/benchmarks/server-2026-10-17/load.txt
new file mode 100644
index 000000000..33d8b191f
--- /dev/null
+++ b/benchmarks/server-2026-10-17/load.txt
@@ -0,0 +1,279 @@
+2026-10-17T15:51:54Z thinkpad: 1.30 2.47 3.85 | macmini (bots): { 67.44 76.34 77.44 }
+2026-10-17T15:52:25Z thinkpad: 2.07 2.54 3.83 | macmini (bots): { 64.78 74.76 76.82 }
+2026-10-17T15:52:55Z thinkpad: 2.08 2.51 3.78 | macmini (bots): { 62.50 73.29 76.22 }
+2026-10-17T15:53:25Z thinkpad: 1.46 2.31 3.67 | macmini (bots): { 63.70 72.67 75.90 }
+2026-10-17T15:53:55Z thinkpad: 1.12 2.15 3.58 | macmini (bots): { 69.06 73.27 76.01 }
+2026-10-17T15:54:26Z thinkpad: 1.34 2.09 3.51 | macmini (bots): { 72.55 73.63 76.04 }
+2026-10-17T15:54:56Z thinkpad: 1.11 1.97 3.42 | macmini (bots): { 77.53 74.77 76.37 }
+2026-10-17T15:55:26Z thinkpad: 1.02 1.87 3.34 | macmini (bots): { 77.61 74.90 76.36 }
+2026-10-17T15:55:56Z thinkpad: 1.09 1.81 3.27 | macmini (bots): { 71.56 73.69 75.86 }
+2026-10-17T15:56:26Z thinkpad: 2.23 1.99 3.29 | macmini (bots): { 65.21 71.93 75.15 }
+2026-10-17T15:56:57Z thinkpad: 2.60 2.12 3.29 | macmini (bots): { 58.16 69.40 74.10 }
+2026-10-17T15:57:27Z thinkpad: 2.57 2.18 3.27 | macmini (bots): { 57.54 68.26 73.52 }
+2026-10-17T15:57:57Z thinkpad: 2.37 2.17 3.23 | macmini (bots): { 56.15 66.85 72.83 }
+2026-10-17T15:58:27Z thinkpad: 1.90 2.08 3.17 | macmini (bots): { 59.28 66.57 72.52 }
+2026-10-17T15:58:58Z thinkpad: 1.71 2.02 3.11 | macmini (bots): { 55.64 64.94 71.72 }
+2026-10-17T15:59:28Z thinkpad: 1.66 1.97 3.06 | macmini (bots): { 66.06 66.49 72.04 }
+2026-10-17T15:59:58Z thinkpad: 1.18 1.83 2.98 | macmini (bots): { 78.15 69.43 72.92 }
+2026-10-17T16:00:28Z thinkpad: 0.83 1.68 2.89 | macmini (bots): { 70.77 68.57 72.49 }
+2026-10-17T16:00:58Z thinkpad: 1.27 1.70 2.86 | macmini (bots): { 71.95 68.97 72.49 }
+2026-10-17T16:01:29Z thinkpad: 1.85 1.79 2.85 | macmini (bots): { 83.43 72.22 73.56 }
+2026-10-17T16:01:59Z thinkpad: 2.51 1.95 2.86 | macmini (bots): { 70.49 70.18 72.77 }
+2026-10-17T16:02:29Z thinkpad: 1.98 1.87 2.81 | macmini (bots): { 64.00 68.64 72.12 }
+2026-10-17T16:02:59Z thinkpad: 1.77 1.84 2.77 | macmini (bots): { 59.65 67.09 71.44 }
+2026-10-17T16:03:30Z thinkpad: 4.04 2.35 2.91 | macmini (bots): { 62.67 67.15 71.31 }
+2026-10-17T16:04:00Z thinkpad: 4.94 2.72 3.01 | macmini (bots): { 67.63 67.82 71.40 }
+2026-10-17T16:04:30Z thinkpad: 4.22 2.78 3.02 | macmini (bots): { 70.41 68.39 71.48 }
+2026-10-17T16:05:00Z thinkpad: 3.81 2.80 3.02 | macmini (bots): { 66.59 67.83 71.18 }
+2026-10-17T16:05:31Z thinkpad: 3.20 2.75 3.00 | macmini (bots): { 72.53 69.01 71.48 }
+2026-10-17T16:06:01Z thinkpad: 4.22 3.04 3.08 | macmini (bots): { 71.30 69.27 71.50 }
+2026-10-17T16:06:31Z thinkpad: 5.43 3.47 3.23 | macmini (bots): { 68.37 68.63 71.19 }
+2026-10-17T16:07:01Z thinkpad: 4.35 3.42 3.22 | macmini (bots): { 60.20 66.68 70.39 }
+2026-10-17T16:07:31Z thinkpad: 3.47 3.31 3.19 | macmini (bots): { 58.03 65.51 69.84 }
+2026-10-17T16:08:02Z thinkpad: 2.30 3.04 3.11 | macmini (bots): { 59.05 65.13 69.55 }
+2026-10-17T16:08:32Z thinkpad: 1.88 2.86 3.04 | macmini (bots): { 51.77 62.75 68.53 }
+2026-10-17T16:09:02Z thinkpad: 1.38 2.65 2.97 | macmini (bots): { 49.05 61.01 67.70 }
+2026-10-17T16:09:32Z thinkpad: 3.10 2.95 3.06 | macmini (bots): { 48.91 59.82 67.03 }
+2026-10-17T16:10:02Z thinkpad: 2.91 2.91 3.04 | macmini (bots): { 47.56 58.44 66.25 }
+2026-10-17T16:10:33Z thinkpad: 2.58 2.83 3.01 | macmini (bots): { 49.23 57.69 65.70 }
+2026-10-17T16:11:03Z thinkpad: 8.38 4.15 3.44 | macmini (bots): { 44.16 55.72 64.71 }
+2026-10-17T16:11:33Z thinkpad: 9.94 4.92 3.72 | macmini (bots): { 44.50 54.71 64.03 }
+2026-10-17T16:12:03Z thinkpad: 10.08 5.42 3.92 | macmini (bots): { 42.15 53.21 63.17 }
+2026-10-17T16:12:33Z thinkpad: 6.79 5.06 3.85 | macmini (bots): { 36.13 50.73 61.92 }
+2026-10-17T16:13:04Z thinkpad: 4.61 4.72 3.77 | macmini (bots): { 41.28 50.64 61.51 }
+2026-10-17T16:13:34Z thinkpad: 3.81 4.50 3.73 | macmini (bots): { 42.92 50.15 60.95 }
+2026-10-17T16:14:04Z thinkpad: 3.39 4.35 3.71 | macmini (bots): { 41.56 49.16 60.22 }
+2026-10-17T16:14:35Z thinkpad: 7.53 5.17 4.00 | macmini (bots): { 47.48 49.82 60.07 }
+2026-10-17T16:15:05Z thinkpad: 9.73 6.01 4.32 | macmini (bots): { 51.43 50.41 59.92 }
+2026-10-17T16:15:35Z thinkpad: 8.07 5.94 4.35 | macmini (bots): { 69.31 54.81 61.18 }
+2026-10-17T16:16:05Z thinkpad: 9.27 6.45 4.57 | macmini (bots): { 71.85 56.92 61.73 }
+2026-10-17T16:16:35Z thinkpad: 8.69 6.59 4.68 | macmini (bots): { 64.77 56.72 61.50 }
+2026-10-17T16:17:06Z thinkpad: 6.11 6.17 4.60 | macmini (bots): { 57.92 55.86 61.02 }
+2026-10-17T16:17:36Z thinkpad: 6.79 6.33 4.70 | macmini (bots): { 51.44 54.51 60.36 }
+2026-10-17T16:18:06Z thinkpad: 5.16 5.99 4.64 | macmini (bots): { 51.33 54.23 60.05 }
+2026-10-17T16:18:36Z thinkpad: 5.30 5.93 4.66 | macmini (bots): { 55.22 54.87 60.08 }
+2026-10-17T16:19:07Z thinkpad: 4.78 5.72 4.63 | macmini (bots): { 51.62 53.94 59.56 }
+2026-10-17T16:19:37Z thinkpad: 5.25 5.78 4.69 | macmini (bots): { 48.77 53.04 59.04 }
+2026-10-17T16:20:07Z thinkpad: 4.63 5.60 4.67 | macmini (bots): { 54.59 53.92 59.14 }
+2026-10-17T16:20:37Z thinkpad: 5.46 5.67 4.72 | macmini (bots): { 59.07 55.03 59.36 }
+2026-10-17T16:21:07Z thinkpad: 8.07 6.19 4.91 | macmini (bots): { 52.53 53.83 58.77 }
+2026-10-17T16:21:38Z thinkpad: 15.01 8.05 5.57 | macmini (bots): { 48.85 52.78 58.19 }
+2026-10-17T16:22:08Z thinkpad: 19.08 9.69 6.20 | macmini (bots): { 54.73 53.61 58.29 }
+2026-10-17T16:22:39Z thinkpad: 27.72 12.63 7.29 | macmini (bots): { 54.23 53.61 58.13 }
+2026-10-17T16:23:09Z thinkpad: 23.10 12.88 7.53 | macmini (bots): { 51.63 53.06 57.77 }
+2026-10-17T16:23:39Z thinkpad: 20.51 13.53 7.96 | macmini (bots): { 45.29 51.38 57.00 }
+2026-10-17T16:24:10Z thinkpad: 12.70 12.30 7.72 | macmini (bots): { 45.61 50.91 56.63 }
+2026-10-17T16:24:40Z thinkpad: 8.67 11.35 7.55 | macmini (bots): { 45.18 50.35 56.23 }
+2026-10-17T16:25:10Z thinkpad: 6.35 10.53 7.40 | macmini (bots): { 41.10 48.88 55.50 }
+2026-10-17T16:25:40Z thinkpad: 6.26 10.16 7.38 | macmini (bots): { 49.86 50.24 55.76 }
+2026-10-17T16:26:11Z thinkpad: 7.71 10.11 7.45 | macmini (bots): { 53.93 51.11 55.88 }
+2026-10-17T16:26:41Z thinkpad: 9.50 10.32 7.61 | macmini (bots): { 47.61 49.86 55.26 }
+2026-10-17T16:27:11Z thinkpad: 10.26 10.39 7.72 | macmini (bots): { 46.43 49.36 54.89 }
+2026-10-17T16:27:42Z thinkpad: 10.61 10.48 7.83 | macmini (bots): { 48.88 49.66 54.80 }
+2026-10-17T16:28:12Z thinkpad: 10.39 10.45 7.91 | macmini (bots): { 58.42 51.74 55.37 }
+2026-10-17T16:28:42Z thinkpad: 10.36 10.44 7.99 | macmini (bots): { 59.59 52.67 55.58 }
+2026-10-17T16:29:13Z thinkpad: 9.63 10.25 8.00 | macmini (bots): { 55.30 52.38 55.38 }
+2026-10-17T16:29:43Z thinkpad: 10.33 10.37 8.12 | macmini (bots): { 57.79 53.13 55.52 }
+2026-10-17T16:30:13Z thinkpad: 9.68 10.18 8.12 | macmini (bots): { 57.83 53.60 55.61 }
+2026-10-17T16:30:43Z thinkpad: 9.72 10.17 8.19 | macmini (bots): { 78.94 59.18 57.56 }
+2026-10-17T16:31:14Z thinkpad: 6.60 9.36 7.98 | macmini (bots): { 87.29 62.98 58.99 }
+2026-10-17T16:31:44Z thinkpad: 6.77 9.08 7.93 | macmini (bots): { 81.82 64.16 59.57 }
+2026-10-17T16:32:14Z thinkpad: 13.15 10.41 8.41 | macmini (bots): { 81.20 65.92 60.37 }
+2026-10-17T16:32:45Z thinkpad: 27.80 14.12 9.71 | macmini (bots): { 75.41 66.22 60.69 }
+2026-10-17T16:33:15Z thinkpad: 44.59 19.25 11.54 | macmini (bots): { 66.92 65.08 60.47 }
+2026-10-17T16:33:46Z thinkpad: 44.87 21.89 12.67 | macmini (bots): { 61.47 63.94 60.22 }
+2026-10-17T16:34:16Z thinkpad: 38.98 22.67 13.23 | macmini (bots): { 62.13 63.78 60.28 }
+2026-10-17T16:34:47Z thinkpad: 47.64 26.08 14.65 | macmini (bots): { 81.23 68.06 61.94 }
+2026-10-17T16:35:17Z thinkpad: 47.83 28.02 15.65 | macmini (bots): { 116.14 78.43 65.98 }
+2026-10-17T16:35:48Z thinkpad: 40.43 28.18 16.10 | macmini (bots): { 125.61 84.41 68.58 }
+2026-10-17T16:36:19Z thinkpad: 41.34 29.71 17.00 | macmini (bots): { 143.61 92.86 72.20 }
+2026-10-17T16:36:49Z thinkpad: 34.40 29.19 17.29 | macmini (bots): { 156.05 100.88 75.83 }
+2026-10-17T16:37:20Z thinkpad: 25.34 27.65 17.17 | macmini (bots): { 151.90 105.26 78.29 }
+2026-10-17T16:37:50Z thinkpad: 18.36 25.71 16.85 | macmini (bots): { 141.10 107.25 79.96 }
+2026-10-17T16:38:20Z thinkpad: 16.19 24.47 16.72 | macmini (bots): { 131.21 107.92 81.13 }
+2026-10-17T16:38:51Z thinkpad: 13.36 23.00 16.48 | macmini (bots): { 122.08 107.78 82.00 }
+2026-10-17T16:39:21Z thinkpad: 11.27 21.57 16.21 | macmini (bots): { 107.07 105.50 82.07 }
+2026-10-17T16:39:51Z thinkpad: 11.19 20.56 16.04 | macmini (bots): { 96.38 103.12 82.02 }
+2026-10-17T16:40:22Z thinkpad: 10.06 19.37 15.79 | macmini (bots): { 89.06 100.79 81.91 }
+2026-10-17T16:40:52Z thinkpad: 7.38 17.86 15.40 | macmini (bots): { 79.35 97.41 81.34 }
+2026-10-17T16:41:23Z thinkpad: 6.18 16.57 15.05 | macmini (bots): { 81.70 96.20 81.46 }
+2026-10-17T16:41:53Z thinkpad: 5.56 15.44 14.72 | macmini (bots): { 86.51 95.88 81.84 }
+2026-10-17T16:42:23Z thinkpad: 4.90 14.33 14.37 | macmini (bots): { 99.20 97.69 83.05 }
+2026-10-17T16:42:53Z thinkpad: 5.01 13.47 14.08 | macmini (bots): { 116.29 101.87 85.07 }
+2026-10-17T16:43:24Z thinkpad: 4.34 12.50 13.74 | macmini (bots): { 131.32 106.77 87.42 }
+2026-10-17T16:43:54Z thinkpad: 4.08 11.65 13.42 | macmini (bots): { 155.44 114.77 90.98 }
+2026-10-17T16:44:24Z thinkpad: 4.00 10.90 13.11 | macmini (bots): { 167.86 121.62 94.28 }
+2026-10-17T16:44:54Z thinkpad: 3.98 10.13 12.77 | macmini (bots): { 160.36 124.31 96.20 }
+2026-10-17T16:45:25Z thinkpad: 4.20 9.59 12.50 | macmini (bots): { 163.23 128.59 98.74 }
+2026-10-17T16:45:55Z thinkpad: 4.54 9.15 12.27 | macmini (bots): { 169.93 133.73 101.65 }
+2026-10-17T16:46:25Z thinkpad: 4.44 8.69 12.01 | macmini (bots): { 162.40 135.22 103.29 }
+2026-10-17T16:46:55Z thinkpad: 4.06 8.20 11.74 | macmini (bots): { 164.16 138.31 105.52 }
+2026-10-17T16:47:26Z thinkpad: 3.96 7.78 11.49 | macmini (bots): { 157.92 139.31 107.02 }
+2026-10-17T16:47:56Z thinkpad: 3.71 7.35 11.23 | macmini (bots): { 155.72 140.55 108.59 }
+2026-10-17T16:48:26Z thinkpad: 4.93 7.32 11.09 | macmini (bots): { 153.39 141.52 110.05 }
+2026-10-17T16:48:56Z thinkpad: 4.61 7.03 10.88 | macmini (bots): { 137.54 138.87 110.18 }
+2026-10-17T16:49:27Z thinkpad: 4.01 6.65 10.63 | macmini (bots): { 136.53 138.36 110.98 }
+2026-10-17T16:49:57Z thinkpad: 3.19 6.19 10.35 | macmini (bots): { 141.12 139.18 112.22 }
+2026-10-17T16:50:27Z thinkpad: 5.31 6.43 10.30 | macmini (bots): { 122.76 135.27 111.75 }
+2026-10-17T16:50:57Z thinkpad: 5.95 6.48 10.19 | macmini (bots): { 114.26 132.02 111.39 }
+2026-10-17T16:51:28Z thinkpad: 5.76 6.41 10.05 | macmini (bots): { 116.04 130.87 111.69 }
+2026-10-17T16:51:58Z thinkpad: 5.11 6.18 9.86 | macmini (bots): { 115.06 129.17 111.74 }
+2026-10-17T16:52:28Z thinkpad: 5.09 6.07 9.70 | macmini (bots): { 109.91 126.59 111.41 }
+2026-10-17T16:52:58Z thinkpad: 4.74 5.90 9.53 | macmini (bots): { 101.90 123.11 110.67 }
+2026-10-17T16:53:29Z thinkpad: 4.89 5.84 9.39 | macmini (bots): { 83.29 116.38 108.74 }
+2026-10-17T16:53:59Z thinkpad: 5.10 5.82 9.27 | macmini (bots): { 119.16 122.10 111.09 }
+2026-10-17T16:54:29Z thinkpad: 4.57 5.67 9.10 | macmini (bots): { 114.87 120.76 110.98 }
+2026-10-17T16:55:00Z thinkpad: 4.74 5.58 8.96 | macmini (bots): { 129.84 123.74 112.39 }
+2026-10-17T16:55:30Z thinkpad: 6.40 5.90 8.96 | macmini (bots): { 100.10 117.29 110.46 }
+2026-10-17T16:56:00Z thinkpad: 6.96 6.08 8.92 | macmini (bots): { 80.18 110.75 108.32 }
+2026-10-17T16:56:30Z thinkpad: 6.07 5.95 8.79 | macmini (bots): { 74.41 106.39 106.82 }
+2026-10-17T16:57:01Z thinkpad: 6.63 6.13 8.75 | macmini (bots): { 81.71 104.99 106.29 }
+2026-10-17T16:57:31Z thinkpad: 6.39 6.14 8.68 | macmini (bots): { 101.10 107.55 107.18 }
+2026-10-17T16:58:01Z thinkpad: 6.32 6.16 8.60 | macmini (bots): { 94.45 105.66 106.52 }
+2026-10-17T16:58:31Z thinkpad: 5.19 5.90 8.44 | macmini (bots): { 78.76 100.83 104.75 }
+2026-10-17T16:59:02Z thinkpad: 5.24 5.83 8.33 | macmini (bots): { 78.19 98.42 103.73 }
+2026-10-17T16:59:32Z thinkpad: 3.95 5.48 8.13 | macmini (bots): { 77.57 96.42 102.82 }
+2026-10-17T17:00:02Z thinkpad: 3.12 5.13 7.93 | macmini (bots): { 85.23 96.29 102.54 }
+2026-10-17T17:00:32Z thinkpad: 3.17 4.93 7.77 | macmini (bots): { 99.84 99.07 103.35 }
+2026-10-17T17:01:02Z thinkpad: 6.09 5.50 7.88 | macmini (bots): { 80.56 94.49 101.54 }
+2026-10-17T17:01:33Z thinkpad: 9.23 6.29 8.06 | macmini (bots): { 79.70 93.03 100.77 }
+2026-10-17T17:02:03Z thinkpad: 9.09 6.54 8.09 | macmini (bots): { 76.63 90.94 99.74 }
+2026-10-17T17:02:33Z thinkpad: 7.86 6.52 8.04 | macmini (bots): { 93.08 93.50 100.36 }
+2026-10-17T17:03:03Z thinkpad: 7.81 6.67 8.04 | macmini (bots): { 83.14 91.09 99.25 }
+2026-10-17T17:03:34Z thinkpad: 6.69 6.51 7.94 | macmini (bots): { 79.37 89.64 98.45 }
+2026-10-17T17:04:04Z thinkpad: 5.63 6.27 7.81 | macmini (bots): { 73.68 87.23 97.27 }
+2026-10-17T17:04:34Z thinkpad: 5.75 6.21 7.75 | macmini (bots): { 75.89 86.23 96.54 }
+2026-10-17T17:05:04Z thinkpad: 5.05 6.01 7.63 | macmini (bots): { 79.29 86.13 96.10 }
+2026-10-17T17:05:35Z thinkpad: 3.88 5.62 7.44 | macmini (bots): { 76.07 84.79 95.28 }
+2026-10-17T17:06:05Z thinkpad: 6.47 6.07 7.53 | macmini (bots): { 70.59 82.62 94.13 }
+2026-10-17T17:06:35Z thinkpad: 8.20 6.53 7.63 | macmini (bots): { 69.09 81.18 93.21 }
+2026-10-17T17:07:05Z thinkpad: 7.59 6.54 7.60 | macmini (bots): { 77.55 82.11 93.13 }
+2026-10-17T17:07:36Z thinkpad: 6.93 6.49 7.55 | macmini (bots): { 84.23 83.41 93.22 }
+2026-10-17T17:08:06Z thinkpad: 7.21 6.61 7.56 | macmini (bots): { 84.31 83.68 92.99 }
+2026-10-17T17:08:36Z thinkpad: 6.73 6.57 7.51 | macmini (bots): { 81.04 82.99 92.42 }
+2026-10-17T17:09:06Z thinkpad: 6.12 6.43 7.44 | macmini (bots): { 86.55 83.77 92.35 }
+2026-10-17T17:09:36Z thinkpad: 6.77 6.58 7.46 | macmini (bots): { 95.19 86.31 92.99 }
+2026-10-17T17:10:07Z thinkpad: 7.13 6.68 7.46 | macmini (bots): { 111.30 91.11 94.50 }
+2026-10-17T17:10:37Z thinkpad: 5.09 6.23 7.29 | macmini (bots): { 118.51 95.17 95.87 }
+2026-10-17T17:11:07Z thinkpad: 4.00 5.86 7.13 | macmini (bots): { 121.12 98.01 96.88 }
+2026-10-17T17:11:38Z thinkpad: 3.50 5.57 6.99 | macmini (bots): { 109.57 97.67 96.81 }
+2026-10-17T17:12:08Z thinkpad: 2.92 5.22 6.83 | macmini (bots): { 108.43 98.44 97.11 }
+2026-10-17T17:12:38Z thinkpad: 3.42 5.12 6.74 | macmini (bots): { 101.61 97.86 96.95 }
+2026-10-17T17:13:09Z thinkpad: 5.64 5.51 6.82 | macmini (bots): { 101.66 98.17 97.09 }
+2026-10-17T17:13:39Z thinkpad: 7.06 5.89 6.91 | macmini (bots): { 88.43 95.36 96.11 }
+2026-10-17T17:14:09Z thinkpad: 7.61 6.13 6.96 | macmini (bots): { 79.03 92.54 95.07 }
+2026-10-17T17:14:39Z thinkpad: 9.06 6.68 7.12 | macmini (bots): { 92.55 94.57 95.72 }
+2026-10-17T17:15:10Z thinkpad: 9.81 7.06 7.22 | macmini (bots): { 93.71 94.49 95.64 }
+2026-10-17T17:15:40Z thinkpad: 9.98 7.41 7.34 | macmini (bots): { 92.26 93.86 95.35 }
+2026-10-17T17:16:10Z thinkpad: 7.60 7.08 7.23 | macmini (bots): { 88.61 92.91 94.96 }
+2026-10-17T17:16:40Z thinkpad: 6.81 6.93 7.17 | macmini (bots): { 96.96 94.47 95.45 }
+2026-10-17T17:17:11Z thinkpad: 6.31 6.81 7.12 | macmini (bots): { 102.92 96.14 96.02 }
+2026-10-17T17:17:41Z thinkpad: 4.81 6.38 6.97 | macmini (bots): { 91.20 94.16 95.32 }
+2026-10-17T17:18:11Z thinkpad: 7.36 6.81 7.09 | macmini (bots): { 93.60 94.31 95.32 }
+2026-10-17T17:18:41Z thinkpad: 9.42 7.38 7.27 | macmini (bots): { 90.86 93.57 95.02 }
+2026-10-17T17:19:11Z thinkpad: 9.95 7.72 7.39 | macmini (bots): { 88.94 92.94 94.75 }
+2026-10-17T17:19:42Z thinkpad: 9.51 7.85 7.45 | macmini (bots): { 94.97 93.93 95.03 }
+2026-10-17T17:20:12Z thinkpad: 8.97 7.90 7.48 | macmini (bots): { 80.46 90.39 93.71 }
+2026-10-17T17:20:42Z thinkpad: 7.56 7.65 7.41 | macmini (bots): { 74.38 87.95 92.71 }
+2026-10-17T17:21:12Z thinkpad: 6.39 7.36 7.32 | macmini (bots): { 77.48 87.26 92.28 }
+2026-10-17T17:21:43Z thinkpad: 5.21 6.98 7.19 | macmini (bots): { 82.05 87.48 92.19 }
+2026-10-17T17:22:13Z thinkpad: 3.87 6.49 7.02 | macmini (bots): { 88.15 88.45 92.38 }
+2026-10-17T17:22:43Z thinkpad: 3.86 6.22 6.91 | macmini (bots): { 100.23 91.12 93.19 }
+2026-10-17T17:23:13Z thinkpad: 8.32 7.05 7.16 | macmini (bots): { 84.55 88.39 92.15 }
+2026-10-17T17:23:43Z thinkpad: 13.84 8.37 7.59 | macmini (bots): { 73.74 85.38 90.92 }
+2026-10-17T17:24:14Z thinkpad: 21.02 10.71 8.40 | macmini (bots): { 71.36 83.72 90.13 }
+2026-10-17T17:24:44Z thinkpad: 20.73 11.82 8.85 | macmini (bots): { 82.27 85.04 90.38 }
+2026-10-17T17:25:14Z thinkpad: 16.80 11.77 8.94 | macmini (bots): { 78.63 83.92 89.78 }
+2026-10-17T17:25:44Z thinkpad: 14.62 11.68 8.99 | macmini (bots): { 82.33 84.06 89.61 }
+2026-10-17T17:26:15Z thinkpad: 14.51 11.94 9.17 | macmini (bots): { 74.13 81.89 88.63 }
+2026-10-17T17:26:45Z thinkpad: 12.48 11.74 9.20 | macmini (bots): { 75.65 81.46 88.24 }
+2026-10-17T17:27:15Z thinkpad: 15.24 12.56 9.56 | macmini (bots): { 71.35 79.78 87.35 }
+2026-10-17T17:27:45Z thinkpad: 15.70 12.87 9.76 | macmini (bots): { 68.21 78.17 86.51 }
+2026-10-17T17:28:16Z thinkpad: 12.80 12.47 9.72 | macmini (bots): { 79.74 80.10 86.92 }
+2026-10-17T17:28:46Z thinkpad: 9.05 11.58 9.51 | macmini (bots): { 101.01 85.27 88.56 }
+2026-10-17T17:29:16Z thinkpad: 9.38 11.41 9.53 | macmini (bots): { 93.76 85.18 88.43 }
+2026-10-17T17:29:46Z thinkpad: 11.08 11.62 9.65 | macmini (bots): { 74.91 81.56 87.01 }
+2026-10-17T17:30:17Z thinkpad: 10.98 11.53 9.69 | macmini (bots): { 61.10 77.50 85.34 }
+2026-10-17T17:30:47Z thinkpad: 9.83 11.21 9.64 | macmini (bots): { 51.19 73.56 83.64 }
+2026-10-17T17:31:18Z thinkpad: 9.65 11.03 9.63 | macmini (bots): { 49.64 71.03 82.37 }
+2026-10-17T17:31:48Z thinkpad: 7.22 10.33 9.44 | macmini (bots): { 53.62 69.90 81.56 }
+2026-10-17T17:32:18Z thinkpad: 5.79 9.68 9.25 | macmini (bots): { 61.07 70.36 81.34 }
+2026-10-17T17:32:48Z thinkpad: 3.70 8.80 8.97 | macmini (bots): { 60.39 69.24 80.55 }
+2026-10-17T17:33:19Z thinkpad: 2.72 8.08 8.73 | macmini (bots): { 57.06 67.51 79.53 }
+2026-10-17T17:33:49Z thinkpad: 1.97 7.37 8.47 | macmini (bots): { 65.72 68.41 79.42 }
+2026-10-17T17:34:19Z thinkpad: 1.25 6.68 8.20 | macmini (bots): { 62.60 67.40 78.67 }
+2026-10-17T17:34:49Z thinkpad: 0.94 6.09 7.96 | macmini (bots): { 71.83 69.24 78.95 }
+2026-10-17T17:35:20Z thinkpad: 0.72 5.54 7.71 | macmini (bots): { 66.16 68.07 78.19 }
+2026-10-17T17:35:50Z thinkpad: 0.44 5.01 7.47 | macmini (bots): { 70.96 68.91 78.13 }
+2026-10-17T17:36:20Z thinkpad: 1.70 4.79 7.30 | macmini (bots): { 79.74 71.45 78.74 }
+2026-10-17T17:36:50Z thinkpad: 3.03 4.80 7.22 | macmini (bots): { 79.71 72.75 78.95 }
+2026-10-17T17:37:21Z thinkpad: 3.07 4.67 7.10 | macmini (bots): { 85.13 74.60 79.40 }
+2026-10-17T17:37:51Z thinkpad: 2.32 4.33 6.91 | macmini (bots): { 84.85 75.70 79.64 }
+2026-10-17T17:38:21Z thinkpad: 1.83 4.03 6.73 | macmini (bots): { 86.47 76.79 79.88 }
+2026-10-17T17:38:51Z thinkpad: 1.11 3.64 6.51 | macmini (bots): { 106.96 82.74 81.94 }
+2026-10-17T17:39:22Z thinkpad: 1.03 3.37 6.33 | macmini (bots): { 114.52 87.01 83.52 }
+2026-10-17T17:39:52Z thinkpad: 1.11 3.16 6.16 | macmini (bots): { 103.99 87.05 83.65 }
+2026-10-17T17:40:22Z thinkpad: 1.31 3.02 6.02 | macmini (bots): { 100.27 87.59 83.95 }
+2026-10-17T17:40:52Z thinkpad: 1.36 2.87 5.87 | macmini (bots): { 98.17 88.44 84.40 }
+2026-10-17T17:41:22Z thinkpad: 2.01 2.88 5.78 | macmini (bots): { 96.27 88.67 84.60 }
+2026-10-17T17:41:53Z thinkpad: 1.96 2.77 5.65 | macmini (bots): { 96.31 89.44 85.03 }
+2026-10-17T17:42:23Z thinkpad: 3.06 2.97 5.62 | macmini (bots): { 80.49 86.30 84.04 }
+2026-10-17T17:42:53Z thinkpad: 2.38 2.81 5.49 | macmini (bots): { 66.40 82.24 82.64 }
+2026-10-17T17:43:24Z thinkpad: 2.44 2.81 5.40 | macmini (bots): { 56.70 78.37 81.22 }
+2026-10-17T17:43:54Z thinkpad: 1.93 2.65 5.26 | macmini (bots): { 61.56 77.39 80.77 }
+2026-10-17T17:44:24Z thinkpad: 1.96 2.59 5.16 | macmini (bots): { 58.25 75.14 79.83 }
+2026-10-17T17:44:54Z thinkpad: 2.25 2.60 5.08 | macmini (bots): { 56.32 73.21 78.98 }
+2026-10-17T17:45:24Z thinkpad: 1.79 2.46 4.95 | macmini (bots): { 62.87 73.14 78.75 }
+2026-10-17T17:45:55Z thinkpad: 2.78 2.64 4.93 | macmini (bots): { 62.58 72.22 78.23 }
+2026-10-17T17:46:25Z thinkpad: 4.82 3.14 5.03 | macmini (bots): { 58.89 70.44 77.38 }
+2026-10-17T17:46:55Z thinkpad: 3.10 2.90 4.88 | macmini (bots): { 61.68 70.08 77.01 }
+2026-10-17T17:47:25Z thinkpad: 2.27 2.71 4.75 | macmini (bots): { 70.43 71.40 77.25 }
+2026-10-17T17:47:56Z thinkpad: 1.71 2.53 4.62 | macmini (bots): { 70.51 71.56 77.12 }
+2026-10-17T17:48:26Z thinkpad: 1.59 2.42 4.52 | macmini (bots): { 68.98 70.98 76.71 }
+2026-10-17T17:48:56Z thinkpad: 2.09 2.47 4.47 | macmini (bots): { 67.75 70.60 76.38 }
+2026-10-17T17:49:26Z thinkpad: 2.14 2.44 4.39 | macmini (bots): { 61.53 69.01 75.58 }
+2026-10-17T17:49:56Z thinkpad: 2.22 2.43 4.33 | macmini (bots): { 58.49 67.45 74.78 }
+2026-10-17T17:50:27Z thinkpad: 1.98 2.36 4.24 | macmini (bots): { 66.15 68.33 74.84 }
+2026-10-17T17:50:57Z thinkpad: 2.38 2.42 4.20 | macmini (bots): { 61.65 67.22 74.22 }
+2026-10-17T17:51:27Z thinkpad: 3.62 2.72 4.24 | macmini (bots): { 54.05 64.88 73.13 }
+2026-10-17T17:51:57Z thinkpad: 3.25 2.70 4.19 | macmini (bots): { 49.14 62.62 72.02 }
+2026-10-17T17:52:28Z thinkpad: 2.45 2.55 4.09 | macmini (bots): { 43.72 60.06 70.77 }
+2026-10-17T17:52:58Z thinkpad: 2.85 2.62 4.06 | macmini (bots): { 42.53 58.22 69.73 }
+2026-10-17T17:53:28Z thinkpad: 8.44 3.97 4.46 | macmini (bots): { 45.21 57.34 69.01 }
+2026-10-17T17:53:58Z thinkpad: 10.75 4.91 4.76 | macmini (bots): { 44.86 56.01 68.11 }
+2026-10-17T17:54:29Z thinkpad: 8.36 4.90 4.76 | macmini (bots): { 51.73 56.60 67.91 }
+2026-10-17T17:54:59Z thinkpad: 7.41 4.98 4.79 | macmini (bots): { 55.80 57.05 67.67 }
+2026-10-17T17:55:29Z thinkpad: 5.45 4.73 4.71 | macmini (bots): { 50.40 55.67 66.81 }
+2026-10-17T17:55:59Z thinkpad: 6.26 4.97 4.79 | macmini (bots): { 57.22 56.88 66.87 }
+2026-10-17T17:56:30Z thinkpad: 8.22 5.52 4.98 | macmini (bots): { 48.94 54.86 65.78 }
+2026-10-17T17:57:00Z thinkpad: 6.71 5.42 4.96 | macmini (bots): { 50.54 54.70 65.35 }
+2026-10-17T17:57:30Z thinkpad: 4.94 5.14 4.89 | macmini (bots): { 58.02 56.25 65.55 }
+2026-10-17T17:58:01Z thinkpad: 4.54 5.04 4.86 | macmini (bots): { 53.98 55.38 64.90 }
+2026-10-17T17:58:31Z thinkpad: 4.65 5.04 4.87 | macmini (bots): { 49.96 54.23 64.16 }
+2026-10-17T17:59:01Z thinkpad: 5.29 5.16 4.92 | macmini (bots): { 49.63 53.68 63.61 }
+2026-10-17T17:59:31Z thinkpad: 4.23 4.94 4.85 | macmini (bots): { 57.15 55.10 63.78 }
+2026-10-17T18:00:01Z thinkpad: 3.57 4.72 4.78 | macmini (bots): { 61.70 56.26 63.89 }
+2026-10-17T18:00:32Z thinkpad: 3.16 4.52 4.71 | macmini (bots): { 62.10 56.86 63.79 }
+2026-10-17T18:01:02Z thinkpad: 2.81 4.29 4.63 | macmini (bots): { 76.29 60.79 64.98 }
+2026-10-17T18:01:32Z thinkpad: 7.77 5.26 4.93 | macmini (bots): { 75.36 62.16 65.34 }
+2026-10-17T18:02:02Z thinkpad: 11.60 6.45 5.34 | macmini (bots): { 70.83 62.28 65.27 }
+2026-10-17T18:02:33Z thinkpad: 11.54 6.97 5.56 | macmini (bots): { 65.66 61.87 65.01 }
+2026-10-17T18:03:03Z thinkpad: 10.80 7.33 5.73 | macmini (bots): { 63.09 61.54 64.78 }
+2026-10-17T18:03:33Z thinkpad: 10.52 7.56 5.85 | macmini (bots): { 60.31 61.12 64.52 }
+2026-10-17T18:04:04Z thinkpad: 10.27 7.76 5.97 | macmini (bots): { 60.99 61.21 64.44 }
+2026-10-17T18:04:34Z thinkpad: 8.77 7.69 6.01 | macmini (bots): { 56.72 60.19 63.96 }
+2026-10-17T18:05:05Z thinkpad: 5.77 7.06 5.85 | macmini (bots): { 56.14 59.70 63.65 }
+2026-10-17T18:05:35Z thinkpad: 5.16 6.79 5.80 | macmini (bots): { 51.25 58.17 62.95 }
+2026-10-17T18:06:05Z thinkpad: 4.16 6.36 5.69 | macmini (bots): { 52.03 57.64 62.59 }
+2026-10-17T18:06:35Z thinkpad: 4.28 6.18 5.65 | macmini (bots): { 64.66 60.00 63.27 }
+2026-10-17T18:07:06Z thinkpad: 7.47 6.76 5.86 | macmini (bots): { 56.20 58.45 62.59 }
+2026-10-17T18:07:36Z thinkpad: 6.95 6.74 5.89 | macmini (bots): { 51.92 57.20 62.00 }
+2026-10-17T18:08:06Z thinkpad: 7.70 6.99 6.00 | macmini (bots): { 51.14 56.65 61.64 }
+2026-10-17T18:08:36Z thinkpad: 5.83 6.60 5.90 | macmini (bots): { 48.08 55.33 60.98 }
+2026-10-17T18:09:07Z thinkpad: 4.89 6.30 5.82 | macmini (bots): { 53.80 56.00 61.00 }
+2026-10-17T18:09:37Z thinkpad: 4.93 6.19 5.80 | macmini (bots): { 60.49 57.24 61.27 }
+2026-10-17T18:10:07Z thinkpad: 4.61 5.98 5.74 | macmini (bots): { 58.95 57.21 61.12 }
+2026-10-17T18:10:37Z thinkpad: 4.74 5.91 5.73 | macmini (bots): { 60.84 57.65 61.13 }
+2026-10-17T18:11:07Z thinkpad: 3.96 5.61 5.63 | macmini (bots): { 64.23 58.82 61.43 }
+2026-10-17T18:11:38Z thinkpad: 4.16 5.53 5.61 | macmini (bots): { 75.59 62.26 62.60 }
+2026-10-17T18:12:08Z thinkpad: 2.97 5.11 5.46 | macmini (bots): { 75.25 63.65 63.10 }
diff --git a/benchmarks/server-2026-10-17/walk-explore.json b/benchmarks/server-2026-10-17/walk-explore.json
new file mode 100644
index 000000000..a9479f455
--- /dev/null
+++ b/benchmarks/server-2026-10-17/walk-explore.json
@@ -0,0 +1,695 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T17:31:40+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "7bbbf6e97fb53683eae0a01ce2c134e53cb649a7",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon,vanilla",
+ "bots": "1,10,25,50,100",
+ "behaviour": "walk,explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 180,
+ "seed": 12345,
+ "explore_speed": 0,
+ "gamerule": "",
+ "heap": "4g",
+ "out": "/home/ludovic/code/horizon/.claude/worktrees/server-host-4/.local/bench-out/walk-explore.json",
+ "nice": 19,
+ "bots_via": "ssh macmini",
+ "bots_bin": "/Users/ludovicmarie/code/horizon/.claude/worktrees/server-host-4/target/release/horizon-bots",
+ "connect": "",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 9.62,
+ "mspt": {
+ "average": 4.01,
+ "p50": 3.54,
+ "p95": 8.19,
+ "p99": 25.59
+ },
+ "mspt_worst_p99": 47.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 782.52,
+ "max": 785.3
+ },
+ "cpu_percent": 58.87,
+ "chunks_per_second": 9.6,
+ "unique_per_second": 0.43,
+ "forgotten_per_second": 9.65,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 2697,
+ "chunks_per_bot": {
+ "walk": 2697.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 693.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 14.85,
+ "mspt": {
+ "average": 18.22,
+ "p50": 17.99,
+ "p95": 29.34,
+ "p99": 50.06
+ },
+ "mspt_worst_p99": 395.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3429.06,
+ "max": 3446.3
+ },
+ "cpu_percent": 68.81,
+ "chunks_per_second": 10.47,
+ "unique_per_second": 0.47,
+ "forgotten_per_second": 10.53,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 2755,
+ "chunks_per_bot": {
+ "walk": 2755.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 697.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 9.21,
+ "mspt": {
+ "average": 8.79,
+ "p50": 8.05,
+ "p95": 17.35,
+ "p99": 30.47
+ },
+ "mspt_worst_p99": 48.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 781.88,
+ "max": 782.8
+ },
+ "cpu_percent": 119.16,
+ "chunks_per_second": 94.63,
+ "unique_per_second": 3.58,
+ "forgotten_per_second": 94.31,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 26003,
+ "chunks_per_bot": {
+ "walk": 2600.3
+ },
+ "unique_chunks_per_bot": {
+ "walk": 679.9
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 15.14,
+ "mspt": {
+ "average": 18.67,
+ "p50": 15.8,
+ "p95": 38.26,
+ "p99": 55.93
+ },
+ "mspt_worst_p99": 101.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3497.35,
+ "max": 3499.4
+ },
+ "cpu_percent": 100.8,
+ "chunks_per_second": 101.1,
+ "unique_per_second": 4.38,
+ "forgotten_per_second": 101.15,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 26537,
+ "chunks_per_bot": {
+ "walk": 2653.7
+ },
+ "unique_chunks_per_bot": {
+ "walk": 687.5
+ },
+ "resent": 0,
+ "pulled_back": 5,
+ "moved_too_quickly": 5,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 9.82,
+ "mspt": {
+ "average": 15.01,
+ "p50": 13.12,
+ "p95": 31.12,
+ "p99": 50.62
+ },
+ "mspt_worst_p99": 101.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 799.52,
+ "max": 799.7
+ },
+ "cpu_percent": 161.02,
+ "chunks_per_second": 234.3,
+ "unique_per_second": 8.49,
+ "forgotten_per_second": 234.35,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 65926,
+ "chunks_per_bot": {
+ "walk": 2637.04
+ },
+ "unique_chunks_per_bot": {
+ "walk": 683.96
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 14.95,
+ "mspt": {
+ "average": 18.78,
+ "p50": 17.47,
+ "p95": 28.16,
+ "p99": 51.03
+ },
+ "mspt_worst_p99": 107.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3520.17,
+ "max": 3573.8
+ },
+ "cpu_percent": 154.9,
+ "chunks_per_second": 252.39,
+ "unique_per_second": 11.89,
+ "forgotten_per_second": 251.75,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 66469,
+ "chunks_per_bot": {
+ "walk": 2658.76
+ },
+ "unique_chunks_per_bot": {
+ "walk": 689.68
+ },
+ "resent": 0,
+ "pulled_back": 10,
+ "moved_too_quickly": 10,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 9.52,
+ "mspt": {
+ "average": 22.72,
+ "p50": 16.98,
+ "p95": 60.19,
+ "p99": 84.16
+ },
+ "mspt_worst_p99": 105.4,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 813.5,
+ "max": 815.8
+ },
+ "cpu_percent": 179.85,
+ "chunks_per_second": 464.75,
+ "unique_per_second": 16.94,
+ "forgotten_per_second": 464.69,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 134839,
+ "chunks_per_bot": {
+ "walk": 2696.78
+ },
+ "unique_chunks_per_bot": {
+ "walk": 685.48
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 16.36,
+ "mspt": {
+ "average": 34.3,
+ "p50": 31.07,
+ "p95": 55.55,
+ "p99": 92.32
+ },
+ "mspt_worst_p99": 452.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3577.02,
+ "max": 3611.2
+ },
+ "cpu_percent": 267.05,
+ "chunks_per_second": 496.77,
+ "unique_per_second": 26.74,
+ "forgotten_per_second": 496.2,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 133505,
+ "chunks_per_bot": {
+ "walk": 2670.1
+ },
+ "unique_chunks_per_bot": {
+ "walk": 688.8
+ },
+ "resent": 0,
+ "pulled_back": 39,
+ "moved_too_quickly": 39,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 9.51,
+ "mspt": {
+ "average": 63.33,
+ "p50": 58.89,
+ "p95": 125.04,
+ "p99": 175.12
+ },
+ "mspt_worst_p99": 261.5,
+ "tps": 15.79,
+ "rss_mb": {
+ "mean": 868.12,
+ "max": 869.9
+ },
+ "cpu_percent": 245.64,
+ "chunks_per_second": 678.18,
+ "unique_per_second": 31.8,
+ "forgotten_per_second": 676.4,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 219787,
+ "chunks_per_bot": {
+ "walk": 2197.87
+ },
+ "unique_chunks_per_bot": {
+ "walk": 637.91
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 34
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 15.14,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 9.72,
+ "mspt": {
+ "average": 9.73,
+ "p50": 8.75,
+ "p95": 20.99,
+ "p99": 34.17
+ },
+ "mspt_worst_p99": 73.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 836.18,
+ "max": 891.0
+ },
+ "cpu_percent": 329.64,
+ "chunks_per_second": 41.11,
+ "unique_per_second": 35.96,
+ "forgotten_per_second": 41.08,
+ "waited_ticks_per_second": 0.16,
+ "chunks_total": 9460,
+ "chunks_per_bot": {
+ "explore": 9460.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 8479.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 15.54,
+ "mspt": {
+ "average": 9.71,
+ "p50": 7.86,
+ "p95": 20.37,
+ "p99": 76.15
+ },
+ "mspt_worst_p99": 388.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3614.97,
+ "max": 3688.5
+ },
+ "cpu_percent": 247.15,
+ "chunks_per_second": 35.47,
+ "unique_per_second": 33.61,
+ "forgotten_per_second": 35.45,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 7912,
+ "chunks_per_bot": {
+ "explore": 7912.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 7580.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 9.31,
+ "mspt": {
+ "average": 21.27,
+ "p50": 19.5,
+ "p95": 39.15,
+ "p99": 54.23
+ },
+ "mspt_worst_p99": 105.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1177.66,
+ "max": 1392.9
+ },
+ "cpu_percent": 321.97,
+ "chunks_per_second": 46.47,
+ "unique_per_second": 46.11,
+ "forgotten_per_second": 43.12,
+ "waited_ticks_per_second": 111.25,
+ "chunks_total": 14103,
+ "chunks_per_bot": {
+ "explore": 1410.3
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1402.4
+ },
+ "resent": 0,
+ "pulled_back": 9856,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 15.24,
+ "mspt": {
+ "average": 16.94,
+ "p50": 14.24,
+ "p95": 30.28,
+ "p99": 109.7
+ },
+ "mspt_worst_p99": 1861.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3953.29,
+ "max": 4232.0
+ },
+ "cpu_percent": 254.11,
+ "chunks_per_second": 24.99,
+ "unique_per_second": 25.01,
+ "forgotten_per_second": 25.33,
+ "waited_ticks_per_second": 77.93,
+ "chunks_total": 7707,
+ "chunks_per_bot": {
+ "explore": 770.7
+ },
+ "unique_chunks_per_bot": {
+ "explore": 769.5
+ },
+ "resent": 0,
+ "pulled_back": 11123,
+ "moved_too_quickly": 20,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 9.92,
+ "mspt": {
+ "average": 25.76,
+ "p50": 23.58,
+ "p95": 45.01,
+ "p99": 61.43
+ },
+ "mspt_worst_p99": 108.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1172.1,
+ "max": 1482.3
+ },
+ "cpu_percent": 314.47,
+ "chunks_per_second": 61.38,
+ "unique_per_second": 60.7,
+ "forgotten_per_second": 55.11,
+ "waited_ticks_per_second": 304.54,
+ "chunks_total": 24085,
+ "chunks_per_bot": {
+ "explore": 963.4
+ },
+ "unique_chunks_per_bot": {
+ "explore": 954.76
+ },
+ "resent": 0,
+ "pulled_back": 31264,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 15.76,
+ "mspt": {
+ "average": 24.93,
+ "p50": 22.04,
+ "p95": 37.09,
+ "p99": 168.46
+ },
+ "mspt_worst_p99": 1724.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 4040.42,
+ "max": 4447.6
+ },
+ "cpu_percent": 305.47,
+ "chunks_per_second": 37.91,
+ "unique_per_second": 37.84,
+ "forgotten_per_second": 38.39,
+ "waited_ticks_per_second": 258.66,
+ "chunks_total": 16865,
+ "chunks_per_bot": {
+ "explore": 674.6
+ },
+ "unique_chunks_per_bot": {
+ "explore": 671.28
+ },
+ "resent": 0,
+ "pulled_back": 33467,
+ "moved_too_quickly": 23,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 9.41,
+ "mspt": {
+ "average": 39.31,
+ "p50": 36.98,
+ "p95": 65.33,
+ "p99": 88.36
+ },
+ "mspt_worst_p99": 157.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1250.32,
+ "max": 1517.1
+ },
+ "cpu_percent": 324.77,
+ "chunks_per_second": 114.99,
+ "unique_per_second": 112.25,
+ "forgotten_per_second": 104.41,
+ "waited_ticks_per_second": 543.77,
+ "chunks_total": 50402,
+ "chunks_per_bot": {
+ "explore": 1008.04
+ },
+ "unique_chunks_per_bot": {
+ "explore": 997.42
+ },
+ "resent": 0,
+ "pulled_back": 64163,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 14.55,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 9.31,
+ "mspt": {
+ "average": 52.7,
+ "p50": 49.49,
+ "p95": 85.73,
+ "p99": 115.34
+ },
+ "mspt_worst_p99": 219.0,
+ "tps": 18.97,
+ "rss_mb": {
+ "mean": 1358.32,
+ "max": 3047.2
+ },
+ "cpu_percent": 327.95,
+ "chunks_per_second": 154.2,
+ "unique_per_second": 151.83,
+ "forgotten_per_second": 141.65,
+ "waited_ticks_per_second": 1132.9,
+ "chunks_total": 84433,
+ "chunks_per_bot": {
+ "explore": 844.33
+ },
+ "unique_chunks_per_bot": {
+ "explore": 839.47
+ },
+ "resent": 0,
+ "pulled_back": 116161,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 35
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 16.47,
+ "error": "[Errno 32] Broken pipe"
+ }
+ ]
+}
diff --git a/benchmarks/server-equal-work-2026-10-17/README.md b/benchmarks/server-equal-work-2026-10-17/README.md
new file mode 100644
index 000000000..737b05858
--- /dev/null
+++ b/benchmarks/server-equal-work-2026-10-17/README.md
@@ -0,0 +1,168 @@
+# Horizon's server against vanilla 26.3, equal work (2026-10-17)
+
+The same bots on Horizon's dedicated server and on vanilla 26.3's, one server at a time, on the same
+machine, with the work each server does made the same before the numbers are compared. This replaces the
+first run in docs/server.md section 9, where the work wasn't equal.
+
+## What was made equal
+
+The first run (PR #556) had three differences that made the comparison unfair. Each is fixed in the code
+that ran here:
+
+- **Refused moves.** Vanilla pulls a player back when a move is too fast ("moved too quickly") or ends
+ inside a block ("moved wrongly"). Horizon now runs both checks the way vanilla does (PR #586), so a bot
+ that flies too fast is pulled back on both servers.
+- **Chunk sending.** Vanilla paces chunks by the client's acknowledgements (PlayerChunkSender: one
+ unacknowledged batch at first, then ten, each at most the client's desired chunks per tick). Horizon used
+ to send twice as many per batch; it now paces them the same way (PR #586), and the bots acknowledge
+ batches and ask for a rate the way vanilla's client does, so both servers send at the pace the client
+ asks for. Chunks sent again while the bot still held
+ them (`resent`) are counted: 0 on both servers in every run.
+- **Movement gated on chunks.** A bot doesn't move while the chunk it stands in hasn't arrived (vanilla's
+ client waits the same way), so a slower server isn't asked to teleport bots into terrain it hasn't sent.
+
+One difference isn't in Horizon yet: vanilla 26.3's locator bar (waypoints), which costs vanilla O(players²)
+work per move. Every vanilla run here sets `gamerule locator_bar false`, so neither server does it.
+
+## Method
+
+`tools/server_bench.py` runs each configuration on a fresh server:
+
+- the same `server.properties` on both (seed 12345, view and simulation distance 10, offline, creative,
+ difficulty easy, `sync-chunk-writes=true`), and `gamerule respawn_radius 0`;
+- the server waits for `Done`, the bots join one a second, a 60-second warm-up, then 300 seconds of
+ measurement;
+- MSPT (average, P50, P95, P99) comes from each server's own `/tick query`, asked every 5 seconds on the
+ console, so both measure themselves the same way (vanilla's ServerTickRateManager numbers, which Horizon
+ reproduces); TPS is 20 while the average fits in 50 ms, else 1000 / MSPT;
+- RSS and CPU are the server's whole process tree, once a second (100 % is one core);
+- chunk counts come from the bots: chunks received per second, chunks no bot had before (new terrain), and
+ pull-backs (position packets that move a bot back).
+
+The bots are `horizon-bots` (creative, flying 24 blocks above spawn, 20 moves a second):
+
+- `walk`: flies to random points within 48 blocks of spawn at sprint speed (5.6 blocks a second);
+- `explore`: flies straight outwards, by default at about 22 blocks a second, as fast as the server sends
+ chunks.
+
+Machine: the ThinkPad (Intel Core i7-7500U, 2 cores / 4 threads, 32 GB, NixOS), servers under `nice -n 19`
+because it also runs other services; vanilla on OpenJDK 25.0.4.1 with a 4 GB heap (`-Xms4g -Xmx4g`). The
+bots ran on the Mac mini and reached the ThinkPad over the tailnet, so they took none of the server's CPU.
+
+What ran: Horizon from `origin/main` at bf851bfe with #586 (move checks and chunk pacing), the bots and
+`server_bench.py` from this PR, #623 (sections encoded once, its first commit) and #649 (a tick's packets
+handed to each connection together). The ThinkPad copy wasn't a git checkout, so the JSON reports have an
+empty `commit`. Vanilla: the pinned 26.3 server jar.
+
+## Results
+
+MSPT is the average milliseconds per tick (50 is the limit for 20 TPS); P95 is the 95th percentile. CPU is
+the whole process tree. "New chunks/s" are chunks no bot had before.
+
+### Walk (the same work on both servers)
+
+| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s |
+|---:|---|---:|---:|---:|---:|---:|---:|---:|
+| 1 | Horizon | 5.5 | 12.1 | 20.0 | 1.37 GB | 57 % | 9 | 0.3 |
+| 1 | Vanilla | 18.3 | 27.3 | 20.0 | 3.35 GB | 66 % | 10 | 0.3 |
+| 10 | Horizon | 11.5 | 22.1 | 20.0 | 1.41 GB | 124 % | 94 | 2.4 |
+| 10 | Vanilla | 16.8 | 30.5 | 20.0 | 3.41 GB | 84 % | 100 | 2.8 |
+| 25 | Horizon | 20.7 | 40.4 | 20.0 | 1.45 GB | 170 % | 236 | 5.7 |
+| 25 | Vanilla | 16.0 | 26.4 | 20.0 | 3.47 GB | 115 % | 252 | 6.7 |
+| 50 | Horizon | 31.4 | 79.0 | 20.0 | 1.52 GB | 173 % | 451 | 10.3 |
+| 50 | Vanilla | 20.5 | 29.7 | 20.0 | 3.55 GB | 194 % | 502 | 12.2 |
+| 100 | Horizon | 114.5 | 256.2 | 8.7 | 1.33 GB | 181 % | 484 | 30.8 |
+| 100 | Vanilla | stopped by its watchdog | | | | | | |
+
+Both servers sent the same chunks (about 10 a second per bot, the churn of flying around) and sent none
+twice. Vanilla pulled back a few bots for moving too quickly when a tick ran long (5 to 33 per run);
+Horizon none. At 100 bots vanilla's watchdog stopped the server (a tick ran over 60 s, in
+`ChunkMap$TrackedEntity.updatePlayer`); Horizon kept running at 8.7 TPS.
+
+### Explore at a rate both servers keep up with (equal work)
+
+The bots fly outwards at 0.8 blocks a second (`--explore-speed 0.8`), slow enough that neither server makes
+them wait for terrain, so both generate and send the same new chunks.
+
+| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s |
+|---:|---|---:|---:|---:|---:|---:|---:|---:|
+| 1 | Horizon | 4.0 | 6.6 | 20.0 | 1.36 GB | 25 % | 2 | 1.3 |
+| 1 | Vanilla | 18.1 | 27.1 | 20.0 | 3.32 GB | 73 % | 2 | 1.4 |
+| 10 | Horizon | 13.5 | 24.8 | 20.0 | 1.64 GB | 89 % | 13 | 11.8 |
+| 10 | Vanilla | 29.2 | 43.0 | 20.0 | 3.52 GB | 143 % | 13 | 11.9 |
+| 25 | Horizon | 20.2 | 36.8 | 20.0 | 1.74 GB | 121 % | 32 | 28.9 |
+| 25 | Vanilla | 37.0 | 49.4 | 20.0 | 3.73 GB | 169 % | 32 | 28.9 |
+
+### Explore as fast as each server sends chunks (not equal work)
+
+The default 22 blocks a second is faster than either server can generate, so each server sets the pace and
+a faster server is given more work: from 10 bots Horizon generated 1.5 to 2 times vanilla's new chunks a
+second. Read it as throughput, not as a like-for-like tick time.
+
+| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s |
+|---:|---|---:|---:|---:|---:|---:|---:|---:|
+| 1 | Horizon | 10.6 | 24.6 | 20.0 | 1.34 GB | 322 % | 39 | 34.6 |
+| 1 | Vanilla | 9.9 | 21.3 | 20.0 | 3.48 GB | 245 % | 36 | 33.4 |
+| 10 | Horizon | 30.4 | 52.3 | 20.0 | 2.18 GB | 345 % | 47 | 46.7 |
+| 10 | Vanilla | 17.0 | 29.6 | 20.0 | 4.04 GB | 242 % | 22 | 22.4 |
+| 25 | Horizon | 50.7 | 89.3 | 19.7 | 2.30 GB | 286 % | 50 | 49.7 |
+| 25 | Vanilla | 24.2 | 36.5 | 20.0 | 4.40 GB | 320 % | 34 | 33.7 |
+| 50 | Horizon | 50.7 | 102.7 | 19.7 | 1.72 GB | 213 % | 97 | 96.5 |
+| 50 | Vanilla | stopped by its watchdog | | | | | | |
+| 100 | Horizon | 92.9 | 139.6 | 10.8 | 1.70 GB | 322 % | 114 | 113.6 |
+| 100 | Vanilla | stopped by its watchdog | | | | | | |
+
+Vanilla's watchdog stopped it at 50 bots (in `ClientboundLightUpdatePacketData`, copying light for a chunk
+packet) and at 100 (in `Entity.move` from a move packet).
+
+## Findings
+
+- Horizon's RSS is 1.9 to 2.6 times smaller in every run, and it starts in 11 s against vanilla's 15 s.
+ Vanilla's heap is fixed at 4 GB (`-Xms4g`), so part of its RSS is that setting rather than need.
+- With 1 bot Horizon's tick is 3.3 times shorter walking and 4.5 times shorter exploring at equal work;
+ at 10 bots it is still shorter in both.
+- At equal exploring work Horizon's tick is about half of vanilla's at 10 and 25 bots.
+- When the bots only fly around spawn (`walk`), vanilla's tick hardly grows with players (16 to 20 ms from
+ 1 to 50 bots) while Horizon's grows by about 0.5 ms per bot, so vanilla is ahead from about 20 bots: 16.0
+ against 20.7 ms at 25 and 20.5 against 31.4 ms at 50. Both keep 20 TPS up to 50.
+- With 100 bots vanilla's watchdog stops it in every pass, and Horizon keeps running at 9 to 11 TPS.
+
+### Where Horizon's walk tick goes at 25 bots
+
+Profiled on the ThinkPad with `perf` (the server thread, 20 s, self time):
+
+| Share | What | Whose |
+|---:|---|---|
+| 18 % | `Streaming::update`: every tick it walks all loaded columns and proto chunks and tests each against every player's area (unloading, dropping protos, finishing and decoration candidates), so the cost grows with players times chunks | streaming / engine tick |
+| 20 % | `PalettedContainer::get` and `World::block`, mostly from block entity ticks: on the Mac profile `tick_hoppers` looks up the block under every block entity in the loaded world each tick and compares names as strings, and spawners rebuild their display id | engine tick |
+| 8 % | `light_data` when a chunk is sent: the light layers were built twice per chunk; a follow-up commit on #623 builds them once and keeps each section's packed layers | server (this work) |
+| 7 % | encoding chunk sections and heightmaps for the chunks each bot newly sees | server |
+| 4 % | `Hub::tick` (moves, tracking) | server |
+| 2 % | the moved-wrongly collision check | server |
+
+The first two grow with the number of players but aren't specific to the server: they are the
+engine's tick and streaming, reported to perf-server-2. Before #623 and #649, encoding every chunk section
+once per player and waking each connection's writer thread once per packet cost more than everything above
+(at 50 walking bots the tick was 281 ms; see the earlier runs).
+
+## Earlier runs (same machine and method)
+
+- `run-1-before-chunk-cache.json`: before #623, with vanilla's locator bar on. Horizon's walk tick was
+ 27.5, 40.7, 281 and 467 ms at 10, 25, 50 and 100 bots, and vanilla's 33.2 ms at 50 (the locator bar).
+- `run-2-chunk-cache.json`: Horizon with #623 only: 13.2, 23.5, 31.4 and 84.4 ms walking at 10 to 100
+ bots.
+
+## Files
+
+- `horizon.json`, `vanilla.json`: the walk and explore passes (vanilla with `locator_bar=false`).
+- `explore-equal-rate.json`: the explore pass at 0.8 blocks a second, both servers.
+- `run-1-before-chunk-cache.json`, `run-2-chunk-cache.json`: the earlier runs.
+
+To run it again (bots on another machine reached at `--connect`):
+
+ cargo build --release -p horizon-client --bin horizon-client -p horizon-server -p horizon-bots
+ python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25,50,100 --behaviour walk,explore \
+ --gamerule locator_bar=false --nice 19 --bots-via 'ssh macmini' --bots-bin /path/to/horizon-bots \
+ --connect --out results.json
+ python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25 --behaviour explore \
+ --explore-speed 0.8 --gamerule locator_bar=false --nice 19 ... --out explore-equal-rate.json
diff --git a/benchmarks/server-equal-work-2026-10-17/explore-equal-rate.json b/benchmarks/server-equal-work-2026-10-17/explore-equal-rate.json
new file mode 100644
index 000000000..bd097e43a
--- /dev/null
+++ b/benchmarks/server-equal-work-2026-10-17/explore-equal-rate.json
@@ -0,0 +1,267 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T05:47:12+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon,vanilla",
+ "bots": "1,10,25",
+ "behaviour": "explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 300,
+ "seed": 12345,
+ "explore_speed": 0.8,
+ "gamerule": "locator_bar=false",
+ "heap": "4g",
+ "out": "/home/ludovic/scratch/sh2-bench5.json",
+ "nice": 19,
+ "bots_via": "ssh -o BatchMode=yes macmini",
+ "bots_bin": "/tmp/sh2-horizon-bots",
+ "connect": "100.72.51.8",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 10.91,
+ "mspt": {
+ "average": 4.02,
+ "p50": 3.75,
+ "p95": 6.63,
+ "p99": 14.55
+ },
+ "mspt_worst_p99": 63.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1392.42,
+ "max": 1746.1
+ },
+ "cpu_percent": 24.52,
+ "chunks_per_second": 1.69,
+ "unique_per_second": 1.34,
+ "forgotten_per_second": 1.62,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 1048,
+ "chunks_per_bot": {
+ "explore": 1048.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 952.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 15.13,
+ "mspt": {
+ "average": 18.12,
+ "p50": 18.78,
+ "p95": 27.07,
+ "p99": 60.81
+ },
+ "mspt_worst_p99": 1397.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3397.31,
+ "max": 3430.2
+ },
+ "cpu_percent": 72.99,
+ "chunks_per_second": 1.69,
+ "unique_per_second": 1.38,
+ "forgotten_per_second": 1.62,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 1048,
+ "chunks_per_bot": {
+ "explore": 1048.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 952.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 11.12,
+ "mspt": {
+ "average": 13.49,
+ "p50": 12.09,
+ "p95": 24.81,
+ "p99": 40.9
+ },
+ "mspt_worst_p99": 101.4,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1684.04,
+ "max": 2660.6
+ },
+ "cpu_percent": 89.04,
+ "chunks_per_second": 13.08,
+ "unique_per_second": 11.84,
+ "forgotten_per_second": 13.02,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 9277,
+ "chunks_per_bot": {
+ "explore": 927.7
+ },
+ "unique_chunks_per_bot": {
+ "explore": 889.9
+ },
+ "resent": 0,
+ "pulled_back": 3381,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 14.84,
+ "mspt": {
+ "average": 29.18,
+ "p50": 26.76,
+ "p95": 43.02,
+ "p99": 80.16
+ },
+ "mspt_worst_p99": 425.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3609.51,
+ "max": 3791.6
+ },
+ "cpu_percent": 142.79,
+ "chunks_per_second": 13.1,
+ "unique_per_second": 11.88,
+ "forgotten_per_second": 13.12,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 9245,
+ "chunks_per_bot": {
+ "explore": 924.5
+ },
+ "unique_chunks_per_bot": {
+ "explore": 885.3
+ },
+ "resent": 0,
+ "pulled_back": 3388,
+ "moved_too_quickly": 6,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 11.02,
+ "mspt": {
+ "average": 20.25,
+ "p50": 18.73,
+ "p95": 36.78,
+ "p99": 55.76
+ },
+ "mspt_worst_p99": 92.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1782.26,
+ "max": 2741.9
+ },
+ "cpu_percent": 120.8,
+ "chunks_per_second": 32.22,
+ "unique_per_second": 28.89,
+ "forgotten_per_second": 32.19,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 23357,
+ "chunks_per_bot": {
+ "explore": 934.28
+ },
+ "unique_chunks_per_bot": {
+ "explore": 890.32
+ },
+ "resent": 0,
+ "pulled_back": 11580,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 14.54,
+ "mspt": {
+ "average": 37.04,
+ "p50": 34.77,
+ "p95": 49.42,
+ "p99": 101.67
+ },
+ "mspt_worst_p99": 735.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3815.46,
+ "max": 4202.0
+ },
+ "cpu_percent": 169.15,
+ "chunks_per_second": 32.34,
+ "unique_per_second": 28.93,
+ "forgotten_per_second": 32.31,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 23306,
+ "chunks_per_bot": {
+ "explore": 932.24
+ },
+ "unique_chunks_per_bot": {
+ "explore": 886.96
+ },
+ "resent": 0,
+ "pulled_back": 11539,
+ "moved_too_quickly": 6,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 59
+ }
+ ]
+}
diff --git a/benchmarks/server-equal-work-2026-10-17/horizon.json b/benchmarks/server-equal-work-2026-10-17/horizon.json
new file mode 100644
index 000000000..d0b162c44
--- /dev/null
+++ b/benchmarks/server-equal-work-2026-10-17/horizon.json
@@ -0,0 +1,415 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T05:04:57+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon",
+ "bots": "1,10,25,50,100",
+ "behaviour": "walk,explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 300,
+ "seed": 12345,
+ "explore_speed": 0,
+ "gamerule": "locator_bar=false",
+ "heap": "4g",
+ "out": "/home/ludovic/scratch/sh2-bench4.json",
+ "nice": 19,
+ "bots_via": "ssh -o BatchMode=yes macmini",
+ "bots_bin": "/tmp/sh2-horizon-bots",
+ "connect": "100.72.51.8",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 11.02,
+ "mspt": {
+ "average": 5.45,
+ "p50": 4.63,
+ "p95": 12.14,
+ "p99": 30.63
+ },
+ "mspt_worst_p99": 91.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1398.5,
+ "max": 1708.4
+ },
+ "cpu_percent": 57.03,
+ "chunks_per_second": 9.17,
+ "unique_per_second": 0.26,
+ "forgotten_per_second": 9.2,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 3708,
+ "chunks_per_bot": {
+ "walk": 3708.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 694.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 11.02,
+ "mspt": {
+ "average": 11.51,
+ "p50": 10.6,
+ "p95": 22.13,
+ "p99": 36.92
+ },
+ "mspt_worst_p99": 71.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1440.2,
+ "max": 1832.4
+ },
+ "cpu_percent": 124.19,
+ "chunks_per_second": 94.04,
+ "unique_per_second": 2.38,
+ "forgotten_per_second": 93.95,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 37269,
+ "chunks_per_bot": {
+ "walk": 3726.9
+ },
+ "unique_chunks_per_bot": {
+ "walk": 688.9
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 10.91,
+ "mspt": {
+ "average": 20.74,
+ "p50": 19.27,
+ "p95": 40.42,
+ "p99": 57.12
+ },
+ "mspt_worst_p99": 102.0,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1485.4,
+ "max": 1871.9
+ },
+ "cpu_percent": 169.52,
+ "chunks_per_second": 235.81,
+ "unique_per_second": 5.68,
+ "forgotten_per_second": 235.83,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 94456,
+ "chunks_per_bot": {
+ "walk": 3778.24
+ },
+ "unique_chunks_per_bot": {
+ "walk": 692.96
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 11.12,
+ "mspt": {
+ "average": 31.41,
+ "p50": 25.39,
+ "p95": 78.97,
+ "p99": 110.73
+ },
+ "mspt_worst_p99": 192.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1558.34,
+ "max": 1915.3
+ },
+ "cpu_percent": 173.27,
+ "chunks_per_second": 450.85,
+ "unique_per_second": 10.3,
+ "forgotten_per_second": 451.86,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 186885,
+ "chunks_per_bot": {
+ "walk": 3737.7
+ },
+ "unique_chunks_per_bot": {
+ "walk": 688.9
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 18.16,
+ "mspt": {
+ "average": 114.55,
+ "p50": 101.37,
+ "p95": 256.19,
+ "p99": 338.64
+ },
+ "mspt_worst_p99": 442.6,
+ "tps": 8.73,
+ "rss_mb": {
+ "mean": 1357.65,
+ "max": 1358.4
+ },
+ "cpu_percent": 181.21,
+ "chunks_per_second": 484.16,
+ "unique_per_second": 30.76,
+ "forgotten_per_second": 478.77,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 212947,
+ "chunks_per_bot": {
+ "walk": 2129.47
+ },
+ "unique_chunks_per_bot": {
+ "walk": 583.02
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 57
+ },
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 17.45,
+ "mspt": {
+ "average": 10.62,
+ "p50": 9.2,
+ "p95": 24.61,
+ "p99": 38.18
+ },
+ "mspt_worst_p99": 81.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1372.73,
+ "max": 1568.7
+ },
+ "cpu_percent": 322.38,
+ "chunks_per_second": 39.21,
+ "unique_per_second": 34.6,
+ "forgotten_per_second": 38.55,
+ "waited_ticks_per_second": 0.51,
+ "chunks_total": 12549,
+ "chunks_per_bot": {
+ "explore": 12549.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 11168.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 11.32,
+ "mspt": {
+ "average": 30.38,
+ "p50": 27.84,
+ "p95": 52.31,
+ "p99": 77.89
+ },
+ "mspt_worst_p99": 158.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 2231.56,
+ "max": 4022.6
+ },
+ "cpu_percent": 344.99,
+ "chunks_per_second": 47.34,
+ "unique_per_second": 46.73,
+ "forgotten_per_second": 44.57,
+ "waited_ticks_per_second": 112.27,
+ "chunks_total": 19870,
+ "chunks_per_bot": {
+ "explore": 1987.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1966.5
+ },
+ "resent": 0,
+ "pulled_back": 16130,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 11.42,
+ "mspt": {
+ "average": 50.67,
+ "p50": 47.61,
+ "p95": 89.3,
+ "p99": 119.15
+ },
+ "mspt_worst_p99": 222.3,
+ "tps": 19.73,
+ "rss_mb": {
+ "mean": 2358.4,
+ "max": 4273.7
+ },
+ "cpu_percent": 286.32,
+ "chunks_per_second": 50.39,
+ "unique_per_second": 49.67,
+ "forgotten_per_second": 47.45,
+ "waited_ticks_per_second": 311.85,
+ "chunks_total": 28954,
+ "chunks_per_bot": {
+ "explore": 1158.16
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1147.56
+ },
+ "resent": 0,
+ "pulled_back": 36319,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 20.06,
+ "mspt": {
+ "average": 50.69,
+ "p50": 47.48,
+ "p95": 102.67,
+ "p99": 133.27
+ },
+ "mspt_worst_p99": 274.4,
+ "tps": 19.73,
+ "rss_mb": {
+ "mean": 1764.01,
+ "max": 2542.0
+ },
+ "cpu_percent": 212.83,
+ "chunks_per_second": 97.33,
+ "unique_per_second": 96.47,
+ "forgotten_per_second": 76.74,
+ "waited_ticks_per_second": 750.49,
+ "chunks_total": 38538,
+ "chunks_per_bot": {
+ "explore": 770.76
+ },
+ "unique_chunks_per_bot": {
+ "explore": 763.84
+ },
+ "resent": 0,
+ "pulled_back": 39880,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 11.82,
+ "mspt": {
+ "average": 92.93,
+ "p50": 87.84,
+ "p95": 139.6,
+ "p99": 178.38
+ },
+ "mspt_worst_p99": 272.9,
+ "tps": 10.76,
+ "rss_mb": {
+ "mean": 1736.38,
+ "max": 1855.7
+ },
+ "cpu_percent": 321.53,
+ "chunks_per_second": 113.89,
+ "unique_per_second": 113.56,
+ "forgotten_per_second": 101.68,
+ "waited_ticks_per_second": 1179.4,
+ "chunks_total": 84617,
+ "chunks_per_bot": {
+ "explore": 846.17
+ },
+ "unique_chunks_per_bot": {
+ "explore": 845.01
+ },
+ "resent": 0,
+ "pulled_back": 128104,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 58
+ }
+ ]
+}
diff --git a/benchmarks/server-equal-work-2026-10-17/run-1-before-chunk-cache.json b/benchmarks/server-equal-work-2026-10-17/run-1-before-chunk-cache.json
new file mode 100644
index 000000000..d79b3f179
--- /dev/null
+++ b/benchmarks/server-equal-work-2026-10-17/run-1-before-chunk-cache.json
@@ -0,0 +1,693 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T00:37:35+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon,vanilla",
+ "bots": "1,10,25,50,100",
+ "behaviour": "walk,explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 300,
+ "seed": 12345,
+ "heap": "4g",
+ "out": "/home/ludovic/scratch/sh2-bench.json",
+ "nice": 19,
+ "bots_via": "ssh -o BatchMode=yes macmini",
+ "bots_bin": "/tmp/sh2-horizon-bots",
+ "connect": "100.72.51.8",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 11.12,
+ "mspt": {
+ "average": 7.63,
+ "p50": 5.51,
+ "p95": 17.46,
+ "p99": 36.79
+ },
+ "mspt_worst_p99": 79.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1391.94,
+ "max": 1700.7
+ },
+ "cpu_percent": 60.18,
+ "chunks_per_second": 9.15,
+ "unique_per_second": 0.29,
+ "forgotten_per_second": 9.18,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 3682,
+ "chunks_per_bot": {
+ "walk": 3682.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 692.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 15.35,
+ "mspt": {
+ "average": 18.08,
+ "p50": 18.66,
+ "p95": 28.05,
+ "p99": 46.94
+ },
+ "mspt_worst_p99": 456.4,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3455.72,
+ "max": 3471.7
+ },
+ "cpu_percent": 65.67,
+ "chunks_per_second": 9.89,
+ "unique_per_second": 0.29,
+ "forgotten_per_second": 9.92,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 3827,
+ "chunks_per_bot": {
+ "walk": 3827.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 699.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 11.22,
+ "mspt": {
+ "average": 27.53,
+ "p50": 24.93,
+ "p95": 53.93,
+ "p99": 77.03
+ },
+ "mspt_worst_p99": 111.4,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1433.85,
+ "max": 1831.9
+ },
+ "cpu_percent": 138.65,
+ "chunks_per_second": 95.98,
+ "unique_per_second": 2.38,
+ "forgotten_per_second": 95.78,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 38041,
+ "chunks_per_bot": {
+ "walk": 3804.1
+ },
+ "unique_chunks_per_bot": {
+ "walk": 690.8
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 14.83,
+ "mspt": {
+ "average": 18.92,
+ "p50": 16.02,
+ "p95": 39.0,
+ "p99": 56.13
+ },
+ "mspt_worst_p99": 180.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3479.45,
+ "max": 3535.7
+ },
+ "cpu_percent": 99.39,
+ "chunks_per_second": 99.93,
+ "unique_per_second": 2.94,
+ "forgotten_per_second": 100.04,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 38411,
+ "chunks_per_bot": {
+ "walk": 3841.1
+ },
+ "unique_chunks_per_bot": {
+ "walk": 697.1
+ },
+ "resent": 0,
+ "pulled_back": 7,
+ "moved_too_quickly": 7,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 11.52,
+ "mspt": {
+ "average": 40.69,
+ "p50": 37.28,
+ "p95": 81.16,
+ "p99": 108.42
+ },
+ "mspt_worst_p99": 149.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1444.12,
+ "max": 1882.6
+ },
+ "cpu_percent": 176.94,
+ "chunks_per_second": 244.11,
+ "unique_per_second": 6.51,
+ "forgotten_per_second": 243.96,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 95219,
+ "chunks_per_bot": {
+ "walk": 3808.76
+ },
+ "unique_chunks_per_bot": {
+ "walk": 695.64
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 15.23,
+ "mspt": {
+ "average": 18.81,
+ "p50": 17.26,
+ "p95": 30.16,
+ "p99": 53.9
+ },
+ "mspt_worst_p99": 390.0,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3517.36,
+ "max": 3555.7
+ },
+ "cpu_percent": 148.52,
+ "chunks_per_second": 252.34,
+ "unique_per_second": 7.75,
+ "forgotten_per_second": 251.95,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 96645,
+ "chunks_per_bot": {
+ "walk": 3865.8
+ },
+ "unique_chunks_per_bot": {
+ "walk": 698.4
+ },
+ "resent": 0,
+ "pulled_back": 11,
+ "moved_too_quickly": 11,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 12.72,
+ "mspt": {
+ "average": 281.42,
+ "p50": 278.28,
+ "p95": 343.64,
+ "p99": 384.23
+ },
+ "mspt_worst_p99": 475.1,
+ "tps": 3.55,
+ "rss_mb": {
+ "mean": 1334.32,
+ "max": 1335.4
+ },
+ "cpu_percent": 197.11,
+ "chunks_per_second": 391.5,
+ "unique_per_second": 21.24,
+ "forgotten_per_second": 388.33,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 153136,
+ "chunks_per_bot": {
+ "walk": 3062.72
+ },
+ "unique_chunks_per_bot": {
+ "walk": 661.82
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 57
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 15.74,
+ "mspt": {
+ "average": 33.21,
+ "p50": 29.9,
+ "p95": 53.37,
+ "p99": 109.14
+ },
+ "mspt_worst_p99": 833.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3568.07,
+ "max": 3594.9
+ },
+ "cpu_percent": 266.59,
+ "chunks_per_second": 496.3,
+ "unique_per_second": 18.64,
+ "forgotten_per_second": 495.77,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 191965,
+ "chunks_per_bot": {
+ "walk": 3839.3
+ },
+ "unique_chunks_per_bot": {
+ "walk": 696.22
+ },
+ "resent": 0,
+ "pulled_back": 184,
+ "moved_too_quickly": 183,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 11.22,
+ "mspt": {
+ "average": 467.37,
+ "p50": 464.62,
+ "p95": 524.07,
+ "p99": 548.77
+ },
+ "mspt_worst_p99": 581.1,
+ "tps": 2.14,
+ "rss_mb": {
+ "mean": 1353.68,
+ "max": 1354.9
+ },
+ "cpu_percent": 191.96,
+ "chunks_per_second": 377.62,
+ "unique_per_second": 55.8,
+ "forgotten_per_second": 348.88,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 165719,
+ "chunks_per_bot": {
+ "walk": 1657.19
+ },
+ "unique_chunks_per_bot": {
+ "walk": 549.8
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 56
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 14.84,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 11.12,
+ "mspt": {
+ "average": 17.07,
+ "p50": 16.6,
+ "p95": 32.82,
+ "p99": 50.3
+ },
+ "mspt_worst_p99": 113.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1391.72,
+ "max": 1566.6
+ },
+ "cpu_percent": 333.8,
+ "chunks_per_second": 39.42,
+ "unique_per_second": 34.77,
+ "forgotten_per_second": 39.34,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 13860,
+ "chunks_per_bot": {
+ "explore": 13860.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 12379.0
+ },
+ "resent": 0,
+ "pulled_back": 192,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 16.03,
+ "mspt": {
+ "average": 9.9,
+ "p50": 8.04,
+ "p95": 20.41,
+ "p99": 63.62
+ },
+ "mspt_worst_p99": 351.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3709.92,
+ "max": 3776.2
+ },
+ "cpu_percent": 246.64,
+ "chunks_per_second": 36.06,
+ "unique_per_second": 33.33,
+ "forgotten_per_second": 35.73,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 12369,
+ "chunks_per_bot": {
+ "explore": 12369.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 11559.0
+ },
+ "resent": 0,
+ "pulled_back": 222,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 11.42,
+ "mspt": {
+ "average": 33.72,
+ "p50": 31.08,
+ "p95": 61.07,
+ "p99": 89.09
+ },
+ "mspt_worst_p99": 142.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 2239.97,
+ "max": 4108.8
+ },
+ "cpu_percent": 350.83,
+ "chunks_per_second": 46.49,
+ "unique_per_second": 46.08,
+ "forgotten_per_second": 44.33,
+ "waited_ticks_per_second": 111.28,
+ "chunks_total": 19915,
+ "chunks_per_bot": {
+ "explore": 1991.5
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1974.4
+ },
+ "resent": 0,
+ "pulled_back": 17516,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 15.15,
+ "mspt": {
+ "average": 16.25,
+ "p50": 13.67,
+ "p95": 28.92,
+ "p99": 115.9
+ },
+ "mspt_worst_p99": 1202.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 4202.72,
+ "max": 4502.7
+ },
+ "cpu_percent": 247.47,
+ "chunks_per_second": 22.3,
+ "unique_per_second": 22.25,
+ "forgotten_per_second": 22.64,
+ "waited_ticks_per_second": 78.89,
+ "chunks_total": 10092,
+ "chunks_per_bot": {
+ "explore": 1009.2
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1007.4
+ },
+ "resent": 0,
+ "pulled_back": 16286,
+ "moved_too_quickly": 12,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 11.82,
+ "mspt": {
+ "average": 48.03,
+ "p50": 44.99,
+ "p95": 83.06,
+ "p99": 109.63
+ },
+ "mspt_worst_p99": 191.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 2214.16,
+ "max": 4598.6
+ },
+ "cpu_percent": 356.03,
+ "chunks_per_second": 64.2,
+ "unique_per_second": 63.5,
+ "forgotten_per_second": 60.9,
+ "waited_ticks_per_second": 301.65,
+ "chunks_total": 32247,
+ "chunks_per_bot": {
+ "explore": 1289.88
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1279.4
+ },
+ "resent": 0,
+ "pulled_back": 42159,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 14.73,
+ "mspt": {
+ "average": 25.73,
+ "p50": 22.75,
+ "p95": 37.72,
+ "p99": 201.98
+ },
+ "mspt_worst_p99": 4051.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 4355.9,
+ "max": 4983.2
+ },
+ "cpu_percent": 309.3,
+ "chunks_per_second": 33.33,
+ "unique_per_second": 33.21,
+ "forgotten_per_second": 34.22,
+ "waited_ticks_per_second": 258.68,
+ "chunks_total": 19426,
+ "chunks_per_bot": {
+ "explore": 777.04
+ },
+ "unique_chunks_per_bot": {
+ "explore": 772.92
+ },
+ "resent": 0,
+ "pulled_back": 53918,
+ "moved_too_quickly": 93,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 11.01,
+ "mspt": {
+ "average": 108.61,
+ "p50": 107.37,
+ "p95": 151.96,
+ "p99": 177.41
+ },
+ "mspt_worst_p99": 271.6,
+ "tps": 9.21,
+ "rss_mb": {
+ "mean": 1775.98,
+ "max": 1956.9
+ },
+ "cpu_percent": 359.7,
+ "chunks_per_second": 100.32,
+ "unique_per_second": 98.91,
+ "forgotten_per_second": 95.42,
+ "waited_ticks_per_second": 518.15,
+ "chunks_total": 55956,
+ "chunks_per_bot": {
+ "explore": 1119.12
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1111.42
+ },
+ "resent": 0,
+ "pulled_back": 69967,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 14.74,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 11.12,
+ "mspt": {
+ "average": 244.43,
+ "p50": 243.58,
+ "p95": 308.39,
+ "p99": 360.12
+ },
+ "mspt_worst_p99": 470.2,
+ "tps": 4.09,
+ "rss_mb": {
+ "mean": 1806.85,
+ "max": 2084.5
+ },
+ "cpu_percent": 310.46,
+ "chunks_per_second": 186.87,
+ "unique_per_second": 182.99,
+ "forgotten_per_second": 161.75,
+ "waited_ticks_per_second": 1131.65,
+ "chunks_total": 100389,
+ "chunks_per_bot": {
+ "explore": 1003.89
+ },
+ "unique_chunks_per_bot": {
+ "explore": 991.9
+ },
+ "resent": 0,
+ "pulled_back": 56791,
+ "moved_too_quickly": 344,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 57
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 14.83,
+ "error": "[Errno 32] Broken pipe"
+ }
+ ]
+}
diff --git a/benchmarks/server-equal-work-2026-10-17/run-2-chunk-cache.json b/benchmarks/server-equal-work-2026-10-17/run-2-chunk-cache.json
new file mode 100644
index 000000000..4c182395c
--- /dev/null
+++ b/benchmarks/server-equal-work-2026-10-17/run-2-chunk-cache.json
@@ -0,0 +1,413 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T02:22:59+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "horizon",
+ "bots": "1,10,25,50,100",
+ "behaviour": "walk,explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 300,
+ "seed": 12345,
+ "heap": "4g",
+ "out": "/home/ludovic/scratch/sh2-bench2.json",
+ "nice": 19,
+ "bots_via": "ssh -o BatchMode=yes macmini",
+ "bots_bin": "/tmp/sh2-horizon-bots",
+ "connect": "100.72.51.8",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 11.12,
+ "mspt": {
+ "average": 5.41,
+ "p50": 4.63,
+ "p95": 11.61,
+ "p99": 30.5
+ },
+ "mspt_worst_p99": 64.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1398.84,
+ "max": 1708.5
+ },
+ "cpu_percent": 56.84,
+ "chunks_per_second": 9.19,
+ "unique_per_second": 0.27,
+ "forgotten_per_second": 9.22,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 3713,
+ "chunks_per_bot": {
+ "walk": 3713.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 694.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 10.92,
+ "mspt": {
+ "average": 13.18,
+ "p50": 11.74,
+ "p95": 26.5,
+ "p99": 44.82
+ },
+ "mspt_worst_p99": 87.6,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1439.83,
+ "max": 1831.6
+ },
+ "cpu_percent": 132.94,
+ "chunks_per_second": 93.87,
+ "unique_per_second": 2.38,
+ "forgotten_per_second": 93.77,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 37240,
+ "chunks_per_bot": {
+ "walk": 3724.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 688.7
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 10.92,
+ "mspt": {
+ "average": 23.52,
+ "p50": 21.92,
+ "p95": 44.7,
+ "p99": 63.12
+ },
+ "mspt_worst_p99": 119.1,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1485.82,
+ "max": 1872.0
+ },
+ "cpu_percent": 173.82,
+ "chunks_per_second": 235.63,
+ "unique_per_second": 5.64,
+ "forgotten_per_second": 235.72,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 94549,
+ "chunks_per_bot": {
+ "walk": 3781.96
+ },
+ "unique_chunks_per_bot": {
+ "walk": 692.8
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 10.91,
+ "mspt": {
+ "average": 31.36,
+ "p50": 26.08,
+ "p95": 70.6,
+ "p99": 92.83
+ },
+ "mspt_worst_p99": 125.5,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1556.81,
+ "max": 1913.0
+ },
+ "cpu_percent": 192.16,
+ "chunks_per_second": 468.69,
+ "unique_per_second": 10.43,
+ "forgotten_per_second": 468.78,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 193547,
+ "chunks_per_bot": {
+ "walk": 3870.94
+ },
+ "unique_chunks_per_bot": {
+ "walk": 692.84
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 11.02,
+ "mspt": {
+ "average": 84.38,
+ "p50": 81.5,
+ "p95": 132.92,
+ "p99": 168.38
+ },
+ "mspt_worst_p99": 245.5,
+ "tps": 11.85,
+ "rss_mb": {
+ "mean": 1395.64,
+ "max": 1941.3
+ },
+ "cpu_percent": 271.28,
+ "chunks_per_second": 850.05,
+ "unique_per_second": 21.79,
+ "forgotten_per_second": 851.1,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 368464,
+ "chunks_per_bot": {
+ "walk": 3684.64
+ },
+ "unique_chunks_per_bot": {
+ "walk": 680.58
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 11.02,
+ "mspt": {
+ "average": 11.63,
+ "p50": 10.27,
+ "p95": 24.52,
+ "p99": 40.53
+ },
+ "mspt_worst_p99": 99.9,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 1413.81,
+ "max": 1596.1
+ },
+ "cpu_percent": 329.84,
+ "chunks_per_second": 39.47,
+ "unique_per_second": 34.81,
+ "forgotten_per_second": 39.42,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 13798,
+ "chunks_per_bot": {
+ "explore": 13798.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 12330.0
+ },
+ "resent": 0,
+ "pulled_back": 185,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 11.02,
+ "mspt": {
+ "average": 28.49,
+ "p50": 26.2,
+ "p95": 48.58,
+ "p99": 72.04
+ },
+ "mspt_worst_p99": 125.7,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 2231.06,
+ "max": 4077.8
+ },
+ "cpu_percent": 344.95,
+ "chunks_per_second": 46.31,
+ "unique_per_second": 45.88,
+ "forgotten_per_second": 44.14,
+ "waited_ticks_per_second": 111.95,
+ "chunks_total": 19722,
+ "chunks_per_bot": {
+ "explore": 1972.2
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1957.0
+ },
+ "resent": 0,
+ "pulled_back": 18533,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 11.12,
+ "mspt": {
+ "average": 40.04,
+ "p50": 37.61,
+ "p95": 62.39,
+ "p99": 83.64
+ },
+ "mspt_worst_p99": 147.0,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 2466.85,
+ "max": 4504.5
+ },
+ "cpu_percent": 340.13,
+ "chunks_per_second": 60.61,
+ "unique_per_second": 59.62,
+ "forgotten_per_second": 56.28,
+ "waited_ticks_per_second": 299.57,
+ "chunks_total": 32877,
+ "chunks_per_bot": {
+ "explore": 1315.08
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1300.72
+ },
+ "resent": 0,
+ "pulled_back": 46272,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 11.32,
+ "mspt": {
+ "average": 61.82,
+ "p50": 59.21,
+ "p95": 90.46,
+ "p99": 115.58
+ },
+ "mspt_worst_p99": 320.9,
+ "tps": 16.18,
+ "rss_mb": {
+ "mean": 2634.54,
+ "max": 4883.1
+ },
+ "cpu_percent": 356.96,
+ "chunks_per_second": 95.26,
+ "unique_per_second": 94.31,
+ "forgotten_per_second": 85.86,
+ "waited_ticks_per_second": 528.08,
+ "chunks_total": 59251,
+ "chunks_per_bot": {
+ "explore": 1185.02
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1173.96
+ },
+ "resent": 0,
+ "pulled_back": 99493,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "horizon",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 10.81,
+ "mspt": {
+ "average": 103.24,
+ "p50": 100.03,
+ "p95": 144.77,
+ "p99": 178.8
+ },
+ "mspt_worst_p99": 258.6,
+ "tps": 9.69,
+ "rss_mb": {
+ "mean": 1784.48,
+ "max": 1922.0
+ },
+ "cpu_percent": 336.94,
+ "chunks_per_second": 115.06,
+ "unique_per_second": 114.86,
+ "forgotten_per_second": 109.43,
+ "waited_ticks_per_second": 1127.57,
+ "chunks_total": 93839,
+ "chunks_per_bot": {
+ "explore": 938.39
+ },
+ "unique_chunks_per_bot": {
+ "explore": 935.28
+ },
+ "resent": 0,
+ "pulled_back": 133404,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 100,
+ "bots_failed": [],
+ "tick_queries": 58
+ }
+ ]
+}
diff --git a/benchmarks/server-equal-work-2026-10-17/vanilla.json b/benchmarks/server-equal-work-2026-10-17/vanilla.json
new file mode 100644
index 000000000..014554cee
--- /dev/null
+++ b/benchmarks/server-equal-work-2026-10-17/vanilla.json
@@ -0,0 +1,324 @@
+{
+ "kind": "horizon-server-benchmark",
+ "date": "2026-10-17T03:29:30+00:00",
+ "machine": {
+ "system": "Linux",
+ "machine": "x86_64",
+ "cpus": 4
+ },
+ "commit": "",
+ "java": [
+ "openjdk 25.0.4.1 2026-08-18"
+ ],
+ "settings": {
+ "servers": "vanilla",
+ "bots": "1,10,25,50,100",
+ "behaviour": "walk,explore",
+ "join_every": 1.0,
+ "warmup": 60,
+ "seconds": 300,
+ "seed": 12345,
+ "gamerule": "locator_bar=false",
+ "heap": "4g",
+ "out": "/home/ludovic/scratch/sh2-bench3.json",
+ "nice": 19,
+ "bots_via": "ssh -o BatchMode=yes macmini",
+ "bots_bin": "/tmp/sh2-horizon-bots",
+ "connect": "100.72.51.8",
+ "properties": {
+ "level-seed": "12345",
+ "view-distance": "10",
+ "simulation-distance": "10",
+ "online-mode": "false",
+ "white-list": "false",
+ "gamemode": "creative",
+ "force-gamemode": "true",
+ "spawn-protection": "0",
+ "max-players": "200",
+ "difficulty": "easy",
+ "sync-chunk-writes": "true"
+ }
+ },
+ "runs": [
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "walk",
+ "start_seconds": 15.43,
+ "mspt": {
+ "average": 18.32,
+ "p50": 19.26,
+ "p95": 27.34,
+ "p99": 45.48
+ },
+ "mspt_worst_p99": 393.3,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3428.43,
+ "max": 3437.7
+ },
+ "cpu_percent": 66.47,
+ "chunks_per_second": 9.92,
+ "unique_per_second": 0.29,
+ "forgotten_per_second": 9.95,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 3850,
+ "chunks_per_bot": {
+ "walk": 3850.0
+ },
+ "unique_chunks_per_bot": {
+ "walk": 699.0
+ },
+ "resent": 0,
+ "pulled_back": 0,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "walk",
+ "start_seconds": 14.76,
+ "mspt": {
+ "average": 16.8,
+ "p50": 14.55,
+ "p95": 30.52,
+ "p99": 50.01
+ },
+ "mspt_worst_p99": 205.2,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3490.15,
+ "max": 3580.7
+ },
+ "cpu_percent": 83.7,
+ "chunks_per_second": 100.01,
+ "unique_per_second": 2.83,
+ "forgotten_per_second": 100.04,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 38623,
+ "chunks_per_bot": {
+ "walk": 3862.3
+ },
+ "unique_chunks_per_bot": {
+ "walk": 697.2
+ },
+ "resent": 0,
+ "pulled_back": 5,
+ "moved_too_quickly": 5,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "walk",
+ "start_seconds": 14.84,
+ "mspt": {
+ "average": 16.01,
+ "p50": 14.55,
+ "p95": 26.39,
+ "p99": 51.26
+ },
+ "mspt_worst_p99": 397.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3550.02,
+ "max": 3593.5
+ },
+ "cpu_percent": 114.96,
+ "chunks_per_second": 251.62,
+ "unique_per_second": 6.72,
+ "forgotten_per_second": 251.16,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 98701,
+ "chunks_per_bot": {
+ "walk": 3948.04
+ },
+ "unique_chunks_per_bot": {
+ "walk": 698.84
+ },
+ "resent": 0,
+ "pulled_back": 10,
+ "moved_too_quickly": 10,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "walk",
+ "start_seconds": 14.43,
+ "mspt": {
+ "average": 20.52,
+ "p50": 19.55,
+ "p95": 29.72,
+ "p99": 49.04
+ },
+ "mspt_worst_p99": 600.4,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3633.12,
+ "max": 3658.7
+ },
+ "cpu_percent": 193.84,
+ "chunks_per_second": 501.86,
+ "unique_per_second": 12.15,
+ "forgotten_per_second": 501.8,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 203429,
+ "chunks_per_bot": {
+ "walk": 4068.58
+ },
+ "unique_chunks_per_bot": {
+ "walk": 698.66
+ },
+ "resent": 0,
+ "pulled_back": 33,
+ "moved_too_quickly": 32,
+ "moved_wrongly": 0,
+ "bots_joined": 50,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "walk",
+ "start_seconds": 15.34,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "vanilla",
+ "bots": 1,
+ "behaviour": "explore",
+ "start_seconds": 15.55,
+ "mspt": {
+ "average": 9.93,
+ "p50": 8.12,
+ "p95": 21.33,
+ "p99": 60.19
+ },
+ "mspt_worst_p99": 373.0,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 3564.11,
+ "max": 3655.0
+ },
+ "cpu_percent": 245.18,
+ "chunks_per_second": 35.93,
+ "unique_per_second": 33.35,
+ "forgotten_per_second": 35.64,
+ "waited_ticks_per_second": 0.0,
+ "chunks_total": 12340,
+ "chunks_per_bot": {
+ "explore": 12340.0
+ },
+ "unique_chunks_per_bot": {
+ "explore": 11569.0
+ },
+ "resent": 0,
+ "pulled_back": 261,
+ "moved_too_quickly": 0,
+ "moved_wrongly": 0,
+ "bots_joined": 1,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "vanilla",
+ "bots": 10,
+ "behaviour": "explore",
+ "start_seconds": 15.03,
+ "mspt": {
+ "average": 16.99,
+ "p50": 14.46,
+ "p95": 29.61,
+ "p99": 132.18
+ },
+ "mspt_worst_p99": 1244.0,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 4135.2,
+ "max": 4453.1
+ },
+ "cpu_percent": 242.32,
+ "chunks_per_second": 22.39,
+ "unique_per_second": 22.41,
+ "forgotten_per_second": 22.78,
+ "waited_ticks_per_second": 78.78,
+ "chunks_total": 10177,
+ "chunks_per_bot": {
+ "explore": 1017.7
+ },
+ "unique_chunks_per_bot": {
+ "explore": 1016.2
+ },
+ "resent": 0,
+ "pulled_back": 17314,
+ "moved_too_quickly": 19,
+ "moved_wrongly": 0,
+ "bots_joined": 10,
+ "bots_failed": [],
+ "tick_queries": 59
+ },
+ {
+ "server": "vanilla",
+ "bots": 25,
+ "behaviour": "explore",
+ "start_seconds": 14.84,
+ "mspt": {
+ "average": 24.19,
+ "p50": 21.22,
+ "p95": 36.51,
+ "p99": 174.82
+ },
+ "mspt_worst_p99": 1532.8,
+ "tps": 20.0,
+ "rss_mb": {
+ "mean": 4504.55,
+ "max": 4988.9
+ },
+ "cpu_percent": 319.55,
+ "chunks_per_second": 33.78,
+ "unique_per_second": 33.66,
+ "forgotten_per_second": 34.64,
+ "waited_ticks_per_second": 269.22,
+ "chunks_total": 20522,
+ "chunks_per_bot": {
+ "explore": 820.88
+ },
+ "unique_chunks_per_bot": {
+ "explore": 815.76
+ },
+ "resent": 0,
+ "pulled_back": 46246,
+ "moved_too_quickly": 28,
+ "moved_wrongly": 0,
+ "bots_joined": 25,
+ "bots_failed": [],
+ "tick_queries": 58
+ },
+ {
+ "server": "vanilla",
+ "bots": 50,
+ "behaviour": "explore",
+ "start_seconds": 14.73,
+ "error": "[Errno 32] Broken pipe"
+ },
+ {
+ "server": "vanilla",
+ "bots": 100,
+ "behaviour": "explore",
+ "start_seconds": 14.54,
+ "error": "[Errno 32] Broken pipe"
+ }
+ ]
+}
diff --git a/crates/horizon-bots/src/main.rs b/crates/horizon-bots/src/main.rs
index d76da5e84..090daeb4e 100644
--- a/crates/horizon-bots/src/main.rs
+++ b/crates/horizon-bots/src/main.rs
@@ -9,6 +9,11 @@
//! horizon-bots --server 127.0.0.1:25565 --bots 25 --behaviour mixed --seconds 360 --report bots.json
//!
//! It prints one JSON line a second (bots online, chunks received) and writes a summary with `--report`.
+//! A bot moves only while it holds the chunk it stands in: vanilla's client stops ticking its player in a chunk
+//! it hasn't received, so a player can't outrun the server's chunk sending, on any server.
+//! Each bot also keeps the chunks it holds, as a client's chunk cache does, so the report tells chunks that
+//! entered the view apart from chunks sent again while the bot still held them (`resent`), and counts the
+//! times the server pulled a bot back (`pulled_back`: a teleport after the first, as for "moved too quickly").
use horizon_protocol::{
PROTOCOL_VERSION,
@@ -25,6 +30,7 @@ use horizon_protocol::{
};
use serde_json::json;
use std::{
+ collections::HashSet,
sync::{
Arc, Mutex,
atomic::{AtomicBool, AtomicU64, Ordering},
@@ -43,8 +49,9 @@ horizon-bots: load-test bots for a Minecraft Java Edition 26.3 server (offline m
--seconds N how long to run after the first bot joins; default 60
--view-distance N what the bots ask for; default 10
--seed N default 12345
+ --explore-speed B blocks a second an explore bot flies; default 22 (as fast as chunks come)
--name PREFIX bot names: PREFIX0, PREFIX1...; default Bot
- --report FILE a JSON summary at the end
+ --report FILE a JSON summary at the end (- prints it after the per-second lines)
";
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -73,6 +80,7 @@ struct Options {
seconds: u64,
view_distance: i8,
seed: u64,
+ explore_speed: f64,
name: String,
report: Option,
}
@@ -87,6 +95,7 @@ fn options() -> Result {
seconds: 60,
view_distance: 10,
seed: 12345,
+ explore_speed: 22.0,
name: "Bot".into(),
report: None,
};
@@ -110,6 +119,9 @@ fn options() -> Result {
"--seconds" => o.seconds = value.parse().map_err(|_| number("seconds"))?,
"--view-distance" => o.view_distance = value.parse().map_err(|_| number("2 to 32"))?,
"--seed" => o.seed = value.parse().map_err(|_| number("a number"))?,
+ "--explore-speed" => {
+ o.explore_speed = value.parse().map_err(|_| number("blocks a second"))?;
+ }
"--name" => o.name = value,
"--report" => o.report = Some(value),
_ => return Err(format!("unknown option {arg}; --help lists them")),
@@ -129,6 +141,17 @@ fn options() -> Result {
struct Bot {
online: AtomicBool,
chunks: AtomicU64,
+ /// Chunks received while the bot already held them (no ForgetLevelChunk in between).
+ resent: AtomicU64,
+ /// Different chunks received over the run.
+ unique: AtomicU64,
+ forgotten: AtomicU64,
+ /// Teleports after the spawn one: the server refused a move.
+ pulled_back: AtomicU64,
+ /// Ticks the bot couldn't move because it didn't hold its chunk yet.
+ waited: AtomicU64,
+ /// The chunks the bot holds (ClientChunkCache).
+ held: Mutex>,
/// Where the server last put the bot (a teleport), to start from.
teleport: Mutex>,
error: Mutex >,
@@ -268,6 +291,36 @@ fn join(o: &Options, name: &str) -> Result {
}
}
+/// ChunkBatchSizeCalculator: the chunks per tick a vanilla client asks for, from how long its batches take
+/// to arrive.
+struct BatchSize {
+ nanos_per_chunk: f64,
+ old_samples_weight: u32,
+ started: Instant,
+}
+
+impl BatchSize {
+ fn new() -> Self {
+ Self {
+ nanos_per_chunk: 2_000_000.0,
+ old_samples_weight: 1,
+ started: Instant::now(),
+ }
+ }
+ fn finished(&mut self, size: i32) {
+ if size > 0 {
+ let per_chunk = self.started.elapsed().as_nanos() as f64 / f64::from(size);
+ let clamped = per_chunk.clamp(self.nanos_per_chunk / 3.0, self.nanos_per_chunk * 3.0);
+ let weight = f64::from(self.old_samples_weight);
+ self.nanos_per_chunk = (self.nanos_per_chunk * weight + clamped) / (weight + 1.0);
+ self.old_samples_weight = (self.old_samples_weight + 1).min(49);
+ }
+ }
+ fn desired_chunks_per_tick(&self) -> f32 {
+ (7_000_000.0 / self.nanos_per_chunk) as f32
+ }
+}
+
/// Reads the play state: answers what a client must answer, counts chunks, records teleports.
fn read(
mut reader: horizon_protocol::connection::ConnReader,
@@ -277,6 +330,9 @@ fn read(
use ids::play::clientbound as cb;
use ids::play::serverbound as sb;
let send = |body: Vec| writer.lock().unwrap().send(&body);
+ let mut seen = HashSet::new();
+ let mut batch = BatchSize::new();
+ let mut teleports = 0u64;
loop {
let (id, body) = match reader.recv() {
Ok(packet) => packet,
@@ -299,14 +355,38 @@ fn read(
},
cb::LEVEL_CHUNK_WITH_LIGHT => {
bot.chunks.fetch_add(1, Ordering::Relaxed);
+ if let (Ok(x), Ok(z)) = (r.i32(), r.i32()) {
+ if !bot.held.lock().unwrap().insert((x, z)) {
+ bot.resent.fetch_add(1, Ordering::Relaxed);
+ }
+ if seen.insert((x, z)) {
+ bot.unique.fetch_add(1, Ordering::Relaxed);
+ }
+ }
Ok(())
}
- cb::CHUNK_BATCH_FINISHED => send(
- play::Serverbound::ChunkBatchReceived(play::ChunkBatchReceived {
- chunks_per_tick: 25.0,
- })
- .encode(),
- ),
+ cb::FORGET_LEVEL_CHUNK => {
+ if let Ok(play::Clientbound::ForgetLevelChunk(p)) =
+ play::Clientbound::decode(id, &body)
+ && bot.held.lock().unwrap().remove(&(p.pos[0], p.pos[1]))
+ {
+ bot.forgotten.fetch_add(1, Ordering::Relaxed);
+ }
+ Ok(())
+ }
+ cb::CHUNK_BATCH_START => {
+ batch.started = Instant::now();
+ Ok(())
+ }
+ cb::CHUNK_BATCH_FINISHED => {
+ batch.finished(r.varint().unwrap_or(0));
+ send(
+ play::Serverbound::ChunkBatchReceived(play::ChunkBatchReceived {
+ chunks_per_tick: batch.desired_chunks_per_tick(),
+ })
+ .encode(),
+ )
+ }
cb::PLAYER_POSITION => match play::Clientbound::decode(id, &body) {
Ok(play::Clientbound::PlayerPosition(p)) => {
let mut at = bot.teleport.lock().unwrap();
@@ -320,6 +400,10 @@ fn read(
}
});
*at = Some(pos);
+ teleports += 1;
+ if teleports > 1 {
+ bot.pulled_back.fetch_add(1, Ordering::Relaxed);
+ }
send(
play::Serverbound::AcceptTeleportation(play::AcceptTeleportation {
id: p.teleport,
@@ -416,7 +500,10 @@ fn run_bot(
if let Some(at) = bot.teleport.lock().unwrap().take() {
pos = at;
}
- if pos[1] < cruise {
+ let here = ((pos[0].floor() as i32) >> 4, (pos[2].floor() as i32) >> 4);
+ if !bot.held.lock().unwrap().contains(&here) {
+ bot.waited.fetch_add(1, Ordering::Relaxed);
+ } else if pos[1] < cruise {
pos[1] = (pos[1] + 0.5).min(cruise);
} else {
match behaviour {
@@ -440,9 +527,11 @@ fn run_bot(
}
}
Behaviour::Explore => {
- // Flying fast in creative: about 22 blocks a second, which keeps new chunks coming.
- pos[0] += heading.cos() * 1.1;
- pos[2] += heading.sin() * 1.1;
+ // Flying in creative, by default about 22 blocks a second, which keeps new
+ // chunks coming as fast as the server sends them.
+ let step = o.explore_speed / 20.0;
+ pos[0] += heading.cos() * step;
+ pos[2] += heading.sin() * step;
}
}
}
@@ -520,6 +609,9 @@ fn main() {
.filter(|b| b.online.load(Ordering::SeqCst))
.count();
let chunks: u64 = bots.iter().map(|b| b.chunks.load(Ordering::Relaxed)).sum();
+ let total = |f: fn(&Bot) -> &AtomicU64| -> u64 {
+ bots.iter().map(|b| f(b).load(Ordering::Relaxed)).sum()
+ };
let failed = bots
.iter()
.filter(|b| b.error.lock().unwrap().is_some())
@@ -536,6 +628,11 @@ fn main() {
"failed": failed,
"chunks": chunks,
"chunks_per_second": chunks - previous_chunks,
+ "unique": total(|b| &b.unique),
+ "forgotten": total(|b| &b.forgotten),
+ "resent": total(|b| &b.resent),
+ "pulled_back": total(|b| &b.pulled_back),
+ "waited_ticks": total(|b| &b.waited),
})
);
previous_chunks = chunks;
@@ -554,19 +651,30 @@ fn main() {
"bots": o.bots,
"behaviour": o.behaviour,
"seed": o.seed,
+ "explore_speed": o.explore_speed,
"view_distance": o.view_distance,
"seconds": o.seconds,
"joined": bots.iter().filter(|b| b.joined_after_ms.load(Ordering::SeqCst) > 0).count(),
"chunks": bots.iter().map(|b| b.chunks.load(Ordering::Relaxed)).sum::(),
+ "resent": bots.iter().map(|b| b.resent.load(Ordering::Relaxed)).sum::(),
+ "pulled_back": bots.iter().map(|b| b.pulled_back.load(Ordering::Relaxed)).sum::(),
+ "waited_ticks": bots.iter().map(|b| b.waited.load(Ordering::Relaxed)).sum::(),
"per_bot": bots.iter().enumerate().map(|(i, b)| json!({
"name": format!("{}{i}", o.name),
"behaviour": behaviour_of(&o.behaviour, i).name(),
"joined_after_ms": b.joined_after_ms.load(Ordering::SeqCst),
"chunks": b.chunks.load(Ordering::Relaxed),
+ "unique_chunks": b.unique.load(Ordering::Relaxed),
+ "resent": b.resent.load(Ordering::Relaxed),
+ "forgotten": b.forgotten.load(Ordering::Relaxed),
+ "pulled_back": b.pulled_back.load(Ordering::Relaxed),
+ "waited_ticks": b.waited.load(Ordering::Relaxed),
"error": *b.error.lock().unwrap(),
})).collect::>(),
});
- if let Some(path) = &o.report {
+ if o.report.as_deref() == Some("-") {
+ println!("{summary:#}");
+ } else if let Some(path) = &o.report {
if let Err(e) = std::fs::write(path, format!("{summary:#}\n")) {
eprintln!("horizon-bots: {path}: {e}");
}
diff --git a/crates/horizon-client/Cargo.toml b/crates/horizon-client/Cargo.toml
index 29a02553f..ffccb88e8 100644
--- a/crates/horizon-client/Cargo.toml
+++ b/crates/horizon-client/Cargo.toml
@@ -37,7 +37,7 @@ miniz_oxide = "0.8"
ab_glyph = "0.2.32"
log = "0.4"
chrono = { version = "0.4.42", default-features = false, features = ["clock", "std"] }
-flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"] }
+flate2 = { version = "1.1.10", default-features = false, features = ["zlib-rs", "runtime_detection"] }
horizon-theme = { path = "../horizon-theme" }
# Opt-in data collection: the game keeps, the launcher sends (docs/telemetry.md).
horizon-telemetry = { path = "../horizon-telemetry", default-features = false }
diff --git a/crates/horizon-client/examples/block_entity_tickers_fixture.rs b/crates/horizon-client/examples/block_entity_tickers_fixture.rs
new file mode 100644
index 000000000..f08c333f6
--- /dev/null
+++ b/crates/horizon-client/examples/block_entity_tickers_fixture.rs
@@ -0,0 +1,99 @@
+//! The Rust side of tools/test_block_entity_tickers_parity.py: the ops of
+//! `VanillaBlockEntityTickerOracle` on `BlockEntities`, as `World` drives it
+//! (a state write calls `state_changed`), printing the tick order.
+use horizon_client::{
+ block_entities::{BlockEntities, Pos, Ticking},
+ containers::BlockEntity,
+};
+use std::collections::HashMap;
+
+/// State ids of the fixture: 0 air, 1 a block whose block entity ticks, 2 a
+/// jukebox without a record, 3 a block entity that never ticks (a chest).
+fn state(name: &str) -> u32 {
+ match name {
+ "chest" | "barrel" => 3,
+ "jukebox" => 2,
+ _ => 1,
+ }
+}
+
+fn entity(name: &str) -> BlockEntity {
+ if name.starts_with("jukebox") {
+ // The game makes a jukebox's block entity when a record goes in.
+ return BlockEntity::Jukebox(Default::default());
+ }
+ BlockEntity::for_block(&format!("minecraft:{name}"))
+ .unwrap_or_else(|| panic!("no block entity for {name}"))
+}
+
+fn main() {
+ let args: Vec = std::env::args().collect();
+ let input = std::fs::read_to_string(&args[1]).expect("input");
+ let mut out = String::new();
+ let mut entities = BlockEntities::default();
+ let mut states: HashMap = HashMap::new();
+ let mut kinds: HashMap = HashMap::new();
+ let table = vec![Ticking::No, Ticking::Yes, Ticking::Idle, Ticking::No];
+ for line in input.lines() {
+ let w: Vec<&str> = line.split_whitespace().collect();
+ let pos = |i: usize| -> Pos {
+ let n = |j: usize| w[i + j].parse::().expect("coordinate");
+ (n(0), n(1), n(2))
+ };
+ match w[0] {
+ "reset" => {
+ entities = BlockEntities::default();
+ entities.set_states(table.clone());
+ states.clear();
+ kinds.clear();
+ }
+ "load" => {
+ let mut chunk = Vec::new();
+ for i in (3..w.len()).step_by(4) {
+ let p = pos(i + 1);
+ states.insert(p, state(w[i]));
+ kinds.insert(p, w[i].to_owned());
+ chunk.push((p, entity(w[i])));
+ }
+ entities.load_chunk(chunk);
+ }
+ "place" => {
+ let p = pos(2);
+ // World::set, then the game adds the block entity.
+ let old = states.insert(p, state(w[1])).unwrap_or(0);
+ kinds.insert(p, w[1].to_owned());
+ entities.state_changed(p, old, state(w[1]));
+ entities.insert(p, entity(w[1]));
+ }
+ "replace" => {
+ let p = pos(1);
+ entities.insert(p, entity(&kinds[&p]));
+ }
+ "remove" => {
+ let p = pos(1);
+ entities.remove(&p);
+ let old = states.insert(p, 0).unwrap_or(0);
+ entities.state_changed(p, old, 0);
+ }
+ "record" => {
+ let p = pos(1);
+ let s = if w[4] == "1" { 1 } else { 2 };
+ let old = states.insert(p, s).unwrap_or(0);
+ entities.state_changed(p, old, s);
+ }
+ "unload" => {
+ let c = (w[1].parse::().unwrap(), w[2].parse::().unwrap());
+ entities.retain(|p, _| (p.0 >> 4, p.2 >> 4) != c);
+ }
+ "tick" => {
+ out.push_str("tick");
+ for (p, _) in entities.tickers(|p| states.get(&p).copied().unwrap_or(0)) {
+ out.push_str(&format!(" {},{},{}", p.0, p.1, p.2));
+ }
+ out.push('\n');
+ }
+ other => panic!("unknown op {other}"),
+ }
+ }
+ std::fs::write(&args[2], out).expect("output");
+}
diff --git a/crates/horizon-client/examples/lan_flat.rs b/crates/horizon-client/examples/lan_flat.rs
index 16fc36b95..20d87e03c 100644
--- a/crates/horizon-client/examples/lan_flat.rs
+++ b/crates/horizon-client/examples/lan_flat.rs
@@ -22,12 +22,7 @@ fn main() -> Result<(), Box> {
let port: u16 = args.next().ok_or("port")?.parse()?;
let assets = Assets::load(&root)?;
let facts = BlockFacts::load(&root, assets.registry)?;
- let state = |name: &str| {
- assets
- .registry
- .default_state(name)
- .map_or(0, |s| s.0 as u16)
- };
+ let state = |name: &str| assets.registry.default_state(name).map_or(0, |s| s.0);
let sync = Arc::new(SyncData::load(&root)?);
let biomes: Vec = sync
.dynamic
@@ -121,6 +116,7 @@ fn main() -> Result<(), Box> {
clock_rate: 1.0,
tick_rate: 20.0,
tick_frozen: false,
+ collision: None,
};
for event in hub.tick(&mut ctx) {
match event {
@@ -132,7 +128,9 @@ fn main() -> Result<(), Box> {
eprintln!("[lan] {packet:?}");
}
}
- HostEvent::Chat(line) => println!("{line}"),
+ HostEvent::Chat { line, .. } | HostEvent::Warn(line) | HostEvent::Error(line) => {
+ println!("{line}")
+ }
HostEvent::Left(_) => {}
}
}
diff --git a/crates/horizon-client/examples/light_parity.rs b/crates/horizon-client/examples/light_parity.rs
index afc3e3156..29488130e 100644
--- a/crates/horizon-client/examples/light_parity.rs
+++ b/crates/horizon-client/examples/light_parity.rs
@@ -232,7 +232,7 @@ fn incremental(
c.lit = true;
world.insert((x, z), Arc::new(c));
}
- let palette: Vec = [
+ let palette: Vec = [
"minecraft:air",
"minecraft:stone",
"minecraft:torch",
@@ -242,7 +242,7 @@ fn incremental(
"minecraft:glass",
]
.iter()
- .filter_map(|n| registry.default_state(n).map(|s| s.0 as u16))
+ .filter_map(|n| registry.default_state(n).map(|s| s.0))
.chain(
facts
.states
@@ -257,7 +257,7 @@ fn incremental(
]
.contains(&&*f.name)
})
- .map(|(i, _)| i as u16)
+ .map(|(i, _)| i as u32)
.step_by(3),
)
.collect();
diff --git a/crates/horizon-client/examples/mob_ai_probe.rs b/crates/horizon-client/examples/mob_ai_probe.rs
index 087fd3edf..0b3adec31 100644
--- a/crates/horizon-client/examples/mob_ai_probe.rs
+++ b/crates/horizon-client/examples/mob_ai_probe.rs
@@ -999,6 +999,7 @@ fn main() -> horizon_client::Result<()> {
hero: false,
uuid: PLAYER_UUID,
allies: Default::default(),
+ remote: false,
}
});
let mut scratch = LegacyRandom::new(0);
diff --git a/crates/horizon-client/examples/options_probe.rs b/crates/horizon-client/examples/options_probe.rs
index 1cdf8c8fb..f186af994 100644
--- a/crates/horizon-client/examples/options_probe.rs
+++ b/crates/horizon-client/examples/options_probe.rs
@@ -1,7 +1,10 @@
#![forbid(unsafe_code)]
//! Loads and saves option files like `Options.load`/`save`, for the
//! differential harness (tools/test_options_parity.py).
-use horizon_client::{Result, keybinds, options_file::OptionsFile};
+use horizon_client::{
+ Result, keybinds,
+ options_file::{OptionsFile, V},
+};
use std::{fs, io::Write};
fn main() -> Result<()> {
@@ -14,11 +17,16 @@ fn main() -> Result<()> {
let mut first = true;
for path in names {
let name = path.file_name().unwrap().to_string_lossy().into_owned();
- let file = if name == "absent.txt" {
+ let mut file = if name == "absent.txt" {
OptionsFile::default()
} else {
OptionsFile::parse(&String::from_utf8_lossy(&fs::read(&path)?))
};
+ // Horizon extends the slider to 64; vanilla rejects 33..64 to its default.
+ // Compare that deliberate extension as vanilla would serialize it.
+ if file.int("renderDistance") > 32 {
+ file.set("renderDistance", V::Int(12));
+ }
write!(out, "== {name}\n{}", file.serialize())?;
if first {
first = false;
diff --git a/crates/horizon-client/examples/random_tick_eligibility_bench.rs b/crates/horizon-client/examples/random_tick_eligibility_bench.rs
index 856d7d520..49c32a8f7 100644
--- a/crates/horizon-client/examples/random_tick_eligibility_bench.rs
+++ b/crates/horizon-client/examples/random_tick_eligibility_bench.rs
@@ -56,16 +56,16 @@ fn main() -> horizon_client::Result<()> {
"resource_load_ms={:.3}",
start.elapsed().as_secs_f64() * 1000.0
);
- let inactive: Vec = facts
+ let inactive: Vec = facts
.states
.iter()
.enumerate()
.filter(|(_, f)| !f.random_ticks)
.take(128)
- .map(|(i, _)| i as u16)
+ .map(|(i, _)| i as u32)
.collect();
- let active = registry.default_state("minecraft:grass_block").unwrap().0 as u16;
- assert!(facts.get(BlockStateId(u32::from(active))).random_ticks);
+ let active = registry.default_state("minecraft:grass_block").unwrap().0;
+ assert!(facts.get(BlockStateId(active)).random_ticks);
for (name, palette) in [("sparse", 1), ("dense", 128)] {
let start = Instant::now();
let mut chunks = FxHashMap::default();
diff --git a/crates/horizon-client/examples/resource_memory.rs b/crates/horizon-client/examples/resource_memory.rs
new file mode 100644
index 000000000..1eb6c45b7
--- /dev/null
+++ b/crates/horizon-client/examples/resource_memory.rs
@@ -0,0 +1,151 @@
+//! Resident memory of each resource loader, in the game's start order: what a
+//! larger registry (content mods, docs/modpacks.md) costs, loader by loader.
+//!
+//! resource_memory RESOURCES
+//!
+//! RESOURCES is a prepared root or a content-mod root (`.horizon-cache/mod-content`).
+//! Prints, after each step, the live heap (a counting allocator: what the
+//! step keeps), the heap's peak during the step (what it parsed on the way)
+//! and the process RSS (what the allocator holds on to). On macOS it ends
+//! with `footprint`'s physical footprint, the number the OS charges: RSS also
+//! counts freed pages the allocator marked reusable.
+use horizon_client::{
+ assets::Assets, biome::Biomes, blocks::BlockFacts, collisions, crafting::Recipes, items::Items,
+ light::LightTables, mesher::MeshTables, models, motion::MotionResources,
+ vanillagen::VanillaTerrain,
+};
+use std::{
+ alloc::{GlobalAlloc, Layout, System},
+ sync::atomic::{AtomicUsize, Ordering::Relaxed},
+};
+use std::{path::PathBuf, process::Command};
+type Result = std::result::Result>;
+
+struct Counting;
+static LIVE: AtomicUsize = AtomicUsize::new(0);
+static PEAK: AtomicUsize = AtomicUsize::new(0);
+// SAFETY: forwards to the system allocator, only counting sizes.
+unsafe impl GlobalAlloc for Counting {
+ unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
+ let p = unsafe { System.alloc(layout) };
+ if !p.is_null() {
+ let now = LIVE.fetch_add(layout.size(), Relaxed) + layout.size();
+ PEAK.fetch_max(now, Relaxed);
+ }
+ p
+ }
+ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
+ unsafe { System.dealloc(ptr, layout) };
+ LIVE.fetch_sub(layout.size(), Relaxed);
+ }
+ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new: usize) -> *mut u8 {
+ let p = unsafe { System.realloc(ptr, layout, new) };
+ if !p.is_null() {
+ if new >= layout.size() {
+ let now = LIVE.fetch_add(new - layout.size(), Relaxed) + new - layout.size();
+ PEAK.fetch_max(now, Relaxed);
+ } else {
+ LIVE.fetch_sub(layout.size() - new, Relaxed);
+ }
+ }
+ p
+ }
+}
+#[global_allocator]
+static ALLOC: Counting = Counting;
+const MB: f64 = 1048576.0;
+
+fn rss_mb() -> f64 {
+ let out = Command::new("ps")
+ .args(["-o", "rss=", "-p", &std::process::id().to_string()])
+ .output()
+ .ok();
+ out.and_then(|o| String::from_utf8(o.stdout).ok())
+ .and_then(|s| s.trim().parse::().ok())
+ .map_or(0.0, |kb| kb / 1024.0)
+}
+
+fn main() -> Result<()> {
+ let root = PathBuf::from(
+ std::env::args()
+ .nth(1)
+ .ok_or("usage: resource_memory RESOURCES")?,
+ );
+ println!(
+ "{:<24} {:>8} {:>8} {:>10} {:>8}",
+ "step", "live MB", "+live", "step peak", "RSS MB"
+ );
+ let mut last = 0usize;
+ let mut step = |name: &str| {
+ let live = LIVE.load(Relaxed);
+ let peak = PEAK.swap(live, Relaxed);
+ println!(
+ "{name:<24} {:>8.0} {:>+8.0} {:>10.0} {:>8.0}",
+ live as f64 / MB,
+ (live as f64 - last as f64) / MB,
+ peak as f64 / MB,
+ rss_mb()
+ );
+ last = live;
+ };
+ step("start");
+ let registry = horizon_world::level::data::load_registry(&root)?;
+ step("registry alone");
+ drop(registry);
+ step("registry dropped");
+ let assets = Assets::load(&root)?;
+ step("assets");
+ println!(
+ " sprites: {} layers of {}px, {:.0} MB of pixels",
+ assets.texture_layers,
+ assets.sprite_size,
+ assets.pixels.len() as f64 / MB
+ );
+ // The game decodes gameplay facts once for both tables (BlockFacts::load_pair).
+ let (facts, behaviours) = BlockFacts::load_pair(&root, assets.registry)?;
+ step("block facts+behaviours");
+ let items = Items::load(&root, assets.registry, &facts)?;
+ step("items");
+ let recipes = Recipes::load(&root, &items)?;
+ step("recipes");
+ let biomes = Biomes::load(&root)?;
+ step("biomes");
+ let light = LightTables::load(&root, assets.registry, &facts)?;
+ step("light tables");
+ let tables = MeshTables::new(
+ &assets,
+ &facts,
+ models::load_visibility(&root, assets.registry)?,
+ )?;
+ step("mesh tables");
+ let collision = collisions::load(&root, assets.registry)?;
+ step("collision");
+ let motion = MotionResources::load_with_facts(&root, &assets, &facts)?;
+ step("motion");
+ let terrain = VanillaTerrain::new(&root.join("worldgen"), assets.registry, &biomes, 1234)?;
+ step("worldgen");
+ println!(
+ "{} block states; live {:.0} MB, RSS {:.0} MB",
+ facts.states.len(),
+ LIVE.load(Relaxed) as f64 / MB,
+ rss_mb()
+ );
+ if let Ok(out) = Command::new("footprint")
+ .arg(std::process::id().to_string())
+ .output()
+ {
+ let text = String::from_utf8_lossy(&out.stdout);
+ for line in text
+ .lines()
+ .filter(|l| l.contains("Footprint") || l.contains("phys_footprint"))
+ {
+ println!(" {}", line.trim());
+ }
+ }
+ // Keep everything alive until the end.
+ drop((
+ terrain, behaviours, motion, collision, tables, light, biomes, recipes, items, facts,
+ assets,
+ ));
+ Ok(())
+}
diff --git a/crates/horizon-client/examples/save_batch_bench.rs b/crates/horizon-client/examples/save_batch_bench.rs
index 11c4f64ed..4ee5103de 100644
--- a/crates/horizon-client/examples/save_batch_bench.rs
+++ b/crates/horizon-client/examples/save_batch_bench.rs
@@ -4,7 +4,7 @@
//! Exact NBT equality is always validated. No GPU, compression or disk I/O timed.
use horizon_client::{
biome::Biomes,
- chunk::{BLOCK_STRATEGY, Chunk},
+ chunk::{Chunk, block_strategy},
containers::BlockEntity,
items::ItemStack,
save::{self, ChunkExtras},
@@ -64,7 +64,7 @@ fn fixture(per_chunk: usize) -> (Vec>, Entities, Names) {
};
let mut template = Chunk::empty(0, 0);
for s in &mut template.sections[..8] {
- Arc::make_mut(s).blocks = PalettedContainer::new(BLOCK_STRATEGY, 1);
+ Arc::make_mut(s).blocks = PalettedContainer::new(block_strategy(), 1);
}
template.heights = Arc::new([64; 256]);
for i in 0..256 {
diff --git a/crates/horizon-client/examples/save_parity.rs b/crates/horizon-client/examples/save_parity.rs
index ba2c4b0fa..3954e3bb3 100644
--- a/crates/horizon-client/examples/save_parity.rs
+++ b/crates/horizon-client/examples/save_parity.rs
@@ -257,9 +257,9 @@ fn main() -> horizon_client::Result<()> {
);
Ok(())
}
-fn tables_air(assets: &Assets) -> u16 {
+fn tables_air(assets: &Assets) -> u32 {
assets
.registry
.default_state("minecraft:air")
- .map_or(0, |s| s.0 as u16)
+ .map_or(0, |s| s.0)
}
diff --git a/crates/horizon-client/examples/section_mesh_fixture.rs b/crates/horizon-client/examples/section_mesh_fixture.rs
index a42448794..6359f32d0 100644
--- a/crates/horizon-client/examples/section_mesh_fixture.rs
+++ b/crates/horizon-client/examples/section_mesh_fixture.rs
@@ -83,7 +83,7 @@ fn scene(
for block in row["blocks"].as_array().ok_or("missing blocks")? {
let (x, y, z) = (int(&block[0])?, int(&block[1])?, int(&block[2])?);
let i = chunk_index(x, z)?;
- chunks[i].set(x & 15, y, z & 15, u16::try_from(int(&block[3])?)?);
+ chunks[i].set(x & 15, y, z & 15, u32::try_from(int(&block[3])?)?);
}
for cell in row["lights"].as_array().ok_or("missing lights")? {
let (x, y, z) = (int(&cell[0])?, int(&cell[1])?, int(&cell[2])?);
diff --git a/crates/horizon-client/examples/tooltip_display_fixture.rs b/crates/horizon-client/examples/tooltip_display_fixture.rs
new file mode 100644
index 000000000..ec61159cd
--- /dev/null
+++ b/crates/horizon-client/examples/tooltip_display_fixture.rs
@@ -0,0 +1,40 @@
+//! Tooltip display visibility oracle companion for tools/test_tooltip_display_parity.py.
+use horizon_client::{item_tooltip::TooltipDisplay, items::ItemStack};
+use horizon_world::nbt::Tag;
+use std::{error::Error, fmt::Write};
+
+fn main() -> Result<(), Box> {
+ let args: Vec = std::env::args().collect();
+ let mut output = String::new();
+ for line in std::fs::read_to_string(&args[1])?.lines() {
+ let fields: Vec<&str> = line.split('\t').collect();
+ let hide_tooltip: bool = fields[0].parse()?;
+ let creative: bool = fields[1].parse()?;
+ let hide_attributes: bool = fields[2].parse()?;
+ let mut component = Vec::new();
+ if hide_tooltip {
+ component.push(("hide_tooltip", Tag::Byte(1)));
+ }
+ if hide_attributes {
+ component.push((
+ "hidden_components",
+ Tag::List(vec![Tag::String("minecraft:attribute_modifiers".into())]),
+ ));
+ }
+ let mut stack = ItemStack::new("minecraft:diamond_sword", 1);
+ if !component.is_empty() {
+ stack
+ .data_mut()
+ .set_other("minecraft:tooltip_display", Some(Tag::compound(component)));
+ }
+ let display = TooltipDisplay::for_stack(&stack);
+ writeln!(
+ output,
+ "{}\t{}",
+ display.name_visible(creative),
+ display.shows("minecraft:attribute_modifiers")
+ )?;
+ }
+ std::fs::write(&args[2], output)?;
+ Ok(())
+}
diff --git a/crates/horizon-client/src/advancements.rs b/crates/horizon-client/src/advancements.rs
index 22ffcc9d7..16028e220 100644
--- a/crates/horizon-client/src/advancements.rs
+++ b/crates/horizon-client/src/advancements.rs
@@ -607,6 +607,29 @@ pub struct Entities<'a> {
pub tool: Option<&'a ItemView>,
pub block_pos: Option<[i32; 3]>,
}
+/// Conditions shared by item/entity interactions and thrown-item pickups.
+pub fn item_entity(
+ v: &Value,
+ player: &EntityView,
+ target: &EntityView,
+ stack: &ItemView,
+ w: &dyn World,
+) -> bool {
+ let pctx = Entities {
+ this: Some(player),
+ origin: player.position,
+ tool: None,
+ block_pos: None,
+ };
+ let ectx = Entities {
+ this: Some(target),
+ ..pctx
+ };
+ conditions(&v["player"], &pctx, w)
+ && conditions(&v["entity"], &ectx, w)
+ && item(&v["item"], stack, w)
+}
+
/// A `ContextAwarePredicate`: a list of loot conditions (or one condition).
pub fn conditions(v: &Value, ctx: &Entities, w: &dyn World) -> bool {
match v {
@@ -996,7 +1019,75 @@ mod tests {
false
}
fn in_tag(&self, _: &str, tag: &str, id: &str) -> bool {
- tag == "minecraft:stone_tool_materials" && id == "minecraft:cobblestone"
+ (tag == "minecraft:stone_tool_materials" && id == "minecraft:cobblestone")
+ || (tag == "minecraft:sulfur_cube_archetype/explosive" && id == "minecraft:tnt")
+ }
+ }
+ #[test]
+ fn uh_oh_accepts_either_tnt_event_only_for_adult_sulfur_cubes() {
+ let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(
+ "../../.local/horizon-client/26.3/data/minecraft/advancement/husbandry/uh_oh.json",
+ );
+ if !path.exists() {
+ return;
+ }
+ let json = serde_json::from_slice(&std::fs::read(path).unwrap()).unwrap();
+ let advancement = parse("minecraft:husbandry/uh_oh", &json).unwrap();
+ assert_eq!(advancement.criteria.len(), 2);
+ let player = EntityView {
+ kind: "minecraft:player".into(),
+ ..Default::default()
+ };
+ let mut target = EntityView {
+ kind: "minecraft:sulfur_cube".into(),
+ ..Default::default()
+ };
+ let mut stack = ItemView {
+ id: "minecraft:tnt".into(),
+ count: 1,
+ ..Default::default()
+ };
+ for criterion in &advancement.criteria {
+ assert!(item_entity(
+ &criterion.conditions,
+ &player,
+ &target,
+ &stack,
+ &Flat
+ ));
+ let mut progress = Progress::default();
+ progress.grant(&advancement.id, &criterion.name, "test");
+ assert!(
+ progress.done(&advancement),
+ "either criterion must award Uh Oh"
+ );
+ target.baby = true;
+ assert!(!item_entity(
+ &criterion.conditions,
+ &player,
+ &target,
+ &stack,
+ &Flat
+ ));
+ target.baby = false;
+ target.kind = "minecraft:pig".into();
+ assert!(!item_entity(
+ &criterion.conditions,
+ &player,
+ &target,
+ &stack,
+ &Flat
+ ));
+ target.kind = "minecraft:sulfur_cube".into();
+ stack.id = "minecraft:stone".into();
+ assert!(!item_entity(
+ &criterion.conditions,
+ &player,
+ &target,
+ &stack,
+ &Flat
+ ));
+ stack.id = "minecraft:tnt".into();
}
}
#[test]
diff --git a/crates/horizon-client/src/assets.rs b/crates/horizon-client/src/assets.rs
index b8551a059..c42f0aaf7 100644
--- a/crates/horizon-client/src/assets.rs
+++ b/crates/horizon-client/src/assets.rs
@@ -2,14 +2,13 @@ use crate::Result;
use horizon_world::{
DATA_VERSION,
heightmap::HeightmapState,
- nbt::Tag,
registry::{BlockRegistry, BlockStateId},
worldgen::{tags::TagDefinitions, terrain::TerrainBlockStates},
};
use serde_json::Value;
use std::{
collections::BTreeSet,
- fs::{self, File},
+ fs::File,
io::{self, BufReader},
path::Path,
sync::Arc,
@@ -74,24 +73,6 @@ pub struct Assets {
fn invalid(message: &str) -> io::Error {
io::Error::new(io::ErrorKind::InvalidData, message)
}
-fn tag(value: &Value) -> Result {
- Ok(match value {
- Value::String(value) => Tag::String(value.as_str().into()),
- Value::Number(value) => Tag::Int(i32::try_from(
- value
- .as_i64()
- .ok_or_else(|| invalid("invalid registry number"))?,
- )?),
- Value::Array(values) => Tag::List(values.iter().map(tag).collect::>()?),
- Value::Object(values) => Tag::Compound(
- values
- .iter()
- .map(|(name, value)| Ok((name.as_str().into(), tag(value)?)))
- .collect::>()?,
- ),
- _ => return Err(invalid("unsupported registry value").into()),
- })
-}
impl Assets {
pub fn load(root: &Path) -> Result {
let manifest: Value = serde_json::from_reader(BufReader::new(File::open(
@@ -100,23 +81,8 @@ impl Assets {
if manifest["data_version"].as_i64() != Some(i64::from(DATA_VERSION)) {
return Err(invalid("resources do not match Horizon's pinned data version").into());
}
- let facts: Value = serde_json::from_slice(&fs::read(root.join("facts.json"))?)?;
- let states = facts["states"]
- .as_array()
- .ok_or_else(|| invalid("missing registry state facts"))?;
- let registry = BlockRegistry::from_nbt(&Tag::compound([
- ("DataVersion", Tag::Int(DATA_VERSION)),
- (
- "states",
- Tag::List(
- states
- .iter()
- .map(|state| tag(&state[4]))
- .collect::>()?,
- ),
- ),
- ("defaults", tag(&facts["defaults"])?),
- ]))?;
+ let (registry, flags) =
+ BlockRegistry::from_facts_json_with_flags(File::open(root.join("facts.json"))?)?;
let bundle: Value =
serde_json::from_reader(BufReader::new(File::open(root.join("block-tags.json"))?))?;
let mut definitions = TagDefinitions::default();
@@ -132,7 +98,7 @@ impl Assets {
)?;
}
let built =
- definitions.build(|name, _| facts["defaults"].get(name).map(|_| name.to_owned()))?;
+ definitions.build(|name, _| registry.default_state(name).map(|_| name.to_owned()))?;
if !built.missing.is_empty() {
return Err(invalid("unresolved block tags").into());
}
@@ -158,27 +124,20 @@ impl Assets {
.cloned()
.collect();
let properties = Properties(Arc::new(
- states
+ flags
.iter()
- .map(|state| {
+ .enumerate()
+ .map(|(i, &(air, fluid))| {
+ let name = ®istry
+ .state(BlockStateId(i as u32))
+ .ok_or_else(|| invalid("missing registry state"))?
+ .name;
Ok(StateFacts {
- air: state[1]
- .as_bool()
- .ok_or_else(|| invalid("missing air fact"))?,
- fluid: state[2]
- .as_bool()
- .ok_or_else(|| invalid("missing fluid fact"))?,
- air_block: state[0].as_str() == Some("minecraft:air"),
- motion: motion.contains(
- state[0]
- .as_str()
- .ok_or_else(|| invalid("missing state name"))?,
- ),
- no_leaves: no_leaves.contains(
- state[0]
- .as_str()
- .ok_or_else(|| invalid("missing state name"))?,
- ),
+ air,
+ fluid,
+ air_block: name == "minecraft:air",
+ motion: motion.contains(name.as_str()),
+ no_leaves: no_leaves.contains(name.as_str()),
})
})
.collect::>()?,
@@ -189,6 +148,9 @@ impl Assets {
.default_state(&format!("minecraft:{name}"))
.ok_or_else(|| invalid("missing test-scene material"))?;
}
+ // Chunks hold every state of this registry: content mods can take it
+ // past vanilla's 16-bit global palette.
+ crate::chunk::set_block_states(registry.len());
let registry: &'static BlockRegistry = Box::leak(Box::new(registry));
Self::with_models(
root,
diff --git a/crates/horizon-client/src/block_entities.rs b/crates/horizon-client/src/block_entities.rs
new file mode 100644
index 000000000..93abb3711
--- /dev/null
+++ b/crates/horizon-client/src/block_entities.rs
@@ -0,0 +1,395 @@
+//! The world's block entities and the order they tick in: vanilla's
+//! `Level.blockEntityTickers`, kept beside the block entity map so a tick
+//! visits only the block entities that tick, in vanilla's order, instead of
+//! scanning the whole map once per kind.
+//!
+//! The list follows `LevelChunk.updateBlockEntityTicker` and
+//! `Level.tickBlockEntities`:
+//! - a block entity whose block state has a ticker gets a slot at the end of
+//! the list (through `pendingBlockEntityTickers`, so a slot made during a
+//! tick first ticks on the next one);
+//! - replacing the block entity at a position (`setBlockEntity`), or changing
+//! its block state to another state with a ticker, keeps its slot
+//! (`RebindableTickingBlockEntityWrapper.rebind`);
+//! - removing it (`removeBlockEntity`), unloading its chunk
+//! (`clearAllBlockEntities`) or changing its state to one without a ticker
+//! (a jukebox losing its record) frees the slot; a later ticker there is
+//! appended again;
+//! - a loaded chunk's block entities are added in the iteration order of its
+//! `Object2ObjectOpenHashMap`
+//! (`registerAllBlockEntitiesAfterLevelLoad`), filled in the order the chunk
+//! listed them.
+//!
+//! Which states tick is a table by state id, built by the game from the block
+//! registry; whether a slot is made is decided when the slot is promoted at
+//! the start of the next tick, from the block state then.
+use crate::containers::BlockEntity;
+use crate::fast_hash::{FxHashMap, FxHashSet};
+use std::collections::HashMap;
+
+pub type Pos = (i32, i32, i32);
+
+/// What a block state's block entity does each tick (`BlockState.getTicker`).
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub enum Ticking {
+ /// No ticker, and the block has no block entity that could have one.
+ #[default]
+ No,
+ /// A ticker.
+ Yes,
+ /// The block's block entity, but this state has no ticker (a jukebox
+ /// without a record): a state change to it frees the slot.
+ Idle,
+}
+
+#[derive(Default)]
+pub struct BlockEntities {
+ map: HashMap,
+ /// `Level.blockEntityTickers`: positions and the slot each was given.
+ tickers: Vec<(Pos, u32)>,
+ /// `LevelChunk.tickersInLevel`: the live slot of each ticking position.
+ live: FxHashMap,
+ /// Positions that may need a slot, in the order vanilla would have made
+ /// it (`pendingBlockEntityTickers`), each with a token; decided at the
+ /// next promotion from the block state then.
+ added: Vec<(Pos, u32)>,
+ /// The token of each position's pending entry: an entry whose token is
+ /// not here any more was cancelled.
+ pending: FxHashMap,
+ next_slot: u32,
+ /// Whether a slot was freed since the list was last swept: otherwise
+ /// every slot in it is still live, unless its block entity is `out`.
+ freed: bool,
+ /// Positions whose block entity `take` took and `put` has not brought
+ /// back.
+ out: FxHashSet,
+ /// `Ticking` by block state id; empty until the game builds it.
+ states: Vec,
+}
+
+impl std::ops::Deref for BlockEntities {
+ type Target = HashMap;
+ fn deref(&self) -> &Self::Target {
+ &self.map
+ }
+}
+
+impl<'a> IntoIterator for &'a BlockEntities {
+ type Item = (&'a Pos, &'a BlockEntity);
+ type IntoIter = std::collections::hash_map::Iter<'a, Pos, BlockEntity>;
+ fn into_iter(self) -> Self::IntoIter {
+ self.map.iter()
+ }
+}
+
+/// `Vec3i.hashCode`.
+fn java_hash((x, y, z): Pos) -> i32 {
+ y.wrapping_add(z.wrapping_mul(31))
+ .wrapping_mul(31)
+ .wrapping_add(x)
+}
+/// `HashCommon.mix`.
+fn mix(x: i32) -> usize {
+ let h = (x as u32).wrapping_mul(0x9E37_79B9);
+ (h ^ (h >> 16)) as usize
+}
+
+/// The order `values().forEach` visits a `new Object2ObjectOpenHashMap<>()`
+/// keyed by these positions, put in this order (repeats keep their first
+/// slot): open addressing with linear probing, a rehash to twice the size
+/// past three quarters full, and iteration from the last slot down.
+pub fn chunk_map_order(positions: impl IntoIterator- ) -> Vec
{
+ // HashCommon.arraySize(16, .75f), and maxFill of each size.
+ let mut slots: Vec> = vec![None; 32];
+ let max_fill = |n: usize| (n * 3).div_ceil(4).min(n - 1);
+ let mut size = 0;
+ for p in positions {
+ let mask = slots.len() - 1;
+ let mut at = mix(java_hash(p)) & mask;
+ let mut known = false;
+ while let Some(k) = slots[at] {
+ if k == p {
+ known = true;
+ break;
+ }
+ at = (at + 1) & mask;
+ }
+ if known {
+ continue;
+ }
+ slots[at] = Some(p);
+ // `if (size++ >= maxFill) rehash(arraySize(size + 1, f))`, which
+ // puts the keys back from the last slot down.
+ size += 1;
+ if size > max_fill(slots.len()) {
+ let n = ((size + 1) * 4).div_ceil(3).next_power_of_two();
+ let old = std::mem::replace(&mut slots, vec![None; n]);
+ for k in old.into_iter().rev().flatten() {
+ let mut at = mix(java_hash(k)) & (n - 1);
+ while slots[at].is_some() {
+ at = (at + 1) & (n - 1);
+ }
+ slots[at] = Some(k);
+ }
+ }
+ }
+ slots.into_iter().rev().flatten().collect()
+}
+
+impl BlockEntities {
+ /// Whether the ticking table has been built.
+ pub fn has_states(&self) -> bool {
+ !self.states.is_empty()
+ }
+ pub fn set_states(&mut self, states: Vec) {
+ self.states = states;
+ }
+ pub fn take_states(&mut self) -> Vec {
+ std::mem::take(&mut self.states)
+ }
+ pub fn ticking(&self, state: u32) -> Ticking {
+ self.states.get(state as usize).copied().unwrap_or_default()
+ }
+
+ fn next(&mut self) -> u32 {
+ let n = self.next_slot;
+ self.next_slot = n.wrapping_add(1);
+ n
+ }
+ /// A ticker may be made for `pos` now (`updateBlockEntityTicker`).
+ fn add(&mut self, pos: Pos) {
+ let token = self.next();
+ self.pending.insert(pos, token);
+ self.added.push((pos, token));
+ }
+ /// `removeBlockEntityTicker`: no slot, made or pending.
+ fn cancel(&mut self, pos: &Pos) {
+ self.freed |= self.live.remove(pos).is_some();
+ self.pending.remove(pos);
+ }
+
+ pub fn get_mut(&mut self, pos: &Pos) -> Option<&mut BlockEntity> {
+ self.map.get_mut(pos)
+ }
+ pub fn iter_mut(&mut self) -> impl Iterator- {
+ self.map.iter_mut()
+ }
+ pub fn values_mut(&mut self) -> impl Iterator
- {
+ self.map.values_mut()
+ }
+ /// `LevelChunk.setBlockEntity` (+ `addAndRegisterBlockEntity`): a new
+ /// block entity may get a slot; one replacing another keeps its slot.
+ pub fn insert(&mut self, pos: Pos, entity: BlockEntity) -> Option
{
+ let old = self.map.insert(pos, entity);
+ if old.is_none() {
+ self.add(pos);
+ }
+ old
+ }
+ /// The block entity at `pos`, made by `make` when there is none.
+ pub fn get_or_insert_with(
+ &mut self,
+ pos: Pos,
+ make: impl FnOnce() -> BlockEntity,
+ ) -> &mut BlockEntity {
+ if !self.map.contains_key(&pos) {
+ self.add(pos);
+ }
+ self.map.entry(pos).or_insert_with(make)
+ }
+ /// `LevelChunk.removeBlockEntity`: the block entity and its slot.
+ pub fn remove(&mut self, pos: &Pos) -> Option {
+ self.cancel(pos);
+ self.map.remove(pos)
+ }
+ /// The block entity at `pos`, out of the map for a while: its slot stays
+ /// for `put` to bring it back (a tick working on it).
+ pub fn take(&mut self, pos: &Pos) -> Option {
+ let taken = self.map.remove(pos);
+ if taken.is_some() {
+ self.out.insert(*pos);
+ }
+ taken
+ }
+ /// Brings back what `take` took, in its slot.
+ pub fn put(&mut self, pos: Pos, entity: BlockEntity) {
+ self.out.remove(&pos);
+ if self.map.insert(pos, entity).is_none()
+ && !self.live.contains_key(&pos)
+ && !self.pending.contains_key(&pos)
+ {
+ self.add(pos);
+ }
+ }
+ /// Removes the block entities `keep` refuses, and their slots
+ /// (`clearAllBlockEntities` of unloaded chunks).
+ pub fn retain(&mut self, mut keep: impl FnMut(&Pos, &mut BlockEntity) -> bool) {
+ let (live, pending, freed) = (&mut self.live, &mut self.pending, &mut self.freed);
+ self.map.retain(|p, e| {
+ let kept = keep(p, e);
+ if !kept {
+ *freed |= live.remove(p).is_some();
+ pending.remove(p);
+ }
+ kept
+ });
+ }
+ pub fn clear(&mut self) {
+ self.map.clear();
+ self.tickers.clear();
+ self.live.clear();
+ self.added.clear();
+ self.pending.clear();
+ self.out.clear();
+ self.freed = false;
+ }
+ /// A loaded or generated chunk's block entities, in the order the chunk
+ /// lists them; they tick in its block entity map's order
+ /// (`registerAllBlockEntitiesAfterLevelLoad`).
+ pub fn load_chunk(&mut self, entities: Vec<(Pos, BlockEntity)>) {
+ let order = chunk_map_order(entities.iter().map(|(p, _)| *p));
+ for (p, e) in entities {
+ self.map.insert(p, e);
+ }
+ for p in order {
+ self.add(p);
+ }
+ }
+ /// `LevelChunk.setBlockState` on a block entity's position, from state
+ /// `old` to `new`: a ticker made, kept or dropped.
+ pub fn state_changed(&mut self, pos: Pos, old: u32, new: u32) {
+ if self.states.is_empty() || !self.map.contains_key(&pos) {
+ return;
+ }
+ match self.ticking(new) {
+ // A new ticker, unless one was made or is pending (rebound).
+ Ticking::Yes => {
+ if self.ticking(old) != Ticking::Yes && !self.live.contains_key(&pos) {
+ self.add(pos);
+ }
+ }
+ Ticking::Idle => self.cancel(&pos),
+ // Another block: the game removes or replaces the block entity.
+ Ticking::No => {}
+ }
+ }
+ /// The start of `Level.tickBlockEntities`: pending slots join the list
+ /// and freed ones leave it. `state` reads the block state at a position.
+ /// Returns the slots to tick, in order; check each with `is_live` before
+ /// ticking it, as the ticks before it can free it.
+ pub fn tickers(&mut self, state: impl Fn(Pos) -> u32) -> Vec<(Pos, u32)> {
+ for (pos, token) in std::mem::take(&mut self.added) {
+ if self.pending.get(&pos) != Some(&token) {
+ continue;
+ }
+ self.pending.remove(&pos);
+ if self.live.contains_key(&pos)
+ || !self.map.contains_key(&pos)
+ || self.ticking(state(pos)) != Ticking::Yes
+ {
+ continue;
+ }
+ let slot = self.next();
+ self.live.insert(pos, slot);
+ self.tickers.push((pos, slot));
+ }
+ if !std::mem::take(&mut self.freed) && self.out.is_empty() {
+ return self.tickers.clone();
+ }
+ self.out.clear();
+ let (live, map) = (&mut self.live, &self.map);
+ self.tickers.retain(|(p, slot)| {
+ let mine = live.get(p) == Some(slot);
+ if mine && !map.contains_key(p) {
+ live.remove(p);
+ }
+ mine && map.contains_key(p)
+ });
+ self.tickers.clone()
+ }
+ /// Whether a slot from `tickers` still ticks.
+ pub fn is_live(&self, (pos, slot): (Pos, u32)) -> bool {
+ self.live.get(&pos) == Some(&slot) && self.map.contains_key(&pos)
+ }
+ /// Frees the slot at `pos` (the block entity stays).
+ pub fn forget(&mut self, pos: &Pos) {
+ self.cancel(pos);
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn hopper() -> BlockEntity {
+ BlockEntity::Chest(vec![None; 5])
+ }
+ /// States: 0 air, 1 ticks, 2 idle.
+ fn level() -> BlockEntities {
+ let mut b = BlockEntities::default();
+ b.set_states(vec![Ticking::No, Ticking::Yes, Ticking::Idle]);
+ b
+ }
+ fn order(b: &mut BlockEntities, states: &HashMap) -> Vec {
+ b.tickers(|p| states.get(&p).copied().unwrap_or(0))
+ .into_iter()
+ .map(|(p, _)| p)
+ .collect()
+ }
+
+ #[test]
+ fn slots_follow_vanilla_lifecycle() {
+ let mut b = level();
+ let mut s = HashMap::new();
+ for p in [(0, 0, 0), (1, 0, 0), (2, 0, 0)] {
+ s.insert(p, 1);
+ b.insert(p, hopper());
+ }
+ assert_eq!(order(&mut b, &s), [(0, 0, 0), (1, 0, 0), (2, 0, 0)]);
+ // Replacing keeps the slot; removing and placing again appends.
+ b.insert((0, 0, 0), hopper());
+ b.remove(&(1, 0, 0));
+ b.insert((1, 0, 0), hopper());
+ assert_eq!(order(&mut b, &s), [(0, 0, 0), (2, 0, 0), (1, 0, 0)]);
+ // Take and put keep it; an idle state frees it, ticking again appends.
+ let e = b.take(&(0, 0, 0)).unwrap();
+ b.put((0, 0, 0), e);
+ assert_eq!(order(&mut b, &s), [(0, 0, 0), (2, 0, 0), (1, 0, 0)]);
+ s.insert((2, 0, 0), 2);
+ b.state_changed((2, 0, 0), 1, 2);
+ assert_eq!(order(&mut b, &s), [(0, 0, 0), (1, 0, 0)]);
+ s.insert((2, 0, 0), 1);
+ b.state_changed((2, 0, 0), 2, 1);
+ assert_eq!(order(&mut b, &s), [(0, 0, 0), (1, 0, 0), (2, 0, 0)]);
+ // A slot freed during a tick is not live any more.
+ let slots = b.tickers(|p| s.get(&p).copied().unwrap_or(0));
+ b.retain(|p, _| *p != (1, 0, 0));
+ assert!(b.is_live(slots[0]) && !b.is_live(slots[1]));
+ // A block entity taken and never brought back loses its slot.
+ b.take(&(0, 0, 0));
+ assert_eq!(order(&mut b, &s), [(2, 0, 0)]);
+ assert_eq!(order(&mut b, &s), [(2, 0, 0)]);
+ }
+
+ #[test]
+ fn chunk_loads_in_open_hash_map_order() {
+ // A few keys: their mixed hashes over 32 slots, read from the top.
+ let positions = [
+ (0, 64, 0),
+ (1, 64, 0),
+ (0, 64, 1),
+ (15, -64, 15),
+ (3, 70, 9),
+ ];
+ let slot = |p: &Pos| mix(java_hash(*p)) & 31;
+ let mut expected = positions.to_vec();
+ expected.sort_by_key(|p| std::cmp::Reverse(slot(p)));
+ let distinct: std::collections::HashSet = positions.iter().map(slot).collect();
+ assert_eq!(distinct.len(), positions.len());
+ assert_eq!(chunk_map_order(positions), expected);
+ // Past 24 keys the table doubles; every key stays, once.
+ let many: Vec = (0..100).map(|i| (i % 16, i / 16, 3)).collect();
+ let order = chunk_map_order(many.iter().copied().chain(many.iter().copied()));
+ assert_eq!(order.len(), 100);
+ }
+}
diff --git a/crates/horizon-client/src/block_entity_render.rs b/crates/horizon-client/src/block_entity_render.rs
index 9c90e8ebf..db6bf7b79 100644
--- a/crates/horizon-client/src/block_entity_render.rs
+++ b/crates/horizon-client/src/block_entity_render.rs
@@ -737,6 +737,8 @@ pub struct Scene<'a> {
pub struct BlockEntityRenderer {
models: HashMap<&'static str, ModelPart>,
kinds: Vec,
+ // Closed chest geometry: dimension lighting, chest part, horizontal facing.
+ closed_chests: [[[Vec; 4]; 3]; 2],
/// Item id to its `PROVIDES_POTTERY_PATTERN` side texture (`Sheets.DECORATED_POT_MAPPER`).
pot_patterns: HashMap,
/// `Block.shouldRenderFace` for End gateway faces (its occlusion pair cache needs a lock).
@@ -817,6 +819,43 @@ impl BlockEntityRenderer {
Ok(renderer)
}
fn new(models: HashMap<&'static str, ModelPart>, registry: &BlockRegistry) -> Self {
+ let closed_chests = [false, true].map(|nether| {
+ ["chest", "double_chest_left", "double_chest_right"].map(|name| {
+ [0.0f32, 90.0, 180.0, 270.0].map(|y_rot| {
+ let mut vertices = Vec::new();
+ if let Some(model) = models.get(name) {
+ draw_part(
+ model,
+ "root",
+ around(
+ Mat4::from_rotation_y((-y_rot).to_radians()),
+ Vec3::new(0.5, 0.0, 0.5),
+ ),
+ &|name, p| {
+ if name == "lid" || name == "lock" {
+ p[3] = crate::block_entity_anim::chest_lid_x_rot(0.0);
+ }
+ },
+ Paint {
+ sprite: Rect {
+ u0: 0.0,
+ v0: 0.0,
+ u1: 1.0,
+ v1: 1.0,
+ w: 16,
+ h: 16,
+ },
+ tint: 0xFFFFFF,
+ light: 0,
+ lights: diffuse_lights(nether),
+ },
+ &mut vertices,
+ );
+ }
+ vertices
+ })
+ })
+ });
let kinds = (0..registry.len() as u32)
.map(|id| {
registry.state(BlockStateId(id)).map_or(Kind::None, |s| {
@@ -831,6 +870,7 @@ impl BlockEntityRenderer {
Self {
models,
kinds,
+ closed_chests,
pot_patterns: HashMap::new(),
visibility: None,
}
@@ -876,7 +916,7 @@ impl BlockEntityRenderer {
.as_vec3();
let base = Mat4::from_translation(origin);
let packed = scene.world.light(pos[0], pos[1], pos[2]);
- self.render_one(scene, *pos, kind, base, packed, lights, false, out);
+ self.render_one(scene, *pos, kind, base, packed, lights, false, true, out);
}
}
/// One block entity at `pos` drawn under `base` with the given packed light
@@ -892,7 +932,7 @@ impl BlockEntityRenderer {
) {
let kind = self.kind(state);
let lights = diffuse_lights(scene.nether);
- self.render_one(scene, pos, kind, base, packed, lights, false, out);
+ self.render_one(scene, pos, kind, base, packed, lights, false, false, out);
}
/// Whether this block state has a block-entity renderer here.
pub fn renders(&self, state: u32) -> bool {
@@ -915,6 +955,7 @@ impl BlockEntityRenderer {
0xff,
diffuse_lights(scene.nether),
true,
+ false,
out,
);
crate::breaking::entity_geometry(&mut out[start..], origin);
@@ -991,7 +1032,17 @@ impl BlockEntityRenderer {
let kind = self.kind(state);
if !matches!(kind, Kind::None) {
let lights = diffuse_lights(scene.nether);
- self.render_one(scene, [i32::MAX; 3], kind, base, packed, lights, false, out);
+ self.render_one(
+ scene,
+ [i32::MAX; 3],
+ kind,
+ base,
+ packed,
+ lights,
+ false,
+ false,
+ out,
+ );
}
}
#[allow(clippy::too_many_arguments)]
@@ -1004,6 +1055,7 @@ impl BlockEntityRenderer {
packed: u8,
lights: (Vec3, Vec3),
crumbling: bool,
+ world_chests: bool,
out: &mut Vec,
) {
let sprite = |name: &str| scene.sprites.get(name).copied();
@@ -1107,6 +1159,23 @@ impl BlockEntityRenderer {
let l = scene.world.light(other[0], other[1], other[2]);
packed = (packed >> 4).max(l >> 4) << 4 | (packed & 15).max(l & 15);
}
+ if world_chests && open == 0.0 {
+ if let Some(paint) = paint(texture, 0xFFFFFF, packed) {
+ let vertices = &self.closed_chests[usize::from(scene.nether)]
+ [*part as usize][*y_rot as usize / 90];
+ let origin = base.w_axis.truncate();
+ out.extend(vertices.iter().map(|v| Vertex {
+ pos: (Vec3::from_array(v.pos) + origin).to_array(),
+ uv: [
+ paint.sprite.u0 + (paint.sprite.u1 - paint.sprite.u0) * v.uv[0],
+ paint.sprite.v0 + (paint.sprite.v1 - paint.sprite.v0) * v.uv[1],
+ ],
+ light: paint.light,
+ ..*v
+ }));
+ }
+ return;
+ }
let m = base
* around(
Mat4::from_rotation_y((-y_rot).to_radians()),
@@ -1791,16 +1860,18 @@ mod tests {
(
name.to_owned(),
Rect {
- u0: 0.0,
- v0: 0.0,
- u1: 1.0,
- v1: 1.0,
+ u0: 0.25,
+ v0: 0.125,
+ u1: 0.375,
+ v1: 0.25,
w: 16,
h: 16,
},
)
})
.collect();
+ let cache_open = std::cell::Cell::new(0.0);
+ let cache_lid = |_| cache_open.get();
let mut scene = Scene {
camera: DVec3::ZERO,
orientation: Quat::IDENTITY,
@@ -1817,6 +1888,56 @@ mod tests {
banner: &|_| Vec::new(),
glyph: &|_| (None, 0.0),
};
+ // Compare the cached world path with the original model renderer,
+ // including atlas replacement, current light and animated fallback.
+ scene.lid = &cache_lid;
+ for nether in [false, true] {
+ scene.nether = nether;
+ for part in [ChestPart::Single, ChestPart::Left, ChestPart::Right] {
+ for y_rot in [0.0, 90.0, 180.0, 270.0] {
+ let kind = Kind::Chest {
+ block: "chest".into(),
+ texture: "entity/chest/normal",
+ part,
+ y_rot,
+ double_with: None,
+ };
+ for (open, packed) in [(0.0, 0xF0), (0.0, 0x7F), (0.5, 0x7F)] {
+ cache_open.set(open);
+ let base = Mat4::from_translation(Vec3::new(3.25, -8.5, 12.75));
+ let mut cached = Vec::new();
+ let mut original = Vec::new();
+ for (use_cache, out) in [(true, &mut cached), (false, &mut original)] {
+ renderer.render_one(
+ &scene,
+ [0; 3],
+ &kind,
+ base,
+ packed,
+ diffuse_lights(nether),
+ false,
+ use_cache,
+ out,
+ );
+ }
+ assert!(!cached.is_empty());
+ assert_eq!(cached.len(), original.len());
+ for (a, b) in cached.iter().zip(&original) {
+ assert!(
+ (Vec3::from_array(a.pos) - Vec3::from_array(b.pos)).length() < 3e-6
+ );
+ assert_eq!(a.uv, b.uv);
+ assert_eq!(a.color, b.color);
+ assert_eq!(a.light, b.light);
+ assert_eq!(a.normal, b.normal);
+ assert_eq!(a.layer, b.layer);
+ }
+ }
+ }
+ }
+ }
+ scene.nether = false;
+ scene.lid = &|_| 0.0;
for state in 0..names.len() as u32 {
let mut base = Vec::new();
renderer.render_block(&scene, [0; 3], state, Mat4::IDENTITY, 0xff, &mut base);
diff --git a/crates/horizon-client/src/chat.rs b/crates/horizon-client/src/chat.rs
index 6156a041d..7c51a40f1 100644
--- a/crates/horizon-client/src/chat.rs
+++ b/crates/horizon-client/src/chat.rs
@@ -386,6 +386,12 @@ pub struct ChatScreen {
parse: Option,
/// The completions at the cursor (`pendingSuggestions`): range start (bytes) and list.
pending: Option<(usize, Vec)>,
+ /// Completions waiting for the server's (an `ask_server` node at the
+ /// cursor): `pendingSuggestions` is not done until they come.
+ awaiting: Option,
+ /// The request to send (`ServerboundCommandSuggestionPacket`): id and
+ /// the command up to the cursor.
+ request: Option<(i32, String)>,
suggestions: Option,
usage: Vec,
usage_position: i32,
@@ -394,6 +400,16 @@ pub struct ChatScreen {
keep_suggestions: bool,
pub auto_suggestions: bool,
}
+/// Local completions waiting for the server's reply to request `id`.
+struct Awaiting {
+ id: i32,
+ /// The command up to the cursor, as sent.
+ truncated: String,
+ local: Vec,
+}
+/// `ClientSuggestionProvider.pendingSuggestionsId`: one counter for the
+/// connection, so a reply to an older request never matches.
+static SUGGESTION_ID: std::sync::atomic::AtomicI32 = std::sync::atomic::AtomicI32::new(0);
/// `CommandSuggestions`' fill colour.
const FILL: i32 = -805306368;
fn byte_at(s: &str, chars: usize) -> usize {
@@ -442,6 +458,8 @@ impl ChatScreen {
history_pos: history_len,
parse: None,
pending: None,
+ awaiting: None,
+ request: None,
suggestions: None,
usage: Vec::new(),
usage_position: 0,
@@ -518,24 +536,84 @@ impl ChatScreen {
}
if cursor >= 1 && (self.suggestions.is_none() || !self.keep_suggestions) {
let parse = self.parse.as_ref().expect("parsed above");
- let (range, list) = c
- .dispatcher
- .client_suggestions(parse, cursor_b, c.registries);
- self.pending = Some((range.0, list));
- self.update_usage_info(m, c);
+ let (range, list, ask) =
+ c.dispatcher
+ .client_suggestions_asking(parse, cursor_b, c.registries);
+ if ask {
+ // ClientSuggestionProvider.customSuggestion: the
+ // suggestions are done when the server answers.
+ let id = SUGGESTION_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
+ let truncated = command[..cursor_b].to_owned();
+ self.request = Some((id, truncated.clone()));
+ self.awaiting = Some(Awaiting {
+ id,
+ truncated,
+ local: list,
+ });
+ self.pending = None;
+ } else {
+ self.awaiting = None;
+ self.pending = Some((range.0, list));
+ self.update_usage_info(m, c);
+ }
}
} else if !command.chars().all(char::is_whitespace) {
let partial = &command[..cursor_b];
let mut builder = SuggestionsBuilder::new(partial, last_word_index(partial));
builder.suggest_matching(c.registries.players.iter().map(String::as_str));
let (range, list) = merge_suggestions(partial, builder.out);
+ self.awaiting = None;
self.pending = Some((range.0, list));
self.usage_width = 0;
self.usage_position = 0;
} else {
+ self.awaiting = None;
self.pending = None;
}
}
+ /// The completion request to send to the server, if one is waiting.
+ pub fn take_request(&mut self) -> Option<(i32, String)> {
+ self.request.take()
+ }
+ /// `ClientSuggestionProvider.completeCustomSuggestions`: the server's
+ /// completions for request `id`, with `range` in UTF-16 units of the
+ /// command sent. They join the local ones (`Suggestions.merge`) and the
+ /// pending suggestions are done.
+ pub fn server_suggestions(
+ &mut self,
+ m: &Measure,
+ c: &Commands,
+ id: i32,
+ range: (usize, usize),
+ list: Vec<(String, Option)>,
+ ) {
+ let Some(awaiting) = self.awaiting.take_if(|a| a.id == id) else {
+ return;
+ };
+ let input = &awaiting.truncated;
+ let byte = |units: usize| {
+ let mut n = 0;
+ input
+ .char_indices()
+ .find(|(_, ch)| {
+ let past = n >= units;
+ n += ch.len_utf16();
+ past
+ })
+ .map_or(input.len(), |(i, _)| i)
+ };
+ let range = (byte(range.0), byte(range.0 + range.1));
+ let mut all = awaiting.local;
+ all.extend(list.into_iter().map(|(text, tooltip)| Suggestion {
+ range,
+ text,
+ tooltip,
+ int_value: None,
+ }));
+ let (range, list) = merge_suggestions(input, all);
+ self.pending = Some((range.0, list));
+ self.update_usage_info(m, c);
+ }
/// `CommandSuggestions.updateUsageInfo`.
fn update_usage_info(&mut self, m: &Measure, c: &Commands) {
let Some(parse) = &self.parse else { return };
diff --git a/crates/horizon-client/src/chat_tests.rs b/crates/horizon-client/src/chat_tests.rs
index 3cbac071b..e1bf2feda 100644
--- a/crates/horizon-client/src/chat_tests.rs
+++ b/crates/horizon-client/src/chat_tests.rs
@@ -230,3 +230,58 @@ fn mod_commands_are_coloured_and_complete_like_vanilla_ones() {
screen.key(&m, &c, &[], winit::keyboard::KeyCode::Tab, false, false);
assert_eq!(screen.value(), "/coords");
}
+
+#[test]
+fn ask_server_nodes_wait_for_the_servers_completions() {
+ // ClientSuggestionProvider.customSuggestion: an `ask_server` node at the
+ // cursor sends the command so far, and the list is done with the reply.
+ let font = font();
+ let m = Measure(&font);
+ let registries = Registries {
+ permission: 4,
+ ..Registries::default()
+ };
+ let mut d = crate::command::vanilla::game_dispatcher().clone();
+ let child = |d: &crate::command::Dispatcher, n: usize, name: &str| {
+ d.nodes[n]
+ .children
+ .iter()
+ .copied()
+ .find(|&c| d.nodes[c].name() == name)
+ .expect(name)
+ };
+ let id = child(&d, child(&d, child(&d, 0, "bossbar"), "get"), "id");
+ d.nodes[id].suggests = Some(crate::command::Suggests::AskServer);
+ let c = Commands {
+ dispatcher: &d,
+ registries: ®istries,
+ };
+ let tab = |screen: &mut ChatScreen| {
+ screen.key(&m, &c, &[], winit::keyboard::KeyCode::Tab, false, false);
+ };
+ let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360);
+ screen.type_text(&m, &c, "/bossbar get pt");
+ let (request, sent) = screen.take_request().expect("the server is asked");
+ assert_eq!(sent, "/bossbar get pt");
+ assert_eq!(screen.take_request(), None);
+ // Nothing to complete until the reply.
+ tab(&mut screen);
+ assert_eq!(screen.value(), "/bossbar get pt");
+ // A reply to an older request is dropped; the range is in UTF-16 units.
+ let reply = |text: &str| vec![(text.to_owned(), None)];
+ screen.server_suggestions(&m, &c, request - 1, (13, 2), reply("pt6:old"));
+ tab(&mut screen);
+ assert_eq!(screen.value(), "/bossbar get pt");
+ screen.server_suggestions(&m, &c, request, (13, 2), reply("pt6:check"));
+ tab(&mut screen);
+ assert_eq!(screen.value(), "/bossbar get pt6:check");
+ // Without the server's provider the local list is done at once.
+ let local = crate::command::vanilla::game_dispatcher();
+ let c = Commands {
+ dispatcher: local,
+ registries: ®istries,
+ };
+ let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360);
+ screen.type_text(&m, &c, "/bossbar get pt");
+ assert_eq!(screen.take_request(), None);
+}
diff --git a/crates/horizon-client/src/chunk.rs b/crates/horizon-client/src/chunk.rs
index b0b2ef262..ce2c4ea71 100644
--- a/crates/horizon-client/src/chunk.rs
+++ b/crates/horizon-client/src/chunk.rs
@@ -9,11 +9,26 @@ pub const MIN_Y: i32 = -64;
pub const HEIGHT: i32 = 384;
pub const SECTIONS: usize = (HEIGHT / 16) as usize;
-/// Block states are `PalettedContainer`s over the pinned registry (35,723
-/// states: a 16-bit global palette); biomes are 4x4x4 containers over the
-/// biome table (67 entries: a 7-bit global palette).
-pub const BLOCK_STRATEGY: Strategy = Strategy::blocks(16);
+/// Biomes are 4x4x4 containers over the biome table (67 entries: a 7-bit
+/// global palette).
pub const BIOME_STRATEGY: Strategy = Strategy::biomes(7);
+
+/// Bits of the block states' global palette: 16 for vanilla's 35,723 states
+/// (what vanilla servers and clients send), more when content mods add states
+/// past 65,536 (docs/modpacks.md). Set once, before the first chunk.
+static BLOCK_BITS: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(16);
+
+/// Block states are `PalettedContainer`s over the registry: vanilla's 16-bit
+/// global palette, wider with enough content mods.
+pub fn block_strategy() -> Strategy {
+ Strategy::blocks(BLOCK_BITS.load(std::sync::atomic::Ordering::Relaxed))
+}
+
+/// Sizes the block states' global palette for a registry of `states`.
+pub fn set_block_states(states: usize) {
+ let bits = horizon_core::paletted::ceil_log2(states).max(16);
+ BLOCK_BITS.store(bits, std::sync::atomic::Ordering::Relaxed);
+}
/// Packed light per block: sky light in the high nibble, block light in the low one.
#[derive(Clone)]
pub enum Light {
@@ -43,7 +58,7 @@ pub struct Section {
impl Default for Section {
fn default() -> Self {
Self {
- blocks: PalettedContainer::new(BLOCK_STRATEGY, 0),
+ blocks: PalettedContainer::new(block_strategy(), 0),
biomes: PalettedContainer::new(BIOME_STRATEGY, 0),
light: Light::Uniform(0xF0),
}
@@ -51,27 +66,26 @@ impl Default for Section {
}
impl Section {
#[inline]
- pub fn get(&self, i: usize) -> u16 {
- self.blocks.get(i) as u16
+ pub fn get(&self, i: usize) -> u32 {
+ self.blocks.get(i)
}
- pub fn set(&mut self, i: usize, v: u16) -> u16 {
- self.blocks.set(i, u32::from(v)) as u16
+ pub fn set(&mut self, i: usize, v: u32) -> u32 {
+ self.blocks.set(i, v)
}
/// All 4,096 block states in index order.
- pub fn unpack(&self, out: &mut [u16; 4096]) {
- self.blocks.unpack_u16(out);
+ pub fn unpack(&self, out: &mut [u32; 4096]) {
+ self.blocks.unpack(out);
}
/// The block states of a whole section at once.
- pub fn from_blocks(values: &[u16; 4096]) -> PalettedContainer {
- let wide: Vec = values.iter().map(|&v| u32::from(v)).collect();
- PalettedContainer::from_values(BLOCK_STRATEGY, &wide)
+ pub fn from_blocks(values: &[u32; 4096]) -> PalettedContainer {
+ PalettedContainer::from_values(block_strategy(), values)
}
#[inline]
pub fn light(&self, i: usize) -> u8 {
self.light.get(i)
}
- pub fn is_uniform(&self, v: u16) -> bool {
- self.blocks.is_uniform(u32::from(v))
+ pub fn is_uniform(&self, v: u32) -> bool {
+ self.blocks.is_uniform(v)
}
/// Heap bytes held by the block, biome and light storage (benchmark accounting).
pub fn heap_bytes(&self) -> usize {
@@ -147,7 +161,7 @@ impl Chunk {
}
}
#[inline]
- pub fn get(&self, x: i32, y: i32, z: i32) -> u16 {
+ pub fn get(&self, x: i32, y: i32, z: i32) -> u32 {
let s = (y - MIN_Y) >> 4;
if !(0..SECTIONS as i32).contains(&s) {
return 0;
@@ -156,11 +170,11 @@ impl Chunk {
}
#[inline]
pub fn block(&self, x: i32, y: i32, z: i32) -> BlockStateId {
- BlockStateId(u32::from(self.get(x, y, z)))
+ BlockStateId(self.get(x, y, z))
}
/// The highest y where `matches`, scanning down. Sections holding only
/// `skip` are passed over whole: `matches` must be false for it.
- pub fn highest(&self, skip: u16, mut matches: impl FnMut(i32) -> bool) -> Option {
+ pub fn highest(&self, skip: u32, mut matches: impl FnMut(i32) -> bool) -> Option {
self.sections
.iter()
.enumerate()
@@ -171,7 +185,7 @@ impl Chunk {
(base..base + 16).rev().find(|&y| matches(y))
})
}
- pub fn set(&mut self, x: i32, y: i32, z: i32, v: u16) -> u16 {
+ pub fn set(&mut self, x: i32, y: i32, z: i32, v: u32) -> u32 {
let s = (y - MIN_Y) >> 4;
if !(0..SECTIONS as i32).contains(&s) {
return v;
@@ -228,15 +242,15 @@ mod tests {
Arc::make_mut(&mut chunk.sections[5]).set(i, cave_air);
}
chunk.set(3, 150, 4, stone);
- let full = |c: &Chunk, matches: &dyn Fn(u16) -> bool| {
+ let full = |c: &Chunk, matches: &dyn Fn(u32) -> bool| {
(MIN_Y..MIN_Y + HEIGHT)
.rev()
.find(|&y| matches(c.get(3, y, 4)))
};
for matches in [
- &(|v: u16| v != air) as &dyn Fn(u16) -> bool,
- &|v: u16| v == stone,
- &|v: u16| v == cave_air,
+ &(|v: u32| v != air) as &dyn Fn(u32) -> bool,
+ &|v: u32| v == stone,
+ &|v: u32| v == cave_air,
] {
let fast = chunk.highest(air, |y| matches(chunk.get(3, y, 4)));
assert_eq!(fast, full(&chunk, matches));
diff --git a/crates/horizon-client/src/chunk_map.rs b/crates/horizon-client/src/chunk_map.rs
index 81e06f020..ed25491c5 100644
--- a/crates/horizon-client/src/chunk_map.rs
+++ b/crates/horizon-client/src/chunk_map.rs
@@ -76,7 +76,7 @@ impl<'a> IntoIterator for &'a ChunkMap {
}
}
impl crate::light::LightWorld for ChunkMap {
- fn state(&self, x: i32, y: i32, z: i32) -> Option {
+ fn state(&self, x: i32, y: i32, z: i32) -> Option {
self.columns.state(x, y, z)
}
fn light(&self, x: i32, y: i32, z: i32) -> Option {
diff --git a/crates/horizon-client/src/collisions.rs b/crates/horizon-client/src/collisions.rs
index d3e00daca..5d5f4c1bb 100644
--- a/crates/horizon-client/src/collisions.rs
+++ b/crates/horizon-client/src/collisions.rs
@@ -15,24 +15,18 @@ use horizon_world::{
entity_obstruction::EntityIdentity,
fluid::{FluidKind, FluidState},
liquid_collision::LiquidCollisionWorld,
- nbt::{self, Limits},
powder_snow_collision::{PowderSnowEntity, PowderSnowWorld},
- registry::BlockRegistry,
+ registry::{BlockRegistry, BlockTableFile},
world_movement::{
CollisionCheckRequest, EntityMovementWorld, MovementRequest, no_world_collision,
resolve_world_movement,
},
};
-use std::{fs, io, path::Path, sync::Arc};
+use std::{io, path::Path, sync::Arc};
pub fn load<'r>(root: &Path, registry: &'r BlockRegistry) -> Result> {
- let data = nbt::read_named(
- &fs::read(root.join("cached-collision.nbt"))?,
- Limits::tables(),
- )?
- .0
- .tag;
- let cached = CachedCollisionRegistry::from_nbt(&data, registry)?;
+ let file = BlockTableFile::open(&root.join("cached-collision.nbt"), registry)?;
+ let cached = CachedCollisionRegistry::from_table(file.table("collision")?)?;
if !cached.has_canonical_identities() {
return Err("scene collisions require canonical shape identities".into());
}
diff --git a/crates/horizon-client/src/command/mod.rs b/crates/horizon-client/src/command/mod.rs
index 52e76100a..e9aeaae51 100644
--- a/crates/horizon-client/src/command/mod.rs
+++ b/crates/horizon-client/src/command/mod.rs
@@ -8,6 +8,7 @@ pub mod block;
pub mod codec;
pub mod component;
pub mod item;
+pub mod network;
pub mod packrat;
pub mod selector;
pub mod snbt;
@@ -311,6 +312,9 @@ pub enum Suggests {
/// ScoreboardCommand.suggestTriggers: trigger objectives some of the
/// parsed `targets` have no score in, or a locked one.
EnableTriggers,
+ /// SuggestionProviders.ASK_SERVER: the server completes the node
+ /// (ClientSuggestionProvider.customSuggestion); nothing locally.
+ AskServer,
}
impl Node {
pub fn name(&self) -> &str {
@@ -690,7 +694,7 @@ impl Suggests {
Suggests::Triggers => {
builder.suggest_matching(reg.trigger_objectives.iter().map(String::as_str))
}
- Suggests::Nothing => {}
+ Suggests::Nothing | Suggests::AskServer => {}
}
}
}
@@ -954,7 +958,8 @@ impl Dispatcher {
cursor: usize,
reg: &Registries,
) -> (Range, Vec) {
- self.suggestions_within(parse, cursor, reg, u8::MAX)
+ let (range, list, _) = self.suggestions_within(parse, cursor, reg, u8::MAX);
+ (range, list)
}
/// The suggestions the player's chat shows: the client's tree only holds
/// the nodes the player may use (Commands.sendCommands prunes by canUse).
@@ -964,6 +969,18 @@ impl Dispatcher {
cursor: usize,
reg: &Registries,
) -> (Range, Vec) {
+ let (range, list, _) = self.suggestions_within(parse, cursor, reg, reg.permission);
+ (range, list)
+ }
+ /// [`Self::client_suggestions`], and whether a node at the cursor asks
+ /// the server (`ask_server`): its completions come with the server's
+ /// reply, to be merged with these.
+ pub fn client_suggestions_asking(
+ &self,
+ parse: &ParseResults,
+ cursor: usize,
+ reg: &Registries,
+ ) -> (Range, Vec, bool) {
self.suggestions_within(parse, cursor, reg, reg.permission)
}
fn suggestions_within(
@@ -972,15 +989,17 @@ impl Dispatcher {
cursor: usize,
reg: &Registries,
permission: u8,
- ) -> (Range, Vec) {
+ ) -> (Range, Vec, bool) {
let (parent, start, context) = parse.context.suggestion_context(cursor);
let start = start.min(cursor);
let truncated = &parse.input[..cursor.min(parse.input.len())];
let mut all = Vec::new();
+ let mut ask = false;
for &child in &self.nodes[parent].children {
if self.nodes[child].permission > permission {
continue;
}
+ ask |= matches!(self.nodes[child].suggests, Some(Suggests::AskServer));
let mut builder = SuggestionsBuilder::new(truncated, start);
match &self.nodes[child].kind {
NodeKind::Literal(l) => {
@@ -996,7 +1015,8 @@ impl Dispatcher {
}
all.extend(builder.out);
}
- merge_suggestions(truncated, all)
+ let (range, list) = merge_suggestions(truncated, all);
+ (range, list, ask)
}
fn smart_usage_of(&self, node: usize, optional: bool, deep: bool, level: u8) -> Option {
let n = &self.nodes[node];
diff --git a/crates/horizon-client/src/command/network.rs b/crates/horizon-client/src/command/network.rs
new file mode 100644
index 000000000..8fed97db0
--- /dev/null
+++ b/crates/horizon-client/src/command/network.rs
@@ -0,0 +1,403 @@
+//! The command tree a server sends (ClientboundCommandsPacket) as a
+//! dispatcher the chat parses, colours and completes with
+//! (ClientPacketListener.handleCommands).
+//!
+//! The packet holds each argument's parser and its network properties. A
+//! node the client's own vanilla tree has at the same path takes that node's
+//! argument type and suggestion provider (the parsers' suggestion lists and
+//! the custom providers are the same code on both sides); any other node
+//! (another server's or a mod's) gets the type its parser and properties
+//! describe.
+use super::{ArgType, Dispatcher, Node, NodeKind, Suggests};
+use horizon_protocol::packets::play::{ARGUMENT_TYPES, ArgumentProperties, Commands};
+use std::{
+ collections::{HashSet, VecDeque},
+ sync::{Mutex, OnceLock},
+};
+
+/// The command id of every executable node of a server's tree: the chat
+/// sends the command, the server runs it.
+pub const SERVER_COMMAND: &str = "server";
+
+/// The dispatcher for a server's tree. `local` is the client's own tree
+/// (vanilla's), whose matching nodes lend their types and providers.
+pub fn from_packet(packet: &Commands, local: &Dispatcher) -> Dispatcher {
+ let count = packet.nodes.len();
+ let root = usize::try_from(packet.root)
+ .ok()
+ .filter(|&r| r < count)
+ .unwrap_or(0);
+ // The packet's root becomes node 0, the others follow in packet order.
+ let index = |i: usize| -> usize {
+ if i == root {
+ 0
+ } else if i < root {
+ i + 1
+ } else {
+ i
+ }
+ };
+ let valid = |c: &i32| usize::try_from(*c).ok().filter(|&c| c < count);
+ // The local node at the same path, found breadth first from the roots
+ // along children (redirects are not paths of their own).
+ let mut matched: Vec> = vec![None; count];
+ matched[root] = Some(0);
+ let mut queue = VecDeque::from([root]);
+ let mut seen = HashSet::from([root]);
+ while let Some(n) = queue.pop_front() {
+ for c in packet.nodes[n].children.iter().filter_map(valid) {
+ if !seen.insert(c) {
+ continue;
+ }
+ let node = &packet.nodes[c];
+ matched[c] = matched[n].and_then(|l| {
+ local.nodes[l].children.iter().copied().find(|&lc| {
+ let ln = &local.nodes[lc];
+ ln.name() == node.name
+ && matches!(
+ (&ln.kind, node.kind),
+ (NodeKind::Literal(_), 1) | (NodeKind::Argument { .. }, 2)
+ )
+ })
+ });
+ queue.push_back(c);
+ }
+ }
+ let mut nodes = vec![None; count];
+ for (i, node) in packet.nodes.iter().enumerate() {
+ let local_node = matched[i].map(|l| &local.nodes[l]);
+ let kind = match node.kind {
+ 1 => NodeKind::Literal(node.name.clone()),
+ 2 => {
+ let ty = match local_node.map(|l| &l.kind) {
+ Some(NodeKind::Argument { ty, .. }) => ty.clone(),
+ _ => node
+ .parser
+ .as_ref()
+ .map_or(ArgType::Word, |(id, props)| argument_type(*id, props)),
+ };
+ NodeKind::Argument {
+ name: node.name.clone(),
+ ty,
+ }
+ }
+ _ => NodeKind::Root,
+ };
+ // The server's providers, as the client knows them
+ // (ArgumentNodeStub.build): its own custom ones arrive as `ask_server`.
+ let suggests = node.suggestions.as_deref().and_then(provider);
+ nodes[index(i)] = Some(Node {
+ kind: if i == root { NodeKind::Root } else { kind },
+ children: node.children.iter().filter_map(valid).map(index).collect(),
+ command: node.executable.then_some(SERVER_COMMAND),
+ redirect: node.redirect.as_ref().and_then(valid).map(index),
+ // The server sent only what the player may use.
+ permission: 0,
+ suggests,
+ });
+ }
+ let mut d = Dispatcher::new();
+ if count > 0 {
+ d.nodes = nodes.into_iter().flatten().collect();
+ }
+ d
+}
+
+/// SuggestionProviders by id (`SuggestionProviders.getProvider`).
+fn provider(id: &str) -> Option {
+ match id {
+ "minecraft:ask_server" => Some(Suggests::AskServer),
+ "minecraft:summonable_entities" => Some(Suggests::SummonableEntities),
+ _ => None,
+ }
+}
+
+/// A registry name kept for the life of the game (argument types hold
+/// `&'static str`): each distinct name is stored once.
+fn intern(name: &str) -> &'static str {
+ static NAMES: OnceLock>> = OnceLock::new();
+ let mut names = NAMES
+ .get_or_init(Default::default)
+ .lock()
+ .unwrap_or_else(|e| e.into_inner());
+ if let Some(&n) = names.get(name) {
+ return n;
+ }
+ let n: &'static str = Box::leak(name.to_owned().into_boxed_str());
+ names.insert(n);
+ n
+}
+
+/// The argument type a parser and its properties describe
+/// (ArgumentTypeInfo.Template.instantiate).
+pub fn argument_type(id: i32, props: &[u8]) -> ArgType {
+ let Some(name) = usize::try_from(id).ok().and_then(|i| ARGUMENT_TYPES.get(i)) else {
+ return ArgType::Word;
+ };
+ let p = ArgumentProperties::decode(id, props).unwrap_or(ArgumentProperties::None);
+ let registry = || match &p {
+ ArgumentProperties::Registry(r) => intern(r),
+ _ => "",
+ };
+ match *name {
+ "brigadier:bool" => ArgType::Bool,
+ "brigadier:integer" => match p {
+ ArgumentProperties::Integer { min, max } => ArgType::Integer {
+ min: min.unwrap_or(i32::MIN),
+ max: max.unwrap_or(i32::MAX),
+ },
+ _ => ArgType::Integer {
+ min: i32::MIN,
+ max: i32::MAX,
+ },
+ },
+ // No long type of its own: a double over the same bounds reads
+ // the same digits.
+ "brigadier:long" => match p {
+ ArgumentProperties::Long { min, max } => ArgType::Double {
+ min: min.map_or(f64::MIN, |v| v as f64),
+ max: max.map_or(f64::MAX, |v| v as f64),
+ },
+ _ => ArgType::Double {
+ min: f64::MIN,
+ max: f64::MAX,
+ },
+ },
+ "brigadier:float" => match p {
+ ArgumentProperties::Float { min, max } => ArgType::Float {
+ min: min.unwrap_or(f32::MIN),
+ max: max.unwrap_or(f32::MAX),
+ },
+ _ => ArgType::Float {
+ min: f32::MIN,
+ max: f32::MAX,
+ },
+ },
+ "brigadier:double" => match p {
+ ArgumentProperties::Double { min, max } => ArgType::Double {
+ min: min.unwrap_or(f64::MIN),
+ max: max.unwrap_or(f64::MAX),
+ },
+ _ => ArgType::Double {
+ min: f64::MIN,
+ max: f64::MAX,
+ },
+ },
+ "brigadier:string" => match p {
+ ArgumentProperties::String(1) => ArgType::Str,
+ ArgumentProperties::String(2) => ArgType::Greedy,
+ _ => ArgType::Word,
+ },
+ "minecraft:entity" => match p {
+ ArgumentProperties::Entity {
+ single,
+ players_only,
+ } => ArgType::Entity {
+ single,
+ players: players_only,
+ },
+ _ => ArgType::Entity {
+ single: false,
+ players: false,
+ },
+ },
+ "minecraft:game_profile" => ArgType::GameProfile,
+ "minecraft:block_pos" => ArgType::BlockPos,
+ "minecraft:column_pos" => ArgType::ColumnPos,
+ "minecraft:vec3" => ArgType::Vec3 { center: true },
+ "minecraft:vec2" => ArgType::Vec2,
+ "minecraft:block_state" => ArgType::BlockState,
+ "minecraft:block_predicate" => ArgType::BlockPredicate,
+ "minecraft:item_stack" => ArgType::Item,
+ "minecraft:item_predicate" => ArgType::ItemPredicate,
+ "minecraft:team_color" => ArgType::TeamColor,
+ "minecraft:hex_color" => ArgType::HexColor,
+ "minecraft:component" => ArgType::Component,
+ "minecraft:style" => ArgType::Style,
+ "minecraft:message" => ArgType::Message,
+ "minecraft:nbt_compound_tag" => ArgType::Nbt,
+ "minecraft:nbt_tag" => ArgType::NbtTag,
+ "minecraft:nbt_path" => ArgType::NbtPath,
+ "minecraft:objective" => ArgType::Objective,
+ "minecraft:objective_criteria" => ArgType::Criteria,
+ "minecraft:operation" => ArgType::Operation,
+ "minecraft:particle" => ArgType::Particle,
+ "minecraft:angle" => ArgType::Angle,
+ "minecraft:rotation" => ArgType::Rotation,
+ "minecraft:scoreboard_slot" => ArgType::ScoreboardSlot,
+ "minecraft:score_holder" => ArgType::ScoreHolder {
+ multiple: matches!(p, ArgumentProperties::ScoreHolder { multiple: true }),
+ },
+ "minecraft:swizzle" => ArgType::Swizzle,
+ "minecraft:team" => ArgType::Team,
+ "minecraft:item_slot" => ArgType::Slot,
+ "minecraft:item_slots" => ArgType::Slots,
+ "minecraft:resource_location" => ArgType::Id("none"),
+ "minecraft:function" => ArgType::Function,
+ "minecraft:entity_anchor" => ArgType::Anchor,
+ "minecraft:int_range" => ArgType::IntRange,
+ "minecraft:float_range" => ArgType::FloatRange,
+ "minecraft:dimension" => ArgType::Dimension,
+ "minecraft:gamemode" => ArgType::GameMode,
+ "minecraft:time" => ArgType::Time {
+ min: match p {
+ ArgumentProperties::Time { min } => min,
+ _ => 0,
+ },
+ },
+ "minecraft:resource_or_tag" => ArgType::ResOrTag(registry()),
+ "minecraft:resource_or_tag_key" => ArgType::ResOrTagKey(registry()),
+ "minecraft:resource" => ArgType::Res(registry()),
+ "minecraft:resource_key" => ArgType::ResKey(registry()),
+ "minecraft:resource_selector" => ArgType::ResourceSelector(registry()),
+ "minecraft:template_mirror" => ArgType::Enum(&["none", "front_back", "left_right"]),
+ "minecraft:template_rotation" => {
+ ArgType::Enum(&["none", "clockwise_90", "180", "counterclockwise_90"])
+ }
+ "minecraft:heightmap" => ArgType::Enum(&[
+ "world_surface",
+ "motion_blocking",
+ "motion_blocking_no_leaves",
+ "ocean_floor",
+ ]),
+ "minecraft:swing_animation" => ArgType::Enum(&["none", "whack", "stab"]),
+ "minecraft:loot_table" => ArgType::ResourceOrId("minecraft:loot_table"),
+ "minecraft:loot_predicate" => ArgType::ResourceOrId("minecraft:predicate"),
+ "minecraft:loot_modifier" => ArgType::ResourceOrId("minecraft:item_modifier"),
+ "minecraft:context_float_provider" => {
+ ArgType::ResourceOrId("minecraft:context_float_provider")
+ }
+ "minecraft:context_int_provider" => ArgType::ResourceOrId("minecraft:context_int_provider"),
+ "minecraft:slot_source" => ArgType::SlotSource,
+ "minecraft:dialog" => ArgType::ResourceOrId("minecraft:dialog"),
+ "minecraft:feature" => ArgType::ResourceOrId("minecraft:worldgen/feature"),
+ "minecraft:uuid" => ArgType::Uuid,
+ _ => ArgType::Word,
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use horizon_protocol::{
+ buf::{Codec, Reader, Writer},
+ packets::play::CommandNode,
+ };
+
+ fn literal(name: &str, children: Vec, executable: bool) -> CommandNode {
+ CommandNode {
+ kind: 1,
+ executable,
+ restricted: false,
+ children,
+ redirect: None,
+ name: name.into(),
+ parser: None,
+ suggestions: None,
+ }
+ }
+
+ fn argument(name: &str, parser: &str, props: Vec, executable: bool) -> CommandNode {
+ let id = ARGUMENT_TYPES.iter().position(|p| *p == parser).unwrap() as i32;
+ CommandNode {
+ kind: 2,
+ executable,
+ restricted: false,
+ children: Vec::new(),
+ redirect: None,
+ name: name.into(),
+ parser: Some((id, props)),
+ suggestions: Some("minecraft:ask_server".into()),
+ }
+ }
+
+ /// A tree with the root last (as vanilla's numbering need not put it
+ /// first), a vanilla command and one the client does not know.
+ fn packet() -> Commands {
+ let mut range = Writer::new();
+ range.u8(3);
+ range.i32(1);
+ range.i32(64);
+ Commands {
+ nodes: vec![
+ literal("give", vec![2], false),
+ literal("warp", vec![3], false),
+ argument("targets", "minecraft:entity", vec![2], false),
+ argument("count", "brigadier:integer", range.data, true),
+ CommandNode {
+ kind: 0,
+ executable: false,
+ restricted: false,
+ children: vec![0, 1],
+ redirect: None,
+ name: String::new(),
+ parser: None,
+ suggestions: None,
+ },
+ ],
+ root: 4,
+ }
+ }
+
+ #[test]
+ fn argument_nodes_round_trip() {
+ let p = packet();
+ let mut w = Writer::new();
+ Commands::write(&p, &mut w);
+ let back = Commands::read(&mut Reader::new(&w.data)).unwrap();
+ assert_eq!(back, p);
+ }
+
+ #[test]
+ fn server_tree_becomes_a_dispatcher() {
+ let local = super::super::vanilla::dispatcher();
+ let d = from_packet(&packet(), local);
+ assert!(matches!(d.nodes[0].kind, NodeKind::Root));
+ let warp = d.find("warp").expect("warp");
+ let count = d.nodes[warp].children[0];
+ match &d.nodes[count].kind {
+ NodeKind::Argument {
+ ty: ArgType::Integer { min, max },
+ ..
+ } => assert_eq!((*min, *max), (1, 64)),
+ other => panic!("count is {other:?}"),
+ }
+ assert_eq!(d.nodes[count].command, Some(SERVER_COMMAND));
+ // `give ` is vanilla's: it keeps the client's type.
+ let give = d.find("give").expect("give");
+ let targets = d.nodes[give].children[0];
+ assert!(matches!(
+ d.nodes[targets].kind,
+ NodeKind::Argument {
+ ty: ArgType::Entity {
+ single: false,
+ players: true
+ },
+ ..
+ }
+ ));
+ }
+
+ #[test]
+ fn every_argument_type_decodes() {
+ for (id, name) in ARGUMENT_TYPES.iter().enumerate() {
+ let mut w = Writer::new();
+ match *name {
+ "brigadier:integer" | "brigadier:long" | "brigadier:float" | "brigadier:double" => {
+ w.u8(0)
+ }
+ "brigadier:string" => w.varint(2),
+ "minecraft:entity" | "minecraft:score_holder" => w.u8(1),
+ "minecraft:time" => w.i32(0),
+ n if n.starts_with("minecraft:resource") && n != "minecraft:resource_location" => {
+ w.string("minecraft:item")
+ }
+ _ => {}
+ }
+ let mut r = Reader::new(&w.data);
+ ArgumentProperties::read(&mut r, id as i32).unwrap();
+ assert_eq!(r.remaining(), 0, "{name}");
+ let _ = argument_type(id as i32, &w.data);
+ }
+ }
+}
diff --git a/crates/horizon-client/src/containers.rs b/crates/horizon-client/src/containers.rs
index 9cdac1463..6a135799c 100644
--- a/crates/horizon-client/src/containers.rs
+++ b/crates/horizon-client/src/containers.rs
@@ -45,6 +45,9 @@ pub struct Furnace {
pub cooking_total: i32,
pub speed: f32,
}
+/// A hopper's slots: the only plain container with five.
+pub const HOPPER_SLOTS: usize = 5;
+
#[derive(Clone, Debug)]
pub enum BlockEntity {
Chest(Vec>),
@@ -242,7 +245,7 @@ impl BlockEntity {
let size = match name {
"minecraft:chest" | "minecraft:trapped_chest" | "minecraft:barrel" => 27,
n if n.ends_with("copper_chest") => 27,
- "minecraft:hopper" => 5,
+ "minecraft:hopper" => HOPPER_SLOTS,
"minecraft:dispenser" | "minecraft:dropper" => 9,
n if n.ends_with("shulker_box") => 27,
_ => return None,
@@ -270,7 +273,7 @@ impl BlockEntity {
pub fn id(&self) -> &'static str {
match self {
Self::Chest(items) => match items.len() {
- 5 => "minecraft:hopper",
+ HOPPER_SLOTS => "minecraft:hopper",
9 => "minecraft:dispenser",
_ => "minecraft:chest",
},
diff --git a/crates/horizon-client/src/crafting.rs b/crates/horizon-client/src/crafting.rs
index 457ddf497..0b8f2856b 100644
--- a/crates/horizon-client/src/crafting.rs
+++ b/crates/horizon-client/src/crafting.rs
@@ -1209,7 +1209,15 @@ impl Recipes {
for (prefix, path) in files {
let stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
let name = format!("{prefix}{stem}");
- let v: Value = serde_json::from_slice(&fs::read(&path)?)?;
+ // Vanilla's RecipeManager logs a file that does not parse and
+ // goes on ("Couldn't parse data file").
+ let v: Value = match serde_json::from_slice(&fs::read(&path)?) {
+ Ok(v) => v,
+ Err(e) => {
+ log::warn!("Horizon: recipe {name} not loaded: {e}");
+ continue;
+ }
+ };
let text = |k: &str| v[k].as_str().unwrap_or("").to_owned();
meta.insert(name.clone(), (text("category"), text("group")));
let ing = |k: &str| Ingredient::parse(&v[k], items);
diff --git a/crates/horizon-client/src/effects.rs b/crates/horizon-client/src/effects.rs
index 2e600333a..a258ccf3a 100644
--- a/crates/horizon-client/src/effects.rs
+++ b/crates/horizon-client/src/effects.rs
@@ -386,6 +386,12 @@ impl PlayerEffects {
4.0,
"add_value",
)),
+ "absorption" => Some((
+ "minecraft:max_absorption",
+ "minecraft:effect.absorption",
+ 4.0,
+ "add_value",
+ )),
"luck" => Some(("minecraft:luck", "minecraft:effect.luck", 1.0, "add_value")),
"unluck" => Some((
"minecraft:luck",
@@ -538,4 +544,29 @@ mod tests {
assert!((fx.mining_speed_factor() - 1.4).abs() < 1e-6);
assert_eq!(fx.modifiers().len(), 1);
}
+
+ #[test]
+ fn absorption_modifier_scales_with_amplifier() {
+ let mut fx = PlayerEffects::default();
+ fx.add(EffectInstance::new("absorption", 2400, 0));
+ assert_eq!(
+ fx.modifiers(),
+ vec![(
+ "minecraft:max_absorption",
+ "minecraft:effect.absorption",
+ 4.0,
+ "add_value",
+ )]
+ );
+ fx.add(EffectInstance::new("absorption", 2400, 3));
+ assert_eq!(
+ fx.modifiers(),
+ vec![(
+ "minecraft:max_absorption",
+ "minecraft:effect.absorption",
+ 16.0,
+ "add_value",
+ )]
+ );
+ }
}
diff --git a/crates/horizon-client/src/entities.rs b/crates/horizon-client/src/entities.rs
index 5e6a3336a..5c905ac54 100644
--- a/crates/horizon-client/src/entities.rs
+++ b/crates/horizon-client/src/entities.rs
@@ -16,6 +16,7 @@ pub struct ItemEntity {
pub fire_ticks: i32,
pub id: u32,
pub stack: ItemStack,
+ pub thrower: Option<[i32; 4]>,
pub position: Vec3,
pub previous: Vec3,
pub velocity: Vec3,
@@ -178,6 +179,8 @@ impl ItemEntity {
/// ExperienceOrb: gravity 0.03, homing towards the player within 8 blocks.
#[derive(Clone, Debug)]
pub struct ExperienceOrb {
+ /// The entity id servers track it by.
+ pub id: u32,
pub position: Vec3,
pub previous: Vec3,
pub velocity: Vec3,
@@ -532,15 +535,16 @@ impl ArmorStand {
Vec3::new(p.x + w, p.y + h, p.z + w),
)
}
- /// LivingEntity.travel with gravity 0.08 and 0.98 drag, falling until it
- /// lands (armor stands have no other movement).
+ /// LivingEntity.travelInAir (armor stands have no other movement): move
+ /// by the velocity (a landing stops the fall,
+ /// `Block.updateEntityMovementAfterFallOn`), then gravity 0.08 and the
+ /// 0.98 drag, so a stand at rest on the ground keeps -0.0784 as vanilla's.
pub fn tick(&mut self, scene: &mut crate::collisions::SceneCollisions) {
if self.marker {
return;
}
- let mut v = self.velocity;
- v.y -= 0.08;
- let wanted = v;
+ let wanted = self.velocity;
+ let mut y = wanted.y;
if let Ok(moved) = scene.resolve(self.bounds(), wanted, 0.0, self.on_ground) {
self.position = Vec3::new(
self.position.x + moved.x,
@@ -548,9 +552,11 @@ impl ArmorStand {
self.position.z + moved.z,
);
self.on_ground = wanted.y < 0.0 && moved.y > wanted.y;
- v = Vec3::new(0.0, if moved.y != wanted.y { 0.0 } else { v.y * 0.98 }, 0.0);
+ if moved.y != wanted.y {
+ y = 0.0;
+ }
}
- self.velocity = v;
+ self.velocity = Vec3::new(0.0, (y - 0.08) * f64::from(0.98f32), 0.0);
}
}
@@ -610,6 +616,7 @@ mod fire_environment_tests {
.unwrap();
let make = |id: &str| ItemEntity {
id: 1,
+ thrower: None,
stack: ItemStack {
item: std::sync::Arc::from(id),
count: 1,
diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs
index adeb1da25..d627dc363 100644
--- a/crates/horizon-client/src/entity_nbt.rs
+++ b/crates/horizon-client/src/entity_nbt.rs
@@ -863,7 +863,7 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) -
Some(m)
}
-/// `ItemEntity`: Health, Age, PickupDelay, Item.
+/// `ItemEntity`: Health, Age, PickupDelay, Item, Thrower.
pub fn item_entity_to_nbt(e: &ItemEntity, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
let base = Base {
id: "minecraft:item",
@@ -887,6 +887,11 @@ pub fn item_entity_to_nbt(e: &ItemEntity, uuid: [i32; 4], raw: Option<&Tag>) ->
] {
put(&mut tag, key, value);
}
+ if let Some(thrower) = e.thrower {
+ put(&mut tag, "Thrower", Tag::IntArray(thrower.to_vec()));
+ } else if let Tag::Compound(map) = &mut tag {
+ map.remove(&"Thrower".into());
+ }
tag
}
pub fn item_entity_from_nbt(tag: &Tag, id: u32, bob_offset: f32) -> Option {
@@ -897,6 +902,7 @@ pub fn item_entity_from_nbt(tag: &Tag, id: u32, bob_offset: f32) -> Option Vec {
};
let count = number(tag.get("Count")).unwrap_or(1).clamp(1, 64) as usize;
let orb = ExperienceOrb {
+ id: 0,
position,
previous: position,
velocity: motion(tag),
@@ -1529,6 +1536,7 @@ mod tests {
let e = ItemEntity {
health: 2,
fire_ticks: 73,
+ thrower: Some([5, 6, 7, 8]),
id: 7,
stack: ItemStack {
item: Arc::from("minecraft:diamond_pickaxe"),
@@ -1555,6 +1563,11 @@ mod tests {
(120, 10, true)
);
assert_eq!(back.position.x, 100.5);
+ assert_eq!(back.thrower, e.thrower);
+ let mut cleared = back;
+ cleared.thrower = None;
+ let cleared = item_entity_to_nbt(&cleared, [1, 2, 3, 4], Some(&tag));
+ assert!(cleared.get("Thrower").is_none());
}
#[test]
fn unknown_fields_survive() {
@@ -1575,6 +1588,7 @@ mod tests {
#[test]
fn orbs_expand_their_count() {
let o = ExperienceOrb {
+ id: 0,
position: Vec3::new(1.0, 2.0, 3.0),
previous: Vec3::ZERO,
velocity: Vec3::ZERO,
diff --git a/crates/horizon-client/src/flatgen.rs b/crates/horizon-client/src/flatgen.rs
index d7764c30e..1cff68b11 100644
--- a/crates/horizon-client/src/flatgen.rs
+++ b/crates/horizon-client/src/flatgen.rs
@@ -4,7 +4,7 @@ use horizon_world::{nbt::Tag, registry::BlockRegistry};
/// The layers of a flat generator, bottom up from the world's minimum Y.
pub struct FlatTerrain {
- layers: Vec,
+ layers: Vec,
biome: u16,
}
impl FlatTerrain {
@@ -30,7 +30,7 @@ impl FlatTerrain {
for layer in list {
let block = crate::save::text(layer.get("block"))?;
let height = crate::save::number(layer.get("height")).unwrap_or(0).max(0);
- let state = registry.default_state(&block)?.0 as u16;
+ let state = registry.default_state(&block)?.0;
layers.extend(std::iter::repeat_n(state, height as usize));
}
}
@@ -44,6 +44,113 @@ impl FlatTerrain {
crate::chunk::MIN_Y + self.layers.len().min(crate::chunk::HEIGHT as usize) as i32
}
}
+/// DimensionType.Y_SIZE: the most layers FlatLevelGeneratorSettings takes.
+const Y_SIZE: i64 = 4064;
+
+/// FlatLevelGeneratorSettings.CODEC reading a dedicated server's
+/// `generator-settings` (DedicatedServerProperties.WorldDimensionData for
+/// the `minecraft:flat` preset): the settings as `world_gen_settings` stores
+/// them, and the errors vanilla logs, in order (the constructor's, then
+/// `resultOrPartial`'s). No settings means the preset's own layers; a layer
+/// that doesn't parse is left out, as the codec's partial result leaves it.
+/// `is_block` says whether a block id is registered, `is_biome` a biome id.
+pub fn settings_from_json(
+ json: &crate::server::json::Json,
+ is_block: impl Fn(&str) -> bool,
+ is_biome: impl Fn(&str) -> bool,
+) -> (Option, Vec) {
+ use crate::server::json::Json;
+ let id = |s: &str| {
+ if s.contains(':') {
+ s.to_owned()
+ } else {
+ format!("minecraft:{s}")
+ }
+ };
+ let Some(Json::Array(list)) = json.get("layers") else {
+ let error = match json.get("layers") {
+ None => format!("No key layers in MapLike[{}]", json.compact()),
+ Some(v) => format!("Not a list: {}", v.compact()),
+ };
+ return (None, vec![error]);
+ };
+ let mut errors = Vec::new();
+ let mut layers = Vec::new();
+ let mut total = 0;
+ for layer in list {
+ let height = layer.get("height").and_then(Json::as_string);
+ let height = height.as_deref().and_then(|h| h.parse::().ok());
+ let block = layer.get("block").and_then(Json::as_string).map(|b| id(&b));
+ match (height, block) {
+ (Some(h), _) if !(0..=Y_SIZE).contains(&h) => {
+ errors.push(format!("Value {h} outside of range [0:{Y_SIZE}]"));
+ }
+ (Some(h), Some(b)) if is_block(&b) => {
+ total += h;
+ layers.push(Tag::compound([
+ ("height", Tag::Int(h as i32)),
+ ("block", Tag::String(b.as_str().into())),
+ ]));
+ }
+ (Some(_), Some(b)) => errors.push(format!(
+ "Unknown registry key in ResourceKey[minecraft:root / minecraft:block]: {b}"
+ )),
+ (None, _) => errors.push(format!("No key height in MapLike[{}]", layer.compact())),
+ (_, None) => errors.push(format!("No key block in MapLike[{}]", layer.compact())),
+ }
+ }
+ // The constructor: Biome.CODEC is lenient, and a biome that is missing
+ // or unknown is Plains.
+ let biome = json
+ .get("biome")
+ .and_then(Json::as_string)
+ .map(|b| id(&b))
+ .filter(|b| is_biome(b));
+ let mut logged = Vec::new();
+ if biome.is_none() {
+ logged.push("Unknown biome, defaulting to plains".to_owned());
+ }
+ let biome = biome.unwrap_or_else(|| "minecraft:plains".to_owned());
+ // validateHeight.
+ if total > Y_SIZE {
+ errors.push(format!("Sum of layer heights is > {Y_SIZE}"));
+ logged.push(errors.join("; "));
+ return (None, logged);
+ }
+ let flag = |key: &str| match json.get(key) {
+ Some(Json::Bool(b)) => *b,
+ Some(Json::Number(n)) => n.parse::().is_ok_and(|v| v != 0.0),
+ _ => false,
+ };
+ let mut settings = Vec::new();
+ // RegistryCodecs.holderSet, lenient too: a tag or a list of ids.
+ match json.get("structure_overrides") {
+ Some(Json::String(s)) => {
+ settings.push(("structure_overrides", Tag::String(s.as_str().into())))
+ }
+ Some(Json::Array(ids)) if ids.iter().all(|i| matches!(i, Json::String(_))) => settings
+ .push((
+ "structure_overrides",
+ Tag::List(
+ ids.iter()
+ .filter_map(Json::as_string)
+ .map(|i| Tag::String(id(&i).as_str().into()))
+ .collect(),
+ ),
+ )),
+ _ => {}
+ }
+ settings.extend([
+ ("layers", Tag::List(layers)),
+ ("lakes", Tag::Byte(i8::from(flag("lakes")))),
+ ("features", Tag::Byte(i8::from(flag("features")))),
+ ("biome", Tag::String(biome.as_str().into())),
+ ]);
+ if !errors.is_empty() {
+ logged.push(errors.join("; "));
+ }
+ (Some(Tag::compound(settings)), logged)
+}
impl ChunkGenerator for FlatTerrain {
type Worker = ();
fn worker(&self) {}
@@ -75,3 +182,71 @@ impl ChunkGenerator for FlatTerrain {
*proto.downcast::().expect("flat terrain proto")
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::save::{number, text};
+ use crate::server::json::{self, Json};
+
+ fn read(text: &str) -> (Option, Vec) {
+ let json: Json = json::parse(text, false).unwrap();
+ settings_from_json(
+ &json,
+ |b| ["minecraft:stone", "minecraft:bedrock"].contains(&b),
+ |b| ["minecraft:plains", "minecraft:desert"].contains(&b),
+ )
+ }
+
+ #[test]
+ fn generator_settings_read_as_flat_level_generator_settings() {
+ // server.properties' default: the preset's own layers, and the codec's error.
+ assert_eq!(
+ read("{}"),
+ (None, vec!["No key layers in MapLike[{}]".into()])
+ );
+ let (settings, errors) = read(
+ r#"{"layers":[{"block":"bedrock","height":1},{"block":"minecraft:stone","height":3}],"biome":"desert","features":true}"#,
+ );
+ assert!(errors.is_empty());
+ let settings = settings.unwrap();
+ let Some(Tag::List(layers)) = settings.get("layers") else {
+ panic!("{settings:?}")
+ };
+ assert_eq!(layers.len(), 2);
+ assert_eq!(
+ text(layers[0].get("block")).as_deref(),
+ Some("minecraft:bedrock")
+ );
+ assert_eq!(number(layers[1].get("height")), Some(3));
+ assert_eq!(
+ text(settings.get("biome")).as_deref(),
+ Some("minecraft:desert")
+ );
+ assert_eq!(number(settings.get("features")), Some(1));
+ assert_eq!(number(settings.get("lakes")), Some(0));
+ // A layer that doesn't parse is left out; an unknown biome is Plains, and logged first.
+ let (settings, errors) = read(
+ r#"{"layers":[{"block":"nope","height":2},{"block":"stone","height":2}],"biome":"x"}"#,
+ );
+ assert_eq!(errors.len(), 2);
+ assert_eq!(errors[0], "Unknown biome, defaulting to plains");
+ assert!(errors[1].contains("minecraft:nope"));
+ let settings = settings.unwrap();
+ let Some(Tag::List(layers)) = settings.get("layers") else {
+ panic!("{settings:?}")
+ };
+ assert_eq!(layers.len(), 1);
+ assert_eq!(
+ text(settings.get("biome")).as_deref(),
+ Some("minecraft:plains")
+ );
+ // validateHeight.
+ assert_eq!(
+ read(
+ r#"{"layers":[{"block":"stone","height":4000},{"block":"stone","height":100}],"biome":"plains"}"#
+ ),
+ (None, vec!["Sum of layer heights is > 4064".into()])
+ );
+ }
+}
diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs
index 0f898f8bf..54d032d20 100644
--- a/crates/horizon-client/src/game.rs
+++ b/crates/horizon-client/src/game.rs
@@ -10,6 +10,7 @@ mod banners;
mod beacon;
mod beehives;
mod block_entity_anims;
+mod block_entity_ticks;
mod block_items;
mod blockctl;
mod boats;
@@ -63,13 +64,17 @@ mod item_particles;
mod jukebox;
mod lan;
mod lan_actions;
+mod lan_chat;
mod lan_crafting;
+mod lan_entities;
mod lan_mobs;
mod lan_pvp;
mod lan_screen;
mod lan_trading;
+mod lan_waypoints;
mod leads;
mod level_particles;
+mod levels;
mod lightning;
mod llamas;
mod loom;
@@ -105,6 +110,8 @@ mod powder_snow;
mod raids;
mod recipe_book;
mod remote;
+mod remote_objects;
+mod remote_projectiles;
mod render_control;
mod render_tick;
mod respawn_anchor;
@@ -195,7 +202,12 @@ use horizon_world::{
use std::{
collections::{HashMap, HashSet},
path::PathBuf,
- sync::Arc,
+ sync::{
+ Arc,
+ atomic::{AtomicU32, Ordering},
+ mpsc::{Receiver, TryRecvError},
+ },
+ thread::JoinHandle,
time::{Duration, Instant},
};
use winit::{
@@ -640,6 +652,8 @@ impl LevelAccess for GameLevel<'_> {
/// FallingBlockEntity carrying a block state.
#[derive(Clone, Debug)]
struct FallingBlock {
+ /// The entity id a server tracks it by (0 until it is tracked).
+ id: u32,
state: BlockStateId,
/// `DATA_START_POS`: spawn position used to select weighted block models.
start_pos: BlockPos,
@@ -967,14 +981,23 @@ struct Game<'a> {
/// `ClientAvatarState`: walked distance and view bob.
avatar: horizon_client::camera::AvatarBob,
flash: u32,
- /// Sleeping in a bed: (bed head position, ticks asleep).
- sleeping: Option<([i32; 3], u32)>,
+ /// The head of the bed while sleeping; the visual timer also survives waking.
+ sleeping: Option<[i32; 3]>,
+ sleep_timer: u32,
dim: Dim,
world_root: PathBuf,
/// A player carried through a portal, re-placed once the destination loads.
travelling: Option<(PlayerMotion, Vec3)>,
- /// A server's lone player on its way to another level.
- server_trip: Option,
+ /// A server's players on their way to another level, each waiting for
+ /// the destination to load around them.
+ server_trips: Vec,
+ /// Players a command sends to another level, once it has run.
+ level_teleports: Vec,
+ /// A server's levels other than the one in place (game/levels.rs).
+ levels: levels::Levels,
+ /// Which pass of a server tick runs (`tick_server`): the first one reads
+ /// the network, the last one ends the players' tick.
+ level_pass: levels::Pass,
/// Nether portals: the player's, items' and mobs' (game/nether_portal.rs).
portals: nether_portal::Portals,
/// The pending travel goes through an End portal (EndPortalBlock destinations).
@@ -1125,7 +1148,7 @@ struct Game<'a> {
lan_events: Vec<(i32, [i32; 3], i32, Option)>,
/// Block events (position, b0, b1, state) and entity events (id, event,
/// position) for the guests.
- lan_block_events: Vec<([i32; 3], i32, i32, u16)>,
+ lan_block_events: Vec<([i32; 3], i32, i32, u32)>,
lan_entity_events: Vec<(i32, i8, [f64; 3])>,
/// `ContainerOpenersCounter`: how many players (the host and the guests)
/// have each chest open.
@@ -1137,6 +1160,16 @@ struct Game<'a> {
lan_acting_uuid: Option,
/// Command feedback to forward to a guest.
chat_capture: Option>,
+ /// Packets for the guest acting now, sent once its action returns.
+ guest_packets: Vec,
+ /// `broadcastToAdmins` lines a guest's command queued, sent once it
+ /// returns: the line, whether operators get it and whether the console
+ /// logs it.
+ admin_feedback: Vec<(horizon_client::text::Text, bool, bool)>,
+ /// The server console is running a command: whether its feedback goes to
+ /// the operators (`DedicatedServer.shouldInformAdmins`,
+ /// `broadcast-console-to-ops`).
+ console_broadcast: Option,
/// State of `/spectate`, `/posteffect`, `/debug`, `/waypoint` and friends.
cmds: commands::extra::CommandExtras,
ui: chat::UiState,
@@ -1156,7 +1189,7 @@ struct Game<'a> {
tab_list: horizon_client::tab_list::TabList,
subtitles: subtitle_hud::SubtitleState,
adv: advancements::AdvState,
- restore_player_environment: bool,
+ restore_player_state: bool,
stats_ui: stats_screen::StatsUi,
adv_ui: advancements_screen::AdvUi,
camera_type: perspective::CameraType,
@@ -1164,7 +1197,7 @@ struct Game<'a> {
/// The local player as a model (third person, the inventory).
player_model: Option,
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum Dim {
Overworld,
Nether,
@@ -1527,6 +1560,7 @@ impl Game<'_> {
self.dropped.push(ItemEntity {
health: 5,
fire_ticks: 0,
+ thrower: None,
id: self.next_entity,
stack,
position: p,
@@ -1609,6 +1643,10 @@ impl Game<'_> {
yaw.cos() * pitch.cos() * 0.3 + spread.sin() * strength,
];
self.spawn_item(thrown, [eye[0], eye[1] - 0.3, eye[2]], v, 40);
+ if self.lan_acting.is_none() {
+ let uuid = self.level.ensure_player_uuid();
+ self.dropped.last_mut().unwrap().thrower = Some(uuid);
+ }
}
fn tick_items(&mut self) {
let mut items = std::mem::take(&mut self.dropped);
@@ -2029,6 +2067,7 @@ impl Game<'_> {
f64::from(pos.z) + 0.5,
);
self.falling.push(FallingBlock {
+ id: 0,
state,
start_pos: pos,
position: p,
@@ -2178,13 +2217,13 @@ impl Game<'_> {
self.audio
.play("minecraft:block.ender_chest.open", Some(at), 0.5, pitch);
} else if &*name == "minecraft:beacon" && self.open_station(pos, &name) {
- self.world.block_entities.entry(key).or_insert_with(|| {
+ self.world.block_entities.get_or_insert_with(key, || {
BlockEntity::for_block(&name).unwrap_or(BlockEntity::Chest(Vec::new()))
});
} else if storage::is_shulker_box(&name) && !self.shulker_can_open(pos) {
// ShulkerBoxBlock.canOpen: the lid has no room; nothing opens.
} else if let Some(entity) = BlockEntity::for_block(&name) {
- self.world.block_entities.entry(key).or_insert(entity);
+ self.world.block_entities.get_or_insert_with(key, || entity);
let centre = [
f64::from(key.0) + 0.5,
f64::from(key.1) + 0.5,
@@ -2741,7 +2780,7 @@ impl Game<'_> {
|| !self
.player
.as_ref()
- .is_some_and(|p| p.health.food.food < 20 || self.creative)
+ .is_some_and(|p| info.can_always_eat || p.health.food.food < 20 || self.creative)
{
return false;
}
@@ -2750,6 +2789,56 @@ impl Game<'_> {
}
true
}
+ fn apply_consume_effect(
+ &mut self,
+ effect: &horizon_client::items::ConsumeEffect,
+ eye: [f64; 3],
+ ) {
+ use horizon_client::items::ConsumeEffect;
+ match effect {
+ ConsumeEffect::ApplyEffects {
+ effects,
+ probability,
+ } => {
+ if *probability >= 1.0 || self.world.random.next_float() <= *probability {
+ for eff in effects {
+ if let Some(def) = horizon_client::brewing::effect(&eff.id) {
+ if def.instant {
+ if let Some(a) =
+ horizon_client::effects::instant(def.id, eff.amplifier, 1.0)
+ {
+ self.apply_effect_action(a);
+ }
+ } else {
+ self.add_player_effect(
+ horizon_client::effects::EffectInstance::new(
+ def.id,
+ eff.duration,
+ eff.amplifier,
+ ),
+ );
+ }
+ }
+ }
+ }
+ }
+ ConsumeEffect::ClearAllEffects => {
+ self.potions.effects.clear();
+ self.apply_effect_status();
+ }
+ ConsumeEffect::RemoveEffects(to_remove) => {
+ for target in to_remove {
+ let id = target.trim_start_matches("minecraft:");
+ self.potions.effects.list.retain(|e| e.id != id);
+ }
+ self.apply_effect_status();
+ }
+ ConsumeEffect::TeleportRandomly => {}
+ ConsumeEffect::PlaySound(sound) => {
+ self.audio.play(sound, Some(eye), 1.0, 1.0);
+ }
+ }
+ }
fn consume_held(&mut self) {
if self.creative {
return;
@@ -2852,19 +2941,22 @@ impl Game<'_> {
self.eat_particles(&stack, 16);
// Consumable.onConsume.
self.post_entity_event("minecraft:eat", horizon_client::mobs::Who::Player);
- if let Some((nutrition, saturation)) = info.food
- && let Some(p) = self.player.as_mut()
- {
- // FoodData.eat(nutrition, saturation)
- let food = &mut p.health.food;
- food.food = (food.food + nutrition as i32).clamp(0, 20);
- food.saturation = (food.saturation + saturation).clamp(0.0, food.food as f32);
+ if let Some((nutrition, saturation)) = info.food {
+ if let Some(p) = self.player.as_mut() {
+ // FoodData.eat(nutrition, saturation)
+ let food = &mut p.health.food;
+ food.food = (food.food + nutrition as i32).clamp(0, 20);
+ food.saturation = (food.saturation + saturation).clamp(0.0, food.food as f32);
+ }
self.audio.play(
"minecraft:entity.player.burp",
Some(eye),
0.5,
self.world.random.next_float() * 0.1 + 0.9,
);
+ for effect in &info.consume_effects {
+ self.apply_consume_effect(effect, eye);
+ }
self.trigger_item("minecraft:consume_item", &stack);
self.consume_held();
}
@@ -3075,14 +3167,16 @@ impl Game<'_> {
};
let mut player = PlayerMotion::new(self.motion, feet)?;
player.yaw = self.yaw;
- player.load_environment_once(
- &mut self.restore_player_environment,
- self.level.player_extra.as_ref(),
- );
+ player.load_saved_state_once(&mut self.restore_player_state, &self.level)?;
let spectator = self.mode == horizon_client::command::args::GameMode::Spectator;
player.may_fly = self.creative || spectator;
player.invulnerable = self.creative || spectator;
player.spectator = spectator;
+ if spectator {
+ player.flying = true;
+ } else if !player.may_fly {
+ player.flying = false;
+ }
player.respiration = self.armor[0]
.as_ref()
.map_or(0, |s| s.enchantment_level("minecraft:respiration") as i32);
@@ -3094,10 +3188,12 @@ impl Game<'_> {
.get(&s.item)
.is_some_and(|i| i.glider && (i.max_damage == 0 || s.damage + 1 < i.max_damage))
});
- if self.level.health > 0.0 && self.ticks < 2 {
- player.set_health(self.level.health, false)?;
- player.health.food.food = self.level.food;
- player.health.food.saturation = self.level.saturation;
+ // A saved death already dropped inventory/XP and counted the death.
+ if player.health.dead_or_dying() {
+ self.screen = Screen::Dead;
+ self.ui.died_at = Some(Instant::now());
+ self.ui.death_text = None;
+ self.capture(false);
}
self.previous_position = feet;
self.player = Some(player);
@@ -3182,7 +3278,7 @@ impl Game<'_> {
if !self.streaming.is_lit(cx, cz) {
return Ok(());
}
- let playing = self.screen == Screen::Playing;
+ let playing = self.screen == Screen::Playing && self.sleeping.is_none();
let held = |k| playing && self.keys.contains(&k);
let keys = Keys {
forward: held(KeyCode::KeyW),
@@ -3276,7 +3372,12 @@ impl Game<'_> {
let feet = [player.position.x, player.position.y, player.position.z];
let player_velocity = [player.velocity.x, player.velocity.y, player.velocity.z];
self.previous_eye = self.eye;
- self.eye += (camera_eye.unwrap_or(player.dimensions.eye_height) - self.eye) * 0.5;
+ let eye_height = if self.sleeping.is_some() {
+ 0.2
+ } else {
+ player.dimensions.eye_height
+ };
+ self.eye += (camera_eye.unwrap_or(eye_height) - self.eye) * 0.5;
let crouching = player.pose == horizon_client::pose::Pose::Crouching;
self.tick_avatar(before, riding);
self.record_combat(&events);
@@ -3539,7 +3640,11 @@ impl Game<'_> {
});
horizon_client::spans::time("tick_particles", || self.tick_particles());
}
- if self.right && self.use_delay == 0 && self.screen == Screen::Playing {
+ if self.right
+ && self.use_delay == 0
+ && self.screen == Screen::Playing
+ && self.sleeping.is_none()
+ {
self.use_with_hand()?;
self.use_delay = 4;
}
@@ -3666,6 +3771,11 @@ impl Game<'_> {
) || self.book.is_some())
}
fn capture(&mut self, capture: bool) {
+ // A guest's action (`as_guest`) opens and closes screens on the
+ // guest's own client: the window's pointer stays the host's (#687).
+ if self.lan_acting.is_some() {
+ return;
+ }
// MouseHandler.grabMouse never captures an inactive window.
if capture && !self.focused {
return;
@@ -3691,10 +3801,7 @@ impl Game<'_> {
/// LevelLoadingScreen.onClose -> Gui.setScreen(null) -> grabMouse.
fn capture_loaded_world(&mut self) {
// Loading may finish after focus was lost or another screen opened.
- if self.title.is_none()
- && self.screen == Screen::Playing
- && !self.remote.as_ref().is_some_and(|r| r.chat_input.is_some())
- {
+ if self.title.is_none() && self.screen == Screen::Playing {
self.capture(true);
}
}
@@ -3922,15 +4029,7 @@ impl Game<'_> {
self.draw_boss_bars(&mut batch);
self.draw_extras(&mut batch);
}
- // Hud.extractSleepOverlay, under the sidebar, titles and chat.
- if let Some((_, ticks)) = self.sleeping {
- let draws = hud_overlays::sleep_overlay(wi, hi, ticks as i32);
- hud_layout::paint(&mut batch, &self.atlas, &draws);
- }
if show_hud {
- self.draw_titles(&mut batch);
- self.draw_scoreboard(&mut batch);
- self.draw_subtitles(&mut batch);
// The mount's hearts (and the jump bar that replaces the experience bar).
let (vehicle_hearts, jump_bar) = if spectator {
(0, false)
@@ -4002,6 +4101,14 @@ impl Game<'_> {
self.draw_selected_name(&mut batch, !self.creative);
}
}
+ // Hud.extractSleepOverlay: over all health/food bars, under titles and chat.
+ let draws = hud_overlays::sleep_overlay(wi, hi, self.sleep_timer as i32);
+ hud_layout::paint(&mut batch, &self.atlas, &draws);
+ if show_hud {
+ self.draw_titles(&mut batch);
+ self.draw_scoreboard(&mut batch);
+ self.draw_subtitles(&mut batch);
+ }
let atlas = &self.atlas;
if show_hud
&& let Some((text, at)) = &self.message
@@ -4513,6 +4620,10 @@ impl Game<'_> {
/// Several clicks on one menu instance (a quick craft drag is three).
fn menu_ops(&mut self, ops: &[(Option, i32, horizon_client::menu::Input)]) -> bool {
use horizon_client::menu::Input;
+ if self.remote.is_some() && self.screen == Screen::Inventory {
+ // On a server the clicks are the server's: predicted and sent.
+ return self.remote_menu_ops(ops);
+ }
if let [(Some(slot), button, input)] = ops {
self.crafter_slot_clicked(*slot, *button, *input);
}
@@ -4687,7 +4798,7 @@ impl Game<'_> {
plain: false,
};
(kind, map)
- } else if self.station.is_none() && !self.mount_active() && self.remote.is_none() {
+ } else if self.station.is_none() && !self.mount_active() {
let table = self.craft_size == 3;
let map = Map {
container: 0,
@@ -4800,7 +4911,12 @@ impl Game<'_> {
Some(false) => return true,
Some(true) => {}
}
- self.register_exploration_maps(made);
+ // On a server the clicks only predict: the server drops, crafts and
+ // makes maps itself.
+ let predicting = self.remote.is_some();
+ if !predicting {
+ self.register_exploration_maps(made);
+ }
if let Some(s) = menu.merchant.take() {
self.merchant_sync_out(s);
}
@@ -4818,10 +4934,12 @@ impl Game<'_> {
if !offhand_mapped {
self.offhand = menu.player_item(40).cloned();
}
- for stack in dropped {
- self.player_drop(stack);
+ if !predicting {
+ for stack in dropped {
+ self.player_drop(stack);
+ }
+ self.award_crafted(&crafted);
}
- self.award_crafted(&crafted);
if kind == Kind::Loom {
if let Some(s) = self.station.as_mut() {
s.loom.selected = usize::try_from(menu.data[0]).ok();
@@ -4953,9 +5071,13 @@ impl Game<'_> {
return;
}
if let Some(moved) = self.last_quick_moved.clone() {
- self.menu_session(|menu, env, to_menu| {
- Some(menu.quick_move_all(env, to_menu(slot)?, &moved).is_ok())
- });
+ if self.remote.is_some() {
+ self.remote_quick_move_all(slot, &moved);
+ } else {
+ self.menu_session(|menu, env, to_menu| {
+ Some(menu.quick_move_all(env, to_menu(slot)?, &moved).is_ok())
+ });
+ }
}
self.last_inv_click = None;
self.inv_clicks.skip_release();
@@ -5584,6 +5706,9 @@ impl Game<'_> {
)
};
let visible = r.block_entities().filter(|(p, state)| {
+ if !self.res.block_entity_render.renders(*state) {
+ return false;
+ }
off_screen(*state)
|| view.is_none_or(|v| {
let o =
@@ -5705,9 +5830,10 @@ impl Game<'_> {
let start = out.len();
self.block_model_vertices(
f.state,
- f.start_pos,
+ horizon_core::random::position_seed(f.start_pos),
glam::Mat4::from_translation(o),
packed,
+ false,
&mut out,
);
let tint = horizon_client::mobs::render::abgr(tint);
@@ -6055,38 +6181,6 @@ impl Game<'_> {
false,
)
}
- fn tick_block_entities(&mut self) -> Result<()> {
- self.tick_hoppers()?;
- self.tick_crafters();
- self.tick_mount_menu();
- self.tick_jukeboxes();
- self.tick_beacons();
- self.tick_creaking_hearts()?;
- self.tick_spawners()?;
- self.tick_trial_spawners()?;
- self.tick_vaults()?;
- self.tick_beehives();
- let mut lit_changes = Vec::new();
- for (pos, entity) in self.world.block_entities.iter_mut() {
- if let BlockEntity::Furnace(f) = entity
- && let Some(lit) = f.tick(&self.res.recipes, &self.res.items, &self.res.providers)
- {
- lit_changes.push((*pos, lit));
- }
- }
- for ((x, y, z), lit) in lit_changes {
- let state = self.world.block(x, y, z);
- if let Some(mut s) = self.pack.assets.registry.state(state).cloned()
- && s.properties.contains_key("lit")
- {
- s.properties.insert("lit".into(), lit.to_string());
- if let Ok(id) = self.pack.assets.registry.resolve(&s) {
- self.world.set(x, y, z, id)?;
- }
- }
- }
- Ok(())
- }
/// Copies of a save batch carrying its live block entities and save data.
fn with_entities<'a>(
&self,
@@ -6231,7 +6325,8 @@ impl Game<'_> {
self.fns = Default::default();
self.bosses = Default::default();
reset_world_progress(&mut self.adv, &mut self.stats);
- self.restore_player_environment = true;
+ self.prefetch_advancement_tree();
+ self.restore_player_state = true;
// RandomSequences: the world's data/minecraft/random_sequences.dat.
self.rand_sequences =
horizon_client::save::read_dat(&save_root.join("data/minecraft/random_sequences.dat"))
@@ -6368,6 +6463,8 @@ impl Game<'_> {
self.clear_entities();
self.travelling = None;
self.player = None;
+ self.sleeping = None;
+ self.sleep_timer = 0;
self.spawn = None;
self.respawn_travel = None;
self.respawn_config =
@@ -6461,7 +6558,10 @@ impl Game<'_> {
res.threads,
)
} else {
- let inner = Arc::new(VanillaTerrain::for_dimension(&self.options.resources.join("worldgen"), pack.assets.registry, &res.biomes, seed, dim.id()).map_err(|e| {
+ // WorldOptions.generateStructures, from the world's settings.
+ let structures =
+ horizon_client::save::WorldGen::read(world_root).is_none_or(|w| w.structures);
+ let inner = Arc::new(VanillaTerrain::for_world(&self.options.resources.join("worldgen"), pack.assets.registry, &res.biomes, seed, dim.id(), structures).map_err(|e| {
format!("{e}\nPrepare the worldgen bundle with the launcher, or: horizon-prepare --prepare")
})?);
self.end.set_locator(Some(inner.clone()));
@@ -6484,8 +6584,9 @@ impl Game<'_> {
streaming.biome_zoom = BiomeZoom::new(obfuscate_seed(seed));
streaming.sky_light = dim != Dim::Nether;
streaming.nether_shading = dim == Dim::Nether;
- // The integrated server draws nothing (the dedicated server keeps its behaviour).
- streaming.mesh = !self.options.integrated;
+ // A server draws nothing: neither the integrated server nor the
+ // dedicated one meshes sections.
+ streaming.mesh = !self.options.integrated && self.options.dedicated.is_none();
Ok((streaming, save))
}
/// Change dimension through a portal (Entity.changeDimension with
@@ -6725,6 +6826,8 @@ impl Game<'_> {
self.streaming.paused = true;
self.world = World::new(self.res.facts.air, 0);
self.player = None;
+ self.sleeping = None;
+ self.sleep_timer = 0;
self.clear_entities();
self.screen = Screen::Playing;
if let Some(r) = self.renderer.as_mut() {
@@ -7336,7 +7439,9 @@ impl Game<'_> {
let mut r = dispenser::entity_random();
let _yaw = r.next_float();
let p = Vec3::new(at[0], at[1], at[2]);
+ self.next_entity += 1;
self.orbs.push(ExperienceOrb {
+ id: self.next_entity,
position: p,
previous: p,
velocity: Vec3::new(
@@ -7400,13 +7505,29 @@ impl Game<'_> {
.player
.as_ref()
.filter(|p| !p.health.dead_or_dying() && !spectator);
- let target = player.map(|p| {
- [
- p.position.x,
- p.position.y + f64::from(p.dimensions.eye_height) / 2.0,
- p.position.z,
- ]
- });
+ // ExperienceOrb.followNearbyPlayer: each orb goes for the nearest
+ // living player within 8 blocks, the host's own or a guest.
+ let mut followed: Vec<([f64; 3], [f64; 3])> = player
+ .map(|p| {
+ let feet = [p.position.x, p.position.y, p.position.z];
+ let eye = f64::from(p.dimensions.eye_height);
+ (feet, [feet[0], feet[1] + eye / 2.0, feet[2]])
+ })
+ .into_iter()
+ .collect();
+ if let Some(host) = self.lan.as_ref() {
+ followed.extend(
+ host.hub
+ .guests
+ .iter()
+ .filter(|g| g.placed && g.loaded && !g.dead && g.health > 0.0)
+ .filter(|g| !g.spectator())
+ .map(|g| {
+ let p = g.position;
+ (p, [p[0], p[1] + g.eye_height() / 2.0, p[2]])
+ }),
+ );
+ }
let bounds = player.map(|p| {
let w = f64::from(p.dimensions.width) / 2.0;
(
@@ -7419,7 +7540,19 @@ impl Game<'_> {
)
});
let mut orbs = std::mem::take(&mut self.orbs);
- orbs.retain_mut(|o| o.tick(&self.world, &self.res.facts, self.collision, target));
+ orbs.retain_mut(|o| {
+ let distance = |feet: &[f64; 3]| -> f64 {
+ (feet[0] - o.position.x).powi(2)
+ + (feet[1] - o.position.y).powi(2)
+ + (feet[2] - o.position.z).powi(2)
+ };
+ let target = followed
+ .iter()
+ .filter(|(feet, _)| distance(feet) < 64.0)
+ .min_by(|a, b| distance(&a.0).total_cmp(&distance(&b.0)))
+ .map(|(_, target)| *target);
+ o.tick(&self.world, &self.res.facts, self.collision, target)
+ });
let mut gained = 0;
let mut taken = Vec::new();
if let Some((min, max)) = bounds {
@@ -7453,19 +7586,25 @@ impl Game<'_> {
(self.world.random.next_float() - self.world.random.next_float()) * 0.35 + 0.9;
self.audio
.play("minecraft:entity.experience_orb.pickup", at, 0.1, pitch);
- if self.experience.give(gained as i32)
- && self.experience.level % 5 == 0
- && self.ticks > self.last_level_up + 100
- {
- self.last_level_up = self.ticks;
- let volume = if self.experience.level > 30 {
- 1.0
- } else {
- self.experience.level as f32 / 30.0
- };
- self.audio
- .play("minecraft:entity.player.levelup", at, volume * 0.75, 1.0);
- }
+ self.give_orb_points(gained);
+ }
+ }
+ /// `Player.giveExperiencePoints`, and `giveExperienceLevels`' level-up
+ /// sound every fifth level (at most every 100 ticks).
+ pub(super) fn give_orb_points(&mut self, gained: u32) {
+ let at = self.eye_position();
+ if self.experience.give(gained as i32)
+ && self.experience.level % 5 == 0
+ && self.ticks > self.last_level_up + 100
+ {
+ self.last_level_up = self.ticks;
+ let volume = if self.experience.level > 30 {
+ 1.0
+ } else {
+ self.experience.level as f32 / 30.0
+ };
+ self.audio
+ .play("minecraft:entity.player.levelup", at, volume * 0.75, 1.0);
}
}
/// BowItem.releaseUsing: power from charge time, arrows at power * 3.
@@ -7554,6 +7693,7 @@ impl Game<'_> {
// GameRenderer.renderItemInHand: F1 hides the hand with the HUD.
if self.spectator()
|| self.ui.hide_gui
+ || self.sleeping.is_some()
|| !self.camera_type.first_person()
|| self
.player
@@ -7750,27 +7890,13 @@ impl Game<'_> {
pack: &PackResources,
atlas: &HudAtlas,
) -> Result {
- let assets = &pack.assets;
- let mut renderer = pollster::block_on(Renderer::new(
+ build_renderer(
window,
self.options.offscreen,
- &assets.pixels,
- assets.sprite_size,
- assets.sprite_minimum_size,
- assets.texture_layers,
- &assets.sprite_mips,
- &assets.animations,
- (&atlas.pixels, atlas.width, atlas.height),
- (&pack.forcefield.2, pack.forcefield.0),
- &pack.panorama,
+ pack,
+ atlas,
self.renderer.as_ref(),
- ))?;
- renderer.hud.fire_animations = atlas
- .fire_animations
- .iter()
- .map(|(rect, animation)| (*rect, animation.clone(), usize::MAX))
- .collect();
- Ok(renderer)
+ )
}
fn apply_settings(&mut self) {
if let Some(r) = &self.renderer {
@@ -8029,44 +8155,59 @@ impl Game<'_> {
return;
}
self.message = Some(("Respawn point set".into(), Instant::now()));
- self.sleeping = Some((head, 0));
+ self.stop_mining();
+ self.left = false;
+ self.right = false;
+ self.using = None;
+ self.sleeping = Some(head);
+ self.sleep_timer = 0;
self.stats.custom("sleep_in_bed", 1);
self.trigger_player("minecraft:slept_in_bed");
self.stats.reset("custom", "minecraft:time_since_rest");
}
+ fn wake_up(&mut self) {
+ if self.remote.is_some() {
+ // InBedChatScreen.sendWakeUp: the server wakes the player.
+ self.remote_stop_sleeping();
+ return;
+ }
+ self.sleeping = None;
+ self.sleep_timer = 100;
+ }
fn tick_sleep(&mut self) {
- let Some((head, ticks)) = self.sleeping else {
- return;
- };
- if self.keys.contains(&KeyCode::ShiftLeft)
- || self
- .player
- .as_ref()
- .is_none_or(|p| p.health.dead_or_dying())
- {
- self.sleeping = None;
- return;
+ self.sleep_timer = tick_sleep_timer(self.sleep_timer, self.sleeping.is_some());
+ if let Some(head) = self.sleeping {
+ if self.keys.contains(&KeyCode::ShiftLeft)
+ || self
+ .player
+ .as_ref()
+ .is_none_or(|p| p.health.dead_or_dying())
+ {
+ self.wake_up();
+ return;
+ }
+ if let Some(p) = self.player.as_mut() {
+ p.position = Vec3::new(
+ f64::from(head[0]) + 0.5,
+ f64::from(head[1]) + 0.5625,
+ f64::from(head[2]) + 0.5,
+ );
+ p.velocity = Vec3::ZERO;
+ }
}
- if let Some(p) = self.player.as_mut() {
- p.position = Vec3::new(
- f64::from(head[0]) + 0.5,
- f64::from(head[1]) + 0.5625,
- f64::from(head[2]) + 0.5,
- );
- p.velocity = Vec3::ZERO;
- }
- let ticks = ticks + 1;
- // ServerLevel: once everyone has slept 100 ticks, skip to morning and clear weather.
- if ticks >= 100 {
+ // ServerLevel.tick: once enough of the players have slept 100 ticks,
+ // skip to morning, clear the weather and wake everyone.
+ if self.enough_slept() {
let t = self.world.day_time;
self.world.day_time = t + 24000 - t.rem_euclid(24000);
self.world.weather.raining = false;
self.world.weather.thundering = false;
self.world.weather.rain_time = 0;
self.world.weather.thunder_time = 0;
- self.sleeping = None;
- } else {
- self.sleeping = Some((head, ticks));
+ if self.sleeping.is_some() {
+ self.wake_up();
+ }
+ self.wake_guests();
}
}
fn creative_origin(batch: &HudBatch) -> (f32, f32) {
@@ -8369,6 +8510,7 @@ impl Game<'_> {
level.food = p.health.food.food;
level.saturation = p.health.food.saturation;
+ level.flying = p.flying;
}
level.inventory = self
.inventory
@@ -8424,18 +8566,10 @@ impl Game<'_> {
if self.remote.is_some() {
return Ok(());
}
- self.streaming.save(&mut self.world, wait);
- let keys: Vec<_> = self.world.modified.drain().collect();
- let chunks = self.with_entities(keys.iter().filter_map(|k| self.world.chunks.get(k)));
- self.save
- .save_later(&chunks, self.pack.assets.registry, &self.res.biomes)?;
- if wait {
- self.save.flush();
- }
- self.save_entities(wait)?;
+ self.save_level(wait)?;
+ self.save_parked_levels(wait)?;
self.save_maps();
self.save_random_sequences();
- self.save_raids();
self.save_fight();
self.save_wandering_trader();
self.save_portal_arrivals();
@@ -8452,6 +8586,20 @@ impl Game<'_> {
self.message = Some(("Saved the game".into(), Instant::now()));
Ok(())
}
+ /// Save the level in place: its changed chunks, its entities and its raids.
+ fn save_level(&mut self, wait: bool) -> Result<()> {
+ self.streaming.save(&mut self.world, wait);
+ let keys: Vec<_> = self.world.modified.drain().collect();
+ let chunks = self.with_entities(keys.iter().filter_map(|k| self.world.chunks.get(k)));
+ self.save
+ .save_later(&chunks, self.pack.assets.registry, &self.res.biomes)?;
+ if wait {
+ self.save.flush();
+ }
+ self.save_entities(wait)?;
+ self.save_raids();
+ Ok(())
+ }
fn render(&mut self) -> Result {
self.poll_shader_pack();
let Some(size) = self
@@ -8489,6 +8637,22 @@ impl Game<'_> {
camera.y.floor() as i32,
camera.z.floor() as i32,
];
+ // The camera inside an opaque block sees nothing through it: disable.
+ let cave_culling = self.settings.horizon.cave_culling
+ && !self
+ .res
+ .facts
+ .get(self.world.block(block[0], block[1], block[2]))
+ .solid_render;
+ // The cave culling search runs on its worker while the frame is prepared.
+ if cave_culling
+ && self.title.is_none()
+ && let Some(renderer) = self.renderer.as_mut()
+ {
+ horizon_client::spans::time("occlusion", || {
+ renderer.start_occlusion(camera, (self.streaming.radius * 16) as f32)
+ });
+ }
let biome = self
.world
.chunks
@@ -8677,13 +8841,7 @@ impl Game<'_> {
skybox: self.dim == Dim::Overworld && self.settings.horizon.sky,
end_sky: self.dim == Dim::End && self.settings.horizon.sky,
environment_fog: (self.dim == Dim::Nether).then_some((sky.fog_start, sky.fog_end)),
- // The camera inside an opaque block sees nothing through it: disable.
- cave_culling: self.settings.horizon.cave_culling
- && !self
- .res
- .facts
- .get(self.world.block(block[0], block[1], block[2]))
- .solid_render,
+ cave_culling,
water_fog,
fog: Some({
let mut fog = self.frame_fog(camera, &sky, biome);
@@ -8874,6 +9032,18 @@ impl Game<'_> {
}
/// A key press while a world is open (keyboard or control socket).
fn key_pressed(&mut self, key: KeyCode) -> Result<()> {
+ if self.sleeping.is_some()
+ && self.screen == Screen::Playing
+ && !matches!(
+ key,
+ KeyCode::F1 | KeyCode::F2 | KeyCode::F11 | KeyCode::KeyT | KeyCode::Slash
+ )
+ {
+ if matches!(key, KeyCode::Escape | KeyCode::ShiftLeft) {
+ self.wake_up();
+ }
+ return Ok(());
+ }
if self.sort_key_press(key) {
return Ok(());
}
@@ -9004,6 +9174,9 @@ impl Game<'_> {
}
/// A mouse button while playing (window or control socket).
fn play_mouse(&mut self, button: MouseButton, pressed: bool) -> Result<()> {
+ if self.sleeping.is_some() {
+ return Ok(());
+ }
if self.remote.is_some() {
return self.remote_mouse(button, pressed);
}
@@ -9333,6 +9506,7 @@ impl ApplicationHandler for Game<'_> {
title.scroll_worlds(d, self.cursor, (batch.width, batch.height));
}
if self.screen == Screen::Playing
+ && self.sleeping.is_none()
&& self.player.is_some()
&& !self.extras_scroll(d)
&& let Some((wheel, _)) =
@@ -9606,9 +9780,6 @@ impl ApplicationHandler for Game<'_> {
self.station_text(event.text.as_deref(), backspace);
}
}
- WindowEvent::KeyboardInput { event, .. } if self.remote_chat_open() => {
- self.remote_chat_key(&event)
- }
WindowEvent::KeyboardInput { event, .. }
if self.screen == Screen::WorldOptions
&& !matches!(event.physical_key, PhysicalKey::Code(KeyCode::Escape)) =>
@@ -9715,7 +9886,6 @@ impl ApplicationHandler for Game<'_> {
&& self.title.is_none()
&& self.sign_edit.is_none()
&& self.book.is_none()
- && !self.remote_chat_open()
{
let turn = |k| f32::from(u8::from(self.keys.contains(&k)));
let secs = elapsed.as_secs_f32().min(0.1);
@@ -9810,6 +9980,10 @@ impl ApplicationHandler for Game<'_> {
self.pause = self.pauses_game();
if let Some(server) = &self.integrated {
server.set_paused(self.pause);
+ server.set_distances(
+ self.settings.render_distance,
+ self.settings.simulation_distance,
+ );
}
self.clock.end_frame(self.pause);
let finished = self
@@ -10124,10 +10298,14 @@ impl<'a> Game<'a> {
avatar: Default::default(),
flash: 0,
sleeping: None,
+ sleep_timer: 0,
dim: Dim::Overworld,
world_root: PathBuf::new(),
travelling: None,
- server_trip: None,
+ server_trips: Vec::new(),
+ level_teleports: Vec::new(),
+ levels: Default::default(),
+ level_pass: Default::default(),
portals: Default::default(),
end_travel: false,
respawn_config: None,
@@ -10230,9 +10408,12 @@ impl<'a> Game<'a> {
lan_entity_events: Vec::new(),
lid_openers: HashMap::new(),
lan_acting: None,
+ guest_packets: Vec::new(),
lan_acting_name: None,
lan_acting_uuid: None,
chat_capture: None,
+ admin_feedback: Vec::new(),
+ console_broadcast: None,
cmds: Default::default(),
ui: Default::default(),
combat: Default::default(),
@@ -10249,7 +10430,7 @@ impl<'a> Game<'a> {
tab_list: Default::default(),
subtitles: Default::default(),
adv: Default::default(),
- restore_player_environment: true,
+ restore_player_state: true,
stats_ui: Default::default(),
adv_ui: Default::default(),
camera_type: Default::default(),
@@ -10259,41 +10440,83 @@ impl<'a> Game<'a> {
}
}
-pub fn run() -> Result<()> {
- let Some(mut options) = Options::read()? else {
- return Ok(());
- };
- if options.dedicated.is_some() && !dedicated::preflight(&mut options)? {
- return Ok(());
+/// The data the background loader produces for `Game::new`.
+struct Loaded {
+ root: PathBuf,
+ pack_error: Option,
+ resources: Resources,
+ pack: PackResources,
+ atlas: HudAtlas,
+}
+
+/// The loader's checkpoints, in order; the loading screen reports them.
+const STAGES: u32 = 9;
+const STAGE_LINES: [&str; 9] = [
+ "Loading assets",
+ "Loading block facts",
+ "Loading items",
+ "Loading biomes",
+ "Loading pack tables",
+ "Loading atlas",
+ "Loading collision",
+ "Loading resources",
+ "Starting audio",
+];
+
+/// The background loader's checkpoint, read by the loading screen each frame.
+#[derive(Clone)]
+struct Progress(Arc);
+impl Progress {
+ fn new() -> Self {
+ Self(Arc::new(AtomicU32::new(0)))
}
- let started = Instant::now();
- horizon_client::spans::enable(options.spikes.is_some());
- let vanilla_root = options.resources.clone();
- let early_settings = Settings::load(&std::env::current_dir()?.join("options.txt"));
- // Snapshots of derived tables live in the game folder, never beside the
- // shared resources.
- Behaviours::set_cache_dir(std::env::current_dir()?.join(".horizon-cache"));
+ fn set(&self, stage: u32) {
+ self.0.store(stage, Ordering::Relaxed);
+ }
+ fn fraction(&self) -> f32 {
+ self.0.load(Ordering::Relaxed) as f32 / (STAGES - 1) as f32
+ }
+ fn line(&self) -> &'static str {
+ STAGE_LINES[(self.0.load(Ordering::Relaxed) as usize).min(STAGE_LINES.len() - 1)]
+ }
+}
+
+/// Harness and dedicated runs keep the fully-synchronous startup so their
+/// output stays byte-identical; only an ordinary launch shows the window first.
+fn synchronous_startup(options: &Options) -> bool {
+ let classic = std::env::var("HORIZON_MENU_STYLE").ok().as_deref() == Some("classic");
+ options.frames.is_some()
+ || options.world_frames.is_some()
+ || options.benchmark.is_some()
+ || options.control.is_some()
+ || options.dedicated.is_some()
+ || classic
+ || std::env::var_os("HORIZON_DISPENSE_FIXTURE").is_some()
+ || std::env::var_os("HORIZON_SCULK_FIXTURE").is_some()
+ || std::env::var_os("HORIZON_COMMAND_SCRIPT").is_some()
+ || std::env::var_os("HORIZON_NET_REPORT").is_some()
+}
+
+/// The current loading sequence, unchanged, as a function so the synchronous
+/// launch can run it on the main thread and an ordinary launch on a worker.
+/// `on_stage` reports [`STAGES`] checkpoints to the loading screen.
+fn load_resources(
+ mut root: PathBuf,
+ vanilla_root: &std::path::Path,
+ settings: &Settings,
+ started: Instant,
+ on_stage: &(dyn Fn(u32) + Sync),
+) -> Result {
let mut pack_error = None;
- options.resources = packs::startup_root(&vanilla_root, &early_settings.resource_packs)
- .unwrap_or_else(|e| {
- log::warn!("Horizon: resource packs not applied: {e}");
- pack_error = Some(e.to_string());
- vanilla_root.clone()
- });
- options.resources = mods::content_root(
- &options.resources,
- &early_settings.mods.enabled,
- &options.dev_mods,
- );
- let assets = match Assets::load(&options.resources) {
+ let assets = match Assets::load(&root) {
Ok(assets) => assets,
// Minecraft.rollbackResourcePacks: the packs break loading, start
// with the game's own resources.
- Err(e) if options.resources != vanilla_root => {
+ Err(e) if root != vanilla_root => {
log::warn!("Horizon: resource packs failed to load ({e}); using the default resources");
pack_error = Some(e.to_string());
- options.resources = vanilla_root.clone();
- Assets::load(&vanilla_root)?
+ root = vanilla_root.to_path_buf();
+ Assets::load(vanilla_root)?
}
Err(e) => {
return Err(format!(
@@ -10302,9 +10525,9 @@ pub fn run() -> Result<()> {
.into());
}
};
- let root = options.resources.clone();
let assets = Arc::new(assets);
log::info!("load assets: {:.2}s", started.elapsed().as_secs_f32());
+ on_stage(0);
let behaviour_json: serde_json::Value = serde_json::from_reader(std::io::BufReader::new(
std::fs::File::open(root.join("block-behaviours.json"))?,
))?;
@@ -10313,31 +10536,37 @@ pub fn run() -> Result<()> {
let mob_data = horizon_client::mobs::MobData::load(&root, &facts);
horizon_client::mobs::trial_spawner::load_registry(&root);
log::info!("load facts: {:.2}s", started.elapsed().as_secs_f32());
+ on_stage(1);
let items = Items::load(&root, assets.registry, &facts)?;
log::info!("load items: {:.2}s", started.elapsed().as_secs_f32());
+ on_stage(2);
let recipes = Recipes::load(&root, &items)?;
let transformers = horizon_client::block_transform::Transformers::load(&root, assets.registry)?;
let biomes = Arc::new(Biomes::load(&root)?);
let environment = Environment::load(&root)?;
log::info!("load biomes+env: {:.2}s", started.elapsed().as_secs_f32());
+ on_stage(3);
let light = Arc::new(LightTables::load(&root, assets.registry, &facts)?);
let pack = PackResources::load(&root, assets.clone(), &facts, biomes.clone(), light)?;
log::info!("load pack tables: {:.2}s", started.elapsed().as_secs_f32());
+ on_stage(4);
let atlas = HudAtlas::build(&root)?;
horizon_client::ui::load_metadata(&root);
horizon_client::lang::set(horizon_client::lang::Language::load(
&[&root],
- &early_settings.language,
+ &settings.language,
));
log::info!("load atlas: {:.2}s", started.elapsed().as_secs_f32());
+ on_stage(5);
let registry_owner = assets.clone();
let collision = collisions::load(&root, registry_owner.registry)?;
- let motion = MotionResources::load(&root, ®istry_owner)?;
+ let motion = MotionResources::load_with_facts(&root, ®istry_owner, &facts)?;
log::info!(
"load collision+motion: {:.2}s",
started.elapsed().as_secs_f32()
);
- let threads = early_settings.horizon.worker_threads();
+ on_stage(6);
+ let threads = settings.horizon.worker_threads();
log::info!(
"Horizon: resources loaded in {:.1}s; {} block states, {} items, {} biomes; {} worker threads",
started.elapsed().as_secs_f32(),
@@ -10346,16 +10575,11 @@ pub fn run() -> Result<()> {
biomes.list.len(),
threads
);
- let audio = if options.dedicated.is_some() {
- Audio::silent(&root)
- } else {
- Audio::new(&root)
- };
let stations = horizon_client::stations::StationData::load(&root, &items);
let animate =
horizon_client::animate_tick::AnimateTables::load(&root, registry_owner.registry, &biomes)?;
let fog = horizon_client::fog::FogTables::load(&root, &biomes);
- let resources = Arc::new(Resources {
+ let resources = Resources {
stations,
facts,
items,
@@ -10392,11 +10616,159 @@ pub fn run() -> Result<()> {
player_type: perspective::player_type(&root),
player_arm: horizon_client::mobs::load_model(&root, "minecraft:player#main")
.and_then(|m| m.children.into_iter().find(|c| c.name == "right_arm")),
- });
+ };
// Both inputs are needed only while constructing the behaviour tables.
// Release their owned JSON/Arc buffers before entering the long-lived game loop.
drop(gameplay_projection);
drop(behaviour_json);
+ on_stage(7);
+ Ok(Loaded {
+ root,
+ pack_error,
+ resources,
+ pack,
+ atlas,
+ })
+}
+
+/// The renderer from a pack's block sprites, its shared atlas and its border
+/// texture; `previous` shares the device and window surface with an old one.
+fn build_renderer(
+ window: Arc,
+ offscreen: bool,
+ pack: &PackResources,
+ atlas: &HudAtlas,
+ previous: Option<&Renderer>,
+) -> Result {
+ let assets = &pack.assets;
+ let mut renderer = pollster::block_on(Renderer::new(
+ window,
+ offscreen,
+ &assets.pixels,
+ assets.sprite_size,
+ assets.sprite_minimum_size,
+ assets.texture_layers,
+ &assets.sprite_mips,
+ &assets.animations,
+ (&atlas.pixels, atlas.width, atlas.height),
+ (&pack.forcefield.2, pack.forcefield.0),
+ &pack.panorama,
+ previous,
+ ))?;
+ renderer.hud.fire_animations = atlas
+ .fire_animations
+ .iter()
+ .map(|(rect, animation)| (*rect, animation.clone(), usize::MAX))
+ .collect();
+ Ok(renderer)
+}
+
+/// The loading screen's renderer: the real HUD atlas and font over one opaque
+/// white block-sprite layer, an empty border texture and an empty panorama.
+fn loading_renderer(
+ window: Arc,
+ offscreen: bool,
+ atlas: Option<&HudAtlas>,
+) -> Result {
+ static FORCEFIELD: [u8; 4] = [0; 4];
+ static EMPTY_HUD: [u8; 4] = [0, 0, 0, 255];
+ let panorama = horizon_client::gfx::panorama::Faces {
+ size: 1,
+ pixels: [0u8; 4].repeat(6),
+ };
+ let (pixels, width, height) = match atlas {
+ Some(atlas) => (atlas.pixels.as_slice(), atlas.width, atlas.height),
+ None => (EMPTY_HUD.as_slice(), 1, 1),
+ };
+ let mut renderer = pollster::block_on(Renderer::new(
+ window,
+ offscreen,
+ &[255, 255, 255, 255],
+ 1,
+ 1,
+ 1,
+ &[],
+ &[],
+ (pixels, width, height),
+ (&FORCEFIELD[..], 1),
+ &panorama,
+ None,
+ ))?;
+ if let Some(atlas) = atlas {
+ renderer.hud.fire_animations = atlas
+ .fire_animations
+ .iter()
+ .map(|(rect, animation)| (*rect, animation.clone(), usize::MAX))
+ .collect();
+ }
+ Ok(renderer)
+}
+
+/// A title-shaped frame: black clear and panorama, only the HUD is drawn.
+fn loading_frame(hud: &HudBatch) -> Frame<'_> {
+ Frame {
+ camera: glam::DVec3::new(0.5, 100.0, 0.5),
+ yaw: 0.0,
+ pitch: 10.0,
+ fov_degrees: 85.0,
+ bob: glam::Mat4::IDENTITY,
+ sky: horizon_client::environment::Sky::default(),
+ distance: 12.0,
+ depth_far: 1000.0,
+ underwater: false,
+ cave_culling: false,
+ title: true,
+ skybox: false,
+ end_sky: false,
+ environment_fog: None,
+ water_fog: [0.0; 3],
+ fog: None,
+ dark_disc: false,
+ outline: Vec::new(),
+ outline_after_terrain: false,
+ debug_lines: &[],
+ debug_lines_on_top: &[],
+ debug_crosshair: &[],
+ hud,
+ nether_lighting: false,
+ entities: &[],
+ clouds: None,
+ additive: &[],
+ see_through: &[],
+ celestial: &[],
+ hand: &[],
+ hand_fov_degrees: 70.0,
+ screen: &[],
+ border: None,
+ game_time: 0.0,
+ shader_game_time: 0.0,
+ end_portal_sprites: [[0.0; 4]; 2],
+ crumbling_sprite: [0.0; 4],
+ ticks: 0,
+ darkness: (0.0, 0.0),
+ night_vision: 0.0,
+ block_flicker: 0.0,
+ post: None,
+ menu_blur: None,
+ shader: Default::default(),
+ }
+}
+
+/// The post-load setup once the resources are ready: `Game::new` and the
+/// options, packs, mods, control socket, benchmark and world selection the
+/// old `run` did after loading. `None` means a harness or dedicated run
+/// finished here instead.
+#[allow(clippy::too_many_arguments)]
+fn start_game<'a>(
+ res: &'a Arc,
+ pack: PackResources,
+ atlas: HudAtlas,
+ options: Options,
+ pack_error: Option,
+ audio: Audio,
+ vanilla_root: PathBuf,
+ started: Instant,
+) -> Result>> {
let mut settings = Settings::load(&std::env::current_dir()?.join("options.txt"));
horizon_client::ui_theme::load_preferences(&std::env::current_dir()?);
// Scripted and frame-limited runs (the parity harnesses) see vanilla's
@@ -10409,7 +10781,7 @@ pub fn run() -> Result<()> {
if let Some(d) = options.distance_override {
settings.render_distance = d;
}
- let mut game = Game::new(&resources, pack, atlas, options, settings, audio)?;
+ let mut game = Game::new(res, pack, atlas, options, settings, audio)?;
game.ui.vanilla_root = vanilla_root;
if let Some(error) = pack_error {
game.open_options_at(true, horizon_client::options_ui::Page::Packs);
@@ -10459,13 +10831,16 @@ pub fn run() -> Result<()> {
);
}
if let Ok(spec) = std::env::var("HORIZON_DISPENSE_FIXTURE") {
- return game.dispense_fixture(&spec);
+ game.dispense_fixture(&spec)?;
+ return Ok(None);
}
if let Ok(spec) = std::env::var("HORIZON_SCULK_FIXTURE") {
- return game.sculk_fixture(&spec);
+ game.sculk_fixture(&spec)?;
+ return Ok(None);
}
if game.options.dedicated.is_some() {
- return game.run_dedicated();
+ game.run_dedicated()?;
+ return Ok(None);
}
match game.options.world.clone() {
_ if game.options.server.is_some() => {
@@ -10475,7 +10850,8 @@ pub fn run() -> Result<()> {
);
game.connect_server(&address, &name)?;
if let Some(report) = std::env::var_os("HORIZON_NET_REPORT") {
- return game.run_net_harness(report.as_ref());
+ game.run_net_harness(report.as_ref())?;
+ return Ok(None);
}
}
Some(folder) => {
@@ -10501,9 +10877,13 @@ pub fn run() -> Result<()> {
std::env::var_os("HORIZON_COMMAND_SCRIPT"),
std::env::var_os("HORIZON_COMMAND_OUTPUT"),
) {
- return game.run_command_harness(script.as_ref(), output.as_ref());
+ game.run_command_harness(script.as_ref(), output.as_ref())?;
+ return Ok(None);
}
- EventLoop::new()?.run_app(&mut game)?;
+ Ok(Some(game))
+}
+
+fn write_report(game: &Game<'_>) -> Result<()> {
if let Some(path) = &game.options.report {
let report = serde_json::json!({
"frames": game.frames,
@@ -10516,12 +10896,399 @@ pub fn run() -> Result<()> {
});
std::fs::write(path, serde_json::to_vec_pretty(&report)?)?;
}
- if let Some(e) = game.error {
+ Ok(())
+}
+
+fn run_event_loop(mut game: Game<'_>) -> Result<()> {
+ EventLoop::new()?.run_app(&mut game)?;
+ write_report(&game)?;
+ if let Some(e) = game.error.take() {
return Err(e);
}
Ok(())
}
+/// The loading screen's state while the worker loads the resources.
+struct Loading {
+ window: Option>,
+ renderer: Option,
+ atlas: Option,
+ settings: Settings,
+ fullscreen: horizon_client::window::FullscreenState,
+ options: Option,
+ vanilla_root: PathBuf,
+ pack_error: Option,
+ started: Instant,
+ progress: Progress,
+ receiver: Receiver>,
+ loaded: Option>,
+ handle: Option>,
+ shown: bool,
+ error: Option>,
+}
+impl Loading {
+ fn resumed(&mut self, event_loop: &ActiveEventLoop) {
+ if self.window.is_some() {
+ return;
+ }
+ // The Window constructor: created fullscreen when options.txt says so.
+ let fullscreen = self.settings.fullscreen;
+ self.fullscreen = horizon_client::window::FullscreenState::new(fullscreen);
+ let attributes = Window::default_attributes()
+ .with_title("Horizon")
+ .with_window_icon(horizon_client::window::icon());
+ // Wayland names the window by its app id, which the horizon.desktop entry matches.
+ #[cfg(target_os = "linux")]
+ let attributes = winit::platform::wayland::WindowAttributesExtWayland::with_name(
+ attributes, "horizon", "horizon",
+ );
+ let window = match event_loop.create_window(
+ attributes
+ .with_inner_size(winit::dpi::LogicalSize::new(1280.0, 720.0))
+ .with_fullscreen(fullscreen.then_some(winit::window::Fullscreen::Borderless(None))),
+ ) {
+ Ok(w) => Arc::new(w),
+ Err(e) => {
+ self.error = Some(e.into());
+ event_loop.exit();
+ return;
+ }
+ };
+ let offscreen = self.options.as_ref().is_some_and(|o| o.offscreen);
+ match loading_renderer(window.clone(), offscreen, self.atlas.as_ref()) {
+ Ok(r) => self.renderer = Some(r),
+ Err(e) => {
+ self.error = Some(e);
+ event_loop.exit();
+ return;
+ }
+ }
+ if let Some(r) = &self.renderer {
+ self.settings
+ .clamp_gui_scale([r.config.width as i32, r.config.height as i32]);
+ }
+ horizon_client::hud::GUI_SCALE.store(self.settings.gui_scale, Ordering::Relaxed);
+ self.window = Some(window);
+ }
+ fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
+ if self.window.as_ref().is_none_or(|w| w.id() != id) {
+ return;
+ }
+ match event {
+ WindowEvent::CloseRequested => event_loop.exit(),
+ WindowEvent::Resized(size) => {
+ if let Some(r) = &mut self.renderer {
+ r.resize(size.width, size.height);
+ }
+ }
+ WindowEvent::RedrawRequested => self.draw(),
+ _ => {}
+ }
+ }
+ fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
+ if self.loaded.is_none() {
+ match self.receiver.try_recv() {
+ Ok(result) => self.loaded = Some(result),
+ Err(TryRecvError::Disconnected) => {
+ if let Some(handle) = self.handle.take() {
+ let _ = handle.join();
+ }
+ self.error = Some("resource loader stopped before finishing".into());
+ event_loop.exit();
+ return;
+ }
+ Err(TryRecvError::Empty) => {}
+ }
+ }
+ if let Some(w) = &self.window {
+ if self.options.as_ref().is_some_and(|o| o.offscreen) {
+ self.draw();
+ } else {
+ w.request_redraw();
+ }
+ }
+ event_loop.set_control_flow(ControlFlow::Poll);
+ }
+ fn draw(&mut self) {
+ let Some(renderer) = self.renderer.as_mut() else {
+ return;
+ };
+ let size = [renderer.config.width, renderer.config.height];
+ let mut batch = HudBatch::new(size);
+ if let Some(atlas) = &self.atlas {
+ horizon_client::level_loading::draw_progress(
+ &mut batch,
+ atlas,
+ self.progress.line(),
+ self.progress.fraction(),
+ );
+ }
+ let frame = loading_frame(&batch);
+ if let Err(e) = renderer.render(&frame) {
+ log::warn!("Horizon: loading screen frame failed: {e}");
+ }
+ if !self.shown {
+ self.shown = true;
+ log::info!(
+ "Horizon: loading screen shown after {} ms",
+ self.started.elapsed().as_millis()
+ );
+ }
+ }
+ fn finish(&mut self, loaded: Loaded) -> Result>> {
+ let mut options = self.options.take().ok_or("loading already finished")?;
+ options.resources = loaded.root.clone();
+ self.progress.set(STAGES - 1);
+ // Audio is created on the main thread, after the join.
+ let audio = if options.dedicated.is_some() {
+ Audio::silent(&options.resources)
+ } else {
+ Audio::new(&options.resources)
+ };
+ let window = self.window.clone().ok_or("window closed")?;
+ // Keep the loader's device and swap in the real textures in one step.
+ if let Some(renderer) = &mut self.renderer {
+ renderer.release_surface();
+ }
+ let renderer = build_renderer(
+ window.clone(),
+ options.offscreen,
+ &loaded.pack,
+ &loaded.atlas,
+ self.renderer.as_ref(),
+ )?;
+ let pack_error = loaded.pack_error.or_else(|| self.pack_error.take());
+ // The game borrows its shared resources for the process's lifetime,
+ // like the single copy an integrated server would share.
+ let res: &'static Arc = Box::leak(Box::new(Arc::new(loaded.resources)));
+ let Some(mut game) = start_game(
+ res,
+ loaded.pack,
+ loaded.atlas,
+ options,
+ pack_error,
+ audio,
+ self.vanilla_root.clone(),
+ self.started,
+ )?
+ else {
+ return Ok(None);
+ };
+ game.window = Some(window);
+ game.renderer = Some(renderer);
+ game.fullscreen = self.fullscreen;
+ game.apply_settings();
+ game.previous = Instant::now();
+ Ok(Some(game))
+ }
+}
+
+/// The application: the loading screen until the resources are ready, then
+/// the game itself, on the same event loop and window.
+enum App {
+ Loading(Box),
+ Ready(Box>),
+}
+impl ApplicationHandler for App {
+ fn resumed(&mut self, event_loop: &ActiveEventLoop) {
+ match self {
+ App::Loading(loading) => loading.resumed(event_loop),
+ App::Ready(game) => game.resumed(event_loop),
+ }
+ }
+ fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
+ match self {
+ App::Loading(loading) => loading.window_event(event_loop, id, event),
+ App::Ready(game) => game.window_event(event_loop, id, event),
+ }
+ }
+ fn device_event(&mut self, event_loop: &ActiveEventLoop, id: DeviceId, event: DeviceEvent) {
+ if let App::Ready(game) = self {
+ game.device_event(event_loop, id, event);
+ }
+ }
+ fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
+ enum Step {
+ Waiting,
+ Ready(Box>),
+ Done,
+ Failed(Box),
+ }
+ let step = match self {
+ App::Ready(game) => {
+ game.about_to_wait(event_loop);
+ return;
+ }
+ App::Loading(loading) => {
+ loading.about_to_wait(event_loop);
+ if loading.error.is_some() {
+ event_loop.exit();
+ return;
+ }
+ match loading.loaded.take() {
+ None => Step::Waiting,
+ Some(Err(e)) => Step::Failed(e.into()),
+ Some(Ok(loaded)) => match loading.finish(loaded) {
+ Ok(Some(game)) => Step::Ready(Box::new(game)),
+ Ok(None) => Step::Done,
+ Err(e) => Step::Failed(e),
+ },
+ }
+ }
+ };
+ match step {
+ Step::Waiting => {}
+ Step::Ready(game) => *self = App::Ready(game),
+ Step::Done => event_loop.exit(),
+ Step::Failed(e) => {
+ if let App::Loading(loading) = self {
+ loading.error = Some(e);
+ }
+ event_loop.exit();
+ }
+ }
+ }
+ fn exiting(&mut self, event_loop: &ActiveEventLoop) {
+ if let App::Ready(game) = self {
+ game.exiting(event_loop);
+ }
+ }
+}
+
+/// The ordinary launch: load the resources on a worker while the window shows
+/// the loading screen, then swap in the game on the main thread.
+fn run_loading(
+ options: Options,
+ settings: Settings,
+ vanilla_root: PathBuf,
+ pack_error: Option,
+ started: Instant,
+) -> Result<()> {
+ let progress = Progress::new();
+ let (sender, receiver) = std::sync::mpsc::channel();
+ let loader = {
+ let progress = progress.clone();
+ let settings = settings.clone();
+ let vanilla_root = vanilla_root.clone();
+ let root = options.resources.clone();
+ std::thread::Builder::new()
+ .name("resource-loader".into())
+ .spawn(move || {
+ let result = load_resources(root, &vanilla_root, &settings, started, &|stage| {
+ progress.set(stage)
+ })
+ .map_err(|e| e.to_string());
+ let _ = sender.send(result);
+ })?
+ };
+ let atlas = HudAtlas::build(&options.resources).ok();
+ let loading = Loading {
+ window: None,
+ renderer: None,
+ atlas,
+ settings,
+ fullscreen: horizon_client::window::FullscreenState::new(false),
+ options: Some(options),
+ vanilla_root,
+ pack_error,
+ started,
+ progress,
+ receiver,
+ loaded: None,
+ handle: Some(loader),
+ shown: false,
+ error: None,
+ };
+ let mut app = App::Loading(Box::new(loading));
+ EventLoop::new()?.run_app(&mut app)?;
+ match app {
+ App::Ready(mut game) => {
+ write_report(&game)?;
+ if let Some(e) = game.error.take() {
+ return Err(e);
+ }
+ }
+ App::Loading(loading) => {
+ if let Some(e) = loading.error {
+ return Err(e);
+ }
+ }
+ }
+ Ok(())
+}
+
+pub fn run() -> Result<()> {
+ let Some(mut options) = Options::read()? else {
+ return Ok(());
+ };
+ if options.dedicated.is_some() && !dedicated::preflight(&mut options)? {
+ return Ok(());
+ }
+ let started = Instant::now();
+ horizon_client::spans::enable(options.spikes.is_some());
+ let vanilla_root = options.resources.clone();
+ let early_settings = Settings::load(&std::env::current_dir()?.join("options.txt"));
+ // Snapshots of derived tables live in the game folder, never beside the
+ // shared resources.
+ Behaviours::set_cache_dir(std::env::current_dir()?.join(".horizon-cache"));
+ let mut pack_error = None;
+ options.resources = packs::startup_root(&vanilla_root, &early_settings.resource_packs)
+ .unwrap_or_else(|e| {
+ log::warn!("Horizon: resource packs not applied: {e}");
+ pack_error = Some(e.to_string());
+ vanilla_root.clone()
+ });
+ options.resources = mods::content_root(
+ &options.resources,
+ &early_settings.mods.enabled,
+ &options.dev_mods,
+ );
+ // Harnesses and dedicated runs stay synchronous; a normal launch enters
+ // the event loop at once and loads the resources on a worker.
+ if !synchronous_startup(&options) {
+ return run_loading(options, early_settings, vanilla_root, pack_error, started);
+ }
+ let loaded = load_resources(
+ options.resources.clone(),
+ &vanilla_root,
+ &early_settings,
+ started,
+ &|_| {},
+ )?;
+ options.resources = loaded.root.clone();
+ let audio = if options.dedicated.is_some() {
+ Audio::silent(&options.resources)
+ } else {
+ Audio::new(&options.resources)
+ };
+ let resources = Arc::new(loaded.resources);
+ let game = start_game(
+ &resources,
+ loaded.pack,
+ loaded.atlas,
+ options,
+ loaded.pack_error.or(pack_error),
+ audio,
+ vanilla_root,
+ started,
+ )?;
+ if let Some(game) = game {
+ run_event_loop(game)?;
+ }
+ Ok(())
+}
+
+// Player.tick: cap the sleeping fade at 100, then fade out over 10 waking ticks.
+fn tick_sleep_timer(timer: u32, sleeping: bool) -> u32 {
+ if sleeping {
+ (timer + 1).min(100)
+ } else if (1..109).contains(&timer) {
+ timer + 1
+ } else {
+ 0
+ }
+}
+
fn reset_world_progress(adv: &mut advancements::AdvState, stats: &mut stats::Stats) {
*adv = Default::default();
*stats = Default::default();
@@ -10556,6 +11323,35 @@ mod tests {
use horizon_client::container_screen::{Button, Clicks, Release, Target};
use horizon_client::keymapping::{KeyAction, SPRINT, ToggleKeys};
+ #[test]
+ fn sleep_fade_lasts_ten_ticks_after_waking() {
+ let alpha = |timer| match hud_overlays::sleep_overlay(320, 240, timer).first() {
+ Some(hud_layout::GuiDraw::Fill { color, .. }) => color >> 24,
+ None => 0,
+ _ => panic!("sleep overlay must be a full-screen fill"),
+ };
+ assert_eq!(tick_sleep_timer(0, false), 0);
+ let mut timer = 0;
+ for _ in 0..50 {
+ timer = tick_sleep_timer(timer, true);
+ }
+ assert_eq!(alpha(timer as i32), 110);
+ for _ in 0..100 {
+ timer = tick_sleep_timer(timer, true);
+ }
+ assert_eq!(timer, 100);
+ assert_eq!(alpha(timer as i32), 220);
+ for _ in 0..5 {
+ timer = tick_sleep_timer(timer, false);
+ }
+ assert_eq!(alpha(timer as i32), 110);
+ for _ in 0..5 {
+ timer = tick_sleep_timer(timer, false);
+ }
+ assert_eq!(timer, 0);
+ assert!(hud_overlays::sleep_overlay(320, 240, timer as i32).is_empty());
+ }
+
/// An integrated server thread shares the loaded resources with the client.
#[test]
fn shared_resources_can_cross_threads() {
diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs
index 22d9a4da0..882b5cc93 100644
--- a/crates/horizon-client/src/game/advancements.rs
+++ b/crates/horizon-client/src/game/advancements.rs
@@ -88,6 +88,9 @@ pub(super) struct AdvState {
pub(super) changed: BTreeSet,
pub(super) unlocked: Vec,
pub(super) announced: Vec,
+ /// The tree being read on another thread since the world opened
+ /// (`prefetch_advancement_tree`), taken by the first `advancement_tree`.
+ pub(super) pending_tree: Option>,
}
/// The game's world for predicates.
struct View<'a, 'g>(&'a Game<'g>);
@@ -221,10 +224,27 @@ impl Game<'_> {
/// The advancement tree, loaded once.
pub(super) fn advancement_tree(&mut self) -> Arc {
if self.adv.tree.list.is_empty() {
- self.adv.tree = Arc::new(Tree::load(&self.options.resources.join("data")));
+ let tree = match self.adv.pending_tree.take().map(|h| h.join()) {
+ Some(Ok(tree)) => tree,
+ _ => Tree::load(&self.options.resources.join("data")),
+ };
+ self.adv.tree = Arc::new(tree);
}
self.adv.tree.clone()
}
+ /// Start reading the advancement files on another thread while the world
+ /// loads. The first tick's first criterion trigger used to read and parse
+ /// all of them on the game thread (about 60 ms).
+ pub(super) fn prefetch_advancement_tree(&mut self) {
+ if !self.adv.tree.list.is_empty() || self.adv.pending_tree.is_some() {
+ return;
+ }
+ let data = self.options.resources.join("data");
+ self.adv.pending_tree = std::thread::Builder::new()
+ .name("horizon-advancements".into())
+ .spawn(move || Tree::load(&data))
+ .ok();
+ }
pub(super) fn load_advancements(&mut self) {
if self.adv.loaded || self.remote.is_some() || self.no_player_here() {
return;
@@ -622,6 +642,19 @@ impl Game<'_> {
adv::conditions(&c["player"], &pctx, w) && adv::item(&c["item"], &it, w)
});
}
+ pub(super) fn trigger_item_entity(
+ &mut self,
+ name: &str,
+ stack: &ItemStack,
+ target: &EntityView,
+ ) {
+ if self.lan_acting.is_some() {
+ return;
+ }
+ let me = self.player_entity();
+ let it = item_view(stack);
+ self.trigger(name, |c, w| adv::item_entity(c, &me, target, &it, w));
+ }
/// `EnterBlockTrigger`: the block, its state properties and the player.
pub(super) fn trigger_enter_block(&mut self, state: horizon_world::registry::BlockStateId) {
let Some(definition) = self.pack.assets.registry.state(state).cloned() else {
diff --git a/crates/horizon-client/src/game/agent.rs b/crates/horizon-client/src/game/agent.rs
index 48b24bbb3..8a6b54650 100644
--- a/crates/horizon-client/src/game/agent.rs
+++ b/crates/horizon-client/src/game/agent.rs
@@ -466,9 +466,16 @@ impl Game<'_> {
}),
"dimension": self.dim.id(),
"gamemode": format!("{:?}", self.mode).to_lowercase(),
+ // The bed (its head) the player sleeps in.
+ "sleeping": self.sleeping,
+ // The item in use: its slot and for how many ticks.
+ "using": self.using.map(|(slot, ticks)| json!({ "slot": slot, "ticks": ticks })),
"time": { "day_time": self.world.day_time, "day": self.world.day_time.div_euclid(24000), "time_of_day": self.world.day_time.rem_euclid(24000) },
"weather": { "raining": self.world.weather.raining, "thundering": self.world.weather.thundering },
"paused": self.pause,
+ // Mouse movement turns the camera (`apply_mouse_look`): the real
+ // pointer is grabbed, or an agent's `mouse-move` stands in for it.
+ "pointer_grabbed": self.captured || self.agent_pointer,
"player": player,
"selected": self.selected + 1,
"held": self.held().map(|s| self.stack_value(s)),
@@ -613,6 +620,9 @@ impl Game<'_> {
"screen": self.screen_label(),
"buttons": buttons,
});
+ if let Some(chat) = &self.ui.chat_screen {
+ v["chat_input"] = json!(chat.input.value);
+ }
if self.title.is_some() {
v["menu"] = self.title_value();
}
@@ -631,6 +641,15 @@ impl Game<'_> {
v["craft_size"] = json!(self.craft_size);
v["station"] = json!(self.station.as_ref().map(|s| format!("{:?}", s.kind)));
v["container"] = json!(self.container);
+ // The recipe book's buttons (GUI pixels): the book button, then
+ // the recipe buttons of the page, page arrows, filter and tabs.
+ let book = self.recipe_book_targets();
+ if !book.is_empty() {
+ v["recipe_book"] = json!({
+ "targets": book.iter().map(|t| t.rect).collect::>(),
+ "known": self.recipe_book_known(),
+ });
+ }
v["slot_ids"] = json!(
"0-8 hotbar, 9-35 inventory, 100+ crafting grid (row-major), 200 crafting result, 300+ container, 500-503 armor, 504 offhand, 600+ station"
);
diff --git a/crates/horizon-client/src/game/armor_stands.rs b/crates/horizon-client/src/game/armor_stands.rs
index 03a60faca..4ea8df359 100644
--- a/crates/horizon-client/src/game/armor_stands.rs
+++ b/crates/horizon-client/src/game/armor_stands.rs
@@ -413,6 +413,32 @@ impl Game<'_> {
if a.invisible {
continue;
}
+ // ArmorStand.shouldRenderAtSqrDistance: 256 times the box's mean
+ // edge (4 for a marker's empty box), whatever the entity distance.
+ // LivingEntityRenderer grows the culling box by 0.5 for a dragon head.
+ let (width, height) = match (a.marker, a.small) {
+ (true, _) => (0.0, 0.0),
+ (false, true) => (0.25, 0.9875),
+ (false, false) => (0.5, 1.975),
+ };
+ let edge = (width + height + width) / 3.0 * 4.0;
+ let range = if edge == 0.0 { 4.0 } else { edge } * 64.0;
+ let dragon = a.equipment[5]
+ .as_ref()
+ .is_some_and(|i| &*i.item == "minecraft:dragon_head");
+ let position = super::entity_culling::at(a.position);
+ if !self.standing_entity_in_view(
+ camera,
+ position,
+ position,
+ alpha,
+ width,
+ height,
+ range,
+ if dragon { 0.5 } else { 0.0 },
+ ) {
+ continue;
+ }
let Some(model) = (if a.small { &assets.small } else { &assets.main }) else {
continue;
};
@@ -700,7 +726,7 @@ impl Game<'_> {
}
}
/// `AbstractSkullBlock.getType` of a skull item.
-fn skull_kind(item: &str) -> Option<&'static str> {
+pub(super) fn skull_kind(item: &str) -> Option<&'static str> {
Some(match item {
"minecraft:skeleton_skull" => "skeleton",
"minecraft:wither_skeleton_skull" => "wither_skeleton",
diff --git a/crates/horizon-client/src/game/beacon.rs b/crates/horizon-client/src/game/beacon.rs
index 15a7de79d..73cdd15a4 100644
--- a/crates/horizon-client/src/game/beacon.rs
+++ b/crates/horizon-client/src/game/beacon.rs
@@ -105,24 +105,13 @@ impl Game<'_> {
.find(|&y| !self.res.facts.is_air(self.world.block(x, y, z)))
.map_or(min, |y| y + 1)
}
- /// `BeaconBlockEntity.tick` for every beacon.
- pub(super) fn tick_beacons(&mut self) {
- let keys: Vec<(i32, i32, i32)> = self
- .world
- .block_entities
- .iter()
- .filter(|(_, e)| matches!(e, BlockEntity::Beacon(_)))
- .map(|(k, _)| *k)
- .collect();
- for key in keys {
- let Some(BlockEntity::Beacon(mut b)) = self.world.block_entities.remove(&key) else {
- continue;
- };
- self.tick_beacon(key, &mut b);
- self.world
- .block_entities
- .insert(key, BlockEntity::Beacon(b));
- }
+ /// `BeaconBlockEntity.tick` of the beacon at `key`.
+ pub(super) fn tick_beacon_at(&mut self, key: (i32, i32, i32)) {
+ let Some(BlockEntity::Beacon(mut b)) = self.world.block_entities.take(&key) else {
+ return;
+ };
+ self.tick_beacon(key, &mut b);
+ self.world.block_entities.put(key, BlockEntity::Beacon(b));
}
fn tick_beacon(&mut self, (x, y, z): (i32, i32, i32), b: &mut Beacon) {
let mut check = if b.last_check_y < y {
@@ -220,7 +209,11 @@ impl Game<'_> {
levels
}
/// `applyEffects`: the powers for players within `levels * 10 + 10` (any height above).
+ /// `BeaconBlockEntity.applyEffects`: every player in range.
fn beacon_effects(&mut self, p: [i32; 3], b: &Beacon) {
+ self.for_each_player(|g| g.beacon_effects_on_player(p, b));
+ }
+ fn beacon_effects_on_player(&mut self, p: [i32; 3], b: &Beacon) {
let Some(primary) = b.primary.as_deref().and_then(effect_id) else {
return;
};
diff --git a/crates/horizon-client/src/game/beehives.rs b/crates/horizon-client/src/game/beehives.rs
index 0520e4367..52fed3f3b 100644
--- a/crates/horizon-client/src/game/beehives.rs
+++ b/crates/horizon-client/src/game/beehives.rs
@@ -87,48 +87,37 @@ impl Game<'_> {
let facing = beehive::facing_step(props.get("facing").map(String::as_str));
Some((honey, facing))
}
- /// `BeehiveBlockEntity.serverTick` for every hive, after an emergency
- /// exit for those with fire beside them (`BeehiveBlock.updateShape`).
- pub(super) fn tick_beehives(&mut self) {
- let mut keys: Vec<(i32, i32, i32)> = self
- .world
- .block_entities
- .iter()
- .filter(|(_, e)| matches!(e, BlockEntity::Beehive(_)))
- .map(|(k, _)| *k)
- .collect();
- keys.sort_unstable();
- for key in keys {
- let at = [key.0, key.1, key.2];
- let Some((honey, facing)) = self.hive_state(at) else {
- continue;
- };
- let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.remove(&key)
- else {
- continue;
- };
- let fire = [
- [1, 0, 0],
- [-1, 0, 0],
- [0, 1, 0],
- [0, -1, 0],
- [0, 0, 1],
- [0, 0, -1],
- ]
- .iter()
- .any(|d| {
- let state = self.world.block(at[0] + d[0], at[1] + d[1], at[2] + d[2]);
- &*self.res.facts.get(state).name == "minecraft:fire"
- });
- let mut host = GameHive { game: self };
- if fire && !hive.bees.is_empty() {
- hive.release_all(at, facing, honey, Release::Emergency, &mut host);
- }
- hive.server_tick(at, facing, honey, &mut host);
- self.world
- .block_entities
- .insert(key, BlockEntity::Beehive(hive));
+ /// `BeehiveBlockEntity.serverTick` of the hive at `key`, after an
+ /// emergency exit if fire is beside it (`BeehiveBlock.updateShape`).
+ pub(super) fn tick_beehive(&mut self, key: (i32, i32, i32)) {
+ let at = [key.0, key.1, key.2];
+ let Some((honey, facing)) = self.hive_state(at) else {
+ return;
+ };
+ let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.take(&key) else {
+ return;
+ };
+ let fire = [
+ [1, 0, 0],
+ [-1, 0, 0],
+ [0, 1, 0],
+ [0, -1, 0],
+ [0, 0, 1],
+ [0, 0, -1],
+ ]
+ .iter()
+ .any(|d| {
+ let state = self.world.block(at[0] + d[0], at[1] + d[1], at[2] + d[2]);
+ &*self.res.facts.get(state).name == "minecraft:fire"
+ });
+ let mut host = GameHive { game: self };
+ if fire && !hive.bees.is_empty() {
+ hive.release_all(at, facing, honey, Release::Emergency, &mut host);
}
+ hive.server_tick(at, facing, honey, &mut host);
+ self.world
+ .block_entities
+ .put(key, BlockEntity::Beehive(hive));
}
/// `BeehiveBlockEntity.addOccupant` for a bee its `BeeEnterHiveGoal`
/// sent in: off its lead, its tag stored, the bee gone.
@@ -152,13 +141,13 @@ impl Game<'_> {
self.mobs[i].extra.mount = None;
let tag = self.mob_tree_nbt(i);
let flower = bee::get(&self.mobs[i]).and_then(|b| b.flower);
- let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.remove(&key) else {
+ let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.take(&key) else {
return;
};
let stored = hive.add_occupant(at, tag, flower, &mut GameHive { game: self });
self.world
.block_entities
- .insert(key, BlockEntity::Beehive(hive));
+ .put(key, BlockEntity::Beehive(hive));
if stored && let Some(m) = self.mobs.iter_mut().find(|m| m.id == mob) {
m.removed = true;
}
@@ -166,13 +155,13 @@ impl Game<'_> {
/// `BeehiveBlockEntity.emptyAllLivingFromHive` with no player about.
pub(super) fn empty_hive(&mut self, at: [i32; 3], facing: [i32; 2], status: Release) {
let key = (at[0], at[1], at[2]);
- let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.remove(&key) else {
+ let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.take(&key) else {
return;
};
hive.release_all(at, facing, None, status, &mut GameHive { game: self });
self.world
.block_entities
- .insert(key, BlockEntity::Beehive(hive));
+ .put(key, BlockEntity::Beehive(hive));
}
/// `BeehiveBlock.playerDestroy` without silk touch: the bees come out
/// angry at the player unless smoke calms them, then
diff --git a/crates/horizon-client/src/game/block_entity_ticks.rs b/crates/horizon-client/src/game/block_entity_ticks.rs
new file mode 100644
index 000000000..afe1224fb
--- /dev/null
+++ b/crates/horizon-client/src/game/block_entity_ticks.rs
@@ -0,0 +1,144 @@
+//! `Level.tickBlockEntities` for the block entities ticked together here
+//! (hoppers, crafters, jukeboxes, beacons, creaking hearts, spawners, trial
+//! spawners, vaults, beehives and furnaces): only those whose state has a
+//! ticker, in vanilla's list order (`horizon_client::block_entities`), in
+//! chunks that tick blocks. Sculk, brewing stands and pistons tick in their
+//! own passes.
+use super::Game;
+use horizon_client::{
+ Result,
+ block_entities::{Pos, Ticking},
+ containers::{BlockEntity, FurnaceKind, HOPPER_SLOTS},
+};
+use horizon_world::registry::BlockStateId;
+
+impl Game<'_> {
+ pub(super) fn tick_block_entities(&mut self) -> Result<()> {
+ self.tick_mount_menu();
+ self.load_entity_types();
+ if !self.world.block_entities.has_states() {
+ let states = self.ticking_states();
+ self.world.block_entities.set_states(states);
+ }
+ self.forget_gone_hoppers();
+ let ticking = self.block_ticking_area();
+ let mut spawners = Vec::new();
+ let mut trial_spawners = Vec::new();
+ for slot in self.world.block_entity_tickers() {
+ let pos = slot.0;
+ // Ticks before this one can remove it (`TickingBlockEntity.isRemoved`).
+ if !self.world.block_entities.is_live(slot)
+ || !ticking(pos.0, pos.2)
+ || !self.border.contains(f64::from(pos.0), f64::from(pos.2))
+ {
+ continue;
+ }
+ match self.world.block_entities.get(&pos) {
+ Some(BlockEntity::Chest(items)) if items.len() == HOPPER_SLOTS => {
+ self.tick_hopper(pos)
+ }
+ Some(BlockEntity::Crafter(_)) => self.tick_crafter(pos),
+ Some(BlockEntity::Jukebox(_)) => self.tick_jukebox(pos),
+ Some(BlockEntity::Beacon(_)) => self.tick_beacon_at(pos),
+ Some(BlockEntity::CreakingHeart(_)) => self.tick_creaking_heart(pos)?,
+ Some(BlockEntity::Spawner(_)) => {
+ self.tick_spawner(pos)?;
+ spawners.push(pos);
+ }
+ Some(BlockEntity::TrialSpawner(_)) => {
+ self.tick_trial_spawner(pos)?;
+ trial_spawners.push(pos);
+ }
+ Some(BlockEntity::Vault(_)) => self.tick_vault(pos)?,
+ Some(BlockEntity::Beehive(_)) => self.tick_beehive(pos),
+ Some(BlockEntity::Furnace(_)) => self.tick_furnace(pos)?,
+ _ => {}
+ }
+ }
+ self.update_song_volumes();
+ self.scan_for_hearts();
+ // The client ticks (particles, sounds, the turning mob) are for a
+ // window; a dedicated or integrated server has none.
+ if self.options.dedicated.is_none() {
+ self.client_tick_spawners(&spawners);
+ for key in trial_spawners {
+ self.client_tick_trial_spawner(key);
+ }
+ }
+ Ok(())
+ }
+ /// `BlockState.getTicker` of every state, for the block entities ticked
+ /// here. A creaking heart keeps its slot while uprooted (see
+ /// `tick_creaking_heart`).
+ fn ticking_states(&self) -> Vec {
+ let registry = self.pack.assets.registry;
+ (0..registry.len())
+ .map(|i| {
+ let state = BlockStateId(i as u32);
+ let name: &str = &self.res.facts.get(state).name;
+ match name {
+ "minecraft:hopper"
+ | "minecraft:crafter"
+ | "minecraft:beacon"
+ | "minecraft:creaking_heart"
+ | "minecraft:spawner"
+ | "minecraft:trial_spawner"
+ | "minecraft:vault"
+ | "minecraft:beehive"
+ | "minecraft:bee_nest" => Ticking::Yes,
+ "minecraft:jukebox" => {
+ let record = registry
+ .state(state)
+ .and_then(|s| s.properties.get("has_record"))
+ .is_some_and(|v| v == "true");
+ if record { Ticking::Yes } else { Ticking::Idle }
+ }
+ n if FurnaceKind::from_block(n).is_some() => Ticking::Yes,
+ _ => Ticking::No,
+ }
+ })
+ .collect()
+ }
+ /// `ServerLevel.shouldTickBlocksAt`: chunks within the simulation
+ /// distance plus one (`DistanceManager.inBlockTickingRange`, Chebyshev
+ /// in chunks) of the player or a guest. With nobody there, a dedicated
+ /// server ticks none; the game alone (no player yet, headless fixtures)
+ /// ticks every chunk.
+ fn block_ticking_area(&self) -> impl Fn(i32, i32) -> bool + use<> {
+ let d = self.settings.simulation_distance.max(2) + 1;
+ let mut centres: Vec<(i32, i32)> = self.streaming.extra.iter().map(|&(c, _)| c).collect();
+ if let Some(p) = &self.player {
+ centres.push((
+ (p.position.x.floor() as i32) >> 4,
+ (p.position.z.floor() as i32) >> 4,
+ ));
+ }
+ let everywhere = centres.is_empty() && self.options.dedicated.is_none();
+ move |x, z| {
+ everywhere
+ || centres
+ .iter()
+ .any(|&(cx, cz)| ((x >> 4) - cx).abs().max(((z >> 4) - cz).abs()) <= d)
+ }
+ }
+ /// `AbstractFurnaceBlockEntity.serverTick` of the furnace at `pos`, and
+ /// its block's `lit` following it.
+ fn tick_furnace(&mut self, pos: Pos) -> Result<()> {
+ let Some(BlockEntity::Furnace(f)) = self.world.block_entities.get_mut(&pos) else {
+ return Ok(());
+ };
+ let Some(lit) = f.tick(&self.res.recipes, &self.res.items, &self.res.providers) else {
+ return Ok(());
+ };
+ let state = self.world.block(pos.0, pos.1, pos.2);
+ if let Some(mut s) = self.pack.assets.registry.state(state).cloned()
+ && s.properties.contains_key("lit")
+ {
+ s.properties.insert("lit".into(), lit.to_string());
+ if let Ok(id) = self.pack.assets.registry.resolve(&s) {
+ self.world.set(pos.0, pos.1, pos.2, id)?;
+ }
+ }
+ Ok(())
+ }
+}
diff --git a/crates/horizon-client/src/game/boats.rs b/crates/horizon-client/src/game/boats.rs
index a5a609cac..8f2cad5f5 100644
--- a/crates/horizon-client/src/game/boats.rs
+++ b/crates/horizon-client/src/game/boats.rs
@@ -2,7 +2,7 @@
//! paddling controls, collisions, riding (`positionRider`, `clampRotation`,
//! dismounting), `BoatItem` placement, `VehicleEntity.hurtServer` breaking,
//! saving and `AbstractBoatRenderer` with animated paddles.
-use super::{Game, Keys, view_vector};
+use super::{Game, Keys, entity_culling::at, view_vector};
use horizon_client::{
blocks::Fluid,
collisions::SceneCollisions,
@@ -700,8 +700,19 @@ impl Game<'_> {
/// AbstractBoatRenderer.
pub(super) fn boat_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec) {
let a = alpha as f32;
+ let range = super::entity_culling::default_range(
+ glam::DVec3::new(WIDTH, HEIGHT, WIDTH),
+ self.settings.entity_distance,
+ );
for b in &self.boats {
let entity_start = out.len();
+ // EntityRenderer.shouldRender.
+ let (previous, position) = (at(b.previous), at(b.position));
+ if !self.standing_entity_in_view(
+ camera, previous, position, alpha, WIDTH, HEIGHT, range, 0.0,
+ ) {
+ continue;
+ }
let models = if b.chest {
&self.boat_models.chest_models
} else {
diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs
index bcf6426e1..cb8a3a0b5 100644
--- a/crates/horizon-client/src/game/chat.rs
+++ b/crates/horizon-client/src/game/chat.rs
@@ -10,6 +10,18 @@ use horizon_client::{
text::{ClickEvent, Style, Text},
};
use std::collections::BTreeMap;
+
+/// The tree the chat parses and completes with: a server's, once it has
+/// sent one (ClientPacketListener.commands), else the game's own.
+fn chat_tree<'a>(
+ remote: &'a Option,
+ mods: &'a super::mods::ModsState,
+) -> &'a horizon_client::command::Dispatcher {
+ match remote.as_ref().and_then(|r| r.commands.as_ref()) {
+ Some(tree) => tree,
+ None => mods.dispatcher(),
+ }
+}
use winit::{
event::KeyEvent,
keyboard::{KeyCode, PhysicalKey},
@@ -378,6 +390,10 @@ impl Game<'_> {
/// The block the player is looking at, for coordinate suggestions.
fn refresh_dynamic_registries(&mut self) {
self.ui.registries.target_block = self.pick().map(|h| h.pos);
+ // ClientPacketListener.getOnlinePlayerNames on a server.
+ if let Some(names) = self.remote_online_names() {
+ self.ui.registries.players = names;
+ }
}
pub(super) fn open_chat(&mut self, initial: &str) {
if self.player.is_none() {
@@ -391,7 +407,7 @@ impl Game<'_> {
let b = HudBatch::new(size);
let m = Measure(&self.atlas.font);
let c = Commands {
- dispatcher: self.mods.dispatcher(),
+ dispatcher: chat_tree(&self.remote, &self.mods),
registries: &self.ui.registries,
};
let mut screen = ChatScreen::new(
@@ -449,7 +465,7 @@ impl Game<'_> {
if let Some(shortcut) = self.edit_shortcut(event) {
let m = Measure(&self.atlas.font);
let c = Commands {
- dispatcher: self.mods.dispatcher(),
+ dispatcher: chat_tree(&self.remote, &self.mods),
registries: &self.ui.registries,
};
if let Some(screen) = self.ui.chat_screen.as_mut() {
@@ -495,7 +511,7 @@ impl Game<'_> {
};
let m = Measure(&self.atlas.font);
let c = Commands {
- dispatcher: self.mods.dispatcher(),
+ dispatcher: chat_tree(&self.remote, &self.mods),
registries: &self.ui.registries,
};
match screen.key(&m, &c, &self.ui.chat.recent, key, shift, ctrl) {
@@ -517,11 +533,28 @@ impl Game<'_> {
}
}
}
+ /// The server's completions for an `ask_server` request
+ /// (ClientPacketListener.handleCommandSuggestions).
+ pub(super) fn chat_server_suggestions(
+ &mut self,
+ id: i32,
+ range: (usize, usize),
+ list: Vec<(String, Option)>,
+ ) {
+ let m = Measure(&self.atlas.font);
+ let c = Commands {
+ dispatcher: chat_tree(&self.remote, &self.mods),
+ registries: &self.ui.registries,
+ };
+ if let Some(screen) = self.ui.chat_screen.as_mut() {
+ screen.server_suggestions(&m, &c, id, range, list);
+ }
+ }
/// Text typed into the chat box (control socket `chat`).
pub(super) fn chat_type(&mut self, text: &str) {
let m = Measure(&self.atlas.font);
let c = Commands {
- dispatcher: self.mods.dispatcher(),
+ dispatcher: chat_tree(&self.remote, &self.mods),
registries: &self.ui.registries,
};
if let Some(screen) = self.ui.chat_screen.as_mut() {
@@ -531,6 +564,11 @@ impl Game<'_> {
/// ChatScreen.handleChatInput: history, then a command or a chat line.
pub(super) fn handle_chat_input(&mut self, message: &str) {
self.ui.chat.add_recent(message);
+ // On a server (single player's own included) the server runs it.
+ if self.remote.is_some() {
+ self.send_chat(message);
+ return;
+ }
if let Some(command) = message.strip_prefix('/') {
self.run_command(command);
} else {
@@ -572,7 +610,7 @@ impl Game<'_> {
});
let m = Measure(&self.atlas.font);
let c = Commands {
- dispatcher: self.mods.dispatcher(),
+ dispatcher: chat_tree(&self.remote, &self.mods),
registries: &self.ui.registries,
};
if let Some(screen) = self.ui.chat_screen.as_mut() {
@@ -617,7 +655,7 @@ impl Game<'_> {
};
let m = Measure(&self.atlas.font);
let c = Commands {
- dispatcher: self.mods.dispatcher(),
+ dispatcher: chat_tree(&self.remote, &self.mods),
registries: &self.ui.registries,
};
screen.resize(&m, &c, batch.width as i32, batch.height as i32);
diff --git a/crates/horizon-client/src/game/command_blocks.rs b/crates/horizon-client/src/game/command_blocks.rs
index 5a5fa11c8..717134515 100644
--- a/crates/horizon-client/src/game/command_blocks.rs
+++ b/crates/horizon-client/src/game/command_blocks.rs
@@ -357,6 +357,7 @@ impl Game<'_> {
silent: false,
store: None,
elsewhere: false,
+ level: None,
block: Some(pos),
};
// performPrefixedCommand: a leading slash is allowed.
@@ -598,13 +599,13 @@ impl Game<'_> {
if let Ok(id) = registry.resolve(&wanted)
&& wanted != *current
{
- let entity = self.world.block_entities.remove(&pos);
+ let entity = self.world.block_entities.take(&pos);
let at = BlockPos::new(pos.0, pos.1, pos.2);
self.with_level(|b, level, ticks| {
b.set_block(level, ticks, at, id, flags::UPDATE_CLIENTS)
});
if let Some(entity) = entity {
- self.world.block_entities.insert(pos, entity);
+ self.world.block_entities.put(pos, entity);
}
let _ = self.process_level_events();
}
diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs
index 6c4817f63..575f5c93e 100644
--- a/crates/horizon-client/src/game/commands.rs
+++ b/crates/horizon-client/src/game/commands.rs
@@ -1,5 +1,6 @@
//! Command execution (the `execute` side of each vanilla command class):
//! entity selectors resolved against the game, vanilla feedback and errors.
+mod admin;
pub(super) mod compute;
mod data;
mod effects;
@@ -160,8 +161,70 @@ impl Game<'_> {
return;
}
if self.ui.rules.bool("send_command_feedback") {
- self.system_message(message);
+ self.system_message(message.clone());
}
+ self.broadcast_to_admins(message);
+ }
+ /// CommandSourceStack.broadcastToAdmins (`sendSuccess` with `broadcast`)
+ /// for a guest's command, the host's in a world open to LAN and the
+ /// dedicated server console's when `broadcast-console-to-ops` is on:
+ /// `[name: message]`, gray and italic, for the other operators when
+ /// `send_command_feedback`, and for a player's command on a dedicated
+ /// server the console when `log_admin_commands`. Queued while the
+ /// command runs; `send_admin_feedback` sends it.
+ pub(super) fn broadcast_to_admins(&mut self, message: Text) {
+ let informs = match self.console_broadcast {
+ Some(broadcast) => broadcast,
+ // While a guest acts the host's LanHost is out of `self.lan`.
+ None => self.lan_acting.is_some() || self.lan.is_some(),
+ };
+ if !informs
+ || message
+ .translation_key()
+ .is_some_and(|k| admin::QUIET.contains(&k))
+ {
+ return;
+ }
+ let ops = self.ui.rules.bool("send_command_feedback");
+ // MinecraftServer.sendSystemMessage, unless the server is the source.
+ let console = self.console_broadcast.is_none()
+ && self.lan_acting.is_some()
+ && self.options.dedicated.is_some()
+ && self.ui.rules.bool("log_admin_commands");
+ if !ops && !console {
+ return;
+ }
+ // getDisplayName: the entity the command runs as (`execute as`), or
+ // the server's own source, "Server".
+ let who = match self.command_source.and_then(|s| s.entity) {
+ Some(entity) => self.target_name(entity),
+ None if self.console_broadcast.is_some() => Text::literal("Server".to_owned()),
+ None => self.player_display_name(),
+ };
+ let line = Text::translate("chat.type.admin", &[who, message])
+ .with_color(text::GRAY)
+ .italic();
+ self.admin_feedback.push((line, ops, console));
+ }
+ /// Player.getDisplayName: the name (team-formatted), suggesting a
+ /// `/tell`, showing the player on hover, inserting the name.
+ fn player_display_name(&self) -> Text {
+ let name = self.acting_player_name().to_owned();
+ let Some(uuid) = self.lan_acting_uuid else {
+ return self.target_name(Target::Player);
+ };
+ self.target_name(Target::Player).with_component_fields(vec![
+ (
+ "click_event".into(),
+ serde_json::json!({"action": "suggest_command", "command": format!("/tell {name} ")}),
+ ),
+ (
+ "hover_event".into(),
+ serde_json::json!({"action": "show_entity", "id": "minecraft:player",
+ "uuid": horizon_protocol::crypto::uuid_string(uuid), "name": name}),
+ ),
+ ("insertion".into(), name.into()),
+ ])
}
fn source_position(&self) -> [f64; 3] {
if let Some(s) = &self.command_source {
@@ -321,12 +384,16 @@ impl Game<'_> {
.map_or_else(String::new, |o| o.kind.clone()),
}
}
+ /// The name of the player the game acts for: a guest's own while their
+ /// command or action runs (`Player.getName`).
+ pub(super) fn acting_player_name(&self) -> &str {
+ self.lan_acting_name.as_deref().unwrap_or(PLAYER_NAME)
+ }
/// Entity.getDisplayName.
pub(super) fn target_name(&self, t: Target) -> Text {
match t {
Target::Player => {
- // A guest's commands name the guest.
- let name = self.lan_acting_name.as_deref().unwrap_or(PLAYER_NAME);
+ let name = self.acting_player_name();
match self.score.board.players_team(name) {
// PlayerTeam.formatNameForTeam.
Some(team) => team.formatted_name(Text::literal(name)),
@@ -767,7 +834,7 @@ impl Game<'_> {
}
self.feedback(Text::translate(
"commands.gamemode.success.other",
- &[Text::literal(PLAYER_NAME), mode_name],
+ &[Text::literal(self.acting_player_name()), mode_name],
));
}
}
@@ -922,7 +989,7 @@ impl Game<'_> {
&[
Text::literal(count.to_string()),
name,
- Text::literal(PLAYER_NAME),
+ Text::literal(self.acting_player_name()),
],
)
} else {
@@ -1089,7 +1156,23 @@ impl Game<'_> {
(-(dy.atan2(horizontal).to_degrees())) as f32,
]);
}
+ // `execute in` another dimension: a server's player moves to that
+ // level (ServerPlayer.teleport into another level), after the command.
+ let level = self
+ .command_source
+ .and_then(|s| s.level)
+ .filter(|d| *d != self.dim && self.options.dedicated.is_some());
for &t in &targets {
+ if let (Some(dim), Target::Player, Some(conn)) = (level, t, self.lan_acting) {
+ self.level_teleports
+ .push(super::server_travel::LevelTeleport {
+ conn,
+ dim,
+ at: pos,
+ rotation,
+ });
+ continue;
+ }
self.teleport_to(t, pos, rotation);
}
let [x, y, z] = pos.map(|v| Text::literal(format_double(v)));
@@ -1418,7 +1501,9 @@ impl Game<'_> {
return Err(err("commands.summon.failed", &[]));
}
"experience_orb" => {
+ self.next_entity += 1;
self.orbs.push(horizon_client::entities::ExperienceOrb {
+ id: self.next_entity,
position: Vec3::new(pos[0], pos[1], pos[2]),
previous: Vec3::new(pos[0], pos[1], pos[2]),
velocity: Vec3::new(0.0, 0.0, 0.0),
@@ -1444,7 +1529,13 @@ impl Game<'_> {
self.carts.push(cart);
name = Text::translate(&format!("entity.minecraft.{k}"), &[]);
}
- _ => return Err(err("commands.summon.failed", &[])),
+ // SummonCommand.createEntity: any other type from an empty compound.
+ _ => {
+ let Some(target) = self.summon_with_nbt(&kind, pos, "{}")? else {
+ return Err(err("commands.summon.failed", &[]));
+ };
+ name = self.target_name(target);
+ }
}
}
self.feedback(Text::translate("commands.summon.success", &[name]));
@@ -1794,7 +1885,7 @@ impl Game<'_> {
),
_ => None,
};
- let player = Text::literal(PLAYER_NAME);
+ let player = Text::literal(self.acting_player_name());
let players = targets.len();
if let (Some(i), Some(Arg::Str(criterion))) = (index, ctx.get("criterion")) {
let a = &tree.list[i];
@@ -1904,7 +1995,10 @@ impl Game<'_> {
};
self.system_message(Text::translate(
&format!("commands.experience.query.{unit}"),
- &[Text::literal(PLAYER_NAME), Text::literal(value.to_string())],
+ &[
+ Text::literal(self.acting_player_name()),
+ Text::literal(value.to_string()),
+ ],
));
return Ok(value);
}
@@ -1941,7 +2035,7 @@ impl Game<'_> {
&key,
&[
Text::literal(amount.to_string()),
- Text::literal(PLAYER_NAME),
+ Text::literal(self.acting_player_name()),
],
));
Ok(targets.len() as i32)
@@ -2248,7 +2342,7 @@ impl Game<'_> {
return Err(if targets.len() == 1 {
CommandError::new(Text::translate(
"clear.failed.single",
- &[Text::literal(PLAYER_NAME)],
+ &[Text::literal(self.acting_player_name())],
))
} else {
err("clear.failed.multiple", &[&targets.len()])
@@ -2259,7 +2353,7 @@ impl Game<'_> {
&format!("commands.clear.{kind}.single"),
&[
Text::literal(removed.to_string()),
- Text::literal(PLAYER_NAME),
+ Text::literal(self.acting_player_name()),
],
));
Ok(removed)
@@ -2312,7 +2406,7 @@ impl Game<'_> {
};
let from = self.source_position().map(|v| v.floor() as i32);
const RANGE: i32 = 256;
- let mut cache: std::collections::HashMap> =
+ let mut cache: std::collections::HashMap> =
std::collections::HashMap::new();
let mut best: Option<(i64, [i32; 3], &'static str)> = None;
let (cx0, cz0) = ((from[0] - RANGE) >> 4, (from[2] - RANGE) >> 4);
@@ -2323,15 +2417,12 @@ impl Game<'_> {
continue;
};
for (i, section) in chunk.sections.iter().enumerate() {
- let mut wanted_state = |v: u32| {
- let state = v as u16;
+ let mut wanted_state = |state: u32| {
cache
.entry(state)
.or_insert_with(|| {
- self.poi_type(horizon_world::registry::BlockStateId(u32::from(
- state,
- )))
- .filter(|t| wanted.iter().any(|w| w == t))
+ self.poi_type(horizon_world::registry::BlockStateId(state))
+ .filter(|t| wanted.iter().any(|w| w == t))
})
.is_some()
};
@@ -2513,7 +2604,7 @@ impl Game<'_> {
let name = match self.command_source.map(|s| s.entity) {
Some(Some(t)) => self.target_name(t),
Some(None) => Text::literal("Server"),
- None => Text::literal(PLAYER_NAME),
+ None => Text::literal(self.acting_player_name()),
};
let line = match id {
"say" => Text::translate("chat.type.announcement", &[name, message]),
@@ -2523,14 +2614,14 @@ impl Game<'_> {
// Whispering to yourself: the incoming and outgoing lines.
let out = Text::translate(
"commands.message.display.outgoing",
- &[Text::literal(PLAYER_NAME), message.clone()],
+ &[Text::literal(self.acting_player_name()), message.clone()],
)
.with_color(text::GRAY)
.italic();
self.system_message(out);
Text::translate(
"commands.message.display.incoming",
- &[Text::literal(PLAYER_NAME), message],
+ &[Text::literal(self.acting_player_name()), message],
)
.with_color(text::GRAY)
.italic()
diff --git a/crates/horizon-client/src/game/commands/admin.rs b/crates/horizon-client/src/game/commands/admin.rs
new file mode 100644
index 000000000..1a5115f4d
--- /dev/null
+++ b/crates/horizon-client/src/game/commands/admin.rs
@@ -0,0 +1,92 @@
+//! Which command feedback vanilla tells the other operators and the console
+//! about (`CommandSourceStack.sendSuccess`'s `broadcast`).
+
+/// The replies vanilla sends with `broadcast` false: queries and lists, which
+/// only the player who asked sees. Every other success message is broadcast.
+pub(super) const QUIET: &[&str] = &[
+ "commands.attribute.base_value.get.success",
+ "commands.attribute.base_value.reset.success",
+ "commands.attribute.base_value.set.success",
+ "commands.attribute.modifier.add.success",
+ "commands.attribute.modifier.remove.success",
+ "commands.attribute.modifier.value.get.success",
+ "commands.attribute.value.get.success",
+ "commands.banlist.entry",
+ "commands.banlist.list",
+ "commands.banlist.none",
+ "commands.bossbar.list.bars.none",
+ "commands.bossbar.list.bars.some",
+ "commands.data.block.get",
+ "commands.data.block.query",
+ "commands.data.entity.get",
+ "commands.data.entity.query",
+ "commands.data.storage.get",
+ "commands.data.storage.query",
+ "commands.datapack.list.available.none",
+ "commands.datapack.list.available.success",
+ "commands.datapack.list.enabled.none",
+ "commands.datapack.list.enabled.success",
+ "commands.difficulty.query",
+ "commands.execute.conditional.pass",
+ "commands.execute.conditional.pass_count",
+ "commands.experience.query.levels",
+ "commands.experience.query.points",
+ "commands.fetchprofile.copy_component",
+ "commands.fetchprofile.copy_text",
+ "commands.fetchprofile.give_item",
+ "commands.fetchprofile.summon_mannequin",
+ "commands.forceload.list.multiple",
+ "commands.forceload.list.single",
+ "commands.forceload.query.success",
+ "commands.gamerule.query",
+ "commands.jfr.started",
+ "commands.jfr.stopped",
+ "commands.list.players",
+ "commands.locate.biome.success",
+ "commands.locate.poi.success",
+ "commands.locate.structure.success",
+ "commands.perf.started",
+ "commands.perf.stopped",
+ "commands.posteffect.list.empty",
+ "commands.posteffect.list.success",
+ "commands.random.reset.all.success",
+ "commands.random.reset.success",
+ "commands.random.sample.success",
+ "commands.save.saving",
+ "commands.scoreboard.objectives.list.empty",
+ "commands.scoreboard.objectives.list.success",
+ "commands.scoreboard.players.get.success",
+ "commands.scoreboard.players.list.empty",
+ "commands.scoreboard.players.list.entity.empty",
+ "commands.scoreboard.players.list.entity.entry",
+ "commands.scoreboard.players.list.entity.success",
+ "commands.scoreboard.players.list.success",
+ "commands.seed.success",
+ "commands.spectate.success.started",
+ "commands.spectate.success.stopped",
+ "commands.team.list.members.empty",
+ "commands.team.list.members.success",
+ "commands.team.list.teams.empty",
+ "commands.team.list.teams.success",
+ "commands.team.option.prefix.success",
+ "commands.team.option.suffix.success",
+ "commands.tick.query.percentiles",
+ "commands.tick.query.rate.running",
+ "commands.tick.query.rate.sprinting",
+ "commands.tick.status.frozen",
+ "commands.tick.status.lagging",
+ "commands.tick.status.running",
+ "commands.tick.status.sprinting",
+ "commands.time.query.absolute",
+ "commands.time.query.gametime",
+ "commands.time.query.timeline",
+ "commands.time.query.timeline.repetitions",
+ "commands.waypoint.list.empty",
+ "commands.waypoint.list.success",
+ "commands.waypoint.modify.color",
+ "commands.waypoint.modify.color.reset",
+ "commands.waypoint.modify.style",
+ "commands.whitelist.list",
+ "commands.whitelist.none",
+ "commands.worldborder.get",
+];
diff --git a/crates/horizon-client/src/game/commands/effects.rs b/crates/horizon-client/src/game/commands/effects.rs
index 3e04f7179..86726fed9 100644
--- a/crates/horizon-client/src/game/commands/effects.rs
+++ b/crates/horizon-client/src/game/commands/effects.rs
@@ -86,7 +86,7 @@ impl Game<'_> {
Target::Player => {
let mut instance = EffectInstance::new(effect.id, duration, amplifier);
instance.visible = particles;
- self.potions.effects.add(instance)
+ self.add_player_effect(instance)
}
Target::Mob(id) => match self.mobs.iter_mut().find(|m| m.id == id) {
Some(m) => {
@@ -134,11 +134,13 @@ impl Game<'_> {
(Target::Player, None) => {
let any = !self.potions.effects.list.is_empty();
self.potions.effects.clear();
+ self.apply_effect_status();
any
}
(Target::Player, Some(e)) => {
let before = self.potions.effects.list.len();
self.potions.effects.list.retain(|x| x.id != e.id);
+ self.apply_effect_status();
self.potions.effects.list.len() != before
}
(Target::Mob(id), e) => match self.mobs.iter_mut().find(|m| m.id == id) {
diff --git a/crates/horizon-client/src/game/commands/execute.rs b/crates/horizon-client/src/game/commands/execute.rs
index 1fa67c8b6..01488db2c 100644
--- a/crates/horizon-client/src/game/commands/execute.rs
+++ b/crates/horizon-client/src/game/commands/execute.rs
@@ -26,6 +26,9 @@ pub(in crate::game) struct Source {
/// `execute in` another dimension than the one Horizon has loaded: none
/// of its chunks are loaded.
pub elsewhere: bool,
+ /// The dimension `execute in` named, if any: a server teleports its
+ /// players there (`TeleportCommand` into the source's level).
+ pub level: Option,
/// The command block whose output this source is
/// (`BaseCommandBlock.CloseableCommandBlockSource`).
pub block: Option<(i32, i32, i32)>,
@@ -77,6 +80,7 @@ impl Game<'_> {
silent: false,
store: None,
elsewhere: false,
+ level: None,
block: None,
}
}
@@ -90,6 +94,7 @@ impl Game<'_> {
silent: true,
store: None,
elsewhere: false,
+ level: None,
block: None,
}
}
@@ -441,6 +446,7 @@ impl Game<'_> {
pos: self.target_position(t)?,
rot: self.target_rotation(t),
elsewhere: false,
+ level: None,
..s
})
})
@@ -544,6 +550,7 @@ impl Game<'_> {
}
vec![Source {
elsewhere: dim != self.dim.id(),
+ level: Some(super::super::Dim::from_id(dim)),
..s
}]
}
diff --git a/crates/horizon-client/src/game/commands/text_commands.rs b/crates/horizon-client/src/game/commands/text_commands.rs
index da8485849..dead07d71 100644
--- a/crates/horizon-client/src/game/commands/text_commands.rs
+++ b/crates/horizon-client/src/game/commands/text_commands.rs
@@ -1,6 +1,7 @@
//! `/tellraw` (TellRawCommand) and `/title` (TitleCommand).
use super::{Arg, Context, Game, R, Target, err};
-use horizon_client::text::Text;
+use horizon_client::{hud_overlays::Titles, lan::data::component_nbt, text::Text};
+use horizon_protocol::packets::play::{self, Clientbound as C};
impl Game<'_> {
/// ComponentArgument with selectors resolved for the source
@@ -153,30 +154,45 @@ impl Game<'_> {
let name = self.target_name(Target::Player);
let single = n == 1;
let key = if ctx.has("clear") {
- self.titles.clear();
+ self.titles_or_packet(Titles::clear, C::ClearTitles(play::Bool1 { value: false }));
"cleared"
} else if ctx.has("reset") {
- self.titles.clear();
- self.titles.reset_times();
+ self.titles_or_packet(
+ |t| {
+ t.clear();
+ t.reset_times();
+ },
+ C::ClearTitles(play::Bool1 { value: true }),
+ );
"reset"
} else if ctx.has("times") {
let get = |k: &str| match ctx.get(k) {
Some(Arg::Int(v)) => *v,
_ => -1,
};
- self.titles
- .set_times(get("fadeIn"), get("stay"), get("fadeOut"));
+ let (fade_in, stay, fade_out) = (get("fadeIn"), get("stay"), get("fadeOut"));
+ self.titles_or_packet(
+ |t| t.set_times(fade_in, stay, fade_out),
+ C::SetTitlesAnimation(play::TitlesAnimation {
+ fade_in,
+ stay,
+ fade_out,
+ }),
+ );
"times"
} else {
let text = self.component_arg(ctx, "title")?;
+ let sent = play::Text {
+ text: component_nbt(&text.component()),
+ };
if ctx.has("subtitle") {
- self.titles.set_subtitle(text);
+ self.titles_or_packet(|t| t.set_subtitle(text), C::SetSubtitleText(sent));
"show.subtitle"
} else if ctx.has("actionbar") {
- self.titles.set_overlay(text, false);
+ self.titles_or_packet(|t| t.set_overlay(text, false), C::SetActionBarText(sent));
"show.actionbar"
} else {
- self.titles.set_title(text);
+ self.titles_or_packet(|t| t.set_title(text), C::SetTitleText(sent));
"show.title"
}
};
@@ -191,4 +207,13 @@ impl Game<'_> {
self.feedback(message);
Ok(n as i32)
}
+ /// The player the title is for: the guest acting now is sent the packet
+ /// (TitleCommand's `connection.send`), the window's own player shows it.
+ fn titles_or_packet(&mut self, local: impl FnOnce(&mut Titles), packet: C) {
+ if self.lan_acting.is_some() {
+ self.guest_packets.push(packet);
+ } else {
+ local(&mut self.titles);
+ }
+ }
}
diff --git a/crates/horizon-client/src/game/commands/world_cmds.rs b/crates/horizon-client/src/game/commands/world_cmds.rs
index 578153247..2055798f4 100644
--- a/crates/horizon-client/src/game/commands/world_cmds.rs
+++ b/crates/horizon-client/src/game/commands/world_cmds.rs
@@ -1,7 +1,6 @@
//! `/recipe`, `/damage`, `/rotate`, `/swing`, `/playsound`, `/stopsound`,
//! `/particle`, `/attribute`, `/ride` and `/spreadplayers`.
use super::{Arg, Context, Game, R, Target, err};
-use crate::game::chat::PLAYER_NAME;
use horizon_client::{
mobs::{Damage, DamageKind, Who},
scoreboard_cmd::{Holder, Tracker},
@@ -313,7 +312,7 @@ impl Game<'_> {
(pos, volume)
};
self.audio.play_on(source, &sound, Some(at), v, pitch);
- tracker.mark(&holder(Text::literal(PLAYER_NAME)));
+ tracker.mark(&holder(Text::literal(self.acting_player_name())));
}
let name = Text::literal(sound.clone());
let (message, total) = tracker.message(
diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs
index cf7510065..6827d49c9 100644
--- a/crates/horizon-client/src/game/control.rs
+++ b/crates/horizon-client/src/game/control.rs
@@ -173,6 +173,16 @@ impl Game<'_> {
.chain(super::pad::HELP)
.collect::>() }))),
"setblock" | "fill" | "particle" | "signedit" => self.render_command(&words),
+ "section-draws" => {
+ let r = self.renderer.as_mut().ok_or("no renderer")?;
+ match words.get(1).copied() {
+ None => {}
+ Some("flat") => r.set_flat_draws(true)?,
+ Some("indirect") => r.set_flat_draws(false)?,
+ Some(other) => return Err(format!("unknown section draw mode {other}").into()),
+ }
+ Ok(Some(json!({ "ok": true, "flat": r.flat_draws() })))
+ }
"sculk" => Ok(Some(self.sculk_command(&words)?)),
"status" => Ok(Some(self.control_status())),
"pad" => Ok(Some(self.pad_command(&words)?)),
@@ -606,18 +616,6 @@ impl Game<'_> {
fn control_key_down(&mut self, key: KeyCode) -> Result<()> {
self.physical_keys.insert(key);
- // A server's chat input takes the keys first, as remote_chat_key does.
- if self.remote_chat_open() {
- use winit::keyboard::NamedKey;
- let named = match key {
- KeyCode::Escape => Some(NamedKey::Escape),
- KeyCode::Enter | KeyCode::NumpadEnter => Some(NamedKey::Enter),
- KeyCode::Backspace => Some(NamedKey::Backspace),
- _ => None,
- };
- self.remote_chat_input(named, None);
- return Ok(());
- }
if self.screen == Screen::Chat {
self.chat_key_code(key, None);
return Ok(());
@@ -684,6 +682,8 @@ impl Game<'_> {
"size": [r.config.width, r.config.height],
"present_mode": format!("{:?}", r.config.present_mode),
"drawn_sections": r.drawn_sections,
+ "section_draws": r.section_draws,
+ "section_draw_calls": r.section_draw_calls,
"uploaded_bytes": r.uploaded_bytes,
"resident_sections": r.resident_sections(),
"arena_bytes": arena_bytes,
@@ -758,6 +758,10 @@ impl Game<'_> {
.map(|e| self.shown_name_tags(glam::DVec3::from_array(e))),
});
status["physical_keys"] = json!(physical_keys);
+ // Boats, minecarts, armor stands, item frames and paintings.
+ status["objects"] = json!(self.objects_status());
+ // Primed TNT, falling blocks, projectiles, tridents and end crystals.
+ status["projectiles"] = json!(self.projectiles_status());
status
}
}
diff --git a/crates/horizon-client/src/game/creaking.rs b/crates/horizon-client/src/game/creaking.rs
index 1caa419ff..1df29a3e4 100644
--- a/crates/horizon-client/src/game/creaking.rs
+++ b/crates/horizon-client/src/game/creaking.rs
@@ -164,7 +164,7 @@ impl Game<'_> {
return;
}
let key = (home[0], home[1], home[2]);
- let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.remove(&key)
+ let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.take(&key)
else {
return;
};
@@ -173,7 +173,7 @@ impl Game<'_> {
});
self.world
.block_entities
- .insert(key, BlockEntity::CreakingHeart(heart));
+ .put(key, BlockEntity::CreakingHeart(heart));
}
/// `Creaking.tearDown`: the crumble particles.
pub(super) fn creaking_tear_down(&mut self, center: [f64; 3], spread: [f64; 3]) {
@@ -220,7 +220,7 @@ impl Game<'_> {
/// death and a natural heart drops experience.
pub(super) fn creaking_heart_broken(&mut self, pos: [i32; 3]) {
let key = (pos[0], pos[1], pos[2]);
- let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.remove(&key)
+ let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.take(&key)
else {
return;
};
@@ -248,43 +248,35 @@ impl Game<'_> {
}
self.world
.block_entities
- .insert(key, BlockEntity::CreakingHeart(heart));
+ .put(key, BlockEntity::CreakingHeart(heart));
}
- /// `CreakingHeartBlockEntity.serverTick` for every heart.
- pub(super) fn tick_creaking_hearts(&mut self) -> Result<()> {
- let keys: Vec = self
- .world
- .block_entities
- .iter()
- .filter(|(_, e)| matches!(e, BlockEntity::CreakingHeart(_)))
- .map(|(k, _)| *k)
- .collect();
- for key in keys {
- let Some(BlockEntity::CreakingHeart(mut heart)) =
- self.world.block_entities.remove(&key)
- else {
- continue;
- };
- let state = self.world.block(key.0, key.1, key.2);
- if &*self.res.facts.get(state).name != "minecraft:creaking_heart" {
- // The block is gone: preRemoveSideEffects.
- self.with_heart(key, &mut heart, |h, _, _, host, out| {
- creaking_heart::remove_protector(h, host, false, out);
- })?;
- continue;
- }
- // getTicker: none once uprooted.
- if self.heart_state_name(state) != "uprooted" {
- let pos = [key.0, key.1, key.2];
- self.with_heart(key, &mut heart, |h, w, lr, host, out| {
- creaking_heart::server_tick(h, pos, w, lr, host, out);
- })?;
- }
- self.world
- .block_entities
- .insert(key, BlockEntity::CreakingHeart(heart));
+ /// `CreakingHeartBlockEntity.serverTick` of the heart at `key`. Its slot
+ /// stays while uprooted, so that a heart whose block went away is still
+ /// found here and lets go of its protector.
+ pub(super) fn tick_creaking_heart(&mut self, key: Pos) -> Result<()> {
+ let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.take(&key)
+ else {
+ return Ok(());
+ };
+ let state = self.world.block(key.0, key.1, key.2);
+ if &*self.res.facts.get(state).name != "minecraft:creaking_heart" {
+ // The block is gone: preRemoveSideEffects.
+ self.world.block_entities.forget(&key);
+ self.with_heart(key, &mut heart, |h, _, _, host, out| {
+ creaking_heart::remove_protector(h, host, false, out);
+ })?;
+ return Ok(());
}
- self.scan_for_hearts();
+ // getTicker: none once uprooted.
+ if self.heart_state_name(state) != "uprooted" {
+ let pos = [key.0, key.1, key.2];
+ self.with_heart(key, &mut heart, |h, w, lr, host, out| {
+ creaking_heart::server_tick(h, pos, w, lr, host, out);
+ })?;
+ }
+ self.world
+ .block_entities
+ .put(key, BlockEntity::CreakingHeart(heart));
Ok(())
}
/// `ServerLevel.isSpawningMonsters`.
@@ -295,7 +287,7 @@ impl Game<'_> {
}
/// Hearts that came with generated or loaded chunks get their block
/// entity (`newBlockEntity`) the first time their chunk is seen.
- fn scan_for_hearts(&mut self) {
+ pub(super) fn scan_for_hearts(&mut self) {
let Some(heart) = self
.pack
.assets
@@ -327,13 +319,16 @@ impl Game<'_> {
}
let hearts = &self.creaking.hearts;
let _ = heart;
+ let is_heart = |id: u32| hearts.get(id as usize).copied().unwrap_or(false);
for (si, section) in chunk.sections.iter().enumerate() {
- if section.is_uniform(0) {
+ // Only a section whose palette holds a heart state can have
+ // one: the others are skipped without reading their 4,096 blocks.
+ if !section.blocks.maybe_has(is_heart) {
continue;
}
for i in 0..4096 {
let id = section.get(i);
- if !hearts.get(usize::from(id)).copied().unwrap_or(false) {
+ if !is_heart(id) {
continue;
}
let (lx, lz, ly) = ((i & 15) as i32, ((i >> 4) & 15) as i32, (i >> 8) as i32);
@@ -344,8 +339,7 @@ impl Game<'_> {
);
self.world
.block_entities
- .entry(pos)
- .or_insert_with(|| BlockEntity::CreakingHeart(Box::default()));
+ .get_or_insert_with(pos, || BlockEntity::CreakingHeart(Box::default()));
}
}
}
@@ -362,3 +356,11 @@ pub(super) struct CreakingState {
/// Which block states are creaking hearts, by state id.
hearts: Vec,
}
+
+impl CreakingState {
+ /// Exchange the chunks scanned for creaking hearts with another level's
+ /// (game/levels.rs).
+ pub(super) fn swap_level(&mut self, other: &mut Self) {
+ std::mem::swap(&mut self.scanned, &mut other.scanned);
+ }
+}
diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs
index 076c2fbef..3ef399e62 100644
--- a/crates/horizon-client/src/game/creatures.rs
+++ b/crates/horizon-client/src/game/creatures.rs
@@ -196,6 +196,7 @@ impl Game<'_> {
hero: self.potions.effects.get("hero_of_the_village").is_some(),
uuid: self.level.player_uuid.unwrap_or_default(),
allies: std::sync::Arc::new(self.player_allies()),
+ remote: false,
})
}
/// Biome facts at a position for finalizeSpawn and variant rules.
@@ -1358,25 +1359,52 @@ impl Game<'_> {
/// mining fatigue III for five minutes unless a stronger or longer one
/// is on, with the curse sound and the elder's apparition.
fn elder_curse(&mut self, at: [f64; 3]) {
+ let mut cursed = Vec::new();
+ self.for_each_player(|g| {
+ if g.elder_curse_player(at) {
+ cursed.push(g.lan_acting);
+ }
+ });
+ // A guest's client shows the apparition and plays the curse itself
+ // (ClientboundGameEventPacket.GUARDIAN_ELDER_EFFECT).
+ if let Some(host) = self.lan.as_ref() {
+ for conn in cursed.into_iter().flatten() {
+ host.hub.send_to(
+ conn,
+ &horizon_protocol::packets::play::Clientbound::GameEvent(
+ horizon_protocol::packets::play::GameEvent {
+ event: horizon_client::lan::hub::game_event::GUARDIAN_ELDER_EFFECT,
+ param: 1.0,
+ },
+ ),
+ );
+ }
+ }
+ }
+ /// The curse on the player in place; whether it took.
+ fn elder_curse_player(&mut self, at: [f64; 3]) -> bool {
if self.creative || self.spectator() {
- return;
+ return false;
}
let Some(p) = self.player.as_ref() else {
- return;
+ return false;
};
let d = p.position.subtract(Vec3::new(at[0], at[1], at[2]));
if d.x * d.x + d.y * d.y + d.z * d.z >= 2500.0 || p.health.dead_or_dying() {
- return;
+ return false;
}
let active = self.potions.effects.get("minecraft:mining_fatigue");
if active.is_some_and(|e| e.amplifier >= 2 && e.duration >= 1200) {
- return;
+ return false;
}
let at = [p.position.x, p.position.y, p.position.z];
self.give_player_effect("minecraft:mining_fatigue", 6000, 2);
- self.audio
- .play("minecraft:entity.elder_guardian.curse", Some(at), 1.0, 1.0);
- self.creatures.elder_apparition = super::mob_blocks::APPARITION_TICKS;
+ if self.lan_acting.is_none() {
+ self.audio
+ .play("minecraft:entity.elder_guardian.curse", Some(at), 1.0, 1.0);
+ self.creatures.elder_apparition = super::mob_blocks::APPARITION_TICKS;
+ }
+ true
}
/// Damage of a given type to the player from a point.
pub(super) fn mob_hits_player_kind(&mut self, amount: f32, from: [f64; 3], kind: &str) {
@@ -2253,6 +2281,10 @@ impl Game<'_> {
return Ok(true);
}
if self.interact_sulfur_cube(index, &item) {
+ if let Some(stack) = &held {
+ let target = self.mob_entity(&self.mobs[index]);
+ self.trigger_item_entity("minecraft:player_interacted_with_entity", stack, &target);
+ }
self.swing_arm();
return Ok(true);
}
@@ -2802,6 +2834,17 @@ impl Game<'_> {
if mob.fire_ticks > 0 || matches!(mob.species(), Species::Blaze | Species::MagmaCube) {
packed = (15 * 16) | ((15 * 16) << 8);
}
+ if mob.species() == Species::SulfurCube
+ && !horizon_client::mobs::trader::is_invisible(mob)
+ {
+ self.sulfur_cube_body_geometry(
+ mob,
+ alpha as f32,
+ horizon_client::mobs::render::base_transform(mob, alpha as f32, camera),
+ packed,
+ out,
+ );
+ }
// Other players on a server: PlayerRenderer's HumanoidArmorLayer.
let armor = if &*mob.kind.id == "minecraft:player" {
self.worn_armor_layers(mob)
diff --git a/crates/horizon-client/src/game/debug_keys.rs b/crates/horizon-client/src/game/debug_keys.rs
index 36761a85e..1de6669e7 100644
--- a/crates/horizon-client/src/game/debug_keys.rs
+++ b/crates/horizon-client/src/game/debug_keys.rs
@@ -88,8 +88,7 @@ impl Game<'_> {
|| self.book.is_some()
|| (self.screen == Screen::Creative && self.creative_screen.tab().search)
|| self.recipe_search_focused()
- || self.station_typing()
- || self.remote_chat_open();
+ || self.station_typing();
// Container screens use Escape, the inventory key and the hotbar and
// drop keys first; any other screen closes on Escape.
let screen_key = match self.screen {
diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs
index 9c4b41db0..8a8ed63f9 100644
--- a/crates/horizon-client/src/game/dedicated.rs
+++ b/crates/horizon-client/src/game/dedicated.rs
@@ -13,7 +13,9 @@ use horizon_client::{
server::{
eula,
java_properties::now_millis,
+ profiles,
properties::{GAME_MODES, ServerProperties, SystemEntropy},
+ user_cache::UserCache,
user_lists::{
BanEntry, BanList, IpBanList, NameAndId, OpEntry, OpList, WhiteEntry, WhiteList,
format_date,
@@ -57,6 +59,18 @@ struct Setup {
started: Instant,
}
static SETUP: OnceLock>> = OnceLock::new();
+/// usercache.json (Services.nameToIdCache): used by the server thread only.
+static USER_CACHE: Mutex> = Mutex::new(None);
+
+/// PlayerList.placeNewPlayer: a player who joined is cached (and the file saved).
+pub(super) fn player_joined(id: u128, name: &str) {
+ if let Some(cache) = USER_CACHE.lock().unwrap().as_mut() {
+ cache.add(NameAndId {
+ id,
+ name: name.to_owned(),
+ });
+ }
+}
/// Log4j's console pattern: `[HH:mm:ss] [thread/LEVEL]: message`.
pub(super) fn log(level: &str, message: &str) {
@@ -276,6 +290,78 @@ impl Lists {
}
}
+/// The world presets of 26.3's `worldgen/world_preset`.
+const WORLD_PRESETS: [&str; 6] = [
+ "minecraft:normal",
+ "minecraft:flat",
+ "minecraft:large_biomes",
+ "minecraft:amplified",
+ "minecraft:single_biome_surface",
+ "minecraft:debug_all_block_states",
+];
+
+/// Identifier.tryParse: `namespace:path`, or a path in `minecraft`.
+fn parse_identifier(text: &str) -> Option {
+ let (namespace, path) = text.split_once(':').unwrap_or(("minecraft", text));
+ let valid = |s: &str, extra: &[char]| {
+ s.chars()
+ .all(|c| matches!(c, 'a'..='z' | '0'..='9' | '_' | '.' | '-') || extra.contains(&c))
+ };
+ (valid(namespace, &[]) && valid(path, &['/'])).then(|| format!("{namespace}:{path}"))
+}
+
+impl Game<'_> {
+ /// DedicatedServerProperties.createDimensions for a world that doesn't
+ /// exist yet: `level-type`'s preset, a flat world's `generator-settings`
+ /// and `generate-structures`, written before the world opens so that
+ /// streaming reads them. Horizon generates the normal and flat presets.
+ fn write_world_gen(&self, dir: &std::path::Path, props: &ServerProperties) -> Result<()> {
+ let level_type = &props.level_type;
+ let preset = parse_identifier(level_type)
+ .filter(|id| WORLD_PRESETS.contains(&id.as_str()))
+ .unwrap_or_else(|| {
+ log_from(
+ "Worker-Main-1",
+ "WARN",
+ &format!(
+ "Failed to parse level-type {level_type}, defaulting to minecraft:normal"
+ ),
+ );
+ "minecraft:normal".to_owned()
+ });
+ let flat = preset == "minecraft:flat";
+ if !flat && preset != "minecraft:normal" {
+ log_from(
+ "Worker-Main-1",
+ "WARN",
+ &format!(
+ "Horizon doesn't generate the {preset} world preset yet: using minecraft:normal"
+ ),
+ );
+ }
+ let settings = if flat {
+ let biomes = &self.res.biomes;
+ let (settings, errors) = horizon_client::flatgen::settings_from_json(
+ &props.generator_settings,
+ |b| self.pack.assets.registry.default_state(b).is_some(),
+ |b| biomes.get(biomes.id(b)).name == b,
+ );
+ for e in errors {
+ log_from("Worker-Main-1", "ERROR", &e);
+ }
+ settings
+ } else {
+ None
+ };
+ let options = horizon_client::save::WorldGen {
+ flat,
+ structures: props.generate_structures,
+ bonus_chest: false,
+ };
+ horizon_client::save::write_world_gen_settings_with(dir, props.seed, options, settings)
+ }
+}
+
/// PlayerList.BAN_DATE_FORMAT ("yyyy-MM-dd 'at' HH:mm:ss z"), in UTC.
fn ban_date(millis: i64) -> String {
let s = format_date(millis);
@@ -316,8 +402,32 @@ struct ServerState {
/// When the last passes of the loop ended, for the tick rate horizon-server shows.
ticks: std::collections::VecDeque,
paused: bool,
+ /// `broadcast-console-to-ops`.
+ broadcast_console: bool,
}
+/// The dedicated-only commands' replies vanilla sends with `broadcast`
+/// (`sendSuccess(..., true)`): the operators hear of them.
+const BROADCAST: &[&str] = &[
+ "commands.ban.success",
+ "commands.banip.info",
+ "commands.banip.success",
+ "commands.deop.success",
+ "commands.kick.success",
+ "commands.op.success",
+ "commands.pardon.success",
+ "commands.pardonip.success",
+ "commands.save.disabled",
+ "commands.save.enabled",
+ "commands.save.success",
+ "commands.stop.stopping",
+ "commands.whitelist.add.success",
+ "commands.whitelist.disabled",
+ "commands.whitelist.enabled",
+ "commands.whitelist.reloaded",
+ "commands.whitelist.remove.success",
+];
+
impl Game<'_> {
/// DedicatedServer.initServer and MinecraftServer.runServer.
pub(super) fn run_dedicated(&mut self) -> Result<()> {
@@ -331,6 +441,13 @@ impl Game<'_> {
.get()
.and_then(|m| m.lock().unwrap().take())
.ok_or("dedicated server not prepared")?;
+ // Main's WorldLoader: a new world's dimensions come from
+ // server.properties before the server starts.
+ let world_dir = std::env::current_dir()?.join(&universe).join(&level_name);
+ let new_world = !world_dir.join("level.dat").exists();
+ if new_world {
+ self.write_world_gen(&world_dir, &props)?;
+ }
// The console thread starts first, as in initServer.
let (tx, console) = mpsc::channel();
std::thread::Builder::new()
@@ -348,6 +465,26 @@ impl Game<'_> {
line.clear();
}
})?;
+ // Main: Services.create loads the universe's usercache.json.
+ let (mut cache, warnings) = UserCache::load(universe.join("usercache.json"));
+ for warning in warnings {
+ log_from("main", "WARN", &warning);
+ }
+ // DedicatedServer.initServer: names nobody has resolve offline only without authentication.
+ cache.resolve_offline_users = !props.online_mode;
+ *USER_CACHE.lock().unwrap() = Some(cache);
+ // Services.create: the services' public keys, fetched in the
+ // background (they check players' chat keys).
+ let secure_chat = Arc::new(horizon_client::lan::SecureChat::new(
+ props.enforce_secure_profile && props.online_mode,
+ || {
+ let discovery = profiles::discovery_url();
+ profiles::fetch_profile_key_keys(&discovery).unwrap_or_else(|e| {
+ ::log::error!("{e}");
+ Vec::new()
+ })
+ },
+ ));
log("INFO", "Starting minecraft server version 26.3");
log("INFO", "Loading properties");
let game_mode = props.game_mode;
@@ -403,9 +540,7 @@ impl Game<'_> {
lists.enforce_whitelist = props.enforce_whitelist;
let lists = Arc::new(Mutex::new(lists));
log("INFO", &format!("Preparing level \"{level_name}\""));
- let world_dir = std::env::current_dir()?.join(&universe).join(&level_name);
let folder = world_dir.to_string_lossy().into_owned();
- let new_world = !world_dir.join("level.dat").exists();
self.open_world(
&folder,
Some(&level_name),
@@ -448,8 +583,7 @@ impl Game<'_> {
enable_status: props.enable_status,
hide_online_players: props.hide_online_players,
favicon,
- // DedicatedServer.enforceSecureProfile needs online mode.
- enforces_secure_chat: false,
+ secure_chat: Some(secure_chat),
accepts_transfers: props.accepts_transfers,
announce: false,
listen: true,
@@ -513,6 +647,7 @@ impl Game<'_> {
empty_ticks: 0,
ticks: Default::default(),
paused: false,
+ broadcast_console: props.broadcast_console_to_ops,
};
let pause_after = props.pause_when_empty_seconds * 20;
let idle_timeout = props.player_idle_timeout;
@@ -520,7 +655,7 @@ impl Game<'_> {
while !state.stop {
let tick_start = Instant::now();
while let Ok(line) = state.console.try_recv() {
- self.console_command(&mut state, &line);
+ self.console_line(&mut state, &line);
}
self.poll_server_control(&mut state);
let players = self.lan.as_ref().map_or(0, |h| h.hub.guests.len());
@@ -543,18 +678,12 @@ impl Game<'_> {
);
self.save_game()?;
}
- self.update_dedicated_streaming();
- self.update_world();
- if paused {
- // MinecraftServer.tickServer: only the connections run.
- self.tick_lan();
- } else {
- if !state.autosave {
- // `save-off`: the periodic save inside the tick is skipped.
- self.ticks = self.ticks.max(1);
- }
- self.tick()?;
+ if !paused && !state.autosave {
+ // `save-off`: the periodic save inside the tick is skipped.
+ self.ticks = self.ticks.max(1);
}
+ // MinecraftServer.tickServer: while paused only the connections run.
+ self.tick_server(paused)?;
if idle_timeout > 0 {
self.kick_idle(idle_timeout);
}
@@ -595,7 +724,13 @@ impl Game<'_> {
let center = self
.lan
.as_ref()
- .and_then(|h| h.hub.guests.iter().find(|g| g.placed).map(|g| g.chunk()))
+ .and_then(|h| {
+ h.hub
+ .guests
+ .iter()
+ .find(|g| h.hub.here(g))
+ .map(|g| g.chunk())
+ })
.or_else(|| {
self.spawn
.map(|s| ((s.x.floor() as i32) >> 4, (s.z.floor() as i32) >> 4))
@@ -641,28 +776,63 @@ impl Game<'_> {
host.hub.resend_commands();
}
- /// A known player by name: online first, else the offline profile.
- fn resolve(&self, name: &str) -> NameAndId {
- self.lan
- .as_ref()
- .and_then(|h| {
- h.hub
- .guests
- .iter()
- .find(|g| g.name.eq_ignore_ascii_case(name))
- })
- .map_or_else(
- || NameAndId::offline(name),
- |g| NameAndId {
- id: g.uuid,
- name: g.name.clone(),
- },
- )
+ /// A player on the server, by name.
+ fn online_player(&self, name: &str) -> Option {
+ let hub = &self.lan.as_ref()?.hub;
+ let g = hub
+ .guests
+ .iter()
+ .find(|g| g.name.eq_ignore_ascii_case(name))?;
+ Some(NameAndId {
+ id: g.uuid,
+ name: g.name.clone(),
+ })
}
- /// MinecraftServer.sendSystemMessage: what the console is told.
- fn console_reply(&self, text: Text) {
+ /// GameProfileArgument for a name: the user cache, else the profile
+ /// service, else (offline) the offline player. None, told to the console:
+ /// no such player.
+ fn resolve(&self, name: &str) -> Option {
+ let found = USER_CACHE.lock().unwrap().as_mut().and_then(|cache| {
+ cache.get_by_name(name, |lower| {
+ let found = profiles::find_by_name(&profiles::discovery_url(), lower);
+ if found.is_none() {
+ log("WARN", &format!("Couldn't find profile with name: {lower}"));
+ }
+ found
+ })
+ });
+ if found.is_none() {
+ let unknown = Text::translate("argument.player.unknown", &[]);
+ log("INFO", &format!("System chat: {}", unknown.plain()));
+ }
+ found
+ }
+
+ /// MinecraftServer.sendSystemMessage: what the console is told; while
+ /// the console runs a command, the replies vanilla broadcasts go to the
+ /// operators too.
+ fn console_reply(&mut self, text: Text) {
log("INFO", &format!("System chat: {}", text.plain()));
+ if self.console_broadcast.is_some()
+ && text
+ .translation_key()
+ .is_some_and(|k| BROADCAST.contains(&k))
+ {
+ self.broadcast_to_admins(text);
+ }
+ }
+
+ /// One console line, then the operators' share of its feedback.
+ fn console_line(&mut self, state: &mut ServerState, line: &str) {
+ self.console_broadcast = Some(state.broadcast_console);
+ self.console_command(state, line);
+ self.console_broadcast = None;
+ if let Some(mut host) = self.lan.take() {
+ self.send_admin_feedback(&mut host, None);
+ self.lan = Some(host);
+ }
+ self.admin_feedback.clear();
}
/// DedicatedServer.handleConsoleInputs: one console line, run as the
@@ -740,7 +910,9 @@ impl Game<'_> {
));
}
"op" | "deop" if !rest.is_empty() => {
- let user = self.resolve(rest[0]);
+ let Some(user) = self.resolve(rest[0]) else {
+ return;
+ };
let level = 4;
let changed = {
let mut l = state.lists.lock().unwrap();
@@ -770,7 +942,9 @@ impl Game<'_> {
}
"whitelist" => self.console_whitelist(state, &rest),
"ban" if !rest.is_empty() => {
- let user = self.resolve(rest[0]);
+ let Some(user) = self.resolve(rest[0]) else {
+ return;
+ };
let reason = (rest.len() > 1).then(|| rest[1..].join(" "));
let added = state.lists.lock().unwrap().bans.add(BanEntry::new(
user.clone(),
@@ -860,7 +1034,9 @@ impl Game<'_> {
}
}
"pardon" if !rest.is_empty() => {
- let user = self.resolve(rest[0]);
+ let Some(user) = self.resolve(rest[0]) else {
+ return;
+ };
let removed = state.lists.lock().unwrap().bans.remove(&user);
let key = if removed {
"commands.pardon.success"
@@ -926,15 +1102,10 @@ impl Game<'_> {
}
}
"kick" if !rest.is_empty() => {
- let user = self.resolve(rest[0]);
- let online = self
- .lan
- .as_ref()
- .is_some_and(|h| h.hub.guests.iter().any(|g| g.uuid == user.id));
- if !online {
+ let Some(user) = self.online_player(rest[0]) else {
self.console_reply(Text::translate("argument.entity.notfound.player", &[]));
return;
- }
+ };
let reason = if rest.len() > 1 {
Tag::String(JavaString::from(rest[1..].join(" ").as_str()))
} else {
@@ -1014,7 +1185,9 @@ impl Game<'_> {
self.console_reply(Text::translate("commands.whitelist.reloaded", &[]));
}
["add", name] | ["remove", name] => {
- let user = self.resolve(name);
+ let Some(user) = self.resolve(name) else {
+ return;
+ };
let mut l = state.lists.lock().unwrap();
let (ok, key) = if rest[0] == "add" {
if l.white.contains(&user) {
diff --git a/crates/horizon-client/src/game/dispense_fixture.rs b/crates/horizon-client/src/game/dispense_fixture.rs
index ee8170bc5..fbad3cfc7 100644
--- a/crates/horizon-client/src/game/dispense_fixture.rs
+++ b/crates/horizon-client/src/game/dispense_fixture.rs
@@ -318,8 +318,18 @@ impl Game<'_> {
} else {
self.dispense_from(origin, state)?;
// CrafterBlockEntity.serverTick, the crafting animation running down.
+ let mut crafters: Vec<(i32, i32, i32)> = self
+ .world
+ .block_entities
+ .iter()
+ .filter(|(_, e)| matches!(e, BlockEntity::Crafter(_)))
+ .map(|(p, _)| *p)
+ .collect();
+ crafters.sort_unstable();
for _ in 0..case["ticks"].as_u64().unwrap_or(0) {
- self.tick_crafters();
+ for &p in &crafters {
+ self.tick_crafter(p);
+ }
}
}
diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs
index ff91df583..e76eb16fb 100644
--- a/crates/horizon-client/src/game/dragon.rs
+++ b/crates/horizon-client/src/game/dragon.rs
@@ -74,6 +74,8 @@ impl Respawn {
}
#[derive(Clone, Debug)]
pub(super) struct Crystal {
+ /// The entity id a server tracks it by (0 until it is tracked).
+ pub id: u32,
pub position: Vec3,
pub show_bottom: bool,
/// EndCrystal.time (the bob and spin), starting random.
@@ -553,6 +555,7 @@ impl Game<'_> {
}
let time = self.world.random.next_int_bound(100_000).unwrap_or(0);
self.crystals.push(Crystal {
+ id: 0,
position: at,
show_bottom: true,
time,
@@ -2301,6 +2304,7 @@ impl Crystal {
pub(super) fn from_nbt(tag: &Tag, time: i32) -> Option {
let (position, _, _) = horizon_client::entity_nbt::boat_from_nbt(tag)?;
Some(Self {
+ id: 0,
position,
show_bottom: !matches!(tag.get("ShowBottom"), Some(Tag::Byte(0))),
time,
@@ -2403,6 +2407,7 @@ impl Game<'_> {
}
let time = self.world.random.next_int_bound(100_000).unwrap_or(0);
self.crystals.push(Crystal {
+ id: 0,
position: Vec3::new(x + 0.5, y, z + 0.5),
show_bottom: false,
time,
@@ -2665,6 +2670,7 @@ impl Game<'_> {
.retain(|c| c.position.distance_squared(at) > 0.01);
let time = self.world.random.next_int_bound(100_000).unwrap_or(0);
self.crystals.push(Crystal {
+ id: 0,
position: at,
show_bottom: true,
time,
diff --git a/crates/horizon-client/src/game/entity_culling.rs b/crates/horizon-client/src/game/entity_culling.rs
index 71ab13378..b710f4e73 100644
--- a/crates/horizon-client/src/game/entity_culling.rs
+++ b/crates/horizon-client/src/game/entity_culling.rs
@@ -49,3 +49,64 @@ impl Game<'_> {
}
}
}
+
+/// Entity.shouldRenderAtSqrDistance's default range: 64 times the bounding
+/// box's mean edge, scaled by the entity distance option.
+pub(super) fn default_range(size: glam::DVec3, view_scale: f32) -> f64 {
+ let edge = (size.x + size.y + size.z) / 3.0;
+ let edge = if edge.is_nan() { 1.0 } else { edge };
+ edge * 64.0 * f64::from(view_scale)
+}
+
+impl Game<'_> {
+ /// EntityRenderer.shouldRender: the entity within `range` blocks of the
+ /// camera, measured from its current `position`, and its culling box
+ /// (`lo`..`hi`, interpolated, in world space) grown by 0.5 in the view.
+ pub(super) fn entity_in_view(
+ &self,
+ camera: glam::DVec3,
+ position: glam::DVec3,
+ range: f64,
+ lo: glam::DVec3,
+ hi: glam::DVec3,
+ ) -> bool {
+ if (position - camera).length_squared() >= range * range {
+ return false;
+ }
+ self.view_frustum.as_ref().is_none_or(|view| {
+ view.intersects(
+ (lo - camera - glam::DVec3::splat(0.5)).as_vec3(),
+ (hi - camera + glam::DVec3::splat(0.5)).as_vec3(),
+ )
+ })
+ }
+}
+
+/// An entity's position as a `DVec3`.
+pub(super) fn at(p: horizon_core::geometry::Vec3) -> glam::DVec3 {
+ glam::DVec3::new(p.x, p.y, p.z)
+}
+
+impl Game<'_> {
+ /// `entity_in_view` for an entity whose box stands on its position,
+ /// `width` wide and `height` tall, interpolated by `alpha` and grown by
+ /// `grow` (a renderer's getBoundingBoxForCulling).
+ #[allow(clippy::too_many_arguments)]
+ pub(super) fn standing_entity_in_view(
+ &self,
+ camera: glam::DVec3,
+ previous: glam::DVec3,
+ position: glam::DVec3,
+ alpha: f64,
+ width: f64,
+ height: f64,
+ range: f64,
+ grow: f64,
+ ) -> bool {
+ let p = previous.lerp(position, alpha);
+ let half = glam::DVec3::new(width / 2.0 + grow, grow, width / 2.0 + grow);
+ let lo = p - half;
+ let hi = p + glam::DVec3::new(half.x, height + grow, half.z);
+ self.entity_in_view(camera, position, range, lo, hi)
+ }
+}
diff --git a/crates/horizon-client/src/game/falling_damage.rs b/crates/horizon-client/src/game/falling_damage.rs
index 16a003c04..f10a3b738 100644
--- a/crates/horizon-client/src/game/falling_damage.rs
+++ b/crates/horizon-client/src/game/falling_damage.rs
@@ -23,7 +23,7 @@ impl Game<'_> {
.guests
.iter()
.filter(|g| {
- g.placed
+ host.hub.here(g)
&& g.loaded
&& !g.dead
&& !g.creative()
diff --git a/crates/horizon-client/src/game/fireworks.rs b/crates/horizon-client/src/game/fireworks.rs
index 0e074025f..85fccc2de 100644
--- a/crates/horizon-client/src/game/fireworks.rs
+++ b/crates/horizon-client/src/game/fireworks.rs
@@ -18,21 +18,46 @@ use horizon_core::{
};
pub(super) struct Rocket {
- position: Vec3,
+ /// The entity id a server tracks it by (0 until it is tracked).
+ pub id: u32,
+ pub(super) position: Vec3,
previous: Vec3,
- velocity: Vec3,
+ pub(super) velocity: Vec3,
life: i32,
lifetime: i32,
explosions: Vec,
/// Boosting the player (attachedToEntity).
- attached: bool,
+ pub(super) attached: bool,
/// `DATA_SHOT_AT_ANGLE` (dispensers): constant velocity, exploding on
/// the first block it hits.
- angled: bool,
+ pub(super) angled: bool,
/// `DATA_ID_FIREWORKS_ITEM`: the stack it was launched from.
- item: ItemStack,
+ pub(super) item: ItemStack,
}
impl Rocket {
+ /// A rocket a server sent (`handleAddEntity`): placed and moved by it.
+ pub(super) fn remote(id: u32, position: Vec3, velocity: Vec3) -> Self {
+ let item = ItemStack::new("minecraft:firework_rocket", 1);
+ let (_, explosions) = fireworks_of(&item);
+ Self {
+ id,
+ position,
+ previous: position,
+ velocity,
+ life: 0,
+ lifetime: i32::MAX,
+ explosions,
+ attached: false,
+ angled: false,
+ item,
+ }
+ }
+ /// One tick of a server's client: the previous position, then `step`.
+ pub(super) fn remote_step(&mut self, step: impl FnOnce(Vec3) -> Vec3) {
+ self.previous = self.position;
+ self.life += 1;
+ self.position = step(self.position);
+ }
/// Position and motion (the dispenser parity fixture).
pub(super) fn motion(&self) -> (Vec3, Vec3) {
(self.position, self.velocity)
@@ -56,6 +81,7 @@ impl Game<'_> {
+ r.next_int_bound(6).unwrap_or(0)
+ r.next_int_bound(7).unwrap_or(0);
Rocket {
+ id: 0,
position: at,
previous: at,
velocity,
@@ -253,6 +279,20 @@ impl Game<'_> {
pub(super) fn rocket_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec) {
let orientation = glam::Mat4::from_quat(self.camera_orientation());
for r in self.rockets.iter().filter(|r| !r.attached) {
+ // FireworkRocketEntity.shouldRenderAtSqrDistance: within 64 blocks;
+ // EntityRenderer.shouldRender: its 0.25 box in the view.
+ if !self.standing_entity_in_view(
+ camera,
+ super::entity_culling::at(r.previous),
+ super::entity_culling::at(r.position),
+ alpha,
+ 0.25,
+ 0.25,
+ 64.0,
+ 0.0,
+ ) {
+ continue;
+ }
let p = glam::DVec3::new(
r.previous.x + (r.position.x - r.previous.x) * alpha,
r.previous.y + (r.position.y - r.previous.y) * alpha,
diff --git a/crates/horizon-client/src/game/fov.rs b/crates/horizon-client/src/game/fov.rs
index 7825d6514..64047b4f7 100644
--- a/crates/horizon-client/src/game/fov.rs
+++ b/crates/horizon-client/src/game/fov.rs
@@ -55,7 +55,13 @@ impl Game<'_> {
.fov_player()
.map_or(1.0, |p| field_of_view_modifier(&p, first_person, effect));
let target = self.zoomed_fov_target(target);
- let eye = self.player.as_ref().map(|p| p.dimensions.eye_height);
+ let eye = self.player.as_ref().map(|p| {
+ if self.sleeping.is_some() {
+ 0.2
+ } else {
+ p.dimensions.eye_height
+ }
+ });
self.view.tick(eye, target);
}
/// The player's `deathTime` while dead or dying.
@@ -106,7 +112,7 @@ impl Game<'_> {
let hurt = &p.health.hurt;
let state = BobState {
living: Some(HurtBob {
- hurt_time: hurt.hurt_time as f32 - partial,
+ hurt_time: p.health.hurt_animation_time as f32 - partial,
hurt_duration: hurt.hurt_duration,
hurt_dir: 0.0,
death_time: self.death_time().map(|t| t as f32 + partial),
diff --git a/crates/horizon-client/src/game/frames.rs b/crates/horizon-client/src/game/frames.rs
index 3ffa0e67e..2977ad483 100644
--- a/crates/horizon-client/src/game/frames.rs
+++ b/crates/horizon-client/src/game/frames.rs
@@ -304,9 +304,27 @@ impl Game<'_> {
let sprites = &self.atlas.sprites;
let mut maps: Vec<(i32, glam::Mat4, u32)> = Vec::new();
let mut items: Vec<(ItemStack, u32, glam::Mat4, u8)> = Vec::new();
+ // ItemFrame.shouldRenderAtSqrDistance: 1024 blocks at 100%.
+ let range = 16.0 * 64.0 * f64::from(self.settings.entity_distance);
for f in &self.item_frames {
let entity_start = out.len();
let map = f.item.as_ref().and_then(super::maps::map_id);
+ // EntityRenderer.shouldRender: its box (a block wide with a map),
+ // measured from the box's centre.
+ let (lo, hi) = f.bounds();
+ let (mut lo, mut hi) = (glam::DVec3::from(lo), glam::DVec3::from(hi));
+ if map.is_some() {
+ let s = f.step();
+ for i in 0..3 {
+ if s[i] == 0 {
+ let c = (lo[i] + hi[i]) / 2.0;
+ (lo[i], hi[i]) = (c - 0.5, c + 0.5);
+ }
+ }
+ }
+ if !self.entity_in_view(camera, (lo + hi) / 2.0, range, lo, hi) {
+ continue;
+ }
let s = f.step();
// Pose: to the block centre, then X/Y rotation by facing.
let (x_rot, y_rot) = if s[1] == 0 {
diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs
index a932913af..19e66174b 100644
--- a/crates/horizon-client/src/game/hand.rs
+++ b/crates/horizon-client/src/game/hand.rs
@@ -67,7 +67,7 @@ impl Game<'_> {
/// attack clicks since the last tick and the held attack button.
pub(super) fn tick_local_hand(&mut self) -> Result<()> {
let attack_clicks = std::mem::take(&mut self.attack_clicks);
- if self.screen == Screen::Playing && self.title.is_none() {
+ if self.screen == Screen::Playing && self.title.is_none() && self.sleeping.is_none() {
let mut clicks = std::mem::take(&mut self.clicks);
// keyAttack.isDown(); playing implies the grabbed mouse here
// (scripts under --control hold buttons without grabbing it).
diff --git a/crates/horizon-client/src/game/integrated.rs b/crates/horizon-client/src/game/integrated.rs
index 7b5f3cced..b2c0a2e7f 100644
--- a/crates/horizon-client/src/game/integrated.rs
+++ b/crates/horizon-client/src/game/integrated.rs
@@ -28,7 +28,7 @@ use std::{
path::Path,
sync::{
Arc,
- atomic::{AtomicBool, AtomicU16, AtomicU32, Ordering},
+ atomic::{AtomicBool, AtomicI32, AtomicU16, AtomicU32, Ordering},
mpsc::{Receiver, Sender, channel, sync_channel},
},
thread::JoinHandle,
@@ -45,6 +45,10 @@ struct Flags {
/// while it is not.
published: AtomicU16,
smoothed_tick_ms: AtomicU32,
+ /// `options.renderDistance` and `options.simulationDistance`, which the
+ /// server follows while it runs (IntegratedServer.tickServer).
+ render_distance: AtomicI32,
+ simulation_distance: AtomicI32,
}
/// Work the window hands its server thread (`MinecraftServer.execute`).
@@ -66,6 +70,13 @@ impl Integrated {
pub fn set_paused(&self, paused: bool) {
self.flags.paused.store(paused, Ordering::Relaxed);
}
+ /// The window's render and simulation distances, for the server to follow.
+ pub fn set_distances(&self, render: i32, simulation: i32) {
+ self.flags.render_distance.store(render, Ordering::Relaxed);
+ self.flags
+ .simulation_distance
+ .store(simulation, Ordering::Relaxed);
+ }
/// `IntegratedServer.getPort` while `isPublished`.
pub fn published(&self) -> Option {
Some(self.flags.published.load(Ordering::Relaxed)).filter(|&p| p != 0)
@@ -192,6 +203,12 @@ impl Game<'_> {
options.dev_mods.clear();
let (res, pack, settings) = (self.res.clone(), self.pack.clone(), self.settings.clone());
let flags = Arc::new(Flags::default());
+ flags
+ .render_distance
+ .store(settings.render_distance, Ordering::Relaxed);
+ flags
+ .simulation_distance
+ .store(settings.simulation_distance, Ordering::Relaxed);
let (ready_tx, ready) = channel();
let (tasks, server_tasks) = channel();
let server_flags = flags.clone();
@@ -249,7 +266,9 @@ impl Game<'_> {
launch.create.as_ref(),
)?;
let saved = Box::new(self.level.clone());
- let view_distance = self.settings.render_distance.clamp(2, 32);
+ // Math.max(2, options.renderDistance): past vanilla's 32 when the
+ // window's render distance is (Horizon's options go to 64).
+ let view_distance = self.settings.render_distance.max(2);
let config = HubConfig {
default_game_mode: self.level.mode(),
// Only the owner until it is opened to the LAN.
@@ -257,7 +276,7 @@ impl Game<'_> {
force_game_mode: false,
hardcore: self.level.hardcore,
view_distance,
- simulation_distance: self.settings.simulation_distance.clamp(2, 32),
+ simulation_distance: self.settings.simulation_distance.max(2),
dimension: self.dim.id().to_owned(),
seed: self.level.seed,
max_players: MAX_PLAYERS,
@@ -314,14 +333,13 @@ impl Game<'_> {
let mut next = Instant::now();
while !flags.stop.load(Ordering::Relaxed) {
self.run_tasks();
- self.update_dedicated_streaming();
- self.update_world();
if flags.paused.load(Ordering::Relaxed) {
// Only the connections run.
- self.tick_lan();
+ self.tick_server(true)?;
} else {
+ self.follow_distances(&flags);
let started = Instant::now();
- self.tick()?;
+ self.tick_server(false)?;
self.debug_charts.log_tick(started, started.elapsed());
flags.smoothed_tick_ms.store(
self.debug_charts.smoothed_tick_ms.to_bits(),
@@ -440,6 +458,28 @@ impl Game<'_> {
}
/// Publish or unpublish for real, once the hub is in its place (a
/// player's `/publish` runs while it is out).
+ /// IntegratedServer.tickServer: the server follows the window's render
+ /// and simulation distances when they change.
+ fn follow_distances(&mut self, flags: &Flags) {
+ let Some(host) = self.lan.as_mut() else {
+ return;
+ };
+ let view = flags.render_distance.load(Ordering::Relaxed).max(2);
+ let old = host.hub.config.view_distance;
+ if view != old {
+ log::info!("Changing view distance to {view}, from {old}");
+ host.hub.set_view_distance(view);
+ self.settings.render_distance = view;
+ }
+ let simulation = flags.simulation_distance.load(Ordering::Relaxed).max(2);
+ let old = host.hub.config.simulation_distance;
+ if simulation != old {
+ log::info!("Changing simulation distance to {simulation}, from {old}");
+ host.hub.set_simulation_distance(simulation);
+ self.settings.simulation_distance = simulation;
+ }
+ }
+
fn apply_publish(&mut self) {
if self.lan.is_none() {
return;
diff --git a/crates/horizon-client/src/game/item_draw.rs b/crates/horizon-client/src/game/item_draw.rs
index aae200b50..b05f4fbf5 100644
--- a/crates/horizon-client/src/game/item_draw.rs
+++ b/crates/horizon-client/src/game/item_draw.rs
@@ -213,7 +213,7 @@ impl Game<'_> {
owner.is_local_player = true;
owner.is_view_entity = true;
if let (Some((slot, ticks)), Some(stack)) = (self.using, stack)
- && self.inventory.get(slot).and_then(Option::as_ref) == Some(stack)
+ && self.stack_in(slot) == Some(stack)
{
let view = item_render::stack_view(stack);
let duration = use_duration(&self.pack.item_renderer.models.components(&view));
diff --git a/crates/horizon-client/src/game/jukebox.rs b/crates/horizon-client/src/game/jukebox.rs
index 235ad7c24..ba7d2b786 100644
--- a/crates/horizon-client/src/game/jukebox.rs
+++ b/crates/horizon-client/src/game/jukebox.rs
@@ -140,63 +140,53 @@ impl Game<'_> {
pub(super) fn jukebox_removed(&mut self, pos: [i32; 3]) {
self.stop_song(pos);
}
- /// `JukeboxSongPlayer.tick` for every playing jukebox.
- pub(super) fn tick_jukeboxes(&mut self) {
- let playing: Vec<((i32, i32, i32), String, i64)> = self
- .world
- .block_entities
- .iter()
- .filter_map(|(k, e)| match e {
- BlockEntity::Jukebox(j) if j.playing => {
- let song = self
- .res
- .items
- .get(&j.record.as_ref()?.item)?
- .jukebox_song
- .clone()?;
- Some((*k, song, j.ticks))
- }
- _ => None,
- })
- .collect();
- for (key, song, ticks) in playing {
- let pos = [key.0, key.1, key.2];
- let Some(s) = self.res.items.songs.get(&song).cloned() else {
- continue;
- };
- if s.finished(ticks) {
- if let Some(BlockEntity::Jukebox(j)) = self.world.block_entities.get_mut(&key) {
- j.playing = false;
- j.ticks = 0;
- }
- self.stop_song(pos);
- self.jukebox_changed(pos);
- continue;
- }
- if !self.jukebox_sounds.contains_key(&key) && ticks == 0 {
- self.start_song(pos, &song);
- }
- if ticks % 20 == 0 {
- let color = f64::from(self.world.random.next_int_bound(4).unwrap_or(0)) / 24.0;
- let at = [
- f64::from(pos[0]) + 0.5,
- f64::from(pos[1]) + 1.2,
- f64::from(pos[2]) + 0.5,
- ];
- self.particles.add(
- &ParticleOptions::simple(ParticleType::Note),
- at,
- [color, 0.0, 0.0],
- );
- }
+ /// `JukeboxSongPlayer.tick` of the jukebox at `key`, while it plays.
+ pub(super) fn tick_jukebox(&mut self, key: (i32, i32, i32)) {
+ let playing = match self.world.block_entities.get(&key) {
+ Some(BlockEntity::Jukebox(j)) if j.playing => j.record.as_ref().and_then(|r| {
+ let song = self.res.items.get(&r.item)?.jukebox_song.clone()?;
+ Some((song, j.ticks))
+ }),
+ _ => None,
+ };
+ let Some((song, ticks)) = playing else {
+ return;
+ };
+ let pos = [key.0, key.1, key.2];
+ let Some(s) = self.res.items.songs.get(&song).cloned() else {
+ return;
+ };
+ if s.finished(ticks) {
if let Some(BlockEntity::Jukebox(j)) = self.world.block_entities.get_mut(&key) {
- j.ticks += 1;
+ j.playing = false;
+ j.ticks = 0;
}
+ self.stop_song(pos);
+ self.jukebox_changed(pos);
+ return;
+ }
+ if !self.jukebox_sounds.contains_key(&key) && ticks == 0 {
+ self.start_song(pos, &song);
+ }
+ if ticks % 20 == 0 {
+ let color = f64::from(self.world.random.next_int_bound(4).unwrap_or(0)) / 24.0;
+ let at = [
+ f64::from(pos[0]) + 0.5,
+ f64::from(pos[1]) + 1.2,
+ f64::from(pos[2]) + 0.5,
+ ];
+ self.particles.add(
+ &ParticleOptions::simple(ParticleType::Note),
+ at,
+ [color, 0.0, 0.0],
+ );
+ }
+ if let Some(BlockEntity::Jukebox(j)) = self.world.block_entities.get_mut(&key) {
+ j.ticks += 1;
}
- self.update_song_volumes();
}
/// Let go of songs that ended or whose jukebox stopped.
- fn update_song_volumes(&mut self) {
+ pub(super) fn update_song_volumes(&mut self) {
let sounds: Vec<_> = self
.jukebox_sounds
.iter()
diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs
index 078083006..114330e51 100644
--- a/crates/horizon-client/src/game/lan.rs
+++ b/crates/horizon-client/src/game/lan.rs
@@ -52,11 +52,15 @@ pub(super) struct LanHost {
/// Blocks broken this tick (their sound is a level event for the guests).
pub broken: Vec<[f64; 3]>,
/// Hurt and death state of the mobs guests see.
- mob_state: HashMap,
+ mob_state: HashMap>,
/// The guest each mob sees as its player, when not the host (game/lan_mobs.rs).
pub mob_players: HashMap,
/// An integrated server's owner (game/integrated.rs).
pub owner: Option,
+ /// The players' locator bars (game/lan_waypoints.rs), and the guests who
+ /// are dead, whose respawn replaces their waypoint.
+ pub waypoints: lan::waypoints::Waypoints,
+ pub waypoint_dead: std::collections::HashSet,
}
/// The player who owns an integrated server's world: a guest whose state is
@@ -69,7 +73,7 @@ pub(super) struct Owner {
}
/// A stable UUID for an entity that has none.
-fn entity_uuid(id: u32) -> u128 {
+pub(super) fn entity_uuid(id: u32) -> u128 {
0x4856_5a4e_0000_0000_0000_0000_0000_0000u128 | u128::from(id)
}
@@ -140,11 +144,15 @@ fn mob_meta(m: &Mob, hub: &Hub) -> Vec<(u8, i32, Value)> {
meta.push((3, serializer::BOOLEAN, Value::Bool(true)));
}
}
- if m.health < m.kind.max_health {
- meta.push((9, serializer::FLOAT, Value::Float(m.health.max(0.0))));
+ // LivingEntity.DATA_HEALTH_ID: defined as 1, then set to the max health.
+ let health = m.health.max(0.0);
+ if health != 1.0 {
+ meta.push((9, serializer::FLOAT, Value::Float(health)));
}
- if kind == "minecraft:rabbit" && m.no_ai {
- meta.push((15, serializer::BYTE, Value::Byte(1)));
+ // Mob.DATA_MOB_FLAGS_ID: no AI 1, left-handed 2.
+ let flags = i8::from(m.no_ai) | i8::from(m.extra.left_handed) << 1;
+ if flags != 0 {
+ meta.push((15, serializer::BYTE, Value::Byte(flags)));
}
if m.is_baby()
&& let Some(index) = baby_index(kind)
@@ -258,7 +266,7 @@ fn mob_meta(m: &Mob, hub: &Hub) -> Vec<(u8, i32, Value)> {
meta.push((
16,
serializer::OPTIONAL_BLOCK_STATE,
- Value::Id(i32::from(state.0 as u16)),
+ Value::Id(state.0 as i32),
));
}
}
@@ -359,6 +367,12 @@ impl Game<'_> {
"open": true,
"host": h.host_name,
"port": h.settings.port,
+ // The server's own world: its finished chunks and how many it
+ // has generated or loaded so far.
+ "world": {
+ "chunks": self.world.chunks.len(),
+ "generated": self.streaming.generated_total,
+ },
"guests": h.hub.guests.iter().map(|g| json!({
"name": g.name,
"position": g.position,
@@ -366,6 +380,7 @@ impl Game<'_> {
"loaded": g.loaded,
"game_mode": g.game_mode,
"sneaking": g.sneaking,
+ "sleeping": g.bed,
"health": g.health,
// FoodData: food level, saturation and exhaustion.
"food": [
@@ -502,6 +517,8 @@ impl Game<'_> {
mob_state: HashMap::new(),
mob_players: HashMap::new(),
owner: None,
+ waypoints: Default::default(),
+ waypoint_dead: Default::default(),
});
self.audio.capture = Some(Vec::new());
Ok(())
@@ -706,9 +723,9 @@ impl Game<'_> {
})
}
- /// Mobs and items as the entities guests track.
- fn lan_entities(&self, hub: &mut Hub) -> Vec {
- let mut out = Vec::with_capacity(self.mobs.len() + self.dropped.len());
+ /// The entities guests track: mobs, items and the rest (game/lan_entities.rs).
+ fn lan_entities(&self, host_entity: Option, hub: &mut Hub) -> Vec {
+ let mut out = Vec::with_capacity(self.mobs.len() + self.dropped.len() + self.orbs.len());
for m in self.mobs.iter().filter(|m| !m.removed) {
let kind = m.kind.id.as_str();
let meta = mob_meta(m, hub);
@@ -727,6 +744,7 @@ impl Game<'_> {
data: 0,
meta,
equipment,
+ precise: false,
});
}
for d in &self.dropped {
@@ -744,8 +762,28 @@ impl Game<'_> {
data: 0,
meta: vec![(8, serializer::ITEM_STACK, Value::Item(stack))],
equipment: Vec::new(),
+ precise: false,
});
}
+ for o in &self.orbs {
+ out.push(EntityState {
+ id: o.id as i32,
+ uuid: entity_uuid(o.id),
+ kind: "minecraft:experience_orb".to_owned(),
+ position: [o.position.x, o.position.y, o.position.z],
+ yaw: 0.0,
+ pitch: 0.0,
+ head_yaw: 0.0,
+ on_ground: o.on_ground,
+ velocity: [o.velocity.x, o.velocity.y, o.velocity.z],
+ data: 0,
+ // ExperienceOrb.DATA_VALUE.
+ meta: vec![(8, serializer::INT, Value::Int(o.value as i32))],
+ equipment: Vec::new(),
+ precise: false,
+ });
+ }
+ self.lan_object_states(host_entity, hub, &mut out);
out
}
@@ -756,12 +794,19 @@ impl Game<'_> {
};
// What the tick sends a guest goes to its connection at the end.
let holding = lan::Holding::start();
+ // The host's own commands' broadcastToAdmins lines.
+ if !self.admin_feedback.is_empty() {
+ self.send_admin_feedback(&mut host, None);
+ }
let state = self.lan_host_state(&host);
// A dedicated server runs the hub without a host player.
if state.is_some() || host.hub.config.dedicated {
let has_guests = !host.hub.guests.is_empty();
let entities = if has_guests {
- self.lan_entities(&mut host.hub)
+ let host_entity = state.as_ref().map(|s| s.entity_id);
+ self.lan_assign_ids();
+ self.lan_riding(host_entity, &mut host.hub.riding);
+ self.lan_entities(host_entity, &mut host.hub)
} else {
Vec::new()
};
@@ -782,8 +827,25 @@ impl Game<'_> {
},
tick_rate: self.clock.rate(),
tick_frozen: self.clock.frozen(),
+ collision: Some(self.collision),
};
- host.hub.tick(&mut ctx)
+ host.hub.movement_checks = (
+ self.ui.rules.bool("player_movement_check"),
+ self.ui.rules.bool("elytra_movement_check"),
+ );
+ // A server with several levels runs a pass for each
+ // (`tick_server`): the network is read once, before the first.
+ let pass = self.level_pass;
+ let mut events = if pass.first {
+ host.hub.poll(&mut ctx)
+ } else {
+ Vec::new()
+ };
+ events.extend(host.hub.tick_level(&mut ctx));
+ if pass.last {
+ host.hub.end_tick();
+ }
+ events
};
if let Some(state) = &state
&& host.host_mode != state.game_mode
@@ -793,12 +855,16 @@ impl Game<'_> {
}
for event in events {
match event {
+ event @ (HostEvent::Chat { .. } | HostEvent::Warn(_) | HostEvent::Error(_)) => {
+ self.lan_log_event(event);
+ }
HostEvent::Joined(conn) => {
self.lan_guest_joined(&mut host, conn, state.as_ref(), &entities, spawn);
if self.options.dedicated.is_some()
&& let Some(g) = host.hub.guest(conn)
{
// PlayerList.placeNewPlayer, then the broadcast join message.
+ super::dedicated::player_joined(g.uuid, &g.name);
let [x, y, z] = g.position;
super::dedicated::log(
"INFO",
@@ -823,7 +889,15 @@ impl Game<'_> {
if let Some(pos) = guest.menu.as_ref().and_then(|m| m.pos)
&& !guest.spectator()
{
- self.container_openers_changed(pos, false);
+ // In the level they were in.
+ let back = self.dim;
+ let theirs = super::Dim::from_id(&guest.dimension);
+ if self.enter_level(Some(&mut host), theirs).is_ok() {
+ self.container_openers_changed(pos, false);
+ }
+ if let Err(e) = self.enter_level(Some(&mut host), back) {
+ log::error!("could not reopen {}: {e}", back.id());
+ }
}
self.lan_crafting_left(&mut host, &mut guest);
self.save_guest(&host, &guest);
@@ -840,11 +914,6 @@ impl Game<'_> {
);
}
}
- // MinecraftServer.logChatMessage of an unsigned message.
- HostEvent::Chat(line) if self.options.dedicated.is_some() => {
- super::dedicated::log("INFO", &format!("[Not Secure] {line}"));
- }
- HostEvent::Chat(line) => self.system_message(Text::literal(line)),
HostEvent::Packet(conn, packet) => {
self.lan_guest_packet(&mut host, conn, *packet);
}
@@ -857,10 +926,9 @@ impl Game<'_> {
self.lan_swings(&mut host);
self.lan_update_streaming(&host);
self.lan_update_models(&mut host);
+ self.lan_update_waypoints(&mut host, state.as_ref());
drop(holding);
- for g in &host.hub.guests {
- g.sender.flush();
- }
+ lan::flush_all(host.hub.guests.iter().map(|g| &g.sender));
self.lan = Some(host);
}
@@ -875,6 +943,7 @@ impl Game<'_> {
let default_mode = host.hub.config.default_game_mode;
let force = host.hub.config.force_game_mode;
let root = self.world_root.clone();
+ let in_place = host.hub.config.dimension.clone();
let owner = host.owner.as_mut();
let Some(g) = host.hub.guest_mut(conn) else {
return;
@@ -897,8 +966,29 @@ impl Game<'_> {
g.previous_position = spawn;
g.health = 20.0;
g.food = 20;
+ g.dimension = super::Dim::Overworld.id().to_owned();
+ }
+ // A server places each player in their own level
+ // (`PlayerList.placeNewPlayer`); the in-frame game has one.
+ let back = self.dim;
+ let level = super::Dim::from_id(&g.dimension);
+ let elsewhere = self.options.dedicated.is_some() && level != back;
+ if !elsewhere {
+ g.dimension = in_place;
}
self.load_guest_records(host, conn);
+ let theirs;
+ let entities = if elsewhere {
+ if let Err(e) = self.enter_level(Some(host), level) {
+ log::error!("could not open {}: {e}", level.id());
+ return;
+ }
+ // A dedicated server has no host player.
+ theirs = self.lan_entities(None, &mut host.hub);
+ &theirs[..]
+ } else {
+ entities
+ };
let mut ctx = TickCtx {
world: &mut self.world,
host: state,
@@ -910,8 +1000,12 @@ impl Game<'_> {
clock_rate: self.ui.clock.rate,
tick_rate: self.clock.rate(),
tick_frozen: self.clock.frozen(),
+ collision: Some(self.collision),
};
host.hub.place_new_player(conn, &mut ctx);
+ if elsewhere && let Err(e) = self.enter_level(Some(host), back) {
+ log::error!("could not reopen {}: {e}", back.id());
+ }
}
/// Level events the game queued, for the guests (`process_level_events`).
@@ -932,7 +1026,7 @@ impl Game<'_> {
/// `Level.blockEvent` for the guests (`ClientboundBlockEventPacket`).
pub(super) fn lan_block_event(&mut self, pos: [i32; 3], b0: i32, b1: i32) {
if self.audio.capture.is_some() {
- let state = self.world.block(pos[0], pos[1], pos[2]).0 as u16;
+ let state = self.world.block(pos[0], pos[1], pos[2]).0;
self.lan_block_events.push((pos, b0, b1, state));
}
}
@@ -966,7 +1060,11 @@ impl Game<'_> {
let mut seen = HashMap::new();
for m in &self.mobs {
let dead = !m.alive();
- let old = host.mob_state.get(&m.id).copied();
+ let old = host
+ .mob_state
+ .get(&self.dim)
+ .and_then(|s| s.get(&m.id))
+ .copied();
let at = [m.position.x, m.position.y, m.position.z];
if m.hurt_time > old.map_or(0, |o| o.0) && !dead {
host.hub.entity_event(m.id as i32, 2, at);
@@ -976,19 +1074,25 @@ impl Game<'_> {
}
seen.insert(m.id, (m.hurt_time, dead));
}
- host.mob_state = seen;
+ host.mob_state.insert(self.dim, seen);
}
/// Keep the chunks around every guest loaded.
fn lan_update_streaming(&mut self, host: &LanHost) {
+ // DistanceManager.PlayerTicketTracker: every chunk within the server's
+ // view distance (Chebyshev) of a player holds a PLAYER_LOADING ticket
+ // at the entity-ticking level (31), whatever the player asked for;
+ // levels rise by one a chunk, so FULL (33) reaches two chunks past
+ // it. An extra area finishes its chunks out to its radius + 1. That
+ // covers what the player tracks (`ChunkTrackingView`, within its view
+ // distance + 1) and those chunks' lit neighbours.
+ let radius = host.hub.config.view_distance + 1;
self.streaming.extra = host
.hub
.guests
.iter()
- .filter(|g| g.placed)
- // The tracked square's corners and their lit neighbours lie
- // within (view distance + 2) * √2 of the player's chunk.
- .map(|g| (g.chunk(), (g.view_distance + 2) * 3 / 2 + 1))
+ .filter(|g| host.hub.here(g))
+ .map(|g| (g.chunk(), radius))
.collect();
}
@@ -1099,3 +1203,24 @@ impl Game<'_> {
}
}
}
+
+impl Game<'_> {
+ /// A hub's chat and log lines: a dedicated server logs them
+ /// (MinecraftServer.logChatMessage, `[Not Secure]` for unsigned or
+ /// expired messages); a LAN host shows the chat.
+ pub(super) fn lan_log_event(&mut self, event: HostEvent) {
+ let dedicated = self.options.dedicated.is_some();
+ match event {
+ HostEvent::Chat { line, secure } if dedicated => {
+ let tag = if secure { "" } else { "[Not Secure] " };
+ super::dedicated::log("INFO", &format!("{tag}{line}"));
+ }
+ HostEvent::Chat { line, .. } => self.system_message(Text::literal(line)),
+ HostEvent::Warn(line) if dedicated => super::dedicated::log("WARN", &line),
+ HostEvent::Warn(line) => log::warn!("{line}"),
+ HostEvent::Error(line) if dedicated => super::dedicated::log("ERROR", &line),
+ HostEvent::Error(line) => log::error!("{line}"),
+ _ => {}
+ }
+ }
+}
diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs
index 1d3433cf0..ced435d8d 100644
--- a/crates/horizon-client/src/game/lan_actions.rs
+++ b/crates/horizon-client/src/game/lan_actions.rs
@@ -18,7 +18,7 @@ use horizon_client::{
},
motion::{MotionEvent, MotionWorld, PlayerMotion},
};
-use horizon_core::geometry::Vec3;
+use horizon_core::{geometry::Vec3, random::RandomSource};
use horizon_protocol::{
packets::play::{self, Clientbound as C, Serverbound as S},
text::literal,
@@ -54,6 +54,10 @@ pub(super) struct GuestPlay {
/// `ServerPlayer.getStats` and the inventory `inventory_changed` last saw.
pub(super) stats: super::stats::Stats,
last_inventory: u64,
+ /// `Entity.portalProcess` and `portalCooldown` (game/server_travel.rs).
+ pub(super) portal: horizon_client::nether_portal::PortalState,
+ /// `Player.takeXpDelay`: ticks until the next orb can be taken.
+ xp_delay: u32,
}
struct ItemRules<'a>(&'a horizon_client::items::Items);
@@ -140,13 +144,20 @@ impl Game<'_> {
total: g.xp_total,
},
);
- let sneak = self.keys.contains(&KeyCode::ShiftLeft);
+ // The host's held keys stay theirs: the guest holds only sneak, and a
+ // screen the guest opens (`keys.clear()`) leaves the host walking.
+ let host_keys = std::mem::take(&mut self.keys);
if g.sneaking {
self.keys.insert(KeyCode::ShiftLeft);
- } else {
- self.keys.remove(&KeyCode::ShiftLeft);
}
+ // The window's screens are the host's: a sign, book, command block or
+ // mount menu the guest's action opens is not drawn over the host's
+ // world (#687). The guest's client opens its own.
let screen = std::mem::replace(&mut self.screen, Screen::Playing);
+ let host_sign = self.sign_edit.take();
+ let host_book = self.book.take();
+ let host_command_block = self.command_block_screen.take();
+ let host_mount_menu = std::mem::take(&mut self.mount_menu);
// The host's crafting grid stays theirs; a crafting table the guest
// opens shows as the 3x3 size.
let craft_size = std::mem::replace(&mut self.craft_size, 2);
@@ -163,6 +174,16 @@ impl Game<'_> {
self.right = play.using.is_some() || self.using.is_some();
let riding = self.riding.take();
let host_station = self.station.take();
+ // The guest's bed, sleep counter and respawn point; the host's
+ // respawn point, anchor and action bar stay theirs.
+ let sleeping = std::mem::replace(&mut self.sleeping, g.bed);
+ let sleep_timer = std::mem::replace(&mut self.sleep_timer, g.sleep_timer);
+ let spawn = std::mem::replace(
+ &mut self.spawn,
+ g.spawn.map(|s| Vec3::new(s[0], s[1], s[2])),
+ );
+ let respawn = (self.respawn_config.take(), self.level.spawn);
+ let message = self.message.take();
// The guest's own ender inventory; one the host has open goes back
// into the host's while the guest acts.
let host_ender = self.ender_open;
@@ -182,6 +203,9 @@ impl Game<'_> {
self.lan_acting_uuid = Some(g.uuid);
let result = f(self);
+ for packet in std::mem::take(&mut self.guest_packets) {
+ host.hub.send_to(conn, &packet);
+ }
self.lan_acting = None;
self.lan_acting_name = None;
self.lan_acting_uuid = None;
@@ -194,6 +218,12 @@ impl Game<'_> {
let opened_table = std::mem::replace(&mut self.craft_size, craft_size) == 3;
self.craft_grid = craft_grid;
let opened_station = std::mem::replace(&mut self.station, host_station);
+ let bed = std::mem::replace(&mut self.sleeping, sleeping);
+ let guest_sleep_timer = std::mem::replace(&mut self.sleep_timer, sleep_timer);
+ let guest_spawn = std::mem::replace(&mut self.spawn, spawn).map(|s| [s.x, s.y, s.z]);
+ (self.respawn_config, self.level.spawn) = respawn;
+ // ServerPlayer.displayClientMessage(_, true): the guest's action bar.
+ let guest_message = std::mem::replace(&mut self.message, message);
self.riding = riding;
self.left = left;
self.right = right;
@@ -205,12 +235,21 @@ impl Game<'_> {
play.swing = std::mem::replace(&mut self.swing, swing);
self.container = container;
self.screen = screen;
- if sneak {
- self.keys.insert(KeyCode::ShiftLeft);
- } else {
- self.keys.remove(&KeyCode::ShiftLeft);
- }
+ self.sign_edit = host_sign;
+ self.book = host_book;
+ self.command_block_screen = host_command_block;
+ self.mount_menu = host_mount_menu;
+ self.keys = host_keys;
let g = &mut host.hub.guests[i];
+ let fell_asleep = bed.is_some() && g.bed.is_none();
+ (g.bed, g.sleep_timer, g.spawn) = (bed, guest_sleep_timer, guest_spawn);
+ g.sleeping = g.bed.is_some();
+ if let Some((text, _)) = guest_message {
+ g.send(&C::SystemChat(play::SystemChat {
+ content: literal(&text),
+ overlay: true,
+ }));
+ }
std::mem::swap(&mut self.ender_items, &mut g.ender_items);
std::mem::swap(&mut self.adv.progress, &mut g.advancements);
std::mem::swap(&mut self.adv.changed, &mut g.advancements_changed);
@@ -260,6 +299,19 @@ impl Game<'_> {
}
}
let g = &mut host.hub.guests[i];
+ if let Some(head) = g.bed.filter(|_| fell_asleep) {
+ // LivingEntity.startSleeping: in the bed, still.
+ let at = [
+ f64::from(head[0]) + 0.5,
+ f64::from(head[1]) + 0.5625,
+ f64::from(head[2]) + 0.5,
+ ];
+ g.position = at;
+ if let Some(m) = g.motion.as_mut() {
+ m.position = Vec3::new(at[0], at[1], at[2]);
+ m.velocity = Vec3::ZERO;
+ }
+ }
if new_mode != g.game_mode {
let conn = g.conn;
host.hub.set_game_mode(conn, new_mode);
@@ -282,6 +334,32 @@ impl Game<'_> {
Some(result)
}
+ /// `ServerLevel.players()` in turn: the host's own player, then each
+ /// guest in the level in place with their state swapped in (`as_guest`).
+ /// What reaches the players around a point (a beacon's powers, a splash
+ /// potion, a warden's darkness, an elder guardian's curse) lands on each
+ /// of them, not only on the host. A server has no player of its own.
+ /// Inside a guest's action (the hub taken) only that player is in place.
+ pub(super) fn for_each_player(&mut self, mut f: impl FnMut(&mut Self)) {
+ if self.player.is_some() {
+ f(self);
+ }
+ let Some(mut host) = self.lan.take() else {
+ return;
+ };
+ let conns: Vec = host
+ .hub
+ .guests
+ .iter()
+ .filter(|g| host.hub.here(g) && g.loaded && !g.dead)
+ .map(|g| g.conn)
+ .collect();
+ for conn in conns {
+ self.as_guest(&mut host, conn, &mut f);
+ }
+ self.lan = Some(host);
+ }
+
/// The game mode fields without `set_mode`'s side effects on the host.
fn set_mode_raw(&mut self, id: i32) {
use horizon_client::command::args::GameMode;
@@ -561,7 +639,8 @@ impl Game<'_> {
self.drop_guest_items(host, gi, vec![c]);
}
}
- S::ChatCommand(c) => self.guest_command(host, conn, &c.command),
+ S::ChatCommand(c) => self.guest_chat_command(host, conn, &c.command),
+ S::ChatCommandSigned(p) => self.guest_signed_command(host, conn, p),
S::ChangeDifficulty(p) if host.hub.guests[gi].permission >= 2 => {
if !self.level.difficulty_locked && (0..=3).contains(&p.difficulty) {
self.ui.difficulty = if self.level.hardcore {
@@ -650,12 +729,7 @@ impl Game<'_> {
}),
);
}
- }
- }
- S::Unknown(8, payload) => {
- // A signed command: the text comes first.
- if let Ok(text) = horizon_protocol::buf::Reader::new(&payload).string(32767) {
- self.guest_command(host, conn, &text);
+ self.send_admin_feedback(host, Some(conn));
}
}
S::Unknown(id, payload)
@@ -663,6 +737,7 @@ impl Game<'_> {
{
self.guest_suggestions(host, conn, &payload);
}
+ S::PlaceRecipe(p) => self.lan_place_recipe(host, conn, &p),
S::ClientCommand(c) if c.action == 0 => self.guest_respawn(host, conn),
// ServerStatsCounter.sendStats.
S::ClientCommand(c) if c.action == 1 => {
@@ -781,7 +856,18 @@ impl Game<'_> {
}
/// Commands.performCommand for a guest with command access.
- fn guest_command(&mut self, host: &mut LanHost, conn: u32, command: &str) {
+ /// Commands.performCommand for a guest, with the message arguments it
+ /// signed (none after an unsigned command packet).
+ pub(super) fn guest_command(
+ &mut self,
+ host: &mut LanHost,
+ conn: u32,
+ command: &str,
+ signed: Option>,
+ ) {
+ if self.guest_message_command(host, conn, command, signed.as_ref()) {
+ return;
+ }
// ListPlayersCommand needs no permission and lists every player.
let words: Vec<&str> = command.trim_start_matches('/').split(' ').collect();
if words[0] == "list" && (words.len() == 1 || words[1..] == ["uuids"]) {
@@ -851,6 +937,8 @@ impl Game<'_> {
.map(|t| horizon_client::lan::data::component_nbt(&t.component()))
.collect::>()
});
+ // A teleport into another level happens before its feedback is sent.
+ self.run_level_teleports(host);
for content in lines.unwrap_or_default() {
host.hub.send_to(
conn,
@@ -860,6 +948,41 @@ impl Game<'_> {
}),
);
}
+ self.send_admin_feedback(host, Some(conn));
+ }
+
+ /// The `broadcastToAdmins` lines a command queued (`source`: the guest
+ /// whose it was; none for the host's or the console's): every other
+ /// operator gets them, and the console logs them as the server's own
+ /// system messages (MinecraftServer.sendSystemMessage).
+ pub(super) fn send_admin_feedback(&mut self, host: &mut LanHost, source: Option) {
+ // PlayerList.isOp for the host of a world open to LAN: the owner when
+ // the world allows commands, everyone when the LAN does.
+ let host_op = source.is_some()
+ && !host.hub.config.dedicated
+ && (self.allow_commands() || host.hub.config.guest_commands);
+ for (line, ops, console) in std::mem::take(&mut self.admin_feedback) {
+ if ops {
+ let content = horizon_client::lan::data::component_nbt(&line.component());
+ for g in host
+ .hub
+ .guests
+ .iter()
+ .filter(|g| Some(g.conn) != source && g.permission > 0)
+ {
+ g.send(&C::SystemChat(play::SystemChat {
+ content: content.clone(),
+ overlay: false,
+ }));
+ }
+ if host_op {
+ self.system_message(line.clone());
+ }
+ }
+ if console {
+ super::dedicated::log("INFO", &format!("System chat: {}", line.plain()));
+ }
+ }
}
/// ServerGamePacketListenerImpl.handleCustomCommandSuggestions: the
@@ -903,14 +1026,34 @@ impl Game<'_> {
}
fn guest_respawn(&mut self, host: &mut LanHost, conn: u32) {
- let spawn = self.spawn.map_or([0.5, 80.0, 0.5], |s| [s.x, s.y, s.z]);
let Some(i) = host.hub.guests.iter().position(|g| g.conn == conn) else {
return;
};
+ // The guest's own bed, else the world spawn: never the host's bed.
+ let world = self
+ .level
+ .world_spawn
+ .map(|[x, y, z]| [f64::from(x) + 0.5, f64::from(y), f64::from(z) + 0.5]);
+ let spawn = host.hub.guests[i]
+ .spawn
+ .or(world)
+ .or(self.spawn.map(|s| [s.x, s.y, s.z]))
+ .unwrap_or([0.5, 80.0, 0.5]);
if !host.hub.guests[i].dead {
return;
}
- self.respawn_level(host);
+ // PlayerList.respawn: a server's player comes back in the Overworld,
+ // where the world spawn is (respawn anchors and beds aside).
+ let back = self.dim;
+ let away = self.options.dedicated.is_some()
+ && host.hub.guests[i].dimension != super::Dim::Overworld.id();
+ if away {
+ self.server_trips.retain(|t| !t.is(conn));
+ if let Err(e) = self.enter_level(Some(host), super::Dim::Overworld) {
+ log::error!("could not open the Overworld: {e}");
+ return;
+ }
+ }
let g = &mut host.hub.guests[i];
g.dead = false;
g.health = 20.0;
@@ -944,8 +1087,12 @@ impl Game<'_> {
},
tick_rate: self.clock.rate(),
tick_frozen: self.clock.frozen(),
+ collision: Some(self.collision),
};
host.hub.respawn(i, spawn, &ctx);
+ if away && let Err(e) = self.enter_level(Some(host), back) {
+ log::error!("could not reopen {}: {e}", back.id());
+ }
}
/// Per tick, for every guest: dig, use items, pick up drops, die.
@@ -956,13 +1103,14 @@ impl Game<'_> {
.hub
.guests
.iter()
- .filter(|g| g.placed && g.loaded)
+ .filter(|g| host.hub.here(g) && g.loaded)
.map(|g| g.conn)
.collect();
for conn in conns {
let Some(gi) = host.hub.guests.iter().position(|g| g.conn == conn) else {
continue;
};
+ self.guest_sleep_tick(host, gi);
if host.hub.guests[gi].dead || self.on_server_trip(conn) {
continue;
}
@@ -1005,6 +1153,7 @@ impl Game<'_> {
host.hub.flush_progress(conn);
self.guest_dig_feedback(host, conn);
self.guest_pickups(host, gi);
+ self.guest_orbs(host, gi);
let g = &mut host.hub.guests[gi];
if g.health <= 0.0 && !g.dead {
g.dead = true;
@@ -1028,6 +1177,62 @@ impl Game<'_> {
}
}
+ /// `Player.tick`'s sleep counter, and `LivingEntity.tick`'s wake-up of a
+ /// sleeper who died or whose bed is gone.
+ fn guest_sleep_tick(&mut self, host: &mut LanHost, gi: usize) {
+ let g = &mut host.hub.guests[gi];
+ g.sleep_timer = super::tick_sleep_timer(g.sleep_timer, g.bed.is_some());
+ if let Some(head) = g.bed {
+ let block = self.world.block(head[0], head[1], head[2]);
+ let bed = self.res.facts.get(block).name.ends_with("_bed");
+ if g.dead || g.health <= 0.0 || !bed {
+ host.hub.wake(gi);
+ }
+ }
+ }
+
+ /// `SleepStatus.areEnoughSleeping` and `areEnoughDeepSleeping` over the
+ /// host's player and the guests: of the players not in spectator mode,
+ /// players_sleeping_percentage of them (at least one) are in bed, and as
+ /// many have slept 100 ticks.
+ pub(super) fn enough_slept(&self) -> bool {
+ let (mut active, mut sleeping, mut deep) = (0i64, 0i64, 0i64);
+ let mut count = |in_bed: bool, timer: u32| {
+ active += 1;
+ if in_bed {
+ sleeping += 1;
+ if timer >= 100 {
+ deep += 1;
+ }
+ }
+ };
+ if self.player.is_some() && !self.spectator() {
+ count(self.sleeping.is_some(), self.sleep_timer);
+ }
+ if let Some(host) = self.lan.as_ref() {
+ for g in host
+ .hub
+ .guests
+ .iter()
+ .filter(|g| g.placed && !g.spectator())
+ {
+ count(g.bed.is_some(), g.sleep_timer);
+ }
+ }
+ let percent = i64::from(self.ui.rules.int("players_sleeping_percentage").max(0));
+ let needed = ((active * percent + 99) / 100).max(1);
+ sleeping >= needed && deep >= needed
+ }
+
+ /// `ServerLevel.wakeUpAllPlayers` for the guests.
+ pub(super) fn wake_guests(&mut self) {
+ if let Some(host) = self.lan.as_mut() {
+ for i in 0..host.hub.guests.len() {
+ host.hub.wake(i);
+ }
+ }
+ }
+
/// `PlayerList.broadcastSystemMessage` of the advancements guests made
/// (their own actions, commands and ticks).
fn announce_guest_advancements(&mut self, host: &mut LanHost) {
@@ -1306,6 +1511,79 @@ impl Game<'_> {
}
}
+ /// `Player.tick`'s takeXpDelay and `Player.aiStep`'s touch of the
+ /// experience orbs in the guest's box grown by 1, 0.5, 1: one of them at
+ /// random, at most every 2 ticks (`ExperienceOrb.playerTouch`), repairs
+ /// with Mending and gives the rest as points. Everyone near hears it.
+ fn guest_orbs(&mut self, host: &mut LanHost, gi: usize) {
+ let g = &host.hub.guests[gi];
+ // Player's standing and crouching boxes: 1.8 and 1.5 high.
+ let height = if g.sneaking { 1.5 } else { 1.8 };
+ let (conn, id, at) = (g.conn, g.entity_id, g.position);
+ let unable = g.spectator() || g.dead || g.health <= 0.0;
+ let play = host.play.entry(conn).or_default();
+ if play.xp_delay > 0 {
+ play.xp_delay -= 1;
+ }
+ if unable || play.xp_delay > 0 {
+ return;
+ }
+ let (min, max) = (
+ [at[0] - 1.3, at[1] - 0.5, at[2] - 1.3],
+ [at[0] + 1.3, at[1] + height + 0.5, at[2] + 1.3],
+ );
+ let touching: Vec = self
+ .orbs
+ .iter()
+ .enumerate()
+ .filter(|(_, o)| {
+ o.position.x + 0.25 > min[0]
+ && o.position.x - 0.25 < max[0]
+ && o.position.y + 0.5 > min[1]
+ && o.position.y < max[1]
+ && o.position.z + 0.25 > min[2]
+ && o.position.z - 0.25 < max[2]
+ })
+ .map(|(i, _)| i)
+ .collect();
+ if touching.is_empty() {
+ return;
+ }
+ // Util.getRandom(orbs, random).
+ let pick = self
+ .world
+ .random
+ .next_int_bound(touching.len() as i32)
+ .unwrap_or(0) as usize;
+ let orb = self.orbs.remove(touching[pick]);
+ play.xp_delay = 2;
+ host.hub.take_item(orb.id as i32, id, 1, at);
+ // ClientPacketListener.handleTakeItemEntity's sound, at the orb.
+ let pitch = (self.world.random.next_float() - self.world.random.next_float()) * 0.35 + 0.9;
+ let p = orb.position;
+ self.audio.play(
+ "minecraft:entity.experience_orb.pickup",
+ Some([p.x, p.y, p.z]),
+ 0.1,
+ pitch,
+ );
+ let value = orb.value;
+ if let Some(target) = super::pickups::guest_target(host, id as u32) {
+ use super::pickups::{Collector, Taken};
+ self.add_pickup_toward(
+ Taken::Orb(Box::new(orb)),
+ Collector::Guest(id as u32),
+ target,
+ );
+ }
+ self.as_guest(host, conn, |game| {
+ let rest = game.mending(value);
+ if rest > 0 {
+ game.give_orb_points(rest);
+ }
+ });
+ }
+
/// The host's own `ItemPickupParticle` toward the guest's model.
fn guest_pickup(
&mut self,
@@ -1348,6 +1626,9 @@ impl Game<'_> {
let Some(g) = host.hub.guests.iter().find(|g| g.conn == conn) else {
continue;
};
+ if !host.hub.here(g) {
+ continue;
+ }
let (id, at) = (g.entity_id, g.position);
let play = host.play.get_mut(&conn).expect("play");
let swinging = play.swing.swinging() && play.swing.ticks == 0;
diff --git a/crates/horizon-client/src/game/lan_chat.rs b/crates/horizon-client/src/game/lan_chat.rs
new file mode 100644
index 000000000..f678480ab
--- /dev/null
+++ b/crates/horizon-client/src/game/lan_chat.rs
@@ -0,0 +1,194 @@
+//! A guest's commands that carry chat: the unsigned and signed command
+//! packets (ServerGamePacketListenerImpl.handleChatCommand and
+//! handleSignedChatCommand), and the message commands whose text they sign
+//! (SayCommand, EmoteCommands, MsgCommand), relayed by the hub as chat.
+use super::{Game, lan::LanHost};
+use horizon_client::{
+ command::{Arg, ArgType, NodeKind, ParseResults, vanilla},
+ lan::{
+ data::component_nbt,
+ hub::{HostEvent, chat::ChatMessage},
+ },
+ text::{self, Text},
+};
+use horizon_protocol::packets::play::{self, Clientbound as C};
+
+/// The signing context of a command: each message argument as the chain
+/// let it through, by argument name (CommandSigningContext.SignedArguments).
+type Signed = Vec<(String, ChatMessage)>;
+
+impl Game<'_> {
+ /// CommandDispatcher.parse with the guest's permission level.
+ fn parse_as(&mut self, permission: u8, command: &str) -> ParseResults {
+ let level = std::mem::replace(&mut self.ui.registries.permission, permission);
+ let parse = vanilla::game_dispatcher().parse(command, &self.ui.registries);
+ self.ui.registries.permission = level;
+ parse
+ }
+
+ /// SignableCommand.of: the command's message arguments, by name, with
+ /// their text, not past a redirect to the root (`execute ... run`).
+ fn signable_arguments(&mut self, permission: u8, command: &str) -> Vec<(String, String)> {
+ let parse = self.parse_as(permission, command);
+ let nodes = &vanilla::game_dispatcher().nodes;
+ let root = parse.context.root;
+ let mut out = Vec::new();
+ let mut context = Some(&parse.context);
+ while let Some(c) = context {
+ for &(node, (start, end)) in &c.nodes {
+ if let NodeKind::Argument {
+ ty: ArgType::Message,
+ name,
+ } = &nodes[node].kind
+ && let Some(text) = command.get(start..end)
+ {
+ out.push((name.clone(), text.to_owned()));
+ }
+ }
+ context = c.child.as_deref().filter(|child| child.root != root);
+ }
+ out
+ }
+
+ /// handleChatCommand (performUnsignedChatCommand): refused when the
+ /// server enforces secure chat and the command has a message to sign.
+ pub(super) fn guest_chat_command(&mut self, host: &mut LanHost, conn: u32, command: &str) {
+ let Some(i) = host.hub.guests.iter().position(|g| g.conn == conn) else {
+ return;
+ };
+ if !host.hub.try_handle_chat(i, command, true) {
+ return;
+ }
+ let permission = host.hub.guests[i].permission;
+ if host.hub.enforces_secure_chat()
+ && !self.signable_arguments(permission, command).is_empty()
+ {
+ let name = host.hub.guests[i].name.clone();
+ self.lan_log_event(HostEvent::Error(format!(
+ "Received unsigned command packet from {name}, but the command requires signable arguments: {command}"
+ )));
+ let failure = Text::translate("chat.disabled.invalid_command_signature", &[])
+ .with_color(text::RED);
+ host.hub.guests[i].send(&C::SystemChat(play::SystemChat {
+ content: component_nbt(&failure.component()),
+ overlay: false,
+ }));
+ return;
+ }
+ self.guest_command(host, conn, command, None);
+ }
+
+ /// handleSignedChatCommand: the acknowledgements, then each message
+ /// argument through the sender's chain, then the command with them.
+ pub(super) fn guest_signed_command(
+ &mut self,
+ host: &mut LanHost,
+ conn: u32,
+ p: play::ChatCommandSigned,
+ ) {
+ let Some(i) = host.hub.guests.iter().position(|g| g.conn == conn) else {
+ return;
+ };
+ let mut events = Vec::new();
+ let mut signed = None;
+ if let Some(last_seen) = host.hub.apply_last_seen(i, &p.last_seen, &mut events)
+ && host.hub.try_handle_chat(i, &p.command, true)
+ {
+ let permission = host.hub.guests[i].permission;
+ let parsed = self.signable_arguments(permission, &p.command);
+ match host
+ .hub
+ .signed_arguments(i, &p, &parsed, &last_seen, &mut events)
+ {
+ Ok(arguments) => signed = Some(arguments),
+ Err(e) => host.hub.decode_failure(i, e, &mut events),
+ }
+ }
+ for event in events {
+ self.lan_log_event(event);
+ }
+ if let Some(signed) = signed {
+ self.guest_command(host, conn, &p.command, Some(signed));
+ }
+ }
+
+ /// SayCommand, EmoteCommands and MsgCommand for a guest: chat to the
+ /// players, signed when the guest signed it (a disguised chat after an
+ /// unsigned command packet). False when the command is another one, or
+ /// one this can't run (selectors other than `@s` and `@a`), for the
+ /// game's dispatcher to handle.
+ pub(super) fn guest_message_command(
+ &mut self,
+ host: &mut LanHost,
+ conn: u32,
+ command: &str,
+ signed: Option<&Signed>,
+ ) -> bool {
+ let Some(i) = host.hub.guests.iter().position(|g| g.conn == conn) else {
+ return false;
+ };
+ let parse = self.parse_as(host.hub.guests[i].permission, command);
+ let Ok((context, id)) = parse.executable() else {
+ return false;
+ };
+ let argument = if id == "me" { "action" } else { "message" };
+ let (Some(Arg::Str(text)), true) =
+ (context.get(argument), matches!(id, "say" | "me" | "msg"))
+ else {
+ return false;
+ };
+ let message = signed.and_then(|s| {
+ s.iter()
+ .find(|(n, _)| n == argument)
+ .map(|(_, m)| m.clone())
+ });
+ let mut events = Vec::new();
+ if id == "msg" {
+ let Some(Arg::Entity(selector)) = context.get("targets") else {
+ return false;
+ };
+ let raw = context
+ .args
+ .iter()
+ .rev()
+ .find(|a| a.name == "targets")
+ .and_then(|a| command.get(a.range.0..a.range.1));
+ let guests = &host.hub.guests;
+ let placed = |k: &usize| guests[*k].placed;
+ let targets: Vec = match (raw, &selector.player_name, selector.uuid) {
+ (Some("@s"), ..) => vec![i],
+ (Some("@a"), ..) => (0..guests.len()).filter(placed).collect(),
+ (_, Some(name), _) => (0..guests.len())
+ .filter(|&k| placed(&k) && guests[k].name.eq_ignore_ascii_case(name))
+ .collect(),
+ (_, None, Some(uuid)) => (0..guests.len())
+ .filter(|&k| placed(&k) && guests[k].uuid == uuid)
+ .collect(),
+ _ => return false,
+ };
+ if targets.is_empty() {
+ let failure = Text::empty()
+ .append(Text::translate("argument.entity.notfound.player", &[]))
+ .with_color(text::RED);
+ host.hub.guests[i].send(&C::SystemChat(play::SystemChat {
+ content: component_nbt(&failure.component()),
+ overlay: false,
+ }));
+ return true;
+ }
+ host.hub.whisper(i, &targets, message, text);
+ } else {
+ let chat_type = if id == "say" {
+ "say_command"
+ } else {
+ "emote_command"
+ };
+ host.hub
+ .broadcast_command_chat(i, chat_type, message, text, &mut events);
+ }
+ for event in events {
+ self.lan_log_event(event);
+ }
+ true
+ }
+}
diff --git a/crates/horizon-client/src/game/lan_crafting.rs b/crates/horizon-client/src/game/lan_crafting.rs
index 9841fa879..1f16a9c74 100644
--- a/crates/horizon-client/src/game/lan_crafting.rs
+++ b/crates/horizon-client/src/game/lan_crafting.rs
@@ -225,6 +225,86 @@ impl Game<'_> {
true
}
+ /// ServerGamePacketListenerImpl.handlePlaceRecipe: the guest's recipe
+ /// book places a known recipe in their inventory grid or crafting table
+ /// (`ServerPlaceRecipe`), and answers with a ghost recipe when the items
+ /// are missing.
+ pub(super) fn lan_place_recipe(
+ &mut self,
+ host: &mut LanHost,
+ conn: u32,
+ p: &horizon_protocol::packets::recipes::PlaceRecipe,
+ ) {
+ use horizon_client::menu::place::PostPlace;
+ let Some(gi) = host.hub.guests.iter().position(|g| g.conn == conn) else {
+ return;
+ };
+ let g = &host.hub.guests[gi];
+ if g.spectator() {
+ return;
+ }
+ let Some(id) = self
+ .res
+ .stations
+ .recipe_index
+ .recipe_of_display(p.recipe)
+ .map(str::to_owned)
+ else {
+ return;
+ };
+ // An unknown or impossible recipe is refused outright.
+ if !g.recipe_book.knows(&id)
+ || self
+ .res
+ .recipes
+ .placement(&id)
+ .is_none_or(|placement| placement.impossible())
+ {
+ return;
+ }
+ let creative = g.creative();
+ let placed = if p.container == 0 {
+ let crafting = host.play.entry(conn).or_default();
+ let mut menu = crafting
+ .crafting
+ .inventory
+ .take()
+ .unwrap_or_else(|| Box::new(Menu::new(Kind::Inventory)));
+ let grid = host.hub.guests[gi].craft_grid.clone();
+ let placed = self.guest_menu_op(host, gi, &mut menu, |menu, env| {
+ for (k, s) in grid.into_iter().enumerate() {
+ menu.set_slot(env, 1 + k, s);
+ }
+ menu.place_recipe(env, &id, p.use_max, creative, None)
+ });
+ let g = &mut host.hub.guests[gi];
+ for k in 0..4 {
+ g.craft_grid[k] = menu.slot(1 + k).cloned();
+ }
+ g.craft_result = menu.slot(0).cloned();
+ host.play.entry(conn).or_default().crafting.inventory = Some(menu);
+ host.hub.send_inventory(gi);
+ placed
+ } else {
+ let Some((window, state, mut menu)) = host
+ .play
+ .get_mut(&conn)
+ .and_then(|play| play.crafting.table.take_if(|(w, _, _)| *w == p.container))
+ else {
+ return;
+ };
+ let placed = self.guest_menu_op(host, gi, &mut menu, |menu, env| {
+ menu.place_recipe(env, &id, p.use_max, creative, None)
+ });
+ host.play.entry(conn).or_default().crafting.table = Some((window, state, menu));
+ self.lan_send_table_content(host, conn);
+ placed
+ };
+ if placed == PostPlace::Ghost {
+ host.hub.send_ghost_recipe(conn, p.container, &id);
+ }
+ }
+
/// The guest opened a crafting table (`CraftingTableBlock.getMenuProvider`).
pub(super) fn lan_open_crafting(&mut self, host: &mut LanHost, conn: u32) {
self.lan_crafting_closed(host, conn, None);
diff --git a/crates/horizon-client/src/game/lan_entities.rs b/crates/horizon-client/src/game/lan_entities.rs
new file mode 100644
index 000000000..3ea172482
--- /dev/null
+++ b/crates/horizon-client/src/game/lan_entities.rs
@@ -0,0 +1,449 @@
+//! The entities beyond mobs and items that a server tracks to its clients
+//! (`ChunkMap.TrackedEntity`, `ServerEntity`): boats, minecarts, armor
+//! stands, item frames, paintings and the entities Horizon keeps without
+//! simulating them, each as vanilla pairs it (`getAddEntityPacket` and the
+//! synched data that differs from the defaults), and who rides what.
+use super::Game;
+use horizon_client::lan::{
+ entity::{EntityState, Riding},
+ hub::Hub,
+};
+use horizon_protocol::entity_data::{Value, serializer};
+use horizon_world::nbt::Tag;
+
+/// `ArmorStand`'s default poses (head, body, left arm, right arm, left leg,
+/// right leg), DATA_HEAD_POSE to DATA_RIGHT_LEG_POSE (entries 16 to 21),
+/// under their `Pose` keys.
+const STAND_POSES: [(&str, [f32; 3]); 6] = [
+ ("Head", [0.0, 0.0, 0.0]),
+ ("Body", [0.0, 0.0, 0.0]),
+ ("LeftArm", [-10.0, 0.0, -10.0]),
+ ("RightArm", [-15.0, 0.0, 10.0]),
+ ("LeftLeg", [-1.0, 0.0, -1.0]),
+ ("RightLeg", [1.0, 0.0, 1.0]),
+];
+
+fn state(id: u32, kind: &str, position: [f64; 3], yaw: f32, on_ground: bool) -> EntityState {
+ EntityState {
+ id: id as i32,
+ uuid: super::lan::entity_uuid(id),
+ kind: kind.to_owned(),
+ position,
+ yaw,
+ pitch: 0.0,
+ head_yaw: 0.0,
+ on_ground,
+ velocity: [0.0; 3],
+ data: 0,
+ meta: Vec::new(),
+ equipment: Vec::new(),
+ precise: false,
+ }
+}
+
+/// `VehicleEntity`'s DATA_ID_HURT, DATA_ID_HURTDIR and DATA_ID_DAMAGE
+/// (entries 8 to 10) when they differ from their defaults (0, 1, 0).
+fn vehicle_meta(hurt_time: i32, hurt_dir: i32, damage: f32) -> Vec<(u8, i32, Value)> {
+ let mut meta = Vec::new();
+ if hurt_time != 0 {
+ meta.push((8, serializer::INT, Value::Int(hurt_time)));
+ }
+ if hurt_dir != 1 {
+ meta.push((9, serializer::INT, Value::Int(hurt_dir)));
+ }
+ if damage != 0.0 {
+ meta.push((10, serializer::FLOAT, Value::Float(damage)));
+ }
+ meta
+}
+
+/// An armor stand's pose from its compound (`ArmorStandPose`), each part
+/// that differs from the default.
+fn stand_poses(raw: Option<&Tag>) -> Vec<(u8, i32, Value)> {
+ let Some(pose) = raw.and_then(|t| t.get("Pose")) else {
+ return Vec::new();
+ };
+ let mut meta = Vec::new();
+ for (i, (key, default)) in STAND_POSES.iter().enumerate() {
+ let Some(Tag::List(values)) = pose.get(key) else {
+ continue;
+ };
+ let mut r = *default;
+ for (k, v) in values.iter().take(3).enumerate() {
+ if let Tag::Float(bits) = v {
+ r[k] = f32::from_bits(*bits);
+ }
+ }
+ if r != *default {
+ meta.push((
+ 16 + i as u8,
+ serializer::ROTATIONS,
+ Value::Floats(r.to_vec()),
+ ));
+ }
+ }
+ meta
+}
+
+impl Game<'_> {
+ /// Who rides what (`Entity.getPassengers`): mobs on mobs, and the
+ /// host in its boat or minecart.
+ pub(super) fn lan_riding(&self, host_entity: Option, riding: &mut Riding) {
+ riding.clear();
+ for m in self.mobs.iter().filter(|m| !m.removed) {
+ if let Some(vehicle) = m.extra.mount {
+ riding.add(vehicle as i32, m.id as i32);
+ }
+ }
+ if let (Some(host), Some(vehicle)) = (host_entity, self.riding) {
+ riding.add(vehicle as i32, host);
+ }
+ }
+
+ /// Boats, minecarts, armor stands, item frames, paintings and the
+ /// entities kept unsimulated, as guests track them.
+ pub(super) fn lan_object_states(
+ &self,
+ host_entity: Option,
+ hub: &mut Hub,
+ out: &mut Vec,
+ ) {
+ for b in &self.boats {
+ let p = b.position;
+ let mut e = state(b.id, &b.entity_type(), [p.x, p.y, p.z], b.yaw, b.on_ground);
+ e.velocity = [b.velocity.x, b.velocity.y, b.velocity.z];
+ e.meta = vehicle_meta(b.hurt_time, b.hurt_dir, b.damage);
+ // AbstractBoat.DATA_ID_PADDLE_LEFT and DATA_ID_PADDLE_RIGHT.
+ for (k, paddling) in b.paddling.iter().enumerate() {
+ if *paddling {
+ e.meta
+ .push((11 + k as u8, serializer::BOOLEAN, Value::Bool(true)));
+ }
+ }
+ out.push(e);
+ }
+ for c in &self.carts {
+ let p = c.position;
+ let mut e = state(c.id, c.kind.id(), [p.x, p.y, p.z], c.yaw, c.on_ground());
+ e.velocity = [c.velocity.x, c.velocity.y, c.velocity.z];
+ e.meta = vehicle_meta(c.hurt_time, c.hurt_dir, c.damage);
+ match c.kind {
+ // MinecartFurnace.DATA_ID_FUEL.
+ super::minecarts::CartKind::Furnace if c.fuel > 0 => {
+ e.meta.push((13, serializer::BOOLEAN, Value::Bool(true)));
+ }
+ // MinecartCommandBlock.DATA_ID_COMMAND_NAME.
+ super::minecarts::CartKind::CommandBlock => {
+ if let Some(Tag::String(command)) =
+ self.persist.raw.get(&c.id).and_then(|t| t.get("Command"))
+ {
+ let command = command.to_string_lossy();
+ if !command.is_empty() {
+ e.meta
+ .push((13, serializer::STRING, Value::String(command)));
+ }
+ }
+ }
+ _ => {}
+ }
+ out.push(e);
+ }
+ for a in &self.armor_stands {
+ let p = a.position;
+ let mut e = state(
+ a.id,
+ "minecraft:armor_stand",
+ [p.x, p.y, p.z],
+ a.yaw,
+ a.on_ground,
+ );
+ e.head_yaw = a.yaw;
+ e.velocity = [a.velocity.x, a.velocity.y, a.velocity.z];
+ if a.fire_ticks > 0 {
+ e.meta.push((0, serializer::BYTE, Value::Byte(1)));
+ }
+ // LivingEntity.DATA_HEALTH_ID: 1 until the stand's max health is set.
+ e.meta.push((9, serializer::FLOAT, Value::Float(a.health)));
+ // ArmorStand.DATA_CLIENT_FLAGS: small 1, arms 4, no base plate 8, marker 16.
+ let flags = i8::from(a.small)
+ | i8::from(a.show_arms) << 2
+ | i8::from(a.no_base_plate) << 3
+ | i8::from(a.marker) << 4;
+ if flags != 0 {
+ e.meta.push((15, serializer::BYTE, Value::Byte(flags)));
+ }
+ e.meta.extend(stand_poses(self.persist.raw.get(&a.id)));
+ // Stored main hand, off hand, feet, legs, chest, head: the wire's slots 0 to 5.
+ for (slot, item) in a.equipment.iter().enumerate() {
+ if item.is_some() {
+ e.equipment.push((slot as u8, hub.stack(item)));
+ }
+ }
+ out.push(e);
+ }
+ for f in &self.item_frames {
+ // ItemFrame.getAddEntityPacket: the block it hangs in and its direction.
+ let mut e = state(f.id, f.kind(), f.pos.map(f64::from), 0.0, false);
+ e.pitch = match f.facing {
+ 0 => 90.0,
+ 1 => -90.0,
+ _ => 0.0,
+ };
+ e.yaw = match f.facing {
+ 2 => 180.0,
+ 4 => 90.0,
+ 5 => 270.0,
+ _ => 0.0,
+ };
+ e.data = i32::from(f.facing);
+ // HangingEntity.DATA_DIRECTION, south by default.
+ if f.facing != 3 {
+ e.meta
+ .push((8, serializer::DIRECTION, Value::Id(i32::from(f.facing))));
+ }
+ if f.item.is_some() {
+ e.meta
+ .push((9, serializer::ITEM_STACK, Value::Item(hub.stack(&f.item))));
+ }
+ if f.rotation != 0 {
+ e.meta
+ .push((10, serializer::INT, Value::Int(i32::from(f.rotation))));
+ }
+ out.push(e);
+ }
+ for p in &self.paintings {
+ let mut e = state(p.id, "minecraft:painting", p.pos.map(f64::from), 0.0, false);
+ // Direction.get2DDataValue (south 0, west 1, north 2, east 3) to its
+ // 3D data value and yaw.
+ let facing = [3, 4, 2, 5][usize::from(p.facing & 3)];
+ e.yaw = f32::from(p.facing & 3) * 90.0;
+ e.data = facing;
+ if facing != 3 {
+ e.meta.push((8, serializer::DIRECTION, Value::Id(facing)));
+ }
+ // Painting.DATA_PAINTING_VARIANT_ID, a registry holder (id + 1),
+ // set unless it is the registry's first variant (VariantUtils.getAny).
+ if let Some(id) = hub.registry_id("minecraft:painting_variant", &p.variant)
+ && id != 0
+ {
+ e.meta
+ .push((9, serializer::PAINTING_VARIANT, Value::Id(id + 1)));
+ }
+ out.push(e);
+ }
+ self.lan_projectile_states(host_entity, hub, out);
+ for o in &self.others {
+ let p = o.position;
+ let mut e = state(o.id, &o.kind, [p.x, p.y, p.z], o.yaw, false);
+ e.pitch = o.pitch;
+ e.head_yaw = o.yaw;
+ out.push(e);
+ }
+ }
+}
+
+impl Game<'_> {
+ /// Gives the entities Horizon keeps without an id one (`Entity.id`, from
+ /// the same counter as the rest) before they are first tracked.
+ pub(super) fn lan_assign_ids(&mut self) {
+ let next = &mut self.next_entity;
+ let mut give = |id: &mut u32| {
+ if *id == 0 {
+ *next += 1;
+ *id = *next;
+ }
+ };
+ self.tnts.iter_mut().for_each(|t| give(&mut t.id));
+ self.falling.iter_mut().for_each(|f| give(&mut f.id));
+ self.creatures
+ .projectiles
+ .iter_mut()
+ .for_each(|p| give(&mut p.id));
+ self.tridents.iter_mut().for_each(|t| give(&mut t.id));
+ self.rockets.iter_mut().for_each(|r| give(&mut r.id));
+ self.crystals.iter_mut().for_each(|c| give(&mut c.id));
+ }
+
+ /// Primed TNT, falling blocks, projectiles, tridents, firework rockets and
+ /// end crystals, as guests track them.
+ fn lan_projectile_states(
+ &self,
+ host_entity: Option,
+ hub: &mut Hub,
+ out: &mut Vec,
+ ) {
+ let owner = |who: Option| match who {
+ Some(horizon_client::mobs::Who::Mob(id)) => id as i32,
+ Some(horizon_client::mobs::Who::Player) => host_entity.unwrap_or(0),
+ None => 0,
+ };
+ let at = |p: horizon_core::geometry::Vec3| [p.x, p.y, p.z];
+ for t in self.tnts.iter().filter(|t| t.id != 0) {
+ let mut e = state(t.id, "minecraft:tnt", at(t.position), 0.0, t.on_ground);
+ e.velocity = at(t.velocity);
+ // PrimedTnt.DATA_FUSE_ID, 80 by default; requiresPrecisePosition
+ // while it touches a block.
+ if t.fuse != 80 {
+ e.meta.push((8, serializer::INT, Value::Int(t.fuse)));
+ }
+ e.precise = t.on_ground;
+ out.push(e);
+ }
+ for f in self.falling.iter().filter(|f| f.id != 0) {
+ let mut e = state(f.id, "minecraft:falling_block", at(f.position), 0.0, false);
+ e.velocity = at(f.velocity);
+ // getAddEntityPacket: the block state; DATA_START_POS.
+ e.data = f.state.0 as i32;
+ if f.no_gravity {
+ e.meta.push((5, serializer::BOOLEAN, Value::Bool(true)));
+ }
+ let start = [f.start_pos.x, f.start_pos.y, f.start_pos.z];
+ if start != [0; 3] {
+ e.meta.push((8, serializer::BLOCK_POS, Value::Pos(start)));
+ }
+ out.push(e);
+ }
+ for p in self.creatures.projectiles.iter().filter(|p| p.id != 0) {
+ use horizon_client::projectiles::ProjectileKind as K;
+ let kind = match &p.kind {
+ K::Arrow { .. } => "minecraft:arrow",
+ K::Snowball => "minecraft:snowball",
+ K::Egg => "minecraft:egg",
+ K::EnderPearl => "minecraft:ender_pearl",
+ K::SmallFireball => "minecraft:small_fireball",
+ K::LargeFireball { .. } => "minecraft:fireball",
+ K::LlamaSpit => "minecraft:llama_spit",
+ K::WindCharge => "minecraft:wind_charge",
+ K::BreezeWindCharge => "minecraft:breeze_wind_charge",
+ K::ShulkerBullet { .. } => "minecraft:shulker_bullet",
+ K::WitherSkull { .. } => "minecraft:wither_skull",
+ K::Potion { .. } => "minecraft:splash_potion",
+ };
+ let mut e = state(p.id, kind, at(p.position), p.yaw, false);
+ e.pitch = p.pitch;
+ e.velocity = at(p.velocity);
+ e.data = owner(p.owner);
+ match &p.kind {
+ K::Arrow { critical, .. } => {
+ let a = p.arrow.as_deref();
+ e.meta.extend(arrow_meta(
+ *critical,
+ a.is_some_and(|a| a.no_physics),
+ a.map_or(0, |a| a.pierce),
+ a.is_some_and(|a| a.in_ground) || p.stuck,
+ ));
+ }
+ // WitherSkull.DATA_DANGEROUS.
+ K::WitherSkull { dangerous: true } => {
+ e.meta.push((8, serializer::BOOLEAN, Value::Bool(true)));
+ }
+ _ => {}
+ }
+ out.push(e);
+ }
+ for t in self.tridents.iter().filter(|t| t.id != 0) {
+ let mut e = state(t.id, "minecraft:trident", at(t.position), t.yaw, false);
+ e.pitch = t.pitch;
+ e.velocity = at(t.velocity);
+ e.meta = arrow_meta(false, t.no_physics, 0, t.in_ground);
+ // ThrownTrident.ID_LOYALTY and ID_FOIL.
+ if t.loyalty != 0 {
+ e.meta
+ .push((11, serializer::BYTE, Value::Byte(t.loyalty as i8)));
+ }
+ if t.stack.has_any_enchantments() {
+ e.meta.push((12, serializer::BOOLEAN, Value::Bool(true)));
+ }
+ out.push(e);
+ }
+ for r in self.rockets.iter().filter(|r| r.id != 0) {
+ let mut e = state(
+ r.id,
+ "minecraft:firework_rocket",
+ at(r.position),
+ 0.0,
+ false,
+ );
+ e.velocity = at(r.velocity);
+ // DATA_ID_FIREWORKS_ITEM once set from a stack, DATA_ATTACHED_TO_TARGET,
+ // DATA_SHOT_AT_ANGLE.
+ let plain = &*r.item.item == "minecraft:firework_rocket"
+ && r.item.count == 1
+ && r.item.extra.is_none();
+ if !plain {
+ e.meta.push((
+ 8,
+ serializer::ITEM_STACK,
+ Value::Item(hub.stack(&Some(r.item.clone()))),
+ ));
+ }
+ if r.attached
+ && let Some(host) = host_entity
+ {
+ e.meta
+ .push((9, serializer::OPTIONAL_UNSIGNED_INT, Value::Id(host + 1)));
+ }
+ if r.angled {
+ e.meta.push((10, serializer::BOOLEAN, Value::Bool(true)));
+ }
+ out.push(e);
+ }
+ for c in self.crystals.iter().filter(|c| c.id != 0) {
+ let mut e = state(c.id, "minecraft:end_crystal", at(c.position), 0.0, false);
+ // EndCrystal.DATA_BEAM_TARGET and DATA_SHOW_BOTTOM (true by default).
+ if c.beam.is_some() {
+ e.meta
+ .push((8, serializer::OPTIONAL_BLOCK_POS, Value::OptPos(c.beam)));
+ }
+ if !c.show_bottom {
+ e.meta.push((9, serializer::BOOLEAN, Value::Bool(false)));
+ }
+ out.push(e);
+ }
+ }
+}
+
+/// `AbstractArrow`'s ID_FLAGS (critical 1, no physics 2), PIERCE_LEVEL and
+/// IN_GROUND, when they differ from the defaults.
+fn arrow_meta(
+ critical: bool,
+ no_physics: bool,
+ pierce: u8,
+ in_ground: bool,
+) -> Vec<(u8, i32, Value)> {
+ let mut meta = Vec::new();
+ let flags = i8::from(critical) | i8::from(no_physics) << 1;
+ if flags != 0 {
+ meta.push((8, serializer::BYTE, Value::Byte(flags)));
+ }
+ if pierce != 0 {
+ meta.push((9, serializer::BYTE, Value::Byte(pierce as i8)));
+ }
+ if in_ground {
+ meta.push((10, serializer::BOOLEAN, Value::Bool(true)));
+ }
+ meta
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn armor_stand_poses_send_only_what_differs() {
+ let tag =
+ horizon_world::nbt::parse_snbt("{Pose:{Head:[10f,20f,0f],LeftArm:[-10f,0f,-10f]}}")
+ .unwrap()
+ .0;
+ let meta = stand_poses(Some(&tag));
+ assert_eq!(
+ meta,
+ vec![(
+ 16,
+ serializer::ROTATIONS,
+ Value::Floats(vec![10.0, 20.0, 0.0])
+ )]
+ );
+ assert!(stand_poses(None).is_empty());
+ }
+}
diff --git a/crates/horizon-client/src/game/lan_mobs.rs b/crates/horizon-client/src/game/lan_mobs.rs
index 7cef7cda6..99888058c 100644
--- a/crates/horizon-client/src/game/lan_mobs.rs
+++ b/crates/horizon-client/src/game/lan_mobs.rs
@@ -92,7 +92,7 @@ impl Game<'_> {
.hub
.guests
.iter()
- .filter(|g| g.placed && g.loaded && !g.dead)
+ .filter(|g| host.hub.here(g) && g.loaded && !g.dead)
.map(|g| {
let moved = [0, 1, 2].map(|k| g.position[k] - g.previous_position[k]);
(g.conn, g.uuid, moved)
@@ -107,6 +107,7 @@ impl Game<'_> {
v.velocity = Vec3::new(moved[0], moved[1], moved[2]);
v.uuid = horizon_client::lan::playerdata::uuid_ints(uuid);
v.allies = Default::default();
+ v.remote = true;
views.push((conn, v));
}
}
@@ -138,7 +139,7 @@ impl Game<'_> {
host.hub
.guests
.iter()
- .filter(|g| g.placed && g.loaded && !g.dead && !g.spectator())
+ .filter(|g| host.hub.here(g) && g.loaded && !g.dead && !g.spectator())
.map(|g| (Who::Mob(g.entity_id as u32), guest_bounds(g)))
.collect()
}
@@ -209,9 +210,12 @@ pub(super) struct Present {
impl Game<'_> {
/// Every guest in the world (`ServerLevel.getPlayers` past the host).
pub(super) fn lan_present(&self) -> Vec {
- let guests = self.lan.iter().flat_map(|h| &h.hub.guests);
+ let guests = self
+ .lan
+ .iter()
+ .flat_map(|h| h.hub.guests.iter().filter(|g| h.hub.here(g)));
guests
- .filter(|g| g.placed && g.loaded)
+ .filter(|g| g.loaded)
.map(|g| {
let [x, y, z] = g.position;
Present {
@@ -271,6 +275,7 @@ mod tests {
hero: false,
uuid: [0; 4],
allies: Default::default(),
+ remote: false,
}
}
diff --git a/crates/horizon-client/src/game/lan_pvp.rs b/crates/horizon-client/src/game/lan_pvp.rs
index bd10241ff..1bdf9146a 100644
--- a/crates/horizon-client/src/game/lan_pvp.rs
+++ b/crates/horizon-client/src/game/lan_pvp.rs
@@ -32,7 +32,7 @@ impl Game<'_> {
host.hub
.guests
.iter()
- .filter(|g| g.placed && g.loaded && !g.dead && !g.spectator())
+ .filter(|g| host.hub.here(g) && g.loaded && !g.dead && !g.spectator())
.filter_map(|g| Some((g.conn, ray_box(eye, dir, reach, guest_bounds(g))?)))
.min_by(|a, b| a.1.total_cmp(&b.1))
}
@@ -64,7 +64,7 @@ impl Game<'_> {
host.hub
.guests
.iter()
- .find(|g| g.entity_id == id && g.conn != conn && g.placed && !g.dead)
+ .find(|g| g.entity_id == id && g.conn != conn && host.hub.here(g) && !g.dead)
.map(|g| Victim::Guest(g.conn))
}
diff --git a/crates/horizon-client/src/game/lan_trading.rs b/crates/horizon-client/src/game/lan_trading.rs
index d6bfc4141..ee6b55d16 100644
--- a/crates/horizon-client/src/game/lan_trading.rs
+++ b/crates/horizon-client/src/game/lan_trading.rs
@@ -372,7 +372,7 @@ impl Game<'_> {
.hub
.guests
.iter()
- .find(|g| g.conn == conn)
+ .find(|g| g.conn == conn && host.hub.here(g))
.map(|g| uuid_words(g.uuid))
else {
continue;
diff --git a/crates/horizon-client/src/game/lan_waypoints.rs b/crates/horizon-client/src/game/lan_waypoints.rs
new file mode 100644
index 000000000..0d0ab69e4
--- /dev/null
+++ b/crates/horizon-client/src/game/lan_waypoints.rs
@@ -0,0 +1,95 @@
+//! The locator bar of the players on a served world (lan/waypoints.rs): what
+//! each player looks like to the waypoint manager this tick.
+use super::{Game, lan::LanHost};
+use horizon_client::{
+ items::ItemStack,
+ lan::{
+ hub::HostState,
+ waypoints::{self, HIDING_HEADS, Icon, PLAYER_RANGE},
+ },
+};
+
+/// `waypoint_transmit_range`: hidden by crouching, invisibility or a head worn.
+fn transmit_range(crouching: bool, invisible: bool, head: Option<&ItemStack>) -> f64 {
+ let hiding_head = head.is_some_and(|s| HIDING_HEADS.contains(&&*s.item));
+ if crouching || invisible || hiding_head {
+ 0.0
+ } else {
+ PLAYER_RANGE
+ }
+}
+
+impl Game<'_> {
+ /// The player's team and its colour, as the locator bar shows it.
+ fn waypoint_team(&self, name: &str) -> Option<(String, Option)> {
+ let team = self.score.board.players_team(name)?;
+ let color = team.color.as_deref().and_then(waypoints::team_rgb);
+ Some((team.name.clone(), color))
+ }
+
+ pub(super) fn lan_update_waypoints(&mut self, host: &mut LanHost, state: Option<&HostState>) {
+ let mut players = Vec::new();
+ if let Some(h) = state {
+ let icon = self
+ .cmds
+ .waypoint_icons
+ .get(&super::commands::Target::Player)
+ .map(|i| Icon {
+ style: i.style.clone(),
+ color: i.color,
+ })
+ .unwrap_or_default();
+ players.push(waypoints::Player {
+ uuid: h.uuid,
+ conn: None,
+ position: h.position,
+ spectator: self.spectator(),
+ transmit_range: transmit_range(
+ h.sneaking,
+ self.potions.effects.get("invisibility").is_some(),
+ h.equipment[5].as_ref(),
+ ),
+ receive_range: PLAYER_RANGE,
+ first_tick: false,
+ view_distance: host.hub.config.view_distance,
+ team: self.waypoint_team(&h.name),
+ icon,
+ });
+ }
+ let mut respawned = Vec::new();
+ for g in host.hub.guests.iter().filter(|g| g.placed) {
+ // PlayerList.respawn makes a new ServerPlayer.
+ if g.dead {
+ host.waypoint_dead.insert(g.uuid);
+ } else if host.waypoint_dead.remove(&g.uuid) {
+ respawned.push(g.uuid);
+ }
+ // Player.updatePlayerPose: the shift key crouches unless flying.
+ let crouching = g.sneaking && !g.flying && !g.fall_flying && !g.sleeping;
+ players.push(waypoints::Player {
+ uuid: g.uuid,
+ conn: Some(g.conn),
+ position: g.position,
+ spectator: g.spectator(),
+ transmit_range: transmit_range(
+ crouching,
+ g.effects.get("invisibility").is_some(),
+ g.armor[0].as_ref(),
+ ),
+ receive_range: PLAYER_RANGE,
+ first_tick: g.ticks == 0,
+ view_distance: g.view_distance,
+ team: self.waypoint_team(&g.name),
+ icon: Icon::default(),
+ });
+ }
+ host.waypoint_dead
+ .retain(|uuid| players.iter().any(|p| p.uuid == *uuid));
+ let locator_bar = self.ui.rules.bool("locator_bar");
+ for (conn, packet) in host.waypoints.tick(&players, &respawned, locator_bar) {
+ if let Some(g) = host.hub.guest(conn) {
+ g.send(&packet);
+ }
+ }
+ }
+}
diff --git a/crates/horizon-client/src/game/levels.rs b/crates/horizon-client/src/game/levels.rs
new file mode 100644
index 000000000..3a84e2f78
--- /dev/null
+++ b/crates/horizon-client/src/game/levels.rs
@@ -0,0 +1,350 @@
+//! A server's levels, one per dimension (`MinecraftServer.levels`).
+//!
+//! The game's tick code reads one level: the one in place, held in `Game`'s
+//! own fields (the world, its streaming and save, block ticks, entities).
+//! A server (the dedicated server and single player's server thread) keeps
+//! the other dimensions' levels here and ticks each one that has players by
+//! swapping it into place (`enter_level`), the way `as_guest` swaps a player
+//! in, so the tick code runs unchanged, one level at a time. The in-frame
+//! game holds one level, which follows its player (`enter_dimension`).
+//!
+//! Shared by every level, as vanilla's derived levels share the
+//! Overworld's level data: the game time, the day time and the weather, the
+//! game rules, the scoreboard, the maps and the entities waiting to arrive
+//! through a portal.
+
+use super::{
+ Dim, ExperienceOrb, FallingBlock, Game, ItemEntity, Mob, boats, commands,
+ creaking::CreakingState, dragon, fireworks, lan::LanHost, lightning, machines, minecarts,
+ ominous_item_spawner, persist, raids::Raiding, sculk::SculkState, tnt, trident,
+};
+use horizon_client::{
+ Result, block_entity_anim::BlockEntityAnims, random_tick_sections::RandomTickSections,
+ save::SaveDir, streaming::Streaming, tick_chunk_membership::TickChunkMembership, world::World,
+};
+use horizon_world::level::{LevelEvent, Ticks};
+use std::{collections::HashMap, sync::Arc};
+
+/// Server ticks a level other than the Overworld stays loaded with no player
+/// in it, before it is saved and closed (vanilla unloads a level's chunks
+/// once no ticket holds them; the Overworld stays loaded).
+const IDLE_TICKS: u32 = 300;
+
+/// A level that is not in place: every per-level field of `Game`.
+pub(super) struct Parked {
+ world: World,
+ streaming: Streaming,
+ save: Arc,
+ block_ticks: Ticks,
+ tick_chunks: TickChunkMembership,
+ random_tick_sections: RandomTickSections,
+ level_events: Vec,
+ falling: Vec,
+ paintings: Vec,
+ item_frames: Vec,
+ armor_stands: Vec,
+ others: Vec,
+ boats: Vec,
+ carts: Vec,
+ jukebox_sounds: HashMap<(i32, i32, i32), u64>,
+ bolts: Vec,
+ crystals: Vec,
+ dragon: Option,
+ dragon_fireballs: Vec,
+ breath_clouds: Vec,
+ tridents: Vec,
+ rockets: Vec,
+ ominous_spawners: Vec,
+ tnts: Vec,
+ hoppers: HashMap<(i32, i32, i32), machines::HopperState>,
+ mobs: Vec,
+ projectiles: Vec,
+ dropped: Vec,
+ orbs: Vec,
+ persist: persist::EntityMemory,
+ lectern_pulses: Vec<((i32, i32, i32), i32)>,
+ lid_openers: HashMap<(i32, i32, i32), i32>,
+ lan_events: Vec<(i32, [i32; 3], i32, Option)>,
+ lan_block_events: Vec<([i32; 3], i32, i32, u32)>,
+ lan_entity_events: Vec<(i32, i8, [f64; 3])>,
+ /// Only the per-level parts of these are used (`swap_level`).
+ anims: BlockEntityAnims,
+ raiding: Raiding,
+ sculk: SculkState,
+ creaking: CreakingState,
+ /// Server ticks since a player was last in the level.
+ idle: u32,
+}
+
+/// Which passes of the server tick the level in place runs: the first
+/// reads the network (`Hub::poll`), the last ends the tick for every player
+/// (`Hub::end_tick`). A tick with one level is both.
+#[derive(Clone, Copy)]
+pub(super) struct Pass {
+ pub first: bool,
+ pub last: bool,
+}
+
+impl Default for Pass {
+ fn default() -> Self {
+ Self {
+ first: true,
+ last: true,
+ }
+ }
+}
+
+/// The levels not in place, by dimension.
+#[derive(Default)]
+pub(super) struct Levels {
+ parked: HashMap,
+}
+
+impl Game<'_> {
+ /// A new level for `dim`, opened from the save (`MinecraftServer.createLevels`).
+ fn open_level(&self, dim: Dim) -> Result {
+ let (streaming, save) =
+ self.make_streaming(&self.world_root.clone(), dim, self.level.seed)?;
+ let mut world = World::new(self.res.facts.air, self.level.seed);
+ world.fast_lava = dim == Dim::Nether;
+ Ok(Parked {
+ world,
+ streaming,
+ save,
+ block_ticks: Ticks::new(self.level.seed as i32),
+ tick_chunks: Default::default(),
+ random_tick_sections: Default::default(),
+ level_events: Vec::new(),
+ falling: Vec::new(),
+ paintings: Vec::new(),
+ item_frames: Vec::new(),
+ armor_stands: Vec::new(),
+ others: Vec::new(),
+ boats: Vec::new(),
+ carts: Vec::new(),
+ jukebox_sounds: HashMap::new(),
+ bolts: Vec::new(),
+ crystals: Vec::new(),
+ dragon: None,
+ dragon_fireballs: Vec::new(),
+ breath_clouds: Vec::new(),
+ tridents: Vec::new(),
+ rockets: Vec::new(),
+ ominous_spawners: Vec::new(),
+ tnts: Vec::new(),
+ hoppers: HashMap::new(),
+ mobs: Vec::new(),
+ projectiles: Vec::new(),
+ dropped: Vec::new(),
+ orbs: Vec::new(),
+ persist: Default::default(),
+ lectern_pulses: Vec::new(),
+ lid_openers: HashMap::new(),
+ lan_events: Vec::new(),
+ lan_block_events: Vec::new(),
+ lan_entity_events: Vec::new(),
+ anims: Default::default(),
+ raiding: Default::default(),
+ sculk: Default::default(),
+ creaking: Default::default(),
+ idle: 0,
+ })
+ }
+
+ /// Exchange the level in place with `p`.
+ fn swap_level(&mut self, p: &mut Parked) {
+ use std::mem::swap;
+ swap(&mut self.world, &mut p.world);
+ swap(&mut self.streaming, &mut p.streaming);
+ swap(&mut self.save, &mut p.save);
+ swap(&mut self.block_ticks, &mut p.block_ticks);
+ swap(&mut self.tick_chunks, &mut p.tick_chunks);
+ swap(&mut self.random_tick_sections, &mut p.random_tick_sections);
+ swap(&mut self.level_events, &mut p.level_events);
+ swap(&mut self.falling, &mut p.falling);
+ swap(&mut self.paintings, &mut p.paintings);
+ swap(&mut self.item_frames, &mut p.item_frames);
+ swap(&mut self.armor_stands, &mut p.armor_stands);
+ swap(&mut self.others, &mut p.others);
+ swap(&mut self.boats, &mut p.boats);
+ swap(&mut self.carts, &mut p.carts);
+ swap(&mut self.jukebox_sounds, &mut p.jukebox_sounds);
+ swap(&mut self.bolts, &mut p.bolts);
+ swap(&mut self.crystals, &mut p.crystals);
+ swap(&mut self.dragon, &mut p.dragon);
+ swap(&mut self.dragon_fireballs, &mut p.dragon_fireballs);
+ swap(&mut self.breath_clouds, &mut p.breath_clouds);
+ swap(&mut self.tridents, &mut p.tridents);
+ swap(&mut self.rockets, &mut p.rockets);
+ swap(&mut self.ominous_spawners, &mut p.ominous_spawners);
+ swap(&mut self.tnts, &mut p.tnts);
+ swap(&mut self.hoppers, &mut p.hoppers);
+ swap(&mut self.mobs, &mut p.mobs);
+ swap(&mut self.creatures.projectiles, &mut p.projectiles);
+ swap(&mut self.dropped, &mut p.dropped);
+ swap(&mut self.orbs, &mut p.orbs);
+ swap(&mut self.persist, &mut p.persist);
+ swap(&mut self.lectern_pulses, &mut p.lectern_pulses);
+ swap(&mut self.lid_openers, &mut p.lid_openers);
+ swap(&mut self.lan_events, &mut p.lan_events);
+ swap(&mut self.lan_block_events, &mut p.lan_block_events);
+ swap(&mut self.lan_entity_events, &mut p.lan_entity_events);
+ let (a, b) = (&mut self.be_anims, &mut p.anims);
+ swap(&mut a.chests, &mut b.chests);
+ swap(&mut a.books, &mut b.books);
+ swap(&mut a.shulkers, &mut b.shulkers);
+ swap(&mut a.bells, &mut b.bells);
+ swap(&mut a.conduits, &mut b.conduits);
+ swap(&mut a.skulls, &mut b.skulls);
+ swap(&mut a.pots, &mut b.pots);
+ swap(&mut a.gateways, &mut b.gateways);
+ swap(&mut a.gateway_servers, &mut b.gateway_servers);
+ self.raiding.swap_level(&mut p.raiding);
+ self.sculk.swap_level(&mut p.sculk);
+ self.creaking.swap_level(&mut p.creaking);
+ // What only the client draws starts over.
+ self.particles.clear();
+ self.pickups.clear();
+ }
+
+ /// Put `target`'s level in place, opening it first if it is not loaded.
+ /// The level that was in place is kept with the others; the shared
+ /// clock and weather go with the swap. `host` is the hub when the caller
+ /// holds it (`self.lan` is taken during the network tick).
+ pub(super) fn enter_level(&mut self, host: Option<&mut LanHost>, target: Dim) -> Result<()> {
+ // The in-frame game keeps its one level (`enter_dimension`).
+ if self.options.dedicated.is_none() {
+ return Ok(());
+ }
+ if target != self.dim {
+ let (mut p, opened) = match self.levels.parked.remove(&target) {
+ Some(p) => (p, false),
+ None => (self.open_level(target)?, true),
+ };
+ p.world.game_time = self.world.game_time;
+ p.world.day_time = self.world.day_time;
+ p.world.weather = self.world.weather;
+ // The sculk tables' watched blocks are built once per game.
+ p.world.watched = std::mem::take(&mut self.world.watched);
+ self.swap_level(&mut p);
+ p.idle = 0;
+ let left = std::mem::replace(&mut self.dim, target);
+ self.levels.parked.insert(left, p);
+ if opened {
+ // The new streaming's radius and meshing options.
+ self.apply_settings();
+ }
+ }
+ let host = match host {
+ Some(h) => Some(h),
+ None => self.lan.as_mut(),
+ };
+ if let Some(h) = host {
+ h.hub.set_dimension(target.id());
+ }
+ Ok(())
+ }
+
+ /// One server tick (`MinecraftServer.tickServer`): each level with
+ /// players in turn (`tickChildren`), its chunks streamed and loaded and
+ /// its world ticked. The first pass reads the network and runs the
+ /// tick's shared parts (the clock, the weather, functions, the autosave);
+ /// the next ones only their level. While `paused`, only the connections
+ /// run.
+ pub(super) fn tick_server(&mut self, paused: bool) -> Result<()> {
+ let dims = self.levels_to_tick();
+ let n = dims.len();
+ let mut result = Ok(());
+ for (k, dim) in dims.into_iter().enumerate() {
+ if let Err(e) = self.enter_level(None, dim) {
+ result = Err(e);
+ break;
+ }
+ self.level_pass = Pass {
+ first: k == 0,
+ last: k + 1 == n,
+ };
+ self.update_dedicated_streaming();
+ self.update_world();
+ result = if paused {
+ self.tick_lan();
+ Ok(())
+ } else if k == 0 {
+ self.tick()
+ } else {
+ let running = self.clock.world_runs();
+ if running {
+ self.tick_weather_effects();
+ }
+ self.tick_world(running)
+ };
+ if result.is_err() {
+ break;
+ }
+ }
+ self.level_pass = Pass::default();
+ result?;
+ self.close_idle_levels()
+ }
+
+ /// The levels this server tick runs, in `MinecraftServer.levels` order
+ /// (the Overworld, the Nether, the End): every level with a player in
+ /// it, or the Overworld while nobody is online.
+ pub(super) fn levels_to_tick(&self) -> Vec {
+ let guests = self
+ .lan
+ .as_ref()
+ .map_or(&[][..], |h| h.hub.guests.as_slice());
+ let mut dims: Vec = [Dim::Overworld, Dim::Nether, Dim::End]
+ .into_iter()
+ .filter(|d| guests.iter().any(|g| g.dimension == d.id()))
+ .collect();
+ if dims.is_empty() {
+ dims.push(Dim::Overworld);
+ }
+ dims
+ }
+
+ /// Count the parked levels' empty ticks, and save and close the ones
+ /// (other than the Overworld) nobody has been in for a while.
+ pub(super) fn close_idle_levels(&mut self) -> Result<()> {
+ let occupied = self.levels_to_tick();
+ let mut closing = Vec::new();
+ for (dim, p) in &mut self.levels.parked {
+ if occupied.contains(dim) {
+ p.idle = 0;
+ continue;
+ }
+ p.idle += 1;
+ if *dim != Dim::Overworld && p.idle >= IDLE_TICKS {
+ closing.push(*dim);
+ }
+ }
+ if closing.is_empty() {
+ return Ok(());
+ }
+ let back = self.dim;
+ for dim in closing {
+ self.enter_level(None, dim)?;
+ self.save_level(true)?;
+ self.enter_level(None, back)?;
+ self.levels.parked.remove(&dim);
+ }
+ Ok(())
+ }
+
+ /// Save every parked level (`MinecraftServer.saveAllChunks`); the level
+ /// in place is the caller's to save.
+ pub(super) fn save_parked_levels(&mut self, wait: bool) -> Result<()> {
+ if self.levels.parked.is_empty() {
+ return Ok(());
+ }
+ let back = self.dim;
+ let dims: Vec = self.levels.parked.keys().copied().collect();
+ for dim in dims {
+ self.enter_level(None, dim)?;
+ self.save_level(wait)?;
+ }
+ self.enter_level(None, back)
+ }
+}
diff --git a/crates/horizon-client/src/game/machines.rs b/crates/horizon-client/src/game/machines.rs
index 0d334d248..d46928060 100644
--- a/crates/horizon-client/src/game/machines.rs
+++ b/crates/horizon-client/src/game/machines.rs
@@ -7,7 +7,7 @@ use super::Game;
mod crafter;
use horizon_client::{
Result,
- containers::BlockEntity,
+ containers::{BlockEntity, HOPPER_SLOTS},
items::{ItemStack, Items},
world::World,
};
@@ -497,36 +497,35 @@ impl Game<'_> {
}
}
}
- /// Every hopper's `pushItemsTick`, in a stable position order.
- pub(super) fn tick_hoppers(&mut self) -> Result<()> {
+ /// `HopperBlockEntity.pushItemsTick` of the hopper at `pos`, if its block
+ /// is still a hopper (`BlockEntityType.isValid`).
+ pub(super) fn tick_hopper(&mut self, pos: Pos) {
let hopper = self
- .pack
- .assets
- .registry
- .default_state("minecraft:hopper")
- .map(|s| self.res.facts.get(s).name.clone());
- let Some(hopper) = hopper else { return Ok(()) };
- let mut positions: Vec = self
- .world
- .block_entities
- .keys()
- .copied()
- .filter(|p| self.res.facts.get(self.world.block(p.0, p.1, p.2)).name == hopper)
- .collect();
- positions.sort_unstable();
- self.hoppers
- .retain(|p, _| positions.binary_search(p).is_ok());
- let time = self.world.game_time;
- for pos in positions {
- let state = self.hoppers.entry(pos).or_default();
- state.cooldown -= 1;
- state.ticked = time;
- if state.cooldown <= 0 {
- state.cooldown = 0;
- self.hopper_try_move_items(pos);
- }
+ .res
+ .facts
+ .get(self.world.block(pos.0, pos.1, pos.2))
+ .name
+ .as_ref()
+ == "minecraft:hopper";
+ if !hopper {
+ self.hoppers.remove(&pos);
+ return;
}
- Ok(())
+ let time = self.world.game_time;
+ let state = self.hoppers.entry(pos).or_default();
+ state.cooldown -= 1;
+ state.ticked = time;
+ if state.cooldown <= 0 {
+ state.cooldown = 0;
+ self.hopper_try_move_items(pos);
+ }
+ }
+ /// Drops the cooldowns of hoppers whose block entity is gone.
+ pub(super) fn forget_gone_hoppers(&mut self) {
+ let entities = &self.world.block_entities;
+ self.hoppers.retain(|p, _| {
+ matches!(entities.get(p), Some(BlockEntity::Chest(items)) if items.len() == HOPPER_SLOTS)
+ });
}
/// `HopperBlockEntity.tryMoveItems` with `suckInItems`.
pub(super) fn hopper_try_move_items(&mut self, pos: Pos) {
diff --git a/crates/horizon-client/src/game/machines/crafter.rs b/crates/horizon-client/src/game/machines/crafter.rs
index 11ca70d5d..5642e5c2a 100644
--- a/crates/horizon-client/src/game/machines/crafter.rs
+++ b/crates/horizon-client/src/game/machines/crafter.rs
@@ -56,44 +56,33 @@ impl Game<'_> {
_ => None,
}
}
- /// `CrafterBlockEntity.serverTick` for every crafter, and the powered
- /// flag following the block state.
- pub(in crate::game) fn tick_crafters(&mut self) {
- let positions: Vec = self
- .world
- .block_entities
- .iter()
- .filter(|(_, e)| matches!(e, BlockEntity::Crafter(_)))
- .map(|(p, _)| *p)
- .collect();
- let mut positions = positions;
- positions.sort_unstable();
- for pos in positions {
- let state = self.world.block(pos.0, pos.1, pos.2);
- let triggered = self.containers().prop(state, "triggered") == Some("true");
- let mut finished = false;
- if let Some(BlockEntity::Crafter(c)) = self.world.block_entities.get_mut(&pos) {
- // CrafterBlock.neighborChanged sets the flag with the state; a
- // loaded crafter keeps its saved flag until then.
- if c.state_triggered.is_some_and(|t| t != triggered) {
- c.triggered = triggered;
- }
- c.state_triggered = Some(triggered);
- let remaining = c.crafting_ticks - 1;
- if remaining >= 0 {
- c.crafting_ticks = remaining;
- finished = remaining == 0;
- }
+ /// `CrafterBlockEntity.serverTick` of the crafter at `pos`, and the
+ /// powered flag following the block state.
+ pub(in crate::game) fn tick_crafter(&mut self, pos: Pos) {
+ let state = self.world.block(pos.0, pos.1, pos.2);
+ let triggered = self.containers().prop(state, "triggered") == Some("true");
+ let mut finished = false;
+ if let Some(BlockEntity::Crafter(c)) = self.world.block_entities.get_mut(&pos) {
+ // CrafterBlock.neighborChanged sets the flag with the state; a
+ // loaded crafter keeps its saved flag until then.
+ if c.state_triggered.is_some_and(|t| t != triggered) {
+ c.triggered = triggered;
}
- if finished {
- self.set_bool_prop(
- pos,
- "crafting",
- false,
- horizon_world::level::flags::UPDATE_ALL,
- );
+ c.state_triggered = Some(triggered);
+ let remaining = c.crafting_ticks - 1;
+ if remaining >= 0 {
+ c.crafting_ticks = remaining;
+ finished = remaining == 0;
}
}
+ if finished {
+ self.set_bool_prop(
+ pos,
+ "crafting",
+ false,
+ horizon_world::level::flags::UPDATE_ALL,
+ );
+ }
}
/// `CrafterBlock.dispenseFrom` (the scheduled tick after a redstone pulse).
pub(super) fn crafter_dispense(&mut self, pos: BlockPos, state: BlockStateId) -> Result<()> {
diff --git a/crates/horizon-client/src/game/minecarts.rs b/crates/horizon-client/src/game/minecarts.rs
index de42c4907..1e0b42b50 100644
--- a/crates/horizon-client/src/game/minecarts.rs
+++ b/crates/horizon-client/src/game/minecarts.rs
@@ -17,7 +17,6 @@ use horizon_client::{
};
use horizon_core::{
geometry::{Aabb, Vec3},
- position::BlockPos,
random::RandomSource,
};
use horizon_world::registry::BlockStateId;
@@ -91,6 +90,10 @@ pub(super) struct Minecart {
}
const WIDTH: f64 = 0.98;
const HEIGHT: f64 = 0.7;
+/// AbstractMinecart.getDefaultDisplayOffset, in sixteenths of a block.
+fn display_offset(kind: CartKind) -> f64 {
+ if kind == CartKind::Hopper { 1.0 } else { 6.0 }
+}
/// The minecart's passenger attachment minus Player.DEFAULT_VEHICLE_ATTACHMENT.
const SEAT: f64 = 0.1875 - 0.6;
/// The placeholder container key under which an open cart's items live.
@@ -154,6 +157,10 @@ pub(super) struct Rail {
powered: bool,
}
impl Minecart {
+ /// `Entity.onGround`.
+ pub(super) fn on_ground(&self) -> bool {
+ self.on_ground
+ }
pub fn new(id: u32, kind: CartKind, position: Vec3) -> Self {
Self {
id,
@@ -1139,16 +1146,17 @@ impl Game<'_> {
}
}
}
- /// A block model's faces under `m` (block space 0..1), lit flat.
+ /// Baked block faces with terrain shade or block-item diffuse lighting.
pub(super) fn block_model_vertices(
&self,
state: BlockStateId,
- seed_pos: BlockPos,
+ seed: i64,
m: glam::Mat4,
light: u32,
+ diffuse: bool,
out: &mut Vec,
) {
- let Ok(models) = self.pack.assets.model_catalog.collect(state, seed_pos) else {
+ let Ok(models) = self.pack.assets.model_catalog.collect_seeded(state, seed) else {
return;
};
for (_, model) in &models {
@@ -1168,12 +1176,30 @@ impl Game<'_> {
D::North | D::South => 204,
D::West | D::East => 153,
};
- let color = 0xFF00_0000 | shade << 16 | shade << 8 | shade;
+ let color = if diffuse {
+ u32::MAX
+ } else {
+ 0xFF00_0000 | shade << 16 | shade << 8 | shade
+ };
+ let normal = if diffuse {
+ use horizon_client::item_render::{direction_vector, transform_normal};
+ let n = transform_normal(m, direction_vector(face.quad.facing));
+ let n = n.to_array().map(|v| (v.clamp(-1.0, 1.0) * 127.0) as i8);
+ [n[0], n[1], n[2], 127]
+ } else {
+ [0; 4]
+ };
+ let light = if diffuse {
+ let emission = u32::from(face.quad.light_emission) * 16;
+ (light & 0xFF) | (light >> 8 & 0xFF).max(emission) << 8
+ } else {
+ light
+ };
for k in 0..4 {
let p = face.quad.positions[k];
let uv = face.quad.uv[k];
out.push(Vertex {
- normal: [0; 4],
+ normal,
pos: m.transform_point3(glam::Vec3::from_array(p)).to_array(),
uv: [s.u0 + uv[0] * (s.u1 - s.u0), s.v0 + uv[1] * (s.v1 - s.v0)],
layer: 0,
@@ -1212,24 +1238,52 @@ impl Game<'_> {
/// front and back points, pitched on slopes, with the display block.
pub(super) fn cart_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec) {
let a = alpha as f32;
+ let Some(uv) = self
+ .atlas
+ .sprites
+ .get("entity/minecart/minecart")
+ .map(|r| [r.u0, r.v0, r.u1, r.v1])
+ else {
+ return;
+ };
+ // Entity.shouldRenderAtSqrDistance: 64 times the bounding box's mean
+ // edge, scaled by the entity distance option.
+ let range =
+ (WIDTH + HEIGHT + WIDTH) / 3.0 * 64.0 * f64::from(self.settings.entity_distance);
for c in &self.carts {
let entity_start = out.len();
let Some(model) = self.cart_models.models.get(&c.kind) else {
continue;
};
- let Some(uv) = self
- .atlas
- .sprites
- .get("entity/minecart/minecart")
- .map(|r| [r.u0, r.v0, r.u1, r.v1])
- else {
- continue;
- };
let (x, y, z) = (
c.previous.x + (c.position.x - c.previous.x) * alpha,
c.previous.y + (c.position.y - c.previous.y) * alpha,
c.previous.z + (c.position.z - c.previous.z) * alpha,
);
+ // LevelExtractor.isEntityVisible: the cart the player rides always draws.
+ if self.riding != Some(c.id) {
+ let d = glam::DVec3::new(c.position.x, c.position.y, c.position.z) - camera;
+ if d.length_squared() >= range * range {
+ continue;
+ }
+ // EntityRenderer.shouldRender: the interpolated box grown by 0.5;
+ // AbstractMinecartRenderer.getBoundingBoxForCulling stretches it
+ // up by the display block's offset.
+ if let Some(view) = &self.view_frustum {
+ let top = HEIGHT
+ + if c.kind == CartKind::Rideable {
+ 0.0
+ } else {
+ display_offset(c.kind) * 0.75 / 16.0
+ };
+ let p = glam::DVec3::new(x, y, z) - camera;
+ let lo = p - glam::DVec3::new(WIDTH / 2.0 + 0.5, 0.5, WIDTH / 2.0 + 0.5);
+ let hi = p + glam::DVec3::new(WIDTH / 2.0 + 0.5, top + 0.5, WIDTH / 2.0 + 0.5);
+ if !view.intersects(lo.as_vec3(), hi.as_vec3()) {
+ continue;
+ }
+ }
+ }
let mut yaw =
c.previous_yaw + ((c.yaw - c.previous_yaw + 180.0).rem_euclid(360.0) - 180.0) * a;
let mut pitch = 0.0f32;
@@ -1274,7 +1328,11 @@ impl Game<'_> {
if let Some(state) = self.display_state(c) {
let display = base
* glam::Mat4::from_scale(glam::Vec3::splat(0.75))
- * glam::Mat4::from_translation(glam::Vec3::new(-0.5, (6.0 - 8.0) / 16.0, 0.5))
+ * glam::Mat4::from_translation(glam::Vec3::new(
+ -0.5,
+ (display_offset(c.kind) as f32 - 8.0) / 16.0,
+ 0.5,
+ ))
* glam::Mat4::from_rotation_y(90f32.to_radians());
if c.kind == CartKind::Chest {
self.cart_chest(state, display, l, out);
@@ -1297,7 +1355,7 @@ impl Game<'_> {
* glam::Mat4::from_translation(glam::Vec3::splat(-0.5));
let flash = c.kind == CartKind::Tnt && c.fuse > -1 && (c.fuse / 5) % 2 == 0;
let start = out.len();
- self.block_model_vertices(state, BlockPos::default(), m, packed, out);
+ self.block_model_vertices(state, 0, m, packed, false, out);
if flash {
// submitWhiteSolidBlock: OverlayTexture.u(1.0) on the cart's own light.
for v in &mut out[start..] {
@@ -1410,3 +1468,18 @@ impl Minecart {
Some(c)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn display_offset_matches_vanilla_for_each_cart_kind() {
+ assert_eq!(display_offset(CartKind::Hopper), 1.0);
+ assert_eq!(display_offset(CartKind::Chest), 6.0);
+ assert_eq!(display_offset(CartKind::Furnace), 6.0);
+ assert_eq!(display_offset(CartKind::Tnt), 6.0);
+ assert_eq!(display_offset(CartKind::CommandBlock), 6.0);
+ assert_eq!(display_offset(CartKind::Rideable), 6.0);
+ }
+}
diff --git a/crates/horizon-client/src/game/mob_blocks.rs b/crates/horizon-client/src/game/mob_blocks.rs
index c2246cf5b..8b2b2da40 100644
--- a/crates/horizon-client/src/game/mob_blocks.rs
+++ b/crates/horizon-client/src/game/mob_blocks.rs
@@ -257,20 +257,36 @@ impl Game<'_> {
out: &mut Vec,
) {
// ItemInHandLayer submits with OverlayTexture.NO_OVERLAY: no hurt tint.
- for (item, left) in [(&mob.extra.main_hand, false), (&mob.extra.off_hand, true)] {
+ for (item, off_hand) in [(&mob.extra.main_hand, false), (&mob.extra.off_hand, true)] {
let Some(item) = item else { continue };
+ let left = off_hand != mob.extra.main_hand_left;
let Some(t) =
render::held_item_transform(mob, alpha as f32, camera, &self.res.mob_data, left)
else {
continue;
};
- let slot = if left {
+ let slot = if off_hand {
horizon_client::mobs::gear::OFF
} else {
horizon_client::mobs::gear::MAIN
};
- let mut stack = ItemStack::new(item, 1);
- if horizon_client::mobs::gear::enchanted(mob, slot) {
+ let local_player = self
+ .player_model
+ .as_ref()
+ .is_some_and(|p| p.id == mob.id && p.kind.id == mob.kind.id);
+ let mut stack = if local_player {
+ let Some(stack) = self.stack_in(if off_hand {
+ super::shield::OFFHAND_SLOT
+ } else {
+ self.selected
+ }) else {
+ continue;
+ };
+ stack.clone()
+ } else {
+ ItemStack::new(item, 1)
+ };
+ if !local_player && horizon_client::mobs::gear::enchanted(mob, slot) {
// The gear's enchantments are not tracked, only that it has some.
stack.enchant("minecraft:unbreaking", 1);
}
@@ -284,12 +300,13 @@ impl Game<'_> {
);
// The local player's rod while its hook is out.
owner.fishing_cast_with_this_item = self.cast_rod().is_some()
- && self.main_hand_rod() != left
+ && self.main_hand_rod() != off_hand
&& self
.player_model
.as_ref()
.is_some_and(|p| std::ptr::eq(p, mob));
- if !left && mob.extra.using_item > 0 {
+ owner.main_arm_left = mob.extra.main_hand_left;
+ if off_hand == mob.extra.using_off_hand && mob.extra.using_item > 0 {
owner.using_this_item = true;
owner.use_duration = 72_000;
owner.use_item_remaining_ticks = 72_000 - mob.extra.using_item;
diff --git a/crates/horizon-client/src/game/natural_spawning.rs b/crates/horizon-client/src/game/natural_spawning.rs
index 571bbf5e0..80d26a823 100644
--- a/crates/horizon-client/src/game/natural_spawning.rs
+++ b/crates/horizon-client/src/game/natural_spawning.rs
@@ -206,7 +206,7 @@ impl NaturalLevel for GameLevel<'_, '_> {
.chunks
.get(&(x >> 4, z >> 4))
.and_then(|chunk| {
- chunk.highest(world.air.0 as u16, |y| {
+ chunk.highest(world.air.0, |y| {
spawn_selection::heightmap_blocks(self, kind, x, y, z)
})
})
diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs
index ed0dccb06..d625f938b 100644
--- a/crates/horizon-client/src/game/options.rs
+++ b/crates/horizon-client/src/game/options.rs
@@ -225,6 +225,11 @@ impl Game<'_> {
let _ = std::fs::create_dir_all(&dir);
super::packs::open_folder(&dir);
}
+ Event::OpenModFolder => {
+ let dir = Self::options_path().with_file_name(horizon_client::mod_list::DIR);
+ let _ = std::fs::create_dir_all(&dir);
+ super::packs::open_folder(&dir);
+ }
}
}
Ok(())
diff --git a/crates/horizon-client/src/game/pad.rs b/crates/horizon-client/src/game/pad.rs
index 62d481b11..0c988c3b7 100644
--- a/crates/horizon-client/src/game/pad.rs
+++ b/crates/horizon-client/src/game/pad.rs
@@ -365,13 +365,6 @@ impl Game<'_> {
self.close_book();
return Ok(());
}
- if let Some(remote) = self.remote.as_mut()
- && remote.chat_input.is_some()
- {
- remote.chat_input = None;
- self.capture(true);
- return Ok(());
- }
self.key_pressed(KeyCode::Escape)
}
diff --git a/crates/horizon-client/src/game/pad_menu.rs b/crates/horizon-client/src/game/pad_menu.rs
index 8f34d2b3a..5c623202b 100644
--- a/crates/horizon-client/src/game/pad_menu.rs
+++ b/crates/horizon-client/src/game/pad_menu.rs
@@ -31,7 +31,7 @@ use winit::{
dpi::PhysicalPosition,
event::{DeviceId, ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent},
event_loop::ActiveEventLoop,
- keyboard::{KeyCode, NamedKey},
+ keyboard::KeyCode,
};
/// D-pad auto-repeat: the first step at once, the next after a pause.
@@ -859,7 +859,6 @@ impl Game<'_> {
|| (self.screen == Screen::Creative && self.creative_screen.tab().search)
|| self.recipe_search_focused()
|| self.station_typing()
- || self.remote_chat_open()
}
/// Open the on-screen keyboard over the focused field: Horizon's, or
@@ -890,7 +889,7 @@ impl Game<'_> {
&& self.pad.in_use
&& menu.open_polls >= 3
&& self.pad_focus_mode()
- && (self.screen == Screen::Chat || self.sign_edit.is_some() || self.remote_chat_open())
+ && (self.screen == Screen::Chat || self.sign_edit.is_some())
{
self.pad.menu.osk_dismissed = true;
self.pad_open_keyboard();
@@ -901,10 +900,10 @@ impl Game<'_> {
/// the field that has focus.
fn pad_osk_output(&mut self, out: osk::Output) {
use osk::Output;
- let (key, named, text) = match &out {
- Output::Text(t) => (None, None, Some(t.as_str())),
- Output::Backspace => (Some(KeyCode::Backspace), Some(NamedKey::Backspace), None),
- Output::Enter => (Some(KeyCode::Enter), Some(NamedKey::Enter), None),
+ let (key, text) = match &out {
+ Output::Text(t) => (None, Some(t.as_str())),
+ Output::Backspace => (Some(KeyCode::Backspace), None),
+ Output::Enter => (Some(KeyCode::Enter), None),
Output::Close => {
self.pad.menu.osk = None;
self.pad.menu.osk_dismissed = true;
@@ -933,8 +932,6 @@ impl Game<'_> {
if key != Some(KeyCode::Enter) {
self.station_text(text, backspace);
}
- } else if self.remote_chat_open() {
- self.remote_chat_input(named, text);
} else if self.screen == Screen::WorldOptions {
if key != Some(KeyCode::Enter) {
self.world_options_text(text);
@@ -985,8 +982,7 @@ impl Game<'_> {
.menu
.focus
.is_some_and(|f| f.center().1 > batch.height / 2.0)
- || self.screen == Screen::Chat
- || self.remote_chat_open();
+ || self.screen == Screen::Chat;
let mut ui = horizon_client::ui_theme::Ui::new(&self.atlas, batch, self.cursor);
keyboard.draw(&mut ui, at_top, self.ui.options.pad_style);
ui.finish();
diff --git a/crates/horizon-client/src/game/paintings.rs b/crates/horizon-client/src/game/paintings.rs
index 2e5542ccc..c65dbbb89 100644
--- a/crates/horizon-client/src/game/paintings.rs
+++ b/crates/horizon-client/src/game/paintings.rs
@@ -255,6 +255,15 @@ impl Game<'_> {
};
for p in &self.paintings {
let entity_start = out.len();
+ // EntityRenderer.shouldRender: the default range and its box,
+ // measured from the box's centre (HangingEntity's position).
+ let (lo, hi) = p.bounds();
+ let (lo, hi) = (glam::DVec3::from(lo), glam::DVec3::from(hi));
+ let range =
+ super::entity_culling::default_range(hi - lo, self.settings.entity_distance);
+ if !self.entity_in_view(camera, (lo + hi) / 2.0, range, lo, hi) {
+ continue;
+ }
let Some(v) = self.painting_variants.get(&p.variant) else {
continue;
};
diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rs
index 96d879f13..53651dc6c 100644
--- a/crates/horizon-client/src/game/persist.rs
+++ b/crates/horizon-client/src/game/persist.rs
@@ -176,7 +176,13 @@ impl Game<'_> {
self.dropped.push(e);
}
}
- "minecraft:experience_orb" => self.orbs.extend(entity_nbt::orbs_from_nbt(&tag)),
+ "minecraft:experience_orb" => {
+ for mut orb in entity_nbt::orbs_from_nbt(&tag) {
+ self.next_entity += 1;
+ orb.id = self.next_entity;
+ self.orbs.push(orb);
+ }
+ }
"minecraft:arrow" => {
if let Some((mut p, in_block)) = entity_nbt::arrow_from_nbt(
&tag,
@@ -196,6 +202,7 @@ impl Game<'_> {
{
let (no_gravity, drop_item) = entity_nbt::falling_block_flags(&tag);
self.falling.push(FallingBlock {
+ id: 0,
state,
// DATA_START_POS is not persisted by vanilla.
start_pos: horizon_core::position::BlockPos::default(),
@@ -214,6 +221,23 @@ impl Game<'_> {
});
}
}
+ // PrimedTnt.readAdditionalSaveData: its fuse (80 when absent) and motion.
+ "minecraft:tnt" => {
+ if let Some(position) = entity_nbt::position(&tag) {
+ let fuse = match tag.get("fuse") {
+ Some(Tag::Short(f)) => i32::from(*f),
+ _ => 80,
+ };
+ self.tnts.push(super::tnt::PrimedTnt {
+ id: 0,
+ position,
+ previous: position,
+ velocity: entity_nbt::motion(&tag),
+ fuse,
+ on_ground: matches!(tag.get("OnGround"), Some(Tag::Byte(1))),
+ });
+ }
+ }
k if super::boats::any_boat_wood(k)
.is_some_and(|(wood, chest)| self.boat_models.has(wood, chest)) =>
{
diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs
index bb463547f..4214bdd70 100644
--- a/crates/horizon-client/src/game/perspective.rs
+++ b/crates/horizon-client/src/game/perspective.rs
@@ -201,7 +201,7 @@ impl Game<'_> {
)
};
let p = self.player.as_ref()?;
- let sleeping = self.sleeping.map(|(head, _)| {
+ let sleeping = self.sleeping.map(|head| {
let state = self.world.block(head[0], head[1], head[2]);
let props = self
.pack
@@ -305,6 +305,13 @@ impl Game<'_> {
let (position, flying) = (p.position, p.flying || p.fall_flying);
let (fall_flying, fly_ticks, velocity) = (p.fall_flying, p.fall_fly_ticks, p.velocity);
let using = self.using.map(|(_, ticks)| ticks as i32 + 1).unwrap_or(0);
+ let using_off_hand = self
+ .using
+ .is_some_and(|(slot, _)| slot == super::shield::OFFHAND_SLOT);
+ let blocking = self
+ .using
+ .and_then(|(slot, _)| self.stack_in(slot))
+ .is_some_and(|stack| self.blocks_attacks(stack).is_some());
let charged = self.inventory[self.selected]
.as_ref()
.is_some_and(|s| s.data().is_some_and(|d| !d.charged.is_empty()));
@@ -313,13 +320,22 @@ impl Game<'_> {
.map_or(25, |s| Self::charge_ticks(s).max(1)) as i32;
let attack = (self.swing.old_animation, self.swing.animation);
let swinging = self.swing.swinging();
+ // currentSwing.hand().asArm(mainArm).
+ let swing_right_arm = swinging.then(|| {
+ (self.swing.attack_hand() == horizon_client::first_person::Hand::Main)
+ != self.settings.main_hand_left
+ });
+ // LivingEntity.isVisuallySwimming and Entity.isInWater.
+ let visually_swimming =
+ p.pose == Pose::Swimming || (!p.fall_flying && p.pose == Pose::FallFlying);
+ let in_water = p.fluids.was_touching_water;
let (yaw, pitch) = (self.yaw, self.pitch);
let main = self.inventory[self.selected]
.as_ref()
.map(|s| s.item.clone());
let off = self.offhand.as_ref().map(|s| s.item.clone());
let riding = self.riding.is_some();
- let hurt = p.health.hurt.hurt_time;
+ let hurt = p.health.hurt_animation_time;
let Some(m) = self.player_model.as_mut() else {
return;
};
@@ -375,9 +391,13 @@ impl Game<'_> {
m.extra.fall_fly_ticks = fly_ticks;
m.extra.main_hand_left = self.settings.main_hand_left;
m.extra.using_item = using;
+ m.extra.using_off_hand = using_off_hand;
+ m.extra.blocking = blocking;
m.extra.charged = charged;
m.extra.ints[5] = charge_duration;
m.extra.elytra.tick(fall_flying, crouching, velocity);
+ m.extra.swim.tick(visually_swimming, in_water);
+ m.extra.swing_right_arm = swing_right_arm;
m.hurt_time = hurt;
}
/// Whether the player's own model shows in the world view.
diff --git a/crates/horizon-client/src/game/pickups.rs b/crates/horizon-client/src/game/pickups.rs
index 2729dc98f..1e19bcfc3 100644
--- a/crates/horizon-client/src/game/pickups.rs
+++ b/crates/horizon-client/src/game/pickups.rs
@@ -148,6 +148,7 @@ mod tests {
fn orb_at(x: f64, y: f64, z: f64) -> Taken {
let at = horizon_core::geometry::Vec3::new(x, y, z);
Taken::Orb(Box::new(ExperienceOrb {
+ id: 0,
position: at,
previous: at,
velocity: horizon_core::geometry::Vec3::new(0.0, 0.0, 0.0),
diff --git a/crates/horizon-client/src/game/potions.rs b/crates/horizon-client/src/game/potions.rs
index a60926256..bc4f3b6bc 100644
--- a/crates/horizon-client/src/game/potions.rs
+++ b/crates/horizon-client/src/game/potions.rs
@@ -228,7 +228,7 @@ impl Game<'_> {
}
let (lasting, now) = PlayerEffects::potion_effects(stack.potion(), 1.0);
for e in lasting {
- self.potions.effects.add(e);
+ self.add_player_effect(e);
}
for a in now {
self.apply_effect_action(a);
@@ -249,7 +249,7 @@ impl Game<'_> {
}
true
}
- fn apply_effect_action(&mut self, action: EffectAction) {
+ pub(super) fn apply_effect_action(&mut self, action: EffectAction) {
let creative = self.creative;
let rules = self.world.health_rules;
let Some(p) = self.player.as_mut() else {
@@ -329,9 +329,24 @@ impl Game<'_> {
}
self.apply_effect_status();
}
+ /// Add an active effect to the player and update attributes / absorption.
+ pub(super) fn add_player_effect(&mut self, effect: EffectInstance) -> bool {
+ let id = effect.id;
+ let amp = effect.amplifier;
+ let changed = self.potions.effects.add(effect);
+ self.apply_effect_status();
+ if id == "absorption"
+ && let Some(p) = self.player.as_mut()
+ {
+ let target = 4.0 * (amp + 1) as f32;
+ let current = p.health.absorption();
+ let _ = p.set_health(current.max(target), true);
+ }
+ changed
+ }
/// The effects' attribute modifiers, armor protection and status flags
/// on `self.player`.
- fn apply_effect_status(&mut self) {
+ pub(super) fn apply_effect_status(&mut self) {
let modifiers = self.potions.effects.modifiers();
if modifiers != self.potions.applied
&& let Some(p) = self.player.as_mut()
@@ -344,6 +359,12 @@ impl Game<'_> {
}
self.potions.applied = modifiers;
}
+ if let Some(p) = self.player.as_mut()
+ && self.potions.effects.amplifier("absorption").is_none()
+ && p.health.absorption() > 0.0
+ {
+ let _ = p.set_health(0.0, true);
+ }
// EnchantmentHelper.getDamageProtection per damage type, recomputed on armor change.
let armor: Vec> = self.armor.to_vec();
if self.potions.protection_for.as_ref() != Some(&armor) {
@@ -467,6 +488,41 @@ impl Game<'_> {
self.splash(&stack, at);
}
}
+ /// A splash potion's effects on the player in place, by their distance.
+ fn splash_on_player(
+ &mut self,
+ effects: &'static [(&'static str, i32, i32)],
+ at: Vec3,
+ scale: f64,
+ ) {
+ if let Some(p) = self.player.as_ref() {
+ let center = Vec3::new(
+ p.position.x,
+ p.position.y + f64::from(p.dimensions.height) / 2.0,
+ p.position.z,
+ );
+ let d2 =
+ (center.x - at.x).powi(2) + (center.y - at.y).powi(2) + (center.z - at.z).powi(2);
+ if d2 < 16.0 && (center.y - at.y).abs() <= 2.0 + f64::from(p.dimensions.height) {
+ let intensity = 1.0 - d2.sqrt() / 4.0;
+ for (id, duration, amp) in effects {
+ let instant = brewing::effect(id).is_some_and(|e| e.instant);
+ if instant {
+ if let Some(a) = horizon_client::effects::instant(id, *amp, intensity) {
+ self.apply_effect_action(a);
+ }
+ } else {
+ let d = (intensity * f64::from(*duration) * scale + 0.5) as i32;
+ if d > 20
+ && let Some(e) = brewing::effect(id)
+ {
+ self.add_player_effect(EffectInstance::new(e.id, d, *amp));
+ }
+ }
+ }
+ }
+ }
+ }
/// `ThrownSplashPotion.onHitAsPotion` (lingering clouds apply as a weaker splash).
fn splash(&mut self, stack: &ItemStack, at: Vec3) {
if &*stack.item == "minecraft:experience_bottle" {
@@ -527,34 +583,9 @@ impl Game<'_> {
let Some(def) = stack.potion().and_then(brewing::potion) else {
return;
};
- // The player.
- if let Some(p) = self.player.as_ref() {
- let center = Vec3::new(
- p.position.x,
- p.position.y + f64::from(p.dimensions.height) / 2.0,
- p.position.z,
- );
- let d2 =
- (center.x - at.x).powi(2) + (center.y - at.y).powi(2) + (center.z - at.z).powi(2);
- if d2 < 16.0 && (center.y - at.y).abs() <= 2.0 + f64::from(p.dimensions.height) {
- let intensity = 1.0 - d2.sqrt() / 4.0;
- for (id, duration, amp) in def.effects {
- let instant = brewing::effect(id).is_some_and(|e| e.instant);
- if instant {
- if let Some(a) = horizon_client::effects::instant(id, *amp, intensity) {
- self.apply_effect_action(a);
- }
- } else {
- let d = (intensity * f64::from(*duration) * scale + 0.5) as i32;
- if d > 20
- && let Some(e) = brewing::effect(id)
- {
- self.potions.effects.add(EffectInstance::new(e.id, d, *amp));
- }
- }
- }
- }
- }
+ // Every player in range (`ThrownSplashPotion.applySplash` over
+ // `LivingEntity`s, the players among them).
+ self.for_each_player(|g| g.splash_on_player(def.effects, at, scale));
// Mobs take the instant effects (undead invert healing and harming).
let undead = &self.res.stations.enchantments.entity_tags;
let mut hits = Vec::new();
diff --git a/crates/horizon-client/src/game/raids.rs b/crates/horizon-client/src/game/raids.rs
index 63f45c1c5..25a440af3 100644
--- a/crates/horizon-client/src/game/raids.rs
+++ b/crates/horizon-client/src/game/raids.rs
@@ -39,6 +39,17 @@ pub(super) struct Raiding {
homes: HashMap>)>,
}
+impl Raiding {
+ /// Exchange the level-held parts (`ServerLevel.getRaids`) with another
+ /// level's (game/levels.rs).
+ pub(super) fn swap_level(&mut self, other: &mut Self) {
+ std::mem::swap(&mut self.raids, &mut other.raids);
+ std::mem::swap(&mut self.loaded, &mut other.loaded);
+ std::mem::swap(&mut self.bar_hurts, &mut other.bar_hurts);
+ std::mem::swap(&mut self.homes, &mut other.homes);
+ }
+}
+
/// `SectionPos` of a block position.
pub(super) fn section(p: [i32; 3]) -> (i32, i32, i32) {
(p[0] >> 4, p[1] >> 4, p[2] >> 4)
@@ -613,17 +624,17 @@ impl Game<'_> {
raider::state_mut(m).ticks_outside_raid = ticks;
}
}
- Action::Victory { heroes, amplifier } => {
- let me = self.level.player_uuid;
- if me.is_some_and(|u| heroes.contains(&u)) && !self.spectator() {
+ // Raid.tick on a victory: each hero who is still alive.
+ Action::Victory { heroes, amplifier } => self.for_each_player(|g| {
+ if heroes.contains(&g.acting_uuid()) && !g.spectator() {
let mut effect =
EffectInstance::new("hero_of_the_village", raid::HERO_DURATION, amplifier);
effect.visible = false;
- self.potions.effects.add(effect);
- self.stats.custom("raid_win", 1);
- self.trigger_player("minecraft:hero_of_the_village");
+ g.potions.effects.add(effect);
+ g.stats.custom("raid_win", 1);
+ g.trigger_player("minecraft:hero_of_the_village");
}
- }
+ }),
}
}
/// `Raid.playSound`: the horn, 13 blocks away from the player toward the
diff --git a/crates/horizon-client/src/game/recipe_book.rs b/crates/horizon-client/src/game/recipe_book.rs
index 67fc46b68..706c8d73e 100644
--- a/crates/horizon-client/src/game/recipe_book.rs
+++ b/crates/horizon-client/src/game/recipe_book.rs
@@ -110,7 +110,7 @@ fn sprite(name: &str) -> String {
impl Game<'_> {
/// The book the open screen has, if any.
fn active_book(&self) -> Option {
- if self.screen != Screen::Inventory || self.remote.is_some() || self.station.is_some() {
+ if self.screen != Screen::Inventory || self.station.is_some() {
return None;
}
if self.mount_active() {
@@ -262,6 +262,33 @@ impl Game<'_> {
/// The items the book counts (`RecipeBookComponent.updateStackedContents`):
/// the inventory and the menu's crafting slots, as the menu engine counts them.
fn book_available(&mut self, _book: BookType) -> Stacked {
+ if self.remote.is_some() {
+ // A server's menu: the slots it last sent, counted the same way.
+ use horizon_client::menu::{Env, Kind, Menu};
+ let table = self.craft_size == 3;
+ let grid: Vec<_> = (0..self.craft_size * self.craft_size)
+ .map(|k| self.slot_mut(100 + k).clone())
+ .collect();
+ let mut menu = Menu::new(if table {
+ Kind::Crafting
+ } else {
+ Kind::Inventory
+ });
+ let env = Env {
+ items: &self.res.items,
+ recipes: &self.res.recipes,
+ brewing: &self.res.stations.brewing,
+ banners: &self.res.stations.banners,
+ trade: None,
+ };
+ for i in 0..36 {
+ menu.set_player_item(i, self.inventory[i].clone());
+ }
+ for (k, stack) in grid.into_iter().enumerate() {
+ menu.set_slot(&env, 1 + k, stack);
+ }
+ return menu.stacked_contents(&env);
+ }
let mut out = Stacked::default();
let stock = &mut out;
self.menu_session(|menu, env, _| {
@@ -274,6 +301,10 @@ impl Game<'_> {
/// replacing batch (vanilla's server iterates an identity hash set; this
/// one goes in id order), then each unlock and removal.
fn sync_client_book(&mut self) {
+ // On a server the book is the server's packets' (remote_recipe_book_*).
+ if self.remote.is_some() {
+ return;
+ }
let known = &self.level.recipe_book.recipes;
let index = &self.res.stations.recipe_index;
let ui = &mut self.recipe_ui;
@@ -660,6 +691,10 @@ impl Game<'_> {
}
false
}
+ /// How many displays the client's book holds.
+ pub(super) fn recipe_book_known(&self) -> usize {
+ self.recipe_ui.client.displays().len()
+ }
/// The recipe book's buttons a controller can focus: the book button,
/// recipes, page arrows, the craftable filter and the tabs (GUI pixels;
/// the search box registers itself as a field).
@@ -800,6 +835,18 @@ impl Game<'_> {
else {
return;
};
+ if self.remote.is_some() {
+ // The server places it and answers with the slots, or a ghost.
+ let container = self.remote_menu_id();
+ self.send(horizon_protocol::packets::play::Serverbound::PlaceRecipe(
+ horizon_protocol::packets::recipes::PlaceRecipe {
+ container,
+ recipe: entry.display_id,
+ use_max,
+ },
+ ));
+ return;
+ }
let creative = self.creative;
let mut post = None;
let answer = &mut post;
@@ -828,6 +875,80 @@ impl Game<'_> {
}
}
+ // ---- a server's recipe book ----
+
+ /// ClientboundRecipeBookAddPacket (`ClientRecipeBook.add`): the
+ /// displays join the book, highlighted when new, and the recipes whose
+ /// entries ask for it show the toast.
+ pub(super) fn remote_recipe_book_add(
+ &mut self,
+ p: horizon_protocol::packets::recipes::RecipeBookAdd,
+ ) {
+ let ui = &mut self.recipe_ui;
+ if p.replace {
+ ui.client.clear();
+ }
+ let mut toast = Vec::new();
+ for e in &p.entries {
+ ui.client.add(e.id);
+ if e.flags & 2 != 0 {
+ ui.client.highlight.insert(e.id);
+ }
+ if e.flags & 1 != 0
+ && let Some(id) = self.res.stations.recipe_index.recipe_of_display(e.id)
+ && !toast.iter().any(|t| t == id)
+ {
+ toast.push(id.to_owned());
+ }
+ }
+ // A local world opened later syncs its book from scratch.
+ ui.client_known = None;
+ ui.client_version += 1;
+ self.recipe_toast(&toast);
+ }
+ /// ClientboundRecipeBookRemovePacket.
+ pub(super) fn remote_recipe_book_remove(
+ &mut self,
+ p: horizon_protocol::packets::recipes::RecipeBookRemove,
+ ) {
+ for id in p.ids {
+ self.recipe_ui.client.remove(id);
+ }
+ self.recipe_ui.client_version += 1;
+ }
+ /// ClientboundRecipeBookSettingsPacket: each book's open and filter flags.
+ pub(super) fn remote_recipe_book_settings(
+ &mut self,
+ p: horizon_protocol::packets::recipes::RecipeBookSettings,
+ ) {
+ for (i, (open, filtering)) in p.books.into_iter().enumerate() {
+ self.level.recipe_book.open[i] = open;
+ self.level.recipe_book.filtering[i] = filtering;
+ }
+ }
+ /// ClientboundPlaceGhostRecipePacket: the recipe last placed, faded into
+ /// the open menu's grid.
+ pub(super) fn remote_ghost_recipe(
+ &mut self,
+ p: horizon_protocol::packets::recipes::PlaceGhostRecipe,
+ ) {
+ let open = self.remote_menu_id();
+ let Some(book_type) = self.active_book() else {
+ return;
+ };
+ if p.container != open {
+ return;
+ }
+ let entry = self.recipe_ui.last_placed.as_ref().and_then(|id| {
+ let book = self.recipe_ui.book.as_ref()?;
+ book.entry(id).cloned()
+ });
+ if let Some(entry) = entry {
+ self.recipe_ui.ghost.clear();
+ self.fill_ghost(book_type, &entry);
+ }
+ }
+
// ---- ghost recipe ----
/// `fillGhostRecipe`: the recipe's ingredients faded into the slots.
diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs
index 05e1f81c3..474e943c0 100644
--- a/crates/horizon-client/src/game/remote.rs
+++ b/crates/horizon-client/src/game/remote.rs
@@ -9,20 +9,26 @@
use super::{Dim, Game, Mining, Screen};
use horizon_client::{
Result,
- chunk::{BIOME_STRATEGY, BLOCK_STRATEGY, Chunk, Light, MIN_Y, SECTIONS, Section},
+ chunk::{BIOME_STRATEGY, Chunk, Light, MIN_Y, SECTIONS, Section, block_strategy},
containers::{BlockEntity, Furnace, FurnaceKind},
- entities::{Experience, ItemEntity},
+ entities::{Experience, ExperienceOrb, ItemEntity},
hud::{HudBatch, rgba},
items::ItemStack,
- mobs::{Mob, MobType},
+ menu::Input,
+ mobs::{Mob, MobType, Who},
motion::{MotionWorld, PlayerMotion},
net::{Event, Session},
save::SaveDir,
sprint::Keys,
streaming::{ChunkGenerator, Proto, Streaming},
+ tab_list::SPECTATOR,
world::World,
};
-use horizon_core::{geometry::Vec3, paletted::PalettedContainer, random::RandomSource};
+use horizon_core::{
+ geometry::Vec3,
+ paletted::{PalettedContainer, Strategy},
+ random::RandomSource,
+};
use horizon_protocol::{
entity_data::{ITEM_ENTITY_ITEM, Value},
item::{Hashed, Stack},
@@ -34,13 +40,15 @@ use horizon_protocol::{
text::{Language, format_java, plain},
};
use horizon_world::{nbt::Tag, registry::BlockStateId};
-use std::{
- collections::HashMap,
- sync::Arc,
- time::{Duration, Instant},
-};
+use std::{collections::HashMap, sync::Arc, time::Instant};
use winit::{event::MouseButton, keyboard::KeyCode};
+/// A text component the server sent, for the HUD.
+fn remote_text(tag: &Tag) -> horizon_client::text::Text {
+ use horizon_client::scoreboard::{comp_text, tag_to_json};
+ comp_text(&tag_to_json(tag))
+}
+
/// Streaming needs a generator; a server world never generates.
struct NoTerrain;
impl ChunkGenerator for NoTerrain {
@@ -61,8 +69,11 @@ struct Tracked {
}
/// Smooth an entity toward a new position over three ticks (InterpolationHandler).
#[derive(Clone, Copy)]
+/// `LinearInterpolationHandler`'s target: a position and rotation (yRot,
+/// xRot) reached in `steps` ticks.
struct Lerp {
target: [f64; 3],
+ rotation: Option<(f32, f32)>,
steps: u32,
}
@@ -71,7 +82,7 @@ pub(super) struct Remote {
pub brand: String,
builtin: Arc,
lang: Arc,
- registries: Arc,
+ pub(super) registries: Arc,
joined: bool,
status: String,
entity_id: i32,
@@ -89,6 +100,8 @@ pub(super) struct Remote {
was_sprinting: bool,
carried: Option,
loaded_sent: bool,
+ /// The view distance last sent in ClientInformation.
+ sent_view: i8,
/// BlockStatePredictionHandler: blocks changed ahead of the server (a predicted break),
/// with the sequence of the last action that changed them and the state the server
/// last said they have. Until the server acknowledges that sequence its block updates
@@ -102,13 +115,15 @@ pub(super) struct Remote {
use_target: Option<[i32; 3]>,
entities: HashMap,
lerps: HashMap,
+ /// `LivingEntity.lerpHeadTo`: the head yaw and the ticks left to reach it.
+ head_lerps: HashMap,
/// Item entities waiting for their item data.
pending_items: HashMap,
health: (f32, i32, f32),
game_mode: i32,
pub chat: Vec<(String, Instant)>,
- pub chat_input: Option,
- action_bar: Option<(String, Instant)>,
+ /// The server's command tree (ClientboundCommandsPacket).
+ pub commands: Option,
players: HashMap,
/// `ClientPacketListener.playerInfoMap` as player-list entries, and
/// which of them are listed.
@@ -196,7 +211,7 @@ impl Game<'_> {
.and_then(|p| Builtin::load(&p).ok())
.ok_or("Resources are incomplete: registries.json is missing or invalid. Click \"Prepare again\" in the launcher (or run horizon-prepare), then try again.")?;
let lang = Arc::new(horizon_client::net::load_language(&root));
- let view = self.settings.render_distance.clamp(2, 32) as i8;
+ let view = client_view_distance(self.settings.render_distance);
if local.is_none() {
horizon_client::crash::set_detail(
"Server",
@@ -233,6 +248,8 @@ impl Game<'_> {
self.player = None;
self.spawn = None;
self.mobs.clear();
+ self.clear_remote_objects();
+ self.clear_remote_projectiles();
self.creatures.projectiles.clear();
self.dropped.clear();
self.particles.clear();
@@ -281,6 +298,7 @@ impl Game<'_> {
was_sprinting: false,
carried: None,
loaded_sent: false,
+ sent_view: view,
predictions: HashMap::new(),
menu: None,
menu_title: None,
@@ -288,12 +306,12 @@ impl Game<'_> {
use_target: None,
entities: HashMap::new(),
lerps: HashMap::new(),
+ head_lerps: HashMap::new(),
pending_items: HashMap::new(),
health: (20.0, 20, 5.0),
game_mode: 0,
chat: Vec::new(),
- chat_input: None,
- action_bar: None,
+ commands: None,
players: HashMap::new(),
tab_players: HashMap::new(),
skin_textures: HashMap::new(),
@@ -350,6 +368,8 @@ impl Game<'_> {
self.world = World::new(self.res.facts.air, 0);
self.player = None;
self.mobs.clear();
+ self.clear_remote_objects();
+ self.clear_remote_projectiles();
self.dropped.clear();
self.particles.clear();
self.pickups.clear();
@@ -432,7 +452,7 @@ impl Game<'_> {
.and_then(|i| i.id(name))
.unwrap_or(0)
}
- fn to_stack(&self, s: &Option) -> Option {
+ pub(super) fn to_stack(&self, s: &Option) -> Option {
let s = s.as_ref()?;
let mut out = ItemStack {
item: self.item_name(s.item),
@@ -470,6 +490,20 @@ impl Game<'_> {
}
}
+ /// The names in the server's player list, sorted.
+ pub(super) fn remote_online_names(&self) -> Option> {
+ let r = self.remote.as_ref()?;
+ let mut names: Vec = r.players.values().cloned().collect();
+ names.sort();
+ Some(names)
+ }
+ /// The open menu's window id (0: the inventory).
+ pub(super) fn remote_menu_id(&self) -> i32 {
+ self.remote
+ .as_ref()
+ .and_then(|r| r.menu.as_ref())
+ .map_or(0, |m| m.0)
+ }
/// The server's last `n` chat lines, newest first.
pub(super) fn remote_chat(&self, n: usize) -> Option