Merge remote-tracking branch 'origin/main' into integ/bl4
This commit is contained in:
Generated
+1
@@ -1556,6 +1556,7 @@ dependencies = [
|
||||
name = "horizon-server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"horizon-bench",
|
||||
"horizon-server-files",
|
||||
"libc",
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
# Horizon's server against vanilla 26.3: mixed bots (2026-10-18)
|
||||
|
||||
The first benchmark from docs/server.md section 10 (item 4): the same bots on Horizon's dedicated server, as
|
||||
`install.sh` installs it today, and on vanilla 26.3's, one server at a time on the same quiet machine.
|
||||
There were 1, 10, 25 and 50 bots, all with the `mixed` behaviour.
|
||||
|
||||
## Summary
|
||||
|
||||
- **Both servers held 20 TPS in every run.**
|
||||
- **Memory:** Horizon's RSS was 3.7 to 5.2 times smaller: 0.65 GB against 3.4 GB with one player, and
|
||||
1.0 GB against 4.0 GB with 50. Vanilla runs with the usual fixed heap (`-Xms4g -Xmx4g`), so its RSS
|
||||
is mostly that heap.
|
||||
- **Tick time (MSPT):**
|
||||
- with 1, 10 and 25 players, Horizon's average tick was shorter (2.4 against 17.9 ms, 12.4 against 34.5,
|
||||
24.0 against 31.6);
|
||||
- with 50, it was longer (35.2 against 29.7 ms);
|
||||
- Horizon's P99 was lower at every count, and so were its worst 5-second windows (241 ms at most,
|
||||
against 424 to 2320 ms for vanilla).
|
||||
- **The work was not equal, and the difference counts against Horizon.** In `mixed`, 20 % of the bots
|
||||
fly straight out at 22 blocks a second, as fast as each server sends them chunks. Horizon kept up:
|
||||
- with 10 or more players it sent 2.9 to 5.9 times as many chunks a second, and generated 1.9 to 2.9
|
||||
times as much new terrain a second;
|
||||
- its walking bots each received 3300 to 4000 chunks, against 640 to 1100 on vanilla once 10 or more
|
||||
were online.
|
||||
|
||||
So at 50 players Horizon's tick is 18 % longer while it generates twice the new terrain. The
|
||||
equal-rate explore pass of `../server-equal-work-2026-10-17/` is the fair comparison for exploring.
|
||||
- **Start (fresh world, to `Done`):** 10 to 20 s for Horizon, 14.5 to 28.6 s for vanilla.
|
||||
|
||||
## Results
|
||||
|
||||
MSPT is milliseconds per tick from each server's own `/tick query` (50 is the limit for 20 TPS). P95 and
|
||||
P99 are over the whole run. "Worst P99" is the highest P99 of a single 5-second query. RSS and CPU cover
|
||||
the server's whole process tree (100 % is one thread; the machine has 4). "New chunks/s" counts chunks
|
||||
no bot had before. "Pulled back" counts position packets that moved a bot back.
|
||||
|
||||
| Bots | Server | MSPT | P95 | P99 | Worst P99 | TPS | RSS (mean / max) | CPU | Start | Chunks/s | New chunks/s | Pulled back |
|
||||
|---:|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
|
||||
| 1 | Horizon | **2.4** | 5.2 | 18.2 | 45.6 | 20 | **0.65 / 0.66 GB** | 25 % | 10.9 s | 9.9 | 0.3 | 0 |
|
||||
| 1 | vanilla | 17.9 | 27.6 | 47.3 | 423.8 | 20 | 3.38 / 3.39 GB | 64 % | 14.8 s | 9.9 | 0.3 | 0 |
|
||||
| 10 | Horizon | **12.4** | 36.0 | 65.9 | 117.1 | 20 | **0.94 / 1.01 GB** | 210 % | 10.2 s | 98.2 | 36.5 | 6267 |
|
||||
| 10 | vanilla | 34.5 | 63.5 | 138.6 | 884.7 | 20 | 3.59 / 3.66 GB | 217 % | 14.5 s | 24.3 | 19.1 | 5500 |
|
||||
| 25 | Horizon | **24.0** | 49.7 | 80.6 | 168.8 | 20 | **1.01 / 1.18 GB** | 192 % | 14.7 s | 178.2 | 31.9 | 5532 |
|
||||
| 25 | vanilla | 31.6 | 70.0 | 222.7 | 2319.6 | 20 | 3.74 / 4.06 GB | 218 % | 28.6 s | 30.4 | 10.8 | 4524 |
|
||||
| 50 | Horizon | 35.2 | 69.0 | 96.6 | 240.8 | 20 | **1.01 / 1.25 GB** | 218 % | 19.8 s | 273.2 | 34.6 | 8369 |
|
||||
| 50 | vanilla | **29.7** | 62.3 | 137.4 | 489.3 | 20 | 4.00 / 4.60 GB | 294 % | 20.6 s | 94.4 | 17.8 | 12034 |
|
||||
|
||||
Chunks each bot received, by behaviour (mean):
|
||||
|
||||
| Bots | Server | walk | explore | idle |
|
||||
|---:|---|---:|---:|---:|
|
||||
| 10 | Horizon | 3992 | 7360 | 473 |
|
||||
| 10 | vanilla | 680 | 2824 | 358 |
|
||||
| 25 | Horizon | 3928 | 2475 | 473 |
|
||||
| 25 | vanilla | 640 | 738 | 180 |
|
||||
| 50 | Horizon | 3300 | 1192 | 460 |
|
||||
| 50 | vanilla | 1105 | 629 | 220 |
|
||||
|
||||
No bot failed to join or was dropped, and no chunk was sent twice (`resent` 0), on either server. Vanilla
|
||||
also logged "moved too quickly" 12, 324 and 2193 times at 10, 25 and 50 bots.
|
||||
|
||||
## Method
|
||||
|
||||
`tools/server_bench.py`, unchanged, 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`, white-list off;
|
||||
- `gamerule respawn_radius 0`, and otherwise vanilla's default game rules on both. The locator bar is on
|
||||
for both: Horizon's server has run it since v2026.10.18.13. The 2026-10-17 runs turned it off on vanilla
|
||||
because Horizon had none then;
|
||||
- the server waits for `Done`, then the bots join one a second, warm up for 60 seconds, and are measured
|
||||
for 300 seconds, with `/tick query` every 5 seconds and RSS and CPU every second.
|
||||
|
||||
The bots are `horizon-bots --behaviour mixed`: 60 % walk, 20 % explore and 20 % idle, each choice
|
||||
deterministic per bot. All are creative and fly 24 blocks above their spawn:
|
||||
|
||||
- `walk`: random points within 48 blocks at 5.6 blocks a second;
|
||||
- `explore`: straight out at up to 22 blocks a second, as fast as chunks come;
|
||||
- `idle`: hovers.
|
||||
|
||||
A bot doesn't move while the chunk it stands in hasn't arrived, and it acknowledges chunk batches as
|
||||
vanilla's client does.
|
||||
|
||||
**Machine.** The ThinkPad: Intel Core i7-7500U (2 cores, 4 threads), 32 GB, NixOS (Linux 6.18). No other
|
||||
session ran on it (`load.txt`: the fleet monitor shows 0 sessions throughout). The busy periods are the
|
||||
servers themselves, which used 2 to 3 of its 4 threads from 10 bots up, so both servers were CPU-bound
|
||||
there. The servers ran under `nice -n 19`. The desktop was meant to run this (24 threads) but didn't
|
||||
wake. The bots ran on the Mac mini (M4 Pro) and reached the ThinkPad over the tailnet, so they took none
|
||||
of the servers' CPU. The Mac mini was shared with other work (70 to 90 % busy), which only affects the
|
||||
bots' timing.
|
||||
|
||||
**What ran.**
|
||||
|
||||
- Horizon: the published v2026.10.18.15 release, `horizon-client` (the engine) at 6c078b28, as
|
||||
`install.sh` installs it. Its game files were prepared from the owner's own Minecraft by the release's
|
||||
`horizon-prepare`. `horizon-server` (the supervisor, which takes no part in the tick) came from #898
|
||||
(4ea2243e), because the release's copy can't find game files prepared without sounds (#893).
|
||||
`horizon-bots` came from main.
|
||||
- Vanilla: the pinned 26.3 server jar (the owner's own copy) on OpenJDK 25.0.4.1, `-Xms4g -Xmx4g`.
|
||||
|
||||
On Linux the release's engine needs `libasound.so.2` and `libudev.so.1`. The ThinkPad has them only in
|
||||
the Nix store, so the run set `LD_LIBRARY_PATH` to them (see #898).
|
||||
|
||||
## Reproduce
|
||||
|
||||
curl -fsSL https://raw.githubusercontent.com/ludovic111/horizon/main/packaging/server/install.sh | sh
|
||||
horizon-prepare --prepare --server-jar /path/to/server.jar # your own copy
|
||||
cargo build --release -p horizon-bots # on the machine that runs the bots
|
||||
# in a checkout whose .local/minecraft holds the pinned vanilla jars (tools/lab.py prepare):
|
||||
HORIZON_BENCH_BIN=<a folder with horizon-server and horizon-client> \
|
||||
python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25,50 --behaviour mixed --nice 19 \
|
||||
--bots-via 'ssh <bots machine>' --bots-bin /path/to/horizon-bots --connect <this machine's address> \
|
||||
--out mixed.json
|
||||
|
||||
`mixed.json` is the report (`horizon-server-benchmark`: machine, versions, settings and every run), and
|
||||
`load.txt` is the ThinkPad's load before and during the run.
|
||||
|
||||
## Next
|
||||
|
||||
- An equal-work `mixed` pass (`--explore-speed` at a rate both servers keep up with), then 100 bots.
|
||||
- The same run on a bigger machine, so neither server is CPU-bound at 25 to 50 bots.
|
||||
- Paper and Fabric + Lithium (docs/server.md section 9).
|
||||
- At 50 players Horizon's tick is longer than vanilla's while it generates and sends far more. The
|
||||
profile of the 2026-10-17 run (streaming and block entity ticks growing with players) is
|
||||
perf-server's to take on.
|
||||
@@ -0,0 +1,286 @@
|
||||
ludothinkpad — OK
|
||||
RAM 29.1 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 2% busy (agents 0.0, rest 0.1 cores) · 67°C · load 2.1
|
||||
· disk 295.5 GB free · battery 96%
|
||||
|
||||
Sessions, most important first:
|
||||
(finished session) 0.0 GB leftovers: node 0.0 GB
|
||||
|
||||
Other machines (≤ 1 min old): desktop offline · macbook offline · macmini ok: 26.6 GB free, 14 threads 69% busy, 1 sessions
|
||||
|
||||
# During the run, once a minute (uptime, then ~/fleet/load fleet)
|
||||
18:25:30
|
||||
18:25:30 up 8 days 3:08, 0 users, load average: 2.13, 1.53, 1.29
|
||||
ludothinkpad ok: 29.1 GB free, 4 threads 2% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.6 GB free, 14 threads 87% busy, 1 sessions
|
||||
18:26:34
|
||||
18:26:34 up 8 days 3:09, 0 users, load average: 1.70, 1.56, 1.31
|
||||
ludothinkpad ok: 28.5 GB free, 4 threads 23% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.4 GB free, 14 threads 85% busy, 1 sessions
|
||||
18:27:38
|
||||
18:27:38 up 8 days 3:10, 0 users, load average: 1.10, 1.43, 1.28
|
||||
ludothinkpad ok: 28.5 GB free, 4 threads 4% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.7 GB free, 14 threads 80% busy, 1 sessions
|
||||
18:28:42
|
||||
18:28:42 up 8 days 3:11, 0 users, load average: 0.93, 1.29, 1.24
|
||||
ludothinkpad ok: 28.5 GB free, 4 threads 22% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.0 GB free, 14 threads 82% busy, 1 sessions
|
||||
18:29:46
|
||||
18:29:46 up 8 days 3:12, 0 users, load average: 0.62, 1.12, 1.18
|
||||
ludothinkpad ok: 28.5 GB free, 4 threads 12% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 25.7 GB free, 14 threads 81% busy, 1 sessions
|
||||
18:30:50
|
||||
18:30:51 up 8 days 3:13, 0 users, load average: 0.79, 1.05, 1.15
|
||||
ludothinkpad ok: 28.5 GB free, 4 threads 7% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.0 GB free, 14 threads 88% busy, 1 sessions
|
||||
18:31:55
|
||||
18:31:55 up 8 days 3:14, 0 users, load average: 0.67, 0.96, 1.11
|
||||
ludothinkpad ok: 28.6 GB free, 4 threads 73% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.3 GB free, 14 threads 79% busy, 1 sessions
|
||||
18:32:59
|
||||
18:32:59 up 8 days 3:15, 0 users, load average: 4.01, 1.91, 1.44
|
||||
ludothinkpad ok: 25.9 GB free, 4 threads 24% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.4 GB free, 14 threads 85% busy, 1 sessions
|
||||
18:34:03
|
||||
18:34:03 up 8 days 3:16, 0 users, load average: 2.24, 1.84, 1.44
|
||||
ludothinkpad ok: 25.9 GB free, 4 threads 21% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.2 GB free, 14 threads 86% busy, 1 sessions
|
||||
18:35:07
|
||||
18:35:07 up 8 days 3:17, 0 users, load average: 1.28, 1.63, 1.40
|
||||
ludothinkpad ok: 25.8 GB free, 4 threads 21% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 31.0 GB free, 14 threads 86% busy, 1 sessions
|
||||
18:36:11
|
||||
18:36:11 up 8 days 3:18, 0 users, load average: 0.79, 1.41, 1.33
|
||||
ludothinkpad ok: 25.9 GB free, 4 threads 18% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.3 GB free, 14 threads 93% busy, 1 sessions
|
||||
18:37:15
|
||||
18:37:15 up 8 days 3:20, 0 users, load average: 1.44, 1.47, 1.36
|
||||
ludothinkpad ok: 25.9 GB free, 4 threads 23% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.8 GB free, 14 threads 86% busy, 1 sessions
|
||||
18:38:19
|
||||
18:38:19 up 8 days 3:21, 0 users, load average: 1.37, 1.45, 1.36
|
||||
ludothinkpad ok: 25.9 GB free, 4 threads 13% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.7 GB free, 14 threads 86% busy, 1 sessions
|
||||
18:39:24
|
||||
18:39:24 up 8 days 3:22, 0 users, load average: 2.27, 1.66, 1.44
|
||||
ludothinkpad ok: 28.3 GB free, 4 threads 62% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.1 GB free, 14 threads 70% busy, 1 sessions
|
||||
18:40:28
|
||||
18:40:28 up 8 days 3:23, 0 users, load average: 1.95, 1.72, 1.48
|
||||
ludothinkpad ok: 28.3 GB free, 4 threads 63% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.7 GB free, 14 threads 84% busy, 1 sessions
|
||||
18:41:32
|
||||
18:41:32 up 8 days 3:24, 0 users, load average: 3.32, 2.22, 1.67
|
||||
ludothinkpad ok: 28.2 GB free, 4 threads 61% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.8 GB free, 14 threads 85% busy, 1 sessions
|
||||
18:42:36
|
||||
18:42:36 up 8 days 3:25, 0 users, load average: 3.13, 2.33, 1.75
|
||||
ludothinkpad ok: 28.2 GB free, 4 threads 60% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.1 GB free, 14 threads 91% busy, 1 sessions
|
||||
18:43:40
|
||||
18:43:40 up 8 days 3:26, 0 users, load average: 3.27, 2.48, 1.83
|
||||
ludothinkpad busy: 28.1 GB free, 4 threads 90% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.3 GB free, 14 threads 92% busy, 1 sessions
|
||||
18:44:44
|
||||
18:44:44 up 8 days 3:27, 0 users, load average: 2.14, 2.32, 1.82
|
||||
ludothinkpad ok: 28.1 GB free, 4 threads 55% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 30.4 GB free, 14 threads 88% busy, 1 sessions
|
||||
18:45:48
|
||||
18:45:48 up 8 days 3:28, 0 users, load average: 4.94, 3.06, 2.11
|
||||
ludothinkpad busy: 25.9 GB free, 4 threads 86% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.7 GB free, 14 threads 84% busy, 1 sessions
|
||||
18:46:53
|
||||
18:46:53 up 8 days 3:29, 0 users, load average: 6.55, 3.92, 2.47
|
||||
ludothinkpad busy: 25.4 GB free, 4 threads 99% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.3 GB free, 14 threads 81% busy, 1 sessions
|
||||
18:47:57
|
||||
18:47:57 up 8 days 3:30, 0 users, load average: 8.50, 4.96, 2.93
|
||||
ludothinkpad busy: 24.0 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.9 GB free, 14 threads 90% busy, 1 sessions
|
||||
18:49:01
|
||||
18:49:01 up 8 days 3:31, 0 users, load average: 8.59, 5.68, 3.31
|
||||
ludothinkpad busy: 22.7 GB free, 4 threads 99% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.2 GB free, 14 threads 85% busy, 1 sessions
|
||||
18:50:05
|
||||
18:50:05 up 8 days 3:32, 0 users, load average: 7.81, 6.07, 3.61
|
||||
ludothinkpad busy: 24.5 GB free, 4 threads 90% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.6 GB free, 14 threads 96% busy, 1 sessions
|
||||
18:51:09
|
||||
18:51:09 up 8 days 3:33, 0 users, load average: 8.29, 6.50, 3.93
|
||||
ludothinkpad busy: 24.3 GB free, 4 threads 92% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.0 GB free, 14 threads 94% busy, 1 sessions
|
||||
18:52:14
|
||||
18:52:14 up 8 days 3:35, 0 users, load average: 5.58, 6.06, 3.95
|
||||
ludothinkpad busy: 26.0 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.3 GB free, 14 threads 87% busy, 1 sessions
|
||||
18:53:18
|
||||
18:53:18 up 8 days 3:36, 0 users, load average: 4.53, 5.69, 3.97
|
||||
ludothinkpad busy: 27.2 GB free, 4 threads 89% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.8 GB free, 14 threads 87% busy, 1 sessions
|
||||
18:54:22
|
||||
18:54:22 up 8 days 3:37, 0 users, load average: 5.31, 5.64, 4.07
|
||||
ludothinkpad busy: 26.3 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.3 GB free, 14 threads 91% busy, 1 sessions
|
||||
18:55:26
|
||||
18:55:26 up 8 days 3:38, 0 users, load average: 10.47, 6.99, 4.63
|
||||
ludothinkpad busy: 26.1 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.7 GB free, 14 threads 90% busy, 1 sessions
|
||||
18:56:30
|
||||
18:56:30 up 8 days 3:39, 0 users, load average: 9.27, 7.45, 4.96
|
||||
ludothinkpad busy: 26.2 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.5 GB free, 14 threads 92% busy, 1 sessions
|
||||
18:57:35
|
||||
18:57:35 up 8 days 3:40, 0 users, load average: 7.79, 7.39, 5.10
|
||||
ludothinkpad busy: 26.1 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.1 GB free, 14 threads 80% busy, 1 sessions
|
||||
18:58:39
|
||||
18:58:39 up 8 days 3:41, 0 users, load average: 8.06, 7.55, 5.32
|
||||
ludothinkpad busy: 26.4 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 31.8 GB free, 14 threads 95% busy, 1 sessions
|
||||
18:59:43
|
||||
18:59:43 up 8 days 3:42, 0 users, load average: 8.44, 7.65, 5.50
|
||||
ludothinkpad busy: 26.2 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 31.4 GB free, 14 threads 94% busy, 1 sessions
|
||||
19:00:47
|
||||
19:00:47 up 8 days 3:43, 0 users, load average: 11.04, 8.66, 6.00
|
||||
ludothinkpad busy: 24.9 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 31.8 GB free, 14 threads 88% busy, 1 sessions
|
||||
19:01:51
|
||||
19:01:51 up 8 days 3:44, 0 users, load average: 11.91, 9.37, 6.41
|
||||
ludothinkpad busy: 24.4 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 32.9 GB free, 14 threads 77% busy, 1 sessions
|
||||
19:02:56
|
||||
19:02:56 up 8 days 3:45, 0 users, load average: 11.64, 9.85, 6.79
|
||||
ludothinkpad ok: 25.5 GB free, 4 threads 70% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 30.9 GB free, 14 threads 91% busy, 1 sessions
|
||||
19:04:00
|
||||
19:04:00 up 8 days 3:46, 0 users, load average: 11.42, 10.06, 7.06
|
||||
ludothinkpad busy: 23.4 GB free, 4 threads 99% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.4 GB free, 14 threads 94% busy, 1 sessions
|
||||
19:05:04
|
||||
19:05:04 up 8 days 3:47, 0 users, load average: 9.83, 9.96, 7.24
|
||||
ludothinkpad busy: 23.2 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 31.4 GB free, 14 threads 80% busy, 1 sessions
|
||||
19:06:09
|
||||
19:06:09 up 8 days 3:48, 0 users, load average: 8.38, 9.68, 7.34
|
||||
ludothinkpad ok: 22.7 GB free, 4 threads 17% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.8 GB free, 14 threads 86% busy, 1 sessions
|
||||
19:07:13
|
||||
19:07:13 up 8 days 3:49, 0 users, load average: 4.51, 8.27, 7.00
|
||||
ludothinkpad ok: 25.7 GB free, 4 threads 75% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.5 GB free, 14 threads 89% busy, 1 sessions
|
||||
19:08:17
|
||||
19:08:17 up 8 days 3:51, 0 users, load average: 6.77, 8.13, 7.04
|
||||
ludothinkpad busy: 25.8 GB free, 4 threads 95% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 30.8 GB free, 14 threads 91% busy, 1 sessions
|
||||
19:09:22
|
||||
19:09:22 up 8 days 3:52, 0 users, load average: 8.27, 8.25, 7.14
|
||||
ludothinkpad busy: 25.2 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.3 GB free, 14 threads 91% busy, 1 sessions
|
||||
19:10:26
|
||||
19:10:26 up 8 days 3:53, 0 users, load average: 8.88, 8.57, 7.34
|
||||
ludothinkpad busy: 24.8 GB free, 4 threads 99% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 32.4 GB free, 14 threads 72% busy, 1 sessions
|
||||
19:11:30
|
||||
19:11:30 up 8 days 3:54, 0 users, load average: 13.33, 10.05, 7.94
|
||||
ludothinkpad busy: 24.7 GB free, 4 threads 97% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 30.1 GB free, 14 threads 87% busy, 1 sessions
|
||||
19:12:35
|
||||
19:12:35 up 8 days 3:55, 0 users, load average: 10.92, 10.13, 8.12
|
||||
ludothinkpad ok: 26.4 GB free, 4 threads 76% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.3 GB free, 14 threads 86% busy, 1 sessions
|
||||
19:13:39
|
||||
19:13:39 up 8 days 3:56, 0 users, load average: 9.98, 9.89, 8.16
|
||||
ludothinkpad busy: 25.8 GB free, 4 threads 90% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.8 GB free, 14 threads 93% busy, 1 sessions
|
||||
19:14:43
|
||||
19:14:43 up 8 days 3:57, 0 users, load average: 8.95, 9.63, 8.19
|
||||
ludothinkpad busy: 25.1 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.6 GB free, 14 threads 71% busy, 1 sessions
|
||||
19:15:47
|
||||
19:15:47 up 8 days 3:58, 0 users, load average: 12.02, 10.38, 8.55
|
||||
ludothinkpad busy: 24.5 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.1 GB free, 14 threads 93% busy, 1 sessions
|
||||
19:16:52
|
||||
19:16:52 up 8 days 3:59, 0 users, load average: 13.82, 11.21, 8.95
|
||||
ludothinkpad busy: 23.9 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.4 GB free, 14 threads 75% busy, 1 sessions
|
||||
19:17:56
|
||||
19:17:56 up 8 days 4:00, 0 users, load average: 11.95, 11.20, 9.10
|
||||
ludothinkpad busy: 25.0 GB free, 4 threads 99% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.4 GB free, 14 threads 81% busy, 1 sessions
|
||||
19:19:00
|
||||
19:19:00 up 8 days 4:01, 0 users, load average: 11.46, 11.14, 9.22
|
||||
ludothinkpad busy: 24.6 GB free, 4 threads 95% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.4 GB free, 14 threads 83% busy, 1 sessions
|
||||
19:20:04
|
||||
19:20:04 up 8 days 4:02, 0 users, load average: 11.11, 10.97, 9.28
|
||||
ludothinkpad busy: 24.6 GB free, 4 threads 93% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.7 GB free, 14 threads 85% busy, 1 sessions
|
||||
19:21:08
|
||||
19:21:08 up 8 days 4:03, 0 users, load average: 9.81, 10.60, 9.27
|
||||
ludothinkpad busy: 24.4 GB free, 4 threads 91% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.8 GB free, 14 threads 75% busy, 1 sessions
|
||||
19:22:13
|
||||
19:22:13 up 8 days 4:04, 0 users, load average: 5.98, 9.51, 9.00
|
||||
ludothinkpad ok: 23.8 GB free, 4 threads 18% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.7 GB free, 14 threads 85% busy, 1 sessions
|
||||
19:23:17
|
||||
19:23:17 up 8 days 4:06, 0 users, load average: 4.01, 8.27, 8.60
|
||||
ludothinkpad ok: 23.1 GB free, 4 threads 56% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.2 GB free, 14 threads 79% busy, 1 sessions
|
||||
@@ -0,0 +1,367 @@
|
||||
{
|
||||
"kind": "horizon-server-benchmark",
|
||||
"date": "2026-10-18T17:23:30+00:00",
|
||||
"machine": {
|
||||
"system": "Linux",
|
||||
"machine": "x86_64",
|
||||
"cpus": 4,
|
||||
"note": "ThinkPad: Intel Core i7-7500U (2 cores, 4 threads), 32 GB, NixOS, Linux 6.18; the bots on the Mac mini (M4 Pro) over the tailnet"
|
||||
},
|
||||
"commit": "4ea2243e4d1a44f910857bd759845db70e3690a8",
|
||||
"java": [
|
||||
"openjdk 25.0.4.1 2026-08-18"
|
||||
],
|
||||
"settings": {
|
||||
"servers": "horizon,vanilla",
|
||||
"bots": "1,10,25,50",
|
||||
"behaviour": "mixed",
|
||||
"join_every": 1.0,
|
||||
"warmup": 60,
|
||||
"seconds": 300,
|
||||
"seed": 12345,
|
||||
"explore_speed": 0,
|
||||
"gamerule": "",
|
||||
"heap": "4g",
|
||||
"out": "mixed.json",
|
||||
"nice": 19,
|
||||
"bots_via": "ssh macmini",
|
||||
"bots_bin": "horizon-bots (on the Mac mini)",
|
||||
"connect": "<the ThinkPad's tailnet address>",
|
||||
"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": "mixed",
|
||||
"start_seconds": 10.92,
|
||||
"mspt": {
|
||||
"average": 2.38,
|
||||
"p50": 1.97,
|
||||
"p95": 5.17,
|
||||
"p99": 18.2
|
||||
},
|
||||
"mspt_worst_p99": 45.6,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 653.7,
|
||||
"max": 659.2
|
||||
},
|
||||
"cpu_percent": 24.51,
|
||||
"chunks_per_second": 9.9,
|
||||
"unique_per_second": 0.3,
|
||||
"forgotten_per_second": 9.93,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 3951,
|
||||
"chunks_per_bot": {
|
||||
"walk": 3951.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": 1,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 14.75,
|
||||
"mspt": {
|
||||
"average": 17.9,
|
||||
"p50": 18.39,
|
||||
"p95": 27.58,
|
||||
"p99": 47.28
|
||||
},
|
||||
"mspt_worst_p99": 423.8,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 3382.06,
|
||||
"max": 3394.1
|
||||
},
|
||||
"cpu_percent": 64.02,
|
||||
"chunks_per_second": 9.92,
|
||||
"unique_per_second": 0.29,
|
||||
"forgotten_per_second": 9.95,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 3846,
|
||||
"chunks_per_bot": {
|
||||
"walk": 3846.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": "mixed",
|
||||
"start_seconds": 10.22,
|
||||
"mspt": {
|
||||
"average": 12.39,
|
||||
"p50": 8.33,
|
||||
"p95": 35.99,
|
||||
"p99": 65.9
|
||||
},
|
||||
"mspt_worst_p99": 117.1,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 935.85,
|
||||
"max": 1008.6
|
||||
},
|
||||
"cpu_percent": 210.37,
|
||||
"chunks_per_second": 98.22,
|
||||
"unique_per_second": 36.49,
|
||||
"forgotten_per_second": 98.25,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 39618,
|
||||
"chunks_per_bot": {
|
||||
"walk": 3992.17,
|
||||
"explore": 7359.5,
|
||||
"idle": 473.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 696.83,
|
||||
"explore": 6869.0,
|
||||
"idle": 473.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 6267,
|
||||
"moved_too_quickly": 0,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 10,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "vanilla",
|
||||
"bots": 10,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 14.54,
|
||||
"mspt": {
|
||||
"average": 34.47,
|
||||
"p50": 29.67,
|
||||
"p95": 63.52,
|
||||
"p99": 138.58
|
||||
},
|
||||
"mspt_worst_p99": 884.7,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 3594.26,
|
||||
"max": 3661.7
|
||||
},
|
||||
"cpu_percent": 217.13,
|
||||
"chunks_per_second": 24.34,
|
||||
"unique_per_second": 19.13,
|
||||
"forgotten_per_second": 20.12,
|
||||
"waited_ticks_per_second": 0.62,
|
||||
"chunks_total": 10443,
|
||||
"chunks_per_bot": {
|
||||
"walk": 679.83,
|
||||
"explore": 2824.0,
|
||||
"idle": 358.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 389.17,
|
||||
"explore": 2824.0,
|
||||
"idle": 358.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 5500,
|
||||
"moved_too_quickly": 12,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 10,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "horizon",
|
||||
"bots": 25,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 14.73,
|
||||
"mspt": {
|
||||
"average": 24.0,
|
||||
"p50": 21.07,
|
||||
"p95": 49.72,
|
||||
"p99": 80.57
|
||||
},
|
||||
"mspt_worst_p99": 168.8,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 1013.07,
|
||||
"max": 1179.4
|
||||
},
|
||||
"cpu_percent": 192.47,
|
||||
"chunks_per_second": 178.23,
|
||||
"unique_per_second": 31.85,
|
||||
"forgotten_per_second": 177.93,
|
||||
"waited_ticks_per_second": 60.59,
|
||||
"chunks_total": 73657,
|
||||
"chunks_per_bot": {
|
||||
"walk": 3927.87,
|
||||
"explore": 2474.8,
|
||||
"idle": 473.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 691.73,
|
||||
"explore": 2447.8,
|
||||
"idle": 473.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 5532,
|
||||
"moved_too_quickly": 0,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 25,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "vanilla",
|
||||
"bots": 25,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 28.57,
|
||||
"mspt": {
|
||||
"average": 31.59,
|
||||
"p50": 25.18,
|
||||
"p95": 70.03,
|
||||
"p99": 222.74
|
||||
},
|
||||
"mspt_worst_p99": 2319.6,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 3742.51,
|
||||
"max": 4055.0
|
||||
},
|
||||
"cpu_percent": 218.34,
|
||||
"chunks_per_second": 30.37,
|
||||
"unique_per_second": 10.84,
|
||||
"forgotten_per_second": 29.44,
|
||||
"waited_ticks_per_second": 50.91,
|
||||
"chunks_total": 14193,
|
||||
"chunks_per_bot": {
|
||||
"walk": 640.2,
|
||||
"explore": 738.0,
|
||||
"idle": 180.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 211.33,
|
||||
"explore": 737.6,
|
||||
"idle": 180.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 4524,
|
||||
"moved_too_quickly": 324,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 25,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 56
|
||||
},
|
||||
{
|
||||
"server": "horizon",
|
||||
"bots": 50,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 19.84,
|
||||
"mspt": {
|
||||
"average": 35.2,
|
||||
"p50": 32.12,
|
||||
"p95": 69.04,
|
||||
"p99": 96.56
|
||||
},
|
||||
"mspt_worst_p99": 240.8,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 1013.2,
|
||||
"max": 1249.1
|
||||
},
|
||||
"cpu_percent": 217.68,
|
||||
"chunks_per_second": 273.18,
|
||||
"unique_per_second": 34.58,
|
||||
"forgotten_per_second": 268.19,
|
||||
"waited_ticks_per_second": 138.29,
|
||||
"chunks_total": 115527,
|
||||
"chunks_per_bot": {
|
||||
"walk": 3300.1,
|
||||
"explore": 1192.4,
|
||||
"idle": 460.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 632.67,
|
||||
"explore": 1186.9,
|
||||
"idle": 460.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 8369,
|
||||
"moved_too_quickly": 0,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 50,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 57
|
||||
},
|
||||
{
|
||||
"server": "vanilla",
|
||||
"bots": 50,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 20.58,
|
||||
"mspt": {
|
||||
"average": 29.74,
|
||||
"p50": 23.6,
|
||||
"p95": 62.25,
|
||||
"p99": 137.41
|
||||
},
|
||||
"mspt_worst_p99": 489.3,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 3995.71,
|
||||
"max": 4597.8
|
||||
},
|
||||
"cpu_percent": 294.31,
|
||||
"chunks_per_second": 94.36,
|
||||
"unique_per_second": 17.76,
|
||||
"forgotten_per_second": 94.69,
|
||||
"waited_ticks_per_second": 101.48,
|
||||
"chunks_total": 41637,
|
||||
"chunks_per_bot": {
|
||||
"walk": 1104.97,
|
||||
"explore": 628.8,
|
||||
"idle": 220.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 279.4,
|
||||
"explore": 626.4,
|
||||
"idle": 220.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 12034,
|
||||
"moved_too_quickly": 2193,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 50,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 57
|
||||
}
|
||||
],
|
||||
"horizon_build": "v2026.10.18.15 release binaries (horizon-client, the engine, at 6c078b28); horizon-server from #898 (4ea2243e, the supervisor only)"
|
||||
}
|
||||
@@ -11,9 +11,7 @@ use horizon_client::{
|
||||
Result,
|
||||
lan::{LoginGate, NetConfig, NetLog, OnlineMode, hub::HubConfig},
|
||||
server::{
|
||||
eula,
|
||||
java_properties::now_millis,
|
||||
profiles,
|
||||
eula, profiles,
|
||||
properties::{GAME_MODES, ServerProperties, SystemEntropy},
|
||||
user_cache::UserCache,
|
||||
user_lists::{
|
||||
@@ -84,18 +82,16 @@ fn log_from(thread: &str, level: &str, message: &str) {
|
||||
"ERROR" => ::log::Level::Error,
|
||||
_ => ::log::Level::Info,
|
||||
};
|
||||
horizon_client::logging::write_only(file_level, message);
|
||||
horizon_client::logging::write_as(thread, file_level, message);
|
||||
CAPTURE.with_borrow_mut(|lines| {
|
||||
if let Some(lines) = lines {
|
||||
lines.push(message.to_owned());
|
||||
}
|
||||
});
|
||||
let secs = now_millis().div_euclid(1000).rem_euclid(86_400);
|
||||
// Log4j's %d{HH:mm:ss}: the local time, as in logs/latest.log.
|
||||
println!(
|
||||
"[{:02}:{:02}:{:02}] [{thread}/{level}]: {message}",
|
||||
secs / 3600,
|
||||
secs / 60 % 60,
|
||||
secs % 60
|
||||
"[{}] [{thread}/{level}]: {message}",
|
||||
chrono::Local::now().format("%H:%M:%S")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -330,6 +330,14 @@ pub fn write_only(level: log::Level, message: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes `message` to the log file only, under the thread vanilla names for it (`Server thread` for
|
||||
/// a login refused on a connection's own thread), as the console line beside it shows.
|
||||
pub fn write_as(thread: &str, level: log::Level, message: &str) {
|
||||
if let Some(logger) = LOGGER.get() {
|
||||
logger.write(thread, level, message);
|
||||
}
|
||||
}
|
||||
|
||||
/// The last lines written, oldest first (for crash reports).
|
||||
pub fn recent_lines() -> Vec<String> {
|
||||
LOGGER.get().map_or_else(Vec::new, |l| {
|
||||
|
||||
@@ -367,6 +367,7 @@ pub fn carry(
|
||||
let mut biome_conventions = BTreeSet::new();
|
||||
let set_tags = crate::worldgen::structure_set_tags(&mut zip);
|
||||
let piece_counts = crate::worldgen::piece_counts(&mut zip);
|
||||
let processor_data = crate::processors::ProcessorData::read(&mut zip);
|
||||
for i in 0..zip.len() {
|
||||
let mut entry = zip.by_index(i).map_err(|e| e.to_string())?;
|
||||
let name = entry.name().to_owned();
|
||||
@@ -426,12 +427,15 @@ pub fn carry(
|
||||
if kind == "structure" {
|
||||
crate::worldgen::convention_tags(&v["biomes"], &mut biome_conventions);
|
||||
}
|
||||
let mut changed = crate::worldgen::upgrade(
|
||||
let types = &mut report.worldgen_types;
|
||||
let carried = crate::processors::carry(
|
||||
kind,
|
||||
&mut v,
|
||||
&mut report.worldgen_types,
|
||||
&set_tags,
|
||||
&processor_data,
|
||||
&mut types.processors_carried,
|
||||
);
|
||||
let mut changed =
|
||||
crate::worldgen::upgrade(kind, &mut v, types, &set_tags) || carried;
|
||||
if kind == "structure" {
|
||||
let path = rel.trim_start_matches("worldgen/structure/");
|
||||
let structure = format!("{id}:{}", path.trim_end_matches(".json"));
|
||||
@@ -453,6 +457,12 @@ pub fn carry(
|
||||
if let Some((kind, mut added)) =
|
||||
modifier.and_then(|v| crate::worldgen::modifier(&v, loaded, types))
|
||||
{
|
||||
crate::processors::carry(
|
||||
kind,
|
||||
&mut added,
|
||||
&processor_data,
|
||||
&mut types.processors_carried,
|
||||
);
|
||||
crate::worldgen::upgrade(kind, &mut added, types, &set_tags);
|
||||
let to = format!(
|
||||
"data/{id}/worldgen/{kind}/{}/{path}",
|
||||
|
||||
@@ -14,5 +14,6 @@ pub mod jar;
|
||||
pub mod modrinth;
|
||||
pub mod oracle;
|
||||
pub mod pipeline;
|
||||
pub mod processors;
|
||||
pub mod report;
|
||||
pub mod worldgen;
|
||||
|
||||
@@ -0,0 +1,505 @@
|
||||
//! Structure processors the structure libraries write in Java, carried over
|
||||
//! as data the game runs: the ones that give spawners their mob.
|
||||
//!
|
||||
//! - Moog's Structure Lib's and Repurposed Structures' spawner randomizing
|
||||
//! processors pick a mob from a weighted list for each spawner. They become
|
||||
//! `horizon:spawner_mobs` (`horizon_world::worldgen::structure::processor`),
|
||||
//! with Repurposed's `rs_spawners` list written in.
|
||||
//! - YUNG's Better Dungeons and Better Desert Temples turn a spawner or a
|
||||
//! placeholder block into a spawner of a fixed mob. That is vanilla's `rule`
|
||||
//! processor with an `append_static` block entity.
|
||||
//! - Moog's vanilla loot swap only acts when its mod's "replace vanilla"
|
||||
//! preset is on; one that ships off is a no-op and is taken out.
|
||||
//!
|
||||
//! What is not here is taken out of its list later and counted
|
||||
//! (`worldgen::upgrade`). The entity NBT is written in 26.3's shape (an
|
||||
//! `equipment` map, not 1.21.1's `HandItems` and `ArmorItems`).
|
||||
use serde_json::{Value, json};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
io::{Read, Seek},
|
||||
};
|
||||
|
||||
/// What the processors read from the mod's own data files.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ProcessorData {
|
||||
/// Repurposed Structures' `rs_spawners/<path>.json` by id: each mob and
|
||||
/// its weight, without the weight-0 entries its loader removes.
|
||||
pub spawners: BTreeMap<String, Vec<(String, f64)>>,
|
||||
/// Moog's "replace vanilla" presets that are on by default:
|
||||
/// `(mod id, vanilla_key)`.
|
||||
pub replace_vanilla: BTreeSet<(String, String)>,
|
||||
}
|
||||
|
||||
impl ProcessorData {
|
||||
pub fn read<R: Read + Seek>(zip: &mut zip::ZipArchive<R>) -> Self {
|
||||
let mut out = Self::default();
|
||||
for i in 0..zip.len() {
|
||||
let Ok(mut entry) = zip.by_index(i) else {
|
||||
continue;
|
||||
};
|
||||
let name = entry.name().to_owned();
|
||||
let Some((ns, rest)) = name
|
||||
.strip_prefix("data/")
|
||||
.and_then(|r| r.strip_suffix(".json"))
|
||||
.and_then(|r| r.split_once('/'))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let spawners = rest.strip_prefix("rs_spawners/");
|
||||
if spawners.is_none() && rest != "moogs_structures/replace_vanilla" {
|
||||
continue;
|
||||
}
|
||||
let mut text = String::new();
|
||||
let Ok(v) = entry
|
||||
.read_to_string(&mut text)
|
||||
.map_err(|_| ())
|
||||
.and_then(|_| serde_json::from_str::<Value>(&text).map_err(|_| ()))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if let Some(path) = spawners {
|
||||
let mobs = v["mobs"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|m| Some((m["name"].as_str()?.to_owned(), m["weight"].as_f64()?)))
|
||||
.filter(|(_, w)| *w != 0.)
|
||||
.collect();
|
||||
out.spawners.insert(format!("{ns}:{path}"), mobs);
|
||||
continue;
|
||||
}
|
||||
for preset in v["presets"].as_array().into_iter().flatten() {
|
||||
if preset["default_enabled"].as_bool() != Some(true) {
|
||||
continue;
|
||||
}
|
||||
for r in preset["replacements"].as_array().into_iter().flatten() {
|
||||
if let Some(key) = r["vanilla_key"].as_str() {
|
||||
out.replace_vanilla.insert((ns.to_owned(), key.to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// Calls `f` on each processor list in a worldgen file: a `processor_list`
|
||||
/// file, and the inline lists of a template pool's elements (list elements
|
||||
/// included). Whether any call changed something.
|
||||
pub fn each_list(kind: &str, v: &mut Value, f: &mut dyn FnMut(&mut Value) -> bool) -> bool {
|
||||
match kind {
|
||||
"processor_list" => f(v),
|
||||
"template_pool" => {
|
||||
let mut changed = false;
|
||||
for e in v["elements"].as_array_mut().into_iter().flatten() {
|
||||
let element = &mut e["element"];
|
||||
if let Some(list) = element.get_mut("elements").and_then(Value::as_array_mut) {
|
||||
for inner in list {
|
||||
if let Some(p) = inner.get_mut("processors") {
|
||||
changed |= f(p);
|
||||
}
|
||||
}
|
||||
} else if let Some(p) = element.get_mut("processors") {
|
||||
changed |= f(p);
|
||||
}
|
||||
}
|
||||
changed
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The processors of a list: `{"processors": [...]}` or a bare list (an id
|
||||
/// names another file and is left alone).
|
||||
pub fn processors(list: &mut Value) -> Option<&mut Vec<Value>> {
|
||||
match list {
|
||||
Value::Array(a) => Some(a),
|
||||
Value::Object(o) => o.get_mut("processors").and_then(Value::as_array_mut),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Rewrites the processors of a worldgen file that have a data form; each is
|
||||
/// counted by type in `carried`. Whether anything changed.
|
||||
pub fn carry(
|
||||
kind: &str,
|
||||
v: &mut Value,
|
||||
data: &ProcessorData,
|
||||
carried: &mut BTreeMap<String, usize>,
|
||||
) -> bool {
|
||||
each_list(kind, v, &mut |list| {
|
||||
let Some(list) = processors(list) else {
|
||||
return false;
|
||||
};
|
||||
let mut changed = false;
|
||||
let mut out = Vec::with_capacity(list.len());
|
||||
for p in list.drain(..) {
|
||||
let kind = p["processor_type"].as_str().unwrap_or_default().to_owned();
|
||||
match as_data(&kind, &p, data) {
|
||||
Some(replacement) => {
|
||||
*carried.entry(kind).or_default() += 1;
|
||||
out.extend(replacement);
|
||||
changed = true;
|
||||
}
|
||||
None => out.push(p),
|
||||
}
|
||||
}
|
||||
*list = out;
|
||||
changed
|
||||
})
|
||||
}
|
||||
|
||||
/// The data form of a Java processor: the processors to put in its place
|
||||
/// (none for a no-op), or `None` when it has none.
|
||||
fn as_data(kind: &str, p: &Value, data: &ProcessorData) -> Option<Vec<Value>> {
|
||||
let (ns, _) = kind.split_once(':')?;
|
||||
Some(match kind {
|
||||
"moogs_structures:spawner_randomizing_processor" => {
|
||||
let mobs = p["weighted_entities"]
|
||||
.as_array()?
|
||||
.iter()
|
||||
.map(|e| {
|
||||
// The entry's NBT, then its id over it.
|
||||
let mut entity = match &e["nbt"] {
|
||||
Value::Object(o) => o.clone(),
|
||||
_ => serde_json::Map::new(),
|
||||
};
|
||||
entity.insert("id".into(), e["entity"].as_str()?.into());
|
||||
Some(json!({"entity": entity, "weight": e["weight"].as_f64()?}))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()?;
|
||||
vec![spawner_mobs(p, mobs, None)]
|
||||
}
|
||||
"repurposed_structures:spawner_randomizing_processor" => {
|
||||
// A list the mod does not ship falls back to a vanilla dungeon
|
||||
// mob in the mod; left out here.
|
||||
let list = data
|
||||
.spawners
|
||||
.get(p["rs_spawner_resourcelocation"].as_str()?)?;
|
||||
let mobs = list
|
||||
.iter()
|
||||
.map(|(id, weight)| json!({"entity": {"id": id}, "weight": weight}))
|
||||
.collect();
|
||||
vec![spawner_mobs(p, mobs, repurposed_light(p)?)]
|
||||
}
|
||||
"moogs_structures:vanilla_loot_swap_processor" => {
|
||||
let key = (
|
||||
p["modid"].as_str()?.to_owned(),
|
||||
p["vanilla_key"].as_str()?.to_owned(),
|
||||
);
|
||||
if data.replace_vanilla.contains(&key) {
|
||||
return None;
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
_ if ns == "betterdungeons" || ns == "betterdeserttemples" => vec![yung_spawner(kind, p)?],
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// [`as_data`]'s `horizon:spawner_mobs` for the mods' spawner randomizing
|
||||
/// processors, whose fields have the same names and defaults.
|
||||
fn spawner_mobs(p: &Value, mobs: Vec<Value>, rules: Option<Value>) -> Value {
|
||||
let mut out = json!({"processor_type": "horizon:spawner_mobs", "mobs": mobs});
|
||||
for key in [
|
||||
"delay",
|
||||
"min_spawn_delay",
|
||||
"max_spawn_delay",
|
||||
"spawn_count",
|
||||
"max_nearby_entities",
|
||||
"required_player_range",
|
||||
"spawn_range",
|
||||
] {
|
||||
if let Some(n) = p.get(key).filter(|n| n.is_i64()) {
|
||||
out[key] = n.clone();
|
||||
}
|
||||
}
|
||||
if let Some(r) = rules {
|
||||
out["custom_spawn_rules"] = r;
|
||||
}
|
||||
if let Some(b) = p.get("spawner_replacement_block") {
|
||||
out["replacement"] = b.clone();
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Repurposed Structures' `custom_spawn_rules` from its light level ranges:
|
||||
/// `Some(None)` without either, `None` when one does not read. The sky
|
||||
/// light's upper bound is written as `max_exclusive`, as the mod does.
|
||||
fn repurposed_light(p: &Value) -> Option<Option<Value>> {
|
||||
let range = |key: &str| -> Option<Option<(i64, i64)>> {
|
||||
match p.get(key) {
|
||||
None => Some(None),
|
||||
Some(Value::Number(n)) => n.as_i64().map(|n| Some((n, n))),
|
||||
Some(v) => Some(Some((
|
||||
v["min_inclusive"].as_i64()?,
|
||||
v["max_inclusive"].as_i64()?,
|
||||
))),
|
||||
}
|
||||
};
|
||||
let (block, sky) = (
|
||||
range("valid_block_light_level")?,
|
||||
range("valid_sky_light_level")?,
|
||||
);
|
||||
if block.is_none() && sky.is_none() {
|
||||
return Some(None);
|
||||
}
|
||||
let mut rules = json!({});
|
||||
if let Some((min, max)) = block {
|
||||
rules["block_light_limit"] = json!({"min_inclusive": min, "max_inclusive": max});
|
||||
}
|
||||
if let Some((min, max)) = sky {
|
||||
rules["sky_light_limit"] = json!({"min_inclusive": min, "max_exclusive": max});
|
||||
}
|
||||
Some(Some(rules))
|
||||
}
|
||||
|
||||
/// An item as 26.3 saves it.
|
||||
fn item(id: &str) -> Value {
|
||||
json!({"id": format!("minecraft:{id}"), "count": 1})
|
||||
}
|
||||
|
||||
/// YUNG's processors that make a spawner of a fixed mob (YUNG's API's
|
||||
/// `MobSpawnerData`), as vanilla's `rule`: every `input` block becomes a
|
||||
/// spawner with that NBT.
|
||||
fn yung_spawner(kind: &str, p: &Value) -> Option<Value> {
|
||||
const SPAWNER: &str = "minecraft:spawner";
|
||||
// (input block, mob, fields other than the defaults, whether the mob is
|
||||
// also the only potential, its equipment)
|
||||
let (input, mob, fields, potential, equipment): (_, _, &[(&str, i64)], _, _) = match kind {
|
||||
"betterdungeons:mob_spawner_processor" => {
|
||||
(SPAWNER, p["spawner_mob"].as_str()?, &[], true, None)
|
||||
}
|
||||
"betterdungeons:zombie_mob_spawner_processor" => (
|
||||
SPAWNER,
|
||||
"minecraft:zombie",
|
||||
&[("MaxNearbyEntities", 8)],
|
||||
true,
|
||||
None,
|
||||
),
|
||||
"betterdungeons:skeleton_mob_spawner_processor" => (
|
||||
SPAWNER,
|
||||
"minecraft:skeleton",
|
||||
&[
|
||||
("RequiredPlayerRange", 18),
|
||||
("MaxNearbyEntities", 8),
|
||||
("MaxSpawnDelay", 650),
|
||||
],
|
||||
true,
|
||||
None,
|
||||
),
|
||||
"betterdungeons:small_nether_dungeon_mob_spawner_processor" => {
|
||||
let mob = p["spawner_mob"].as_str()?;
|
||||
// Wither skeletons get netherite armor that never drops and a
|
||||
// stone sword (with the mod's default config, they and blazes
|
||||
// keep their loot).
|
||||
let armor = (mob == "minecraft:wither_skeleton").then(|| {
|
||||
json!({
|
||||
"equipment": {
|
||||
"feet": item("netherite_boots"),
|
||||
"legs": item("netherite_leggings"),
|
||||
"chest": item("netherite_chestplate"),
|
||||
"head": item("netherite_helmet"),
|
||||
"mainhand": item("stone_sword"),
|
||||
},
|
||||
"drop_chances": {"feet": 0.0, "legs": 0.0, "chest": 0.0, "head": 0.0},
|
||||
})
|
||||
});
|
||||
(SPAWNER, mob, &[], true, armor)
|
||||
}
|
||||
"betterdungeons:zombie_tombstone_spawner_processor" => (
|
||||
"minecraft:black_stained_glass",
|
||||
"minecraft:skeleton",
|
||||
&[],
|
||||
false,
|
||||
Some(json!({"equipment": {"mainhand": item("iron_sword")}})),
|
||||
),
|
||||
"betterdeserttemples:gravel_processor" => (
|
||||
"minecraft:gravel",
|
||||
"minecraft:husk",
|
||||
&[("MaxNearbyEntities", 8), ("RequiredPlayerRange", 24)],
|
||||
false,
|
||||
None,
|
||||
),
|
||||
// An empty hand list in 1.21.1: the skeletons spawn without a bow,
|
||||
// since a spawn entry with more than its id is not finalized.
|
||||
"betterdeserttemples:bone_block_processor" => (
|
||||
"minecraft:bone_block",
|
||||
"minecraft:skeleton",
|
||||
&[("RequiredPlayerRange", 32)],
|
||||
false,
|
||||
Some(json!({"equipment": {}})),
|
||||
),
|
||||
"betterdeserttemples:infested_cracked_stone_bricks_processor" => (
|
||||
"minecraft:infested_cracked_stone_bricks",
|
||||
"minecraft:silverfish",
|
||||
&[("RequiredPlayerRange", 24)],
|
||||
false,
|
||||
None,
|
||||
),
|
||||
// 1.21.1 ignores the items' old `Count` and `tag` (the shield's
|
||||
// pattern, the boots' dye): plain items.
|
||||
"betterdeserttemples:yellow_wool_processor" => (
|
||||
"minecraft:yellow_wool",
|
||||
"minecraft:husk",
|
||||
&[("MaxNearbyEntities", 8), ("RequiredPlayerRange", 24)],
|
||||
false,
|
||||
Some(json!({"equipment": {
|
||||
"mainhand": item("golden_sword"),
|
||||
"offhand": item("shield"),
|
||||
"feet": item("leather_boots"),
|
||||
"legs": item("leather_leggings"),
|
||||
"chest": item("golden_chestplate"),
|
||||
"head": item("chainmail_helmet"),
|
||||
}})),
|
||||
),
|
||||
_ => return None,
|
||||
};
|
||||
let mut entity = json!({"id": mob});
|
||||
if let Some(Value::Object(extra)) = equipment {
|
||||
entity.as_object_mut()?.extend(extra);
|
||||
}
|
||||
let potentials = match potential {
|
||||
true => json!([{"data": {"entity": entity.clone()}, "weight": 1}]),
|
||||
false => json!([]),
|
||||
};
|
||||
let mut nbt = json!({
|
||||
"Delay": 20, "MinSpawnDelay": 200, "MaxSpawnDelay": 800, "SpawnCount": 4,
|
||||
"MaxNearbyEntities": 6, "RequiredPlayerRange": 16, "SpawnRange": 4,
|
||||
"SpawnData": {"entity": entity},
|
||||
"SpawnPotentials": potentials,
|
||||
});
|
||||
for (key, value) in fields {
|
||||
nbt[*key] = (*value).into();
|
||||
}
|
||||
Some(json!({
|
||||
"processor_type": "minecraft:rule",
|
||||
"rules": [{
|
||||
"input_predicate": {"predicate_type": "minecraft:block_match", "block": input},
|
||||
"location_predicate": {"predicate_type": "minecraft:always_true"},
|
||||
"output_state": {"Name": SPAWNER},
|
||||
"block_entity_modifier": {"type": "minecraft:append_static", "data": nbt},
|
||||
}],
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn data() -> ProcessorData {
|
||||
let mut d = ProcessorData::default();
|
||||
d.spawners.insert(
|
||||
"repurposed_structures:dungeons/badlands".into(),
|
||||
vec![
|
||||
("minecraft:husk".into(), 10.),
|
||||
("minecraft:cave_spider".into(), 3.),
|
||||
],
|
||||
);
|
||||
d.replace_vanilla.insert(("mvs".into(), "village".into()));
|
||||
d
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawner_processors_become_data() {
|
||||
let mut list = json!({"processors": [
|
||||
{"processor_type": "moogs_structures:spawner_randomizing_processor",
|
||||
"weighted_entities": [{"entity": "minecraft:blaze", "weight": 2, "nbt": {"Health": 5}}],
|
||||
"spawn_count": 2, "spawner_replacement_block": {"Name": "minecraft:stone"}},
|
||||
{"processor_type": "repurposed_structures:spawner_randomizing_processor",
|
||||
"rs_spawner_resourcelocation": "repurposed_structures:dungeons/badlands",
|
||||
"valid_block_light_level": {"min_inclusive": 0, "max_inclusive": 7}},
|
||||
{"processor_type": "repurposed_structures:spawner_randomizing_processor",
|
||||
"rs_spawner_resourcelocation": "repurposed_structures:missing"},
|
||||
{"processor_type": "minecraft:gravity", "heightmap": "WORLD_SURFACE_WG", "offset": 0},
|
||||
{"processor_type": "moogs_structures:vanilla_loot_swap_processor",
|
||||
"modid": "mns", "vanilla_key": "fortress", "loot_table_mapping": {}},
|
||||
{"processor_type": "moogs_structures:vanilla_loot_swap_processor",
|
||||
"modid": "mvs", "vanilla_key": "village", "loot_table_mapping": {}}]});
|
||||
let mut carried = BTreeMap::new();
|
||||
assert!(carry("processor_list", &mut list, &data(), &mut carried));
|
||||
let p = list["processors"].as_array().unwrap();
|
||||
assert_eq!(p.len(), 5, "{p:#?}");
|
||||
assert_eq!(
|
||||
p[0],
|
||||
json!({"processor_type": "horizon:spawner_mobs",
|
||||
"mobs": [{"entity": {"Health": 5, "id": "minecraft:blaze"}, "weight": 2.0}],
|
||||
"spawn_count": 2, "replacement": {"Name": "minecraft:stone"}})
|
||||
);
|
||||
assert_eq!(
|
||||
p[1],
|
||||
json!({"processor_type": "horizon:spawner_mobs",
|
||||
"mobs": [{"entity": {"id": "minecraft:husk"}, "weight": 10.0},
|
||||
{"entity": {"id": "minecraft:cave_spider"}, "weight": 3.0}],
|
||||
"custom_spawn_rules": {"block_light_limit": {"min_inclusive": 0, "max_inclusive": 7}}})
|
||||
);
|
||||
// Unknown list, vanilla processor, and a swap whose preset is on: kept
|
||||
// (the Java ones are dropped later); the swap that is off is gone.
|
||||
assert_eq!(
|
||||
p[2]["rs_spawner_resourcelocation"],
|
||||
"repurposed_structures:missing"
|
||||
);
|
||||
assert_eq!(p[3]["processor_type"], "minecraft:gravity");
|
||||
assert_eq!(p[4]["modid"], "mvs");
|
||||
assert_eq!(
|
||||
carried,
|
||||
BTreeMap::from([
|
||||
("moogs_structures:spawner_randomizing_processor".into(), 1),
|
||||
("moogs_structures:vanilla_loot_swap_processor".into(), 1),
|
||||
(
|
||||
"repurposed_structures:spawner_randomizing_processor".into(),
|
||||
1
|
||||
),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn yungs_spawners_become_rules() {
|
||||
let mut pool = json!({"elements": [{"element": {"processors": {"processors": [
|
||||
{"processor_type": "betterdungeons:skeleton_mob_spawner_processor"},
|
||||
{"processor_type": "betterdeserttemples:bone_block_processor"},
|
||||
{"processor_type": "betterdungeons:small_nether_dungeon_mob_spawner_processor",
|
||||
"spawner_mob": "minecraft:wither_skeleton"},
|
||||
{"processor_type": "betterdungeons:candle_processor"}]}}}]});
|
||||
let mut carried = BTreeMap::new();
|
||||
assert!(carry("template_pool", &mut pool, &data(), &mut carried));
|
||||
let p = &pool["elements"][0]["element"]["processors"]["processors"];
|
||||
let rule = |i: usize| &p[i]["rules"][0];
|
||||
assert_eq!(rule(0)["input_predicate"]["block"], "minecraft:spawner");
|
||||
assert_eq!(
|
||||
rule(0)["output_state"],
|
||||
json!({"Name": "minecraft:spawner"})
|
||||
);
|
||||
let nbt = &rule(0)["block_entity_modifier"]["data"];
|
||||
assert_eq!(
|
||||
(
|
||||
nbt["RequiredPlayerRange"].clone(),
|
||||
nbt["MaxNearbyEntities"].clone()
|
||||
),
|
||||
(json!(18), json!(8))
|
||||
);
|
||||
assert_eq!(nbt["MaxSpawnDelay"], 650);
|
||||
assert_eq!(
|
||||
nbt["SpawnPotentials"],
|
||||
json!([{"data": {"entity": {"id": "minecraft:skeleton"}}, "weight": 1}])
|
||||
);
|
||||
// Bone blocks become bowless skeleton spawners with no potentials.
|
||||
let bone = &rule(1)["block_entity_modifier"]["data"];
|
||||
assert_eq!(rule(1)["input_predicate"]["block"], "minecraft:bone_block");
|
||||
assert_eq!(
|
||||
bone["SpawnData"],
|
||||
json!({"entity": {"id": "minecraft:skeleton", "equipment": {}}})
|
||||
);
|
||||
assert_eq!(bone["SpawnPotentials"], json!([]));
|
||||
let wither = &rule(2)["block_entity_modifier"]["data"]["SpawnData"]["entity"];
|
||||
assert_eq!(
|
||||
wither["equipment"]["head"]["id"],
|
||||
"minecraft:netherite_helmet"
|
||||
);
|
||||
assert_eq!(wither["drop_chances"]["feet"], 0.0);
|
||||
assert_eq!(p[3]["processor_type"], "betterdungeons:candle_processor");
|
||||
assert_eq!(carried.values().sum::<usize>(), 3);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,16 @@ const NETHER_JIGSAWS: [&str; 2] = [
|
||||
"moogs_structures:moogs_structures_generic_nether_jigsaw_structure",
|
||||
"repurposed_structures:generic_nether_jigsaw_structure",
|
||||
];
|
||||
/// Repurposed Structures' generic jigsaws with a start check of their own: the
|
||||
/// `repurposed` key of `horizon:start_checks` names it.
|
||||
const REPURPOSED_CHECKED: [(&str, &str); 3] = [
|
||||
("repurposed_structures:city_nether_structure", "city_nether"),
|
||||
(
|
||||
"repurposed_structures:shipwreck_nether_structure",
|
||||
"shipwreck_nether",
|
||||
),
|
||||
("repurposed_structures:stronghold_end", "stronghold_end"),
|
||||
];
|
||||
/// Layout rules the piece-limited assembler keeps (`horizon:piece_limited`).
|
||||
const PIECE_LIMITED_RULES: [&str; 4] = [
|
||||
"y_allowance",
|
||||
@@ -118,6 +128,9 @@ pub struct Upgrade {
|
||||
pub rules_lost: BTreeMap<String, usize>,
|
||||
/// Processors written in Java, taken out of their lists, by type.
|
||||
pub processors_dropped: BTreeMap<String, usize>,
|
||||
/// Processors written in Java carried as data the game runs
|
||||
/// ([`crate::processors`]), by type.
|
||||
pub processors_carried: BTreeMap<String, usize>,
|
||||
/// Entries added to other structure sets and template pools
|
||||
/// (`horizon:add_to`), by the set or pool they join.
|
||||
pub added_to: BTreeMap<String, usize>,
|
||||
@@ -332,49 +345,28 @@ pub fn upgrade(
|
||||
) -> bool {
|
||||
let states = block_states(v);
|
||||
report.block_states += usize::from(states);
|
||||
let dropped = match kind {
|
||||
"processor_list" => drop_java_processors(v, &mut report.processors_dropped),
|
||||
"template_pool" => {
|
||||
let mut changed = false;
|
||||
for e in v["elements"].as_array_mut().into_iter().flatten() {
|
||||
let element = &mut e["element"];
|
||||
if let Some(list) = element.get_mut("elements").and_then(Value::as_array_mut) {
|
||||
for inner in list {
|
||||
if let Some(p) = inner.get_mut("processors") {
|
||||
changed |= drop_java_processors(p, &mut report.processors_dropped);
|
||||
}
|
||||
}
|
||||
} else if let Some(p) = element.get_mut("processors") {
|
||||
changed |= drop_java_processors(p, &mut report.processors_dropped);
|
||||
}
|
||||
}
|
||||
changed
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
let dropped = crate::processors::each_list(kind, v, &mut |list| {
|
||||
drop_java_processors(list, &mut report.processors_dropped)
|
||||
});
|
||||
upgrade_types(kind, v, report, set_tags) || states || dropped
|
||||
}
|
||||
|
||||
/// Takes the processors written in Java (any type outside `minecraft:`)
|
||||
/// out of a processor list: `{"processors": [...]}`, a bare list, or an id
|
||||
/// (left as it is). The game, like vanilla, refuses a list holding a type it
|
||||
/// Takes the processors written in Java (any type outside `minecraft:` and
|
||||
/// the game's own `horizon:`) out of a processor list: `{"processors":
|
||||
/// [...]}`, a bare list, or an id (left as it is). The ones with a data form
|
||||
/// were rewritten before ([`crate::processors::carry`]). The game, like vanilla, refuses a list holding a type it
|
||||
/// does not know, and with it every pool that names the list, so without
|
||||
/// this the structure does not generate at all. Without them it generates
|
||||
/// undecorated: no pillars under it, spawners left as the template has
|
||||
/// them, blocks not swapped. Whether anything was taken out.
|
||||
fn drop_java_processors(list: &mut Value, dropped: &mut BTreeMap<String, usize>) -> bool {
|
||||
let processors = match list {
|
||||
Value::Array(a) => a,
|
||||
Value::Object(o) => match o.get_mut("processors") {
|
||||
Some(Value::Array(a)) => a,
|
||||
_ => return false,
|
||||
},
|
||||
_ => return false,
|
||||
let Some(processors) = crate::processors::processors(list) else {
|
||||
return false;
|
||||
};
|
||||
let before = processors.len();
|
||||
processors.retain(|p| {
|
||||
let t = p["processor_type"].as_str().unwrap_or_default();
|
||||
let java = !t.starts_with("minecraft:");
|
||||
let java = !t.starts_with("minecraft:") && !t.starts_with("horizon:");
|
||||
if java {
|
||||
*dropped.entry(t.to_owned()).or_default() += 1;
|
||||
}
|
||||
@@ -426,7 +418,13 @@ fn upgrade_types(
|
||||
yung_structure(v, lost);
|
||||
true
|
||||
}
|
||||
Some(t) if JIGSAWS.contains(&t) || NETHER_JIGSAWS.contains(&t) => {
|
||||
Some(t)
|
||||
if JIGSAWS.contains(&t)
|
||||
|| NETHER_JIGSAWS.contains(&t)
|
||||
|| REPURPOSED_CHECKED.iter().any(|(r, _)| *r == t) =>
|
||||
{
|
||||
let check = REPURPOSED_CHECKED.iter().find(|(r, _)| *r == t);
|
||||
let check = check.map(|(_, c)| *c);
|
||||
let library = match t.split_once(':').map(|(ns, _)| ns) {
|
||||
Some("moogs_structures") => Some("moogs"),
|
||||
Some("repurposed_structures") => Some("repurposed"),
|
||||
@@ -439,6 +437,12 @@ fn upgrade_types(
|
||||
};
|
||||
let limited = library.map(|l| piece_limited(v, l));
|
||||
start_checks(v, liquid, lost, limited.is_some());
|
||||
if let Some(check) = check {
|
||||
if !v["horizon:start_checks"].is_object() {
|
||||
v["horizon:start_checks"] = Value::Object(Default::default());
|
||||
}
|
||||
v["horizon:start_checks"]["repurposed"] = check.into();
|
||||
}
|
||||
if let Some(limited) = limited {
|
||||
v["horizon:piece_limited"] = limited;
|
||||
}
|
||||
@@ -1102,6 +1106,20 @@ mod tests {
|
||||
"cannot_spawn_in_liquid": true});
|
||||
assert!(upgrade("structure", &mut rs, &mut report, &NO_TAGS));
|
||||
assert_eq!(rs["horizon:start_checks"], json!({"liquid": "lowest"}));
|
||||
// Repurposed's own checks: the Nether city, Nether shipwrecks, the End stronghold.
|
||||
for (t, check) in [
|
||||
("city_nether_structure", "city_nether"),
|
||||
("shipwreck_nether_structure", "shipwreck_nether"),
|
||||
("stronghold_end", "stronghold_end"),
|
||||
] {
|
||||
let mut rs = json!({"type": format!("repurposed_structures:{t}"),
|
||||
"cannot_spawn_in_liquid": false, "size": 7});
|
||||
assert!(upgrade("structure", &mut rs, &mut report, &NO_TAGS));
|
||||
assert_eq!(rs["type"], "minecraft:jigsaw");
|
||||
assert_eq!(rs["horizon:start_checks"], json!({"repurposed": check}));
|
||||
assert_eq!(rs["horizon:piece_limited"]["library"], "repurposed");
|
||||
}
|
||||
assert!(report.unsupported.is_empty());
|
||||
// Nothing to check: no key.
|
||||
let mut plain = json!({"type": "lithostitched:jigsaw", "cannot_spawn_in_liquid": false});
|
||||
assert!(upgrade("structure", &mut plain, &mut report, &NO_TAGS));
|
||||
|
||||
@@ -10,6 +10,8 @@ description = "Host a Horizon server: server.toml, the CLI and the supervisor th
|
||||
horizon-server-files = { path = "../horizon-server-files" }
|
||||
# The game process's RAM and CPU (the same probes the benchmark reports use).
|
||||
horizon-bench = { path = "../horizon-bench" }
|
||||
# The log's local times, as the game prints them.
|
||||
chrono = { version = "0.4.42", default-features = false, features = ["clock", "std"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
toml = "1.1"
|
||||
|
||||
@@ -49,6 +49,52 @@ pub fn program(config: &Config, dir: &Path) -> Result<PathBuf, String> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Checks that the game program starts at all: `--help` loads no game files, so it fails only when the
|
||||
/// system can't load the program, as on a Linux without the ALSA and udev libraries it links (even a
|
||||
/// server needs them until there is a headless engine). The reason, with what to install.
|
||||
pub fn check_starts(program: &Path) -> Result<(), String> {
|
||||
let output = Command::new(program)
|
||||
.arg("--help")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.map_err(|e| format!("the game ({}) can't start: {e}", program.display()))?;
|
||||
if output.status.success() {
|
||||
return Ok(());
|
||||
}
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
Err(start_failure(program, output.status.code(), &stderr))
|
||||
}
|
||||
|
||||
/// What to tell the owner when the game program exits at once.
|
||||
fn start_failure(program: &Path, code: Option<i32>, stderr: &str) -> String {
|
||||
let reason = stderr
|
||||
.lines()
|
||||
.find(|l| !l.trim().is_empty())
|
||||
.unwrap_or("")
|
||||
.trim();
|
||||
let mut text = format!(
|
||||
"the game ({}) can't start{}{}",
|
||||
program.display(),
|
||||
code.map_or(String::new(), |c| format!(" (exit status {c})")),
|
||||
if reason.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(": {reason}")
|
||||
}
|
||||
);
|
||||
if reason.contains("error while loading shared libraries") {
|
||||
text.push_str(
|
||||
"\nIt needs ALSA's and udev's libraries (libasound.so.2, libudev.so.1), even on a server. Install \
|
||||
them:\n Debian, Ubuntu: sudo apt install libasound2 libudev1 (Ubuntu 24.04 and later: \
|
||||
libasound2t64)\n Fedora, RHEL: sudo dnf install alsa-lib systemd-libs\n Arch: sudo pacman -S \
|
||||
alsa-lib systemd-libs\n NixOS: enable programs.nix-ld with alsa-lib and udev in its libraries",
|
||||
);
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
/// Where the prepared game files may be, in the order they are tried.
|
||||
pub fn resource_candidates(config: &Config, dir: &Path, program: Option<&Path>) -> Vec<PathBuf> {
|
||||
if !config.engine.resources.is_empty() {
|
||||
@@ -65,12 +111,13 @@ pub fn resource_candidates(config: &Config, dir: &Path, program: Option<&Path>)
|
||||
out
|
||||
}
|
||||
|
||||
/// The prepared game files: a folder holding the asset index `horizon-prepare` writes.
|
||||
/// The prepared game files: a folder holding the manifest every `horizon-prepare` run writes
|
||||
/// (`asset-index.json` comes only with the optional sounds, which a server doesn't need).
|
||||
pub fn resources(config: &Config, dir: &Path, program: Option<&Path>) -> Result<PathBuf, String> {
|
||||
let candidates = resource_candidates(config, dir, program);
|
||||
candidates
|
||||
.iter()
|
||||
.find(|d| d.join("asset-index.json").is_file())
|
||||
.find(|d| d.join("horizon-resources.json").is_file())
|
||||
.cloned()
|
||||
.ok_or_else(|| {
|
||||
let tried: Vec<String> = candidates
|
||||
@@ -179,4 +226,65 @@ mod tests {
|
||||
[PathBuf::from("/data/res")]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resources_prepared_without_sounds_are_found() {
|
||||
let root = std::env::temp_dir().join(format!("horizon-server-res-{}", std::process::id()));
|
||||
let prepared = root.join(".local/horizon-client/26.3");
|
||||
std::fs::create_dir_all(&prepared).unwrap();
|
||||
let program = root.join("horizon-client");
|
||||
let config = Config::default();
|
||||
let server = root.join("server");
|
||||
assert!(resources(&config, &server, Some(&program)).is_err());
|
||||
// What `horizon-prepare` writes on every run; no asset index without `horizon-prepare sounds`.
|
||||
std::fs::write(prepared.join("horizon-resources.json"), "{}").unwrap();
|
||||
assert_eq!(resources(&config, &server, Some(&program)), Ok(prepared));
|
||||
std::fs::remove_dir_all(&root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_library_says_what_to_install() {
|
||||
let program = Path::new("/opt/horizon/horizon-client");
|
||||
let text = start_failure(
|
||||
program,
|
||||
Some(127),
|
||||
"/opt/horizon/horizon-client: error while loading shared libraries: libasound.so.2: cannot open \
|
||||
shared object file: No such file or directory\n",
|
||||
);
|
||||
assert!(text.starts_with(
|
||||
"the game (/opt/horizon/horizon-client) can't start (exit status 127): /opt/horizon/horizon-client: \
|
||||
error while loading shared libraries: libasound.so.2"
|
||||
));
|
||||
assert!(text.contains("sudo apt install libasound2 libudev1"));
|
||||
let other = start_failure(program, Some(1), "something else\n");
|
||||
assert_eq!(
|
||||
other,
|
||||
"the game (/opt/horizon/horizon-client) can't start (exit status 1): something else"
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn the_check_runs_the_program() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let root =
|
||||
std::env::temp_dir().join(format!("horizon-server-check-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
let script = |name: &str, body: &str| {
|
||||
let path = root.join(name);
|
||||
std::fs::write(&path, format!("#!/bin/sh\n{body}\n")).unwrap();
|
||||
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
|
||||
path
|
||||
};
|
||||
assert_eq!(check_starts(&script("starts", "exit 0")), Ok(()));
|
||||
let fails = script("fails", "echo 'no luck' >&2; exit 3");
|
||||
assert_eq!(
|
||||
check_starts(&fails),
|
||||
Err(format!(
|
||||
"the game ({}) can't start (exit status 3): no luck",
|
||||
fails.display()
|
||||
))
|
||||
);
|
||||
std::fs::remove_dir_all(&root).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +205,9 @@ pub fn run(dir: &Path, answers: Answers) -> Result<(), String> {
|
||||
match engine::program(&cfg, dir) {
|
||||
Ok(program) => {
|
||||
println!("Game: {}", program.display());
|
||||
if let Err(e) = engine::check_starts(&program) {
|
||||
println!("Warning: {e}");
|
||||
}
|
||||
match engine::resources(&cfg, dir, Some(&program)) {
|
||||
Ok(resources) => println!("Game files: {}", resources.display()),
|
||||
Err(e) => println!("{e}"),
|
||||
|
||||
@@ -32,7 +32,8 @@ pub fn name(dir: &Path) -> String {
|
||||
}
|
||||
|
||||
/// The program the service runs: the `horizon-server` on the PATH (the installer's launcher, which keeps
|
||||
/// running the current version after an update), else this program.
|
||||
/// running the current version after an update), else this program, through the installer's `current`
|
||||
/// link when it runs from an installed release.
|
||||
fn program() -> Result<PathBuf, String> {
|
||||
let on_path = std::env::var_os("PATH")
|
||||
.map(|p| std::env::split_paths(&p).collect::<Vec<_>>())
|
||||
@@ -42,10 +43,30 @@ fn program() -> Result<PathBuf, String> {
|
||||
.find(|p| p.is_file());
|
||||
match on_path {
|
||||
Some(path) => Ok(path),
|
||||
None => std::env::current_exe().map_err(|e| e.to_string()),
|
||||
None => std::env::current_exe()
|
||||
.map(|exe| through_current(&exe))
|
||||
.map_err(|e| e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
/// `<dir>/releases/<tag>/horizon-server` as `<dir>/current/horizon-server` while `current` points at that
|
||||
/// release (install.sh and install.ps1's layout), so an update applies at the next restart. Linux reports
|
||||
/// the running program with links resolved, so the release's own path is what this program sees there.
|
||||
fn through_current(exe: &Path) -> PathBuf {
|
||||
let current = (|| {
|
||||
let release = exe.parent()?;
|
||||
let releases = release.parent()?;
|
||||
if releases.file_name()? != "releases" {
|
||||
return None;
|
||||
}
|
||||
let current = releases.parent()?.join("current");
|
||||
let name = exe.file_name()?;
|
||||
let same = std::fs::canonicalize(¤t).ok()? == std::fs::canonicalize(release).ok()?;
|
||||
same.then(|| current.join(name))
|
||||
})();
|
||||
current.unwrap_or_else(|| exe.to_path_buf())
|
||||
}
|
||||
|
||||
/// A systemd unit: a user unit, or with `user` a system unit running as that user.
|
||||
pub fn systemd_unit(program: &Path, dir: &Path, user: Option<&str>) -> String {
|
||||
let (run_as, wanted_by) = match user {
|
||||
@@ -374,4 +395,22 @@ mod tests {
|
||||
assert!(plist.contains("<string>/srv/R&D</string>"));
|
||||
assert!(plist.contains("<string>/srv/R&D/logs/supervisor.log</string>"));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn an_installed_release_runs_through_current() {
|
||||
let root =
|
||||
std::env::temp_dir().join(format!("horizon-service-current-{}", std::process::id()));
|
||||
let release = root.join("releases/v1");
|
||||
std::fs::create_dir_all(&release).unwrap();
|
||||
let exe = release.join("horizon-server");
|
||||
std::fs::write(&exe, "").unwrap();
|
||||
// Not the release in use (or no installer layout): this program as it is.
|
||||
assert_eq!(through_current(&exe), exe);
|
||||
std::os::unix::fs::symlink(&release, root.join("current")).unwrap();
|
||||
assert_eq!(through_current(&exe), root.join("current/horizon-server"));
|
||||
let other = root.join("bin/horizon-server");
|
||||
assert_eq!(through_current(&other), other);
|
||||
std::fs::remove_dir_all(&root).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use crate::{
|
||||
config::Config,
|
||||
engine, signals,
|
||||
};
|
||||
use horizon_server_files::java_properties::now_millis;
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
fs::File,
|
||||
@@ -29,15 +28,12 @@ const MAX_BACKOFF: Duration = Duration::from_secs(300);
|
||||
/// How long `stop` may take before the game is killed.
|
||||
const STOP_TIMEOUT: Duration = Duration::from_secs(120);
|
||||
|
||||
/// A line from the supervisor, in the game's log format (`[HH:mm:ss] [thread/LEVEL]: message`, UTC), on
|
||||
/// stdout and in the log the API serves.
|
||||
/// A line from the supervisor, in the game's log format (`[HH:mm:ss] [thread/LEVEL]: message`, local time
|
||||
/// as the game's own lines), on stdout and in the log the API serves.
|
||||
fn note(shared: &Shared, level: &str, message: &str) {
|
||||
let secs = now_millis().div_euclid(1000).rem_euclid(86_400);
|
||||
let line = format!(
|
||||
"[{:02}:{:02}:{:02}] [Supervisor/{level}]: {message}",
|
||||
secs / 3600,
|
||||
secs / 60 % 60,
|
||||
secs % 60
|
||||
"[{}] [Supervisor/{level}]: {message}",
|
||||
chrono::Local::now().format("%H:%M:%S")
|
||||
);
|
||||
println!("{line}");
|
||||
shared.log.lock().unwrap().push(line);
|
||||
@@ -76,6 +72,8 @@ pub fn run(dir: &Path) -> Result<(), String> {
|
||||
let config = Config::load(dir)?;
|
||||
let program = engine::program(&config, dir)?;
|
||||
let resources = engine::resources(&config, dir, Some(&program))?;
|
||||
// A game the system can't load would only crash again at every restart: say why at once.
|
||||
engine::check_starts(&program)?;
|
||||
let _lock = lock(dir)?;
|
||||
let shared = Shared::new(dir);
|
||||
let _endpoint = api::start(shared.clone())?;
|
||||
|
||||
@@ -57,6 +57,58 @@ enum Modifier {
|
||||
AppendLoot(String),
|
||||
AppendStatic(Compound),
|
||||
}
|
||||
impl PosRule {
|
||||
/// A rule's `position_predicate` (always true when missing). Types are
|
||||
/// identifiers: `"always_true"` is `minecraft:always_true`, as vanilla
|
||||
/// reads it.
|
||||
fn decode(value: Option<&Value>) -> Result<Self, DecodeError> {
|
||||
let Some(p) = value else {
|
||||
return Ok(Self::Always);
|
||||
};
|
||||
let kind = p["predicate_type"]
|
||||
.as_str()
|
||||
.unwrap_or("minecraft:always_true");
|
||||
Ok(match super::super::tags::identifier(kind)?.as_str() {
|
||||
"minecraft:always_true" => Self::Always,
|
||||
kind @ ("minecraft:linear_pos" | "minecraft:axis_aligned_linear_pos") => Self::Linear {
|
||||
min_chance: p.get("min_chance").and_then(Value::as_f64).unwrap_or(0.) as f32,
|
||||
max_chance: p.get("max_chance").and_then(Value::as_f64).unwrap_or(0.) as f32,
|
||||
min_dist: p.get("min_dist").and_then(Value::as_i64).unwrap_or(0) as i32,
|
||||
max_dist: p.get("max_dist").and_then(Value::as_i64).unwrap_or(0) as i32,
|
||||
axis: (kind == "minecraft:axis_aligned_linear_pos").then(|| {
|
||||
match p.get("axis").and_then(Value::as_str) {
|
||||
Some("x") => 0,
|
||||
Some("z") => 2,
|
||||
_ => 1,
|
||||
}
|
||||
}),
|
||||
},
|
||||
_ => return Err(DecodeError::Field("position predicate")),
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Modifier {
|
||||
/// A rule's `block_entity_modifier` (passthrough when missing).
|
||||
fn decode(value: Option<&Value>) -> Result<Self, DecodeError> {
|
||||
let Some(m) = value else {
|
||||
return Ok(Self::Passthrough);
|
||||
};
|
||||
Ok(
|
||||
match super::super::tags::identifier(m["type"].as_str().unwrap_or(""))?.as_str() {
|
||||
"minecraft:passthrough" => Self::Passthrough,
|
||||
"minecraft:clear" => Self::Clear,
|
||||
"minecraft:append_loot" => {
|
||||
Self::AppendLoot(m["loot_table"].as_str().unwrap_or_default().to_owned())
|
||||
}
|
||||
"minecraft:append_static" => match json_to_nbt(&m["data"]) {
|
||||
Tag::Compound(c) => Self::AppendStatic(c),
|
||||
_ => Self::AppendStatic(Compound::new()),
|
||||
},
|
||||
_ => return Err(DecodeError::Field("block entity modifier")),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Rule {
|
||||
input: RuleTest,
|
||||
@@ -87,10 +139,119 @@ pub enum Processor {
|
||||
BlockAge(f32),
|
||||
LavaSubmerged,
|
||||
BlackstoneReplace,
|
||||
SpawnerMobs(Box<SpawnerMobs>),
|
||||
}
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct ProcessorList(pub Vec<Processor>);
|
||||
|
||||
/// The spawner fields `horizon:spawner_mobs` writes: its JSON key, the NBT
|
||||
/// key and the default (BaseSpawner's).
|
||||
const SPAWNER_FIELDS: [(&str, &str, i16); 7] = [
|
||||
("delay", "Delay", 20),
|
||||
("min_spawn_delay", "MinSpawnDelay", 200),
|
||||
("max_spawn_delay", "MaxSpawnDelay", 800),
|
||||
("spawn_count", "SpawnCount", 4),
|
||||
("max_nearby_entities", "MaxNearbyEntities", 6),
|
||||
("required_player_range", "RequiredPlayerRange", 16),
|
||||
("spawn_range", "SpawnRange", 4),
|
||||
];
|
||||
|
||||
/// `horizon:spawner_mobs`, which `horizon-port-pack` writes for the spawner
|
||||
/// randomizing processors of Moog's Structure Lib and Repurposed Structures
|
||||
/// (Java code in the mods): a spawner gets one mob of a weighted list,
|
||||
/// picked with `settings.getRandom(pos).nextFloat()` as theirs do, and the
|
||||
/// spawner NBT they write. With no mob to pick it becomes `replacement`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SpawnerMobs {
|
||||
/// Each mob's entity compound (its `id` and any NBT) and weight.
|
||||
mobs: Vec<(Compound, f64)>,
|
||||
/// [`SPAWNER_FIELDS`]' values.
|
||||
fields: [i16; 7],
|
||||
/// `custom_spawn_rules`, in `SpawnData` and the potential alike.
|
||||
rules: Option<Compound>,
|
||||
replacement: BlockStateId,
|
||||
}
|
||||
impl SpawnerMobs {
|
||||
fn decode(
|
||||
value: &Value,
|
||||
replacement: impl FnOnce(Option<&Value>) -> Result<BlockStateId, DecodeError>,
|
||||
) -> Result<Self, DecodeError> {
|
||||
let mobs = value["mobs"]
|
||||
.as_array()
|
||||
.ok_or(DecodeError::Field("spawner_mobs mobs"))?
|
||||
.iter()
|
||||
.map(
|
||||
|m| match (json_to_nbt(&m["entity"]), m["weight"].as_f64()) {
|
||||
(Tag::Compound(entity), Some(weight))
|
||||
if entity.contains_key(&JavaString::from("id")) =>
|
||||
{
|
||||
Ok((entity, weight))
|
||||
}
|
||||
_ => Err(DecodeError::Field("spawner_mobs mob")),
|
||||
},
|
||||
)
|
||||
.collect::<Result<_, _>>()?;
|
||||
let mut fields = [0; 7];
|
||||
for (field, (key, _, default)) in fields.iter_mut().zip(SPAWNER_FIELDS) {
|
||||
// The mods' codecs read ints; the spawner saves them as shorts.
|
||||
*field = value
|
||||
.get(key)
|
||||
.map_or(Some(default), |v| v.as_i64().map(|v| v as i16))
|
||||
.ok_or(DecodeError::Field("spawner_mobs field"))?;
|
||||
}
|
||||
let rules = match value.get("custom_spawn_rules").map(json_to_nbt) {
|
||||
None => None,
|
||||
Some(Tag::Compound(c)) => Some(c),
|
||||
Some(_) => return Err(DecodeError::Field("spawner_mobs custom_spawn_rules")),
|
||||
};
|
||||
Ok(Self {
|
||||
mobs,
|
||||
fields,
|
||||
rules,
|
||||
replacement: replacement(value.get("replacement"))?,
|
||||
})
|
||||
}
|
||||
/// The mob for a spawner, drawing from `random` only when there is one
|
||||
/// to pick (pickWeightedRandom; Repurposed Structures' getSpawnerMob,
|
||||
/// whose float product can round differently only on a boundary).
|
||||
fn pick(&self, random: impl FnOnce() -> f32) -> Option<&Compound> {
|
||||
let total: f64 = self.mobs.iter().map(|m| m.1).sum();
|
||||
if self.mobs.is_empty() || total <= 0. {
|
||||
return None;
|
||||
}
|
||||
let mut pick = f64::from(random()) * total;
|
||||
for (entity, weight) in &self.mobs {
|
||||
pick -= weight;
|
||||
if pick <= 0. {
|
||||
return Some(entity);
|
||||
}
|
||||
}
|
||||
self.mobs.last().map(|m| &m.0)
|
||||
}
|
||||
/// The spawner's NBT with `entity` as its only potential and next spawn.
|
||||
fn nbt(&self, entity: &Compound) -> Compound {
|
||||
let mut data = Compound::new();
|
||||
data.insert("entity".into(), Tag::Compound(entity.clone()));
|
||||
if let Some(rules) = &self.rules {
|
||||
data.insert("custom_spawn_rules".into(), Tag::Compound(rules.clone()));
|
||||
}
|
||||
let mut potential = Compound::new();
|
||||
potential.insert("data".into(), Tag::Compound(data.clone()));
|
||||
potential.insert("weight".into(), Tag::Int(1));
|
||||
let mut nbt: Compound = SPAWNER_FIELDS
|
||||
.iter()
|
||||
.zip(self.fields)
|
||||
.map(|((_, key, _), v)| (JavaString::from(*key), Tag::Short(v)))
|
||||
.collect();
|
||||
nbt.insert(
|
||||
"SpawnPotentials".into(),
|
||||
Tag::List(vec![Tag::Compound(potential)]),
|
||||
);
|
||||
nbt.insert("SpawnData".into(), Tag::Compound(data));
|
||||
nbt
|
||||
}
|
||||
}
|
||||
|
||||
fn holder_set(
|
||||
value: &Value,
|
||||
bindings: &FeatureBlockBindings<'_>,
|
||||
@@ -208,55 +369,8 @@ impl Processor {
|
||||
.iter()
|
||||
.map(|rule| {
|
||||
let test = |key| RuleTest::from_json(&rule[key].to_string(), bindings);
|
||||
let position = match rule.get("position_predicate") {
|
||||
Some(p) => match p["predicate_type"]
|
||||
.as_str()
|
||||
.unwrap_or("minecraft:always_true")
|
||||
{
|
||||
"minecraft:always_true" => PosRule::Always,
|
||||
kind @ ("minecraft:linear_pos"
|
||||
| "minecraft:axis_aligned_linear_pos") => PosRule::Linear {
|
||||
min_chance: p
|
||||
.get("min_chance")
|
||||
.and_then(Value::as_f64)
|
||||
.unwrap_or(0.)
|
||||
as f32,
|
||||
max_chance: p
|
||||
.get("max_chance")
|
||||
.and_then(Value::as_f64)
|
||||
.unwrap_or(0.)
|
||||
as f32,
|
||||
min_dist: p.get("min_dist").and_then(Value::as_i64).unwrap_or(0)
|
||||
as i32,
|
||||
max_dist: p.get("max_dist").and_then(Value::as_i64).unwrap_or(0)
|
||||
as i32,
|
||||
axis: (kind == "minecraft:axis_aligned_linear_pos").then(
|
||||
|| match p.get("axis").and_then(Value::as_str) {
|
||||
Some("x") => 0,
|
||||
Some("z") => 2,
|
||||
_ => 1,
|
||||
},
|
||||
),
|
||||
},
|
||||
_ => return Err(DecodeError::Field("position predicate")),
|
||||
},
|
||||
None => PosRule::Always,
|
||||
};
|
||||
let modifier = match rule.get("block_entity_modifier") {
|
||||
None => Modifier::Passthrough,
|
||||
Some(m) => match m["type"].as_str().unwrap_or("") {
|
||||
"minecraft:passthrough" => Modifier::Passthrough,
|
||||
"minecraft:clear" => Modifier::Clear,
|
||||
"minecraft:append_loot" => Modifier::AppendLoot(
|
||||
m["loot_table"].as_str().unwrap_or_default().to_owned(),
|
||||
),
|
||||
"minecraft:append_static" => match json_to_nbt(&m["data"]) {
|
||||
Tag::Compound(c) => Modifier::AppendStatic(c),
|
||||
_ => Modifier::AppendStatic(Compound::new()),
|
||||
},
|
||||
_ => return Err(DecodeError::Field("block entity modifier")),
|
||||
},
|
||||
};
|
||||
let position = PosRule::decode(rule.get("position_predicate"))?;
|
||||
let modifier = Modifier::decode(rule.get("block_entity_modifier"))?;
|
||||
Ok(Rule {
|
||||
input: test("input_predicate")?,
|
||||
location: test("location_predicate")?,
|
||||
@@ -267,6 +381,12 @@ impl Processor {
|
||||
})
|
||||
.collect::<Result<_, DecodeError>>()?,
|
||||
),
|
||||
"horizon:spawner_mobs" => {
|
||||
Self::SpawnerMobs(Box::new(SpawnerMobs::decode(value, |v| match v {
|
||||
Some(v) => state(v),
|
||||
None => Ok(resources.registry.default_state("minecraft:air").unwrap()),
|
||||
})?))
|
||||
}
|
||||
_ => return Err(DecodeError::Field("structure processor type")),
|
||||
})
|
||||
}
|
||||
@@ -532,6 +652,24 @@ fn process_block<W: PlacementContext>(
|
||||
Some(info)
|
||||
}
|
||||
Processor::Capped { .. } => Some(info),
|
||||
Processor::SpawnerMobs(spawner) => {
|
||||
if name(info.state) != "minecraft:spawner" {
|
||||
return Ok(Some(info));
|
||||
}
|
||||
let pos = info.pos;
|
||||
let entity = spawner.pick(|| settings.with_random(pos, |r| r.float()));
|
||||
Some(match entity {
|
||||
Some(entity) => BlockInfo {
|
||||
nbt: Some(spawner.nbt(entity)),
|
||||
..info
|
||||
},
|
||||
None => BlockInfo {
|
||||
pos,
|
||||
state: spawner.replacement,
|
||||
nbt: None,
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
fn block_age(
|
||||
@@ -1021,3 +1159,127 @@ fn update_shape_at_edge<W: PlacementContext>(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
fn spawner(value: Value) -> SpawnerMobs {
|
||||
SpawnerMobs::decode(&value, |v| {
|
||||
assert_eq!(v, Some(&json!({"id": "minecraft:cobblestone"})));
|
||||
Ok(BlockStateId(7))
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
fn id(entity: Option<&Compound>) -> Option<String> {
|
||||
match entity?.get(&JavaString::from("id")) {
|
||||
Some(Tag::String(s)) => Some(s.to_string_lossy()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawner_mobs_pick_by_weight() {
|
||||
let s = spawner(json!({
|
||||
"mobs": [
|
||||
{"entity": {"id": "minecraft:zombie"}, "weight": 1},
|
||||
{"entity": {"id": "minecraft:husk"}, "weight": 3}],
|
||||
"replacement": {"id": "minecraft:cobblestone"}}));
|
||||
// pick = nextFloat * 4, less each weight in turn, until <= 0.
|
||||
for (r, mob) in [
|
||||
(0., "zombie"),
|
||||
(0.25, "zombie"),
|
||||
(0.2501, "husk"),
|
||||
(0.999, "husk"),
|
||||
] {
|
||||
assert_eq!(id(s.pick(|| r)), Some(format!("minecraft:{mob}")), "{r}");
|
||||
}
|
||||
let empty = spawner(json!({"mobs": [], "replacement": {"id": "minecraft:cobblestone"}}));
|
||||
assert_eq!(empty.pick(|| unreachable!()), None);
|
||||
assert_eq!(empty.replacement, BlockStateId(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawner_mobs_write_the_mods_nbt() {
|
||||
let s = spawner(json!({
|
||||
"mobs": [{"entity": {"id": "minecraft:skeleton", "Health": 30}, "weight": 2}],
|
||||
"delay": 10, "spawn_count": 2,
|
||||
"custom_spawn_rules": {"block_light_limit": {"min_inclusive": 0, "max_inclusive": 7}},
|
||||
"replacement": {"id": "minecraft:cobblestone"}}));
|
||||
let nbt = s.nbt(s.pick(|| 0.5).unwrap());
|
||||
let short = |k: &str| nbt.get(&JavaString::from(k)).cloned();
|
||||
for (k, v) in [
|
||||
("Delay", 10),
|
||||
("MinSpawnDelay", 200),
|
||||
("MaxSpawnDelay", 800),
|
||||
("SpawnCount", 2),
|
||||
("MaxNearbyEntities", 6),
|
||||
("RequiredPlayerRange", 16),
|
||||
("SpawnRange", 4),
|
||||
] {
|
||||
assert_eq!(short(k), Some(Tag::Short(v)), "{k}");
|
||||
}
|
||||
let Some(Tag::Compound(data)) = short("SpawnData") else {
|
||||
panic!("SpawnData")
|
||||
};
|
||||
assert!(data.contains_key(&JavaString::from("custom_spawn_rules")));
|
||||
let Some(Tag::Compound(entity)) = data.get(&JavaString::from("entity")) else {
|
||||
panic!("entity")
|
||||
};
|
||||
assert_eq!(entity.get(&JavaString::from("Health")), Some(&Tag::Int(30)));
|
||||
let Some(Tag::List(potentials)) = short("SpawnPotentials") else {
|
||||
panic!("SpawnPotentials")
|
||||
};
|
||||
let Tag::Compound(potential) = &potentials[0] else {
|
||||
panic!("potential")
|
||||
};
|
||||
assert_eq!(
|
||||
potential.get(&JavaString::from("weight")),
|
||||
Some(&Tag::Int(1))
|
||||
);
|
||||
assert_eq!(
|
||||
potential.get(&JavaString::from("data")),
|
||||
Some(&Tag::Compound(data.clone()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawner_mobs_refuse_a_mob_without_an_id() {
|
||||
let bad = json!({"mobs": [{"entity": {}, "weight": 1}]});
|
||||
assert!(SpawnerMobs::decode(&bad, |_| Ok(BlockStateId(0))).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rule_parts_read_ids_without_a_namespace() {
|
||||
// CTOV writes "always_true"; vanilla reads it as minecraft:always_true.
|
||||
for kind in ["always_true", "minecraft:always_true"] {
|
||||
let p = json!({"predicate_type": kind});
|
||||
assert!(
|
||||
matches!(PosRule::decode(Some(&p)), Ok(PosRule::Always)),
|
||||
"{kind}"
|
||||
);
|
||||
}
|
||||
let linear = json!({"predicate_type": "axis_aligned_linear_pos", "axis": "z",
|
||||
"min_chance": 0.1, "max_dist": 8});
|
||||
assert!(matches!(
|
||||
PosRule::decode(Some(&linear)),
|
||||
Ok(PosRule::Linear {
|
||||
axis: Some(2),
|
||||
max_dist: 8,
|
||||
..
|
||||
})
|
||||
));
|
||||
assert!(PosRule::decode(Some(&json!({"predicate_type": "x:unknown"}))).is_err());
|
||||
assert!(matches!(PosRule::decode(None), Ok(PosRule::Always)));
|
||||
let loot = json!({"type": "append_loot", "loot_table": "minecraft:chests/x"});
|
||||
assert!(
|
||||
matches!(Modifier::decode(Some(&loot)), Ok(Modifier::AppendLoot(t)) if t == "minecraft:chests/x")
|
||||
);
|
||||
assert!(matches!(
|
||||
Modifier::decode(Some(&json!({"type": "clear"}))),
|
||||
Ok(Modifier::Clear)
|
||||
));
|
||||
assert!(Modifier::decode(Some(&json!({"type": ""}))).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,15 @@
|
||||
//! "terrain_radius": 1, // chunks, with terrain_range and/or min_y, max_y
|
||||
//! "terrain_range": 15,
|
||||
//! "min_y": 60,
|
||||
//! "max_y": 200
|
||||
//! "max_y": 200,
|
||||
//! "repurposed": "city_nether" // or "shipwreck_nether", "stronghold_end": below
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! `repurposed` is the extra check of one of Repurposed Structures' jigsaw
|
||||
//! types, after the others: its Nether city needs open air above the lava sea
|
||||
//! in the chunks around, its Nether shipwreck open air or lava around the
|
||||
//! start, and its End stronghold land around the chunk.
|
||||
use crate::{heightmap::HeightmapType, worldgen::biome::BiomeId};
|
||||
use horizon_core::position::ChunkPos;
|
||||
use serde_json::Value;
|
||||
@@ -33,6 +39,20 @@ pub enum LiquidCheck {
|
||||
Lowest,
|
||||
}
|
||||
|
||||
/// The extra start check of a Repurposed Structures jigsaw type.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Repurposed {
|
||||
/// CityNetherStructure: air from sea level + 20 to + 45 (or the top of
|
||||
/// the noise) at the corner of each of the 8 chunks around.
|
||||
CityNether,
|
||||
/// ShipwreckNetherStructure: no solid block at 5×5 columns 8 apart
|
||||
/// around the chunk corner, from the start height up 30 in steps of 5.
|
||||
ShipwreckNether,
|
||||
/// StrongholdEndStructure: land at least 45 above the bottom 35 and 70
|
||||
/// blocks away in each direction and at the chunk corner.
|
||||
StrongholdEnd,
|
||||
}
|
||||
|
||||
/// The checks of one structure; all empty for vanilla's.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct StartChecks {
|
||||
@@ -42,6 +62,7 @@ pub struct StartChecks {
|
||||
terrain_range: Option<i32>,
|
||||
min_y: Option<i32>,
|
||||
max_y: Option<i32>,
|
||||
repurposed: Option<Repurposed>,
|
||||
}
|
||||
|
||||
/// The column and biome queries the checks need.
|
||||
@@ -53,6 +74,9 @@ pub trait CheckQueries {
|
||||
/// and does not block motion is a liquid.
|
||||
fn liquid_column(&mut self, x: i32, z: i32) -> (Vec<bool>, Vec<bool>);
|
||||
fn noise_biome(&mut self, quart: [i32; 3]) -> BiomeId;
|
||||
fn sea_level(&self) -> i32;
|
||||
/// The noise's bottom, where the columns start.
|
||||
fn bottom(&self) -> i32;
|
||||
}
|
||||
|
||||
impl<T: super::start::StartContext> CheckQueries for T {
|
||||
@@ -71,6 +95,12 @@ impl<T: super::start::StartContext> CheckQueries for T {
|
||||
fn noise_biome(&mut self, quart: [i32; 3]) -> BiomeId {
|
||||
super::start::StartContext::noise_biome(self, quart)
|
||||
}
|
||||
fn sea_level(&self) -> i32 {
|
||||
super::start::StartContext::sea_level(self)
|
||||
}
|
||||
fn bottom(&self) -> i32 {
|
||||
self.min_y()
|
||||
}
|
||||
}
|
||||
|
||||
impl StartChecks {
|
||||
@@ -91,6 +121,12 @@ impl StartChecks {
|
||||
terrain_range: int("terrain_range"),
|
||||
min_y: int("min_y"),
|
||||
max_y: int("max_y"),
|
||||
repurposed: match v.get("repurposed").and_then(Value::as_str) {
|
||||
Some("city_nether") => Some(Repurposed::CityNether),
|
||||
Some("shipwreck_nether") => Some(Repurposed::ShipwreckNether),
|
||||
Some("stronghold_end") => Some(Repurposed::StrongholdEnd),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +191,76 @@ impl StartChecks {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
match self.repurposed {
|
||||
Some(check) => repurposed(check, queries, chunk, y),
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Repurposed`]'s checks. A noise column reads air past its ends; its
|
||||
/// length is the noise's depth (GeneralUtils.getMaxTerrainLimit).
|
||||
fn repurposed(check: Repurposed, queries: &mut impl CheckQueries, chunk: ChunkPos, y: i32) -> bool {
|
||||
let (x0, z0) = (chunk.x * 16, chunk.z * 16);
|
||||
let bottom = queries.bottom();
|
||||
let at = |column: &[bool], y: i32| {
|
||||
usize::try_from(y - bottom)
|
||||
.ok()
|
||||
.and_then(|i| column.get(i).copied())
|
||||
.unwrap_or(false)
|
||||
};
|
||||
match check {
|
||||
Repurposed::CityNether => {
|
||||
let sea = queries.sea_level();
|
||||
for cx in chunk.x - 1..=chunk.x + 1 {
|
||||
for cz in chunk.z - 1..=chunk.z + 1 {
|
||||
if (cx, cz) == (chunk.x, chunk.z) {
|
||||
continue;
|
||||
}
|
||||
let (filled, _) = queries.liquid_column(cx << 4, cz << 4);
|
||||
let top = (bottom + filled.len() as i32).min(sea + 45);
|
||||
if (sea + 20..top).any(|y| at(&filled, y)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Repurposed::ShipwreckNether => {
|
||||
for dx in (-16..=16).step_by(8) {
|
||||
for dz in (-16..=16).step_by(8) {
|
||||
let (filled, solid) = queries.liquid_column(x0 + dx, z0 + dz);
|
||||
// Not air and no fluid: in a noise column, a solid block.
|
||||
if (0..=30)
|
||||
.step_by(5)
|
||||
.any(|dy| at(&filled, y + dy) && at(&solid, y + dy))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Repurposed::StrongholdEnd => {
|
||||
let (filled, _) = queries.liquid_column(x0, z0);
|
||||
let min_land = (bottom + filled.len() as i32).min(bottom + 45);
|
||||
// getHeightAt: the lowest height so far, less one at every sample.
|
||||
let mut land = i32::MAX;
|
||||
let mut sample = |x: i32, z: i32, land: &mut i32| {
|
||||
let h = queries.first_free_height(x, z, HeightmapType::WorldSurfaceWg);
|
||||
*land = (*land).min(h) - 1;
|
||||
*land >= min_land
|
||||
};
|
||||
for distance in [70, 35] {
|
||||
// Direction.Plane.HORIZONTAL: north, east, south, west.
|
||||
for (dx, dz) in [(0, -1), (1, 0), (0, 1), (-1, 0)] {
|
||||
if !sample(x0 + dx * distance, z0 + dz * distance, &mut land) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
sample(x0, z0, &mut land)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,18 +277,27 @@ mod tests {
|
||||
column: Vec<char>,
|
||||
biomes: BTreeMap<(i32, i32), u32>,
|
||||
asked: Vec<[i32; 3]>,
|
||||
/// Columns by (x, z), instead of `column`, from y 0.
|
||||
columns: BTreeMap<(i32, i32), Vec<char>>,
|
||||
}
|
||||
impl CheckQueries for Fake {
|
||||
fn first_free_height(&mut self, x: i32, z: i32, _: HeightmapType) -> i32 {
|
||||
self.heights.get(&(x, z)).copied().unwrap_or(64)
|
||||
}
|
||||
fn liquid_column(&mut self, _: i32, _: i32) -> (Vec<bool>, Vec<bool>) {
|
||||
fn liquid_column(&mut self, x: i32, z: i32) -> (Vec<bool>, Vec<bool>) {
|
||||
// '.' air, '#' stone, '~' water, from the bottom up.
|
||||
let column = self.columns.get(&(x, z)).unwrap_or(&self.column);
|
||||
(
|
||||
self.column.iter().map(|&c| c != '.').collect(),
|
||||
self.column.iter().map(|&c| c == '#').collect(),
|
||||
column.iter().map(|&c| c != '.').collect(),
|
||||
column.iter().map(|&c| c == '#').collect(),
|
||||
)
|
||||
}
|
||||
fn sea_level(&self) -> i32 {
|
||||
32
|
||||
}
|
||||
fn bottom(&self) -> i32 {
|
||||
0
|
||||
}
|
||||
fn noise_biome(&mut self, quart: [i32; 3]) -> BiomeId {
|
||||
self.asked.push(quart);
|
||||
BiomeId(self.biomes.get(&(quart[0], quart[2])).copied().unwrap_or(1))
|
||||
@@ -274,4 +388,75 @@ mod tests {
|
||||
assert!(bounds(0, 64).pass(&mut fake, &none, CHUNK, 0, None));
|
||||
assert!(!bounds(0, 59).pass(&mut fake, &none, CHUNK, 0, None));
|
||||
}
|
||||
|
||||
/// A column of `n` blocks: `fill` up to `top` (exclusive), air above.
|
||||
fn column(n: usize, top: usize, fill: char) -> Vec<char> {
|
||||
(0..n).map(|y| if y < top { fill } else { '.' }).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repurposed_city_needs_air_above_the_lava_sea_around() {
|
||||
let none = BTreeSet::new();
|
||||
let city = checks(json!({"repurposed": "city_nether"}));
|
||||
// Sea 32: air needed from 52 to 76 (128 deep), in the 8 chunks around.
|
||||
let mut fake = Fake {
|
||||
column: column(128, 52, '#'),
|
||||
..Fake::default()
|
||||
};
|
||||
// The chunk itself is not read.
|
||||
fake.columns.insert((32, -16), column(128, 100, '#'));
|
||||
assert!(city.pass(&mut fake, &none, CHUNK, 33, None));
|
||||
fake.columns.insert((48, 0), column(128, 53, '#'));
|
||||
assert!(!city.pass(&mut fake, &none, CHUNK, 33, None));
|
||||
// Above sea + 45 nothing is read.
|
||||
fake.columns.insert((48, 0), {
|
||||
let mut c = column(128, 52, '#');
|
||||
c[77] = '#';
|
||||
c
|
||||
});
|
||||
assert!(city.pass(&mut fake, &none, CHUNK, 33, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repurposed_shipwreck_needs_no_solid_block_around() {
|
||||
let none = BTreeSet::new();
|
||||
let wreck = checks(json!({"repurposed": "shipwreck_nether"}));
|
||||
// Lava up to 40, air above: the samples at 28..=58 meet only lava and air.
|
||||
let mut fake = Fake {
|
||||
column: column(128, 40, '~'),
|
||||
..Fake::default()
|
||||
};
|
||||
assert!(wreck.pass(&mut fake, &none, CHUNK, 28, None));
|
||||
// Netherrack at y 43, between samples (28 + 15, + 20 are 43, 48).
|
||||
let mut rock = column(128, 40, '~');
|
||||
rock[43] = '#';
|
||||
fake.columns.insert((32 - 16, -16 + 16), rock.clone());
|
||||
assert!(!wreck.pass(&mut fake, &none, CHUNK, 28, None));
|
||||
rock[43] = '.';
|
||||
rock[44] = '#';
|
||||
fake.columns.insert((16, 0), rock);
|
||||
assert!(wreck.pass(&mut fake, &none, CHUNK, 28, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repurposed_end_stronghold_needs_land_around() {
|
||||
let none = BTreeSet::new();
|
||||
let end = checks(json!({"repurposed": "stronghold_end"}));
|
||||
let mut fake = Fake {
|
||||
column: column(256, 0, '#'),
|
||||
..Fake::default()
|
||||
};
|
||||
// Every height 64 by default: 63, 62, ... 55 after the 9 samples.
|
||||
assert!(end.pass(&mut fake, &none, CHUNK, 0, None));
|
||||
// Land at least 45 above the bottom, after the sample's minus one:
|
||||
// 46 at the corner passes, 45 fails.
|
||||
fake.heights.insert((32, -16), 46);
|
||||
assert!(end.pass(&mut fake, &none, CHUNK, 0, None));
|
||||
fake.heights.insert((32, -16), 45);
|
||||
assert!(!end.pass(&mut fake, &none, CHUNK, 0, None));
|
||||
// Void 70 blocks north fails at once.
|
||||
fake.heights.clear();
|
||||
fake.heights.insert((32, -86), 0);
|
||||
assert!(!end.pass(&mut fake, &none, CHUNK, 0, None));
|
||||
}
|
||||
}
|
||||
|
||||
+29
-5
@@ -438,7 +438,23 @@ Two cases the oracle fills in:
|
||||
list. The structures now generate undecorated (no pillars under them, spawners as the
|
||||
template has them); 1,427 processors of 146 types in ATM10's mods, the most common
|
||||
`lithostitched:block_swap`, Formations' `biome_replacements` and Repurposed Structures'
|
||||
pillar, fluid and void processors. Porting the common ones is next.
|
||||
pillar, fluid and void processors.
|
||||
- **Spawner processors** carried as data (`horizon-port-pack/src/processors.rs`). Most
|
||||
chests in the mods' templates already name their loot table; what the Java processors add
|
||||
is the spawners' mobs. Moog's and Repurposed Structures' spawner randomizing processors
|
||||
become `horizon:spawner_mobs` (a weighted mob per spawner, picked with the placement's
|
||||
random as theirs do, and the spawner NBT they write; Repurposed's `rs_spawners` lists are
|
||||
written in). YUNG's Better Dungeons and Better Desert Temples turn a spawner or a
|
||||
placeholder block (gravel, bone block, yellow wool...) into a spawner of a fixed mob: that
|
||||
is vanilla's `rule` processor with an `append_static` block entity. Moog's vanilla loot
|
||||
swap acts only when a "replace vanilla" preset is on, and they ship off. 119 of the 1,427
|
||||
processors are carried; 1,308 are still taken out (blocks swapped, aged or propped up,
|
||||
Moog's trial spawner and vault configs, YUNG's chest caps).
|
||||
In the 128×128-chunk square (seed 1234), every spawner of a mod structure now has its mob:
|
||||
in the Overworld 83 Better Dungeons spawners held the template's placeholder pig and 17 of
|
||||
Moog's were empty (763 spawners with a mob, up from 628); in the Nether the 52 empty ones
|
||||
in Moog's Nether Structures are filled (162, up from 110). Chests are unchanged: 2,777
|
||||
and 1,405 with a loot table.
|
||||
- **Big templates** (#838). Vanilla reads structure templates with no limit on their tag
|
||||
count; Horizon now does too (`nbt::Limits::templates`). Seven of ATM10's 8,962 carried
|
||||
templates are past the old 1,000,000-tag cap: YUNG's monument start, four When Dungeons
|
||||
@@ -484,11 +500,11 @@ Two cases the oracle fills in:
|
||||
- Still lost, written in Java:
|
||||
- Formations' structure and element types (179): their placements read block states in the
|
||||
noise column (solid, water, lava), which the structure context doesn't give yet;
|
||||
- Repurposed's mineshafts, mansions, monuments, Nether cities and shipwrecks, Better
|
||||
Mineshafts and two Better Dungeons types: Java structure types;
|
||||
- Repurposed's mineshafts, mansions and monuments, Better Mineshafts and two Better
|
||||
Dungeons types: Java structure types;
|
||||
- YUNG's and Moog's enhanced terrain adaptation, YUNG's piece modifiers and dead-end pools,
|
||||
and the processors written in Java (YUNG's spawners, chests, banners; 29 in Better Dungeons
|
||||
alone), so these structures place their template blocks only;
|
||||
and the block processors written in Java (YUNG's banners, legs and decorations, Repurposed's
|
||||
pillars and fluid fixes, Lithostitched's block swaps);
|
||||
- MO Structures (38; its library is only on CurseForge).
|
||||
|
||||
With every structure PR above, the same square (seed 1234, chunks -64..63) holds 362
|
||||
@@ -499,6 +515,14 @@ Two cases the oracle fills in:
|
||||
(vanilla 0), Better Jungle Temples 5, Better Witch Huts 11. Vanilla's own worlds are
|
||||
unchanged: the structure-start oracle still matches 35 of 35.
|
||||
|
||||
Repurposed's Nether city, Nether shipwrecks and End stronghold are its generic jigsaw with
|
||||
one more start check each, carried as `minecraft:jigsaw` with the check named in
|
||||
`horizon:start_checks.repurposed`: open air from sea level + 20 to + 45 around the city's
|
||||
chunk, no solid block in a 33×30×33 grid over a shipwreck, and land 45 blocks up at nine
|
||||
points 35 and 70 blocks apart for the stronghold. Over chunks -320..319 in the Nether there
|
||||
are 2 cities and 45 shipwrecks (30 and 865 without the checks); the End stronghold keeps
|
||||
8,000 blocks from the centre, and chunks 500..1139 × -320..319 hold 2 (43 without).
|
||||
|
||||
In a world with the 40 mods, seed 1234, `/locate structure mvs:azelea_house` finds one 27
|
||||
blocks from spawn and it stands there as the template builds it; When Dungeons Arise's
|
||||
bandit towers and Structory's chapel locate too.
|
||||
|
||||
+16
-1
@@ -185,6 +185,11 @@ comes out of the headless-engine work.
|
||||
it from GitHub Releases, and checks it against the SHA-256 GitHub publishes for each asset. It never asks
|
||||
for sudo. Options: `--version vX.Y.Z`, `--dir` (default `~/.local/share/horizon`), `--bin` (default
|
||||
`~/.local/bin`).
|
||||
On Linux the game links ALSA's and udev's libraries (`libasound.so.2`, `libudev.so.1`) even as a server,
|
||||
until the headless engine exists. Minimal server images often lack ALSA (Debian and Ubuntu:
|
||||
`sudo apt install libasound2 libudev1`, `libasound2t64` on Ubuntu 24.04 and later). The script lists any
|
||||
that are missing, `init` warns, and `run` stops at once with what to install, rather than restarting a
|
||||
game that can't load.
|
||||
- Windows:
|
||||
`irm https://raw.githubusercontent.com/ludovic111/horizon/main/packaging/server/install.ps1 | iex`
|
||||
The script does the same into `%LOCALAPPDATA%\Horizon` (`-Version`, `-Dir`), with junctions instead of
|
||||
@@ -480,6 +485,16 @@ reproducible by anyone, and show the same gameplay on both sides.
|
||||
and every packet woke its connection's writer thread (#649). Together they took the 50-bot walking tick
|
||||
from 281 ms to 31 ms. At 25 walking bots most of what remains is the engine's streaming and block entity
|
||||
ticks, both of which grow with players (the README has the profile).
|
||||
- **Mixed bots, as installed (2026-10-18,** `benchmarks/server-mixed-2026-10-18/`, the first published
|
||||
run for the working version). It used the v2026.10.18.15 release as `install.sh` installs it, against
|
||||
vanilla 26.3, with 1, 10, 25 and 50 `mixed` bots and vanilla's default game rules on both (Horizon has
|
||||
the locator bar now). The servers ran on the ThinkPad and the bots on the Mac mini. Results:
|
||||
- Both kept 20 TPS in every run.
|
||||
- Horizon's RSS was 3.7 to 5.2 times smaller (1.0 GB against 4.0 GB at 50).
|
||||
- Horizon's average tick was shorter with 1, 10 and 25 bots (2.4 against 17.9 ms, 12.4 against 34.5,
|
||||
24.0 against 31.6) and longer with 50 (35.2 against 29.7). Its P99 was lower at every count.
|
||||
- Horizon also did more work: it kept up with the exploring bots, so it generated 1.9 to 2.9 times
|
||||
the new terrain a second.
|
||||
- **Ownership.** perf-server-1 owns making the tick faster. This work only measures it, files what it finds,
|
||||
and fixes startup, RAM and packaging.
|
||||
|
||||
@@ -498,7 +513,7 @@ vanilla.
|
||||
archive in the release.
|
||||
3. The web panel MVP: status, live TPS/MSPT/RAM/CPU, players, console, backups and login links.
|
||||
4. `horizon-bots` and `tools/server_bench.py`, with a first run against vanilla (1/10/25/50 bots, `mixed`)
|
||||
published in `benchmarks/`.
|
||||
published in `benchmarks/`: done, `benchmarks/server-mixed-2026-10-18/` (section 9).
|
||||
5. Small engine fixes found on the way: logging refused logins (vanilla's lines).
|
||||
|
||||
**Where it stands (2026-10-16):** items 1 to 4 are built and in review (section 11). What's left for the 23rd:
|
||||
|
||||
@@ -86,6 +86,18 @@ for tool in horizon-server horizon-prepare; do
|
||||
done
|
||||
|
||||
echo "Installed Horizon $TAG in $RELEASE; horizon-server and horizon-prepare are in $BIN."
|
||||
# The game links ALSA and udev, even as a server; minimal Linux images often lack them.
|
||||
if [ "$(uname -s)" = Linux ] && command -v ldd >/dev/null; then
|
||||
MISSING=$(ldd "$RELEASE/horizon-client" 2>/dev/null | awk '/not found/ { printf "%s ", $1 }')
|
||||
if [ -n "$MISSING" ]; then
|
||||
echo "The game needs libraries this system doesn't have: $MISSING"
|
||||
echo "Install them before starting a server:"
|
||||
echo " Debian, Ubuntu: sudo apt install libasound2 libudev1 (Ubuntu 24.04 and later: libasound2t64)"
|
||||
echo " Fedora, RHEL: sudo dnf install alsa-lib systemd-libs"
|
||||
echo " Arch: sudo pacman -S alsa-lib systemd-libs"
|
||||
echo " NixOS: enable programs.nix-ld with alsa-lib and udev in its libraries"
|
||||
fi
|
||||
fi
|
||||
case ":$PATH:" in
|
||||
*":$BIN:"*) ;;
|
||||
*) echo "Add $BIN to your PATH, for example: echo 'export PATH=\"$BIN:\$PATH\"' >> ~/.profile" ;;
|
||||
|
||||
+8
-2
@@ -1523,9 +1523,15 @@ def check_light(host, guest, out):
|
||||
host('command', command=f'setblock {near} {y} {gz} minecraft:glowstone')
|
||||
try:
|
||||
lo, hi = (untracked * 16 - 16, y - 3, gz - 8), (untracked * 16 - 1, y + 3, gz + 8)
|
||||
# On the server thread the host's game is a client too, as dark as the guest until the light
|
||||
# update arrives: wait for it before comparing them.
|
||||
for _ in range(10):
|
||||
lit = guest.raw('light', near - 2, y, gz, near - 2, y, gz)['block']
|
||||
if lit == 'd':
|
||||
break
|
||||
host.wait(10)
|
||||
assert lit == 'd', f'the border chunk by the glowstone has block light {lit}, not 13, after 100 ticks'
|
||||
results['border'] = same_light(host, guest, lo, hi, 'border chunk')
|
||||
lit = guest.raw('light', near - 2, y, gz, near - 2, y, gz)['block']
|
||||
assert lit == 'd', f'the border chunk by the glowstone has block light {lit}, not 13'
|
||||
finally:
|
||||
host('command', command=f'setblock {near} {y} {gz} minecraft:air')
|
||||
results['border_cleared'] = same_light(host, guest, lo, hi, 'border chunk without the glowstone')
|
||||
|
||||
Reference in New Issue
Block a user