Merge origin/main into #800 (execute in: source dimension)
main's #880 added Source::level and Source::elsewhere for server players teleported into another level; this branch adds Source::dimension and moves the local player. Kept dimension (it covers what elsewhere was read for) and level; /tp tries main's teleport_across for a server's players first, then this branch's local-player level switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
name: cancel-on-close
|
||||
# A closed or merged pull request's queued and running checks free the runners at once.
|
||||
# pull_request_target so the token can cancel runs of pull requests from forks too;
|
||||
# it checks out nothing and runs no code from the pull request.
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [closed]
|
||||
permissions:
|
||||
actions: write
|
||||
jobs:
|
||||
cancel:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Cancel the pull request's unfinished runs
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
BRANCH: ${{ github.event.pull_request.head.ref }}
|
||||
SHA: ${{ github.event.pull_request.head.sha }}
|
||||
run: |
|
||||
for status in queued in_progress waiting pending requested; do
|
||||
gh run list -R "$REPO" --branch "$BRANCH" --status "$status" --limit 100 \
|
||||
--json databaseId,event,headSha \
|
||||
-q ".[] | select(.event == \"pull_request\" and .headSha == \"$SHA\") | .databaseId"
|
||||
done | sort -u | while read -r id; do
|
||||
gh run cancel -R "$REPO" "$id" || true
|
||||
done
|
||||
@@ -56,6 +56,8 @@ jobs:
|
||||
run: |
|
||||
cargo +stable fmt --all -- --check
|
||||
cargo +stable clippy --workspace --all-targets -- -D warnings
|
||||
# The server build (released as horizon-engine): the game without sound or controllers.
|
||||
cargo +stable clippy -p horizon-client --all-targets --no-default-features -- -D warnings
|
||||
- name: Test Rust core and voxel kernel correctness
|
||||
if: steps.rust.outputs.required != 'false'
|
||||
run: cargo +stable test --workspace
|
||||
|
||||
@@ -76,6 +76,9 @@ jobs:
|
||||
os: ubuntu-22.04
|
||||
dir: horizon-linux-x86_64
|
||||
asset: horizon-linux-x86_64.tar.gz
|
||||
# The server build too: packaging/server/install.sh installs it on Linux.
|
||||
server_dir: horizon-server-linux-x86_64
|
||||
server_asset: horizon-server-linux-x86_64.tar.gz
|
||||
- name: windows
|
||||
os: windows-latest
|
||||
dir: horizon-windows-x64
|
||||
@@ -190,6 +193,29 @@ jobs:
|
||||
path: dist/${{ matrix.asset }}
|
||||
if-no-files-found: error
|
||||
retention-days: 3
|
||||
- name: The server build (the game without sound or controllers, as horizon-engine)
|
||||
if: matrix.server_asset
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# After the client is packaged: target/release/horizon-client is rebuilt without the audio and
|
||||
# controllers features, so it needs neither libasound nor libudev (minimal server images lack them).
|
||||
cargo build --release --locked -p horizon-client --no-default-features --bin horizon-client
|
||||
cargo run --locked -p xtask -- package-server target/release/horizon-client "dist/${{ matrix.server_dir }}"
|
||||
folder="dist/${{ matrix.server_dir }}"
|
||||
python3 tools/check_imports.py --server "$folder/horizon-engine" "$folder/horizon-server" "$folder/horizon-prepare"
|
||||
"$folder/horizon-engine" --help | grep -q -- '--resources'
|
||||
"$folder/horizon-server" --version
|
||||
cd dist
|
||||
rm -f "${{ matrix.server_asset }}"
|
||||
tar czf "${{ matrix.server_asset }}" "${{ matrix.server_dir }}"
|
||||
ls -l "${{ matrix.server_asset }}"
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: matrix.server_asset
|
||||
with:
|
||||
name: ${{ matrix.server_asset }}
|
||||
path: dist/${{ matrix.server_asset }}
|
||||
if-no-files-found: error
|
||||
retention-days: 3
|
||||
|
||||
publish:
|
||||
needs: [decide, build]
|
||||
@@ -220,7 +246,7 @@ jobs:
|
||||
run: |
|
||||
gh release create "$TAG" --target "${{ needs.decide.outputs.head }}" --title "$(cat notes/title.txt)" \
|
||||
--notes-file notes/body.md --latest dist/horizon-linux-x86_64.tar.gz dist/horizon-windows-x64.zip \
|
||||
dist/horizon-macos-arm64.zip
|
||||
dist/horizon-macos-arm64.zip dist/horizon-server-linux-x86_64.tar.gz
|
||||
- name: Dry run, the release that would be published
|
||||
if: needs.decide.outputs.dry_run == 'true'
|
||||
run: |
|
||||
|
||||
Generated
+4
@@ -1435,6 +1435,7 @@ dependencies = [
|
||||
"naga",
|
||||
"png",
|
||||
"pollster",
|
||||
"rustix 1.1.5",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
@@ -1539,6 +1540,7 @@ dependencies = [
|
||||
"horizon-world",
|
||||
"serde_json",
|
||||
"sha1",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1554,6 +1556,7 @@ dependencies = [
|
||||
name = "horizon-server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"horizon-bench",
|
||||
"horizon-server-files",
|
||||
"libc",
|
||||
@@ -1569,6 +1572,7 @@ dependencies = [
|
||||
name = "horizon-server-files"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"horizon-core",
|
||||
"horizon-protocol",
|
||||
"horizon-world",
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
# Horizon's server against vanilla 26.3: mixed bots, equal work (2026-10-18)
|
||||
|
||||
This reruns `../server-mixed-2026-10-18/` with the bots' load made the same on both servers. In that run the
|
||||
`explore` bots flew as fast as each server sent them chunks. Horizon kept up and vanilla didn't, so Horizon
|
||||
sent 2.9 to 5.9 times as many chunks a second, and vanilla's walking bots got a fifth of the chunks Horizon's
|
||||
got. The comparison of tick times wasn't fair.
|
||||
|
||||
## Summary
|
||||
|
||||
- **The work was equal** at 1 and 10 bots. At 25 bots it was equal in chunks sent a second (158.6 against 157.6);
|
||||
vanilla was still catching up on chunks its bots hadn't had yet, see "Equal work" below. Every bot joined, none
|
||||
was dropped, no chunk was sent twice, and no bot ever waited for the chunk it stood in.
|
||||
- **Tick time (MSPT), same work:**
|
||||
- 1 bot: 1.8 ms on Horizon against 11.3 on vanilla;
|
||||
- 10 bots: 4.7 against 34.3 ms;
|
||||
- 25 bots: 11.7 against 50.5 ms. Vanilla dropped just under 20 TPS (19.8) and its worst 5-second P99 was
|
||||
1388 ms, against Horizon's 130;
|
||||
- 50 bots: Horizon ran at 23.8 ms (20 TPS). Vanilla's watchdog stopped its server 30 s after the last bot
|
||||
joined ("A single server tick took 60.01 seconds").
|
||||
- **Memory:** Horizon's RSS was 4.1 to 4.9 times smaller: 0.69 against 3.40 GB with one bot, 0.95 against
|
||||
3.87 GB with 25, and 1.03 GB with 50. Vanilla's heap is fixed at 4 GB, so its RSS is mostly that heap.
|
||||
- **CPU** (100 % is one of the machine's 4 threads): 30 against 128 % at 10 bots, 58 against 192 % at 25.
|
||||
- **What changed since the first run:** the first run's vanilla held 50 bots at 29.7 ms because its walking
|
||||
bots got 640 to 1100 chunks each. With the explore bots paced, vanilla serves the walking bots in full
|
||||
(5400 to 6100 chunks each, against Horizon's 6100 to 6600), and that is the load it can't carry at 50.
|
||||
|
||||
## 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 300 measured seconds. "Worst P99" is the highest P99 of a single 5-second query. RSS and CPU
|
||||
cover the server's process tree. "First-time chunks/s" counts chunks a bot hadn't received before (summed
|
||||
over the bots). "Waited" is ticks a second that bots stood still waiting for their own chunk. "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 | First-time chunks/s | Waited | Pulled back |
|
||||
|---:|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
|
||||
| 1 | Horizon | **1.77** | 4.21 | 13.04 | 47.5 | 20 | **0.69 / 0.69 GB** | 28 % | 19.7 s | 9.94 | 0.01 | 0 | 0 |
|
||||
| 1 | vanilla | 11.34 | 17.12 | 33.22 | 119.1 | 20 | 3.40 / 3.42 GB | 36 % | 20.4 s | 9.98 | 0.01 | 0 | 0 |
|
||||
| 10 | Horizon | **4.74** | 10.48 | 19.69 | 120.1 | 20 | **0.86 / 0.88 GB** | 30 % | 19.5 s | 61.35 | 1.79 | 0 | 4159 |
|
||||
| 10 | vanilla | 34.30 | 53.72 | 89.08 | 375.8 | 20 | 3.71 / 3.75 GB | 128 % | 19.9 s | 61.66 | 1.93 | 0 | 3976 |
|
||||
| 25 | Horizon | **11.72** | 24.45 | 43.79 | 129.8 | 20 | **0.95 / 1.09 GB** | 58 % | 9.6 s | 158.57 | 5.78 | 0 | 3496 |
|
||||
| 25 | vanilla | 50.45 | 74.09 | 191.21 | 1388.1 | 19.82 | 3.87 / 4.75 GB | 192 % | 37.8 s | 157.63 | 8.25 | 0 | 3629 |
|
||||
| 50 | Horizon | **23.82** | 50.98 | 74.64 | 195.9 | 20 | **1.03 / 1.20 GB** | 98 % | 14.9 s | 302.81 | 10.96 | 0 | 7565 |
|
||||
| 50 | vanilla | stopped by its watchdog | | | | | | | 11.2 s | | | | |
|
||||
|
||||
Chunks each bot received over the whole run, by behaviour (mean):
|
||||
|
||||
| Bots | Server | walk | explore | idle |
|
||||
|---:|---|---:|---:|---:|
|
||||
| 1 | Horizon | 6092 | | |
|
||||
| 1 | vanilla | 6084 | | |
|
||||
| 10 | Horizon | 6248 | 1165 | 473 |
|
||||
| 10 | vanilla | 5729 | 1124 | 473 |
|
||||
| 25 | Horizon | 6629 | 1267 | 473 |
|
||||
| 25 | vanilla | 5387 | 1119 | 473 |
|
||||
| 50 | Horizon | 6497 | 1256 | 473 |
|
||||
|
||||
Both servers pulled bots back about as often (`moved too quickly` 20 and 296 times on vanilla at 10 and 25
|
||||
bots).
|
||||
|
||||
## Equal work
|
||||
|
||||
`tools/server_bench.py` now prints a work table after the runs. At each bot count it compares every server's
|
||||
chunks sent a second and first-time chunks a second with the busiest server's. Work counts as equal when
|
||||
both are within 10 % (or within a chunk a second when there are few). The report keeps the table as `work`.
|
||||
|
||||
| Bots | Chunks/s (Horizon, vanilla) | First-time chunks/s (Horizon, vanilla) | Equal |
|
||||
|---:|---|---|---|
|
||||
| 1 | 9.94, 9.98 | 0.01, 0.01 | yes |
|
||||
| 10 | 61.35, 61.66 | 1.79, 1.93 | yes |
|
||||
| 25 | 158.57, 157.63 | 5.78, 8.25 | no: vanilla sent 2.5 more first-time chunks a second |
|
||||
|
||||
Two settings made the load the same:
|
||||
|
||||
- **Explore bots paced at 0.8 blocks a second** (`--explore-speed 0.8`), the rate the 2026-10-17 run showed
|
||||
both servers keep up with. Every bot then follows the same path on both servers. The path is deterministic
|
||||
per bot, and a bot only stops while the chunk it stands in hasn't arrived, which never happened here
|
||||
(`Waited` 0). So both servers had the same chunks to send.
|
||||
- **A 300-second warm-up** before the 300 measured seconds. A first pass with the old 60-second warm-up
|
||||
(aborted after 10 bots) sent the same chunks a second on both (63.1 against 61.4). But vanilla was still
|
||||
delivering the bots' first views during the measurement (12.9 first-time chunks a second against Horizon's
|
||||
4.1), so its window held more work than Horizon's. With 300 seconds both were in steady state at 1 and 10
|
||||
bots. At 25, vanilla still sent 2.5 more first-time chunks a second than Horizon: 1.6 % of all it sent, and
|
||||
its walking bots ended the run with 19 % fewer chunks. Read the 25-bot tick times with that in mind: the
|
||||
extra first-time chunks are work vanilla had still to do because it fell behind.
|
||||
|
||||
## Method
|
||||
|
||||
`tools/server_bench.py` ran 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 (the locator bar on for both);
|
||||
- the server waits for `Done`, the bots join one a second, warm up for 300 seconds and are measured for 300,
|
||||
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 spawn. `walk` flies to random points within 48 blocks at
|
||||
5.6 blocks a second, `explore` flies straight out at 0.8 blocks a second, and `idle` hovers.
|
||||
|
||||
**Machine.** The ThinkPad: Intel Core i7-7500U (2 cores, 4 threads), 32 GB, NixOS. The desktop (24 threads)
|
||||
was meant to run it, but it didn't wake (`~/fleet/power wake desktop` timed out, as it did for the first run).
|
||||
No other session ran on the ThinkPad during the runs (`load.txt`, a sample a minute). The servers ran under
|
||||
`nice -n 19`. The bots ran on the Mac mini (M4 Pro, shared with other work at 70 to 90 % CPU) and reached the
|
||||
ThinkPad over the tailnet.
|
||||
|
||||
**What ran.**
|
||||
|
||||
- Horizon: the server build from #916 (`horizon-client --no-default-features`, no sound or controllers) at
|
||||
519ec121, packaged with `xtask package-server` and installed with `install.sh --archive`, as Linux owners
|
||||
will get it. `horizon-server` ran it as `horizon-engine`. The game files were prepared from the owner's own
|
||||
Minecraft. `horizon-bots` and `server_bench.py` came from this PR.
|
||||
- Vanilla: the pinned 26.3 server jar (the owner's own copy) on OpenJDK 25.0.4.1, `-Xms4g -Xmx4g`.
|
||||
|
||||
`server_bench.py` stopped after vanilla's 50-bot server crashed and before it wrote its report.
|
||||
`mixed-equal.json` holds the run lines it printed. The vanilla 50 entry and its error come from that server's
|
||||
log, and the `work` table was computed with `server_bench.work`. `load.txt` is the fleet monitor's view of the
|
||||
machines during the runs.
|
||||
|
||||
## 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=~/.local/share/horizon/current \
|
||||
python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25,50 --behaviour mixed \
|
||||
--explore-speed 0.8 --warmup 300 --nice 19 \
|
||||
--bots-via 'ssh <bots machine>' --bots-bin /path/to/horizon-bots --connect <this machine's address> \
|
||||
--out mixed-equal.json
|
||||
|
||||
## Next
|
||||
|
||||
- One pass per configuration ran. Vanilla at 50 bots, in particular, needs a second pass, ideally on the
|
||||
desktop (24 threads), where neither server is CPU-bound.
|
||||
- 100 bots, and Paper and Fabric + Lithium (docs/server.md section 9).
|
||||
- A longer warm-up, or measuring from when the first-time chunk rate settles, so the 25-bot work is equal too.
|
||||
@@ -0,0 +1,702 @@
|
||||
2026-10-18T19:32:39Z
|
||||
ludothinkpad ok: 27.2 GB free, 4 threads 17% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 25.9 GB free, 14 threads 73% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 27.0 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 42% busy (agents 0.0, rest 1.6 cores) · 80°C · load 5.9
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:33:44Z
|
||||
ludothinkpad ok: 26.7 GB free, 4 threads 19% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.7 GB free, 14 threads 93% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 34% busy (agents 0.0, rest 1.7 cores) · 81°C · load 4.0
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:34:48Z
|
||||
ludothinkpad ok: 26.4 GB free, 4 threads 56% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.9 GB free, 14 threads 90% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 54% busy (agents 0.0, rest 2.2 cores) · 79°C · load 2.8
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:35:52Z
|
||||
ludothinkpad ok: 26.7 GB free, 4 threads 27% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 25.4 GB free, 14 threads 85% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 30% busy (agents 0.0, rest 1.1 cores) · 82°C · load 2.2
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:36:57Z
|
||||
ludothinkpad ok: 26.7 GB free, 4 threads 25% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 25.4 GB free, 14 threads 93% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 37% busy (agents 0.0, rest 1.2 cores) · 80°C · load 1.5
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:38:01Z
|
||||
ludothinkpad ok: 26.6 GB free, 4 threads 54% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.7 GB free, 14 threads 64% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 21% busy (agents 0.0, rest 1.2 cores) · 81°C · load 1.9
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:39:05Z
|
||||
ludothinkpad ok: 26.7 GB free, 4 threads 20% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.1 GB free, 14 threads 70% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 28% busy (agents 0.0, rest 1.0 cores) · 81°C · load 1.3
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:40:10Z
|
||||
ludothinkpad ok: 26.7 GB free, 4 threads 39% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.2 GB free, 14 threads 73% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 32% busy (agents 0.0, rest 1.7 cores) · 80°C · load 0.9
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:41:14Z
|
||||
ludothinkpad ok: 26.7 GB free, 4 threads 31% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.8 GB free, 14 threads 77% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 15% busy (agents 0.0, rest 1.1 cores) · 82°C · load 1.3
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:42:19Z
|
||||
ludothinkpad ok: 26.5 GB free, 4 threads 26% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.1 GB free, 14 threads 94% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 30% busy (agents 0.0, rest 1.3 cores) · 78°C · load 1.1
|
||||
· disk 289.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:43:23Z
|
||||
ludothinkpad busy: 26.7 GB free, 4 threads 99% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.2 GB free, 14 threads 83% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 99% busy (agents 0.0, rest 3.8 cores) · 86°C · load 2.4
|
||||
· disk 289.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:44:27Z
|
||||
ludothinkpad busy: 25.2 GB free, 4 threads 98% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.0 GB free, 14 threads 73% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 24.9 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 83% busy (agents 0.0, rest 3.7 cores) · 83°C · load 5.5
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:45:31Z
|
||||
ludothinkpad ok: 24.5 GB free, 4 threads 39% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.0 GB free, 14 threads 93% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 24.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 34% busy (agents 0.0, rest 1.5 cores) · 84°C · load 3.5
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:46:35Z
|
||||
ludothinkpad ok: 23.7 GB free, 4 threads 69% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.2 GB free, 14 threads 90% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 23.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 75% busy (agents 0.0, rest 2.8 cores) · 87°C · load 2.7
|
||||
· disk 289.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:47:40Z
|
||||
ludothinkpad ok: 23.8 GB free, 4 threads 66% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 25.9 GB free, 14 threads 85% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 23.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 59% busy (agents 0.0, rest 2.5 cores) · 83°C · load 2.9
|
||||
· disk 291.7 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:48:44Z
|
||||
ludothinkpad ok: 24.2 GB free, 4 threads 61% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.0 GB free, 14 threads 90% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 24.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 62% busy (agents 0.0, rest 2.5 cores) · 84°C · load 3.2
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:49:48Z
|
||||
ludothinkpad ok: 25.1 GB free, 4 threads 59% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 31.1 GB free, 14 threads 81% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 25.1 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 57% busy (agents 0.0, rest 2.4 cores) · 85°C · load 2.9
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:50:52Z
|
||||
ludothinkpad ok: 25.7 GB free, 4 threads 39% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.4 GB free, 14 threads 88% busy, 2 sessions
|
||||
macbook offline
|
||||
RAM 25.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 18% busy (agents 0.0, rest 1.4 cores) · 67°C · load 2.4
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:51:57Z
|
||||
ludothinkpad ok: 23.7 GB free, 4 threads 40% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.9 GB free, 14 threads 83% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 23.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 23% busy (agents 0.0, rest 1.4 cores) · 81°C · load 1.8
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:53:01Z
|
||||
ludothinkpad ok: 25.3 GB free, 4 threads 25% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.1 GB free, 14 threads 84% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 25.1 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 31% busy (agents 0.0, rest 1.2 cores) · 80°C · load 1.8
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:54:05Z
|
||||
ludothinkpad ok: 26.5 GB free, 4 threads 75% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.1 GB free, 14 threads 91% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.5 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 69% busy (agents 0.0, rest 2.5 cores) · 78°C · load 2.3
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:55:09Z
|
||||
ludothinkpad busy: 26.4 GB free, 4 threads 89% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.3 GB free, 14 threads 86% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 32% busy (agents 0.0, rest 2.4 cores) · 79°C · load 2.9
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:56:14Z
|
||||
ludothinkpad ok: 26.4 GB free, 4 threads 39% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.1 GB free, 14 threads 68% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 63% busy (agents 0.0, rest 1.8 cores) · 82°C · load 2.3
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:57:18Z
|
||||
ludothinkpad ok: 26.3 GB free, 4 threads 20% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.2 GB free, 14 threads 85% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 19% busy (agents 0.0, rest 1.0 cores) · 80°C · load 1.8
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:58:22Z
|
||||
ludothinkpad ok: 26.3 GB free, 4 threads 28% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.3 GB free, 14 threads 88% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.1 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 93% busy (agents 0.0, rest 2.5 cores) · 80°C · load 2.0
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T19:59:27Z
|
||||
ludothinkpad ok: 26.2 GB free, 4 threads 52% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 35.0 GB free, 14 threads 85% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 26.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 22% busy (agents 0.0, rest 1.8 cores) · 80°C · load 3.6
|
||||
· disk 291.4 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:00:31Z
|
||||
ludothinkpad busy: 25.8 GB free, 4 threads 87% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 33.0 GB free, 14 threads 87% busy, 1 sessions
|
||||
macbook offline
|
||||
RAM 27.5 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 51% busy (agents 0.0, rest 2.9 cores) · 79°C · load 3.6
|
||||
· disk 291.5 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:01:35Z
|
||||
ludothinkpad ok: 25.6 GB free, 4 threads 35% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 32.4 GB free, 14 threads 81% busy, 1 sessions
|
||||
macbook ok: 7.2 GB free, 12 threads 32% busy, 0 sessions
|
||||
RAM 25.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 34% busy (agents 0.0, rest 1.3 cores) · 81°C · load 2.5
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:02:40Z
|
||||
ludothinkpad ok: 26.6 GB free, 4 threads 35% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.2 GB free, 14 threads 79% busy, 1 sessions
|
||||
macbook ok: 6.5 GB free, 12 threads 39% busy, 0 sessions
|
||||
RAM 26.5 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 33% busy (agents 0.0, rest 1.3 cores) · 81°C · load 2.7
|
||||
· disk 291.6 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:03:44Z
|
||||
ludothinkpad ok: 25.5 GB free, 4 threads 56% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 31.1 GB free, 14 threads 89% busy, 1 sessions
|
||||
macbook ok: 6.8 GB free, 12 threads 6% busy, 0 sessions
|
||||
RAM 25.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 66% busy (agents 0.0, rest 2.5 cores) · 87°C · load 2.5
|
||||
· disk 291.3 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:04:48Z
|
||||
ludothinkpad busy: 26.2 GB free, 4 threads 99% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 30.0 GB free, 14 threads 89% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 31% busy, 0 sessions
|
||||
RAM 25.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 84% busy (agents 0.0, rest 3.7 cores) · 85°C · load 3.4
|
||||
· disk 291.3 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:05:52Z
|
||||
ludothinkpad busy: 24.5 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 34.1 GB free, 14 threads 89% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 24.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 100% busy (agents 0.0, rest 4.0 cores) · 83°C · load 9.0
|
||||
· disk 291.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:06:57Z
|
||||
ludothinkpad busy: 23.5 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.3 GB free, 14 threads 88% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 5% busy, 0 sessions
|
||||
RAM 23.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 99% busy (agents 0.0, rest 4.0 cores) · 82°C · load 10.1
|
||||
· disk 309.2 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:08:01Z
|
||||
ludothinkpad busy: 23.4 GB free, 4 threads 88% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.6 GB free, 14 threads 83% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 2% busy, 0 sessions
|
||||
RAM 23.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 77% busy (agents 0.0, rest 3.4 cores) · 84°C · load 7.5
|
||||
· disk 309.2 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:09:05Z
|
||||
ludothinkpad busy: 24.0 GB free, 4 threads 89% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 25.9 GB free, 14 threads 83% busy, 1 sessions
|
||||
macbook ok: 7.1 GB free, 12 threads 19% busy, 0 sessions
|
||||
RAM 23.9 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 91% busy (agents 0.0, rest 3.6 cores) · 82°C · load 5.9
|
||||
· disk 309.1 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:10:09Z
|
||||
ludothinkpad busy: 24.0 GB free, 4 threads 98% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.1 GB free, 14 threads 88% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 19% busy, 0 sessions
|
||||
RAM 24.0 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 92% busy (agents 0.0, rest 3.7 cores) · 84°C · load 6.6
|
||||
· disk 309.1 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:11:14Z
|
||||
ludothinkpad busy: 24.3 GB free, 4 threads 92% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.3 GB free, 14 threads 84% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 18% busy, 0 sessions
|
||||
RAM 24.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 99% busy (agents 0.0, rest 3.7 cores) · 85°C · load 6.5
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:12:18Z
|
||||
ludothinkpad busy: 24.7 GB free, 4 threads 89% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.6 GB free, 14 threads 78% busy, 1 sessions
|
||||
macbook ok: 7.3 GB free, 12 threads 20% busy, 0 sessions
|
||||
RAM 24.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 82% busy (agents 0.0, rest 3.4 cores) · 84°C · load 6.1
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:13:22Z
|
||||
ludothinkpad ok: 23.4 GB free, 4 threads 53% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.1 GB free, 14 threads 77% busy, 1 sessions
|
||||
macbook ok: 7.3 GB free, 12 threads 20% busy, 0 sessions
|
||||
RAM 23.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 48% busy (agents 0.0, rest 2.4 cores) · 80°C · load 4.2
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:14:27Z
|
||||
ludothinkpad ok: 24.0 GB free, 4 threads 44% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.0 GB free, 14 threads 71% busy, 1 sessions
|
||||
macbook ok: 6.9 GB free, 12 threads 2% busy, 0 sessions
|
||||
RAM 24.1 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 23% busy (agents 0.0, rest 2.0 cores) · 77°C · load 4.3
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:15:31Z
|
||||
ludothinkpad ok: 22.7 GB free, 4 threads 31% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.2 GB free, 14 threads 86% busy, 1 sessions
|
||||
macbook ok: 6.9 GB free, 12 threads 19% busy, 0 sessions
|
||||
RAM 22.5 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 30% busy (agents 0.0, rest 1.3 cores) · 77°C · load 2.6
|
||||
· disk 309.1 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:16:35Z
|
||||
ludothinkpad ok: 26.8 GB free, 4 threads 37% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.6 GB free, 14 threads 82% busy, 1 sessions
|
||||
macbook ok: 6.8 GB free, 12 threads 9% busy, 0 sessions
|
||||
RAM 26.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 42% busy (agents 0.0, rest 1.7 cores) · 81°C · load 2.3
|
||||
· disk 309.1 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:17:39Z
|
||||
ludothinkpad ok: 26.3 GB free, 4 threads 63% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.8 GB free, 14 threads 78% busy, 1 sessions
|
||||
macbook ok: 7.0 GB free, 12 threads 19% busy, 0 sessions
|
||||
RAM 26.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 64% busy (agents 0.0, rest 2.6 cores) · 87°C · load 1.9
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:18:43Z
|
||||
ludothinkpad ok: 26.9 GB free, 4 threads 37% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 32.2 GB free, 14 threads 87% busy, 1 sessions
|
||||
macbook ok: 7.0 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 26.9 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 56% busy (agents 0.0, rest 1.9 cores) · 84°C · load 3.9
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:19:48Z
|
||||
ludothinkpad ok: 26.0 GB free, 4 threads 77% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.2 GB free, 14 threads 83% busy, 1 sessions
|
||||
macbook ok: 7.0 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 26.0 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 66% busy (agents 0.0, rest 2.9 cores) · 86°C · load 3.2
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:20:52Z
|
||||
ludothinkpad ok: 25.9 GB free, 4 threads 80% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.8 GB free, 14 threads 84% busy, 1 sessions
|
||||
macbook ok: 7.0 GB free, 12 threads 17% busy, 0 sessions
|
||||
RAM 25.9 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 68% busy (agents 0.0, rest 3.2 cores) · 86°C · load 4.4
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:21:56Z
|
||||
ludothinkpad ok: 26.3 GB free, 4 threads 63% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.3 GB free, 14 threads 77% busy, 1 sessions
|
||||
macbook ok: 6.8 GB free, 12 threads 14% busy, 0 sessions
|
||||
RAM 26.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 66% busy (agents 0.0, rest 2.8 cores) · 84°C · load 3.1
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:23:00Z
|
||||
ludothinkpad ok: 26.8 GB free, 4 threads 74% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.1 GB free, 14 threads 82% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 11% busy, 0 sessions
|
||||
RAM 26.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 65% busy (agents 0.0, rest 2.8 cores) · 84°C · load 5.0
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:24:05Z
|
||||
ludothinkpad ok: 26.9 GB free, 4 threads 64% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.3 GB free, 14 threads 90% busy, 1 sessions
|
||||
macbook ok: 6.8 GB free, 12 threads 8% busy, 0 sessions
|
||||
RAM 26.9 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 64% busy (agents 0.0, rest 2.7 cores) · 86°C · load 4.9
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:25:09Z
|
||||
ludothinkpad ok: 26.0 GB free, 4 threads 56% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.2 GB free, 14 threads 88% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 12% busy, 0 sessions
|
||||
RAM 26.0 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 49% busy (agents 0.0, rest 2.1 cores) · 72°C · load 5.5
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:26:13Z
|
||||
ludothinkpad ok: 25.8 GB free, 4 threads 47% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.8 GB free, 14 threads 78% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 8% busy, 0 sessions
|
||||
RAM 25.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 56% busy (agents 0.0, rest 2.1 cores) · 78°C · load 3.1
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:27:18Z
|
||||
ludothinkpad busy: 25.5 GB free, 4 threads 94% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.6 GB free, 14 threads 82% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 17% busy, 0 sessions
|
||||
RAM 25.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 100% busy (agents 0.0, rest 3.9 cores) · 78°C · load 4.7
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:28:22Z
|
||||
ludothinkpad busy: 24.6 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.4 GB free, 14 threads 80% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 8% busy, 0 sessions
|
||||
RAM 24.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 99% busy (agents 0.0, rest 4.0 cores) · 77°C · load 10.5
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:29:27Z
|
||||
ludothinkpad busy: 24.3 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.8 GB free, 14 threads 80% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 8% busy, 0 sessions
|
||||
RAM 24.0 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 99% busy (agents 0.0, rest 4.0 cores) · 82°C · load 10.0
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:30:31Z
|
||||
ludothinkpad busy: 23.7 GB free, 4 threads 91% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 30.1 GB free, 14 threads 71% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 9% busy, 0 sessions
|
||||
RAM 23.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 94% busy (agents 0.0, rest 3.8 cores) · 80°C · load 10.3
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:31:36Z
|
||||
ludothinkpad busy: 23.6 GB free, 4 threads 93% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.0 GB free, 14 threads 81% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 14% busy, 0 sessions
|
||||
RAM 23.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 95% busy (agents 0.0, rest 3.7 cores) · 80°C · load 10.7
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:32:40Z
|
||||
ludothinkpad busy: 23.6 GB free, 4 threads 94% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.9 GB free, 14 threads 76% busy, 1 sessions
|
||||
macbook ok: 6.8 GB free, 12 threads 22% busy, 0 sessions
|
||||
RAM 23.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 84% busy (agents 0.0, rest 3.5 cores) · 80°C · load 9.7
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:33:45Z
|
||||
ludothinkpad ok: 25.2 GB free, 4 threads 51% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.1 GB free, 14 threads 82% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 17% busy, 0 sessions
|
||||
RAM 25.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 48% busy (agents 0.0, rest 2.1 cores) · 87°C · load 6.5
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:34:49Z
|
||||
ludothinkpad ok: 25.1 GB free, 4 threads 56% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 28.2 GB free, 14 threads 87% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 17% busy, 0 sessions
|
||||
RAM 24.5 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 78% busy (agents 0.0, rest 2.7 cores) · 88°C · load 4.0
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:35:53Z
|
||||
ludothinkpad busy: 23.6 GB free, 4 threads 86% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.9 GB free, 14 threads 86% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 17% busy, 0 sessions
|
||||
RAM 23.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 88% busy (agents 0.0, rest 3.3 cores) · 85°C · load 4.9
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:36:58Z
|
||||
ludothinkpad ok: 23.6 GB free, 4 threads 75% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.4 GB free, 14 threads 84% busy, 1 sessions
|
||||
macbook ok: 6.5 GB free, 12 threads 18% busy, 0 sessions
|
||||
RAM 23.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 85% busy (agents 0.0, rest 3.2 cores) · 85°C · load 5.1
|
||||
· disk 309.0 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:38:02Z
|
||||
ludothinkpad ok: 22.6 GB free, 4 threads 55% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.5 GB free, 14 threads 80% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 22.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 54% busy (agents 0.0, rest 2.2 cores) · 85°C · load 4.5
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:39:06Z
|
||||
ludothinkpad ok: 27.2 GB free, 4 threads 55% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 29.5 GB free, 14 threads 85% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 9% busy, 0 sessions
|
||||
RAM 27.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 48% busy (agents 0.0, rest 2.2 cores) · 87°C · load 4.0
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:40:10Z
|
||||
ludothinkpad ok: 26.2 GB free, 4 threads 72% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.7 GB free, 14 threads 84% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 19% busy, 0 sessions
|
||||
RAM 26.3 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 80% busy (agents 0.0, rest 3.1 cores) · 86°C · load 10.8
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:41:15Z
|
||||
ludothinkpad busy: 26.4 GB free, 4 threads 86% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.5 GB free, 14 threads 79% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 26.4 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 90% busy (agents 0.0, rest 3.4 cores) · 86°C · load 12.8
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:42:19Z
|
||||
ludothinkpad ok: 26.2 GB free, 4 threads 82% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.9 GB free, 14 threads 78% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 11% busy, 0 sessions
|
||||
RAM 26.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 74% busy (agents 0.0, rest 3.3 cores) · 85°C · load 8.8
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:43:23Z
|
||||
ludothinkpad busy: 26.7 GB free, 4 threads 93% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 27.3 GB free, 14 threads 81% busy, 1 sessions
|
||||
macbook ok: 6.6 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 26.7 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 88% busy (agents 0.0, rest 3.4 cores) · 85°C · load 5.4
|
||||
· disk 308.9 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:44:27Z
|
||||
ludothinkpad ok: 27.0 GB free, 4 threads 82% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.9 GB free, 14 threads 87% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 13% busy, 0 sessions
|
||||
RAM 27.0 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 75% busy (agents 0.0, rest 3.3 cores) · 82°C · load 9.8
|
||||
· disk 308.8 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:45:32Z
|
||||
ludothinkpad ok: 27.2 GB free, 4 threads 76% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.8 GB free, 14 threads 80% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 27.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 84% busy (agents 0.0, rest 3.2 cores) · 85°C · load 6.9
|
||||
· disk 308.8 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:46:36Z
|
||||
ludothinkpad busy: 27.1 GB free, 4 threads 87% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 26.8 GB free, 14 threads 92% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 9% busy, 0 sessions
|
||||
RAM 26.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 85% busy (agents 0.0, rest 3.2 cores) · 82°C · load 4.4
|
||||
· disk 308.8 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:47:40Z
|
||||
ludothinkpad busy: 25.3 GB free, 4 threads 86% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 26.5 GB free, 14 threads 72% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 9% busy, 0 sessions
|
||||
RAM 25.5 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 85% busy (agents 0.0, rest 3.4 cores) · 86°C · load 3.7
|
||||
· disk 308.8 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:48:45Z
|
||||
ludothinkpad busy: 26.1 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 28.5 GB free, 14 threads 84% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 15% busy, 0 sessions
|
||||
RAM 26.1 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 98% busy (agents 0.0, rest 3.9 cores) · 80°C · load 6.5
|
||||
· disk 308.8 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:49:50Z
|
||||
ludothinkpad ok: 26.8 GB free, 4 threads 71% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.7 GB free, 14 threads 93% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 26.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 92% busy (agents 0.0, rest 3.4 cores) · 81°C · load 5.2
|
||||
· disk 308.7 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:50:54Z
|
||||
ludothinkpad busy: 25.8 GB free, 4 threads 100% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 31.3 GB free, 14 threads 95% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 11% busy, 0 sessions
|
||||
RAM 25.8 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 99% busy (agents 0.0, rest 4.0 cores) · 82°C · load 8.1
|
||||
· disk 308.7 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:51:59Z
|
||||
ludothinkpad ok: 27.2 GB free, 4 threads 12% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 31.2 GB free, 14 threads 76% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 8% busy, 0 sessions
|
||||
RAM 27.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 15% busy (agents 0.0, rest 1.3 cores) · 81°C · load 7.9
|
||||
· disk 308.7 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:53:03Z
|
||||
ludothinkpad ok: 27.3 GB free, 4 threads 42% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini busy: 27.8 GB free, 14 threads 87% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 9% busy, 0 sessions
|
||||
RAM 27.2 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 14% busy (agents 0.0, rest 0.8 cores) · 82°C · load 3.1
|
||||
· disk 308.7 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:54:08Z
|
||||
ludothinkpad ok: 28.9 GB free, 4 threads 4% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 29.2 GB free, 14 threads 80% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 9% busy, 0 sessions
|
||||
RAM 28.9 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 2% busy (agents 0.0, rest 0.3 cores) · 82°C · load 1.3
|
||||
· disk 308.7 GB free · battery 96% · Ludovic: away
|
||||
|
||||
2026-10-18T20:55:12Z
|
||||
ludothinkpad ok: 27.7 GB free, 4 threads 27% busy, 0 sessions
|
||||
desktop offline
|
||||
macmini ok: 31.2 GB free, 14 threads 70% busy, 1 sessions
|
||||
macbook ok: 6.7 GB free, 12 threads 10% busy, 0 sessions
|
||||
RAM 27.6 GB free of 31.2 GB · swap 0.3 GB/15.6 GB
|
||||
CPU 4 threads, 26% busy (agents 0.0, rest 1.2 cores) · 69°C · load 1.0
|
||||
· disk 308.8 GB free · battery 96% · Ludovic: away
|
||||
|
||||
@@ -0,0 +1,421 @@
|
||||
{
|
||||
"kind": "horizon-server-benchmark",
|
||||
"date": "2026-10-18T19:32:00+00:00",
|
||||
"machine": {
|
||||
"system": "Linux",
|
||||
"machine": "x86_64",
|
||||
"cpus": 4,
|
||||
"name": "ThinkPad, Intel Core i7-7500U, 32 GB, NixOS"
|
||||
},
|
||||
"commit": "f1d5bf520986b00a5b968a84d85809fca1a039fa",
|
||||
"engine": "horizon-engine: the server build of #916 (horizon-client --no-default-features) at 519ec121, as install.sh --archive installed it",
|
||||
"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": 300,
|
||||
"seconds": 300,
|
||||
"seed": 12345,
|
||||
"explore_speed": 0.8,
|
||||
"gamerule": "",
|
||||
"heap": "4g",
|
||||
"nice": 19,
|
||||
"bots_via": "ssh macmini",
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"note": "server_bench.py was stopped after vanilla's 50-bot server crashed, before it wrote this file; the runs are the lines it printed, and the vanilla 50 entry is taken from that server's log.",
|
||||
"runs": [
|
||||
{
|
||||
"server": "horizon",
|
||||
"bots": 1,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 19.73,
|
||||
"mspt": {
|
||||
"average": 1.77,
|
||||
"p50": 1.34,
|
||||
"p95": 4.21,
|
||||
"p99": 13.04
|
||||
},
|
||||
"mspt_worst_p99": 47.5,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 686.54,
|
||||
"max": 686.7
|
||||
},
|
||||
"cpu_percent": 27.92,
|
||||
"chunks_per_second": 9.94,
|
||||
"unique_per_second": 0.01,
|
||||
"forgotten_per_second": 9.9,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 6092,
|
||||
"chunks_per_bot": {
|
||||
"walk": 6092.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": 20.45,
|
||||
"mspt": {
|
||||
"average": 11.34,
|
||||
"p50": 10.6,
|
||||
"p95": 17.12,
|
||||
"p99": 33.22
|
||||
},
|
||||
"mspt_worst_p99": 119.1,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 3404.16,
|
||||
"max": 3416.3
|
||||
},
|
||||
"cpu_percent": 35.93,
|
||||
"chunks_per_second": 9.98,
|
||||
"unique_per_second": 0.01,
|
||||
"forgotten_per_second": 9.93,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 6084,
|
||||
"chunks_per_bot": {
|
||||
"walk": 6084.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": 59
|
||||
},
|
||||
{
|
||||
"server": "horizon",
|
||||
"bots": 10,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 19.54,
|
||||
"mspt": {
|
||||
"average": 4.74,
|
||||
"p50": 3.83,
|
||||
"p95": 10.48,
|
||||
"p99": 19.69
|
||||
},
|
||||
"mspt_worst_p99": 120.1,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 855.26,
|
||||
"max": 882.7
|
||||
},
|
||||
"cpu_percent": 29.78,
|
||||
"chunks_per_second": 61.35,
|
||||
"unique_per_second": 1.79,
|
||||
"forgotten_per_second": 61.47,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 40762,
|
||||
"chunks_per_bot": {
|
||||
"walk": 6247.67,
|
||||
"explore": 1165.0,
|
||||
"idle": 473.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 701.83,
|
||||
"explore": 1086.0,
|
||||
"idle": 473.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 4159,
|
||||
"moved_too_quickly": 0,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 10,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "vanilla",
|
||||
"bots": 10,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 19.95,
|
||||
"mspt": {
|
||||
"average": 34.3,
|
||||
"p50": 32.2,
|
||||
"p95": 53.72,
|
||||
"p99": 89.08
|
||||
},
|
||||
"mspt_worst_p99": 375.8,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 3713.5,
|
||||
"max": 3754.9
|
||||
},
|
||||
"cpu_percent": 128.07,
|
||||
"chunks_per_second": 61.66,
|
||||
"unique_per_second": 1.93,
|
||||
"forgotten_per_second": 61.71,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 37568,
|
||||
"chunks_per_bot": {
|
||||
"walk": 5729.0,
|
||||
"explore": 1124.0,
|
||||
"idle": 473.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 701.17,
|
||||
"explore": 1055.0,
|
||||
"idle": 473.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 3976,
|
||||
"moved_too_quickly": 20,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 10,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "horizon",
|
||||
"bots": 25,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 9.61,
|
||||
"mspt": {
|
||||
"average": 11.72,
|
||||
"p50": 9.88,
|
||||
"p95": 24.45,
|
||||
"p99": 43.79
|
||||
},
|
||||
"mspt_worst_p99": 129.8,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 947.35,
|
||||
"max": 1086.1
|
||||
},
|
||||
"cpu_percent": 57.83,
|
||||
"chunks_per_second": 158.57,
|
||||
"unique_per_second": 5.78,
|
||||
"forgotten_per_second": 158.45,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 108126,
|
||||
"chunks_per_bot": {
|
||||
"walk": 6628.53,
|
||||
"explore": 1266.6,
|
||||
"idle": 473.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 704.67,
|
||||
"explore": 1189.2,
|
||||
"idle": 473.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 3496,
|
||||
"moved_too_quickly": 0,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 25,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "vanilla",
|
||||
"bots": 25,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 37.78,
|
||||
"mspt": {
|
||||
"average": 50.45,
|
||||
"p50": 46.39,
|
||||
"p95": 74.09,
|
||||
"p99": 191.21
|
||||
},
|
||||
"mspt_worst_p99": 1388.1,
|
||||
"tps": 19.82,
|
||||
"rss_mb": {
|
||||
"mean": 3866.18,
|
||||
"max": 4745.0
|
||||
},
|
||||
"cpu_percent": 192.42,
|
||||
"chunks_per_second": 157.63,
|
||||
"unique_per_second": 8.25,
|
||||
"forgotten_per_second": 156.12,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 88763,
|
||||
"chunks_per_bot": {
|
||||
"walk": 5387.0,
|
||||
"explore": 1118.6,
|
||||
"idle": 473.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 699.0,
|
||||
"explore": 1075.0,
|
||||
"idle": 473.0
|
||||
},
|
||||
"resent": 2,
|
||||
"pulled_back": 3629,
|
||||
"moved_too_quickly": 296,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 25,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "horizon",
|
||||
"bots": 50,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 14.93,
|
||||
"mspt": {
|
||||
"average": 23.82,
|
||||
"p50": 20.11,
|
||||
"p95": 50.98,
|
||||
"p99": 74.64
|
||||
},
|
||||
"mspt_worst_p99": 195.9,
|
||||
"tps": 20.0,
|
||||
"rss_mb": {
|
||||
"mean": 1031.41,
|
||||
"max": 1201.2
|
||||
},
|
||||
"cpu_percent": 98.21,
|
||||
"chunks_per_second": 302.81,
|
||||
"unique_per_second": 10.96,
|
||||
"forgotten_per_second": 303.47,
|
||||
"waited_ticks_per_second": 0.0,
|
||||
"chunks_total": 212181,
|
||||
"chunks_per_bot": {
|
||||
"walk": 6496.53,
|
||||
"explore": 1255.5,
|
||||
"idle": 473.0
|
||||
},
|
||||
"unique_chunks_per_bot": {
|
||||
"walk": 701.9,
|
||||
"explore": 1184.7,
|
||||
"idle": 473.0
|
||||
},
|
||||
"resent": 0,
|
||||
"pulled_back": 7565,
|
||||
"moved_too_quickly": 0,
|
||||
"moved_wrongly": 0,
|
||||
"bots_joined": 50,
|
||||
"bots_failed": [],
|
||||
"tick_queries": 58
|
||||
},
|
||||
{
|
||||
"server": "vanilla",
|
||||
"bots": 50,
|
||||
"behaviour": "mixed",
|
||||
"start_seconds": 11.16,
|
||||
"error": "stopped by its watchdog 30 s after the last bot joined: \"A single server tick took 60.01 seconds (should be max 0.05)\" (Player.tick)"
|
||||
}
|
||||
],
|
||||
"work": [
|
||||
{
|
||||
"behaviour": "mixed",
|
||||
"bots": 1,
|
||||
"servers": {
|
||||
"horizon": {
|
||||
"chunks_per_second": {
|
||||
"value": 9.94,
|
||||
"share": 0.996
|
||||
},
|
||||
"unique_per_second": {
|
||||
"value": 0.01,
|
||||
"share": 1.0
|
||||
},
|
||||
"waited_ticks_per_second": 0.0
|
||||
},
|
||||
"vanilla": {
|
||||
"chunks_per_second": {
|
||||
"value": 9.98,
|
||||
"share": 1.0
|
||||
},
|
||||
"unique_per_second": {
|
||||
"value": 0.01,
|
||||
"share": 1.0
|
||||
},
|
||||
"waited_ticks_per_second": 0.0
|
||||
}
|
||||
},
|
||||
"equal": true
|
||||
},
|
||||
{
|
||||
"behaviour": "mixed",
|
||||
"bots": 10,
|
||||
"servers": {
|
||||
"horizon": {
|
||||
"chunks_per_second": {
|
||||
"value": 61.35,
|
||||
"share": 0.995
|
||||
},
|
||||
"unique_per_second": {
|
||||
"value": 1.79,
|
||||
"share": 0.927
|
||||
},
|
||||
"waited_ticks_per_second": 0.0
|
||||
},
|
||||
"vanilla": {
|
||||
"chunks_per_second": {
|
||||
"value": 61.66,
|
||||
"share": 1.0
|
||||
},
|
||||
"unique_per_second": {
|
||||
"value": 1.93,
|
||||
"share": 1.0
|
||||
},
|
||||
"waited_ticks_per_second": 0.0
|
||||
}
|
||||
},
|
||||
"equal": true
|
||||
},
|
||||
{
|
||||
"behaviour": "mixed",
|
||||
"bots": 25,
|
||||
"servers": {
|
||||
"horizon": {
|
||||
"chunks_per_second": {
|
||||
"value": 158.57,
|
||||
"share": 1.0
|
||||
},
|
||||
"unique_per_second": {
|
||||
"value": 5.78,
|
||||
"share": 0.701
|
||||
},
|
||||
"waited_ticks_per_second": 0.0
|
||||
},
|
||||
"vanilla": {
|
||||
"chunks_per_second": {
|
||||
"value": 157.63,
|
||||
"share": 0.994
|
||||
},
|
||||
"unique_per_second": {
|
||||
"value": 8.25,
|
||||
"share": 1.0
|
||||
},
|
||||
"waited_ticks_per_second": 0.0
|
||||
}
|
||||
},
|
||||
"equal": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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)"
|
||||
}
|
||||
@@ -31,31 +31,42 @@ toml = "1.1"
|
||||
naga = { version = "30.0.1", features = ["wgsl-in"] }
|
||||
# Java (OptiFine/Iris) shader packs, translated to WGSL.
|
||||
horizon-shaderpack = { path = "../horizon-shaderpack" }
|
||||
cpal = "0.16"
|
||||
# Sound (ALSA on Linux); the `audio` feature.
|
||||
cpal = { version = "0.16", optional = true }
|
||||
symphonia = { version = "0.5", default-features = false, features = ["ogg", "vorbis"] }
|
||||
miniz_oxide = "0.8"
|
||||
ab_glyph = "0.2.32"
|
||||
log = "0.4"
|
||||
chrono = { version = "0.4.42", default-features = false, features = ["clock", "std"] }
|
||||
flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"] }
|
||||
flate2 = { version = "1.1.10", default-features = false, features = ["zlib-rs", "runtime_detection"] }
|
||||
horizon-theme = { path = "../horizon-theme" }
|
||||
# Opt-in data collection: the game keeps, the launcher sends (docs/telemetry.md).
|
||||
horizon-telemetry = { path = "../horizon-telemetry", default-features = false }
|
||||
horizon-bench = { path = "../horizon-bench" }
|
||||
arboard = { version = "3.6.1", default-features = false, features = ["wayland-data-control"] }
|
||||
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||
# Controllers (evdev + libudev on Linux, IOKit on macOS, Windows.Gaming.Input).
|
||||
gilrs = "0.11"
|
||||
# Controllers (evdev + libudev on Linux, IOKit on macOS, Windows.Gaming.Input); the `controllers` feature.
|
||||
gilrs = { version = "0.11", optional = true }
|
||||
# The DualSense's rumble, adaptive triggers and lights over HID (gilrs only reads it).
|
||||
horizon-dualsense = { path = "../horizon-dualsense" }
|
||||
horizon-dualsense = { path = "../horizon-dualsense", optional = true }
|
||||
# HTTPS to the Minecraft services (online-mode session join).
|
||||
ureq = { version = "2", default-features = false, features = ["tls"] }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
# The server thread's CPU time per tick (`HORIZON_SPIKES`, spans.rs).
|
||||
rustix = { version = "1", default-features = false, features = ["std", "time"] }
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
# The icon resource in the .exe (build.rs).
|
||||
winresource = "0.1"
|
||||
|
||||
[features]
|
||||
default = ["audio", "controllers"]
|
||||
# Sound output. Without it (and `controllers`) the program links neither libasound nor libudev on
|
||||
# Linux: the server build (`--no-default-features`, released as horizon-engine; docs/server.md).
|
||||
audio = ["dep:cpal"]
|
||||
# Controllers: gilrs, and the DualSense's own output. Without it only `horizon-ctl pad`'s virtual pad.
|
||||
controllers = ["dep:gilrs", "dep:horizon-dualsense"]
|
||||
# Records the call sites of mob random draws (`mob_ai_probe` traces).
|
||||
rng-trace = ["horizon-core/rng-trace"]
|
||||
|
||||
|
||||
@@ -58,11 +58,12 @@ fn main() -> Result<()> {
|
||||
let root = PathBuf::from(&args[0]);
|
||||
let dir = PathBuf::from(&args[1]);
|
||||
let assets = Assets::load(&root)?;
|
||||
let mut scene = World::test_scene(&assets, 1)?;
|
||||
let render = assets.reload(&root)?;
|
||||
let mut scene = World::test_scene(&assets, &render, 1)?;
|
||||
fs::write(
|
||||
dir.join("scene.json"),
|
||||
serde_json::to_vec(
|
||||
&serde_json::json!({"radius":1,"resident_chunks":scene.chunks.len(),"model_gallery":assets.model_gallery}),
|
||||
&serde_json::json!({"radius":1,"resident_chunks":scene.chunks.len(),"model_gallery":render.model_gallery}),
|
||||
)?,
|
||||
)?;
|
||||
if args[2] == "--describe" {
|
||||
|
||||
@@ -31,13 +31,14 @@ fn main() -> Result<()> {
|
||||
};
|
||||
let root = PathBuf::from(root);
|
||||
let assets = Assets::load(&root)?;
|
||||
let mut scene = World::test_scene(&assets, 1)?;
|
||||
let render = assets.reload(&root)?;
|
||||
let mut scene = World::test_scene(&assets, &render, 1)?;
|
||||
let binding = collisions::load(&root, assets.registry)?;
|
||||
let resources = MotionResources::load(&root, &assets)?;
|
||||
fs::write(
|
||||
scene_json,
|
||||
serde_json::to_vec(&serde_json::json!({
|
||||
"radius": 1, "resident_chunks": scene.chunks.len(), "model_gallery": assets.model_gallery,
|
||||
"radius": 1, "resident_chunks": scene.chunks.len(), "model_gallery": render.model_gallery,
|
||||
}))?,
|
||||
)?;
|
||||
let mut out = BufWriter::new(fs::File::create(output)?);
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
//! The Rust side of tools/test_block_entity_tickers_parity.py: the ops of
|
||||
//! `VanillaBlockEntityTickerOracle` on `BlockEntities`, as `World` drives it
|
||||
//! (a state write calls `state_changed`), printing the tick order.
|
||||
use horizon_client::{
|
||||
block_entities::{BlockEntities, Pos, Ticking},
|
||||
containers::BlockEntity,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// State ids of the fixture: 0 air, 1 a block whose block entity ticks, 2 a
|
||||
/// jukebox without a record, 3 a block entity that never ticks (a chest).
|
||||
fn state(name: &str) -> u32 {
|
||||
match name {
|
||||
"chest" | "barrel" => 3,
|
||||
"jukebox" => 2,
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn entity(name: &str) -> BlockEntity {
|
||||
if name.starts_with("jukebox") {
|
||||
// The game makes a jukebox's block entity when a record goes in.
|
||||
return BlockEntity::Jukebox(Default::default());
|
||||
}
|
||||
BlockEntity::for_block(&format!("minecraft:{name}"))
|
||||
.unwrap_or_else(|| panic!("no block entity for {name}"))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let input = std::fs::read_to_string(&args[1]).expect("input");
|
||||
let mut out = String::new();
|
||||
let mut entities = BlockEntities::default();
|
||||
let mut states: HashMap<Pos, u32> = HashMap::new();
|
||||
let mut kinds: HashMap<Pos, String> = HashMap::new();
|
||||
let table = vec![Ticking::No, Ticking::Yes, Ticking::Idle, Ticking::No];
|
||||
for line in input.lines() {
|
||||
let w: Vec<&str> = line.split_whitespace().collect();
|
||||
let pos = |i: usize| -> Pos {
|
||||
let n = |j: usize| w[i + j].parse::<i32>().expect("coordinate");
|
||||
(n(0), n(1), n(2))
|
||||
};
|
||||
match w[0] {
|
||||
"reset" => {
|
||||
entities = BlockEntities::default();
|
||||
entities.set_states(table.clone());
|
||||
states.clear();
|
||||
kinds.clear();
|
||||
}
|
||||
"load" => {
|
||||
let mut chunk = Vec::new();
|
||||
for i in (3..w.len()).step_by(4) {
|
||||
let p = pos(i + 1);
|
||||
states.insert(p, state(w[i]));
|
||||
kinds.insert(p, w[i].to_owned());
|
||||
chunk.push((p, entity(w[i])));
|
||||
}
|
||||
entities.load_chunk(chunk);
|
||||
}
|
||||
"place" => {
|
||||
let p = pos(2);
|
||||
// World::set, then the game adds the block entity.
|
||||
let old = states.insert(p, state(w[1])).unwrap_or(0);
|
||||
kinds.insert(p, w[1].to_owned());
|
||||
entities.state_changed(p, old, state(w[1]));
|
||||
entities.insert(p, entity(w[1]));
|
||||
}
|
||||
"replace" => {
|
||||
let p = pos(1);
|
||||
entities.insert(p, entity(&kinds[&p]));
|
||||
}
|
||||
"remove" => {
|
||||
let p = pos(1);
|
||||
entities.remove(&p);
|
||||
let old = states.insert(p, 0).unwrap_or(0);
|
||||
entities.state_changed(p, old, 0);
|
||||
}
|
||||
"record" => {
|
||||
let p = pos(1);
|
||||
let s = if w[4] == "1" { 1 } else { 2 };
|
||||
let old = states.insert(p, s).unwrap_or(0);
|
||||
entities.state_changed(p, old, s);
|
||||
}
|
||||
"unload" => {
|
||||
let c = (w[1].parse::<i32>().unwrap(), w[2].parse::<i32>().unwrap());
|
||||
entities.retain(|p, _| (p.0 >> 4, p.2 >> 4) != c);
|
||||
}
|
||||
"tick" => {
|
||||
out.push_str("tick");
|
||||
for (p, _) in entities.tickers(|p| states.get(&p).copied().unwrap_or(0)) {
|
||||
out.push_str(&format!(" {},{},{}", p.0, p.1, p.2));
|
||||
}
|
||||
out.push('\n');
|
||||
}
|
||||
other => panic!("unknown op {other}"),
|
||||
}
|
||||
}
|
||||
std::fs::write(&args[2], out).expect("output");
|
||||
}
|
||||
@@ -12,9 +12,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let root = Path::new(&args[1]);
|
||||
let assets = Assets::load(root)?;
|
||||
let render = assets.reload(root)?;
|
||||
let facts = BlockFacts::load(root, assets.registry)?;
|
||||
let tables = MeshTables::new(
|
||||
&assets,
|
||||
&render,
|
||||
&facts,
|
||||
models::load_visibility(root, assets.registry)?,
|
||||
)?;
|
||||
|
||||
@@ -18,9 +18,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let root = Path::new(&args[1]);
|
||||
let assets = Assets::load(root)?;
|
||||
let render = assets.reload(root)?;
|
||||
let facts = BlockFacts::load(root, assets.registry)?;
|
||||
let tables = MeshTables::new(
|
||||
&assets,
|
||||
&render,
|
||||
&facts,
|
||||
models::load_visibility(root, assets.registry)?,
|
||||
)?;
|
||||
@@ -33,7 +35,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut vertices = Vec::new();
|
||||
let mut translucent = false;
|
||||
if facts.get(state).render_shape == RenderShape::Model {
|
||||
let models = assets
|
||||
let models = render
|
||||
.model_catalog
|
||||
.collect(state, BlockPos::new(p[0], p[1], p[2]))?;
|
||||
let offset = tables.offset(state, p[0], p[2]).unwrap_or([0.0; 3]);
|
||||
|
||||
@@ -31,10 +31,12 @@ fn main() -> Result<()> {
|
||||
};
|
||||
let (seed, size) = (flag("--seed", 12345), flag("--size", 8) as i32);
|
||||
let assets = Assets::load(&root)?;
|
||||
let render = assets.reload(&root)?;
|
||||
let facts = BlockFacts::load(&root, assets.registry)?;
|
||||
let biomes = Biomes::load(&root)?;
|
||||
let tables = MeshTables::new(
|
||||
&assets,
|
||||
&render,
|
||||
&facts,
|
||||
models::load_visibility(&root, assets.registry)?,
|
||||
)?;
|
||||
@@ -132,6 +134,7 @@ fn main() -> Result<()> {
|
||||
let mut mesher = Mesher {
|
||||
nether_shading: false,
|
||||
assets: &assets,
|
||||
render: &render,
|
||||
tables: &tables,
|
||||
biomes: &biomes,
|
||||
visibility: tables.visibility.clone(),
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
use horizon_client::interaction_input::{
|
||||
Button, InteractionInput, InteractionWorld, TargetUseWorld, use_on_target,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use std::io::{BufRead, Write};
|
||||
|
||||
struct World {
|
||||
using: bool,
|
||||
destroying: bool,
|
||||
entity: bool,
|
||||
dig_on_attack: bool,
|
||||
begin_using: bool,
|
||||
delay: u32,
|
||||
events: Vec<String>,
|
||||
passing: bool,
|
||||
}
|
||||
impl InteractionWorld for World {
|
||||
fn using_item(&self) -> bool {
|
||||
self.using
|
||||
}
|
||||
fn release_using(&mut self) {
|
||||
self.events.push("release".into());
|
||||
self.using = false;
|
||||
}
|
||||
fn start_attack(&mut self) -> bool {
|
||||
self.events.push("attack".into());
|
||||
if !self.entity {
|
||||
self.destroying = self.dig_on_attack;
|
||||
}
|
||||
false
|
||||
}
|
||||
fn start_use(&mut self) {
|
||||
if self.destroying {
|
||||
return;
|
||||
}
|
||||
self.delay = 4;
|
||||
let entity = self.entity;
|
||||
use_on_target(self, entity);
|
||||
}
|
||||
fn pick(&mut self) {
|
||||
self.events.push("pick".into());
|
||||
}
|
||||
fn use_delay(&self) -> u32 {
|
||||
self.delay
|
||||
}
|
||||
fn continue_attack(&mut self, down: bool) {
|
||||
if self.using {
|
||||
return;
|
||||
}
|
||||
let down = down && !self.entity;
|
||||
self.events.push(format!("continue {down}"));
|
||||
if !down {
|
||||
self.destroying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TargetUseWorld for World {
|
||||
fn use_entity(&mut self) -> bool {
|
||||
self.events
|
||||
.push(if self.passing { "entity" } else { "use" }.into());
|
||||
if self.passing {
|
||||
false
|
||||
} else {
|
||||
self.using = self.begin_using;
|
||||
true
|
||||
}
|
||||
}
|
||||
fn use_block(&mut self) -> bool {
|
||||
self.events
|
||||
.push(if self.passing { "block" } else { "use" }.into());
|
||||
if self.passing {
|
||||
false
|
||||
} else {
|
||||
self.using = self.begin_using;
|
||||
true
|
||||
}
|
||||
}
|
||||
fn use_item(&mut self) {
|
||||
self.events.push("item".into());
|
||||
self.using = self.begin_using;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let input = std::io::BufReader::new(std::fs::File::open(&args[1])?);
|
||||
let mut out = std::io::BufWriter::new(std::fs::File::create(&args[2])?);
|
||||
for (i, line) in input.lines().enumerate() {
|
||||
let row: Value = serde_json::from_str(&line?)?;
|
||||
let flag = |key: &str| row[key].as_bool().unwrap();
|
||||
let mut world = World {
|
||||
using: flag("using"),
|
||||
destroying: flag("destroying"),
|
||||
entity: flag("entity"),
|
||||
dig_on_attack: flag("dig_on_attack"),
|
||||
begin_using: flag("begin_using"),
|
||||
delay: row["delay"].as_u64().unwrap() as u32,
|
||||
events: vec![],
|
||||
passing: row["passing"].as_bool().unwrap_or(false),
|
||||
};
|
||||
let mut input = InteractionInput::default();
|
||||
for button in row["clicks"].as_array().unwrap() {
|
||||
input.press(match button.as_u64().unwrap() {
|
||||
0 => Button::Attack,
|
||||
1 => Button::Use,
|
||||
_ => Button::Pick,
|
||||
});
|
||||
}
|
||||
input.tick(&mut world, flag("attack_down"), flag("use_down"));
|
||||
writeln!(out, "== {i}")?;
|
||||
for event in world.events {
|
||||
writeln!(out, "{event}")?;
|
||||
}
|
||||
writeln!(
|
||||
out,
|
||||
"state {} {} {}",
|
||||
world.using, world.destroying, world.delay
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -101,6 +101,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
sprinting: false,
|
||||
equipment: Default::default(),
|
||||
health: 20.0,
|
||||
attributes: Vec::new(),
|
||||
living_flags: 0,
|
||||
};
|
||||
loop {
|
||||
world.game_time += 1;
|
||||
@@ -128,7 +130,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
eprintln!("[lan] {packet:?}");
|
||||
}
|
||||
}
|
||||
HostEvent::Chat(line) | HostEvent::Warn(line) => println!("{line}"),
|
||||
HostEvent::Chat { line, .. } | HostEvent::Warn(line) | HostEvent::Error(line) => {
|
||||
println!("{line}")
|
||||
}
|
||||
HostEvent::Left(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ fn incremental(
|
||||
sky_light: bool,
|
||||
edits: usize,
|
||||
) {
|
||||
use horizon_client::light::relight;
|
||||
use horizon_client::light::{LightChanges, relight};
|
||||
use std::sync::Arc;
|
||||
let mut world: HashMap<(i32, i32), Arc<Chunk>> = HashMap::new();
|
||||
let inner: Vec<(i32, i32)> = {
|
||||
@@ -285,7 +285,14 @@ fn incremental(
|
||||
if old == state || !tables.differs(old, state) {
|
||||
continue;
|
||||
}
|
||||
relight(&mut world, tables, sky_light, &[(x, y, z)], false);
|
||||
relight(
|
||||
&mut world,
|
||||
tables,
|
||||
sky_light,
|
||||
&[(x, y, z)],
|
||||
false,
|
||||
&mut LightChanges::default(),
|
||||
);
|
||||
for dz in -1..=1 {
|
||||
for dx in -1..=1 {
|
||||
let (kx, kz) = (cx + dx, cz + dz);
|
||||
|
||||
@@ -999,6 +999,7 @@ fn main() -> horizon_client::Result<()> {
|
||||
hero: false,
|
||||
uuid: PLAYER_UUID,
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
}
|
||||
});
|
||||
let mut scratch = LegacyRandom::new(0);
|
||||
|
||||
@@ -56,10 +56,11 @@ fn main() -> horizon_client::Result<()> {
|
||||
let initial = LIVE.load(Relaxed);
|
||||
let start = Instant::now();
|
||||
let assets = Assets::load(root)?;
|
||||
let render = assets.reload(root)?;
|
||||
let block_ms = start.elapsed().as_secs_f64() * 1000.;
|
||||
let block_retained = LIVE.load(Relaxed) - initial;
|
||||
let start_items = Instant::now();
|
||||
let items = ItemRenderer::load_with_library(root, assets.model_library.clone())?;
|
||||
let items = ItemRenderer::load_with_library(root, render.model_library.clone())?;
|
||||
let item_ms = start_items.elapsed().as_secs_f64() * 1000.;
|
||||
let total_ms = start.elapsed().as_secs_f64() * 1000.;
|
||||
let retained = LIVE.load(Relaxed) - initial;
|
||||
@@ -74,7 +75,7 @@ fn main() -> horizon_client::Result<()> {
|
||||
horizon_core::position::BlockPos::new(0, 0, 0),
|
||||
horizon_core::position::BlockPos::new(-17, 65, 31),
|
||||
] {
|
||||
if let Ok(selected) = assets.model_catalog.collect(id, pos) {
|
||||
if let Ok(selected) = render.model_catalog.collect(id, pos) {
|
||||
for (variant, model) in selected {
|
||||
format!("{variant:?}").hash(&mut hash);
|
||||
model.ambient_occlusion.hash(&mut hash);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
use horizon_client::player_sync::{PositionSender, teleport_velocity};
|
||||
use horizon_core::geometry::Vec3;
|
||||
use horizon_protocol::packets::play::{PlayerPosition, Serverbound as S};
|
||||
use serde_json::Value;
|
||||
use std::io::{BufRead, Write};
|
||||
|
||||
fn number(value: &Value) -> f64 {
|
||||
f64::from_bits(u64::from_str_radix(value.as_str().unwrap(), 16).unwrap())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let input = std::io::BufReader::new(std::fs::File::open(&args[1])?);
|
||||
let mut out = std::io::BufWriter::new(std::fs::File::create(&args[2])?);
|
||||
for line in input.lines() {
|
||||
let row: Value = serde_json::from_str(&line?)?;
|
||||
if row["kind"] == "movement" {
|
||||
let mut sender = PositionSender::default();
|
||||
for op in row["ops"].as_array().unwrap() {
|
||||
let pos = std::array::from_fn(|i| number(&op[i]));
|
||||
let rot = (number(&op[3]) as f32, number(&op[4]) as f32);
|
||||
if let Some(packet) =
|
||||
sender.update(pos, rot, op[5].as_bool().unwrap(), op[6].as_bool().unwrap())
|
||||
{
|
||||
let name = match packet {
|
||||
S::MovePlayerPos(_) => "pos",
|
||||
S::MovePlayerPosRot(_) => "posrot",
|
||||
S::MovePlayerRot(_) => "rot",
|
||||
S::MovePlayerStatus(_) => "status",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
write!(out, "{name} ")?;
|
||||
for byte in &packet.encode()[1..] {
|
||||
write!(out, "{byte:02x}")?;
|
||||
}
|
||||
writeln!(out)?;
|
||||
} else {
|
||||
writeln!(out, "-")?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let vector = |key: &str| {
|
||||
Vec3::new(
|
||||
number(&row[key][0]),
|
||||
number(&row[key][1]),
|
||||
number(&row[key][2]),
|
||||
)
|
||||
};
|
||||
let rotation = |key: &str| (number(&row[key][0]) as f32, number(&row[key][1]) as f32);
|
||||
let old = rotation("old");
|
||||
let new = rotation("new");
|
||||
let delta = vector("delta");
|
||||
let packet = PlayerPosition {
|
||||
teleport: 0,
|
||||
position: [0.0; 3],
|
||||
delta: [delta.x, delta.y, delta.z],
|
||||
yaw: new.0,
|
||||
pitch: new.1,
|
||||
relatives: row["flags"].as_i64().unwrap() as i32,
|
||||
};
|
||||
let v = teleport_velocity(vector("velocity"), old, new, &packet);
|
||||
writeln!(
|
||||
out,
|
||||
"{:016x} {:016x} {:016x}",
|
||||
v.x.to_bits(),
|
||||
v.y.to_bits(),
|
||||
v.z.to_bits()
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
//! The `entity_portals` section scan only: `may_hold_portal` over synthetic
|
||||
//! entity reaches, with the per-tick palette map against the resident cache.
|
||||
//! Run with prepared client resources:
|
||||
//! cargo run --profile fast -p horizon-client --example portal_scan_bench -- RESOURCES
|
||||
use horizon_client::{
|
||||
blocks::BlockFacts,
|
||||
chunk::{Chunk, MIN_Y, SECTIONS, Section},
|
||||
fast_hash::FxHashMap,
|
||||
portal_sections::PortalSections,
|
||||
};
|
||||
use horizon_core::{
|
||||
geometry::{Aabb, Vec3},
|
||||
position::BlockPos,
|
||||
};
|
||||
use horizon_world::{level::Behaviours, registry::BlockStateId};
|
||||
use std::{hint::black_box, path::Path, sync::Arc, time::Instant};
|
||||
|
||||
/// `Game::swept_portal`'s reach (`Entity.checkInsideBlocks`'s swept box).
|
||||
fn reach(from: Vec3, to: Vec3, width: f32, height: f32) -> Aabb {
|
||||
let half = f64::from(width) / 2.0;
|
||||
let bounds = Aabb::new(
|
||||
Vec3::new(to.x - half, to.y, to.z - half),
|
||||
Vec3::new(to.x + half, to.y + f64::from(height), to.z + half),
|
||||
)
|
||||
.deflate(Vec3::new(1.0e-5, 1.0e-5, 1.0e-5));
|
||||
bounds
|
||||
.union_bounds(bounds.move_by(from.subtract(to)))
|
||||
.inflate(Vec3::new(1.0, 1.0, 1.0))
|
||||
}
|
||||
|
||||
fn sections(reach: Aabb) -> (i64, i32, i32, i32, i32, i32, i32) {
|
||||
let (min, max) = (reach.min_position(), reach.max_position());
|
||||
let (min, max) = (BlockPos::containing(min), BlockPos::containing(max));
|
||||
let top = SECTIONS as i32 - 1;
|
||||
let (x0, x1) = (min.x >> 4, max.x >> 4);
|
||||
let (z0, z1) = (min.z >> 4, max.z >> 4);
|
||||
let (y0, y1) = (
|
||||
((min.y - MIN_Y) >> 4).clamp(0, top),
|
||||
((max.y - MIN_Y) >> 4).clamp(0, top),
|
||||
);
|
||||
let count = (i64::from(x1) - i64::from(x0) + 1)
|
||||
* (i64::from(y1) - i64::from(y0) + 1)
|
||||
* (i64::from(z1) - i64::from(z0) + 1);
|
||||
(count, x0, x1, y0, y1, z0, z1)
|
||||
}
|
||||
|
||||
/// The original `Game::may_hold_portal`: per-tick `seen`, palette per section.
|
||||
fn may_hold_portal_baseline(
|
||||
reach: Aabb,
|
||||
world: &FxHashMap<(i32, i32), Arc<Chunk>>,
|
||||
seen: &mut FxHashMap<(i32, i32, i32), bool>,
|
||||
behaviours: &Behaviours,
|
||||
) -> bool {
|
||||
let (count, x0, x1, y0, y1, z0, z1) = sections(reach);
|
||||
if count > 64 {
|
||||
return true;
|
||||
}
|
||||
(x0..=x1).any(|cx| {
|
||||
(z0..=z1).any(|cz| {
|
||||
(y0..=y1).any(|sy| {
|
||||
*seen.entry((cx, sy, cz)).or_insert_with(|| {
|
||||
world
|
||||
.get(&(cx, cz))
|
||||
.and_then(|c| c.sections.get(sy as usize))
|
||||
.is_some_and(|s| {
|
||||
s.blocks
|
||||
.maybe_has(|v| behaviours.portal_axis(BlockStateId(v)).is_some())
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// The cached `Game::may_hold_portal`: one mask per resident chunk.
|
||||
fn may_hold_portal_cached(
|
||||
reach: Aabb,
|
||||
world: &FxHashMap<(i32, i32), Arc<Chunk>>,
|
||||
cache: &mut PortalSections,
|
||||
behaviours: &Behaviours,
|
||||
) -> bool {
|
||||
let (count, x0, x1, y0, y1, z0, z1) = sections(reach);
|
||||
if count > 64 {
|
||||
return true;
|
||||
}
|
||||
let mut y_mask = 0u32;
|
||||
for sy in y0..=y1 {
|
||||
y_mask |= 1 << sy;
|
||||
}
|
||||
(x0..=x1).any(|cx| {
|
||||
(z0..=z1).any(|cz| {
|
||||
world.get(&(cx, cz)).is_some_and(|chunk| {
|
||||
cache.get((cx, cz), chunk, |v| {
|
||||
behaviours.portal_axis(BlockStateId(v)).is_some()
|
||||
}) & y_mask
|
||||
!= 0
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn main() -> horizon_client::Result<()> {
|
||||
let root = std::env::args()
|
||||
.nth(1)
|
||||
.ok_or("expected prepared client resource directory")?;
|
||||
let start = Instant::now();
|
||||
let registry = horizon_world::level::data::load_registry(Path::new(&root))?;
|
||||
let (facts, behaviours) = BlockFacts::load_pair(Path::new(&root), ®istry)?;
|
||||
println!(
|
||||
"resource_load_ms={:.3}",
|
||||
start.elapsed().as_secs_f64() * 1000.0
|
||||
);
|
||||
let len = registry.len() as u32;
|
||||
let portal: Vec<u32> = (0..len)
|
||||
.filter(|&id| behaviours.portal_axis(BlockStateId(id)).is_some())
|
||||
.collect();
|
||||
let inactive_states: Vec<u32> = (0..len)
|
||||
.filter(|&id| behaviours.portal_axis(BlockStateId(id)).is_none())
|
||||
.collect();
|
||||
let _ = &facts;
|
||||
let portal_state = *portal
|
||||
.first()
|
||||
.ok_or("no nether portal block state in the registry")?;
|
||||
println!("portal_states={}", portal.len());
|
||||
|
||||
// 500 entities spread over a 17x17 chunk world. Their reaches touch 1-4
|
||||
// sections, as an item or a mob standing in or stepping into a portal does.
|
||||
let grid = 17;
|
||||
let base = -(grid / 2) * 16;
|
||||
let entities: Vec<(Vec3, Vec3, f32, f32)> = (0..500)
|
||||
.map(|i| {
|
||||
let x = base + (i % grid) * 16 + (i % 5);
|
||||
let z = base + (i / grid % grid) * 16 + (i % 7);
|
||||
let y = 64 + (i % 3) * 16;
|
||||
let from = Vec3::new(f64::from(x), f64::from(y), f64::from(z));
|
||||
let to = from.add_vector(Vec3::new(0.1, 0.0, 0.07));
|
||||
(from, to, 0.25, 0.25)
|
||||
})
|
||||
.collect();
|
||||
let reaches: Vec<Aabb> = entities
|
||||
.iter()
|
||||
.map(|&(from, to, w, h)| reach(from, to, w, h))
|
||||
.collect();
|
||||
|
||||
for (name, palette, portals_every) in [
|
||||
("sparse", 1usize, 0usize),
|
||||
("dense", 128, 0),
|
||||
("global", 300, 0),
|
||||
("dense_portal", 128, 5),
|
||||
] {
|
||||
let start = Instant::now();
|
||||
let mut world: FxHashMap<(i32, i32), Arc<Chunk>> = FxHashMap::default();
|
||||
for czi in 0..grid {
|
||||
for cxi in 0..grid {
|
||||
let (cx, cz) = (-(grid / 2) + cxi, -(grid / 2) + czi);
|
||||
let mut chunk = Chunk::empty(cx, cz);
|
||||
for (i, section) in chunk.sections.iter_mut().enumerate() {
|
||||
let values: [u32; 4096] = std::array::from_fn(|j| {
|
||||
if portals_every > 0 && i % portals_every == 0 && j == 0 {
|
||||
portal_state
|
||||
} else {
|
||||
inactive_states[(j * 7 + i) % palette.min(inactive_states.len())]
|
||||
}
|
||||
});
|
||||
Arc::make_mut(section).blocks = Section::from_blocks(&values);
|
||||
}
|
||||
world.insert((cx, cz), Arc::new(chunk));
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"{name} fixture_ms={:.3}",
|
||||
start.elapsed().as_secs_f64() * 1000.0
|
||||
);
|
||||
let keys: Vec<_> = world.keys().copied().collect();
|
||||
let portal_chunks: Vec<(i32, i32)> = keys
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|&(cx, cz)| {
|
||||
world[&(cx, cz)]
|
||||
.sections
|
||||
.iter()
|
||||
.any(|s| s.blocks.maybe_has(|v| v == portal_state))
|
||||
})
|
||||
.collect();
|
||||
println!("{name} portal_chunks={}", portal_chunks.len());
|
||||
// The global palette's maybe_has walks the whole ID range, so rescanning
|
||||
// every chunk each tick (cold/reload/edit_all) is intractable; those rows
|
||||
// are only meaningful for the palettes whose scans are bounded.
|
||||
let workloads: &[(&str, usize)] = if name == "global" {
|
||||
&[("steady", 0), ("edit_1pct", 3)]
|
||||
} else {
|
||||
&[
|
||||
("steady", 0),
|
||||
("cold", 0),
|
||||
("reload", 0),
|
||||
("edit_1pct", 3),
|
||||
("edit_all", 289),
|
||||
]
|
||||
};
|
||||
for &(workload, changed) in workloads {
|
||||
let mut baseline = Vec::new();
|
||||
let mut candidate = Vec::new();
|
||||
let mut cache = PortalSections::default();
|
||||
let (mut base_hits, mut cand_hits) = (0u64, 0u64);
|
||||
for sample in 0..8 {
|
||||
for cached in if sample % 2 == 0 {
|
||||
[false, true]
|
||||
} else {
|
||||
[true, false]
|
||||
} {
|
||||
let start = Instant::now();
|
||||
let mut result = 0u64;
|
||||
for tick in 0..300 {
|
||||
if cached && workload == "cold" {
|
||||
cache = PortalSections::default();
|
||||
}
|
||||
if cached && workload == "reload" {
|
||||
cache.clear();
|
||||
}
|
||||
for key in keys.iter().take(changed) {
|
||||
Arc::make_mut(world.get_mut(key).unwrap()).set(
|
||||
0,
|
||||
MIN_Y,
|
||||
0,
|
||||
inactive_states[tick % inactive_states.len()],
|
||||
);
|
||||
}
|
||||
let mut seen = FxHashMap::default();
|
||||
for reach in &reaches {
|
||||
let hit = if cached {
|
||||
may_hold_portal_cached(*reach, &world, &mut cache, &behaviours)
|
||||
} else {
|
||||
may_hold_portal_baseline(*reach, &world, &mut seen, &behaviours)
|
||||
};
|
||||
result += hit as u64;
|
||||
}
|
||||
}
|
||||
if cached {
|
||||
cache = PortalSections::default();
|
||||
cand_hits += black_box(result);
|
||||
} else {
|
||||
base_hits += black_box(result);
|
||||
}
|
||||
if sample > 0 {
|
||||
let us = start.elapsed().as_secs_f64() * 1e6 / 300.0;
|
||||
if cached {
|
||||
candidate.push(us);
|
||||
} else {
|
||||
baseline.push(us);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
base_hits, cand_hits,
|
||||
"{name} {workload}: cached may_hold_portal diverged"
|
||||
);
|
||||
println!("{name} {workload} baseline_us={baseline:.3?} candidate_us={candidate:.3?}");
|
||||
}
|
||||
}
|
||||
println!("chunk_wrapper_bytes={}", std::mem::size_of::<Chunk>());
|
||||
Ok(())
|
||||
}
|
||||
@@ -94,12 +94,13 @@ fn main() -> Result<()> {
|
||||
drop(registry);
|
||||
step("registry dropped");
|
||||
let assets = Assets::load(&root)?;
|
||||
let render = assets.reload(&root)?;
|
||||
step("assets");
|
||||
println!(
|
||||
" sprites: {} layers of {}px, {:.0} MB of pixels",
|
||||
assets.texture_layers,
|
||||
assets.sprite_size,
|
||||
assets.pixels.len() as f64 / MB
|
||||
render.texture_layers,
|
||||
render.sprite_size,
|
||||
render.pixels.len() as f64 / MB
|
||||
);
|
||||
// The game decodes gameplay facts once for both tables (BlockFacts::load_pair).
|
||||
let (facts, behaviours) = BlockFacts::load_pair(&root, assets.registry)?;
|
||||
@@ -114,28 +115,15 @@ fn main() -> Result<()> {
|
||||
step("light tables");
|
||||
let tables = MeshTables::new(
|
||||
&assets,
|
||||
&render,
|
||||
&facts,
|
||||
models::load_visibility(&root, assets.registry)?,
|
||||
)?;
|
||||
step("mesh tables");
|
||||
let collision = collisions::load(&root, assets.registry)?;
|
||||
step("collision");
|
||||
let motion = MotionResources::load(&root, &assets)?;
|
||||
let motion = MotionResources::load_with_facts(&root, &assets, &facts)?;
|
||||
step("motion");
|
||||
for name in [
|
||||
"worldgen/blocks/block-properties.nbt",
|
||||
"worldgen/blocks/cached-collision.nbt",
|
||||
"worldgen/blocks/cached-support.nbt",
|
||||
"cached-collision.nbt",
|
||||
"occlusion.nbt",
|
||||
"movement-properties.nbt",
|
||||
] {
|
||||
let bytes = std::fs::read(root.join(name))?;
|
||||
let tree = horizon_world::nbt::read_named(&bytes, horizon_world::nbt::Limits::tables())?;
|
||||
step(&format!(" tree of {name}"));
|
||||
drop((tree, bytes));
|
||||
step(" dropped");
|
||||
}
|
||||
let terrain = VanillaTerrain::new(&root.join("worldgen"), assets.registry, &biomes, 1234)?;
|
||||
step("worldgen");
|
||||
println!(
|
||||
|
||||
@@ -66,7 +66,6 @@ fn fixture(per_chunk: usize) -> (Vec<Arc<Chunk>>, Entities, Names) {
|
||||
for s in &mut template.sections[..8] {
|
||||
Arc::make_mut(s).blocks = PalettedContainer::new(block_strategy(), 1);
|
||||
}
|
||||
template.heights = Arc::new([64; 256]);
|
||||
for i in 0..256 {
|
||||
let x = i % 16 - 8;
|
||||
let z = i / 16 - 8;
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
//! The region writer on real chunks, without a window: how long a world's
|
||||
//! chunks take to be encoded, compressed and written by `SaveDir`, against
|
||||
//! the same encoding and compression done one chunk after another (what the
|
||||
//! writer thread did alone before it had helpers).
|
||||
//!
|
||||
//! save_bench RESOURCES DIMENSION_DIR [--rounds N]
|
||||
//!
|
||||
//! DIMENSION_DIR is a saved dimension folder (`saves/W/dimensions/minecraft/
|
||||
//! overworld`); its chunks are read once, then each round saves them all into
|
||||
//! a scratch folder with `save_later` + `flush`, and times the one-thread
|
||||
//! baseline. The written chunks are checked byte for byte against the
|
||||
//! baseline's compressed records.
|
||||
use horizon_client::{
|
||||
assets::Assets,
|
||||
biome::Biomes,
|
||||
blocks::BlockFacts,
|
||||
save::{SaveDir, SaveTables, encode_with},
|
||||
};
|
||||
use horizon_core::position::ChunkPos;
|
||||
use horizon_world::{
|
||||
compression::Compression,
|
||||
nbt::Limits,
|
||||
region::{ChunkRecord, RegionFile},
|
||||
};
|
||||
use std::{path::PathBuf, sync::Arc, time::Instant};
|
||||
|
||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let usage = "usage: save_bench RESOURCES DIMENSION_DIR [--rounds N]";
|
||||
let root = PathBuf::from(args.first().ok_or(usage)?);
|
||||
let dimension = PathBuf::from(args.get(1).ok_or(usage)?);
|
||||
let rounds: usize = args
|
||||
.iter()
|
||||
.position(|a| a == "--rounds")
|
||||
.and_then(|i| args.get(i + 1))
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(5);
|
||||
|
||||
let assets = Assets::load(&root)?;
|
||||
let facts = BlockFacts::load(&root, assets.registry)?;
|
||||
let biomes = Arc::new(Biomes::load(&root)?);
|
||||
let tables = Arc::new(SaveTables::new(&assets).with_block_entities(&facts));
|
||||
let registry = assets.registry;
|
||||
|
||||
let source = SaveDir::new(dimension.clone());
|
||||
let _ = source.tables.set(tables.clone());
|
||||
let mut chunks = Vec::new();
|
||||
for entry in std::fs::read_dir(dimension.join("region"))? {
|
||||
let path = entry?.path();
|
||||
if path.extension().is_none_or(|e| e != "mca") {
|
||||
continue;
|
||||
}
|
||||
let region = RegionFile::open(&path)?;
|
||||
for (pos, _) in region.chunks() {
|
||||
if let Some(chunk) = source.load(pos.x, pos.z, registry, &biomes) {
|
||||
chunks.push(Arc::new(chunk));
|
||||
}
|
||||
}
|
||||
}
|
||||
chunks.sort_by_key(|c| (c.x, c.z));
|
||||
println!("{} chunks from {}", chunks.len(), dimension.display());
|
||||
|
||||
let scratch = std::env::temp_dir().join(format!("save_bench_{}", std::process::id()));
|
||||
// Encoding and compressing on one thread (what the writer did alone),
|
||||
// then SaveDir's writer with its helpers.
|
||||
let mut times = [Vec::new(), Vec::new(), Vec::new()];
|
||||
let mut written = Vec::new();
|
||||
for round in 0..rounds {
|
||||
let started = Instant::now();
|
||||
let tags: Vec<_> = chunks
|
||||
.iter()
|
||||
.map(|c| encode_with(c, registry, &biomes, Some(&tables), true))
|
||||
.collect();
|
||||
times[0].push(started.elapsed().as_secs_f64());
|
||||
let started = Instant::now();
|
||||
let baseline: Vec<ChunkRecord> = tags
|
||||
.iter()
|
||||
.map(|tag| ChunkRecord::from_nbt(tag, Compression::Zlib, 0, Limits::default()))
|
||||
.collect::<std::io::Result<_>>()?;
|
||||
times[1].push(started.elapsed().as_secs_f64());
|
||||
drop(tags);
|
||||
|
||||
let _ = std::fs::remove_dir_all(&scratch);
|
||||
let save = SaveDir::new(scratch.clone());
|
||||
let _ = save.tables.set(tables.clone());
|
||||
let started = Instant::now();
|
||||
save.save_later(&chunks, registry, &biomes)?;
|
||||
save.flush();
|
||||
times[2].push(started.elapsed().as_secs_f64());
|
||||
drop(save);
|
||||
|
||||
if round == 0 {
|
||||
for (chunk, want) in chunks.iter().zip(&baseline) {
|
||||
let path = scratch.join(format!("region/r.{}.{}.mca", chunk.x >> 5, chunk.z >> 5));
|
||||
let got = RegionFile::open(&path)?
|
||||
.read(ChunkPos::new(chunk.x, chunk.z))?
|
||||
.ok_or("a saved chunk is missing")?;
|
||||
if got.compressed != want.compressed {
|
||||
return Err(format!("chunk {} {} differs", chunk.x, chunk.z).into());
|
||||
}
|
||||
}
|
||||
written = baseline.iter().map(|r| r.compressed.len()).collect();
|
||||
}
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&scratch);
|
||||
println!(
|
||||
"{} KiB compressed, identical to the one-thread records",
|
||||
written.iter().sum::<usize>() / 1024
|
||||
);
|
||||
let per_chunk = 1000.0 / chunks.len() as f64;
|
||||
let names = [
|
||||
"one thread: encode",
|
||||
"one thread: compress",
|
||||
"SaveDir (encode, compress, write)",
|
||||
];
|
||||
for (name, t) in names.iter().zip(&mut times) {
|
||||
t.sort_by(f64::total_cmp);
|
||||
println!(
|
||||
"{name}: best {:.0} ms, median {:.0} ms of {rounds} ({:.3} ms per chunk at best)",
|
||||
t[0] * 1000.0,
|
||||
t[t.len() / 2] * 1000.0,
|
||||
t[0] * per_chunk
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -40,7 +40,8 @@ fn main() -> Result<()> {
|
||||
return Err("radius must be 1..16".into());
|
||||
}
|
||||
let assets = assets::Assets::load(&resources)?;
|
||||
let world = world::World::test_scene(&assets, radius)?;
|
||||
let render = assets.reload(&resources)?;
|
||||
let world = world::World::test_scene(&assets, &render, radius)?;
|
||||
let binding = collisions::load(&resources, assets.registry)?;
|
||||
let mut scene = collisions::SceneCollisions {
|
||||
world: &world,
|
||||
@@ -50,7 +51,7 @@ fn main() -> Result<()> {
|
||||
fs::write(
|
||||
dir.join("scene.json"),
|
||||
serde_json::to_vec(&serde_json::json!({
|
||||
"radius":radius,"resident_chunks":world.chunks.len(),"model_gallery":assets.model_gallery,
|
||||
"radius":radius,"resident_chunks":world.chunks.len(),"model_gallery":render.model_gallery,
|
||||
}))?,
|
||||
)?;
|
||||
let mut output = std::io::BufWriter::new(fs::File::create(dir.join("rust.txt"))?);
|
||||
|
||||
@@ -243,13 +243,14 @@ fn main() -> Result<()> {
|
||||
let root = PathBuf::from(&args[0]);
|
||||
let dir = PathBuf::from(&args[1]);
|
||||
let assets = Assets::load(&root)?;
|
||||
let mut scene = World::test_scene(&assets, 1)?;
|
||||
let render = assets.reload(&root)?;
|
||||
let mut scene = World::test_scene(&assets, &render, 1)?;
|
||||
let binding = collisions::load(&root, assets.registry)?;
|
||||
let resources = MotionResources::load(&root, &assets)?;
|
||||
fs::write(
|
||||
dir.join("scene.json"),
|
||||
serde_json::to_vec(
|
||||
&serde_json::json!({"radius":1,"resident_chunks":scene.chunks.len(),"model_gallery":assets.model_gallery}),
|
||||
&serde_json::json!({"radius":1,"resident_chunks":scene.chunks.len(),"model_gallery":render.model_gallery}),
|
||||
)?,
|
||||
)?;
|
||||
if args[2] == "--describe" {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! the oracle's canonical form (vanilla ARGB colours and packed light coords).
|
||||
#![forbid(unsafe_code)]
|
||||
use horizon_client::{
|
||||
assets::Assets,
|
||||
assets::{Assets, RenderAssets},
|
||||
biome::{BiomeInfo, Biomes, GrassModifier},
|
||||
blocks::BlockFacts,
|
||||
chunk::{Chunk, Light, MIN_Y, index},
|
||||
@@ -48,6 +48,7 @@ fn chunk_index(x: i32, z: i32) -> Result<usize> {
|
||||
fn scene(
|
||||
row: &Value,
|
||||
assets: &Assets,
|
||||
render: &RenderAssets,
|
||||
tables: &MeshTables,
|
||||
biomes: &mut Biomes,
|
||||
pristine: &[BiomeInfo],
|
||||
@@ -127,6 +128,7 @@ fn scene(
|
||||
let mut mesher = Mesher {
|
||||
nether_shading: row["nether"].as_bool().unwrap_or(false),
|
||||
assets,
|
||||
render,
|
||||
tables,
|
||||
biomes: &*biomes,
|
||||
visibility: tables.visibility.clone(),
|
||||
@@ -159,15 +161,8 @@ fn scene(
|
||||
let vertices: Vec<Value> = quad
|
||||
.iter()
|
||||
.map(|v| {
|
||||
json!([
|
||||
v.pos[0],
|
||||
v.pos[1],
|
||||
v.pos[2],
|
||||
v.uv[0],
|
||||
v.uv[1],
|
||||
argb(v.color),
|
||||
light_coords(v.light)
|
||||
])
|
||||
let ([x, y, z], [u, w]) = (v.pos, v.uv());
|
||||
json!([x, y, z, u, w, argb(v.color), light_coords(v.light)])
|
||||
})
|
||||
.collect();
|
||||
quads.push(json!({"layer": layer, "sprite": sprite, "vertices": vertices}));
|
||||
@@ -184,11 +179,12 @@ fn main() -> Result<()> {
|
||||
}
|
||||
let root = PathBuf::from(&args[0]);
|
||||
let assets = Assets::load(&root)?;
|
||||
let render = assets.reload(&root)?;
|
||||
let facts = BlockFacts::load(&root, assets.registry)?;
|
||||
let mut biomes = Biomes::load(&root)?;
|
||||
let visibility = models::load_visibility(&root, assets.registry)?;
|
||||
let tables = MeshTables::new(&assets, &facts, visibility)?;
|
||||
let names: BTreeMap<u32, &str> = assets
|
||||
let tables = MeshTables::new(&assets, &render, &facts, visibility)?;
|
||||
let names: BTreeMap<u32, &str> = render
|
||||
.sprite_layers
|
||||
.iter()
|
||||
.map(|(name, layer)| (*layer, name.as_str()))
|
||||
@@ -222,6 +218,7 @@ fn main() -> Result<()> {
|
||||
let result = scene(
|
||||
&row,
|
||||
&assets,
|
||||
&render,
|
||||
&tables,
|
||||
&mut biomes,
|
||||
&pristine,
|
||||
|
||||
@@ -144,10 +144,12 @@ fn main() -> Result<()> {
|
||||
let hz = flag("--hz", 240.0);
|
||||
|
||||
let assets = Arc::new(Assets::load(&root)?);
|
||||
let render = Arc::new(assets.reload(&root)?);
|
||||
let facts = BlockFacts::load(&root, assets.registry)?;
|
||||
let biomes = Arc::new(Biomes::load(&root)?);
|
||||
let tables = Arc::new(MeshTables::new(
|
||||
&assets,
|
||||
&render,
|
||||
&facts,
|
||||
models::load_visibility(&root, assets.registry)?,
|
||||
)?);
|
||||
@@ -160,6 +162,7 @@ fn main() -> Result<()> {
|
||||
)?);
|
||||
let context = Arc::new(WorkerContext {
|
||||
assets,
|
||||
render: render.clone(),
|
||||
tables,
|
||||
biomes,
|
||||
light,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//! Tooltip display visibility oracle companion for tools/test_tooltip_display_parity.py.
|
||||
use horizon_client::{item_tooltip::TooltipDisplay, items::ItemStack};
|
||||
use horizon_world::nbt::Tag;
|
||||
use std::{error::Error, fmt::Write};
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let mut output = String::new();
|
||||
for line in std::fs::read_to_string(&args[1])?.lines() {
|
||||
let fields: Vec<&str> = line.split('\t').collect();
|
||||
let hide_tooltip: bool = fields[0].parse()?;
|
||||
let creative: bool = fields[1].parse()?;
|
||||
let hide_attributes: bool = fields[2].parse()?;
|
||||
let mut component = Vec::new();
|
||||
if hide_tooltip {
|
||||
component.push(("hide_tooltip", Tag::Byte(1)));
|
||||
}
|
||||
if hide_attributes {
|
||||
component.push((
|
||||
"hidden_components",
|
||||
Tag::List(vec![Tag::String("minecraft:attribute_modifiers".into())]),
|
||||
));
|
||||
}
|
||||
let mut stack = ItemStack::new("minecraft:diamond_sword", 1);
|
||||
if !component.is_empty() {
|
||||
stack
|
||||
.data_mut()
|
||||
.set_other("minecraft:tooltip_display", Some(Tag::compound(component)));
|
||||
}
|
||||
let display = TooltipDisplay::for_stack(&stack);
|
||||
writeln!(
|
||||
output,
|
||||
"{}\t{}",
|
||||
display.name_visible(creative),
|
||||
display.shows("minecraft:attribute_modifiers")
|
||||
)?;
|
||||
}
|
||||
std::fs::write(&args[2], output)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -2,14 +2,13 @@ use crate::Result;
|
||||
use horizon_world::{
|
||||
DATA_VERSION,
|
||||
heightmap::HeightmapState,
|
||||
nbt::Tag,
|
||||
registry::{BlockRegistry, BlockStateId},
|
||||
worldgen::{tags::TagDefinitions, terrain::TerrainBlockStates},
|
||||
};
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
collections::BTreeSet,
|
||||
fs::{self, File},
|
||||
fs::File,
|
||||
io::{self, BufReader},
|
||||
path::Path,
|
||||
sync::Arc,
|
||||
@@ -49,11 +48,20 @@ impl TerrainBlockStates for Properties {
|
||||
self.0[id.0 as usize]
|
||||
}
|
||||
}
|
||||
/// The block registry and the facts read from `facts.json` and the block tags:
|
||||
/// everything world generation and collisions need, with none of the block
|
||||
/// models or baked sprites.
|
||||
pub struct Assets {
|
||||
/// Leaked once per process: shared by world generation threads.
|
||||
pub registry: &'static BlockRegistry,
|
||||
pub properties: Properties,
|
||||
pub material_states: [BlockStateId; 6],
|
||||
/// Block names in `#minecraft:blocks_fluid_flow` (fluid flow vectors).
|
||||
pub blocks_fluid_flow: BTreeSet<String>,
|
||||
}
|
||||
/// The block models and their baked sprites, read from the pack at `root` over
|
||||
/// an existing block registry: everything the mesher and renderer need.
|
||||
pub struct RenderAssets {
|
||||
pub sprite_size: u32,
|
||||
pub sprite_minimum_size: u32,
|
||||
pub pixels: Vec<u8>,
|
||||
@@ -68,30 +76,10 @@ pub struct Assets {
|
||||
pub translucent_layers: Vec<bool>,
|
||||
/// Each layer's `MipmapGenerator` settings.
|
||||
pub sprite_mips: Vec<crate::mipmap::Settings>,
|
||||
/// Block names in `#minecraft:blocks_fluid_flow` (fluid flow vectors).
|
||||
pub blocks_fluid_flow: BTreeSet<String>,
|
||||
}
|
||||
fn invalid(message: &str) -> io::Error {
|
||||
io::Error::new(io::ErrorKind::InvalidData, message)
|
||||
}
|
||||
fn tag(value: &Value) -> Result<Tag> {
|
||||
Ok(match value {
|
||||
Value::String(value) => Tag::String(value.as_str().into()),
|
||||
Value::Number(value) => Tag::Int(i32::try_from(
|
||||
value
|
||||
.as_i64()
|
||||
.ok_or_else(|| invalid("invalid registry number"))?,
|
||||
)?),
|
||||
Value::Array(values) => Tag::List(values.iter().map(tag).collect::<Result<_>>()?),
|
||||
Value::Object(values) => Tag::Compound(
|
||||
values
|
||||
.iter()
|
||||
.map(|(name, value)| Ok((name.as_str().into(), tag(value)?)))
|
||||
.collect::<Result<_>>()?,
|
||||
),
|
||||
_ => return Err(invalid("unsupported registry value").into()),
|
||||
})
|
||||
}
|
||||
impl Assets {
|
||||
pub fn load(root: &Path) -> Result<Self> {
|
||||
let manifest: Value = serde_json::from_reader(BufReader::new(File::open(
|
||||
@@ -100,23 +88,8 @@ impl Assets {
|
||||
if manifest["data_version"].as_i64() != Some(i64::from(DATA_VERSION)) {
|
||||
return Err(invalid("resources do not match Horizon's pinned data version").into());
|
||||
}
|
||||
let facts: Value = serde_json::from_slice(&fs::read(root.join("facts.json"))?)?;
|
||||
let states = facts["states"]
|
||||
.as_array()
|
||||
.ok_or_else(|| invalid("missing registry state facts"))?;
|
||||
let registry = BlockRegistry::from_nbt(&Tag::compound([
|
||||
("DataVersion", Tag::Int(DATA_VERSION)),
|
||||
(
|
||||
"states",
|
||||
Tag::List(
|
||||
states
|
||||
.iter()
|
||||
.map(|state| tag(&state[4]))
|
||||
.collect::<Result<_>>()?,
|
||||
),
|
||||
),
|
||||
("defaults", tag(&facts["defaults"])?),
|
||||
]))?;
|
||||
let (registry, flags) =
|
||||
BlockRegistry::from_facts_json_with_flags(File::open(root.join("facts.json"))?)?;
|
||||
let bundle: Value =
|
||||
serde_json::from_reader(BufReader::new(File::open(root.join("block-tags.json"))?))?;
|
||||
let mut definitions = TagDefinitions::default();
|
||||
@@ -132,7 +105,7 @@ impl Assets {
|
||||
)?;
|
||||
}
|
||||
let built =
|
||||
definitions.build(|name, _| facts["defaults"].get(name).map(|_| name.to_owned()))?;
|
||||
definitions.build(|name, _| registry.default_state(name).map(|_| name.to_owned()))?;
|
||||
if !built.missing.is_empty() {
|
||||
return Err(invalid("unresolved block tags").into());
|
||||
}
|
||||
@@ -158,27 +131,20 @@ impl Assets {
|
||||
.cloned()
|
||||
.collect();
|
||||
let properties = Properties(Arc::new(
|
||||
states
|
||||
flags
|
||||
.iter()
|
||||
.map(|state| {
|
||||
.enumerate()
|
||||
.map(|(i, &(air, fluid))| {
|
||||
let name = ®istry
|
||||
.state(BlockStateId(i as u32))
|
||||
.ok_or_else(|| invalid("missing registry state"))?
|
||||
.name;
|
||||
Ok(StateFacts {
|
||||
air: state[1]
|
||||
.as_bool()
|
||||
.ok_or_else(|| invalid("missing air fact"))?,
|
||||
fluid: state[2]
|
||||
.as_bool()
|
||||
.ok_or_else(|| invalid("missing fluid fact"))?,
|
||||
air_block: state[0].as_str() == Some("minecraft:air"),
|
||||
motion: motion.contains(
|
||||
state[0]
|
||||
.as_str()
|
||||
.ok_or_else(|| invalid("missing state name"))?,
|
||||
),
|
||||
no_leaves: no_leaves.contains(
|
||||
state[0]
|
||||
.as_str()
|
||||
.ok_or_else(|| invalid("missing state name"))?,
|
||||
),
|
||||
air,
|
||||
fluid,
|
||||
air_block: name == "minecraft:air",
|
||||
motion: motion.contains(name.as_str()),
|
||||
no_leaves: no_leaves.contains(name.as_str()),
|
||||
})
|
||||
})
|
||||
.collect::<Result<_>>()?,
|
||||
@@ -193,33 +159,23 @@ impl Assets {
|
||||
// past vanilla's 16-bit global palette.
|
||||
crate::chunk::set_block_states(registry.len());
|
||||
let registry: &'static BlockRegistry = Box::leak(Box::new(registry));
|
||||
Self::with_models(
|
||||
root,
|
||||
Ok(Self {
|
||||
registry,
|
||||
properties,
|
||||
material_states,
|
||||
blocks_fluid_flow,
|
||||
)
|
||||
})
|
||||
}
|
||||
/// The same blocks with the models and sprites of another resource root
|
||||
/// The models and sprites of another resource root over these blocks
|
||||
/// (resource packs changed): the registry and block facts come from the
|
||||
/// game data, which resource packs do not touch.
|
||||
pub fn reload(&self, root: &Path) -> Result<Self> {
|
||||
Self::with_models(
|
||||
root,
|
||||
self.registry,
|
||||
self.properties.clone(),
|
||||
self.material_states,
|
||||
self.blocks_fluid_flow.clone(),
|
||||
)
|
||||
pub fn reload(&self, root: &Path) -> Result<RenderAssets> {
|
||||
RenderAssets::load(root, self)
|
||||
}
|
||||
fn with_models(
|
||||
root: &Path,
|
||||
registry: &'static BlockRegistry,
|
||||
properties: Properties,
|
||||
material_states: [BlockStateId; 6],
|
||||
blocks_fluid_flow: BTreeSet<String>,
|
||||
) -> Result<Self> {
|
||||
}
|
||||
impl RenderAssets {
|
||||
pub fn load(root: &Path, assets: &Assets) -> Result<Self> {
|
||||
let registry = assets.registry;
|
||||
let mut sprites = crate::sprites::Sprites::default();
|
||||
for name in MATERIALS {
|
||||
sprites.insert(root, &format!("minecraft:block/{name}"))?;
|
||||
@@ -243,9 +199,6 @@ impl Assets {
|
||||
}
|
||||
sprites.finish();
|
||||
Ok(Self {
|
||||
registry,
|
||||
properties,
|
||||
material_states,
|
||||
sprite_size: sprites.size,
|
||||
sprite_minimum_size: sprites.minimum_size,
|
||||
texture_layers: u32::try_from(sprites.count())?,
|
||||
@@ -258,7 +211,6 @@ impl Assets {
|
||||
sprite_layers: sprites.layers,
|
||||
translucent_layers: sprites.translucent,
|
||||
sprite_mips: sprites.mips,
|
||||
blocks_fluid_flow,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::sound_engine::{
|
||||
Sounds, TickContext,
|
||||
};
|
||||
use crate::sound_events::{Sound, SoundRegistry};
|
||||
#[cfg(feature = "audio")]
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use horizon_core::random::{LegacyRandom, RandomSource};
|
||||
use std::{
|
||||
@@ -134,8 +135,14 @@ fn attach(mixer: &Mutex<Mixer>, channel: ChannelId, samples: Samples, looping: b
|
||||
c.looping |= looping;
|
||||
}
|
||||
}
|
||||
/// The open output stream. A build without the `audio` feature (the server build, which must not
|
||||
/// need libasound) never has one.
|
||||
#[cfg(feature = "audio")]
|
||||
type Stream = cpal::Stream;
|
||||
#[cfg(not(feature = "audio"))]
|
||||
type Stream = std::convert::Infallible;
|
||||
pub struct Audio {
|
||||
_stream: Option<cpal::Stream>,
|
||||
_stream: Option<Stream>,
|
||||
pub engine: SoundEngine,
|
||||
backend: MixerBackend,
|
||||
/// Record `Heard` sounds (the subtitle overlay is listening).
|
||||
@@ -333,6 +340,8 @@ fn distance_gain(linear: Option<f32>, distance: f32) -> f32 {
|
||||
Some(_) => 0.0,
|
||||
}
|
||||
}
|
||||
// Only the output stream mixes; a build without one (no `audio` feature) never does.
|
||||
#[cfg_attr(not(feature = "audio"), allow(dead_code))]
|
||||
fn mix(mixer: &mut Mixer, data: &mut [f32], channels: usize, rate: u32) {
|
||||
data.fill(0.0);
|
||||
let listener = mixer.listener;
|
||||
@@ -415,6 +424,7 @@ fn mix(mixer: &mut Mixer, data: &mut [f32], channels: usize, rate: u32) {
|
||||
/// `HORIZON_NO_AUDIO`, or a virtual screen (`vscreen`), where agents and
|
||||
/// harnesses run the game and must stay off the user's speakers.
|
||||
/// `HORIZON_AUDIO=1` opens the output anyway (testing into a null sink).
|
||||
#[cfg(any(feature = "audio", test))]
|
||||
fn output_disabled(var: impl Fn(&str) -> Option<std::ffi::OsString>) -> Option<String> {
|
||||
if var("HORIZON_NO_AUDIO").is_some() {
|
||||
return Some("audio off: HORIZON_NO_AUDIO is set".into());
|
||||
@@ -430,6 +440,7 @@ fn output_disabled(var: impl Fn(&str) -> Option<std::ffi::OsString>) -> Option<S
|
||||
}
|
||||
/// An output stream on `device` in its default configuration, whatever its
|
||||
/// sample format: the mixer works in f32 and converts.
|
||||
#[cfg(feature = "audio")]
|
||||
fn open_device(
|
||||
device: &cpal::Device,
|
||||
mixer: Arc<Mutex<Mixer>>,
|
||||
@@ -450,6 +461,7 @@ fn open_device(
|
||||
stream.play()?;
|
||||
Ok((stream, config))
|
||||
}
|
||||
#[cfg(feature = "audio")]
|
||||
fn build_stream<T: cpal::SizedSample + cpal::FromSample<f32>>(
|
||||
device: &cpal::Device,
|
||||
config: &cpal::SupportedStreamConfig,
|
||||
@@ -523,7 +535,12 @@ impl Audio {
|
||||
capture: None,
|
||||
}
|
||||
}
|
||||
fn open(mixer: Arc<Mutex<Mixer>>) -> Result<cpal::Stream> {
|
||||
#[cfg(not(feature = "audio"))]
|
||||
fn open(_: Arc<Mutex<Mixer>>) -> Result<Stream> {
|
||||
Err("this build has no sound output (built without the `audio` feature)".into())
|
||||
}
|
||||
#[cfg(feature = "audio")]
|
||||
fn open(mixer: Arc<Mutex<Mixer>>) -> Result<Stream> {
|
||||
if let Some(reason) = output_disabled(|name| std::env::var_os(name)) {
|
||||
return Err(reason.into());
|
||||
}
|
||||
|
||||
@@ -187,6 +187,10 @@ pub const COMMANDS: &[Cmd] = &[
|
||||
&[opt("radius", Ty::Num, "search radius in blocks (default 32)"), opt("type", Ty::Str, "entity type filter")], mcp: true, local: false),
|
||||
cmd!("block", Observe, "block X Y Z", "the block state at a position", "",
|
||||
["horizon-ctl block 10 64 -3"], &BLOCK_XYZ, mcp: true, local: false),
|
||||
cmd!("light", Observe, "light X1 Y1 Z1 X2 Y2 Z2", "the stored sky and block light of a box",
|
||||
"At most 32768 blocks per request. One hex digit per block in `sky` and `block`, x fastest, then z, then y; `.` where no chunk is loaded.",
|
||||
["horizon-ctl light 0 64 0 15 70 15"],
|
||||
&[p("x1", Ty::Int, "corner X"), p("y1", Ty::Int, "corner Y"), p("z1", Ty::Int, "corner Z"), p("x2", Ty::Int, "opposite X"), p("y2", Ty::Int, "opposite Y"), p("z2", Ty::Int, "opposite Z")], mcp: true, local: false),
|
||||
cmd!("blocks", Observe, "blocks X1 Y1 Z1 X2 Y2 Z2", "the non-air blocks of a box, with counts per block",
|
||||
"At most 32768 blocks per request.", ["horizon-ctl blocks 0 60 0 15 70 15"],
|
||||
&[p("x1", Ty::Int, "corner X"), p("y1", Ty::Int, "corner Y"), p("z1", Ty::Int, "corner Z"), p("x2", Ty::Int, "opposite X"), p("y2", Ty::Int, "opposite Y"), p("z2", Ty::Int, "opposite Z")], mcp: true, local: false),
|
||||
@@ -339,7 +343,7 @@ pub const COMMANDS: &[Cmd] = &[
|
||||
cmd!("bench", Scripting, "bench SECONDS", "reset frame stats, wait, reply with the summary", "", ["horizon-ctl bench 10"], &[], mcp: false, local: false),
|
||||
cmd!("stats", Scripting, "stats [reset]", "frame-time summary since the last reset", "", ["horizon-ctl stats"], &[], mcp: false, local: false),
|
||||
cmd!("fly", Scripting, "fly X1 Y1 Z1 X2 Y2 Z2 SECONDS [PITCH [raw]]", "fly the camera along a line, then reply with the frame summary",
|
||||
"With raw, the reply also lists every frame time in milliseconds (frame_ms).",
|
||||
"The reply's tick_ms and tick_ms_max are the world's smoothed tick time over the flight (the server thread's when single player runs on one). With raw, the reply also lists every frame time in milliseconds (frame_ms).",
|
||||
["horizon-ctl fly 0 100 0 500 100 0 20"], &[], mcp: false, local: false),
|
||||
];
|
||||
|
||||
|
||||
@@ -215,7 +215,12 @@ impl Session {
|
||||
let deadline = Instant::now() + Duration::from_secs_f64(limit.max(0.0));
|
||||
loop {
|
||||
let status = self.game("status")?;
|
||||
if !status["player"].is_null() && status["pending_chunks"] == 0 {
|
||||
// On a server (single player's server thread too), also the
|
||||
// level around the player.
|
||||
if !status["player"].is_null()
|
||||
&& status["pending_chunks"] == 0
|
||||
&& status["server"]["loaded"] != false
|
||||
{
|
||||
return Ok(status);
|
||||
}
|
||||
if Instant::now() > deadline {
|
||||
|
||||
@@ -0,0 +1,395 @@
|
||||
//! The world's block entities and the order they tick in: vanilla's
|
||||
//! `Level.blockEntityTickers`, kept beside the block entity map so a tick
|
||||
//! visits only the block entities that tick, in vanilla's order, instead of
|
||||
//! scanning the whole map once per kind.
|
||||
//!
|
||||
//! The list follows `LevelChunk.updateBlockEntityTicker` and
|
||||
//! `Level.tickBlockEntities`:
|
||||
//! - a block entity whose block state has a ticker gets a slot at the end of
|
||||
//! the list (through `pendingBlockEntityTickers`, so a slot made during a
|
||||
//! tick first ticks on the next one);
|
||||
//! - replacing the block entity at a position (`setBlockEntity`), or changing
|
||||
//! its block state to another state with a ticker, keeps its slot
|
||||
//! (`RebindableTickingBlockEntityWrapper.rebind`);
|
||||
//! - removing it (`removeBlockEntity`), unloading its chunk
|
||||
//! (`clearAllBlockEntities`) or changing its state to one without a ticker
|
||||
//! (a jukebox losing its record) frees the slot; a later ticker there is
|
||||
//! appended again;
|
||||
//! - a loaded chunk's block entities are added in the iteration order of its
|
||||
//! `Object2ObjectOpenHashMap<BlockPos, BlockEntity>`
|
||||
//! (`registerAllBlockEntitiesAfterLevelLoad`), filled in the order the chunk
|
||||
//! listed them.
|
||||
//!
|
||||
//! Which states tick is a table by state id, built by the game from the block
|
||||
//! registry; whether a slot is made is decided when the slot is promoted at
|
||||
//! the start of the next tick, from the block state then.
|
||||
use crate::containers::BlockEntity;
|
||||
use crate::fast_hash::{FxHashMap, FxHashSet};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub type Pos = (i32, i32, i32);
|
||||
|
||||
/// What a block state's block entity does each tick (`BlockState.getTicker`).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Ticking {
|
||||
/// No ticker, and the block has no block entity that could have one.
|
||||
#[default]
|
||||
No,
|
||||
/// A ticker.
|
||||
Yes,
|
||||
/// The block's block entity, but this state has no ticker (a jukebox
|
||||
/// without a record): a state change to it frees the slot.
|
||||
Idle,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct BlockEntities {
|
||||
map: HashMap<Pos, BlockEntity>,
|
||||
/// `Level.blockEntityTickers`: positions and the slot each was given.
|
||||
tickers: Vec<(Pos, u32)>,
|
||||
/// `LevelChunk.tickersInLevel`: the live slot of each ticking position.
|
||||
live: FxHashMap<Pos, u32>,
|
||||
/// Positions that may need a slot, in the order vanilla would have made
|
||||
/// it (`pendingBlockEntityTickers`), each with a token; decided at the
|
||||
/// next promotion from the block state then.
|
||||
added: Vec<(Pos, u32)>,
|
||||
/// The token of each position's pending entry: an entry whose token is
|
||||
/// not here any more was cancelled.
|
||||
pending: FxHashMap<Pos, u32>,
|
||||
next_slot: u32,
|
||||
/// Whether a slot was freed since the list was last swept: otherwise
|
||||
/// every slot in it is still live, unless its block entity is `out`.
|
||||
freed: bool,
|
||||
/// Positions whose block entity `take` took and `put` has not brought
|
||||
/// back.
|
||||
out: FxHashSet<Pos>,
|
||||
/// `Ticking` by block state id; empty until the game builds it.
|
||||
states: Vec<Ticking>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for BlockEntities {
|
||||
type Target = HashMap<Pos, BlockEntity>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.map
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a BlockEntities {
|
||||
type Item = (&'a Pos, &'a BlockEntity);
|
||||
type IntoIter = std::collections::hash_map::Iter<'a, Pos, BlockEntity>;
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.map.iter()
|
||||
}
|
||||
}
|
||||
|
||||
/// `Vec3i.hashCode`.
|
||||
fn java_hash((x, y, z): Pos) -> i32 {
|
||||
y.wrapping_add(z.wrapping_mul(31))
|
||||
.wrapping_mul(31)
|
||||
.wrapping_add(x)
|
||||
}
|
||||
/// `HashCommon.mix`.
|
||||
fn mix(x: i32) -> usize {
|
||||
let h = (x as u32).wrapping_mul(0x9E37_79B9);
|
||||
(h ^ (h >> 16)) as usize
|
||||
}
|
||||
|
||||
/// The order `values().forEach` visits a `new Object2ObjectOpenHashMap<>()`
|
||||
/// keyed by these positions, put in this order (repeats keep their first
|
||||
/// slot): open addressing with linear probing, a rehash to twice the size
|
||||
/// past three quarters full, and iteration from the last slot down.
|
||||
pub fn chunk_map_order(positions: impl IntoIterator<Item = Pos>) -> Vec<Pos> {
|
||||
// HashCommon.arraySize(16, .75f), and maxFill of each size.
|
||||
let mut slots: Vec<Option<Pos>> = vec![None; 32];
|
||||
let max_fill = |n: usize| (n * 3).div_ceil(4).min(n - 1);
|
||||
let mut size = 0;
|
||||
for p in positions {
|
||||
let mask = slots.len() - 1;
|
||||
let mut at = mix(java_hash(p)) & mask;
|
||||
let mut known = false;
|
||||
while let Some(k) = slots[at] {
|
||||
if k == p {
|
||||
known = true;
|
||||
break;
|
||||
}
|
||||
at = (at + 1) & mask;
|
||||
}
|
||||
if known {
|
||||
continue;
|
||||
}
|
||||
slots[at] = Some(p);
|
||||
// `if (size++ >= maxFill) rehash(arraySize(size + 1, f))`, which
|
||||
// puts the keys back from the last slot down.
|
||||
size += 1;
|
||||
if size > max_fill(slots.len()) {
|
||||
let n = ((size + 1) * 4).div_ceil(3).next_power_of_two();
|
||||
let old = std::mem::replace(&mut slots, vec![None; n]);
|
||||
for k in old.into_iter().rev().flatten() {
|
||||
let mut at = mix(java_hash(k)) & (n - 1);
|
||||
while slots[at].is_some() {
|
||||
at = (at + 1) & (n - 1);
|
||||
}
|
||||
slots[at] = Some(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
slots.into_iter().rev().flatten().collect()
|
||||
}
|
||||
|
||||
impl BlockEntities {
|
||||
/// Whether the ticking table has been built.
|
||||
pub fn has_states(&self) -> bool {
|
||||
!self.states.is_empty()
|
||||
}
|
||||
pub fn set_states(&mut self, states: Vec<Ticking>) {
|
||||
self.states = states;
|
||||
}
|
||||
pub fn take_states(&mut self) -> Vec<Ticking> {
|
||||
std::mem::take(&mut self.states)
|
||||
}
|
||||
pub fn ticking(&self, state: u32) -> Ticking {
|
||||
self.states.get(state as usize).copied().unwrap_or_default()
|
||||
}
|
||||
|
||||
fn next(&mut self) -> u32 {
|
||||
let n = self.next_slot;
|
||||
self.next_slot = n.wrapping_add(1);
|
||||
n
|
||||
}
|
||||
/// A ticker may be made for `pos` now (`updateBlockEntityTicker`).
|
||||
fn add(&mut self, pos: Pos) {
|
||||
let token = self.next();
|
||||
self.pending.insert(pos, token);
|
||||
self.added.push((pos, token));
|
||||
}
|
||||
/// `removeBlockEntityTicker`: no slot, made or pending.
|
||||
fn cancel(&mut self, pos: &Pos) {
|
||||
self.freed |= self.live.remove(pos).is_some();
|
||||
self.pending.remove(pos);
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, pos: &Pos) -> Option<&mut BlockEntity> {
|
||||
self.map.get_mut(pos)
|
||||
}
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&Pos, &mut BlockEntity)> {
|
||||
self.map.iter_mut()
|
||||
}
|
||||
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut BlockEntity> {
|
||||
self.map.values_mut()
|
||||
}
|
||||
/// `LevelChunk.setBlockEntity` (+ `addAndRegisterBlockEntity`): a new
|
||||
/// block entity may get a slot; one replacing another keeps its slot.
|
||||
pub fn insert(&mut self, pos: Pos, entity: BlockEntity) -> Option<BlockEntity> {
|
||||
let old = self.map.insert(pos, entity);
|
||||
if old.is_none() {
|
||||
self.add(pos);
|
||||
}
|
||||
old
|
||||
}
|
||||
/// The block entity at `pos`, made by `make` when there is none.
|
||||
pub fn get_or_insert_with(
|
||||
&mut self,
|
||||
pos: Pos,
|
||||
make: impl FnOnce() -> BlockEntity,
|
||||
) -> &mut BlockEntity {
|
||||
if !self.map.contains_key(&pos) {
|
||||
self.add(pos);
|
||||
}
|
||||
self.map.entry(pos).or_insert_with(make)
|
||||
}
|
||||
/// `LevelChunk.removeBlockEntity`: the block entity and its slot.
|
||||
pub fn remove(&mut self, pos: &Pos) -> Option<BlockEntity> {
|
||||
self.cancel(pos);
|
||||
self.map.remove(pos)
|
||||
}
|
||||
/// The block entity at `pos`, out of the map for a while: its slot stays
|
||||
/// for `put` to bring it back (a tick working on it).
|
||||
pub fn take(&mut self, pos: &Pos) -> Option<BlockEntity> {
|
||||
let taken = self.map.remove(pos);
|
||||
if taken.is_some() {
|
||||
self.out.insert(*pos);
|
||||
}
|
||||
taken
|
||||
}
|
||||
/// Brings back what `take` took, in its slot.
|
||||
pub fn put(&mut self, pos: Pos, entity: BlockEntity) {
|
||||
self.out.remove(&pos);
|
||||
if self.map.insert(pos, entity).is_none()
|
||||
&& !self.live.contains_key(&pos)
|
||||
&& !self.pending.contains_key(&pos)
|
||||
{
|
||||
self.add(pos);
|
||||
}
|
||||
}
|
||||
/// Removes the block entities `keep` refuses, and their slots
|
||||
/// (`clearAllBlockEntities` of unloaded chunks).
|
||||
pub fn retain(&mut self, mut keep: impl FnMut(&Pos, &mut BlockEntity) -> bool) {
|
||||
let (live, pending, freed) = (&mut self.live, &mut self.pending, &mut self.freed);
|
||||
self.map.retain(|p, e| {
|
||||
let kept = keep(p, e);
|
||||
if !kept {
|
||||
*freed |= live.remove(p).is_some();
|
||||
pending.remove(p);
|
||||
}
|
||||
kept
|
||||
});
|
||||
}
|
||||
pub fn clear(&mut self) {
|
||||
self.map.clear();
|
||||
self.tickers.clear();
|
||||
self.live.clear();
|
||||
self.added.clear();
|
||||
self.pending.clear();
|
||||
self.out.clear();
|
||||
self.freed = false;
|
||||
}
|
||||
/// A loaded or generated chunk's block entities, in the order the chunk
|
||||
/// lists them; they tick in its block entity map's order
|
||||
/// (`registerAllBlockEntitiesAfterLevelLoad`).
|
||||
pub fn load_chunk(&mut self, entities: Vec<(Pos, BlockEntity)>) {
|
||||
let order = chunk_map_order(entities.iter().map(|(p, _)| *p));
|
||||
for (p, e) in entities {
|
||||
self.map.insert(p, e);
|
||||
}
|
||||
for p in order {
|
||||
self.add(p);
|
||||
}
|
||||
}
|
||||
/// `LevelChunk.setBlockState` on a block entity's position, from state
|
||||
/// `old` to `new`: a ticker made, kept or dropped.
|
||||
pub fn state_changed(&mut self, pos: Pos, old: u32, new: u32) {
|
||||
if self.states.is_empty() || !self.map.contains_key(&pos) {
|
||||
return;
|
||||
}
|
||||
match self.ticking(new) {
|
||||
// A new ticker, unless one was made or is pending (rebound).
|
||||
Ticking::Yes => {
|
||||
if self.ticking(old) != Ticking::Yes && !self.live.contains_key(&pos) {
|
||||
self.add(pos);
|
||||
}
|
||||
}
|
||||
Ticking::Idle => self.cancel(&pos),
|
||||
// Another block: the game removes or replaces the block entity.
|
||||
Ticking::No => {}
|
||||
}
|
||||
}
|
||||
/// The start of `Level.tickBlockEntities`: pending slots join the list
|
||||
/// and freed ones leave it. `state` reads the block state at a position.
|
||||
/// Returns the slots to tick, in order; check each with `is_live` before
|
||||
/// ticking it, as the ticks before it can free it.
|
||||
pub fn tickers(&mut self, state: impl Fn(Pos) -> u32) -> Vec<(Pos, u32)> {
|
||||
for (pos, token) in std::mem::take(&mut self.added) {
|
||||
if self.pending.get(&pos) != Some(&token) {
|
||||
continue;
|
||||
}
|
||||
self.pending.remove(&pos);
|
||||
if self.live.contains_key(&pos)
|
||||
|| !self.map.contains_key(&pos)
|
||||
|| self.ticking(state(pos)) != Ticking::Yes
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let slot = self.next();
|
||||
self.live.insert(pos, slot);
|
||||
self.tickers.push((pos, slot));
|
||||
}
|
||||
if !std::mem::take(&mut self.freed) && self.out.is_empty() {
|
||||
return self.tickers.clone();
|
||||
}
|
||||
self.out.clear();
|
||||
let (live, map) = (&mut self.live, &self.map);
|
||||
self.tickers.retain(|(p, slot)| {
|
||||
let mine = live.get(p) == Some(slot);
|
||||
if mine && !map.contains_key(p) {
|
||||
live.remove(p);
|
||||
}
|
||||
mine && map.contains_key(p)
|
||||
});
|
||||
self.tickers.clone()
|
||||
}
|
||||
/// Whether a slot from `tickers` still ticks.
|
||||
pub fn is_live(&self, (pos, slot): (Pos, u32)) -> bool {
|
||||
self.live.get(&pos) == Some(&slot) && self.map.contains_key(&pos)
|
||||
}
|
||||
/// Frees the slot at `pos` (the block entity stays).
|
||||
pub fn forget(&mut self, pos: &Pos) {
|
||||
self.cancel(pos);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn hopper() -> BlockEntity {
|
||||
BlockEntity::Chest(vec![None; 5])
|
||||
}
|
||||
/// States: 0 air, 1 ticks, 2 idle.
|
||||
fn level() -> BlockEntities {
|
||||
let mut b = BlockEntities::default();
|
||||
b.set_states(vec![Ticking::No, Ticking::Yes, Ticking::Idle]);
|
||||
b
|
||||
}
|
||||
fn order(b: &mut BlockEntities, states: &HashMap<Pos, u32>) -> Vec<Pos> {
|
||||
b.tickers(|p| states.get(&p).copied().unwrap_or(0))
|
||||
.into_iter()
|
||||
.map(|(p, _)| p)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slots_follow_vanilla_lifecycle() {
|
||||
let mut b = level();
|
||||
let mut s = HashMap::new();
|
||||
for p in [(0, 0, 0), (1, 0, 0), (2, 0, 0)] {
|
||||
s.insert(p, 1);
|
||||
b.insert(p, hopper());
|
||||
}
|
||||
assert_eq!(order(&mut b, &s), [(0, 0, 0), (1, 0, 0), (2, 0, 0)]);
|
||||
// Replacing keeps the slot; removing and placing again appends.
|
||||
b.insert((0, 0, 0), hopper());
|
||||
b.remove(&(1, 0, 0));
|
||||
b.insert((1, 0, 0), hopper());
|
||||
assert_eq!(order(&mut b, &s), [(0, 0, 0), (2, 0, 0), (1, 0, 0)]);
|
||||
// Take and put keep it; an idle state frees it, ticking again appends.
|
||||
let e = b.take(&(0, 0, 0)).unwrap();
|
||||
b.put((0, 0, 0), e);
|
||||
assert_eq!(order(&mut b, &s), [(0, 0, 0), (2, 0, 0), (1, 0, 0)]);
|
||||
s.insert((2, 0, 0), 2);
|
||||
b.state_changed((2, 0, 0), 1, 2);
|
||||
assert_eq!(order(&mut b, &s), [(0, 0, 0), (1, 0, 0)]);
|
||||
s.insert((2, 0, 0), 1);
|
||||
b.state_changed((2, 0, 0), 2, 1);
|
||||
assert_eq!(order(&mut b, &s), [(0, 0, 0), (1, 0, 0), (2, 0, 0)]);
|
||||
// A slot freed during a tick is not live any more.
|
||||
let slots = b.tickers(|p| s.get(&p).copied().unwrap_or(0));
|
||||
b.retain(|p, _| *p != (1, 0, 0));
|
||||
assert!(b.is_live(slots[0]) && !b.is_live(slots[1]));
|
||||
// A block entity taken and never brought back loses its slot.
|
||||
b.take(&(0, 0, 0));
|
||||
assert_eq!(order(&mut b, &s), [(2, 0, 0)]);
|
||||
assert_eq!(order(&mut b, &s), [(2, 0, 0)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chunk_loads_in_open_hash_map_order() {
|
||||
// A few keys: their mixed hashes over 32 slots, read from the top.
|
||||
let positions = [
|
||||
(0, 64, 0),
|
||||
(1, 64, 0),
|
||||
(0, 64, 1),
|
||||
(15, -64, 15),
|
||||
(3, 70, 9),
|
||||
];
|
||||
let slot = |p: &Pos| mix(java_hash(*p)) & 31;
|
||||
let mut expected = positions.to_vec();
|
||||
expected.sort_by_key(|p| std::cmp::Reverse(slot(p)));
|
||||
let distinct: std::collections::HashSet<usize> = positions.iter().map(slot).collect();
|
||||
assert_eq!(distinct.len(), positions.len());
|
||||
assert_eq!(chunk_map_order(positions), expected);
|
||||
// Past 24 keys the table doubles; every key stays, once.
|
||||
let many: Vec<Pos> = (0..100).map(|i| (i % 16, i / 16, 3)).collect();
|
||||
let order = chunk_map_order(many.iter().copied().chain(many.iter().copied()));
|
||||
assert_eq!(order.len(), 100);
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,11 @@
|
||||
//! (blocks, entities, game time) as closures, so the parity fixture can drive
|
||||
//! them with scripted inputs (`tools/test_block_entity_anim_parity.py`).
|
||||
use crate::block_entity_render::BlockAnim;
|
||||
use crate::fast_hash::FxHashMap;
|
||||
use horizon_core::{
|
||||
geometry::trig::{self, Mth},
|
||||
random::{LegacyRandom, RandomSource},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// `Direction` names by `get3DDataValue`.
|
||||
pub const DIRECTIONS: [&str; 6] = ["down", "up", "north", "south", "west", "east"];
|
||||
@@ -832,38 +832,44 @@ pub fn ticker(name: &str, prop: impl Fn(&str) -> Option<String>) -> Option<Ticke
|
||||
/// The animated block entities of a level, by position.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BlockEntityAnims {
|
||||
pub chests: HashMap<[i32; 3], ChestLid>,
|
||||
pub books: HashMap<[i32; 3], EnchantingBook>,
|
||||
pub chests: FxHashMap<[i32; 3], ChestLid>,
|
||||
pub books: FxHashMap<[i32; 3], EnchantingBook>,
|
||||
/// `EnchantingTableBlockEntity.RANDOM`, shared by every table.
|
||||
pub book_random: LegacyRandom,
|
||||
pub shulkers: HashMap<[i32; 3], Shulker>,
|
||||
pub bells: HashMap<[i32; 3], Bell>,
|
||||
pub conduits: HashMap<[i32; 3], Conduit>,
|
||||
pub skulls: HashMap<[i32; 3], Skull>,
|
||||
pub pots: HashMap<[i32; 3], PotWobble>,
|
||||
pub gateways: HashMap<[i32; 3], EndGateway>,
|
||||
pub shulkers: FxHashMap<[i32; 3], Shulker>,
|
||||
pub bells: FxHashMap<[i32; 3], Bell>,
|
||||
pub conduits: FxHashMap<[i32; 3], Conduit>,
|
||||
pub skulls: FxHashMap<[i32; 3], Skull>,
|
||||
pub pots: FxHashMap<[i32; 3], PotWobble>,
|
||||
pub gateways: FxHashMap<[i32; 3], EndGateway>,
|
||||
/// The integrated server's copies of the gateways (`portalTick`).
|
||||
pub gateway_servers: HashMap<[i32; 3], EndGateway>,
|
||||
pub gateway_servers: FxHashMap<[i32; 3], EndGateway>,
|
||||
/// The client level's random (conduit particles).
|
||||
pub random: LegacyRandom,
|
||||
/// [`Ticker`] by block state id (see [`BlockEntityAnims::classify`]).
|
||||
pub kinds: Vec<Option<Ticker>>,
|
||||
/// The drawn block entities with a ticker, sorted by position, and the
|
||||
/// renderer's block entity revision they were read at.
|
||||
pub present: Vec<([i32; 3], Ticker)>,
|
||||
pub present_revision: Option<u64>,
|
||||
}
|
||||
impl Default for BlockEntityAnims {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
chests: HashMap::new(),
|
||||
books: HashMap::new(),
|
||||
chests: FxHashMap::default(),
|
||||
books: FxHashMap::default(),
|
||||
book_random: LegacyRandom::new(0x626f6f6b),
|
||||
shulkers: HashMap::new(),
|
||||
bells: HashMap::new(),
|
||||
conduits: HashMap::new(),
|
||||
skulls: HashMap::new(),
|
||||
pots: HashMap::new(),
|
||||
gateways: HashMap::new(),
|
||||
gateway_servers: HashMap::new(),
|
||||
shulkers: FxHashMap::default(),
|
||||
bells: FxHashMap::default(),
|
||||
conduits: FxHashMap::default(),
|
||||
skulls: FxHashMap::default(),
|
||||
pots: FxHashMap::default(),
|
||||
gateways: FxHashMap::default(),
|
||||
gateway_servers: FxHashMap::default(),
|
||||
random: LegacyRandom::new(0x6c6576656c),
|
||||
kinds: Vec::new(),
|
||||
present: Vec::new(),
|
||||
present_revision: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -877,15 +883,20 @@ impl BlockEntityAnims {
|
||||
.and_then(|s| ticker(&s.name, |k| s.properties.get(k).cloned()))
|
||||
})
|
||||
.collect();
|
||||
self.present_revision = None;
|
||||
}
|
||||
/// The ticker of a block state.
|
||||
pub fn ticker(&self, state: u32) -> Option<Ticker> {
|
||||
self.kinds.get(state as usize).copied().flatten()
|
||||
}
|
||||
/// Drops the state of block entities that are gone or changed kind:
|
||||
/// `present` maps the loaded block entities to their tickers.
|
||||
pub fn retain_present(&mut self, present: &HashMap<[i32; 3], Ticker>) {
|
||||
let is = |p: &[i32; 3], f: fn(&Ticker) -> bool| present.get(p).is_some_and(f);
|
||||
/// `present` holds the loaded block entities' tickers, sorted by position.
|
||||
pub fn retain_present(&mut self, present: &[([i32; 3], Ticker)]) {
|
||||
let is = |p: &[i32; 3], f: fn(&Ticker) -> bool| {
|
||||
present
|
||||
.binary_search_by_key(p, |(q, _)| *q)
|
||||
.is_ok_and(|i| f(&present[i].1))
|
||||
};
|
||||
self.chests.retain(|p, _| is(p, |t| *t == Ticker::Lid));
|
||||
self.books.retain(|p, _| is(p, |t| *t == Ticker::Book));
|
||||
self.shulkers
|
||||
|
||||
@@ -386,6 +386,12 @@ pub struct ChatScreen {
|
||||
parse: Option<ParseResults>,
|
||||
/// The completions at the cursor (`pendingSuggestions`): range start (bytes) and list.
|
||||
pending: Option<(usize, Vec<Suggestion>)>,
|
||||
/// Completions waiting for the server's (an `ask_server` node at the
|
||||
/// cursor): `pendingSuggestions` is not done until they come.
|
||||
awaiting: Option<Awaiting>,
|
||||
/// The request to send (`ServerboundCommandSuggestionPacket`): id and
|
||||
/// the command up to the cursor.
|
||||
request: Option<(i32, String)>,
|
||||
suggestions: Option<SuggestionList>,
|
||||
usage: Vec<Text>,
|
||||
usage_position: i32,
|
||||
@@ -394,6 +400,16 @@ pub struct ChatScreen {
|
||||
keep_suggestions: bool,
|
||||
pub auto_suggestions: bool,
|
||||
}
|
||||
/// Local completions waiting for the server's reply to request `id`.
|
||||
struct Awaiting {
|
||||
id: i32,
|
||||
/// The command up to the cursor, as sent.
|
||||
truncated: String,
|
||||
local: Vec<Suggestion>,
|
||||
}
|
||||
/// `ClientSuggestionProvider.pendingSuggestionsId`: one counter for the
|
||||
/// connection, so a reply to an older request never matches.
|
||||
static SUGGESTION_ID: std::sync::atomic::AtomicI32 = std::sync::atomic::AtomicI32::new(0);
|
||||
/// `CommandSuggestions`' fill colour.
|
||||
const FILL: i32 = -805306368;
|
||||
fn byte_at(s: &str, chars: usize) -> usize {
|
||||
@@ -442,6 +458,8 @@ impl ChatScreen {
|
||||
history_pos: history_len,
|
||||
parse: None,
|
||||
pending: None,
|
||||
awaiting: None,
|
||||
request: None,
|
||||
suggestions: None,
|
||||
usage: Vec::new(),
|
||||
usage_position: 0,
|
||||
@@ -518,24 +536,84 @@ impl ChatScreen {
|
||||
}
|
||||
if cursor >= 1 && (self.suggestions.is_none() || !self.keep_suggestions) {
|
||||
let parse = self.parse.as_ref().expect("parsed above");
|
||||
let (range, list) = c
|
||||
.dispatcher
|
||||
.client_suggestions(parse, cursor_b, c.registries);
|
||||
self.pending = Some((range.0, list));
|
||||
self.update_usage_info(m, c);
|
||||
let (range, list, ask) =
|
||||
c.dispatcher
|
||||
.client_suggestions_asking(parse, cursor_b, c.registries);
|
||||
if ask {
|
||||
// ClientSuggestionProvider.customSuggestion: the
|
||||
// suggestions are done when the server answers.
|
||||
let id = SUGGESTION_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
|
||||
let truncated = command[..cursor_b].to_owned();
|
||||
self.request = Some((id, truncated.clone()));
|
||||
self.awaiting = Some(Awaiting {
|
||||
id,
|
||||
truncated,
|
||||
local: list,
|
||||
});
|
||||
self.pending = None;
|
||||
} else {
|
||||
self.awaiting = None;
|
||||
self.pending = Some((range.0, list));
|
||||
self.update_usage_info(m, c);
|
||||
}
|
||||
}
|
||||
} else if !command.chars().all(char::is_whitespace) {
|
||||
let partial = &command[..cursor_b];
|
||||
let mut builder = SuggestionsBuilder::new(partial, last_word_index(partial));
|
||||
builder.suggest_matching(c.registries.players.iter().map(String::as_str));
|
||||
let (range, list) = merge_suggestions(partial, builder.out);
|
||||
self.awaiting = None;
|
||||
self.pending = Some((range.0, list));
|
||||
self.usage_width = 0;
|
||||
self.usage_position = 0;
|
||||
} else {
|
||||
self.awaiting = None;
|
||||
self.pending = None;
|
||||
}
|
||||
}
|
||||
/// The completion request to send to the server, if one is waiting.
|
||||
pub fn take_request(&mut self) -> Option<(i32, String)> {
|
||||
self.request.take()
|
||||
}
|
||||
/// `ClientSuggestionProvider.completeCustomSuggestions`: the server's
|
||||
/// completions for request `id`, with `range` in UTF-16 units of the
|
||||
/// command sent. They join the local ones (`Suggestions.merge`) and the
|
||||
/// pending suggestions are done.
|
||||
pub fn server_suggestions(
|
||||
&mut self,
|
||||
m: &Measure,
|
||||
c: &Commands,
|
||||
id: i32,
|
||||
range: (usize, usize),
|
||||
list: Vec<(String, Option<String>)>,
|
||||
) {
|
||||
let Some(awaiting) = self.awaiting.take_if(|a| a.id == id) else {
|
||||
return;
|
||||
};
|
||||
let input = &awaiting.truncated;
|
||||
let byte = |units: usize| {
|
||||
let mut n = 0;
|
||||
input
|
||||
.char_indices()
|
||||
.find(|(_, ch)| {
|
||||
let past = n >= units;
|
||||
n += ch.len_utf16();
|
||||
past
|
||||
})
|
||||
.map_or(input.len(), |(i, _)| i)
|
||||
};
|
||||
let range = (byte(range.0), byte(range.0 + range.1));
|
||||
let mut all = awaiting.local;
|
||||
all.extend(list.into_iter().map(|(text, tooltip)| Suggestion {
|
||||
range,
|
||||
text,
|
||||
tooltip,
|
||||
int_value: None,
|
||||
}));
|
||||
let (range, list) = merge_suggestions(input, all);
|
||||
self.pending = Some((range.0, list));
|
||||
self.update_usage_info(m, c);
|
||||
}
|
||||
/// `CommandSuggestions.updateUsageInfo`.
|
||||
fn update_usage_info(&mut self, m: &Measure, c: &Commands) {
|
||||
let Some(parse) = &self.parse else { return };
|
||||
|
||||
@@ -230,3 +230,58 @@ fn mod_commands_are_coloured_and_complete_like_vanilla_ones() {
|
||||
screen.key(&m, &c, &[], winit::keyboard::KeyCode::Tab, false, false);
|
||||
assert_eq!(screen.value(), "/coords");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ask_server_nodes_wait_for_the_servers_completions() {
|
||||
// ClientSuggestionProvider.customSuggestion: an `ask_server` node at the
|
||||
// cursor sends the command so far, and the list is done with the reply.
|
||||
let font = font();
|
||||
let m = Measure(&font);
|
||||
let registries = Registries {
|
||||
permission: 4,
|
||||
..Registries::default()
|
||||
};
|
||||
let mut d = crate::command::vanilla::game_dispatcher().clone();
|
||||
let child = |d: &crate::command::Dispatcher, n: usize, name: &str| {
|
||||
d.nodes[n]
|
||||
.children
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|&c| d.nodes[c].name() == name)
|
||||
.expect(name)
|
||||
};
|
||||
let id = child(&d, child(&d, child(&d, 0, "bossbar"), "get"), "id");
|
||||
d.nodes[id].suggests = Some(crate::command::Suggests::AskServer);
|
||||
let c = Commands {
|
||||
dispatcher: &d,
|
||||
registries: ®istries,
|
||||
};
|
||||
let tab = |screen: &mut ChatScreen| {
|
||||
screen.key(&m, &c, &[], winit::keyboard::KeyCode::Tab, false, false);
|
||||
};
|
||||
let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360);
|
||||
screen.type_text(&m, &c, "/bossbar get pt");
|
||||
let (request, sent) = screen.take_request().expect("the server is asked");
|
||||
assert_eq!(sent, "/bossbar get pt");
|
||||
assert_eq!(screen.take_request(), None);
|
||||
// Nothing to complete until the reply.
|
||||
tab(&mut screen);
|
||||
assert_eq!(screen.value(), "/bossbar get pt");
|
||||
// A reply to an older request is dropped; the range is in UTF-16 units.
|
||||
let reply = |text: &str| vec![(text.to_owned(), None)];
|
||||
screen.server_suggestions(&m, &c, request - 1, (13, 2), reply("pt6:old"));
|
||||
tab(&mut screen);
|
||||
assert_eq!(screen.value(), "/bossbar get pt");
|
||||
screen.server_suggestions(&m, &c, request, (13, 2), reply("pt6:check"));
|
||||
tab(&mut screen);
|
||||
assert_eq!(screen.value(), "/bossbar get pt6:check");
|
||||
// Without the server's provider the local list is done at once.
|
||||
let local = crate::command::vanilla::game_dispatcher();
|
||||
let c = Commands {
|
||||
dispatcher: local,
|
||||
registries: ®istries,
|
||||
};
|
||||
let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360);
|
||||
screen.type_text(&m, &c, "/bossbar get pt");
|
||||
assert_eq!(screen.take_request(), None);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! (copy-on-write through `Arc::make_mut`).
|
||||
use horizon_core::paletted::{PalettedContainer, Strategy};
|
||||
use horizon_world::registry::BlockStateId;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
pub const MIN_Y: i32 = -64;
|
||||
pub const HEIGHT: i32 = 384;
|
||||
@@ -45,6 +45,10 @@ impl Light {
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn column(x: i32, z: i32) -> usize {
|
||||
((z & 15) << 4 | (x & 15)) as usize
|
||||
}
|
||||
#[inline]
|
||||
pub fn index(x: i32, y: i32, z: i32) -> usize {
|
||||
((y & 15) << 8 | (z & 15) << 4 | (x & 15)) as usize
|
||||
}
|
||||
@@ -118,8 +122,10 @@ pub struct Chunk {
|
||||
pub x: i32,
|
||||
pub z: i32,
|
||||
pub sections: Vec<Arc<Section>>,
|
||||
/// Highest non-air, light-blocking-or-fluid Y per column (MOTION_BLOCKING-like), for rain/sky.
|
||||
pub heights: Arc<[i16; 256]>,
|
||||
/// `Heightmap.Types.WORLD_SURFACE` per column (`z << 4 | x`): one above
|
||||
/// the highest non-air block, or `MIN_Y`. Built on the first read; a
|
||||
/// `set` that can move a column's surface drops it.
|
||||
surface: OnceLock<Box<[i16; 256]>>,
|
||||
pub lit: bool,
|
||||
/// Light read from a save with `isLightOn`: no light job is needed.
|
||||
pub light_loaded: bool,
|
||||
@@ -148,7 +154,7 @@ impl Chunk {
|
||||
sections: (0..SECTIONS)
|
||||
.map(|_| Arc::new(Section::default()))
|
||||
.collect(),
|
||||
heights: Arc::new([MIN_Y as i16; 256]),
|
||||
surface: OnceLock::new(),
|
||||
lit: false,
|
||||
light_loaded: false,
|
||||
fresh: false,
|
||||
@@ -190,7 +196,52 @@ impl Chunk {
|
||||
if !(0..SECTIONS as i32).contains(&s) {
|
||||
return v;
|
||||
}
|
||||
Arc::make_mut(&mut self.sections[s as usize]).set(index(x, y, z), v)
|
||||
let previous = Arc::make_mut(&mut self.sections[s as usize]).set(index(x, y, z), v);
|
||||
// `Heightmap.update`: a write two or more below the surface can't
|
||||
// move it. Any other change rebuilds the map on the next read.
|
||||
if previous != v
|
||||
&& let Some(surface) = self.surface.get()
|
||||
&& y >= i32::from(surface[column(x, z)]) - 1
|
||||
{
|
||||
self.surface = OnceLock::new();
|
||||
}
|
||||
previous
|
||||
}
|
||||
/// `getHeight(Heightmap.Types.WORLD_SURFACE, x, z)` (`x`, `z` within the
|
||||
/// chunk): one above the highest block that isn't `air`, or `MIN_Y`.
|
||||
/// Sections must change only through `set` once this has been read.
|
||||
pub fn world_surface(&self, x: i32, z: i32, air: impl Fn(u32) -> bool) -> i32 {
|
||||
let surface = self.surface.get_or_init(|| self.prime_surface(air));
|
||||
i32::from(surface[column(x, z)])
|
||||
}
|
||||
/// `Heightmap.primeHeightmaps` for WORLD_SURFACE: each section from the
|
||||
/// top, skipping those of one air state, until every column is found.
|
||||
fn prime_surface(&self, air: impl Fn(u32) -> bool) -> Box<[i16; 256]> {
|
||||
let mut surface = Box::new([MIN_Y as i16; 256]);
|
||||
let mut found = [false; 256];
|
||||
let mut left = 256;
|
||||
let mut values = [0u32; 4096];
|
||||
for (s, section) in self.sections.iter().enumerate().rev() {
|
||||
if left == 0 {
|
||||
break;
|
||||
}
|
||||
if section.blocks.uniform().is_some_and(&air) {
|
||||
continue;
|
||||
}
|
||||
section.unpack(&mut values);
|
||||
let base = MIN_Y + s as i32 * 16;
|
||||
for i in 0..256 {
|
||||
if found[i] {
|
||||
continue;
|
||||
}
|
||||
if let Some(dy) = (0..16).rev().find(|&dy| !air(values[dy << 8 | i])) {
|
||||
surface[i] = (base + dy as i32 + 1) as i16;
|
||||
found[i] = true;
|
||||
left -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
surface
|
||||
}
|
||||
#[inline]
|
||||
pub fn light(&self, x: i32, y: i32, z: i32) -> u8 {
|
||||
@@ -261,4 +312,50 @@ mod tests {
|
||||
);
|
||||
assert_eq!(Chunk::empty(0, 0).highest(air, |_| unreachable!()), None);
|
||||
}
|
||||
/// The kept WORLD_SURFACE heights match a scan of every column after
|
||||
/// each of a few thousand writes (air, cave air, stone, whole sections).
|
||||
#[test]
|
||||
fn world_surface_follows_writes() {
|
||||
let (air, cave_air, stone) = (0, 7, 1);
|
||||
let is_air = |v: u32| v == air || v == cave_air;
|
||||
let scan = |c: &Chunk, x: i32, z: i32| {
|
||||
(MIN_Y..MIN_Y + HEIGHT)
|
||||
.rev()
|
||||
.find(|&y| !is_air(c.get(x, y, z)))
|
||||
.map_or(MIN_Y, |y| y + 1)
|
||||
};
|
||||
let mut chunk = Chunk::empty(0, 0);
|
||||
assert_eq!(chunk.world_surface(5, 5, is_air), MIN_Y);
|
||||
for y in MIN_Y..MIN_Y + 70 {
|
||||
for i in 0..256 {
|
||||
chunk.set(i & 15, y, i >> 4, stone);
|
||||
}
|
||||
}
|
||||
for i in 0..4096 {
|
||||
Arc::make_mut(&mut chunk.sections[8]).set(i, cave_air);
|
||||
}
|
||||
let mut random = horizon_core::random::LegacyRandom::new(9);
|
||||
use horizon_core::random::RandomSource;
|
||||
for step in 0..4000 {
|
||||
let x = random.next_int_bound(16).unwrap();
|
||||
let z = random.next_int_bound(16).unwrap();
|
||||
let y = MIN_Y + 40 + random.next_int_bound(120).unwrap();
|
||||
let v = [air, cave_air, stone][random.next_int_bound(3).unwrap() as usize];
|
||||
chunk.set(x, y, z, v);
|
||||
if step % 7 == 0 {
|
||||
for i in 0..256 {
|
||||
assert_eq!(
|
||||
chunk.world_surface(i & 15, i >> 4, is_air),
|
||||
scan(&chunk, i & 15, i >> 4)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Out-of-range writes and unchanged states keep the map.
|
||||
let before = chunk.world_surface(3, 3, is_air);
|
||||
chunk.set(3, MIN_Y + HEIGHT, 3, stone);
|
||||
chunk.set(3, before - 1, 3, chunk.get(3, before - 1, 3));
|
||||
assert!(chunk.surface.get().is_some());
|
||||
assert_eq!(chunk.world_surface(3, 3, |_| unreachable!()), before);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,24 +15,18 @@ use horizon_world::{
|
||||
entity_obstruction::EntityIdentity,
|
||||
fluid::{FluidKind, FluidState},
|
||||
liquid_collision::LiquidCollisionWorld,
|
||||
nbt::{self, Limits},
|
||||
powder_snow_collision::{PowderSnowEntity, PowderSnowWorld},
|
||||
registry::BlockRegistry,
|
||||
registry::{BlockRegistry, BlockTableFile},
|
||||
world_movement::{
|
||||
CollisionCheckRequest, EntityMovementWorld, MovementRequest, no_world_collision,
|
||||
resolve_world_movement,
|
||||
},
|
||||
};
|
||||
use std::{fs, io, path::Path, sync::Arc};
|
||||
use std::{io, path::Path, sync::Arc};
|
||||
|
||||
pub fn load<'r>(root: &Path, registry: &'r BlockRegistry) -> Result<BlockCollisionRegistry<'r>> {
|
||||
let data = nbt::read_named(
|
||||
&fs::read(root.join("cached-collision.nbt"))?,
|
||||
Limits::tables(),
|
||||
)?
|
||||
.0
|
||||
.tag;
|
||||
let cached = CachedCollisionRegistry::from_nbt(&data, registry)?;
|
||||
let file = BlockTableFile::open(&root.join("cached-collision.nbt"), registry)?;
|
||||
let cached = CachedCollisionRegistry::from_table(file.table("collision")?)?;
|
||||
if !cached.has_canonical_identities() {
|
||||
return Err("scene collisions require canonical shape identities".into());
|
||||
}
|
||||
@@ -137,12 +131,25 @@ impl SceneCollisions<'_, '_> {
|
||||
movement: Vec3,
|
||||
max_step: f32,
|
||||
on_ground: bool,
|
||||
) -> Result<Vec3> {
|
||||
self.resolve_with_context(bounds, movement, max_step, on_ground, self.context(bounds))
|
||||
}
|
||||
/// Resolve movement with the entity's captured collision context. Most
|
||||
/// callers only need the position context; entities such as falling blocks
|
||||
/// also affect contextual block shapes (for example powder snow).
|
||||
pub fn resolve_with_context(
|
||||
&mut self,
|
||||
bounds: Aabb,
|
||||
movement: Vec3,
|
||||
max_step: f32,
|
||||
on_ground: bool,
|
||||
context: CollisionContext<'_>,
|
||||
) -> Result<Vec3> {
|
||||
Ok(resolve_world_movement(
|
||||
self,
|
||||
MovementRequest {
|
||||
entity: EntityIdentity(0),
|
||||
context: self.context(bounds),
|
||||
context,
|
||||
bounds,
|
||||
movement,
|
||||
max_step,
|
||||
|
||||
@@ -312,6 +312,9 @@ pub enum Suggests {
|
||||
/// ScoreboardCommand.suggestTriggers: trigger objectives some of the
|
||||
/// parsed `targets` have no score in, or a locked one.
|
||||
EnableTriggers,
|
||||
/// SuggestionProviders.ASK_SERVER: the server completes the node
|
||||
/// (ClientSuggestionProvider.customSuggestion); nothing locally.
|
||||
AskServer,
|
||||
}
|
||||
impl Node {
|
||||
pub fn name(&self) -> &str {
|
||||
@@ -691,7 +694,7 @@ impl Suggests {
|
||||
Suggests::Triggers => {
|
||||
builder.suggest_matching(reg.trigger_objectives.iter().map(String::as_str))
|
||||
}
|
||||
Suggests::Nothing => {}
|
||||
Suggests::Nothing | Suggests::AskServer => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -955,7 +958,8 @@ impl Dispatcher {
|
||||
cursor: usize,
|
||||
reg: &Registries,
|
||||
) -> (Range, Vec<Suggestion>) {
|
||||
self.suggestions_within(parse, cursor, reg, u8::MAX)
|
||||
let (range, list, _) = self.suggestions_within(parse, cursor, reg, u8::MAX);
|
||||
(range, list)
|
||||
}
|
||||
/// The suggestions the player's chat shows: the client's tree only holds
|
||||
/// the nodes the player may use (Commands.sendCommands prunes by canUse).
|
||||
@@ -965,6 +969,18 @@ impl Dispatcher {
|
||||
cursor: usize,
|
||||
reg: &Registries,
|
||||
) -> (Range, Vec<Suggestion>) {
|
||||
let (range, list, _) = self.suggestions_within(parse, cursor, reg, reg.permission);
|
||||
(range, list)
|
||||
}
|
||||
/// [`Self::client_suggestions`], and whether a node at the cursor asks
|
||||
/// the server (`ask_server`): its completions come with the server's
|
||||
/// reply, to be merged with these.
|
||||
pub fn client_suggestions_asking(
|
||||
&self,
|
||||
parse: &ParseResults,
|
||||
cursor: usize,
|
||||
reg: &Registries,
|
||||
) -> (Range, Vec<Suggestion>, bool) {
|
||||
self.suggestions_within(parse, cursor, reg, reg.permission)
|
||||
}
|
||||
fn suggestions_within(
|
||||
@@ -973,15 +989,17 @@ impl Dispatcher {
|
||||
cursor: usize,
|
||||
reg: &Registries,
|
||||
permission: u8,
|
||||
) -> (Range, Vec<Suggestion>) {
|
||||
) -> (Range, Vec<Suggestion>, bool) {
|
||||
let (parent, start, context) = parse.context.suggestion_context(cursor);
|
||||
let start = start.min(cursor);
|
||||
let truncated = &parse.input[..cursor.min(parse.input.len())];
|
||||
let mut all = Vec::new();
|
||||
let mut ask = false;
|
||||
for &child in &self.nodes[parent].children {
|
||||
if self.nodes[child].permission > permission {
|
||||
continue;
|
||||
}
|
||||
ask |= matches!(self.nodes[child].suggests, Some(Suggests::AskServer));
|
||||
let mut builder = SuggestionsBuilder::new(truncated, start);
|
||||
match &self.nodes[child].kind {
|
||||
NodeKind::Literal(l) => {
|
||||
@@ -997,7 +1015,8 @@ impl Dispatcher {
|
||||
}
|
||||
all.extend(builder.out);
|
||||
}
|
||||
merge_suggestions(truncated, all)
|
||||
let (range, list) = merge_suggestions(truncated, all);
|
||||
(range, list, ask)
|
||||
}
|
||||
fn smart_usage_of(&self, node: usize, optional: bool, deep: bool, level: u8) -> Option<String> {
|
||||
let n = &self.nodes[node];
|
||||
|
||||
@@ -83,10 +83,9 @@ pub fn from_packet(packet: &Commands, local: &Dispatcher) -> Dispatcher {
|
||||
}
|
||||
_ => NodeKind::Root,
|
||||
};
|
||||
let suggests = match local_node {
|
||||
Some(l) => l.suggests.clone(),
|
||||
None => node.suggestions.as_deref().and_then(provider),
|
||||
};
|
||||
// The server's providers, as the client knows them
|
||||
// (ArgumentNodeStub.build): its own custom ones arrive as `ask_server`.
|
||||
let suggests = node.suggestions.as_deref().and_then(provider);
|
||||
nodes[index(i)] = Some(Node {
|
||||
kind: if i == root { NodeKind::Root } else { kind },
|
||||
children: node.children.iter().filter_map(valid).map(index).collect(),
|
||||
@@ -104,10 +103,10 @@ pub fn from_packet(packet: &Commands, local: &Dispatcher) -> Dispatcher {
|
||||
d
|
||||
}
|
||||
|
||||
/// SuggestionProviders by id (`ask_server` asks the server; the client's
|
||||
/// own argument suggestions stand in for it).
|
||||
/// SuggestionProviders by id (`SuggestionProviders.getProvider`).
|
||||
fn provider(id: &str) -> Option<Suggests> {
|
||||
match id {
|
||||
"minecraft:ask_server" => Some(Suggests::AskServer),
|
||||
"minecraft:summonable_entities" => Some(Suggests::SummonableEntities),
|
||||
_ => None,
|
||||
}
|
||||
|
||||
@@ -336,73 +336,8 @@ impl PlayerEffects {
|
||||
pub fn modifiers(&self) -> Vec<(&'static str, &'static str, f64, &'static str)> {
|
||||
let mut out = Vec::new();
|
||||
for e in &self.list {
|
||||
let level = f64::from(e.amplifier + 1);
|
||||
let m = match e.id {
|
||||
"speed" => Some((
|
||||
"minecraft:movement_speed",
|
||||
"minecraft:effect.speed",
|
||||
0.2,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"slowness" => Some((
|
||||
"minecraft:movement_speed",
|
||||
"minecraft:effect.slowness",
|
||||
-0.15,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"haste" => Some((
|
||||
"minecraft:attack_speed",
|
||||
"minecraft:effect.haste",
|
||||
0.1,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"mining_fatigue" => Some((
|
||||
"minecraft:attack_speed",
|
||||
"minecraft:effect.mining_fatigue",
|
||||
-0.1,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"strength" => Some((
|
||||
"minecraft:attack_damage",
|
||||
"minecraft:effect.strength",
|
||||
3.0,
|
||||
"add_value",
|
||||
)),
|
||||
"weakness" => Some((
|
||||
"minecraft:attack_damage",
|
||||
"minecraft:effect.weakness",
|
||||
-4.0,
|
||||
"add_value",
|
||||
)),
|
||||
"jump_boost" => Some((
|
||||
"minecraft:safe_fall_distance",
|
||||
"minecraft:effect.jump_boost",
|
||||
1.0,
|
||||
"add_value",
|
||||
)),
|
||||
"health_boost" => Some((
|
||||
"minecraft:max_health",
|
||||
"minecraft:effect.health_boost",
|
||||
4.0,
|
||||
"add_value",
|
||||
)),
|
||||
"absorption" => Some((
|
||||
"minecraft:max_absorption",
|
||||
"minecraft:effect.absorption",
|
||||
4.0,
|
||||
"add_value",
|
||||
)),
|
||||
"luck" => Some(("minecraft:luck", "minecraft:effect.luck", 1.0, "add_value")),
|
||||
"unluck" => Some((
|
||||
"minecraft:luck",
|
||||
"minecraft:effect.unluck",
|
||||
-1.0,
|
||||
"add_value",
|
||||
)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((a, id, amount, op)) = m {
|
||||
out.push((a, id, amount * level, op));
|
||||
if let Some((a, id, amount, op)) = effect_modifier(e.id) {
|
||||
out.push((a, id, amount * f64::from(e.amplifier + 1), op));
|
||||
}
|
||||
}
|
||||
out
|
||||
@@ -445,6 +380,76 @@ impl StatusFlags {
|
||||
}
|
||||
}
|
||||
|
||||
/// The attribute modifier an effect adds at amplifier 0
|
||||
/// (`MobEffect.addAttributeModifier`): (attribute, id, amount, operation).
|
||||
/// Each level multiplies the amount (`amplifier + 1`).
|
||||
pub fn effect_modifier(effect: &str) -> Option<(&'static str, &'static str, f64, &'static str)> {
|
||||
match effect {
|
||||
"speed" => Some((
|
||||
"minecraft:movement_speed",
|
||||
"minecraft:effect.speed",
|
||||
0.2,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"slowness" => Some((
|
||||
"minecraft:movement_speed",
|
||||
"minecraft:effect.slowness",
|
||||
-0.15,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"haste" => Some((
|
||||
"minecraft:attack_speed",
|
||||
"minecraft:effect.haste",
|
||||
0.1,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"mining_fatigue" => Some((
|
||||
"minecraft:attack_speed",
|
||||
"minecraft:effect.mining_fatigue",
|
||||
-0.1,
|
||||
"add_multiplied_total",
|
||||
)),
|
||||
"strength" => Some((
|
||||
"minecraft:attack_damage",
|
||||
"minecraft:effect.strength",
|
||||
3.0,
|
||||
"add_value",
|
||||
)),
|
||||
"weakness" => Some((
|
||||
"minecraft:attack_damage",
|
||||
"minecraft:effect.weakness",
|
||||
-4.0,
|
||||
"add_value",
|
||||
)),
|
||||
"jump_boost" => Some((
|
||||
"minecraft:safe_fall_distance",
|
||||
"minecraft:effect.jump_boost",
|
||||
1.0,
|
||||
"add_value",
|
||||
)),
|
||||
"health_boost" => Some((
|
||||
"minecraft:max_health",
|
||||
"minecraft:effect.health_boost",
|
||||
4.0,
|
||||
"add_value",
|
||||
)),
|
||||
"absorption" => Some((
|
||||
"minecraft:max_absorption",
|
||||
"minecraft:effect.absorption",
|
||||
4.0,
|
||||
"add_value",
|
||||
)),
|
||||
"luck" => Some(("minecraft:luck", "minecraft:effect.luck", 1.0, "add_value")),
|
||||
"unluck" => Some((
|
||||
"minecraft:luck",
|
||||
"minecraft:effect.unluck",
|
||||
-1.0,
|
||||
"add_value",
|
||||
)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -179,6 +179,8 @@ impl ItemEntity {
|
||||
/// ExperienceOrb: gravity 0.03, homing towards the player within 8 blocks.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ExperienceOrb {
|
||||
/// The entity id servers track it by.
|
||||
pub id: u32,
|
||||
pub position: Vec3,
|
||||
pub previous: Vec3,
|
||||
pub velocity: Vec3,
|
||||
@@ -533,15 +535,16 @@ impl ArmorStand {
|
||||
Vec3::new(p.x + w, p.y + h, p.z + w),
|
||||
)
|
||||
}
|
||||
/// LivingEntity.travel with gravity 0.08 and 0.98 drag, falling until it
|
||||
/// lands (armor stands have no other movement).
|
||||
/// LivingEntity.travelInAir (armor stands have no other movement): move
|
||||
/// by the velocity (a landing stops the fall,
|
||||
/// `Block.updateEntityMovementAfterFallOn`), then gravity 0.08 and the
|
||||
/// 0.98 drag, so a stand at rest on the ground keeps -0.0784 as vanilla's.
|
||||
pub fn tick(&mut self, scene: &mut crate::collisions::SceneCollisions) {
|
||||
if self.marker {
|
||||
return;
|
||||
}
|
||||
let mut v = self.velocity;
|
||||
v.y -= 0.08;
|
||||
let wanted = v;
|
||||
let wanted = self.velocity;
|
||||
let mut y = wanted.y;
|
||||
if let Ok(moved) = scene.resolve(self.bounds(), wanted, 0.0, self.on_ground) {
|
||||
self.position = Vec3::new(
|
||||
self.position.x + moved.x,
|
||||
@@ -549,9 +552,11 @@ impl ArmorStand {
|
||||
self.position.z + moved.z,
|
||||
);
|
||||
self.on_ground = wanted.y < 0.0 && moved.y > wanted.y;
|
||||
v = Vec3::new(0.0, if moved.y != wanted.y { 0.0 } else { v.y * 0.98 }, 0.0);
|
||||
if moved.y != wanted.y {
|
||||
y = 0.0;
|
||||
}
|
||||
}
|
||||
self.velocity = v;
|
||||
self.velocity = Vec3::new(0.0, (y - 0.08) * f64::from(0.98f32), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,9 +602,10 @@ mod fire_environment_tests {
|
||||
return;
|
||||
}
|
||||
let assets = crate::assets::Assets::load(&root).unwrap();
|
||||
let render = assets.reload(&root).unwrap();
|
||||
let facts = BlockFacts::load(&root, assets.registry).unwrap();
|
||||
let items = crate::items::Items::load(&root, assets.registry, &facts).unwrap();
|
||||
let mut world = World::test_scene(&assets, 3).unwrap();
|
||||
let mut world = World::test_scene(&assets, &render, 3).unwrap();
|
||||
let at = Vec3::new(20.5, 4.0, 20.5);
|
||||
world
|
||||
.set(
|
||||
|
||||
@@ -840,9 +840,12 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
|
||||
m.species(),
|
||||
crate::mobs::Species::Slime | crate::mobs::Species::MagmaCube
|
||||
) {
|
||||
let health = m.health;
|
||||
// AbstractCubeMob.readAdditionalSaveData: the size's attributes, then
|
||||
// the saved health, the max health when there is none.
|
||||
crate::mobs::cube::set_size(&mut m, number(tag.get("Size")).unwrap_or(0) as i32 + 1);
|
||||
m.health = health;
|
||||
if let Some(h) = float(tag.get("Health")) {
|
||||
m.health = h as f32;
|
||||
}
|
||||
m.extra.flag2 = flag(tag, "wasOnGround");
|
||||
}
|
||||
// Zombie, Piglin and Zoglin.readAdditionalSaveData: IsBaby (the baby
|
||||
@@ -943,6 +946,7 @@ pub fn orbs_from_nbt(tag: &Tag) -> Vec<ExperienceOrb> {
|
||||
};
|
||||
let count = number(tag.get("Count")).unwrap_or(1).clamp(1, 64) as usize;
|
||||
let orb = ExperienceOrb {
|
||||
id: 0,
|
||||
position,
|
||||
previous: position,
|
||||
velocity: motion(tag),
|
||||
@@ -1587,6 +1591,7 @@ mod tests {
|
||||
#[test]
|
||||
fn orbs_expand_their_count() {
|
||||
let o = ExperienceOrb {
|
||||
id: 0,
|
||||
position: Vec3::new(1.0, 2.0, 3.0),
|
||||
previous: Vec3::ZERO,
|
||||
velocity: Vec3::ZERO,
|
||||
|
||||
@@ -32,6 +32,7 @@ pub struct FogData {
|
||||
}
|
||||
|
||||
/// Per-biome water fog end multipliers (`visual/water_fog_end_distance`).
|
||||
#[derive(Default)]
|
||||
pub struct FogTables {
|
||||
water_fog_end: Vec<f32>,
|
||||
}
|
||||
|
||||
+1423
-578
File diff suppressed because it is too large
Load Diff
@@ -106,7 +106,7 @@ impl adv::World for View<'_, '_> {
|
||||
.map(|c| {
|
||||
self.0
|
||||
.res
|
||||
.biomes
|
||||
.biomes()
|
||||
.get(c.biome(p[0], p[1], p[2]))
|
||||
.name
|
||||
.clone()
|
||||
@@ -118,7 +118,7 @@ impl adv::World for View<'_, '_> {
|
||||
}
|
||||
fn block(&self, p: [i32; 3]) -> (String, BTreeMap<String, String>) {
|
||||
let state = self.0.world.block(p[0], p[1], p[2]);
|
||||
let name = self.0.res.facts.get(state).name.to_string();
|
||||
let name = self.0.res.facts().get(state).name.to_string();
|
||||
let props = self
|
||||
.0
|
||||
.pack
|
||||
@@ -138,7 +138,7 @@ impl adv::World for View<'_, '_> {
|
||||
match self
|
||||
.0
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.0.world.block(p[0], p[1], p[2]))
|
||||
.fluid
|
||||
{
|
||||
@@ -152,7 +152,7 @@ impl adv::World for View<'_, '_> {
|
||||
!self
|
||||
.0
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.0.world.block(p[0], y, p[2]))
|
||||
.full_collision
|
||||
})
|
||||
@@ -165,19 +165,19 @@ impl adv::World for View<'_, '_> {
|
||||
(1..=5).any(|d| {
|
||||
self.0
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.0.world.block(p[0], p[1] - d, p[2]))
|
||||
.name
|
||||
.ends_with("campfire")
|
||||
})
|
||||
}
|
||||
fn in_tag(&self, registry: &str, tag: &str, id: &str) -> bool {
|
||||
let items = &self.0.res.items;
|
||||
let items = &self.0.res.items();
|
||||
match registry {
|
||||
"item" => items.item_tags.get(tag).is_some_and(|t| t.contains(id)),
|
||||
"block" => items.block_tags.get(tag).is_some_and(|t| t.contains(id)),
|
||||
"entity_type" => self.0.res.mob_data.entity_has(tag, id),
|
||||
"worldgen/biome" => self.0.res.mob_data.biome_has(tag, id),
|
||||
"entity_type" => self.0.res.mob_data().entity_has(tag, id),
|
||||
"worldgen/biome" => self.0.res.mob_data().biome_has(tag, id),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -408,6 +408,9 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if hits.is_empty() {
|
||||
return;
|
||||
}
|
||||
let date = now_text();
|
||||
for (ai, ci) in hits {
|
||||
let a = &tree.list[ai];
|
||||
@@ -454,17 +457,17 @@ impl Game<'_> {
|
||||
.rewards
|
||||
.recipes
|
||||
.iter()
|
||||
.filter(|r| self.res.stations.recipe_index.contains(r))
|
||||
.filter(|r| self.res.stations().recipe_index.contains(r))
|
||||
.cloned()
|
||||
.collect();
|
||||
let (_, unlocked) = self
|
||||
.level
|
||||
.recipe_book
|
||||
.add_recipes(&self.res.stations.recipe_index, &rewards);
|
||||
.add_recipes(&self.res.stations().recipe_index, &rewards);
|
||||
for table in &a.rewards.loot {
|
||||
let items = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.loot_table(table, false, None, &mut self.world.random);
|
||||
for s in items {
|
||||
if let Some(rest) = self.give(s)
|
||||
@@ -497,10 +500,13 @@ impl Game<'_> {
|
||||
// PlayerList.broadcastSystemMessage: everyone hears of a
|
||||
// network player's advancement.
|
||||
match self.lan_acting_name.clone() {
|
||||
Some(player) => self
|
||||
.adv
|
||||
.announced
|
||||
.push(Text::translate(key, &[Text::literal(&player), name])),
|
||||
// Player.getDisplayName.
|
||||
Some(_) => {
|
||||
let player = self.target_name(super::commands::Target::Player);
|
||||
self.adv
|
||||
.announced
|
||||
.push(Text::translate(key, &[player, name]));
|
||||
}
|
||||
None => self.system_message(Text::translate(
|
||||
key,
|
||||
&[Text::literal(super::chat::PLAYER_NAME), name],
|
||||
@@ -549,7 +555,7 @@ impl Game<'_> {
|
||||
.filter_map(|s| s.as_ref())
|
||||
.filter(|s| {
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.get(&s.item)
|
||||
.is_some_and(|i| s.count >= i.max_stack)
|
||||
})
|
||||
@@ -790,11 +796,11 @@ impl Game<'_> {
|
||||
if let Some((station, item)) = recipe {
|
||||
// RecipeToast: black description under a purple title, the
|
||||
// station at 0.6 scale in the corner over the cycling result.
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
batch.sprite(atlas, "gui/sprites/toast/recipe", x, 0.0);
|
||||
let title = self.translate("recipe.toast.title", "New Recipe(s) Unlocked!");
|
||||
let description = self.translate("recipe.toast.description", "Check your recipe book");
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
batch.text(atlas, &title, x + 30.0, 7.0, 0xFF50_0050, false);
|
||||
batch.text(atlas, &description, x + 30.0, 18.0, 0xFF00_0000, false);
|
||||
let start = batch.vertices.len();
|
||||
@@ -803,7 +809,7 @@ impl Game<'_> {
|
||||
self.draw_item_model(batch, &item, x + 8.0, 8.0);
|
||||
return;
|
||||
}
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
batch.sprite(atlas, "gui/sprites/toast/advancement", x, 0.0);
|
||||
let (key, color) = match frame {
|
||||
Frame::Task => ("advancements.toast.task", 0xFF00_FFFF),
|
||||
@@ -832,18 +838,25 @@ pub(super) fn adv_name(a: &adv::Advancement) -> Text {
|
||||
Frame::Challenge => text::DARK_PURPLE,
|
||||
_ => text::GREEN,
|
||||
};
|
||||
let tooltip = text_of(&d.title)
|
||||
.with_color(color)
|
||||
// Advancement.decorateName: the title in the frame's colour (styles
|
||||
// merged into it), a new line and the description.
|
||||
let coloured = text_of(&d.title).with_color(color);
|
||||
let mut component = coloured.component();
|
||||
if let Some(o) = component.as_object_mut() {
|
||||
o.insert(
|
||||
"extra".into(),
|
||||
serde_json::json!(["\n", text_of(&d.description).component()]),
|
||||
);
|
||||
}
|
||||
let tooltip = coloured
|
||||
.append("\n")
|
||||
.append(text_of(&d.description));
|
||||
.append(text_of(&d.description))
|
||||
.with_component(component);
|
||||
let title = text_of(&d.title).with_style(&Style {
|
||||
hover: Some(Box::new(tooltip)),
|
||||
..Style::default()
|
||||
});
|
||||
Text::literal("[")
|
||||
.append(title)
|
||||
.append("]")
|
||||
.with_color(color)
|
||||
Text::translate("chat.square_brackets", &[title]).with_color(color)
|
||||
}
|
||||
impl Game<'_> {
|
||||
/// `AdvancementCommands.Action.GRANT` on one advancement (or one of
|
||||
|
||||
@@ -269,7 +269,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// `AdvancementWidget`'s title lines, description lines and width.
|
||||
fn adv_widget_text(&self, i: usize) -> (Vec<Text>, Vec<Text>, f32) {
|
||||
let font = &self.atlas.font;
|
||||
let font = &self.gui.atlas.font;
|
||||
let a = &self.adv.tree.list[i];
|
||||
let Some(d) = &a.display else {
|
||||
return (Vec::new(), Vec::new(), 0.0);
|
||||
@@ -332,7 +332,7 @@ impl Game<'_> {
|
||||
let (sx, sy) = self.adv_ui.scroll.unwrap_or_default();
|
||||
let (sx, sy) = (sx.floor() as i32, sy.floor() as i32);
|
||||
self.adv_tick_hover(&view, sx, sy, left, top);
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
ui::menu_background(batch, atlas, 0.0, 0.0, w, h, true);
|
||||
let title = Text::translate("gui.advancements", &[]);
|
||||
let tw = atlas.font.width_text(&title);
|
||||
@@ -444,7 +444,7 @@ impl Game<'_> {
|
||||
}
|
||||
let (x, y) = pos(i);
|
||||
let (x, y) = ((ox + x) as f32, (oy + y) as f32);
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
batch.sprite_scaled(
|
||||
atlas,
|
||||
frame_sprite(d.frame, done),
|
||||
@@ -461,7 +461,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
// The window, tabs and title.
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
batch.sprite_region(
|
||||
atlas,
|
||||
"gui/advancements/window",
|
||||
@@ -475,7 +475,7 @@ impl Game<'_> {
|
||||
let (x, y) = tab_pos(ty, i);
|
||||
let sprite = tab_sprite(ty, i, ty.3, Some(t) == tab);
|
||||
batch.sprite_scaled(
|
||||
&self.atlas,
|
||||
&self.gui.atlas,
|
||||
&sprite,
|
||||
left + x,
|
||||
top + y,
|
||||
@@ -494,7 +494,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let title = tab.and_then(|t| tree.list[t].display.as_ref()).map_or_else(
|
||||
|| Text::translate("gui.advancements", &[]),
|
||||
|d| text_of(&d.title),
|
||||
@@ -509,7 +509,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
// Done.
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let (bx, by) = ((w / 2.0 - 100.0).floor(), h - FOOTER + 6.0);
|
||||
let hover = ui::hovered(self.cursor, bx, by, 200.0, 20.0);
|
||||
ui::button(
|
||||
@@ -532,7 +532,7 @@ impl Game<'_> {
|
||||
let (cx, cy) = self.cursor;
|
||||
if cx > x && cx < x + ty.1 && cy > y && cy < y + ty.2 {
|
||||
if let Some(d) = &tree.list[t].display {
|
||||
ui::tooltip(batch, &self.atlas, &[text_of(&d.title)], self.cursor);
|
||||
ui::tooltip(batch, &self.gui.atlas, &[text_of(&d.title)], self.cursor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -616,7 +616,7 @@ impl Game<'_> {
|
||||
],
|
||||
)
|
||||
});
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let progress_w = progress.as_ref().map_or(0.0, |t| atlas.font.width_text(t)) as i32;
|
||||
let top_side = title_bottom + desc_h >= INSIDE_H;
|
||||
let amount = if a.criteria.is_empty() || total == 0 {
|
||||
|
||||
@@ -4,7 +4,13 @@
|
||||
//! take time run as a task advanced every frame and reply when they finish or
|
||||
//! time out, so `horizon-ctl break 10 64 3` returns what the block dropped.
|
||||
use super::{Game, Screen};
|
||||
use horizon_client::{Result, block_entity_anim::Ticker, items::ItemStack, widgets};
|
||||
use horizon_client::{
|
||||
Result,
|
||||
block_entity_anim::Ticker,
|
||||
chunk::{MIN_Y, SECTIONS},
|
||||
items::ItemStack,
|
||||
widgets,
|
||||
};
|
||||
use horizon_core::geometry::Vec3;
|
||||
use horizon_world::registry::BlockStateId;
|
||||
use serde_json::{Value, json};
|
||||
@@ -27,6 +33,7 @@ pub(super) const HELP: &[&str] = &[
|
||||
"entities [RADIUS] [TYPE] mobs, dropped items and orbs near the player, nearest first",
|
||||
"block X Y Z the block state at a position",
|
||||
"blocks X1 Y1 Z1 X2 Y2 Z2 the non-air blocks of a box (at most 32768 blocks)",
|
||||
"light X1 Y1 Z1 X2 Y2 Z2 the stored sky and block light of a box (at most 32768 blocks)",
|
||||
"find-block BLOCK [RADIUS] the nearest loaded blocks of a kind (default radius 32)",
|
||||
"inventory hotbar, main inventory, armor, offhand and carried stack",
|
||||
"screen the open screen or menu, its slots and its buttons",
|
||||
@@ -318,7 +325,7 @@ impl Game<'_> {
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
let mut v = json!({
|
||||
"pos": pos,
|
||||
"block": &*self.res.facts.get(state).name,
|
||||
"block": &*self.res.facts().get(state).name,
|
||||
"state": self.state_string(state),
|
||||
"loaded": self.world.chunks.contains_key(&(pos[0] >> 4, pos[2] >> 4)),
|
||||
});
|
||||
@@ -466,6 +473,12 @@ impl Game<'_> {
|
||||
}),
|
||||
"dimension": self.dim.id(),
|
||||
"gamemode": format!("{:?}", self.mode).to_lowercase(),
|
||||
// The bed (its head) the player sleeps in.
|
||||
"sleeping": self.sleeping,
|
||||
// The item in use: its slot and for how many ticks.
|
||||
"using": self.using.map(|(slot, ticks)| json!({ "slot": slot, "ticks": ticks })),
|
||||
// The arm swings started (LivingEntity.swing).
|
||||
"swings": self.swings_started,
|
||||
"time": { "day_time": self.world.day_time, "day": self.world.day_time.div_euclid(24000), "time_of_day": self.world.day_time.rem_euclid(24000) },
|
||||
"weather": { "raining": self.world.weather.raining, "thundering": self.world.weather.thundering },
|
||||
"paused": self.pause,
|
||||
@@ -568,7 +581,7 @@ impl Game<'_> {
|
||||
push(
|
||||
[m.position.x, m.position.y, m.position.z],
|
||||
m.kind.id.as_ref(),
|
||||
json!({ "id": m.id, "kind": "mob", "health": m.health, "baby": m.is_baby() }),
|
||||
json!({ "id": m.id, "kind": "mob", "health": m.health, "baby": m.is_baby(), "hurt_time": m.hurt_time }),
|
||||
);
|
||||
}
|
||||
for item in &self.dropped {
|
||||
@@ -666,17 +679,25 @@ impl Game<'_> {
|
||||
|
||||
/// Whether a block stops movement, for the path finder.
|
||||
fn blocks_motion(&self, pos: [i32; 3]) -> bool {
|
||||
let f = self.res.facts.get(self.world.block(pos[0], pos[1], pos[2]));
|
||||
let f = self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(pos[0], pos[1], pos[2]));
|
||||
f.full_collision || f.legacy_solid
|
||||
}
|
||||
fn walkable(&self, n: Node) -> bool {
|
||||
let below = self.world.block(n[0], n[1] - 1, n[2]);
|
||||
let lava = |p: [i32; 3]| {
|
||||
&*self.res.facts.get(self.world.block(p[0], p[1], p[2])).name == "minecraft:lava"
|
||||
&*self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(p[0], p[1], p[2]))
|
||||
.name
|
||||
== "minecraft:lava"
|
||||
};
|
||||
self.world.chunks.contains_key(&(n[0] >> 4, n[2] >> 4))
|
||||
&& (self.blocks_motion([n[0], n[1] - 1, n[2]])
|
||||
|| self.res.facts.get(below).fluid != horizon_client::blocks::Fluid::None)
|
||||
|| self.res.facts().get(below).fluid != horizon_client::blocks::Fluid::None)
|
||||
&& !self.blocks_motion(n)
|
||||
&& !self.blocks_motion([n[0], n[1] + 1, n[2]])
|
||||
&& !lava(n)
|
||||
@@ -737,7 +758,11 @@ impl Game<'_> {
|
||||
if !clear || !self.walkable(m) {
|
||||
continue;
|
||||
}
|
||||
let water = self.res.facts.get(self.world.block(m[0], m[1], m[2])).fluid
|
||||
let water = self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(m[0], m[1], m[2]))
|
||||
.fluid
|
||||
!= horizon_client::blocks::Fluid::None;
|
||||
let step = 10 + if dy != 0 { 5 } else { 0 } + if water { 30 } else { 0 };
|
||||
let c = base + step;
|
||||
@@ -947,10 +972,10 @@ impl Game<'_> {
|
||||
for z in lo[2]..=hi[2] {
|
||||
for x in lo[0]..=hi[0] {
|
||||
let state = self.world.block(x, y, z);
|
||||
if self.res.facts.is_air(state) {
|
||||
if self.res.facts().is_air(state) {
|
||||
continue;
|
||||
}
|
||||
let name = self.res.facts.get(state).name.to_string();
|
||||
let name = self.res.facts().get(state).name.to_string();
|
||||
*census.entry(name).or_insert(0) += 1;
|
||||
list.push(json!([x, y, z, self.state_string(state)]));
|
||||
}
|
||||
@@ -958,6 +983,35 @@ impl Game<'_> {
|
||||
}
|
||||
ok(json!({ "from": lo, "to": hi, "counts": census, "blocks": list }))
|
||||
}
|
||||
"light" => {
|
||||
self.need_world()?;
|
||||
let (p, q) = (a.block_pos(0)?, a.block_pos(3)?);
|
||||
let lo = [0, 1, 2].map(|i| p[i].min(q[i]));
|
||||
let hi = [0, 1, 2].map(|i| p[i].max(q[i]));
|
||||
let volume: i64 = (0..3).map(|i| i64::from(hi[i] - lo[i] + 1)).product();
|
||||
if volume > 32768 {
|
||||
return Err(format!("{volume} blocks; at most 32768 per request").into());
|
||||
}
|
||||
// One hex digit per block, x fastest, then z, then y; `.`
|
||||
// outside the loaded chunks.
|
||||
let (mut sky, mut block) = (String::new(), String::new());
|
||||
for y in lo[1]..=hi[1] {
|
||||
for z in lo[2]..=hi[2] {
|
||||
for x in lo[0]..=hi[0] {
|
||||
let packed = self
|
||||
.world
|
||||
.chunks
|
||||
.get(&(x >> 4, z >> 4))
|
||||
.filter(|_| (MIN_Y..MIN_Y + SECTIONS as i32 * 16).contains(&y))
|
||||
.map(|c| c.light(x & 15, y, z & 15));
|
||||
let digit = |v: u8| char::from_digit(u32::from(v), 16).unwrap_or('.');
|
||||
sky.push(packed.map_or('.', |v| digit(v >> 4)));
|
||||
block.push(packed.map_or('.', |v| digit(v & 15)));
|
||||
}
|
||||
}
|
||||
}
|
||||
ok(json!({ "from": lo, "to": hi, "sky": sky, "block": block }))
|
||||
}
|
||||
"find-block" => {
|
||||
self.need_world()?;
|
||||
let want = namespaced(a.get(0, "BLOCK")?);
|
||||
@@ -973,7 +1027,7 @@ impl Game<'_> {
|
||||
for z in c[2] - radius..=c[2] + radius {
|
||||
for x in c[0] - radius..=c[0] + radius {
|
||||
let state = self.world.block(x, y, z);
|
||||
if *self.res.facts.get(state).name == *want {
|
||||
if *self.res.facts().get(state).name == *want {
|
||||
let d = dist(eye, [x, y, z].map(|v| f64::from(v) + 0.5));
|
||||
found.push((d, [x, y, z]));
|
||||
}
|
||||
@@ -1181,7 +1235,7 @@ impl Game<'_> {
|
||||
self.playing()?;
|
||||
let pos = a.block_pos(0)?;
|
||||
let before = self.world.block(pos[0], pos[1], pos[2]);
|
||||
if self.res.facts.is_air(before) {
|
||||
if self.res.facts().is_air(before) {
|
||||
return Err(format!("there is no block at {pos:?}").into());
|
||||
}
|
||||
self.aim_block(pos, None)?;
|
||||
@@ -1210,24 +1264,24 @@ impl Game<'_> {
|
||||
.ok_or("nothing in hand to place; select an item")?;
|
||||
let held = held.item.clone();
|
||||
let before = self.world.block(pos[0], pos[1], pos[2]);
|
||||
if !self.res.facts.get(before).replaceable && !self.res.facts.is_air(before) {
|
||||
if !self.res.facts().get(before).replaceable && !self.res.facts().is_air(before) {
|
||||
return Err(format!(
|
||||
"{pos:?} holds {}; break it first",
|
||||
self.res.facts.get(before).name
|
||||
self.res.facts().get(before).name
|
||||
)
|
||||
.into());
|
||||
}
|
||||
// A replaceable block there (grass, snow) is clicked itself, as
|
||||
// a player would; otherwise the face of a neighbour touching it.
|
||||
let mut aimed = !self.res.facts.is_air(before)
|
||||
&& !self.res.facts.get(before).outline.is_empty()
|
||||
let mut aimed = !self.res.facts().is_air(before)
|
||||
&& !self.res.facts().get(before).outline.is_empty()
|
||||
&& self.aim_block(pos, None).is_ok();
|
||||
for (_, d) in FACES.iter().filter(|_| !aimed) {
|
||||
let d = *d;
|
||||
let support = add(pos, d);
|
||||
let state = self.world.block(support[0], support[1], support[2]);
|
||||
let f = self.res.facts.get(state);
|
||||
if self.res.facts.is_air(state)
|
||||
let f = self.res.facts().get(state);
|
||||
if self.res.facts().is_air(state)
|
||||
|| f.replaceable
|
||||
|| f.fluid != horizon_client::blocks::Fluid::None && !f.waterlogged
|
||||
{
|
||||
@@ -1494,6 +1548,13 @@ impl Game<'_> {
|
||||
return Err("command TEXT".into());
|
||||
}
|
||||
let command = format!("/{text}");
|
||||
// Single player's console is its server thread's.
|
||||
if let Some(server) = &self.integrated {
|
||||
let chat = server
|
||||
.call(move |g| g.owner_console_command(&command))
|
||||
.ok_or("the integrated server stopped")?;
|
||||
return ok(json!({ "ok": true, "chat": chat }));
|
||||
}
|
||||
if self.remote.is_some() {
|
||||
self.send_chat(&command);
|
||||
return ok(json!({ "ok": true }));
|
||||
@@ -1893,7 +1954,10 @@ impl Game<'_> {
|
||||
// Step up onto the next block, or out of water.
|
||||
let in_water = {
|
||||
let b = p.map(|v| v.floor() as i32);
|
||||
self.res.facts.get(self.world.block(b[0], b[1], b[2])).fluid
|
||||
self.res
|
||||
.facts()
|
||||
.get(self.world.block(b[0], b[1], b[2]))
|
||||
.fluid
|
||||
!= horizon_client::blocks::Fluid::None
|
||||
};
|
||||
if aim[1] > p[1] + 0.5 && horizontal(p, aim) < 1.6 && on_ground {
|
||||
|
||||
@@ -29,7 +29,11 @@ impl Game<'_> {
|
||||
continue;
|
||||
};
|
||||
let carried = self.mobs[i].extra.ints[1];
|
||||
let max = self.res.items.get(&held).map_or(64, |i| i.max_stack as i32);
|
||||
let max = self
|
||||
.res
|
||||
.items()
|
||||
.get(&held)
|
||||
.map_or(64, |i| i.max_stack as i32);
|
||||
// GoToWantedItem / wantsToPickUp: the same item within 32.
|
||||
let wanted = if griefing && carried < max && self.mobs[i].extra.ints[3] <= 0 {
|
||||
self.dropped
|
||||
|
||||
@@ -111,7 +111,12 @@ impl Game<'_> {
|
||||
let Some(item) = item else {
|
||||
continue;
|
||||
};
|
||||
let Some(asset) = self.res.items.get(item).and_then(|i| i.equip_asset.clone()) else {
|
||||
let Some(asset) = self
|
||||
.res
|
||||
.items()
|
||||
.get(item)
|
||||
.and_then(|i| i.equip_asset.clone())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let kind = if layer == "leggings" {
|
||||
@@ -124,7 +129,7 @@ impl Game<'_> {
|
||||
continue;
|
||||
};
|
||||
let (Some(r), Some(part)) = (
|
||||
self.atlas.sprites.get(texture.as_str()),
|
||||
self.gui.atlas.sprites.get(texture.as_str()),
|
||||
assets.player.get(layer),
|
||||
) else {
|
||||
continue;
|
||||
@@ -144,7 +149,7 @@ impl Game<'_> {
|
||||
// BlockPlaceContext: a replaceable clicked block is replaced.
|
||||
let clicked = self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(hit.pos[0], hit.pos[1], hit.pos[2]));
|
||||
let pos = if clicked.replaceable {
|
||||
hit.pos
|
||||
@@ -230,7 +235,7 @@ impl Game<'_> {
|
||||
fn equipment_slot(&self, stack: &ItemStack) -> usize {
|
||||
match self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.and_then(|i| i.equip_slot.as_deref())
|
||||
{
|
||||
@@ -379,7 +384,7 @@ impl Game<'_> {
|
||||
let mut dead = Vec::new();
|
||||
for (i, a) in self.armor_stands.iter_mut().enumerate() {
|
||||
a.tick(&mut scene);
|
||||
if !a.environment_tick(&self.world, &self.res.facts, self.pack.assets.registry) {
|
||||
if !a.environment_tick(&self.world, self.res.facts(), self.pack.assets.registry) {
|
||||
dead.push(i);
|
||||
}
|
||||
}
|
||||
@@ -403,7 +408,7 @@ impl Game<'_> {
|
||||
out: &mut Vec<Vertex>,
|
||||
) {
|
||||
let assets = &self.armor_stand_assets;
|
||||
let sprites = &self.atlas.sprites;
|
||||
let sprites = &self.gui.atlas.sprites;
|
||||
let uv_of = |name: &str| sprites.get(name).map(|r| [r.u0, r.v0, r.u1, r.v1]);
|
||||
let Some(wood) = uv_of("entity/armorstand/armorstand") else {
|
||||
return;
|
||||
@@ -413,6 +418,32 @@ impl Game<'_> {
|
||||
if a.invisible {
|
||||
continue;
|
||||
}
|
||||
// ArmorStand.shouldRenderAtSqrDistance: 256 times the box's mean
|
||||
// edge (4 for a marker's empty box), whatever the entity distance.
|
||||
// LivingEntityRenderer grows the culling box by 0.5 for a dragon head.
|
||||
let (width, height) = match (a.marker, a.small) {
|
||||
(true, _) => (0.0, 0.0),
|
||||
(false, true) => (0.25, 0.9875),
|
||||
(false, false) => (0.5, 1.975),
|
||||
};
|
||||
let edge = (width + height + width) / 3.0 * 4.0;
|
||||
let range = if edge == 0.0 { 4.0 } else { edge } * 64.0;
|
||||
let dragon = a.equipment[5]
|
||||
.as_ref()
|
||||
.is_some_and(|i| &*i.item == "minecraft:dragon_head");
|
||||
let position = super::entity_culling::at(a.position);
|
||||
if !self.standing_entity_in_view(
|
||||
camera,
|
||||
position,
|
||||
position,
|
||||
alpha,
|
||||
width,
|
||||
height,
|
||||
range,
|
||||
if dragon { 0.5 } else { 0.0 },
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
let Some(model) = (if a.small { &assets.small } else { &assets.main }) else {
|
||||
continue;
|
||||
};
|
||||
@@ -490,7 +521,7 @@ impl Game<'_> {
|
||||
};
|
||||
let Some(asset) = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.and_then(|i| i.equip_asset.clone())
|
||||
else {
|
||||
@@ -542,7 +573,7 @@ impl Game<'_> {
|
||||
/// `Equippable.swapWithEquipmentSlot`: right-clicking armor swaps it into
|
||||
/// its slot (the worn piece comes back to the hand).
|
||||
pub(super) fn equip_from_hand(&mut self, stack: &ItemStack) -> bool {
|
||||
let Some(info) = self.res.items.get(&stack.item) else {
|
||||
let Some(info) = self.res.items().get(&stack.item) else {
|
||||
return false;
|
||||
};
|
||||
let index = match info.equip_slot.as_deref() {
|
||||
@@ -673,7 +704,7 @@ impl Game<'_> {
|
||||
&serde_json::Value::Null,
|
||||
false,
|
||||
pose,
|
||||
&self.atlas.sprites,
|
||||
&self.gui.atlas.sprites,
|
||||
&self.item_host(),
|
||||
&mut sink,
|
||||
);
|
||||
@@ -683,7 +714,7 @@ impl Game<'_> {
|
||||
if let Some(stack) = &a.equipment[5]
|
||||
&& self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.is_none_or(|i| i.equip_asset.is_none())
|
||||
&& let Some(head) = part_matrix(model, base, poses, "head", 0.0)
|
||||
|
||||
@@ -71,8 +71,10 @@ impl Game<'_> {
|
||||
}
|
||||
/// Called every frame while the title is up.
|
||||
pub(super) fn update_backdrop(&mut self) -> Result<()> {
|
||||
let wanted = self.title.is_some()
|
||||
let wanted = self.pending_entry.is_none()
|
||||
&& self.title.is_some()
|
||||
&& horizon_client::ui_theme::horizon()
|
||||
&& self.world_renderer_ready
|
||||
&& self.renderer.is_some()
|
||||
&& self.options.frames.is_none();
|
||||
if !wanted {
|
||||
@@ -127,6 +129,10 @@ impl Game<'_> {
|
||||
.is_some_and(|r| r.section_count() > 40)
|
||||
{
|
||||
self.backdrop.ready = Some(Instant::now());
|
||||
log::info!(
|
||||
"Horizon: title backdrop ready; world rest ready: {}",
|
||||
self.res.rest.get().is_some()
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -139,10 +145,14 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
fn surface_y(&self, x: i32, z: i32) -> Option<i32> {
|
||||
let air = self.res.facts.air;
|
||||
let air = self.res.facts().air;
|
||||
(-60..320).rev().find(|&y| self.world.block(x, y, z) != air)
|
||||
}
|
||||
fn start_backdrop(&mut self) -> Result<()> {
|
||||
log::info!(
|
||||
"Horizon: starting title backdrop after {} ms",
|
||||
self.started.elapsed().as_millis()
|
||||
);
|
||||
let seed = seed();
|
||||
let root = std::env::current_dir()?
|
||||
.join("saves")
|
||||
@@ -155,7 +165,7 @@ impl Game<'_> {
|
||||
VanillaTerrain::new(
|
||||
&self.options.resources.join("worldgen"),
|
||||
pack.assets.registry,
|
||||
&res.biomes,
|
||||
res.biomes(),
|
||||
seed,
|
||||
)
|
||||
.map_err(|e| format!("title backdrop: {e}"))?,
|
||||
@@ -165,10 +175,10 @@ impl Game<'_> {
|
||||
inner: inner.clone(),
|
||||
save: save.clone(),
|
||||
registry: pack.assets.clone(),
|
||||
biomes: res.biomes.clone(),
|
||||
biomes: res.biomes().clone(),
|
||||
}),
|
||||
pack.context.clone(),
|
||||
res.threads.min(6),
|
||||
res.threads().min(6),
|
||||
);
|
||||
streaming.radius = self.settings.render_distance.clamp(4, 10);
|
||||
streaming.biome_blend = self.settings.biome_blend;
|
||||
@@ -179,7 +189,7 @@ impl Game<'_> {
|
||||
streaming.paused = true;
|
||||
self.streaming = streaming;
|
||||
self.save = save;
|
||||
let mut world = World::new(self.res.facts.air, seed);
|
||||
let mut world = World::new(self.res.facts().air, seed);
|
||||
world.day_time = DAY_TIME;
|
||||
world.game_time = 6000;
|
||||
// Light snow: the weather renders as snow in frozen biomes.
|
||||
@@ -237,7 +247,7 @@ impl Game<'_> {
|
||||
}
|
||||
fn stop_backdrop(&mut self) {
|
||||
self.streaming.paused = true;
|
||||
self.world = World::new(self.res.facts.air, 0);
|
||||
self.world = World::new(self.res.facts().air, 0);
|
||||
if let Some(r) = self.renderer.as_mut() {
|
||||
r.clear_sections();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ impl Game<'_> {
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
layer_textures(&self.res.stations.banners, &b.layers)
|
||||
layer_textures(&self.res.stations().banners, &b.layers)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,30 +99,16 @@ impl Game<'_> {
|
||||
}
|
||||
/// `getHeight(WORLD_SURFACE)`: above the highest non-air block.
|
||||
pub(super) fn world_surface(&self, x: i32, z: i32) -> i32 {
|
||||
let (min, max) = (super::MIN_Y, super::MIN_Y + super::HEIGHT);
|
||||
(min..max)
|
||||
.rev()
|
||||
.find(|&y| !self.res.facts.is_air(self.world.block(x, y, z)))
|
||||
.map_or(min, |y| y + 1)
|
||||
self.world
|
||||
.world_surface(x, z, |id| self.res.facts().is_air(id))
|
||||
}
|
||||
/// `BeaconBlockEntity.tick` for every beacon.
|
||||
pub(super) fn tick_beacons(&mut self) {
|
||||
let keys: Vec<(i32, i32, i32)> = self
|
||||
.world
|
||||
.block_entities
|
||||
.iter()
|
||||
.filter(|(_, e)| matches!(e, BlockEntity::Beacon(_)))
|
||||
.map(|(k, _)| *k)
|
||||
.collect();
|
||||
for key in keys {
|
||||
let Some(BlockEntity::Beacon(mut b)) = self.world.block_entities.remove(&key) else {
|
||||
continue;
|
||||
};
|
||||
self.tick_beacon(key, &mut b);
|
||||
self.world
|
||||
.block_entities
|
||||
.insert(key, BlockEntity::Beacon(b));
|
||||
}
|
||||
/// `BeaconBlockEntity.tick` of the beacon at `key`.
|
||||
pub(super) fn tick_beacon_at(&mut self, key: (i32, i32, i32)) {
|
||||
let Some(BlockEntity::Beacon(mut b)) = self.world.block_entities.take(&key) else {
|
||||
return;
|
||||
};
|
||||
self.tick_beacon(key, &mut b);
|
||||
self.world.block_entities.put(key, BlockEntity::Beacon(b));
|
||||
}
|
||||
fn tick_beacon(&mut self, (x, y, z): (i32, i32, i32), b: &mut Beacon) {
|
||||
let mut check = if b.last_check_y < y {
|
||||
@@ -136,7 +122,7 @@ impl Game<'_> {
|
||||
let mut i = 0;
|
||||
while i < 10 && check <= surface {
|
||||
let state = self.world.block(x, check, z);
|
||||
let f = self.res.facts.get(state);
|
||||
let f = self.res.facts().get(state);
|
||||
if let Some(color) = self.beam_color(&f.name) {
|
||||
if b.checking.len() <= 1 {
|
||||
b.checking.push((color, 1));
|
||||
@@ -197,7 +183,7 @@ impl Game<'_> {
|
||||
fn beacon_base(&self, x: i32, y: i32, z: i32) -> i32 {
|
||||
let base = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get("minecraft:beacon_base_blocks");
|
||||
let mut levels = 0;
|
||||
@@ -208,7 +194,7 @@ impl Game<'_> {
|
||||
}
|
||||
let ok = (x - step..=x + step).all(|lx| {
|
||||
(z - step..=z + step).all(|lz| {
|
||||
let name = &self.res.facts.get(self.world.block(lx, ly, lz)).name;
|
||||
let name = &self.res.facts().get(self.world.block(lx, ly, lz)).name;
|
||||
base.is_some_and(|t| t.contains(&**name))
|
||||
})
|
||||
});
|
||||
@@ -389,7 +375,7 @@ impl Game<'_> {
|
||||
let levels = self.beacon_levels();
|
||||
let sel = self.station.as_ref().map_or([None; 2], |s| s.beacon);
|
||||
let paid = self.station.as_ref().is_some_and(|s| s.inputs[0].is_some());
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
batch.fill(
|
||||
atlas,
|
||||
0.0,
|
||||
@@ -410,7 +396,7 @@ impl Game<'_> {
|
||||
("block.minecraft.beacon.secondary", "Secondary Power", 169.0),
|
||||
] {
|
||||
let text = self.translate(key, fallback);
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let w = HudBatch::text_width(atlas, &text);
|
||||
batch.text(
|
||||
atlas,
|
||||
@@ -425,7 +411,7 @@ impl Game<'_> {
|
||||
let x = [20.0, 41.0, 63.0, 86.0, 108.0][i];
|
||||
self.draw_item(batch, &ItemStack::new(item, 1), bx + x, by + 109.0);
|
||||
}
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let mut tooltip = None;
|
||||
let button =
|
||||
|batch: &mut HudBatch, x: f32, y: f32, active: bool, selected: bool, icon: &str| {
|
||||
@@ -507,7 +493,7 @@ impl Game<'_> {
|
||||
if let Some(slot) = self.slot_at(batch, self.cursor.0, self.cursor.1) {
|
||||
let (sx, sy) = self.slot_position(slot);
|
||||
batch.fill(
|
||||
&self.atlas,
|
||||
&self.gui.atlas,
|
||||
ox + sx,
|
||||
oy + sy,
|
||||
16.0,
|
||||
@@ -528,7 +514,13 @@ impl Game<'_> {
|
||||
}
|
||||
/// `BeaconRenderer`: each section's rotating solid beam and its glow.
|
||||
pub(super) fn beacon_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec<Vertex>) {
|
||||
let Some(s) = self.atlas.sprites.get("entity/beacon/beacon_beam").copied() else {
|
||||
let Some(s) = self
|
||||
.gui
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/beacon/beacon_beam")
|
||||
.copied()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let time = (self.world.game_time.rem_euclid(40)) as f32 + alpha as f32;
|
||||
|
||||
@@ -41,7 +41,7 @@ impl HiveHost for GameHive<'_, '_> {
|
||||
if !self
|
||||
.game
|
||||
.res
|
||||
.mob_data
|
||||
.mob_data()
|
||||
.entity_has("minecraft:beehive_inhabitors", &kind)
|
||||
{
|
||||
return None;
|
||||
@@ -72,10 +72,10 @@ impl Game<'_> {
|
||||
/// The hive's honey level and front, from its block state.
|
||||
pub(super) fn hive_state(&self, at: [i32; 3]) -> Option<(Option<i32>, [i32; 2])> {
|
||||
let state = self.world.block(at[0], at[1], at[2]);
|
||||
let name = &self.res.facts.get(state).name;
|
||||
let name = &self.res.facts().get(state).name;
|
||||
if !self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get("minecraft:beehives")
|
||||
.is_some_and(|t| t.contains(&**name))
|
||||
@@ -87,48 +87,37 @@ impl Game<'_> {
|
||||
let facing = beehive::facing_step(props.get("facing").map(String::as_str));
|
||||
Some((honey, facing))
|
||||
}
|
||||
/// `BeehiveBlockEntity.serverTick` for every hive, after an emergency
|
||||
/// exit for those with fire beside them (`BeehiveBlock.updateShape`).
|
||||
pub(super) fn tick_beehives(&mut self) {
|
||||
let mut keys: Vec<(i32, i32, i32)> = self
|
||||
.world
|
||||
.block_entities
|
||||
.iter()
|
||||
.filter(|(_, e)| matches!(e, BlockEntity::Beehive(_)))
|
||||
.map(|(k, _)| *k)
|
||||
.collect();
|
||||
keys.sort_unstable();
|
||||
for key in keys {
|
||||
let at = [key.0, key.1, key.2];
|
||||
let Some((honey, facing)) = self.hive_state(at) else {
|
||||
continue;
|
||||
};
|
||||
let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.remove(&key)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let fire = [
|
||||
[1, 0, 0],
|
||||
[-1, 0, 0],
|
||||
[0, 1, 0],
|
||||
[0, -1, 0],
|
||||
[0, 0, 1],
|
||||
[0, 0, -1],
|
||||
]
|
||||
.iter()
|
||||
.any(|d| {
|
||||
let state = self.world.block(at[0] + d[0], at[1] + d[1], at[2] + d[2]);
|
||||
&*self.res.facts.get(state).name == "minecraft:fire"
|
||||
});
|
||||
let mut host = GameHive { game: self };
|
||||
if fire && !hive.bees.is_empty() {
|
||||
hive.release_all(at, facing, honey, Release::Emergency, &mut host);
|
||||
}
|
||||
hive.server_tick(at, facing, honey, &mut host);
|
||||
self.world
|
||||
.block_entities
|
||||
.insert(key, BlockEntity::Beehive(hive));
|
||||
/// `BeehiveBlockEntity.serverTick` of the hive at `key`, after an
|
||||
/// emergency exit if fire is beside it (`BeehiveBlock.updateShape`).
|
||||
pub(super) fn tick_beehive(&mut self, key: (i32, i32, i32)) {
|
||||
let at = [key.0, key.1, key.2];
|
||||
let Some((honey, facing)) = self.hive_state(at) else {
|
||||
return;
|
||||
};
|
||||
let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.take(&key) else {
|
||||
return;
|
||||
};
|
||||
let fire = [
|
||||
[1, 0, 0],
|
||||
[-1, 0, 0],
|
||||
[0, 1, 0],
|
||||
[0, -1, 0],
|
||||
[0, 0, 1],
|
||||
[0, 0, -1],
|
||||
]
|
||||
.iter()
|
||||
.any(|d| {
|
||||
let state = self.world.block(at[0] + d[0], at[1] + d[1], at[2] + d[2]);
|
||||
&*self.res.facts().get(state).name == "minecraft:fire"
|
||||
});
|
||||
let mut host = GameHive { game: self };
|
||||
if fire && !hive.bees.is_empty() {
|
||||
hive.release_all(at, facing, honey, Release::Emergency, &mut host);
|
||||
}
|
||||
hive.server_tick(at, facing, honey, &mut host);
|
||||
self.world
|
||||
.block_entities
|
||||
.put(key, BlockEntity::Beehive(hive));
|
||||
}
|
||||
/// `BeehiveBlockEntity.addOccupant` for a bee its `BeeEnterHiveGoal`
|
||||
/// sent in: off its lead, its tag stored, the bee gone.
|
||||
@@ -152,13 +141,13 @@ impl Game<'_> {
|
||||
self.mobs[i].extra.mount = None;
|
||||
let tag = self.mob_tree_nbt(i);
|
||||
let flower = bee::get(&self.mobs[i]).and_then(|b| b.flower);
|
||||
let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.remove(&key) else {
|
||||
let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.take(&key) else {
|
||||
return;
|
||||
};
|
||||
let stored = hive.add_occupant(at, tag, flower, &mut GameHive { game: self });
|
||||
self.world
|
||||
.block_entities
|
||||
.insert(key, BlockEntity::Beehive(hive));
|
||||
.put(key, BlockEntity::Beehive(hive));
|
||||
if stored && let Some(m) = self.mobs.iter_mut().find(|m| m.id == mob) {
|
||||
m.removed = true;
|
||||
}
|
||||
@@ -166,13 +155,13 @@ impl Game<'_> {
|
||||
/// `BeehiveBlockEntity.emptyAllLivingFromHive` with no player about.
|
||||
pub(super) fn empty_hive(&mut self, at: [i32; 3], facing: [i32; 2], status: Release) {
|
||||
let key = (at[0], at[1], at[2]);
|
||||
let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.remove(&key) else {
|
||||
let Some(BlockEntity::Beehive(mut hive)) = self.world.block_entities.take(&key) else {
|
||||
return;
|
||||
};
|
||||
hive.release_all(at, facing, None, status, &mut GameHive { game: self });
|
||||
self.world
|
||||
.block_entities
|
||||
.insert(key, BlockEntity::Beehive(hive));
|
||||
.put(key, BlockEntity::Beehive(hive));
|
||||
}
|
||||
/// `BeehiveBlock.playerDestroy` without silk touch: the bees come out
|
||||
/// angry at the player unless smoke calms them, then
|
||||
|
||||
@@ -13,7 +13,6 @@ use horizon_client::{
|
||||
};
|
||||
use horizon_core::geometry::{Aabb, Vec3};
|
||||
use horizon_world::nbt::Tag;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// The handle of the local player among a bell's gathered entities.
|
||||
const PLAYER: u64 = u64::MAX;
|
||||
@@ -174,18 +173,27 @@ impl Game<'_> {
|
||||
let Some(r) = &self.renderer else {
|
||||
return;
|
||||
};
|
||||
let present: HashMap<[i32; 3], Ticker> = r
|
||||
.block_entities()
|
||||
.filter_map(|(p, s)| Some((*p, self.be_anims.ticker(*s)?)))
|
||||
.collect();
|
||||
self.be_anims.retain_present(&present);
|
||||
// Sorted by position: the order they tick in, and a quick lookup.
|
||||
// Read again only when the drawn block entities changed.
|
||||
let revision = r.block_entity_revision();
|
||||
if self.be_anims.present_revision != Some(revision) {
|
||||
let mut present: Vec<([i32; 3], Ticker)> = r
|
||||
.block_entities()
|
||||
.filter_map(|(p, s)| Some((*p, self.be_anims.ticker(*s)?)))
|
||||
.collect();
|
||||
present.sort_unstable_by_key(|(p, _)| *p);
|
||||
self.be_anims.retain_present(&present);
|
||||
self.be_anims.present = present;
|
||||
self.be_anims.present_revision = Some(revision);
|
||||
}
|
||||
let positions = std::mem::take(&mut self.be_anims.present);
|
||||
let players: Vec<[f64; 3]> = match &self.player {
|
||||
Some(p) if !self.spectator() => vec![[p.position.x, p.position.y, p.position.z]],
|
||||
_ => Vec::new(),
|
||||
};
|
||||
let raiders = self
|
||||
.res
|
||||
.stations
|
||||
.stations()
|
||||
.enchantments
|
||||
.entity_tags
|
||||
.get("minecraft:raiders")
|
||||
@@ -193,14 +201,12 @@ impl Game<'_> {
|
||||
.unwrap_or_default();
|
||||
let frames = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get("minecraft:conduit_effect_block")
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let mut positions: Vec<([i32; 3], Ticker)> = present.into_iter().collect();
|
||||
positions.sort_unstable_by_key(|(p, _)| *p);
|
||||
for (pos, ticker) in positions {
|
||||
for &(pos, ticker) in &positions {
|
||||
match ticker {
|
||||
Ticker::Lid => self.be_anims.chests.entry(pos).or_default().tick(),
|
||||
Ticker::Book => {
|
||||
@@ -279,7 +285,7 @@ impl Game<'_> {
|
||||
}
|
||||
Ticker::Conduit => {
|
||||
let world = &self.world;
|
||||
let facts = &self.res.facts;
|
||||
let facts = self.res.facts();
|
||||
let registry = self.pack.assets.registry;
|
||||
let is_water = |p: [i32; 3]| {
|
||||
facts.get(world.block(p[0], p[1], p[2])).fluid
|
||||
@@ -322,6 +328,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.be_anims.present = positions;
|
||||
}
|
||||
/// `EndGatewayBlock.entityInside` on the server: whether the gateway at
|
||||
/// `pos` let the entity in (`triggerCooldown`, with its block event).
|
||||
@@ -365,7 +372,7 @@ impl Game<'_> {
|
||||
/// pot's saved `sherds` (back, left, right, front).
|
||||
pub(super) fn block_anim(&self, pos: [i32; 3], partial: f32) -> BlockAnim {
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
let sherds = if &*self.res.facts.get(state).name == "minecraft:decorated_pot" {
|
||||
let sherds = if &*self.res.facts().get(state).name == "minecraft:decorated_pot" {
|
||||
let sherds = self.saved_tag(pos).and_then(|t| t.get("sherds"));
|
||||
["back", "left", "right", "front"].map(|side| match sherds.and_then(|s| s.get(side)) {
|
||||
// An item id, or the item stack the processed templates hold.
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
//! `Level.tickBlockEntities` for the block entities ticked together here
|
||||
//! (hoppers, crafters, jukeboxes, beacons, creaking hearts, spawners, trial
|
||||
//! spawners, vaults, beehives and furnaces): only those whose state has a
|
||||
//! ticker, in vanilla's list order (`horizon_client::block_entities`), in
|
||||
//! chunks that tick blocks. Sculk, brewing stands and pistons tick in their
|
||||
//! own passes.
|
||||
use super::Game;
|
||||
use horizon_client::{
|
||||
Result,
|
||||
block_entities::{Pos, Ticking},
|
||||
containers::{BlockEntity, FurnaceKind, HOPPER_SLOTS},
|
||||
};
|
||||
use horizon_world::registry::BlockStateId;
|
||||
|
||||
impl Game<'_> {
|
||||
pub(super) fn tick_block_entities(&mut self) -> Result<()> {
|
||||
self.tick_mount_menu();
|
||||
self.load_entity_types();
|
||||
if !self.world.block_entities.has_states() {
|
||||
let states = self.ticking_states();
|
||||
self.world.block_entities.set_states(states);
|
||||
}
|
||||
self.forget_gone_hoppers();
|
||||
let ticking = self.block_ticking_area();
|
||||
let mut spawners = Vec::new();
|
||||
let mut trial_spawners = Vec::new();
|
||||
for slot in self.world.block_entity_tickers() {
|
||||
let pos = slot.0;
|
||||
// Ticks before this one can remove it (`TickingBlockEntity.isRemoved`).
|
||||
if !self.world.block_entities.is_live(slot)
|
||||
|| !ticking(pos.0, pos.2)
|
||||
|| !self.border.contains(f64::from(pos.0), f64::from(pos.2))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
match self.world.block_entities.get(&pos) {
|
||||
Some(BlockEntity::Chest(items)) if items.len() == HOPPER_SLOTS => {
|
||||
self.tick_hopper(pos)
|
||||
}
|
||||
Some(BlockEntity::Crafter(_)) => self.tick_crafter(pos),
|
||||
Some(BlockEntity::Jukebox(_)) => self.tick_jukebox(pos),
|
||||
Some(BlockEntity::Beacon(_)) => self.tick_beacon_at(pos),
|
||||
Some(BlockEntity::CreakingHeart(_)) => self.tick_creaking_heart(pos)?,
|
||||
Some(BlockEntity::Spawner(_)) => {
|
||||
self.tick_spawner(pos)?;
|
||||
spawners.push(pos);
|
||||
}
|
||||
Some(BlockEntity::TrialSpawner(_)) => {
|
||||
self.tick_trial_spawner(pos)?;
|
||||
trial_spawners.push(pos);
|
||||
}
|
||||
Some(BlockEntity::Vault(_)) => self.tick_vault(pos)?,
|
||||
Some(BlockEntity::Beehive(_)) => self.tick_beehive(pos),
|
||||
Some(BlockEntity::Furnace(_)) => self.tick_furnace(pos)?,
|
||||
Some(BlockEntity::Brewing(_)) => self.tick_brewing_stand(pos)?,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
self.update_song_volumes();
|
||||
self.scan_for_hearts();
|
||||
// The client ticks (particles, sounds, the turning mob) are for a
|
||||
// window; a dedicated or integrated server has none.
|
||||
if self.options.dedicated.is_none() {
|
||||
self.client_tick_spawners(&spawners);
|
||||
for key in trial_spawners {
|
||||
self.client_tick_trial_spawner(key);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/// `BlockState.getTicker` of every state, for the block entities ticked
|
||||
/// here. A creaking heart keeps its slot while uprooted (see
|
||||
/// `tick_creaking_heart`).
|
||||
fn ticking_states(&self) -> Vec<Ticking> {
|
||||
let registry = self.pack.assets.registry;
|
||||
(0..registry.len())
|
||||
.map(|i| {
|
||||
let state = BlockStateId(i as u32);
|
||||
let name: &str = &self.res.facts().get(state).name;
|
||||
match name {
|
||||
"minecraft:hopper"
|
||||
| "minecraft:crafter"
|
||||
| "minecraft:beacon"
|
||||
| "minecraft:creaking_heart"
|
||||
| "minecraft:spawner"
|
||||
| "minecraft:trial_spawner"
|
||||
| "minecraft:vault"
|
||||
| "minecraft:beehive"
|
||||
| "minecraft:bee_nest"
|
||||
| "minecraft:brewing_stand" => Ticking::Yes,
|
||||
"minecraft:jukebox" => {
|
||||
let record = registry
|
||||
.state(state)
|
||||
.and_then(|s| s.properties.get("has_record"))
|
||||
.is_some_and(|v| v == "true");
|
||||
if record { Ticking::Yes } else { Ticking::Idle }
|
||||
}
|
||||
n if FurnaceKind::from_block(n).is_some() => Ticking::Yes,
|
||||
_ => Ticking::No,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
/// `ServerLevel.shouldTickBlocksAt` in a block-ticking chunk
|
||||
/// (`LevelChunk.isTicking`, block coordinates), from every player's
|
||||
/// tickets (`update_chunk_tickets`).
|
||||
fn block_ticking_area(&self) -> impl Fn(i32, i32) -> bool + use<> {
|
||||
let levels = self.tickets.levels();
|
||||
move |x, z| levels.block_ticking_at(x, z)
|
||||
}
|
||||
/// `AbstractFurnaceBlockEntity.serverTick` of the furnace at `pos`, and
|
||||
/// its block's `lit` following it.
|
||||
fn tick_furnace(&mut self, pos: Pos) -> Result<()> {
|
||||
let Some(BlockEntity::Furnace(f)) = self.world.block_entities.get_mut(&pos) else {
|
||||
return Ok(());
|
||||
};
|
||||
let Some(lit) = f.tick(self.res.recipes(), self.res.items(), self.res.providers()) else {
|
||||
return Ok(());
|
||||
};
|
||||
let state = self.world.block(pos.0, pos.1, pos.2);
|
||||
if let Some(mut s) = self.pack.assets.registry.state(state).cloned()
|
||||
&& s.properties.contains_key("lit")
|
||||
{
|
||||
s.properties.insert("lit".into(), lit.to_string());
|
||||
if let Ok(id) = self.pack.assets.registry.resolve(&s) {
|
||||
self.world.set(pos.0, pos.1, pos.2, id)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ impl Game<'_> {
|
||||
let entity = self.world.block_entities.get(&key)?;
|
||||
let block = &self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(key.0, key.1, key.2))
|
||||
.name;
|
||||
let mut tag = save::encode_block_entity(key, entity, block);
|
||||
@@ -37,7 +37,7 @@ impl Game<'_> {
|
||||
pub(super) fn picked_stack(&self, pos: [i32; 3], include_data: bool) -> Option<ItemStack> {
|
||||
let key = (pos[0], pos[1], pos[2]);
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
let facts = self.res.facts.get(state);
|
||||
let facts = self.res.facts().get(state);
|
||||
if &*facts.item == "minecraft:air" {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ impl Game<'_> {
|
||||
format!("{}[{}]", s.name, props.join(","))
|
||||
}
|
||||
fn put_block(&mut self, pos: [i32; 3], state: BlockStateId) -> Result<()> {
|
||||
let name = self.res.facts.get(state).name.clone();
|
||||
let name = self.res.facts().get(state).name.clone();
|
||||
self.world.block_entities.remove(&(pos[0], pos[1], pos[2]));
|
||||
self.level_set(pos, state)?;
|
||||
if let Some(entity) = BlockEntity::for_block(&name) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! paddling controls, collisions, riding (`positionRider`, `clampRotation`,
|
||||
//! dismounting), `BoatItem` placement, `VehicleEntity.hurtServer` breaking,
|
||||
//! saving and `AbstractBoatRenderer` with animated paddles.
|
||||
use super::{Game, Keys, view_vector};
|
||||
use super::{Game, Keys, entity_culling::at, view_vector};
|
||||
use horizon_client::{
|
||||
blocks::Fluid,
|
||||
collisions::SceneCollisions,
|
||||
@@ -180,11 +180,11 @@ impl BoatModels {
|
||||
}
|
||||
impl Game<'_> {
|
||||
fn fluid_height(&self, x: i32, y: i32, z: i32) -> Option<(f32, bool)> {
|
||||
let f = self.res.facts.get(self.world.block(x, y, z));
|
||||
let f = self.res.facts().get(self.world.block(x, y, z));
|
||||
if f.fluid != Fluid::Water {
|
||||
return None;
|
||||
}
|
||||
let above = self.res.facts.get(self.world.block(x, y + 1, z));
|
||||
let above = self.res.facts().get(self.world.block(x, y + 1, z));
|
||||
// FluidState.getHeight: 1 under the same fluid, else amount / 9.
|
||||
let height = if above.fluid == Fluid::Water {
|
||||
1.0
|
||||
@@ -277,7 +277,7 @@ impl Game<'_> {
|
||||
&& f64::from(x + 1) > lo.x
|
||||
&& f64::from(z) < hi.z
|
||||
&& f64::from(z + 1) > lo.z;
|
||||
let f = self.res.facts.get(self.world.block(x, y0, z));
|
||||
let f = self.res.facts().get(self.world.block(x, y0, z));
|
||||
if inside && (f.full_collision || f.legacy_solid) && !f.has_class("LilyPadBlock") {
|
||||
friction += f.friction;
|
||||
count += 1;
|
||||
@@ -495,8 +495,8 @@ impl Game<'_> {
|
||||
);
|
||||
let top = b.bounds().max_position().y;
|
||||
let (bx, by, bz) = (x.floor() as i32, top.floor() as i32, z.floor() as i32);
|
||||
let below = self.res.facts.get(self.world.block(bx, by - 1, bz));
|
||||
let here = self.res.facts.get(self.world.block(bx, by, bz));
|
||||
let below = self.res.facts().get(self.world.block(bx, by - 1, bz));
|
||||
let here = self.res.facts().get(self.world.block(bx, by, bz));
|
||||
let target = if below.fluid != Fluid::Water
|
||||
&& !here.full_collision
|
||||
&& (below.full_collision || below.legacy_solid)
|
||||
@@ -700,8 +700,19 @@ impl Game<'_> {
|
||||
/// AbstractBoatRenderer.
|
||||
pub(super) fn boat_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec<Vertex>) {
|
||||
let a = alpha as f32;
|
||||
let range = super::entity_culling::default_range(
|
||||
glam::DVec3::new(WIDTH, HEIGHT, WIDTH),
|
||||
self.settings.entity_distance,
|
||||
);
|
||||
for b in &self.boats {
|
||||
let entity_start = out.len();
|
||||
// EntityRenderer.shouldRender.
|
||||
let (previous, position) = (at(b.previous), at(b.position));
|
||||
if !self.standing_entity_in_view(
|
||||
camera, previous, position, alpha, WIDTH, HEIGHT, range, 0.0,
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
let models = if b.chest {
|
||||
&self.boat_models.chest_models
|
||||
} else {
|
||||
@@ -712,6 +723,7 @@ impl Game<'_> {
|
||||
};
|
||||
let folder = if b.chest { "chest_boat" } else { "boat" };
|
||||
let Some(uv) = self
|
||||
.gui
|
||||
.atlas
|
||||
.sprites
|
||||
.get(&format!("entity/{folder}/{}", b.wood))
|
||||
|
||||
@@ -45,7 +45,7 @@ pub(super) enum BookScreen {
|
||||
}
|
||||
impl Game<'_> {
|
||||
fn book_lines(&self, page: &str) -> Vec<Text> {
|
||||
self.atlas.font.split(&Text::literal(page), 114.0)
|
||||
self.gui.atlas.font.split(&Text::literal(page), 114.0)
|
||||
}
|
||||
/// `WritableBookItem.use` / `WrittenBookItem.use`.
|
||||
pub(super) fn use_book(&mut self, stack: &ItemStack) -> bool {
|
||||
@@ -242,7 +242,7 @@ impl Game<'_> {
|
||||
/// the page (`MultilineTextField.insertText`: line breaks kept, cut to
|
||||
/// the 1024 characters left, rejected when it overflows the 14 lines).
|
||||
fn book_shortcut(&mut self, shortcut: horizon_client::clipboard::EditShortcut) {
|
||||
let font = &self.atlas.font;
|
||||
let font = &self.gui.atlas.font;
|
||||
match self.book.as_mut() {
|
||||
Some(BookScreen::Edit {
|
||||
signing: true,
|
||||
@@ -397,7 +397,7 @@ impl Game<'_> {
|
||||
let key = (pos[0], pos[1], pos[2]);
|
||||
if &*self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(pos[0], pos[1], pos[2]))
|
||||
.name
|
||||
!= "minecraft:lectern"
|
||||
@@ -549,7 +549,7 @@ impl Game<'_> {
|
||||
}
|
||||
pub(super) fn draw_book(&self, batch: &mut HudBatch) {
|
||||
let Some(book) = &self.book else { return };
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let (w, h) = (batch.width, batch.height);
|
||||
let (mx, my) = self.cursor;
|
||||
let hover =
|
||||
|
||||
@@ -40,7 +40,7 @@ impl Game<'_> {
|
||||
m.position.z.floor() as i32,
|
||||
);
|
||||
let mut state = self.world.block(x, y, z);
|
||||
if self.res.facts.is_air(state) {
|
||||
if self.res.facts().is_air(state) {
|
||||
state = self.world.block(x, (m.position.y - 0.2).floor() as i32, z);
|
||||
}
|
||||
let Some((sprite, tint)) = self.particle_sprite(state) else {
|
||||
|
||||
@@ -89,17 +89,17 @@ impl Game<'_> {
|
||||
if is_locked {
|
||||
locked = true;
|
||||
if scaling || locking {
|
||||
batch.sprite(&self.atlas, error, ox + 35.0, oy + 31.0);
|
||||
batch.sprite(&self.gui.atlas, error, ox + 35.0, oy + 31.0);
|
||||
}
|
||||
}
|
||||
if scaling && scale >= 4 {
|
||||
locked = true;
|
||||
batch.sprite(&self.atlas, error, ox + 35.0, oy + 31.0);
|
||||
batch.sprite(&self.gui.atlas, error, ox + 35.0, oy + 31.0);
|
||||
}
|
||||
}
|
||||
let sprite = |batch: &mut HudBatch, game: &Self, name: &str, x: f32, y: f32| {
|
||||
batch.sprite(
|
||||
&game.atlas,
|
||||
&game.gui.atlas,
|
||||
&format!("gui/sprites/container/cartography_table/{name}"),
|
||||
ox + x,
|
||||
oy + y,
|
||||
|
||||
@@ -219,12 +219,18 @@ impl Game<'_> {
|
||||
.map(|a| format!("minecraft:{a}"))
|
||||
.collect();
|
||||
let reg = &mut self.ui.registries;
|
||||
let mut items: Vec<String> = self.res.items.order.iter().map(|s| s.to_string()).collect();
|
||||
let mut items: Vec<String> = self
|
||||
.res
|
||||
.items()
|
||||
.order
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
items.sort();
|
||||
reg.items = items;
|
||||
reg.item_tags = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.item_tags
|
||||
.keys()
|
||||
.map(|k| horizon_client::command::args::normalize(k))
|
||||
@@ -232,7 +238,7 @@ impl Game<'_> {
|
||||
reg.item_tags.sort();
|
||||
reg.block_tags = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.keys()
|
||||
.map(|k| horizon_client::command::args::normalize(k))
|
||||
@@ -259,7 +265,7 @@ impl Game<'_> {
|
||||
.collect();
|
||||
let mut summonable: Vec<String> = self
|
||||
.res
|
||||
.mob_types
|
||||
.mob_types()
|
||||
.keys()
|
||||
.map(|k| horizon_client::command::args::normalize(k))
|
||||
.collect();
|
||||
@@ -405,7 +411,7 @@ impl Game<'_> {
|
||||
.as_ref()
|
||||
.map_or([1280, 720], |r| [r.config.width, r.config.height]);
|
||||
let b = HudBatch::new(size);
|
||||
let m = Measure(&self.atlas.font);
|
||||
let m = Measure(&self.gui.atlas.font);
|
||||
let c = Commands {
|
||||
dispatcher: chat_tree(&self.remote, &self.mods),
|
||||
registries: &self.ui.registries,
|
||||
@@ -450,7 +456,7 @@ impl Game<'_> {
|
||||
let focused = self.screen == Screen::Chat;
|
||||
let heard = self.mods.mods.is_running().then(|| text.plain());
|
||||
self.ui.chat.add(
|
||||
&self.atlas,
|
||||
&self.gui.atlas,
|
||||
text,
|
||||
Some(SYSTEM_INDICATOR),
|
||||
self.ticks,
|
||||
@@ -463,7 +469,7 @@ impl Game<'_> {
|
||||
/// Keys while the chat screen is open.
|
||||
pub(super) fn chat_key(&mut self, event: &KeyEvent) {
|
||||
if let Some(shortcut) = self.edit_shortcut(event) {
|
||||
let m = Measure(&self.atlas.font);
|
||||
let m = Measure(&self.gui.atlas.font);
|
||||
let c = Commands {
|
||||
dispatcher: chat_tree(&self.remote, &self.mods),
|
||||
registries: &self.ui.registries,
|
||||
@@ -509,7 +515,7 @@ impl Game<'_> {
|
||||
let Some(mut screen) = self.ui.chat_screen.take() else {
|
||||
return;
|
||||
};
|
||||
let m = Measure(&self.atlas.font);
|
||||
let m = Measure(&self.gui.atlas.font);
|
||||
let c = Commands {
|
||||
dispatcher: chat_tree(&self.remote, &self.mods),
|
||||
registries: &self.ui.registries,
|
||||
@@ -533,9 +539,26 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The server's completions for an `ask_server` request
|
||||
/// (ClientPacketListener.handleCommandSuggestions).
|
||||
pub(super) fn chat_server_suggestions(
|
||||
&mut self,
|
||||
id: i32,
|
||||
range: (usize, usize),
|
||||
list: Vec<(String, Option<String>)>,
|
||||
) {
|
||||
let m = Measure(&self.gui.atlas.font);
|
||||
let c = Commands {
|
||||
dispatcher: chat_tree(&self.remote, &self.mods),
|
||||
registries: &self.ui.registries,
|
||||
};
|
||||
if let Some(screen) = self.ui.chat_screen.as_mut() {
|
||||
screen.server_suggestions(&m, &c, id, range, list);
|
||||
}
|
||||
}
|
||||
/// Text typed into the chat box (control socket `chat`).
|
||||
pub(super) fn chat_type(&mut self, text: &str) {
|
||||
let m = Measure(&self.atlas.font);
|
||||
let m = Measure(&self.gui.atlas.font);
|
||||
let c = Commands {
|
||||
dispatcher: chat_tree(&self.remote, &self.mods),
|
||||
registries: &self.ui.registries,
|
||||
@@ -563,7 +586,7 @@ impl Game<'_> {
|
||||
let heard = self.mods.mods.is_running().then(|| line.plain());
|
||||
self.ui
|
||||
.chat
|
||||
.add(&self.atlas, line, None, self.ticks, focused);
|
||||
.add(&self.gui.atlas, line, None, self.ticks, focused);
|
||||
if let Some(line) = heard {
|
||||
self.mods_chat(&line);
|
||||
}
|
||||
@@ -591,7 +614,7 @@ impl Game<'_> {
|
||||
let height = self.renderer.as_ref().map_or(720.0, |r| {
|
||||
HudBatch::new([r.config.width, r.config.height]).height
|
||||
});
|
||||
let m = Measure(&self.atlas.font);
|
||||
let m = Measure(&self.gui.atlas.font);
|
||||
let c = Commands {
|
||||
dispatcher: chat_tree(&self.remote, &self.mods),
|
||||
registries: &self.ui.registries,
|
||||
@@ -604,7 +627,7 @@ impl Game<'_> {
|
||||
return;
|
||||
}
|
||||
match self.ui.chat.click_at(
|
||||
&self.atlas.font,
|
||||
&self.gui.atlas.font,
|
||||
height as i32,
|
||||
cursor.0 as f64,
|
||||
cursor.1 as f64,
|
||||
@@ -630,13 +653,15 @@ impl Game<'_> {
|
||||
if self.ui.hide_gui && !focused {
|
||||
return;
|
||||
}
|
||||
self.ui.chat.draw(batch, &self.atlas, self.ticks, focused);
|
||||
self.ui
|
||||
.chat
|
||||
.draw(batch, &self.gui.atlas, self.ticks, focused);
|
||||
}
|
||||
pub(super) fn draw_chat_screen(&mut self, batch: &mut HudBatch) {
|
||||
let Some(mut screen) = self.ui.chat_screen.take() else {
|
||||
return;
|
||||
};
|
||||
let m = Measure(&self.atlas.font);
|
||||
let m = Measure(&self.gui.atlas.font);
|
||||
let c = Commands {
|
||||
dispatcher: chat_tree(&self.remote, &self.mods),
|
||||
registries: &self.ui.registries,
|
||||
@@ -654,7 +679,7 @@ impl Game<'_> {
|
||||
.chat_opened
|
||||
.map_or(0, |t| t.elapsed().as_millis() as u64);
|
||||
let draws = screen.draw(&m, mouse, blink, background);
|
||||
horizon_client::screen_draw::paint(batch, &self.atlas, &draws);
|
||||
horizon_client::screen_draw::paint(batch, &self.gui.atlas, &draws);
|
||||
self.ui.chat_screen = Some(screen);
|
||||
}
|
||||
/// Advance the overworld clock (ServerClockManager.tick) when
|
||||
@@ -672,6 +697,16 @@ impl Game<'_> {
|
||||
c.partial -= whole;
|
||||
self.world.day_time += whole as i64;
|
||||
}
|
||||
/// `ServerClockInstance.packNetworkState`: the rate players' clients
|
||||
/// advance the overworld clock at, 0 while it is paused (`/time pause`)
|
||||
/// or `advance_time` is off.
|
||||
pub(super) fn network_clock_rate(&self) -> f32 {
|
||||
if self.ui.rules.bool("advance_time") && !self.ui.clock.paused {
|
||||
self.ui.clock.rate
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
/// The engine-side rule values (block behaviour and health).
|
||||
pub(super) fn level_rules(&self) -> horizon_world::level::GameRules {
|
||||
let r = &self.ui.rules;
|
||||
@@ -846,11 +881,11 @@ impl Game<'_> {
|
||||
let focused = self.screen == Screen::Chat;
|
||||
self.ui
|
||||
.chat
|
||||
.add(&self.atlas, message, None, self.ticks, focused);
|
||||
.add(&self.gui.atlas, message, None, self.ticks, focused);
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
fn chat_debug_fill(&self, batch: &mut HudBatch) {
|
||||
batch.fill(&self.atlas, 0.0, 0.0, 1.0, 1.0, rgba(0, 0, 0, 0));
|
||||
batch.fill(&self.gui.atlas, 0.0, 0.0, 1.0, 1.0, rgba(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
/// `yyyy-MM-dd_HH.mm.ss[_n].png` (Util.getFilenameFormattedDateTime, local time
|
||||
|
||||
@@ -114,7 +114,7 @@ impl Game<'_> {
|
||||
let location = if let Some(c) = p.last_climbable {
|
||||
let name = self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(c.x, c.y, c.z))
|
||||
.name
|
||||
.clone();
|
||||
@@ -127,7 +127,7 @@ impl Game<'_> {
|
||||
_ => "other_climbable",
|
||||
})
|
||||
} else {
|
||||
let f = self.res.facts.get(self.world.block(
|
||||
let f = self.res.facts().get(self.world.block(
|
||||
p.position.x.floor() as i32,
|
||||
(p.position.y + 0.1).floor() as i32,
|
||||
p.position.z.floor() as i32,
|
||||
|
||||
@@ -357,6 +357,7 @@ impl Game<'_> {
|
||||
silent: false,
|
||||
store: None,
|
||||
dimension: self.dim,
|
||||
level: None,
|
||||
block: Some(pos),
|
||||
};
|
||||
// performPrefixedCommand: a leading slash is allowed.
|
||||
@@ -458,7 +459,7 @@ impl Game<'_> {
|
||||
self.close_command_block();
|
||||
return;
|
||||
}
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let (w, h) = (batch.width, batch.height);
|
||||
let mid = (w / 2.0).floor();
|
||||
ui::menu_background(batch, atlas, 0.0, 0.0, w, h, true);
|
||||
@@ -598,13 +599,13 @@ impl Game<'_> {
|
||||
if let Ok(id) = registry.resolve(&wanted)
|
||||
&& wanted != *current
|
||||
{
|
||||
let entity = self.world.block_entities.remove(&pos);
|
||||
let entity = self.world.block_entities.take(&pos);
|
||||
let at = BlockPos::new(pos.0, pos.1, pos.2);
|
||||
self.with_level(|b, level, ticks| {
|
||||
b.set_block(level, ticks, at, id, flags::UPDATE_CLIENTS)
|
||||
});
|
||||
if let Some(entity) = entity {
|
||||
self.world.block_entities.insert(pos, entity);
|
||||
self.world.block_entities.put(pos, entity);
|
||||
}
|
||||
let _ = self.process_level_events();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ pub(super) mod extra;
|
||||
mod items;
|
||||
mod misc;
|
||||
mod place;
|
||||
mod players;
|
||||
mod raid;
|
||||
mod terrain_cmds;
|
||||
mod text_commands;
|
||||
@@ -33,7 +34,11 @@ pub(super) type R<T> = Result<T, CommandError>;
|
||||
/// An entity a selector found.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub(super) enum Target {
|
||||
/// The player in place: the host's, or the guest whose turn it is.
|
||||
Player,
|
||||
/// Another player of a hosted world or server: a guest by connection
|
||||
/// (game/commands/players.rs).
|
||||
Guest(u32),
|
||||
Mob(u32),
|
||||
Item(u32),
|
||||
Orb(usize),
|
||||
@@ -165,14 +170,20 @@ impl Game<'_> {
|
||||
}
|
||||
self.broadcast_to_admins(message);
|
||||
}
|
||||
/// CommandSourceStack.broadcastToAdmins, for a guest's command on a
|
||||
/// dedicated server (`sendSuccess` with `broadcast`): `[name: message]`,
|
||||
/// gray and italic, for the other operators when `send_command_feedback`
|
||||
/// and the console when `log_admin_commands`. Queued while the guest acts;
|
||||
/// `send_admin_feedback` sends it.
|
||||
fn broadcast_to_admins(&mut self, message: Text) {
|
||||
if self.lan_acting.is_none()
|
||||
|| self.options.dedicated.is_none()
|
||||
/// CommandSourceStack.broadcastToAdmins (`sendSuccess` with `broadcast`)
|
||||
/// for a guest's command, the host's in a world open to LAN and the
|
||||
/// dedicated server console's when `broadcast-console-to-ops` is on:
|
||||
/// `[name: message]`, gray and italic, for the other operators when
|
||||
/// `send_command_feedback`, and for a player's command on a dedicated
|
||||
/// server the console when `log_admin_commands`. Queued while the
|
||||
/// command runs; `send_admin_feedback` sends it.
|
||||
pub(super) fn broadcast_to_admins(&mut self, message: Text) {
|
||||
let informs = match self.console_broadcast {
|
||||
Some(broadcast) => broadcast,
|
||||
// While a guest acts the host's LanHost is out of `self.lan`.
|
||||
None => self.lan_acting.is_some() || self.lan.is_some(),
|
||||
};
|
||||
if !informs
|
||||
|| message
|
||||
.translation_key()
|
||||
.is_some_and(|k| admin::QUIET.contains(&k))
|
||||
@@ -180,29 +191,62 @@ impl Game<'_> {
|
||||
return;
|
||||
}
|
||||
let ops = self.ui.rules.bool("send_command_feedback");
|
||||
let console = self.ui.rules.bool("log_admin_commands");
|
||||
// MinecraftServer.sendSystemMessage, unless the server is the source.
|
||||
let console = self.console_broadcast.is_none()
|
||||
&& self.lan_acting.is_some()
|
||||
&& self.options.dedicated.is_some()
|
||||
&& self.ui.rules.bool("log_admin_commands");
|
||||
if !ops && !console {
|
||||
return;
|
||||
}
|
||||
// getDisplayName: the entity the command runs as (`execute as`).
|
||||
let who = self
|
||||
.command_source
|
||||
.and_then(|s| s.entity)
|
||||
.unwrap_or(Target::Player);
|
||||
let line = Text::translate("chat.type.admin", &[self.target_name(who), message])
|
||||
// getDisplayName: the entity the command runs as (`execute as`), or
|
||||
// the server's own source, "Server".
|
||||
let who = match self.command_source.and_then(|s| s.entity) {
|
||||
Some(entity) => self.target_name(entity),
|
||||
None if self.console_broadcast.is_some() => Text::literal("Server".to_owned()),
|
||||
None => self.player_display_name(),
|
||||
};
|
||||
let line = Text::translate("chat.type.admin", &[who, message])
|
||||
.with_color(text::GRAY)
|
||||
.italic();
|
||||
self.admin_feedback.push((line, ops, console));
|
||||
}
|
||||
/// Player.getDisplayName: the name (team-formatted), suggesting a
|
||||
/// `/tell`, showing the player on hover, inserting the name.
|
||||
fn player_display_name(&self) -> Text {
|
||||
let name = self.acting_player_name().to_owned();
|
||||
let Some(uuid) = self.lan_acting_uuid else {
|
||||
return self.target_name(Target::Player);
|
||||
};
|
||||
self.target_name(Target::Player).with_component_fields(vec![
|
||||
(
|
||||
"click_event".into(),
|
||||
serde_json::json!({"action": "suggest_command", "command": format!("/tell {name} ")}),
|
||||
),
|
||||
(
|
||||
"hover_event".into(),
|
||||
serde_json::json!({"action": "show_entity", "id": "minecraft:player",
|
||||
"uuid": horizon_protocol::crypto::uuid_string(uuid), "name": name}),
|
||||
),
|
||||
("insertion".into(), name.into()),
|
||||
])
|
||||
}
|
||||
fn source_position(&self) -> [f64; 3] {
|
||||
if let Some(s) = &self.command_source {
|
||||
return s.pos;
|
||||
}
|
||||
match &self.player {
|
||||
Some(p) => [p.position.x, p.position.y, p.position.z],
|
||||
None => self.spawn.map_or([0.0, 64.0, 0.0], |s| [s.x, s.y, s.z]),
|
||||
None => self.server_position(),
|
||||
}
|
||||
}
|
||||
/// MinecraftServer.createCommandSourceStack's position: the corner of
|
||||
/// the respawn block (`Vec3.atLowerCornerOf`).
|
||||
pub(super) fn server_position(&self) -> [f64; 3] {
|
||||
self.spawn.map_or([0.0, 64.0, 0.0], |s| {
|
||||
[s.x.floor(), s.y.floor(), s.z.floor()]
|
||||
})
|
||||
}
|
||||
fn source_rotation(&self) -> [f32; 2] {
|
||||
self.command_source
|
||||
.map_or([self.yaw, self.pitch], |s| s.rot)
|
||||
@@ -256,6 +300,7 @@ impl Game<'_> {
|
||||
.player
|
||||
.as_ref()
|
||||
.map(|p| [p.position.x, p.position.y, p.position.z]),
|
||||
Target::Guest(conn) => self.command_guest(conn).map(|g| g.position),
|
||||
Target::Mob(id) => self
|
||||
.mobs
|
||||
.iter()
|
||||
@@ -315,7 +360,7 @@ impl Game<'_> {
|
||||
}
|
||||
pub(super) fn target_type(&self, t: Target) -> String {
|
||||
match t {
|
||||
Target::Player => "minecraft:player".into(),
|
||||
Target::Player | Target::Guest(_) => "minecraft:player".into(),
|
||||
Target::Mob(id) => self
|
||||
.mobs
|
||||
.iter()
|
||||
@@ -362,12 +407,19 @@ impl Game<'_> {
|
||||
match t {
|
||||
Target::Player => {
|
||||
let name = self.acting_player_name();
|
||||
if let Some(uuid) = self.lan_acting_uuid {
|
||||
return self.player_text(name, uuid);
|
||||
}
|
||||
match self.score.board.players_team(name) {
|
||||
// PlayerTeam.formatNameForTeam.
|
||||
Some(team) => team.formatted_name(Text::literal(name)),
|
||||
None => Text::literal(name),
|
||||
}
|
||||
}
|
||||
Target::Guest(conn) => match self.command_guest(conn) {
|
||||
Some(g) => self.player_text(&g.name, g.uuid),
|
||||
None => Text::empty(),
|
||||
},
|
||||
Target::Item(id) => {
|
||||
let item = self
|
||||
.dropped
|
||||
@@ -414,11 +466,10 @@ impl Game<'_> {
|
||||
/// EntitySelector.findEntities.
|
||||
pub(super) fn select(&mut self, s: &Selector) -> Vec<Target> {
|
||||
if let Some(name) = &s.player_name {
|
||||
return if name.eq_ignore_ascii_case(PLAYER_NAME) && self.player.is_some() {
|
||||
vec![Target::Player]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
return self.player_named(name).into_iter().collect();
|
||||
}
|
||||
if let Some(uuid) = s.uuid {
|
||||
return self.target_by_uuid(uuid).into_iter().collect();
|
||||
}
|
||||
let origin = {
|
||||
let p = self.source_position();
|
||||
@@ -432,10 +483,15 @@ impl Game<'_> {
|
||||
match (s.kind, self.command_source) {
|
||||
// @s: the executing entity (none for a server source).
|
||||
('s', Some(source)) => candidates.extend(source.entity),
|
||||
_ if self.player.is_some() => candidates.push(Target::Player),
|
||||
('s', None) => candidates.extend(self.source_entity()),
|
||||
// A guest in place is among the players, in join order.
|
||||
_ if self.player.is_some() && self.lan_acting.is_none() => {
|
||||
candidates.push(Target::Player);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if s.kind != 's' {
|
||||
candidates.extend(self.player_candidates(s));
|
||||
candidates.extend(
|
||||
self.mobs
|
||||
.iter()
|
||||
@@ -479,7 +535,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
if !s.include_entities
|
||||
&& t != Target::Player
|
||||
&& !t.is_player()
|
||||
&& s.types.iter().all(|(w, n)| *n || w != &ty)
|
||||
&& s.kind != 'e'
|
||||
&& s.kind != 'n'
|
||||
@@ -495,16 +551,20 @@ impl Game<'_> {
|
||||
if !passing.contains(&t) {
|
||||
return None;
|
||||
}
|
||||
let player = match t {
|
||||
Target::Player => Some((level, if creative { "creative" } else { "survival" })),
|
||||
Target::Guest(conn) => self.guest_level_and_mode(conn),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((lo, hi)) = s.level
|
||||
&& (t != Target::Player
|
||||
|| lo.is_some_and(|l| level < l)
|
||||
|| hi.is_some_and(|h| level > h))
|
||||
&& player.is_none_or(|(level, _)| {
|
||||
lo.is_some_and(|l| level < l) || hi.is_some_and(|h| level > h)
|
||||
})
|
||||
{
|
||||
return None;
|
||||
}
|
||||
for (mode, neg) in &s.gamemodes {
|
||||
let current = if creative { "creative" } else { "survival" };
|
||||
if t != Target::Player || (current == mode) == *neg {
|
||||
if player.is_none_or(|(_, current)| (current == mode) == *neg) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
@@ -563,12 +623,12 @@ impl Game<'_> {
|
||||
/// EntityArgument.getEntities / getPlayers / getEntity / getPlayer.
|
||||
pub(super) fn entities(&mut self, ctx: &Context, name: &str, players: bool) -> R<Vec<Target>> {
|
||||
let Some(Arg::Entity(s)) = ctx.get(name).cloned() else {
|
||||
return Ok(vec![Target::Player]);
|
||||
return Ok(vec![self.implied_player()]);
|
||||
};
|
||||
let found: Vec<Target> = self
|
||||
.select(&s)
|
||||
.into_iter()
|
||||
.filter(|t| !players || *t == Target::Player)
|
||||
.filter(|t| !players || t.is_player())
|
||||
.collect();
|
||||
if found.is_empty() {
|
||||
return Err(err(
|
||||
@@ -774,63 +834,63 @@ impl Game<'_> {
|
||||
let targets = if ctx.get("target").is_some() {
|
||||
self.entities(ctx, "target", true)?
|
||||
} else {
|
||||
vec![Target::Player]
|
||||
vec![self.implied_player()]
|
||||
};
|
||||
let mut count = 0;
|
||||
for t in targets {
|
||||
if t != Target::Player || !self.set_game_mode(mode) {
|
||||
let mode_name = Text::translate(&format!("gameMode.{}", mode.name()), &[]);
|
||||
// GameModeCommand.logGamemodeChange: the source's own entity.
|
||||
let own = self.source_entity() == Some(t);
|
||||
let told = !own && self.ui.rules.bool("send_command_feedback");
|
||||
let changed = self.for_player(t, |g| {
|
||||
if !g.set_game_mode(mode) {
|
||||
return false;
|
||||
}
|
||||
if told {
|
||||
g.system_message(Text::translate(
|
||||
"gameMode.changed",
|
||||
std::slice::from_ref(&mode_name),
|
||||
));
|
||||
}
|
||||
true
|
||||
});
|
||||
if changed != Some(true) {
|
||||
continue;
|
||||
}
|
||||
count += 1;
|
||||
let mode_name = Text::translate(&format!("gameMode.{}", mode.name()), &[]);
|
||||
// GameModeCommand.logGamemodeChange: the source's own entity.
|
||||
let own = match self.command_source {
|
||||
None => true,
|
||||
Some(s) => s.entity == Some(t),
|
||||
};
|
||||
if own {
|
||||
self.feedback(Text::translate(
|
||||
"commands.gamemode.success.self",
|
||||
&[mode_name],
|
||||
));
|
||||
} else {
|
||||
if self.ui.rules.bool("send_command_feedback") {
|
||||
self.system_message(Text::translate(
|
||||
"gameMode.changed",
|
||||
std::slice::from_ref(&mode_name),
|
||||
));
|
||||
}
|
||||
self.feedback(Text::translate(
|
||||
"commands.gamemode.success.other",
|
||||
&[Text::literal(self.acting_player_name()), mode_name],
|
||||
&[self.target_name(t), mode_name],
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(count)
|
||||
}
|
||||
/// ItemStack.getDisplayName: "[Name]" in the rarity colour.
|
||||
/// ItemStack.getDisplayName of one `item` with no components.
|
||||
pub(super) fn item_display_name(&self, item: &str) -> Text {
|
||||
let rarity = self.item_rarity(item);
|
||||
let color = match rarity.as_str() {
|
||||
"uncommon" => text::YELLOW,
|
||||
"rare" => text::AQUA,
|
||||
"epic" => text::LIGHT_PURPLE,
|
||||
_ => text::WHITE,
|
||||
};
|
||||
Text::literal("[")
|
||||
.append(Text::literal(self.pack.names.item(item)))
|
||||
.append("]")
|
||||
.with_color(color)
|
||||
self.stack_display_name(&ItemStack {
|
||||
item: item.into(),
|
||||
count: 1,
|
||||
damage: 0,
|
||||
extra: None,
|
||||
})
|
||||
}
|
||||
/// `ItemStack.getDisplayName`: the hover name (custom name in italics,
|
||||
/// a written book's title, a potion's effect name...) in brackets, in the
|
||||
/// rarity colour unless the stack is empty.
|
||||
/// a written book's title, a potion's effect name, else the item's
|
||||
/// translated name) in brackets, in the rarity colour and showing the
|
||||
/// stack on hover unless it is empty.
|
||||
pub(super) fn stack_display_name(&self, s: &ItemStack) -> Text {
|
||||
let item = &*s.item;
|
||||
let empty = item == "minecraft:air" || s.count == 0;
|
||||
let custom = s.custom_name();
|
||||
let hover = if let Some(c) = custom {
|
||||
Text::literal(c).italic()
|
||||
Text::literal(c)
|
||||
} else if let Some(title) = s
|
||||
.data()
|
||||
.and_then(|d| d.written.as_ref())
|
||||
@@ -851,9 +911,22 @@ impl Game<'_> {
|
||||
&[],
|
||||
)
|
||||
} else {
|
||||
Text::literal(self.pack.names.item(item))
|
||||
// Item.getDescriptionId: a block item's is the block's.
|
||||
let (namespace, path) = item.split_once(':').unwrap_or(("minecraft", item));
|
||||
let key = format!("item.{namespace}.{path}");
|
||||
let key = if self.pack.names.get(&key).is_some() {
|
||||
key
|
||||
} else {
|
||||
format!("block.{namespace}.{path}")
|
||||
};
|
||||
Text::translate(&key, &[])
|
||||
};
|
||||
let wrapped = Text::translate("chat.square_brackets", &[hover]);
|
||||
// Component.empty().append(getHoverName()), italic for a custom name.
|
||||
let mut name = Text::empty().append(hover);
|
||||
if custom.is_some() {
|
||||
name = name.italic();
|
||||
}
|
||||
let wrapped = Text::translate("chat.square_brackets", &[name]);
|
||||
if empty {
|
||||
return wrapped;
|
||||
}
|
||||
@@ -871,7 +944,14 @@ impl Game<'_> {
|
||||
"epic" => text::LIGHT_PURPLE,
|
||||
_ => text::WHITE,
|
||||
};
|
||||
wrapped.with_color(color)
|
||||
// HoverEvent.ShowItem: the count only when it is not one.
|
||||
let mut shown = serde_json::json!({"action": "show_item", "id": item});
|
||||
if s.count != 1 {
|
||||
shown["count"] = s.count.into();
|
||||
}
|
||||
wrapped
|
||||
.with_color(color)
|
||||
.with_component_fields(vec![("hover_event".into(), shown)])
|
||||
}
|
||||
pub(super) fn item_rarity(&self, item: &str) -> String {
|
||||
static RARITY: std::sync::OnceLock<std::collections::HashMap<String, String>> =
|
||||
@@ -909,7 +989,7 @@ impl Game<'_> {
|
||||
};
|
||||
let count = Self::int(ctx, "count").unwrap_or(1);
|
||||
let targets = self.entities(ctx, "targets", true)?;
|
||||
let max_stack = self.res.items.get(&id).map_or(64, |i| i.max_stack) as i32;
|
||||
let max_stack = self.res.items().get(&id).map_or(64, |i| i.max_stack) as i32;
|
||||
if count > max_stack * 100 {
|
||||
return Err(CommandError::new(Text::translate(
|
||||
"commands.give.failed.toomanyitems",
|
||||
@@ -921,33 +1001,38 @@ impl Game<'_> {
|
||||
}
|
||||
// An air stack is empty: nothing is given (but the message still is).
|
||||
let empty = id == "minecraft:air";
|
||||
for _ in targets.iter().filter(|_| !empty) {
|
||||
let mut remaining = count;
|
||||
while remaining > 0 {
|
||||
let size = remaining.min(max_stack);
|
||||
remaining -= size;
|
||||
let left = self.give(ItemStack {
|
||||
item: id.as_str().into(),
|
||||
count: size as u32,
|
||||
damage,
|
||||
extra: extra.clone(),
|
||||
});
|
||||
if let Some(rest) = left {
|
||||
// Inventory full: drop the rest at the player's feet without pickup delay.
|
||||
let p = self.source_position();
|
||||
self.spawn_item(rest, [p[0], p[1] + 1.32, p[2]], [0.0, 0.0, 0.0], 0);
|
||||
} else {
|
||||
let r = &mut self.world.random;
|
||||
let pitch = ((r.next_float() - r.next_float()) * 0.7 + 1.0) * 2.0;
|
||||
let p = self.source_position();
|
||||
self.audio
|
||||
.play("minecraft:entity.item.pickup", Some(p), 0.2, pitch);
|
||||
for &t in targets.iter().filter(|_| !empty) {
|
||||
self.for_player(t, |g| {
|
||||
let mut remaining = count;
|
||||
while remaining > 0 {
|
||||
let size = remaining.min(max_stack);
|
||||
remaining -= size;
|
||||
let left = g.give(ItemStack {
|
||||
item: id.as_str().into(),
|
||||
count: size as u32,
|
||||
damage,
|
||||
extra: extra.clone(),
|
||||
});
|
||||
// At the player who gets them.
|
||||
let p = g
|
||||
.target_position(Target::Player)
|
||||
.unwrap_or(g.source_position());
|
||||
if let Some(rest) = left {
|
||||
// Inventory full: drop the rest at the player's feet without pickup delay.
|
||||
g.spawn_item(rest, [p[0], p[1] + 1.32, p[2]], [0.0, 0.0, 0.0], 0);
|
||||
} else {
|
||||
let r = &mut g.world.random;
|
||||
let pitch = ((r.next_float() - r.next_float()) * 0.7 + 1.0) * 2.0;
|
||||
g.audio
|
||||
.play("minecraft:entity.item.pickup", Some(p), 0.2, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// The prototype stack: one item.
|
||||
let name = self.stack_display_name(&ItemStack {
|
||||
item: id.as_str().into(),
|
||||
count: count.max(1) as u32,
|
||||
count: 1,
|
||||
damage,
|
||||
extra: extra.clone(),
|
||||
});
|
||||
@@ -957,7 +1042,7 @@ impl Game<'_> {
|
||||
&[
|
||||
Text::literal(count.to_string()),
|
||||
name,
|
||||
Text::literal(self.acting_player_name()),
|
||||
self.target_name(targets[0]),
|
||||
],
|
||||
)
|
||||
} else {
|
||||
@@ -976,6 +1061,9 @@ impl Game<'_> {
|
||||
fn teleport_to(&mut self, t: Target, pos: [f64; 3], rotation: Option<[f32; 2]>) {
|
||||
let v = Vec3::new(pos[0], pos[1], pos[2]);
|
||||
match t {
|
||||
Target::Guest(_) => {
|
||||
self.for_player(t, |g| g.teleport_to(Target::Player, pos, rotation));
|
||||
}
|
||||
Target::Player => {
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
p.position = v;
|
||||
@@ -1092,17 +1180,60 @@ impl Game<'_> {
|
||||
self.end_portal_travel = false;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A server's player teleported into another level than theirs
|
||||
/// (ServerPlayer.teleport): queued to move after the command. False
|
||||
/// when `t` is not a player in another level.
|
||||
fn teleport_across(
|
||||
&mut self,
|
||||
t: Target,
|
||||
level: super::Dim,
|
||||
pos: [f64; 3],
|
||||
rotation: Option<[f32; 2]>,
|
||||
) -> bool {
|
||||
let (conn, at) = match t {
|
||||
Target::Player => (self.lan_acting, self.dim),
|
||||
Target::Guest(conn) => (
|
||||
Some(conn),
|
||||
self.command_guest(conn)
|
||||
.map_or(self.dim, |g| super::Dim::from_id(&g.dimension)),
|
||||
),
|
||||
_ => (None, self.dim),
|
||||
};
|
||||
let Some(conn) = conn.filter(|_| at != level && self.options.dedicated.is_some()) else {
|
||||
return false;
|
||||
};
|
||||
self.level_teleports
|
||||
.push(super::server_travel::LevelTeleport {
|
||||
conn,
|
||||
dim: level,
|
||||
at: pos,
|
||||
rotation,
|
||||
});
|
||||
true
|
||||
}
|
||||
fn cmd_teleport(&mut self, id: &str, ctx: &Context) -> R<i32> {
|
||||
let targets = if id.starts_with("teleport.targets") {
|
||||
self.entities(ctx, "targets", false)?
|
||||
} else {
|
||||
vec![Target::Player]
|
||||
vec![self.implied_player()]
|
||||
};
|
||||
if id.ends_with("destination") {
|
||||
let dest = self.entities(ctx, "destination", false)?[0];
|
||||
let pos = self.target_position(dest).unwrap_or(self.source_position());
|
||||
// Into the destination's level.
|
||||
let level = match dest {
|
||||
Target::Guest(conn) => self
|
||||
.command_guest(conn)
|
||||
.map_or(self.dim, |g| super::Dim::from_id(&g.dimension)),
|
||||
_ => self.dim,
|
||||
};
|
||||
// TeleportCommand.teleportToEntity: the destination's rotation too.
|
||||
let rotation = Some(self.target_rotation(dest));
|
||||
for &t in &targets {
|
||||
self.teleport_to(t, pos, None);
|
||||
if !self.teleport_across(t, level, pos, rotation) {
|
||||
self.teleport_to(t, pos, rotation);
|
||||
}
|
||||
}
|
||||
let message = if targets.len() == 1 {
|
||||
Text::translate(
|
||||
@@ -1160,7 +1291,18 @@ impl Game<'_> {
|
||||
(-(dy.atan2(horizontal).to_degrees())) as f32,
|
||||
]);
|
||||
}
|
||||
// A server's player in another level than the source's (`execute
|
||||
// in`, the console's Overworld) moves there (ServerPlayer.teleport
|
||||
// into another level), after the command.
|
||||
let source_level = match self.command_source.and_then(|s| s.level) {
|
||||
Some(level) => level,
|
||||
None if self.source_entity().is_none() => super::Dim::Overworld,
|
||||
None => self.dim,
|
||||
};
|
||||
for &t in &targets {
|
||||
if self.teleport_across(t, source_level, pos, rotation) {
|
||||
continue;
|
||||
}
|
||||
let dimension = self.command_source.map_or(self.dim, |s| s.dimension);
|
||||
if t == Target::Player && dimension != self.dim {
|
||||
self.teleport_player_to_dimension(dimension, pos, rotation)?;
|
||||
@@ -1366,6 +1508,9 @@ impl Game<'_> {
|
||||
}
|
||||
fn kill_target(&mut self, t: Target) {
|
||||
match t {
|
||||
Target::Guest(_) => {
|
||||
self.for_player(t, |g| g.kill_target(Target::Player));
|
||||
}
|
||||
Target::Player => {
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
let _ = p.set_health(0.0, false);
|
||||
@@ -1408,7 +1553,7 @@ impl Game<'_> {
|
||||
let targets = if ctx.get("targets").is_some() {
|
||||
self.entities(ctx, "targets", false)?
|
||||
} else {
|
||||
vec![Target::Player]
|
||||
vec![self.implied_player()]
|
||||
};
|
||||
let names: Vec<Text> = targets.iter().map(|&t| self.target_name(t)).collect();
|
||||
// Remove indexed entities from the back so earlier indices stay valid.
|
||||
@@ -1461,7 +1606,7 @@ impl Game<'_> {
|
||||
if self.ui.difficulty == 0
|
||||
&& self
|
||||
.res
|
||||
.mob_types
|
||||
.mob_types()
|
||||
.get(&format!("minecraft:{short}"))
|
||||
.is_some_and(|t| t.category == "monster")
|
||||
{
|
||||
@@ -1478,7 +1623,7 @@ impl Game<'_> {
|
||||
let name;
|
||||
if let Some(t) = self
|
||||
.res
|
||||
.mob_types
|
||||
.mob_types()
|
||||
.get(&format!("minecraft:{short}"))
|
||||
.cloned()
|
||||
{
|
||||
@@ -1494,7 +1639,9 @@ impl Game<'_> {
|
||||
return Err(err("commands.summon.failed", &[]));
|
||||
}
|
||||
"experience_orb" => {
|
||||
self.next_entity += 1;
|
||||
self.orbs.push(horizon_client::entities::ExperienceOrb {
|
||||
id: self.next_entity,
|
||||
position: Vec3::new(pos[0], pos[1], pos[2]),
|
||||
previous: Vec3::new(pos[0], pos[1], pos[2]),
|
||||
velocity: Vec3::new(0.0, 0.0, 0.0),
|
||||
@@ -1520,7 +1667,13 @@ impl Game<'_> {
|
||||
self.carts.push(cart);
|
||||
name = Text::translate(&format!("entity.minecraft.{k}"), &[]);
|
||||
}
|
||||
_ => return Err(err("commands.summon.failed", &[])),
|
||||
// SummonCommand.createEntity: any other type from an empty compound.
|
||||
_ => {
|
||||
let Some(target) = self.summon_with_nbt(&kind, pos, "{}")? else {
|
||||
return Err(err("commands.summon.failed", &[]));
|
||||
};
|
||||
name = self.target_name(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.feedback(Text::translate("commands.summon.success", &[name]));
|
||||
@@ -1546,10 +1699,10 @@ impl Game<'_> {
|
||||
let name_ok = if b.tag {
|
||||
let tag = b.id.trim_start_matches("minecraft:");
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get(tag)
|
||||
.or_else(|| self.res.items.block_tags.get(&b.id))
|
||||
.or_else(|| self.res.items().block_tags.get(&b.id))
|
||||
.is_some_and(|set| {
|
||||
set.contains(&s.name) || set.contains(s.name.trim_start_matches("minecraft:"))
|
||||
})
|
||||
@@ -1574,8 +1727,8 @@ impl Game<'_> {
|
||||
}
|
||||
// A different block replaces the block entity (Level.setBlock).
|
||||
let (old, new) = (
|
||||
self.res.facts.get(previous).name.clone(),
|
||||
self.res.facts.get(state).name.clone(),
|
||||
self.res.facts().get(previous).name.clone(),
|
||||
self.res.facts().get(state).name.clone(),
|
||||
);
|
||||
// The command clears the old block entity without its side effects
|
||||
// (UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS); the new block gets a fresh one.
|
||||
@@ -2169,10 +2322,10 @@ impl Game<'_> {
|
||||
let tag = predicate.id.trim_start_matches("minecraft:");
|
||||
return self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.item_tags
|
||||
.get(tag)
|
||||
.or_else(|| self.res.items.item_tags.get(&predicate.id))
|
||||
.or_else(|| self.res.items().item_tags.get(&predicate.id))
|
||||
.is_some_and(|s| {
|
||||
s.contains(item) || s.contains(item.trim_start_matches("minecraft:"))
|
||||
});
|
||||
@@ -2618,7 +2771,7 @@ impl Game<'_> {
|
||||
let focused = self.screen == Screen::Chat;
|
||||
self.ui
|
||||
.chat
|
||||
.add(&self.atlas, line, None, self.ticks, focused);
|
||||
.add(&self.gui.atlas, line, None, self.ticks, focused);
|
||||
Ok(1)
|
||||
}
|
||||
/// MessageArgument: `@p`-style selectors in a message become names.
|
||||
|
||||
@@ -502,7 +502,7 @@ impl Game<'_> {
|
||||
Some(Value::String(b)) => match b.strip_prefix('#') {
|
||||
Some(tag) => self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get(tag.trim_start_matches("minecraft:"))
|
||||
.is_some_and(|set| {
|
||||
|
||||
@@ -35,6 +35,11 @@ impl Game<'_> {
|
||||
pub(in crate::game) fn entity_nbt(&mut self, t: Target) -> Option<Tag> {
|
||||
let player_uuid = self.level.player_uuid;
|
||||
Some(match t {
|
||||
Target::Guest(_) => {
|
||||
return self
|
||||
.for_player(t, |g| g.entity_nbt(Target::Player))
|
||||
.flatten();
|
||||
}
|
||||
Target::Player => {
|
||||
self.player.as_ref()?;
|
||||
self.sync_level();
|
||||
@@ -142,7 +147,7 @@ impl Game<'_> {
|
||||
set_key(&mut tag, "id", Tag::String(k.as_str().into()));
|
||||
}
|
||||
let new =
|
||||
entity_nbt::mob_from_nbt(&tag, &self.res.mob_types, id).ok_or_else(stale)?;
|
||||
entity_nbt::mob_from_nbt(&tag, self.res.mob_types(), id).ok_or_else(stale)?;
|
||||
if let Some(slot) = self.mobs.iter_mut().find(|m| m.id == id) {
|
||||
// Runtime-only state (AI, animation) carries over.
|
||||
let old = std::mem::replace(slot, new);
|
||||
|
||||
@@ -59,7 +59,7 @@ impl Game<'_> {
|
||||
if ctx.get("targets").is_some() {
|
||||
self.entities(ctx, "targets", false)
|
||||
} else {
|
||||
Ok(vec![Target::Player])
|
||||
Ok(vec![self.implied_player()])
|
||||
}
|
||||
}
|
||||
/// `EffectCommands.giveEffect`.
|
||||
@@ -83,10 +83,11 @@ impl Game<'_> {
|
||||
let mut tracker = Tracker::default();
|
||||
for t in self.living_targets(ctx)? {
|
||||
let changed = match t {
|
||||
Target::Player => {
|
||||
Target::Player | Target::Guest(_) => {
|
||||
let mut instance = EffectInstance::new(effect.id, duration, amplifier);
|
||||
instance.visible = particles;
|
||||
self.add_player_effect(instance)
|
||||
self.for_player(t, |g| g.add_player_effect(instance))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
Target::Mob(id) => match self.mobs.iter_mut().find(|m| m.id == id) {
|
||||
Some(m) => {
|
||||
@@ -131,18 +132,22 @@ impl Game<'_> {
|
||||
let mut tracker = Tracker::default();
|
||||
for t in self.living_targets(ctx)? {
|
||||
let changed = match (t, effect) {
|
||||
(Target::Player, None) => {
|
||||
let any = !self.potions.effects.list.is_empty();
|
||||
self.potions.effects.clear();
|
||||
self.apply_effect_status();
|
||||
any
|
||||
}
|
||||
(Target::Player, Some(e)) => {
|
||||
let before = self.potions.effects.list.len();
|
||||
self.potions.effects.list.retain(|x| x.id != e.id);
|
||||
self.apply_effect_status();
|
||||
self.potions.effects.list.len() != before
|
||||
}
|
||||
(Target::Player | Target::Guest(_), None) => self
|
||||
.for_player(t, |g| {
|
||||
let any = !g.potions.effects.list.is_empty();
|
||||
g.potions.effects.clear();
|
||||
g.apply_effect_status();
|
||||
any
|
||||
})
|
||||
.unwrap_or(false),
|
||||
(Target::Player | Target::Guest(_), Some(e)) => self
|
||||
.for_player(t, |g| {
|
||||
let before = g.potions.effects.list.len();
|
||||
g.potions.effects.list.retain(|x| x.id != e.id);
|
||||
g.apply_effect_status();
|
||||
g.potions.effects.list.len() != before
|
||||
})
|
||||
.unwrap_or(false),
|
||||
(Target::Mob(id), e) => match self.mobs.iter_mut().find(|m| m.id == id) {
|
||||
Some(m) => {
|
||||
let before = m.extra.effects.len();
|
||||
@@ -187,7 +192,7 @@ impl Game<'_> {
|
||||
return Ok(0);
|
||||
};
|
||||
let level = Self::int(ctx, "level").unwrap_or(1);
|
||||
let enchantments = &self.res.stations.enchantments;
|
||||
let enchantments = &self.res.stations().enchantments;
|
||||
let Some(def) = enchantments.get(&id) else {
|
||||
return Err(err(
|
||||
"argument.resource.not_found",
|
||||
@@ -213,8 +218,8 @@ impl Game<'_> {
|
||||
}
|
||||
continue;
|
||||
};
|
||||
let e = &self.res.stations.enchantments;
|
||||
let compatible = e.can_enchant(&self.res.items, &id, &stack.item)
|
||||
let e = &self.res.stations().enchantments;
|
||||
let compatible = e.can_enchant(self.res.items(), &id, &stack.item)
|
||||
&& stack
|
||||
.crafting_enchantments()
|
||||
.iter()
|
||||
@@ -265,7 +270,7 @@ impl Game<'_> {
|
||||
}
|
||||
let (name, curse) = self
|
||||
.res
|
||||
.stations
|
||||
.stations()
|
||||
.enchantments
|
||||
.full_name(&id, level.max(0) as u32);
|
||||
let style = Style {
|
||||
|
||||
@@ -26,6 +26,9 @@ pub(in crate::game) struct Source {
|
||||
/// The level this command source uses. Horizon has only this dimension's
|
||||
/// chunks loaded in the single-player client.
|
||||
pub dimension: Dim,
|
||||
/// The dimension `execute in` named, if any: a server teleports its
|
||||
/// players there (`TeleportCommand` into the source's level).
|
||||
pub level: Option<super::super::Dim>,
|
||||
/// The command block whose output this source is
|
||||
/// (`BaseCommandBlock.CloseableCommandBlockSource`).
|
||||
pub block: Option<(i32, i32, i32)>,
|
||||
@@ -70,13 +73,15 @@ impl Game<'_> {
|
||||
/// The source a command typed by the player starts from.
|
||||
pub(in crate::game) fn player_source(&self) -> Source {
|
||||
Source {
|
||||
entity: Some(Target::Player),
|
||||
// The server console has no entity (CommandSourceStack of the server).
|
||||
entity: self.player.is_some().then_some(Target::Player),
|
||||
pos: self.source_position(),
|
||||
rot: self.source_rotation(),
|
||||
eyes: false,
|
||||
silent: false,
|
||||
store: None,
|
||||
dimension: self.dim,
|
||||
level: None,
|
||||
block: None,
|
||||
}
|
||||
}
|
||||
@@ -84,18 +89,22 @@ impl Game<'_> {
|
||||
pub(in crate::game) fn server_source(&self) -> Source {
|
||||
Source {
|
||||
entity: None,
|
||||
pos: self.spawn.map_or([0.0, 64.0, 0.0], |s| [s.x, s.y, s.z]),
|
||||
pos: self.server_position(),
|
||||
rot: [0.0, 0.0],
|
||||
eyes: false,
|
||||
silent: true,
|
||||
store: None,
|
||||
dimension: self.dim,
|
||||
level: None,
|
||||
block: None,
|
||||
}
|
||||
}
|
||||
pub(super) fn target_rotation(&self, t: Target) -> [f32; 2] {
|
||||
match t {
|
||||
Target::Player => [self.yaw, self.pitch],
|
||||
Target::Guest(conn) => self
|
||||
.command_guest(conn)
|
||||
.map_or([0.0; 2], |g| [g.yaw, g.pitch]),
|
||||
Target::Mob(id) => self
|
||||
.mobs
|
||||
.iter()
|
||||
@@ -130,6 +139,7 @@ impl Game<'_> {
|
||||
.player
|
||||
.as_ref()
|
||||
.map_or(1.62, |p| f64::from(p.dimensions.eye_height)),
|
||||
Target::Guest(conn) => self.command_guest(conn).map_or(1.62, |g| g.eye_height()),
|
||||
Target::Mob(id) => self
|
||||
.mobs
|
||||
.iter()
|
||||
@@ -441,6 +451,7 @@ impl Game<'_> {
|
||||
pos: self.target_position(t)?,
|
||||
rot: self.target_rotation(t),
|
||||
dimension: self.dim,
|
||||
level: None,
|
||||
..s
|
||||
})
|
||||
})
|
||||
@@ -548,6 +559,7 @@ impl Game<'_> {
|
||||
vec![Source {
|
||||
pos: [s.pos[0] * scale, s.pos[1], s.pos[2] * scale],
|
||||
dimension,
|
||||
level: Some(super::super::Dim::from_id(dim)),
|
||||
..s
|
||||
}]
|
||||
}
|
||||
@@ -630,7 +642,7 @@ impl Game<'_> {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
fn target_with_uuid(&self, uuid: [i32; 4]) -> Option<Target> {
|
||||
pub(super) fn target_with_uuid(&self, uuid: [i32; 4]) -> Option<Target> {
|
||||
if Some(uuid) == self.level.player_uuid {
|
||||
return Some(Target::Player);
|
||||
}
|
||||
@@ -653,7 +665,7 @@ impl Game<'_> {
|
||||
if state == self.world.air {
|
||||
continue;
|
||||
}
|
||||
let facts = self.res.facts.get(state);
|
||||
let facts = self.res.facts().get(state);
|
||||
let blocks = facts.legacy_solid || facts.fluid != horizon_client::blocks::Fluid::None;
|
||||
let leaves = self
|
||||
.pack
|
||||
@@ -947,7 +959,7 @@ impl Game<'_> {
|
||||
let chunk = self.world.chunks.get(&(p[0] >> 4, p[2] >> 4))?;
|
||||
Some(
|
||||
self.res
|
||||
.biomes
|
||||
.biomes()
|
||||
.get(chunk.biome(p[0], p[1], p[2]))
|
||||
.name
|
||||
.clone(),
|
||||
@@ -970,7 +982,7 @@ impl Game<'_> {
|
||||
.resources
|
||||
.join(format!("data/{ns}/tags/worldgen/biome/{path}.json"));
|
||||
let Ok(bytes) = std::fs::read(file) else {
|
||||
return self.res.mob_data.biome_has(tag, biome);
|
||||
return self.res.mob_data().biome_has(tag, biome);
|
||||
};
|
||||
let v: serde_json::Value = serde_json::from_slice(&bytes).unwrap_or_default();
|
||||
v["values"].as_array().is_some_and(|a| {
|
||||
|
||||
@@ -586,7 +586,7 @@ impl Game<'_> {
|
||||
);
|
||||
let hit = traverse_blocks(eye, end, 256, |b: BlockPos| {
|
||||
let state = self.world.block(b.x, b.y, b.z);
|
||||
(!self.res.facts.is_air(state)).then_some([b.x, b.y, b.z])
|
||||
(!self.res.facts().is_air(state)).then_some([b.x, b.y, b.z])
|
||||
});
|
||||
hit.ok().flatten().unwrap_or([
|
||||
end.x.floor() as i32,
|
||||
|
||||
@@ -375,7 +375,11 @@ impl Game<'_> {
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let max = self.res.items.get(&stack.item).map_or(64, |i| i.max_stack);
|
||||
let max = self
|
||||
.res
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.map_or(64, |i| i.max_stack);
|
||||
stack.count = (base + n).clamp(0, max as i32) as u32;
|
||||
}
|
||||
"minecraft:limit_count" => {
|
||||
@@ -389,7 +393,11 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
"minecraft:set_damage" => {
|
||||
let max = self.res.items.get(&stack.item).map_or(0, |i| i.max_damage);
|
||||
let max = self
|
||||
.res
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.map_or(0, |i| i.max_damage);
|
||||
if max > 0 {
|
||||
let f = match m["damage"].as_f64() {
|
||||
Some(f) => f as f32,
|
||||
@@ -587,7 +595,7 @@ impl Game<'_> {
|
||||
if let Some(Tag::Int(n)) = s.data().and_then(|d| d.other("minecraft:max_stack_size")) {
|
||||
return (*n).clamp(1, 99) as u32;
|
||||
}
|
||||
self.res.items.get(&s.item).map_or(64, |i| i.max_stack)
|
||||
self.res.items().get(&s.item).map_or(64, |i| i.max_stack)
|
||||
}
|
||||
/// `ResourceOrIdArgument.getItemModifier`: an inline modifier (SNBT) or
|
||||
/// a registered one.
|
||||
|
||||
@@ -53,13 +53,7 @@ impl Game<'_> {
|
||||
let Ok(raw) = Compression::Gzip.decode(&bytes, 1 << 28) else {
|
||||
continue;
|
||||
};
|
||||
let Ok((named, _)) = nbt::read_named(
|
||||
&raw,
|
||||
Limits {
|
||||
max_bytes: 1 << 28,
|
||||
..Limits::default()
|
||||
},
|
||||
) else {
|
||||
let Ok((named, _)) = nbt::read_named(&raw, Limits::templates()) else {
|
||||
continue;
|
||||
};
|
||||
return Some(Arc::new(StructureTemplate::from_nbt(
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
//! Commands acting on the other players of a hosted world or a server
|
||||
//! (EntitySelector.findPlayers and EntityArgument's player targets). The
|
||||
//! player in place (the host's, or the guest whose turn it is) is
|
||||
//! `Target::Player`; every other guest is `Target::Guest`, found by name,
|
||||
//! UUID or selector, and what a command does to them runs with their state
|
||||
//! swapped in (`for_player`), as their own turn, what it tells them going to
|
||||
//! their chat.
|
||||
use super::{Game, Target};
|
||||
use horizon_client::{command::args::Selector, lan::guest::Guest, text::Text};
|
||||
use horizon_protocol::packets::play::{self, Clientbound as C};
|
||||
|
||||
impl Target {
|
||||
/// A player, in place or not (`instanceof ServerPlayer`).
|
||||
pub(in crate::game) fn is_player(self) -> bool {
|
||||
matches!(self, Target::Player | Target::Guest(_))
|
||||
}
|
||||
}
|
||||
|
||||
/// GameType.getName for a guest's game mode id.
|
||||
fn mode_name(id: i32) -> &'static str {
|
||||
match id {
|
||||
1 => "creative",
|
||||
2 => "adventure",
|
||||
3 => "spectator",
|
||||
_ => "survival",
|
||||
}
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// The guest `conn`, while the hub is in `self.lan`.
|
||||
pub(in crate::game) fn command_guest(&self, conn: u32) -> Option<&Guest> {
|
||||
self.lan.as_ref()?.hub.guest(conn)
|
||||
}
|
||||
|
||||
/// `PlayerList.getPlayers` but the player in place: the guests who
|
||||
/// joined the world.
|
||||
fn command_players(&self) -> impl Iterator<Item = &Guest> {
|
||||
let acting = self.lan_acting;
|
||||
self.lan
|
||||
.iter()
|
||||
.flat_map(|h| h.hub.guests.iter())
|
||||
.filter(move |g| g.placed && Some(g.conn) != acting)
|
||||
}
|
||||
|
||||
/// The entity the command runs as (`CommandSourceStack.getEntity`): a
|
||||
/// command typed by the player in place runs as them, the server
|
||||
/// console's as nobody.
|
||||
pub(in crate::game) fn source_entity(&self) -> Option<Target> {
|
||||
match self.command_source {
|
||||
Some(s) => s.entity,
|
||||
None => self.player.is_some().then_some(Target::Player),
|
||||
}
|
||||
}
|
||||
|
||||
/// `CommandSourceStack.getPlayerOrException` for the commands whose
|
||||
/// player argument is optional: the source's player (the player in
|
||||
/// place when it has none, as before).
|
||||
pub(in crate::game) fn implied_player(&self) -> Target {
|
||||
self.source_entity()
|
||||
.filter(|t| t.is_player())
|
||||
.unwrap_or(Target::Player)
|
||||
}
|
||||
|
||||
/// `PlayerList.getPlayerByName`: names are not case sensitive.
|
||||
pub(super) fn player_named(&self, name: &str) -> Option<Target> {
|
||||
if self.player.is_some() && name.eq_ignore_ascii_case(self.acting_player_name()) {
|
||||
return Some(Target::Player);
|
||||
}
|
||||
self.command_players()
|
||||
.find(|g| g.name.eq_ignore_ascii_case(name))
|
||||
.map(|g| Target::Guest(g.conn))
|
||||
}
|
||||
|
||||
/// `EntitySelector.findEntities` with a UUID: the player with it, else
|
||||
/// the entity.
|
||||
pub(super) fn target_by_uuid(&self, uuid: u128) -> Option<Target> {
|
||||
let own = self.lan_acting_uuid.or_else(|| {
|
||||
self.level.player_uuid.map(|[a, b, c, d]| {
|
||||
(u128::from(a as u32) << 96)
|
||||
| (u128::from(b as u32) << 64)
|
||||
| (u128::from(c as u32) << 32)
|
||||
| u128::from(d as u32)
|
||||
})
|
||||
});
|
||||
if self.player.is_some() && own == Some(uuid) {
|
||||
return Some(Target::Player);
|
||||
}
|
||||
if let Some(g) = self.command_players().find(|g| g.uuid == uuid) {
|
||||
return Some(Target::Guest(g.conn));
|
||||
}
|
||||
let words = [96, 64, 32, 0].map(|shift| (uuid >> shift) as u32 as i32);
|
||||
self.target_with_uuid(words)
|
||||
}
|
||||
|
||||
/// The guests a selector looks at, in join order (`PlayerList.getPlayers`),
|
||||
/// the one in place as `Target::Player`: all of them, or those in the
|
||||
/// source's level when it limits the search to a place
|
||||
/// (`isWorldLimited`); `@e` and `@n` skip the dead (`Entity::isAlive`).
|
||||
pub(super) fn player_candidates(&self, s: &Selector) -> Vec<Target> {
|
||||
let limited = s.distance.is_some()
|
||||
|| s.pos.iter().any(Option::is_some)
|
||||
|| s.delta.iter().any(Option::is_some);
|
||||
let alive = matches!(s.kind, 'e' | 'n');
|
||||
let here = self.dim.id();
|
||||
let in_place = self.lan_acting.filter(|_| self.player.is_some());
|
||||
self.lan
|
||||
.iter()
|
||||
.flat_map(|h| h.hub.guests.iter())
|
||||
.filter(|g| g.placed)
|
||||
.filter(|g| !limited || g.dimension == here || Some(g.conn) == in_place)
|
||||
.filter(|g| !alive || (!g.dead && g.health > 0.0))
|
||||
.map(|g| {
|
||||
if Some(g.conn) == in_place {
|
||||
Target::Player
|
||||
} else {
|
||||
Target::Guest(g.conn)
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A guest's experience level and game mode, for `level=` and `gamemode=`.
|
||||
pub(super) fn guest_level_and_mode(&self, conn: u32) -> Option<(i32, &'static str)> {
|
||||
self.command_guest(conn)
|
||||
.map(|g| (g.xp_level, mode_name(g.game_mode)))
|
||||
}
|
||||
|
||||
/// `Player.getDisplayName`: the name as its team shows it, suggesting a
|
||||
/// `/tell`, showing the player on hover, inserting the name.
|
||||
pub(in crate::game) fn player_text(&self, name: &str, uuid: u128) -> Text {
|
||||
let shown = match self.score.board.players_team(name) {
|
||||
Some(team) => team.formatted_name(Text::literal(name)),
|
||||
None => Text::literal(name),
|
||||
};
|
||||
shown.with_component_fields(vec![
|
||||
(
|
||||
"click_event".into(),
|
||||
serde_json::json!({"action": "suggest_command", "command": format!("/tell {name} ")}),
|
||||
),
|
||||
(
|
||||
"hover_event".into(),
|
||||
serde_json::json!({"action": "show_entity", "id": "minecraft:player",
|
||||
"uuid": horizon_protocol::crypto::uuid_string(uuid), "name": name}),
|
||||
),
|
||||
("insertion".into(), name.into()),
|
||||
])
|
||||
}
|
||||
|
||||
/// Run `f` for the player `t` (None for anything else): in place, or
|
||||
/// with the guest's state swapped in, in their level, as their own turn.
|
||||
/// What `f` tells the player (`system_message`) goes to their chat; the
|
||||
/// command's own feedback is the caller's to send.
|
||||
pub(in crate::game) fn for_player<T>(
|
||||
&mut self,
|
||||
t: Target,
|
||||
f: impl FnOnce(&mut Self) -> T,
|
||||
) -> Option<T> {
|
||||
let conn = match t {
|
||||
Target::Player => return Some(f(self)),
|
||||
Target::Guest(conn) if self.lan_acting == Some(conn) => return Some(f(self)),
|
||||
Target::Guest(conn) => conn,
|
||||
_ => return None,
|
||||
};
|
||||
let mut host = self.lan.take()?;
|
||||
let back = self.dim;
|
||||
let theirs = host
|
||||
.hub
|
||||
.guest(conn)
|
||||
.map(|g| super::super::Dim::from_id(&g.dimension));
|
||||
if let Some(dim) = theirs.filter(|d| *d != back)
|
||||
&& let Err(e) = self.enter_level(Some(&mut host), dim)
|
||||
{
|
||||
log::error!("could not open {}: {e}", dim.id());
|
||||
}
|
||||
let Some(swap) = self.enter_guest(&mut host, conn) else {
|
||||
if self.dim != back
|
||||
&& let Err(e) = self.enter_level(Some(&mut host), back)
|
||||
{
|
||||
log::error!("could not reopen {}: {e}", back.id());
|
||||
}
|
||||
self.lan = Some(host);
|
||||
return None;
|
||||
};
|
||||
self.lan = Some(host);
|
||||
let source = self.chat_capture.replace(Vec::new());
|
||||
let out = f(self);
|
||||
let told = std::mem::replace(&mut self.chat_capture, source).unwrap_or_default();
|
||||
let mut host = self
|
||||
.lan
|
||||
.take()
|
||||
.expect("the hub is back after a player's turn");
|
||||
self.leave_guest(&mut host, swap);
|
||||
for line in told {
|
||||
host.hub.send_to(
|
||||
conn,
|
||||
&C::SystemChat(play::SystemChat {
|
||||
content: horizon_client::lan::data::component_nbt(&line.component()),
|
||||
overlay: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if self.dim != back
|
||||
&& let Err(e) = self.enter_level(Some(&mut host), back)
|
||||
{
|
||||
log::error!("could not reopen {}: {e}", back.id());
|
||||
}
|
||||
self.lan = Some(host);
|
||||
Some(out)
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,7 @@ impl Game<'_> {
|
||||
if volume > i64::from(limit) {
|
||||
return Err(err("commands.fillbiome.toobig", &[&limit, &volume]));
|
||||
}
|
||||
let Some(target) = self.res.biomes.list.iter().position(|b| b.name == biome) else {
|
||||
let Some(target) = self.res.biomes().list.iter().position(|b| b.name == biome) else {
|
||||
return Err(err(
|
||||
"argument.resource.not_found",
|
||||
&[&biome, &"minecraft:worldgen/biome"],
|
||||
@@ -201,7 +201,7 @@ impl Game<'_> {
|
||||
continue;
|
||||
};
|
||||
let current = chunk.biome(x, y, z);
|
||||
let current_name = &self.res.biomes.list[usize::from(current)].name;
|
||||
let current_name = &self.res.biomes().list[usize::from(current)].name;
|
||||
if let Some(f) = &filter
|
||||
&& !self.biome_matches(f, current_name)
|
||||
{
|
||||
@@ -474,11 +474,11 @@ impl Game<'_> {
|
||||
let json = horizon_client::scoreboard::tag_to_json(&tag);
|
||||
let drops = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.inline_loot_table(&json, &mut self.world.random);
|
||||
(drops, None)
|
||||
} else {
|
||||
if !self.res.items.has_loot_table(&table) {
|
||||
if !self.res.items().has_loot_table(&table) {
|
||||
return Err(err("argument.resource_or_id.failed_to_parse", &[&table]));
|
||||
}
|
||||
let held = if id == "loot.fish" {
|
||||
@@ -486,14 +486,14 @@ impl Game<'_> {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let drops = match self.res.items.loot_sequence(&table) {
|
||||
let drops = match self.res.items().loot_sequence(&table) {
|
||||
Some(seq) => {
|
||||
let random = self.rand_sequences.get(&seq, self.level.seed);
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.loot_table(&table, false, held.as_ref(), random)
|
||||
}
|
||||
None => self.res.items.loot_table(
|
||||
None => self.res.items().loot_table(
|
||||
&table,
|
||||
false,
|
||||
held.as_ref(),
|
||||
@@ -510,7 +510,7 @@ impl Game<'_> {
|
||||
};
|
||||
let ty = self.target_type(t);
|
||||
let table = format!("minecraft:entities/{}", ty.trim_start_matches("minecraft:"));
|
||||
if t == Target::Player || !self.res.items.has_loot_table(&table) {
|
||||
if t == Target::Player || !self.res.items().has_loot_table(&table) {
|
||||
return Err(err(
|
||||
"commands.drop.no_loot_table.entity",
|
||||
&[&self.target_name(t).plain()],
|
||||
@@ -521,14 +521,14 @@ impl Game<'_> {
|
||||
None | Some(Some(Target::Player))
|
||||
);
|
||||
let held = self.slot_get(&super::items::Slot::Inv(self.selected));
|
||||
let drops = match self.res.items.loot_sequence(&table) {
|
||||
let drops = match self.res.items().loot_sequence(&table) {
|
||||
Some(seq) => {
|
||||
let random = self.rand_sequences.get(&seq, self.level.seed);
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.entity_drops(&ty, by_player, held.as_ref(), random)
|
||||
}
|
||||
None => self.res.items.entity_drops(
|
||||
None => self.res.items().entity_drops(
|
||||
&ty,
|
||||
by_player,
|
||||
held.as_ref(),
|
||||
@@ -543,21 +543,21 @@ impl Game<'_> {
|
||||
let state = self.world.block(p[0], p[1], p[2]);
|
||||
let name = self.data_block_name(p);
|
||||
let table = format!("minecraft:blocks/{}", name.trim_start_matches("minecraft:"));
|
||||
if !self.res.items.has_loot_table(&table) {
|
||||
if !self.res.items().has_loot_table(&table) {
|
||||
return Err(err("commands.drop.no_loot_table.block", &[&name]));
|
||||
}
|
||||
let tool = self.tool_stack(ctx)?;
|
||||
let drops = match self.res.items.loot_sequence(&table) {
|
||||
let drops = match self.res.items().loot_sequence(&table) {
|
||||
Some(seq) => {
|
||||
let random = self.rand_sequences.get(&seq, self.level.seed);
|
||||
self.res.items.block_drops(
|
||||
self.res.items().block_drops(
|
||||
self.pack.assets.registry,
|
||||
state,
|
||||
tool.as_ref(),
|
||||
random,
|
||||
)
|
||||
}
|
||||
None => self.res.items.block_drops(
|
||||
None => self.res.items().block_drops(
|
||||
self.pack.assets.registry,
|
||||
state,
|
||||
tool.as_ref(),
|
||||
@@ -624,7 +624,7 @@ impl Game<'_> {
|
||||
&& cur.damage == left.damage
|
||||
&& cur.extra == left.extra =>
|
||||
{
|
||||
let max = self.res.items.get(&cur.item).map_or(64, |i| i.max_stack);
|
||||
let max = self.res.items().get(&cur.item).map_or(64, |i| i.max_stack);
|
||||
let take = left.count.min(max.saturating_sub(cur.count));
|
||||
if take > 0 {
|
||||
cur.count += take;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! `/tellraw` (TellRawCommand) and `/title` (TitleCommand).
|
||||
use super::{Arg, Context, Game, R, Target, err};
|
||||
use horizon_client::text::Text;
|
||||
use horizon_client::{hud_overlays::Titles, lan::data::component_nbt, text::Text};
|
||||
use horizon_protocol::packets::play::{self, Clientbound as C};
|
||||
|
||||
impl Game<'_> {
|
||||
/// ComponentArgument with selectors resolved for the source
|
||||
@@ -153,30 +154,45 @@ impl Game<'_> {
|
||||
let name = self.target_name(Target::Player);
|
||||
let single = n == 1;
|
||||
let key = if ctx.has("clear") {
|
||||
self.titles.clear();
|
||||
self.titles_or_packet(Titles::clear, C::ClearTitles(play::Bool1 { value: false }));
|
||||
"cleared"
|
||||
} else if ctx.has("reset") {
|
||||
self.titles.clear();
|
||||
self.titles.reset_times();
|
||||
self.titles_or_packet(
|
||||
|t| {
|
||||
t.clear();
|
||||
t.reset_times();
|
||||
},
|
||||
C::ClearTitles(play::Bool1 { value: true }),
|
||||
);
|
||||
"reset"
|
||||
} else if ctx.has("times") {
|
||||
let get = |k: &str| match ctx.get(k) {
|
||||
Some(Arg::Int(v)) => *v,
|
||||
_ => -1,
|
||||
};
|
||||
self.titles
|
||||
.set_times(get("fadeIn"), get("stay"), get("fadeOut"));
|
||||
let (fade_in, stay, fade_out) = (get("fadeIn"), get("stay"), get("fadeOut"));
|
||||
self.titles_or_packet(
|
||||
|t| t.set_times(fade_in, stay, fade_out),
|
||||
C::SetTitlesAnimation(play::TitlesAnimation {
|
||||
fade_in,
|
||||
stay,
|
||||
fade_out,
|
||||
}),
|
||||
);
|
||||
"times"
|
||||
} else {
|
||||
let text = self.component_arg(ctx, "title")?;
|
||||
let sent = play::Text {
|
||||
text: component_nbt(&text.component()),
|
||||
};
|
||||
if ctx.has("subtitle") {
|
||||
self.titles.set_subtitle(text);
|
||||
self.titles_or_packet(|t| t.set_subtitle(text), C::SetSubtitleText(sent));
|
||||
"show.subtitle"
|
||||
} else if ctx.has("actionbar") {
|
||||
self.titles.set_overlay(text, false);
|
||||
self.titles_or_packet(|t| t.set_overlay(text, false), C::SetActionBarText(sent));
|
||||
"show.actionbar"
|
||||
} else {
|
||||
self.titles.set_title(text);
|
||||
self.titles_or_packet(|t| t.set_title(text), C::SetTitleText(sent));
|
||||
"show.title"
|
||||
}
|
||||
};
|
||||
@@ -191,4 +207,13 @@ impl Game<'_> {
|
||||
self.feedback(message);
|
||||
Ok(n as i32)
|
||||
}
|
||||
/// The player the title is for: the guest acting now is sent the packet
|
||||
/// (TitleCommand's `connection.send`), the window's own player shows it.
|
||||
fn titles_or_packet(&mut self, local: impl FnOnce(&mut Titles), packet: C) {
|
||||
if self.lan_acting.is_some() {
|
||||
self.guest_packets.push(packet);
|
||||
} else {
|
||||
local(&mut self.titles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ impl Game<'_> {
|
||||
|
||||
/// Every recipe id of the recipe manager (what `/recipe` resolves and suggests).
|
||||
pub(super) fn learnable_recipes(&self) -> Vec<String> {
|
||||
self.res.stations.recipe_index.ids().cloned().collect()
|
||||
self.res.stations().recipe_index.ids().cloned().collect()
|
||||
}
|
||||
pub(super) fn cmd_recipe(&mut self, id: &str, ctx: &Context) -> R<i32> {
|
||||
let targets = self.entities(ctx, "targets", true)?;
|
||||
@@ -52,7 +52,7 @@ impl Game<'_> {
|
||||
// displays (a transmute recipe has one per material count).
|
||||
let mut n = 0;
|
||||
// ServerPlayer.awardRecipes / resetRecipes: the displays changed.
|
||||
let index = &self.res.stations.recipe_index;
|
||||
let index = &self.res.stations().recipe_index;
|
||||
n += if give {
|
||||
let (count, unlocked) = self.level.recipe_book.add_recipes(index, &recipes);
|
||||
self.recipe_unlocked(&unlocked);
|
||||
@@ -1267,7 +1267,7 @@ impl Game<'_> {
|
||||
fn spread_spawn_y(&self, p: [f64; 2], max_y: i32) -> i32 {
|
||||
let (x, z) = (p[0].floor() as i32, p[1].floor() as i32);
|
||||
let air = |y: i32| {
|
||||
let name: &str = &self.res.facts.get(self.world.block(x, y, z)).name;
|
||||
let name: &str = &self.res.facts().get(self.world.block(x, y, z)).name;
|
||||
matches!(
|
||||
name,
|
||||
"minecraft:air" | "minecraft:cave_air" | "minecraft:void_air"
|
||||
@@ -1292,16 +1292,16 @@ impl Game<'_> {
|
||||
fn spread_safe(&self, p: [f64; 2], max_y: i32) -> bool {
|
||||
let y = self.spread_spawn_y(p, max_y) - 1;
|
||||
let (x, z) = (p[0].floor() as i32, p[1].floor() as i32);
|
||||
let name = self.res.facts.get(self.world.block(x, y, z)).name.clone();
|
||||
let name = self.res.facts().get(self.world.block(x, y, z)).name.clone();
|
||||
let liquid = matches!(&*name, "minecraft:water" | "minecraft:lava");
|
||||
let teleportable = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get("entities_can_teleport_to")
|
||||
.or_else(|| {
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get("minecraft:entities_can_teleport_to")
|
||||
})
|
||||
|
||||
@@ -21,7 +21,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// The item's `compostable` layers provider.
|
||||
fn compostable(&self, stack: &ItemStack) -> Option<serde_json::Value> {
|
||||
self.res.items.get(&stack.item)?.compostable.clone()
|
||||
self.res.items().get(&stack.item)?.compostable.clone()
|
||||
}
|
||||
/// `ComposterBlock.addLayer` and level event 1500: the provider is
|
||||
/// evaluated in the composter's block-interaction loot context (its
|
||||
|
||||
@@ -0,0 +1,330 @@
|
||||
//! Finishing a consumable (`Consumable.onConsume` and the use remainder),
|
||||
//! its particles and sounds, and `TeleportRandomlyConsumeEffect` (chorus
|
||||
//! fruit) for the local player. The level random stands in for the player's
|
||||
//! own, as for every other player draw.
|
||||
use super::{Dim, Game};
|
||||
use horizon_client::{
|
||||
items::{ConsumeEffect, ItemInfo, ItemStack},
|
||||
mobs::Who,
|
||||
particles::{ParticleOptions, ParticleType},
|
||||
};
|
||||
use horizon_core::{
|
||||
geometry::Vec3, position::BlockPos, random::LegacyRandom, random::RandomSource,
|
||||
};
|
||||
use horizon_world::{
|
||||
consumable::{Consumable, EmissionWorld, UseAnimation},
|
||||
teleport_consume::{TeleportConsume, TeleportConsumeWorld},
|
||||
};
|
||||
use std::convert::Infallible;
|
||||
|
||||
type ItemConsumable = Consumable<String, ConsumeEffect>;
|
||||
|
||||
impl Game<'_> {
|
||||
/// `Consumable.emitParticlesAndSounds(user.getRandom(), user, stack, count)`.
|
||||
pub(super) fn emit_consume(
|
||||
&mut self,
|
||||
consumable: &ItemConsumable,
|
||||
stack: &ItemStack,
|
||||
count: i32,
|
||||
) {
|
||||
let Ok(()) = consumable.emit(&mut Emitter(self), (), stack.clone(), count);
|
||||
}
|
||||
/// `LivingEntity.completeUsingItem` for a consumable: `Consumable.onConsume`,
|
||||
/// then `ItemStack.applyAfterUseComponentSideEffects`' use remainder.
|
||||
pub(super) fn finish_consuming(
|
||||
&mut self,
|
||||
info: &ItemInfo,
|
||||
consumable: &ItemConsumable,
|
||||
stack: &ItemStack,
|
||||
) {
|
||||
self.emit_consume(consumable, stack, 16);
|
||||
// ServerPlayer: the used statistic and the consume_item trigger.
|
||||
self.stats.add("used", &stack.item, 1);
|
||||
self.trigger_item("minecraft:consume_item", stack);
|
||||
// FoodProperties.onConsume, the player's one ConsumableListener.
|
||||
if let Some((nutrition, saturation)) = info.food {
|
||||
let at = self.feet();
|
||||
let pitch = self.world.random.triangle_float(1.0, 0.4);
|
||||
self.audio.play(&consumable.sound, at, 1.0, pitch);
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
// FoodData.eat(nutrition, saturation)
|
||||
let food = &mut p.health.food;
|
||||
food.food = (food.food + nutrition as i32).clamp(0, 20);
|
||||
food.saturation = (food.saturation + saturation).clamp(0.0, food.food as f32);
|
||||
}
|
||||
// Mth.randomBetween(random, 0.9, 1.0)
|
||||
let pitch = self.world.random.next_float() * (1.0f32 - 0.9f32) + 0.9;
|
||||
self.audio
|
||||
.play("minecraft:entity.player.burp", self.feet(), 0.5, pitch);
|
||||
}
|
||||
for effect in &consumable.effects {
|
||||
self.apply_consume_effect(effect);
|
||||
}
|
||||
let event = if consumable.animation == UseAnimation::Drink {
|
||||
"minecraft:drink"
|
||||
} else {
|
||||
"minecraft:eat"
|
||||
};
|
||||
self.post_entity_event(event, Who::Player);
|
||||
// ItemStack.consume, then UseRemainder.convertIntoRemainder: nothing
|
||||
// with infinite materials, the hand when emptied, else the inventory
|
||||
// (ServerPlayer.handleExtraItemsCreatedOnUse) or a drop.
|
||||
self.consume_held();
|
||||
if let Some(remainder) = &info.use_remainder
|
||||
&& !self.creative
|
||||
{
|
||||
let remainder = ItemStack::new(remainder, 1);
|
||||
if self.held().is_none() {
|
||||
*self.held_mut() = Some(remainder);
|
||||
} else if let Some(rest) = self.give(remainder) {
|
||||
self.player_drop(rest);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn feet(&self) -> Option<[f64; 3]> {
|
||||
self.player
|
||||
.as_ref()
|
||||
.map(|p| [p.position.x, p.position.y, p.position.z])
|
||||
}
|
||||
/// `TeleportRandomlyConsumeEffect.apply` for the local player.
|
||||
pub(super) fn teleport_randomly(&mut self, teleport: &TeleportConsume) {
|
||||
if self.player.is_none() {
|
||||
return;
|
||||
}
|
||||
let dim = self.dim;
|
||||
let Ok(_) = teleport.apply(&mut Teleporter(self), dim);
|
||||
}
|
||||
/// `LivingEntity.randomTeleport(x, y, z, true, avoid)`: down to the first
|
||||
/// block entities can teleport onto, inside the border, in a loaded chunk.
|
||||
fn random_teleport(&mut self, target: Vec3, avoid: &str) -> bool {
|
||||
let [min_x, min_z, max_x, max_z] = self.border.bounds();
|
||||
// WorldBorder.clampVec3ToBound (Mth.clamp, 1.0E-5F inside the far edge).
|
||||
let clamp = |v: f64, low: f64, high: f64| if v < low { low } else { v.min(high) };
|
||||
let x = clamp(target.x, min_x, max_x - f64::from(1.0e-5_f32));
|
||||
let z = clamp(target.z, min_z, max_z - f64::from(1.0e-5_f32));
|
||||
let mut y = target.y;
|
||||
let mut pos = BlockPos::containing(Vec3::new(x, y, z));
|
||||
if !self.world.loaded(pos.x, pos.z) {
|
||||
return false;
|
||||
}
|
||||
while pos.y > self.dim.min_y() {
|
||||
pos.y -= 1;
|
||||
let state = self.world.block(pos.x, pos.y, pos.z);
|
||||
if self.state_in_tag("minecraft:entities_can_teleport_to", state) {
|
||||
return self.check_position_and_teleport(Vec3::new(x, y, z), state, avoid);
|
||||
}
|
||||
y -= 1.0;
|
||||
}
|
||||
false
|
||||
}
|
||||
/// `LivingEntity.checkPositionAndTeleport`, then `ServerPlayer.teleportTo`
|
||||
/// (the motion and rotation kept) and entity event 46.
|
||||
fn check_position_and_teleport(
|
||||
&mut self,
|
||||
at: Vec3,
|
||||
ground: horizon_world::registry::BlockStateId,
|
||||
avoid: &str,
|
||||
) -> bool {
|
||||
if self.state_in_tag(avoid, ground) {
|
||||
return false;
|
||||
}
|
||||
let entities = self.happy_ghast_player_collisions();
|
||||
let Some(player) = self.player.as_mut() else {
|
||||
return false;
|
||||
};
|
||||
let bounds = player.dimensions.bounds(at);
|
||||
let free = horizon_client::motion::MotionWorld {
|
||||
entities: &entities,
|
||||
player,
|
||||
scene: &mut self.world,
|
||||
assets: &self.pack.assets,
|
||||
collision_binding: self.collision,
|
||||
resources: self.motion,
|
||||
}
|
||||
.no_player_collision(bounds)
|
||||
.unwrap_or(false);
|
||||
// LevelReader.containsAnyLiquid and findBlocksIn: the blocks from the
|
||||
// box's minimum corner to the one holding its maximum corner.
|
||||
let (lo, hi) = (
|
||||
BlockPos::containing(bounds.min_position()),
|
||||
BlockPos::containing(bounds.max_position()),
|
||||
);
|
||||
let blocks = (lo.x..=hi.x)
|
||||
.flat_map(|x| (lo.y..=hi.y).flat_map(move |y| (lo.z..=hi.z).map(move |z| (x, y, z))));
|
||||
let states: Vec<_> = blocks.map(|(x, y, z)| self.world.block(x, y, z)).collect();
|
||||
let liquid = states
|
||||
.iter()
|
||||
.any(|&s| self.res.facts().get(s).fluid != horizon_client::blocks::Fluid::None);
|
||||
if !free || liquid || states.iter().any(|&s| self.state_in_tag(avoid, s)) {
|
||||
return false;
|
||||
}
|
||||
if let Some(p) = self.player.as_mut() {
|
||||
p.position = at;
|
||||
}
|
||||
// The position packet moves the old position along (absolute xyz).
|
||||
self.previous_position = at;
|
||||
self.portal_particles();
|
||||
true
|
||||
}
|
||||
fn state_in_tag(&self, tag: &str, state: horizon_world::registry::BlockStateId) -> bool {
|
||||
let name = &self.res.facts().get(state).name;
|
||||
self.res
|
||||
.items()
|
||||
.block_tags
|
||||
.get(tag)
|
||||
.is_some_and(|s| s.contains(&**name))
|
||||
}
|
||||
/// `LivingEntity.handleEntityEvent(46)`: 128 portal particles from the old
|
||||
/// to the new position, from the client player's random (the particle
|
||||
/// engine's here).
|
||||
fn portal_particles(&mut self) {
|
||||
let Some(p) = self.player.as_ref() else {
|
||||
return;
|
||||
};
|
||||
let (from, to) = (self.previous_position, p.position);
|
||||
let (width, height) = (
|
||||
f64::from(p.dimensions.width),
|
||||
f64::from(p.dimensions.height),
|
||||
);
|
||||
let options = ParticleOptions::simple(ParticleType::Portal);
|
||||
for i in 0..128 {
|
||||
let d = f64::from(i) / 127.0;
|
||||
let r = self.particles.random();
|
||||
let v = [0; 3].map(|_| f64::from((r.next_float() - 0.5) * 0.2));
|
||||
let x = from.x + d * (to.x - from.x) + (r.next_double() - 0.5) * width * 2.0;
|
||||
let y = from.y + d * (to.y - from.y) + r.next_double() * height;
|
||||
let z = from.z + d * (to.z - from.z) + (r.next_double() - 0.5) * width * 2.0;
|
||||
self.particles.add(&options, [x, y, z], v);
|
||||
}
|
||||
}
|
||||
/// `LivingEntity.stopRiding`.
|
||||
pub(super) fn stop_riding(&mut self) {
|
||||
let Some(id) = self.riding else {
|
||||
return;
|
||||
};
|
||||
if let Some(i) = self.boats.iter().position(|b| b.id == id) {
|
||||
self.dismount(i);
|
||||
} else if let Some(i) = self.carts.iter().position(|c| c.id == id) {
|
||||
self.dismount_cart(i);
|
||||
} else {
|
||||
self.dismount_mount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `Consumable.emitParticlesAndSounds` against the local player.
|
||||
struct Emitter<'a, 'g>(&'a mut Game<'g>);
|
||||
impl EmissionWorld for Emitter<'_, '_> {
|
||||
type Error = Infallible;
|
||||
type Stack = ItemStack;
|
||||
type Sound = String;
|
||||
type Random = ();
|
||||
type Source = LegacyRandom;
|
||||
fn random_source(&mut self, (): ()) -> &mut LegacyRandom {
|
||||
&mut self.0.world.random
|
||||
}
|
||||
/// `LivingEntity.spawnItemParticles`.
|
||||
fn spawn_item_particles(&mut self, stack: ItemStack, count: i32) -> Result<(), Infallible> {
|
||||
self.0.eat_particles(&stack, count.max(0) as u32);
|
||||
Ok(())
|
||||
}
|
||||
fn overrides_consume_sound(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn consume_sound(&mut self, _: ItemStack) -> Result<String, Infallible> {
|
||||
unreachable!("players play the consumable's own sound")
|
||||
}
|
||||
/// `Entity.playSound`: at the player's position.
|
||||
fn play_sound(&mut self, sound: String, volume: f32, pitch: f32) -> Result<(), Infallible> {
|
||||
let at = self.0.feet();
|
||||
self.0.audio.play(&sound, at, volume, pitch);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// The local player as `TeleportRandomlyConsumeEffect`'s user.
|
||||
struct Teleporter<'a, 'g>(&'a mut Game<'g>);
|
||||
impl Teleporter<'_, '_> {
|
||||
fn at(&self) -> Vec3 {
|
||||
self.0.player.as_ref().map_or(Vec3::ZERO, |p| p.position)
|
||||
}
|
||||
}
|
||||
impl TeleportConsumeWorld for Teleporter<'_, '_> {
|
||||
type Error = Infallible;
|
||||
type Level = Dim;
|
||||
type Random = ();
|
||||
type Source = LegacyRandom;
|
||||
fn position_field(&self) -> Vec3 {
|
||||
self.at()
|
||||
}
|
||||
fn get_random(&mut self) -> Result<(), Infallible> {
|
||||
Ok(())
|
||||
}
|
||||
fn random_source(&mut self, (): ()) -> &mut LegacyRandom {
|
||||
&mut self.0.world.random
|
||||
}
|
||||
fn min_y(&mut self, level: Dim) -> Result<i32, Infallible> {
|
||||
Ok(level.min_y())
|
||||
}
|
||||
fn logical_height(&mut self, level: Dim) -> Result<i32, Infallible> {
|
||||
Ok(level.logical_height())
|
||||
}
|
||||
fn is_passenger(&mut self) -> Result<bool, Infallible> {
|
||||
Ok(self.0.riding.is_some())
|
||||
}
|
||||
fn stop_riding(&mut self) -> Result<(), Infallible> {
|
||||
self.0.stop_riding();
|
||||
Ok(())
|
||||
}
|
||||
fn position(&mut self) -> Result<Vec3, Infallible> {
|
||||
Ok(self.at())
|
||||
}
|
||||
fn random_teleport(&mut self, target: Vec3) -> Result<bool, Infallible> {
|
||||
Ok(self
|
||||
.0
|
||||
.random_teleport(target, "minecraft:consumable_does_not_teleport_to"))
|
||||
}
|
||||
fn teleport_event(&mut self, _: Dim, old: Vec3) -> Result<(), Infallible> {
|
||||
let ctx = self.0.who_context(Some(Who::Player), None);
|
||||
self.0
|
||||
.post_game_event("minecraft:teleport", [old.x, old.y, old.z], ctx);
|
||||
Ok(())
|
||||
}
|
||||
fn is_fox(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn teleport_sound(&mut self, _: Dim, at: Vec3, _: bool) -> Result<(), Infallible> {
|
||||
self.0.audio.play(
|
||||
"minecraft:item.chorus_fruit.teleport",
|
||||
Some([at.x, at.y, at.z]),
|
||||
1.0,
|
||||
1.0,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
fn block_position(&mut self) -> Result<BlockPos, Infallible> {
|
||||
Ok(BlockPos::containing(self.at()))
|
||||
}
|
||||
fn directional_particles(
|
||||
&mut self,
|
||||
_: Dim,
|
||||
origin: BlockPos,
|
||||
offset: i32,
|
||||
) -> Result<(), Infallible> {
|
||||
self.0
|
||||
.level_event_at(2017, [origin.x, origin.y, origin.z], offset);
|
||||
Ok(())
|
||||
}
|
||||
fn reset_fall_distance(&mut self) -> Result<(), Infallible> {
|
||||
if let Some(p) = self.0.player.as_mut() {
|
||||
p.fall_distance = 0.0;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn reset_impulse(&mut self) -> Result<(), Infallible> {
|
||||
if let Some(p) = self.0.player.as_mut() {
|
||||
p.impulse.reset();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -54,12 +54,23 @@ pub struct Flight {
|
||||
/// Reply with every frame time too (`fly ... PITCH raw`).
|
||||
raw: bool,
|
||||
reply: Sender<String>,
|
||||
/// The world's smoothed tick time each frame (the F3 server line): the
|
||||
/// server thread's when single player runs on one.
|
||||
tick_ms: Vec<f32>,
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// Move the camera along the running flight; reply when it ends.
|
||||
pub(super) fn advance_flight(&mut self) {
|
||||
let Some(flight) = &self.flight else { return };
|
||||
let tick_ms = self
|
||||
.integrated
|
||||
.as_ref()
|
||||
.map_or(self.debug_charts.smoothed_tick_ms, |s| s.smoothed_tick_ms());
|
||||
let Some(flight) = self.flight.as_mut() else {
|
||||
return;
|
||||
};
|
||||
flight.tick_ms.push(tick_ms);
|
||||
let flight = &*flight;
|
||||
let t = (flight.started.elapsed().as_secs_f64() / flight.seconds).min(1.0);
|
||||
let (a, b) = (flight.from, flight.to);
|
||||
let d = [b.x - a.x, b.y - a.y, b.z - a.z];
|
||||
@@ -79,6 +90,9 @@ impl Game<'_> {
|
||||
&& let Some(flight) = self.flight.take()
|
||||
{
|
||||
let mut summary = self.frame_stats.summary();
|
||||
let n = flight.tick_ms.len().max(1) as f32;
|
||||
summary["tick_ms"] = (flight.tick_ms.iter().sum::<f32>() / n).into();
|
||||
summary["tick_ms_max"] = flight.tick_ms.iter().copied().fold(0.0, f32::max).into();
|
||||
if flight.raw {
|
||||
summary["frame_ms"] = self.frame_stats.frame_millis().into();
|
||||
summary["cpu_ms"] = self.frame_stats.cpu_millis().into();
|
||||
@@ -183,6 +197,16 @@ impl Game<'_> {
|
||||
}
|
||||
Ok(Some(json!({ "ok": true, "flat": r.flat_draws() })))
|
||||
}
|
||||
"section-cull" => {
|
||||
let r = self.renderer.as_mut().ok_or("no renderer")?;
|
||||
match words.get(1).copied() {
|
||||
None => {}
|
||||
Some("on") => r.set_section_cull(true)?,
|
||||
Some("off") => r.set_section_cull(false)?,
|
||||
Some(other) => return Err(format!("unknown section cull mode {other}").into()),
|
||||
}
|
||||
Ok(Some(json!({ "ok": true, "cull": r.section_cull() })))
|
||||
}
|
||||
"sculk" => Ok(Some(self.sculk_command(&words)?)),
|
||||
"status" => Ok(Some(self.control_status())),
|
||||
"pad" => Ok(Some(self.pad_command(&words)?)),
|
||||
@@ -345,10 +369,18 @@ impl Game<'_> {
|
||||
};
|
||||
let info = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&item)
|
||||
.ok_or_else(|| format!("unknown item {item}"))?;
|
||||
let count: u32 = words.get(2).map_or(Ok(1), |c| c.parse())?;
|
||||
// Single player's inventory is its server thread's player's.
|
||||
if let Some(server) = &self.integrated {
|
||||
let command = format!("give @s {item} {count}");
|
||||
server
|
||||
.call(move |g| g.owner_console_command(&command))
|
||||
.ok_or("the integrated server stopped")?;
|
||||
return Ok(Some(json!({ "ok": true, "given": count })));
|
||||
}
|
||||
let max = info.max_stack;
|
||||
let mut given = 0;
|
||||
// Stop once the inventory is full.
|
||||
@@ -379,7 +411,14 @@ impl Game<'_> {
|
||||
ok()
|
||||
}
|
||||
"time" => {
|
||||
self.world.day_time = arg(1)?.parse()?;
|
||||
let time: i64 = arg(1)?.parse()?;
|
||||
self.world.day_time = time;
|
||||
// Single player's clock is its server thread's.
|
||||
if let Some(server) = &self.integrated {
|
||||
server
|
||||
.call(move |g| g.world.day_time = time)
|
||||
.ok_or("the integrated server stopped")?;
|
||||
}
|
||||
ok()
|
||||
}
|
||||
"summon" => {
|
||||
@@ -437,7 +476,7 @@ impl Game<'_> {
|
||||
match self.screen {
|
||||
Screen::Chat => self.chat_type(text),
|
||||
Screen::CommandBlock => self.command_block_type(text),
|
||||
Screen::Options => self.ui.options.type_text(&self.atlas, text),
|
||||
Screen::Options => self.ui.options.type_text(&self.gui.atlas, text),
|
||||
// The port, or the game rules' search and number boxes.
|
||||
Screen::WorldOptions if text == "\\b" => self.world_options_text(None),
|
||||
Screen::WorldOptions => self.world_options_text(Some(text)),
|
||||
@@ -527,6 +566,7 @@ impl Game<'_> {
|
||||
seconds: n(7)?.max(0.1),
|
||||
raw: words.get(9) == Some(&"raw"),
|
||||
reply: reply.clone(),
|
||||
tick_ms: Vec::new(),
|
||||
});
|
||||
Ok(None)
|
||||
}
|
||||
@@ -661,7 +701,7 @@ impl Game<'_> {
|
||||
});
|
||||
let target = self.pick().map(|hit| {
|
||||
let state = self.world.block(hit.pos[0], hit.pos[1], hit.pos[2]);
|
||||
json!({ "pos": hit.pos, "block": &*self.res.facts.get(state).name })
|
||||
json!({ "pos": hit.pos, "block": &*self.res.facts().get(state).name })
|
||||
});
|
||||
let renderer = self.renderer.as_ref().map(|r| {
|
||||
let [arena_bytes, section_vertex_bytes] = r.section_vertex_bytes();
|
||||
@@ -684,6 +724,7 @@ impl Game<'_> {
|
||||
"drawn_sections": r.drawn_sections,
|
||||
"section_draws": r.section_draws,
|
||||
"section_draw_calls": r.section_draw_calls,
|
||||
"culled_sections": r.culled_sections(),
|
||||
"uploaded_bytes": r.uploaded_bytes,
|
||||
"resident_sections": r.resident_sections(),
|
||||
"arena_bytes": arena_bytes,
|
||||
@@ -758,6 +799,10 @@ impl Game<'_> {
|
||||
.map(|e| self.shown_name_tags(glam::DVec3::from_array(e))),
|
||||
});
|
||||
status["physical_keys"] = json!(physical_keys);
|
||||
// Boats, minecarts, armor stands, item frames and paintings.
|
||||
status["objects"] = json!(self.objects_status());
|
||||
// Primed TNT, falling blocks, projectiles, tridents and end crystals.
|
||||
status["projectiles"] = json!(self.projectiles_status());
|
||||
status
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ impl Game<'_> {
|
||||
fn golem_chest_sound(&mut self, p: [i32; 3], open: bool) {
|
||||
let name = self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(p[0], p[1], p[2]))
|
||||
.name
|
||||
.clone();
|
||||
@@ -292,7 +292,7 @@ impl Game<'_> {
|
||||
pub(super) fn golem_shearable(&self, index: usize) -> bool {
|
||||
self.mobs[index].saddle_item().is_some_and(|a| {
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.item_tags
|
||||
.get("minecraft:shearable_from_copper_golem")
|
||||
.is_some_and(|t| t.contains(&*a.item))
|
||||
|
||||
@@ -110,7 +110,7 @@ impl Game<'_> {
|
||||
let mut next_entity = self.next_entity;
|
||||
let mut random = self.world.random.clone();
|
||||
let spawning = self.spawning_monsters();
|
||||
let creaking = self.res.mob_types.get("minecraft:creaking").cloned();
|
||||
let creaking = self.res.mob_types().get("minecraft:creaking").cloned();
|
||||
let player_uuid = self.level.player_uuid;
|
||||
let snapshot: Vec<_> = mobs.iter().map(|m| seen(m, player_uuid)).collect();
|
||||
let mut events = Vec::new();
|
||||
@@ -164,7 +164,7 @@ impl Game<'_> {
|
||||
return;
|
||||
}
|
||||
let key = (home[0], home[1], home[2]);
|
||||
let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.remove(&key)
|
||||
let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.take(&key)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
@@ -173,7 +173,7 @@ impl Game<'_> {
|
||||
});
|
||||
self.world
|
||||
.block_entities
|
||||
.insert(key, BlockEntity::CreakingHeart(heart));
|
||||
.put(key, BlockEntity::CreakingHeart(heart));
|
||||
}
|
||||
/// `Creaking.tearDown`: the crumble particles.
|
||||
pub(super) fn creaking_tear_down(&mut self, center: [f64; 3], spread: [f64; 3]) {
|
||||
@@ -220,7 +220,13 @@ impl Game<'_> {
|
||||
/// death and a natural heart drops experience.
|
||||
pub(super) fn creaking_heart_broken(&mut self, pos: [i32; 3]) {
|
||||
let key = (pos[0], pos[1], pos[2]);
|
||||
let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.remove(&key)
|
||||
if !matches!(
|
||||
self.world.block_entities.get(&key),
|
||||
Some(BlockEntity::CreakingHeart(_))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.take(&key)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
@@ -248,43 +254,35 @@ impl Game<'_> {
|
||||
}
|
||||
self.world
|
||||
.block_entities
|
||||
.insert(key, BlockEntity::CreakingHeart(heart));
|
||||
.put(key, BlockEntity::CreakingHeart(heart));
|
||||
}
|
||||
/// `CreakingHeartBlockEntity.serverTick` for every heart.
|
||||
pub(super) fn tick_creaking_hearts(&mut self) -> Result<()> {
|
||||
let keys: Vec<Pos> = self
|
||||
.world
|
||||
.block_entities
|
||||
.iter()
|
||||
.filter(|(_, e)| matches!(e, BlockEntity::CreakingHeart(_)))
|
||||
.map(|(k, _)| *k)
|
||||
.collect();
|
||||
for key in keys {
|
||||
let Some(BlockEntity::CreakingHeart(mut heart)) =
|
||||
self.world.block_entities.remove(&key)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let state = self.world.block(key.0, key.1, key.2);
|
||||
if &*self.res.facts.get(state).name != "minecraft:creaking_heart" {
|
||||
// The block is gone: preRemoveSideEffects.
|
||||
self.with_heart(key, &mut heart, |h, _, _, host, out| {
|
||||
creaking_heart::remove_protector(h, host, false, out);
|
||||
})?;
|
||||
continue;
|
||||
}
|
||||
// getTicker: none once uprooted.
|
||||
if self.heart_state_name(state) != "uprooted" {
|
||||
let pos = [key.0, key.1, key.2];
|
||||
self.with_heart(key, &mut heart, |h, w, lr, host, out| {
|
||||
creaking_heart::server_tick(h, pos, w, lr, host, out);
|
||||
})?;
|
||||
}
|
||||
self.world
|
||||
.block_entities
|
||||
.insert(key, BlockEntity::CreakingHeart(heart));
|
||||
/// `CreakingHeartBlockEntity.serverTick` of the heart at `key`. Its slot
|
||||
/// stays while uprooted, so that a heart whose block went away is still
|
||||
/// found here and lets go of its protector.
|
||||
pub(super) fn tick_creaking_heart(&mut self, key: Pos) -> Result<()> {
|
||||
let Some(BlockEntity::CreakingHeart(mut heart)) = self.world.block_entities.take(&key)
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
let state = self.world.block(key.0, key.1, key.2);
|
||||
if &*self.res.facts().get(state).name != "minecraft:creaking_heart" {
|
||||
// The block is gone: preRemoveSideEffects.
|
||||
self.world.block_entities.forget(&key);
|
||||
self.with_heart(key, &mut heart, |h, _, _, host, out| {
|
||||
creaking_heart::remove_protector(h, host, false, out);
|
||||
})?;
|
||||
return Ok(());
|
||||
}
|
||||
self.scan_for_hearts();
|
||||
// getTicker: none once uprooted.
|
||||
if self.heart_state_name(state) != "uprooted" {
|
||||
let pos = [key.0, key.1, key.2];
|
||||
self.with_heart(key, &mut heart, |h, w, lr, host, out| {
|
||||
creaking_heart::server_tick(h, pos, w, lr, host, out);
|
||||
})?;
|
||||
}
|
||||
self.world
|
||||
.block_entities
|
||||
.put(key, BlockEntity::CreakingHeart(heart));
|
||||
Ok(())
|
||||
}
|
||||
/// `ServerLevel.isSpawningMonsters`.
|
||||
@@ -295,7 +293,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// Hearts that came with generated or loaded chunks get their block
|
||||
/// entity (`newBlockEntity`) the first time their chunk is seen.
|
||||
fn scan_for_hearts(&mut self) {
|
||||
pub(super) fn scan_for_hearts(&mut self) {
|
||||
let Some(heart) = self
|
||||
.pack
|
||||
.assets
|
||||
@@ -319,7 +317,7 @@ impl Game<'_> {
|
||||
if self.creaking.hearts.is_empty() {
|
||||
self.creaking.hearts = self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.states
|
||||
.iter()
|
||||
.map(|f| &*f.name == "minecraft:creaking_heart")
|
||||
@@ -327,13 +325,16 @@ impl Game<'_> {
|
||||
}
|
||||
let hearts = &self.creaking.hearts;
|
||||
let _ = heart;
|
||||
let is_heart = |id: u32| hearts.get(id as usize).copied().unwrap_or(false);
|
||||
for (si, section) in chunk.sections.iter().enumerate() {
|
||||
if section.is_uniform(0) {
|
||||
// Only a section whose palette holds a heart state can have
|
||||
// one: the others are skipped without reading their 4,096 blocks.
|
||||
if !section.blocks.maybe_has(is_heart) {
|
||||
continue;
|
||||
}
|
||||
for i in 0..4096 {
|
||||
let id = section.get(i);
|
||||
if !hearts.get(id as usize).copied().unwrap_or(false) {
|
||||
if !is_heart(id) {
|
||||
continue;
|
||||
}
|
||||
let (lx, lz, ly) = ((i & 15) as i32, ((i >> 4) & 15) as i32, (i >> 8) as i32);
|
||||
@@ -344,8 +345,7 @@ impl Game<'_> {
|
||||
);
|
||||
self.world
|
||||
.block_entities
|
||||
.entry(pos)
|
||||
.or_insert_with(|| BlockEntity::CreakingHeart(Box::default()));
|
||||
.get_or_insert_with(pos, || BlockEntity::CreakingHeart(Box::default()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +196,7 @@ impl Game<'_> {
|
||||
hero: self.potions.effects.get("hero_of_the_village").is_some(),
|
||||
uuid: self.level.player_uuid.unwrap_or_default(),
|
||||
allies: std::sync::Arc::new(self.player_allies()),
|
||||
remote: false,
|
||||
})
|
||||
}
|
||||
/// Biome facts at a position for finalizeSpawn and variant rules.
|
||||
@@ -203,8 +204,8 @@ impl Game<'_> {
|
||||
let Some(chunk) = self.world.chunks.get(&(x >> 4, z >> 4)) else {
|
||||
return BiomeFacts::default();
|
||||
};
|
||||
let b = self.res.biomes.get(chunk.biome(x, y, z));
|
||||
let tags = &self.res.mob_data;
|
||||
let b = self.res.biomes().get(chunk.biome(x, y, z));
|
||||
let tags = self.res.mob_data();
|
||||
let has = |t: &str| tags.biome_has(t, &b.name);
|
||||
let climate = if has("minecraft:spawns_warm_variant_farm_animals") {
|
||||
Climate::Warm
|
||||
@@ -254,7 +255,7 @@ impl Game<'_> {
|
||||
} else {
|
||||
format!("minecraft:{kind}")
|
||||
};
|
||||
let t = self.res.mob_types.get(&kind).cloned()?;
|
||||
let t = self.res.mob_types().get(&kind).cloned()?;
|
||||
self.next_entity += 1;
|
||||
let yaw = self.world.random.next_float() * 360.0;
|
||||
let mut mob = Mob::new(self.next_entity, t, Vec3::new(at[0], at[1], at[2]), yaw);
|
||||
@@ -367,7 +368,7 @@ impl Game<'_> {
|
||||
pub(super) fn motion_top(&self, x: i32, z: i32) -> i32 {
|
||||
let top = if self.dim == Dim::Nether { 127 } else { 319 };
|
||||
for y in (horizon_client::chunk::MIN_Y..=top).rev() {
|
||||
let f = self.res.facts.get(self.world.block(x, y, z));
|
||||
let f = self.res.facts().get(self.world.block(x, y, z));
|
||||
if (f.full_collision || f.fluid != Fluid::None) && !f.name.ends_with("leaves") {
|
||||
return y + 1;
|
||||
}
|
||||
@@ -379,10 +380,10 @@ impl Game<'_> {
|
||||
MobWorld {
|
||||
world: &self.world,
|
||||
registry: self.pack.assets.registry,
|
||||
facts: &self.res.facts,
|
||||
facts: self.res.facts(),
|
||||
movement: &self.motion.blocks,
|
||||
collision: self.collision,
|
||||
data: &self.res.mob_data,
|
||||
data: self.res.mob_data(),
|
||||
player: self.player_view(),
|
||||
others,
|
||||
others_grid: None,
|
||||
@@ -392,14 +393,14 @@ impl Game<'_> {
|
||||
raining: rain > 0.2,
|
||||
thundering: thunder > 0.9,
|
||||
nether: self.dim == Dim::Nether,
|
||||
block_tags: &self.res.items.block_tags,
|
||||
biomes: &self.res.biomes,
|
||||
block_tags: &self.res.items().block_tags,
|
||||
biomes: self.res.biomes(),
|
||||
mob_griefing: self.ui.rules.bool("mob_griefing"),
|
||||
end: self.dim == Dim::End,
|
||||
world_seed: self.level.seed,
|
||||
sea_level: if self.dim == Dim::Nether { 32 } else { 63 },
|
||||
teams: self.mob_teams(),
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
difficulty: self.local_difficulty(
|
||||
self.player
|
||||
.as_ref()
|
||||
@@ -474,24 +475,11 @@ impl Game<'_> {
|
||||
self.tick_raids();
|
||||
self.tick_creature_entities()
|
||||
}
|
||||
/// `DistanceManager.inEntityTickingRange`: chunks within the simulation
|
||||
/// distance (Chebyshev, in chunks) of the player or of a guest.
|
||||
/// `DistanceManager.inEntityTickingRange` in an entity-ticking chunk
|
||||
/// (block coordinates), from every player's tickets (`update_chunk_tickets`).
|
||||
pub(super) fn entity_ticking_area(&self) -> impl Fn(i32, i32) -> bool + use<> {
|
||||
let d = self.settings.simulation_distance.max(2);
|
||||
let mut centres: Vec<(i32, i32)> = self.streaming.extra.iter().map(|&(c, _)| c).collect();
|
||||
if let Some(p) = &self.player {
|
||||
centres.push((
|
||||
(p.position.x.floor() as i32) >> 4,
|
||||
(p.position.z.floor() as i32) >> 4,
|
||||
));
|
||||
}
|
||||
let everywhere = centres.is_empty();
|
||||
move |x, z| {
|
||||
everywhere
|
||||
|| centres
|
||||
.iter()
|
||||
.any(|&(cx, cz)| ((x >> 4) - cx).abs().max(((z >> 4) - cz).abs()) <= d)
|
||||
}
|
||||
let levels = self.tickets.levels();
|
||||
move |x, z| levels.entity_ticking_at(x, z)
|
||||
}
|
||||
/// The entity phase of `tick_creatures`: every mob's tick, deaths, and the
|
||||
/// projectiles and effects that follow from them.
|
||||
@@ -983,7 +971,7 @@ impl Game<'_> {
|
||||
if effect {
|
||||
let old = self.world.block(pos[0], pos[1], pos[2]);
|
||||
self.destroy_particles(pos, old);
|
||||
let s = self.res.facts.get(old).sounds.break_sound.clone();
|
||||
let s = self.res.facts().get(old).sounds.break_sound.clone();
|
||||
self.audio.play(
|
||||
&s,
|
||||
Some([
|
||||
@@ -1003,7 +991,7 @@ impl Game<'_> {
|
||||
let old = self.world.block(pos[0], pos[1], pos[2]);
|
||||
self.destroy_particles(pos, old);
|
||||
if drop {
|
||||
let drops = self.res.items.block_drops_in(
|
||||
let drops = self.res.items().block_drops_in(
|
||||
self.pack.assets.registry,
|
||||
old,
|
||||
None,
|
||||
@@ -1157,7 +1145,7 @@ impl Game<'_> {
|
||||
MobEvent::GiftLoot { table, at } => {
|
||||
let drops =
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.loot_table(table, false, None, &mut self.world.random);
|
||||
for d in drops {
|
||||
self.spawn_item(d, at, [0.0, 0.2, 0.0], 10);
|
||||
@@ -1420,7 +1408,7 @@ impl Game<'_> {
|
||||
}
|
||||
let projectile = self
|
||||
.res
|
||||
.stations
|
||||
.stations()
|
||||
.enchantments
|
||||
.damage_tags
|
||||
.get("minecraft:is_projectile")
|
||||
@@ -1780,7 +1768,7 @@ impl Game<'_> {
|
||||
horizon_client::arrows::ArrowScene {
|
||||
world: &self.world,
|
||||
registry: self.pack.assets.registry,
|
||||
facts: &self.res.facts,
|
||||
facts: self.res.facts(),
|
||||
collision: self.collision,
|
||||
fluids: &self.motion.fluids,
|
||||
raining: rain,
|
||||
@@ -2032,7 +2020,7 @@ impl Game<'_> {
|
||||
let fire = [pos[0] + face[0], pos[1] + face[1], pos[2] + face[2]];
|
||||
if self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.is_air(self.world.block(fire[0], fire[1], fire[2]))
|
||||
&& let Some(state) =
|
||||
self.pack.assets.registry.default_state("minecraft:fire")
|
||||
@@ -2358,7 +2346,7 @@ impl Game<'_> {
|
||||
Species::Sheep if item == "minecraft:shears" && !m.extra.sheared && !m.is_baby() => {
|
||||
m.extra.sheared = true;
|
||||
let color = horizon_client::mobs::render::DYE_NAMES[m.extra.color as usize & 15];
|
||||
let stacks = self.res.items.loot_table(
|
||||
let stacks = self.res.items().loot_table(
|
||||
&format!("minecraft:shearing/sheep/{color}"),
|
||||
false,
|
||||
None,
|
||||
@@ -2390,7 +2378,7 @@ impl Game<'_> {
|
||||
Species::Wolf if m.extra.tame && is_food && m.health < m.attrs.max_health => {
|
||||
let heal = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&item)
|
||||
.and_then(|i| i.food.as_ref())
|
||||
.map_or(2.0, |f| f.0 as f32);
|
||||
@@ -2494,7 +2482,7 @@ impl Game<'_> {
|
||||
Species::Cat if m.extra.tame && is_food && m.health < m.attrs.max_health => {
|
||||
let heal = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&item)
|
||||
.and_then(|i| i.food.as_ref())
|
||||
.map_or(1.0, |f| f.0 as f32);
|
||||
@@ -2661,7 +2649,7 @@ impl Game<'_> {
|
||||
return;
|
||||
}
|
||||
if let Some(stack) = self.inventory[self.selected].as_mut()
|
||||
&& let Some(info) = self.res.items.get(&stack.item)
|
||||
&& let Some(info) = self.res.items().get(&stack.item)
|
||||
&& info.max_damage > 0
|
||||
{
|
||||
stack.damage += 1;
|
||||
@@ -2734,7 +2722,7 @@ impl Game<'_> {
|
||||
// EntityType.canSpawn: no monsters in peaceful (FAIL ends the click).
|
||||
let id = format!("minecraft:{}", kind.trim_start_matches("minecraft:"));
|
||||
if self.ui.difficulty == 0
|
||||
&& let Some(t) = self.res.mob_types.get(&id)
|
||||
&& let Some(t) = self.res.mob_types().get(&id)
|
||||
&& !horizon_client::mobs::spawn_rules::allowed_in_peaceful(t.species)
|
||||
{
|
||||
return Ok(true);
|
||||
@@ -2798,7 +2786,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// Mob models and projectiles for the entity pass.
|
||||
pub(super) fn mob_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec<Vertex>) {
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let lookup = |name: &str| atlas.sprites.get(name).map(|r| [r.u0, r.v0, r.u1, r.v1]);
|
||||
let scale = f64::from(self.settings.entity_distance);
|
||||
for mob in &self.mobs {
|
||||
@@ -2856,7 +2844,7 @@ impl Game<'_> {
|
||||
camera,
|
||||
&lookup,
|
||||
packed,
|
||||
&self.res.mob_data,
|
||||
self.res.mob_data(),
|
||||
&armor,
|
||||
out,
|
||||
);
|
||||
@@ -3015,7 +3003,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// Mob.getBaseExperienceReward
|
||||
/// The damage type id of a Horizon damage kind.
|
||||
fn damage_type(kind: horizon_client::mobs::DamageKind, player: bool) -> &'static str {
|
||||
pub(super) fn damage_type(kind: horizon_client::mobs::DamageKind, player: bool) -> &'static str {
|
||||
use horizon_client::mobs::DamageKind as K;
|
||||
match kind {
|
||||
K::PlayerAttack => "minecraft:player_attack",
|
||||
@@ -3100,13 +3088,17 @@ impl Game<'_> {
|
||||
return;
|
||||
}
|
||||
let mut y = pos[1];
|
||||
while &*self.res.facts.get(self.world.block(pos[0], y, pos[2])).name
|
||||
while &*self
|
||||
.res
|
||||
.facts()
|
||||
.get(self.world.block(pos[0], y, pos[2]))
|
||||
.name
|
||||
== "minecraft:nether_portal"
|
||||
{
|
||||
y -= 1;
|
||||
}
|
||||
// isValidSpawn: a sturdy top face (portal frames emit no light).
|
||||
let below = self.res.facts.get(self.world.block(pos[0], y, pos[2]));
|
||||
let below = self.res.facts().get(self.world.block(pos[0], y, pos[2]));
|
||||
if below.sturdy_full & (1 << 1) == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ impl DebugHost for Host<'_, '_> {
|
||||
|
||||
impl Game<'_> {
|
||||
fn open_screen(&self) -> OpenScreen {
|
||||
if self.title.is_some() {
|
||||
return OpenScreen::Other;
|
||||
}
|
||||
match self.screen {
|
||||
Screen::GameModeSwitcher => OpenScreen::GameModeSwitcher,
|
||||
Screen::Playing if self.book.is_none() && self.sign_edit.is_none() => OpenScreen::None,
|
||||
@@ -437,7 +440,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
let (left, right) = d.columns(&self.debug_chart_lines());
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
let mut draws = debug_overlay::draw(&atlas.font, [&left, &right], scale, width);
|
||||
let charts = self.debug_charts.draw(
|
||||
&atlas.font,
|
||||
|
||||
@@ -63,7 +63,7 @@ impl Game<'_> {
|
||||
/// pot without), or None when no pot is there.
|
||||
fn pot_tag(&mut self, pos: [i32; 3]) -> Option<Tag> {
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
if &*self.res.facts.get(state).name != "minecraft:decorated_pot" {
|
||||
if &*self.res.facts().get(state).name != "minecraft:decorated_pot" {
|
||||
return None;
|
||||
}
|
||||
let mut tag = spill::saved_entity(&self.world, pos).unwrap_or_else(|| {
|
||||
|
||||
@@ -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")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -340,7 +336,7 @@ impl Game<'_> {
|
||||
);
|
||||
}
|
||||
let settings = if flat {
|
||||
let biomes = &self.res.biomes;
|
||||
let biomes = self.res.biomes();
|
||||
let (settings, errors) = horizon_client::flatgen::settings_from_json(
|
||||
&props.generator_settings,
|
||||
|b| self.pack.assets.registry.default_state(b).is_some(),
|
||||
@@ -402,11 +398,36 @@ struct ServerState {
|
||||
/// When the last passes of the loop ended, for the tick rate horizon-server shows.
|
||||
ticks: std::collections::VecDeque<Instant>,
|
||||
paused: bool,
|
||||
/// `broadcast-console-to-ops`.
|
||||
broadcast_console: bool,
|
||||
}
|
||||
|
||||
/// The dedicated-only commands' replies vanilla sends with `broadcast`
|
||||
/// (`sendSuccess(..., true)`): the operators hear of them.
|
||||
const BROADCAST: &[&str] = &[
|
||||
"commands.ban.success",
|
||||
"commands.banip.info",
|
||||
"commands.banip.success",
|
||||
"commands.deop.success",
|
||||
"commands.kick.success",
|
||||
"commands.op.success",
|
||||
"commands.pardon.success",
|
||||
"commands.pardonip.success",
|
||||
"commands.save.disabled",
|
||||
"commands.save.enabled",
|
||||
"commands.save.success",
|
||||
"commands.stop.stopping",
|
||||
"commands.whitelist.add.success",
|
||||
"commands.whitelist.disabled",
|
||||
"commands.whitelist.enabled",
|
||||
"commands.whitelist.reloaded",
|
||||
"commands.whitelist.remove.success",
|
||||
];
|
||||
|
||||
impl Game<'_> {
|
||||
/// DedicatedServer.initServer and MinecraftServer.runServer.
|
||||
pub(super) fn run_dedicated(&mut self) -> Result<()> {
|
||||
self.join_world_rest()?;
|
||||
let Setup {
|
||||
props,
|
||||
universe,
|
||||
@@ -449,6 +470,18 @@ impl Game<'_> {
|
||||
// DedicatedServer.initServer: names nobody has resolve offline only without authentication.
|
||||
cache.resolve_offline_users = !props.online_mode;
|
||||
*USER_CACHE.lock().unwrap() = Some(cache);
|
||||
// Services.create: the services' public keys, fetched in the
|
||||
// background (they check players' chat keys).
|
||||
let secure_chat = Arc::new(horizon_client::lan::SecureChat::new(
|
||||
props.enforce_secure_profile && props.online_mode,
|
||||
|| {
|
||||
let discovery = profiles::discovery_url();
|
||||
profiles::fetch_profile_key_keys(&discovery).unwrap_or_else(|e| {
|
||||
::log::error!("{e}");
|
||||
Vec::new()
|
||||
})
|
||||
},
|
||||
));
|
||||
log("INFO", "Starting minecraft server version 26.3");
|
||||
log("INFO", "Loading properties");
|
||||
let game_mode = props.game_mode;
|
||||
@@ -547,8 +580,7 @@ impl Game<'_> {
|
||||
enable_status: props.enable_status,
|
||||
hide_online_players: props.hide_online_players,
|
||||
favicon,
|
||||
// DedicatedServer.enforceSecureProfile needs online mode.
|
||||
enforces_secure_chat: false,
|
||||
secure_chat: Some(secure_chat),
|
||||
accepts_transfers: props.accepts_transfers,
|
||||
announce: false,
|
||||
listen: true,
|
||||
@@ -612,6 +644,7 @@ impl Game<'_> {
|
||||
empty_ticks: 0,
|
||||
ticks: Default::default(),
|
||||
paused: false,
|
||||
broadcast_console: props.broadcast_console_to_ops,
|
||||
};
|
||||
let pause_after = props.pause_when_empty_seconds * 20;
|
||||
let idle_timeout = props.player_idle_timeout;
|
||||
@@ -619,7 +652,7 @@ impl Game<'_> {
|
||||
while !state.stop {
|
||||
let tick_start = Instant::now();
|
||||
while let Ok(line) = state.console.try_recv() {
|
||||
self.console_command(&mut state, &line);
|
||||
self.console_line(&mut state, &line);
|
||||
}
|
||||
self.poll_server_control(&mut state);
|
||||
let players = self.lan.as_ref().map_or(0, |h| h.hub.guests.len());
|
||||
@@ -647,7 +680,7 @@ impl Game<'_> {
|
||||
self.ticks = self.ticks.max(1);
|
||||
}
|
||||
// MinecraftServer.tickServer: while paused only the connections run.
|
||||
self.tick_server(paused)?;
|
||||
self.tick_server_timed(paused)?;
|
||||
if idle_timeout > 0 {
|
||||
self.kick_idle(idle_timeout);
|
||||
}
|
||||
@@ -767,14 +800,37 @@ impl Game<'_> {
|
||||
})
|
||||
});
|
||||
if found.is_none() {
|
||||
self.console_reply(Text::translate("argument.player.unknown", &[]));
|
||||
let unknown = Text::translate("argument.player.unknown", &[]);
|
||||
log("INFO", &format!("System chat: {}", unknown.plain()));
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
/// MinecraftServer.sendSystemMessage: what the console is told.
|
||||
fn console_reply(&self, text: Text) {
|
||||
/// MinecraftServer.sendSystemMessage: what the console is told; while
|
||||
/// the console runs a command, the replies vanilla broadcasts go to the
|
||||
/// operators too.
|
||||
fn console_reply(&mut self, text: Text) {
|
||||
log("INFO", &format!("System chat: {}", text.plain()));
|
||||
if self.console_broadcast.is_some()
|
||||
&& text
|
||||
.translation_key()
|
||||
.is_some_and(|k| BROADCAST.contains(&k))
|
||||
{
|
||||
self.broadcast_to_admins(text);
|
||||
}
|
||||
}
|
||||
|
||||
/// One console line, then the operators' share of its feedback.
|
||||
fn console_line(&mut self, state: &mut ServerState, line: &str) {
|
||||
self.console_broadcast = Some(state.broadcast_console);
|
||||
self.console_command(state, line);
|
||||
self.console_broadcast = None;
|
||||
if let Some(mut host) = self.lan.take() {
|
||||
self.run_level_teleports(&mut host);
|
||||
self.send_admin_feedback(&mut host, None);
|
||||
self.lan = Some(host);
|
||||
}
|
||||
self.admin_feedback.clear();
|
||||
}
|
||||
|
||||
/// DedicatedServer.handleConsoleInputs: one console line, run as the
|
||||
|
||||
@@ -114,9 +114,9 @@ impl Game<'_> {
|
||||
}
|
||||
|
||||
fn fixture_reset(&mut self, seed: i64) {
|
||||
self.world = World::new(self.res.facts.air, seed);
|
||||
self.world = World::new(self.res.facts().air, seed);
|
||||
// The oracle level is plains everywhere (bone meal's flowers, freezing).
|
||||
let plains = u32::from(self.res.biomes.id("minecraft:plains"));
|
||||
let plains = u32::from(self.res.biomes().id("minecraft:plains"));
|
||||
for cx in -2..=2 {
|
||||
for cz in -2..=2 {
|
||||
let mut chunk = Chunk::empty(cx, cz);
|
||||
@@ -198,7 +198,7 @@ impl Game<'_> {
|
||||
let state = BlockStateId(cell[3].as_u64().unwrap_or(0) as u32);
|
||||
self.world.set(p.0, p.1, p.2, state)?;
|
||||
before.insert(p, state.0);
|
||||
if let Some(entity) = BlockEntity::for_block(&self.res.facts.get(state).name) {
|
||||
if let Some(entity) = BlockEntity::for_block(&self.res.facts().get(state).name) {
|
||||
self.world.block_entities.insert(p, entity);
|
||||
}
|
||||
}
|
||||
@@ -284,7 +284,7 @@ impl Game<'_> {
|
||||
let state = self.world.block(origin.x, origin.y, origin.z);
|
||||
let mut used = Vec::new();
|
||||
if let Some(op) = case.get("remove") {
|
||||
self.fixture_remove(origin, op)?;
|
||||
used = self.fixture_remove(origin, op)?;
|
||||
} else if let Some(op) = case.get("use") {
|
||||
used = self.fixture_use(origin, op)?;
|
||||
} else if let Some(op) = case.get("use_item") {
|
||||
@@ -318,8 +318,18 @@ impl Game<'_> {
|
||||
} else {
|
||||
self.dispense_from(origin, state)?;
|
||||
// CrafterBlockEntity.serverTick, the crafting animation running down.
|
||||
let mut crafters: Vec<(i32, i32, i32)> = self
|
||||
.world
|
||||
.block_entities
|
||||
.iter()
|
||||
.filter(|(_, e)| matches!(e, BlockEntity::Crafter(_)))
|
||||
.map(|(p, _)| *p)
|
||||
.collect();
|
||||
crafters.sort_unstable();
|
||||
for _ in 0..case["ticks"].as_u64().unwrap_or(0) {
|
||||
self.tick_crafters();
|
||||
for &p in &crafters {
|
||||
self.tick_crafter(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +339,7 @@ impl Game<'_> {
|
||||
changed.dedup();
|
||||
for p in changed {
|
||||
let now = self.world.block(p.0, p.1, p.2).0;
|
||||
if before.get(&p).copied().unwrap_or(self.res.facts.air.0) != now {
|
||||
if before.get(&p).copied().unwrap_or(self.res.facts().air.0) != now {
|
||||
out.push(format!("set {},{},{} {now}", p.0, p.1, p.2));
|
||||
}
|
||||
}
|
||||
@@ -696,7 +706,7 @@ impl Game<'_> {
|
||||
/// lectern's book, or the items of a block entity Horizon keeps as saved.
|
||||
fn fixture_fill(&mut self, p: (i32, i32, i32), slot: usize, stack: Option<ItemStack>) {
|
||||
let jukebox =
|
||||
&*self.res.facts.get(self.world.block(p.0, p.1, p.2)).name == "minecraft:jukebox";
|
||||
&*self.res.facts().get(self.world.block(p.0, p.1, p.2)).name == "minecraft:jukebox";
|
||||
match self.world.block_entities.get_mut(&p) {
|
||||
Some(BlockEntity::Jukebox(j)) => j.record = stack,
|
||||
Some(BlockEntity::Lectern(l)) => l.book = stack,
|
||||
@@ -725,7 +735,7 @@ impl Game<'_> {
|
||||
use horizon_world::nbt::Tag;
|
||||
let name = self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(p.0, p.1, p.2))
|
||||
.name
|
||||
.clone();
|
||||
@@ -778,8 +788,9 @@ impl Game<'_> {
|
||||
other => *other = Tag::List(vec![item]),
|
||||
}
|
||||
}
|
||||
/// `Level.setBlock`, `destroyBlock` or `removeBlock` on the case's block.
|
||||
fn fixture_remove(&mut self, origin: BlockPos, op: &Value) -> Result<()> {
|
||||
/// `Level.setBlock`, `destroyBlock` or `removeBlock` on the case's block, or
|
||||
/// a player mining it (`fixture_mine`).
|
||||
fn fixture_remove(&mut self, origin: BlockPos, op: &Value) -> Result<Vec<String>> {
|
||||
match op["op"].as_str().unwrap_or("") {
|
||||
"set" => {
|
||||
let state = BlockStateId(op["state"].as_u64().unwrap_or(0) as u32);
|
||||
@@ -793,9 +804,61 @@ impl Game<'_> {
|
||||
"remove" => {
|
||||
self.with_level(|b, level, ticks| b.remove_block(level, ticks, origin, false));
|
||||
}
|
||||
"mine" => return self.fixture_mine(origin, op),
|
||||
other => return Err(format!("unknown removal {other}").into()),
|
||||
}
|
||||
self.process_level_events()
|
||||
self.process_level_events()?;
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
/// A survival player three blocks south of `pos` mines it holding the
|
||||
/// case's item (`break_block`, which every player's mining goes through):
|
||||
/// the statistics and the held stack, as `VanillaDispenserOracle.mine`
|
||||
/// prints them.
|
||||
fn fixture_mine(&mut self, pos: BlockPos, op: &Value) -> Result<Vec<String>> {
|
||||
let stack = parse_stack(op["item"].as_str().unwrap_or("-"))?;
|
||||
self.mode = GameMode::Survival;
|
||||
self.creative = false;
|
||||
self.player = Some(PlayerMotion::new(
|
||||
self.motion,
|
||||
horizon_core::geometry::Vec3::new(
|
||||
f64::from(pos.x) + 0.5,
|
||||
f64::from(pos.y) + 1.0,
|
||||
f64::from(pos.z) + 3.5,
|
||||
),
|
||||
)?);
|
||||
self.yaw = 0.0;
|
||||
self.pitch = 90.0;
|
||||
self.keys.clear();
|
||||
self.inventory[self.selected] = stack.clone();
|
||||
self.offhand = None;
|
||||
let state = self.world.block(pos.x, pos.y, pos.z);
|
||||
let block = self.res.facts().get(state).name.clone();
|
||||
let item = stack.as_ref().map(|s| s.item.clone());
|
||||
let before = |game: &Self| {
|
||||
let used = item.as_ref().map_or(0, |i| game.stats.get("used", i));
|
||||
(used, game.stats.get("mined", &block))
|
||||
};
|
||||
let (used, mined) = before(self);
|
||||
self.break_block([pos.x, pos.y, pos.z])?;
|
||||
let (used_after, mined_after) = before(self);
|
||||
let mut out = Vec::new();
|
||||
if let Some(item) = &item
|
||||
&& used_after != used
|
||||
{
|
||||
out.push(format!("stat {item} minecraft:used {}", used_after - used));
|
||||
}
|
||||
if mined_after != mined {
|
||||
out.push(format!(
|
||||
"stat {block} minecraft:mined {}",
|
||||
mined_after - mined
|
||||
));
|
||||
}
|
||||
out.push(format!(
|
||||
"mine held {}",
|
||||
canon_stack(self.inventory[self.selected].as_ref())
|
||||
));
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// `EntityType.create` and `snapTo` for one target: no spawn finalization.
|
||||
@@ -819,7 +882,7 @@ impl Game<'_> {
|
||||
}
|
||||
let t = self
|
||||
.res
|
||||
.mob_types
|
||||
.mob_types()
|
||||
.get(kind)
|
||||
.cloned()
|
||||
.ok_or_else(|| format!("no mob type {kind}"))?;
|
||||
|
||||
@@ -328,18 +328,18 @@ impl Game<'_> {
|
||||
self.world.block(p.0, p.1, p.2)
|
||||
}
|
||||
fn dispenser_block_name(&self, p: Pos) -> std::sync::Arc<str> {
|
||||
self.res.facts.get(self.block_at(p)).name.clone()
|
||||
self.res.facts().get(self.block_at(p)).name.clone()
|
||||
}
|
||||
fn in_block_tag(&self, tag: &str, block: &str) -> bool {
|
||||
self.res
|
||||
.items
|
||||
.items()
|
||||
.block_tags
|
||||
.get(tag)
|
||||
.is_some_and(|s| s.contains(block))
|
||||
}
|
||||
fn water_at(&self, p: Pos) -> bool {
|
||||
matches!(
|
||||
self.res.behaviours.fluid_kind(self.block_at(p)),
|
||||
self.res.behaviours().fluid_kind(self.block_at(p)),
|
||||
FluidKind::Water | FluidKind::FlowingWater
|
||||
)
|
||||
}
|
||||
@@ -520,7 +520,7 @@ impl Game<'_> {
|
||||
if let Some(entity) = self.world.block_entities.get_mut(&pos) {
|
||||
let max = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&rest.item)
|
||||
.map_or(64, |i| i.max_stack)
|
||||
.max(1);
|
||||
@@ -555,7 +555,11 @@ impl Game<'_> {
|
||||
}
|
||||
/// `ItemStack.hurtAndBreak(amount)` without an entity.
|
||||
fn hurt_and_break(&mut self, mut stack: ItemStack, amount: u32) -> Option<ItemStack> {
|
||||
let max = self.res.items.get(&stack.item).map_or(0, |i| i.max_damage);
|
||||
let max = self
|
||||
.res
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.map_or(0, |i| i.max_damage);
|
||||
if max == 0 {
|
||||
return Some(stack);
|
||||
}
|
||||
@@ -637,7 +641,7 @@ impl Game<'_> {
|
||||
) -> Result<Dispensed> {
|
||||
let equippable = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&stack.item)
|
||||
.is_some_and(|i| i.equip_slot.is_some());
|
||||
if equippable {
|
||||
@@ -649,7 +653,7 @@ impl Game<'_> {
|
||||
}
|
||||
let swallowable = self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.item_tags
|
||||
.get("minecraft:sulfur_cube_swallowable")
|
||||
.is_some_and(|t| t.contains(&*stack.item));
|
||||
@@ -748,7 +752,7 @@ impl Game<'_> {
|
||||
} else {
|
||||
format!("minecraft:{kind}")
|
||||
};
|
||||
let t = self.res.mob_types.get(&name)?.clone();
|
||||
let t = self.res.mob_types().get(&name)?.clone();
|
||||
let y_off = if try_move_down {
|
||||
self.drop_offset(t.width, t.height, p)
|
||||
} else {
|
||||
@@ -768,7 +772,7 @@ impl Game<'_> {
|
||||
/// `EquipmentDispenseItemBehavior.dispenseEquipment`: the first living
|
||||
/// entity in front that `canEquipWithDispenser` gets one of the item.
|
||||
fn dispense_equipment(&mut self, pos: Pos, facing: Direction, stack: &mut ItemStack) -> bool {
|
||||
let Some(info) = self.res.items.get(&stack.item) else {
|
||||
let Some(info) = self.res.items().get(&stack.item) else {
|
||||
return false;
|
||||
};
|
||||
let (Some(slot), true) = (
|
||||
@@ -1078,7 +1082,7 @@ impl Game<'_> {
|
||||
let below = (front.0, front.1 - 1, front.2);
|
||||
let y_offset = if self.water_at(front) {
|
||||
1.0
|
||||
} else if self.res.facts.is_air(self.block_at(front)) && self.water_at(below) {
|
||||
} else if self.res.facts().is_air(self.block_at(front)) && self.water_at(below) {
|
||||
0.0
|
||||
} else {
|
||||
return (self.dispense_default(pos, facing, stack), CLICK);
|
||||
@@ -1116,7 +1120,7 @@ impl Game<'_> {
|
||||
let y_offset = if let Some(rail) = self.rail(front.0, front.1, front.2) {
|
||||
if rail.shape.is_slope() { 0.6 } else { 0.1 }
|
||||
} else {
|
||||
if !self.res.facts.is_air(self.block_at(front)) {
|
||||
if !self.res.facts().is_air(self.block_at(front)) {
|
||||
return (self.dispense_default(pos, facing, stack), CLICK);
|
||||
}
|
||||
let below = (front.0, front.1 - 1, front.2);
|
||||
@@ -1389,7 +1393,7 @@ impl Game<'_> {
|
||||
stack: ItemStack,
|
||||
) -> Result<Dispensed> {
|
||||
let target = offset(pos, facing);
|
||||
let free = self.res.facts.is_air(self.block_at(target))
|
||||
let free = self.res.facts().is_air(self.block_at(target))
|
||||
&& target.1 >= horizon_client::chunk::MIN_Y + 2
|
||||
&& self.ui.difficulty != 0
|
||||
&& self.can_build_wither(target);
|
||||
@@ -1443,7 +1447,7 @@ impl Game<'_> {
|
||||
"minecraft:soul_sand" | "minecraft:soul_soil"
|
||||
)
|
||||
};
|
||||
let air = |p: Pos| self.res.facts.is_air(self.block_at(p));
|
||||
let air = |p: Pos| self.res.facts().is_air(self.block_at(p));
|
||||
for (ax, az) in [(1, 0), (0, 1)] {
|
||||
for col in 0..3 {
|
||||
let left = (head.0 - ax * col, head.1, head.2 - az * col);
|
||||
@@ -1466,7 +1470,7 @@ impl Game<'_> {
|
||||
stack: ItemStack,
|
||||
) -> Result<Dispensed> {
|
||||
let target = offset(pos, facing);
|
||||
if self.res.facts.is_air(self.block_at(target))
|
||||
if self.res.facts().is_air(self.block_at(target))
|
||||
&& self.can_spawn_golem([target.0, target.1, target.2])
|
||||
{
|
||||
if let Some(pumpkin) = self
|
||||
@@ -1511,7 +1515,7 @@ impl Game<'_> {
|
||||
let front = offset(pos, facing);
|
||||
let below_empty = self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.is_air(self.block_at((front.0, front.1 - 1, front.2)));
|
||||
let clicked_face = if below_empty { facing } else { Direction::Up };
|
||||
let ctx = PlaceContext {
|
||||
@@ -1539,7 +1543,7 @@ impl Game<'_> {
|
||||
return Ok((Some(stack), FAIL));
|
||||
};
|
||||
let target = (placed.x, placed.y, placed.z);
|
||||
if let Some(entity) = BlockEntity::for_block(&self.res.facts.get(state).name) {
|
||||
if let Some(entity) = BlockEntity::for_block(&self.res.facts().get(state).name) {
|
||||
self.world.block_entities.insert(target, entity);
|
||||
self.apply_placed_item([target.0, target.1, target.2], &stack, false);
|
||||
}
|
||||
@@ -1689,14 +1693,14 @@ impl Game<'_> {
|
||||
table: &str,
|
||||
held: Option<&ItemStack>,
|
||||
) -> Vec<ItemStack> {
|
||||
match self.res.items.loot_sequence(parent) {
|
||||
match self.res.items().loot_sequence(parent) {
|
||||
Some(sequence) => {
|
||||
let random = self.rand_sequences.get(&sequence, self.level.seed);
|
||||
self.res.items.loot_table_from(table, false, held, random)
|
||||
self.res.items().loot_table_from(table, false, held, random)
|
||||
}
|
||||
None => self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.loot_table(table, false, held, &mut self.world.random),
|
||||
}
|
||||
}
|
||||
@@ -1717,7 +1721,7 @@ impl Game<'_> {
|
||||
/// random draws) keeps the name, flags, persistence and age; the old one
|
||||
/// is discarded.
|
||||
pub(super) fn convert_mob(&mut self, index: usize, kind: &str) -> Option<u32> {
|
||||
let t = self.res.mob_types.get(kind).cloned()?;
|
||||
let t = self.res.mob_types().get(kind).cloned()?;
|
||||
let old = &self.mobs[index];
|
||||
self.next_entity += 1;
|
||||
let mut mob = Mob::new(self.next_entity, t, old.position, old.yaw);
|
||||
|
||||
@@ -74,6 +74,8 @@ impl Respawn {
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub(super) struct Crystal {
|
||||
/// The entity id a server tracks it by (0 until it is tracked).
|
||||
pub id: u32,
|
||||
pub position: Vec3,
|
||||
pub show_bottom: bool,
|
||||
/// EndCrystal.time (the bob and spin), starting random.
|
||||
@@ -445,9 +447,9 @@ impl Game<'_> {
|
||||
}
|
||||
fn end_portal_active(&self) -> bool {
|
||||
(0..256).any(|y| {
|
||||
&*self.res.facts.get(self.world.block(0, y, 0)).name == "minecraft:bedrock"
|
||||
&*self.res.facts().get(self.world.block(0, y, 0)).name == "minecraft:bedrock"
|
||||
&& (-3..=3).any(|d| {
|
||||
&*self.res.facts.get(self.world.block(d, y, 0)).name == "minecraft:end_portal"
|
||||
&*self.res.facts().get(self.world.block(d, y, 0)).name == "minecraft:end_portal"
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -553,6 +555,7 @@ impl Game<'_> {
|
||||
}
|
||||
let time = self.world.random.next_int_bound(100_000).unwrap_or(0);
|
||||
self.crystals.push(Crystal {
|
||||
id: 0,
|
||||
position: at,
|
||||
show_bottom: true,
|
||||
time,
|
||||
@@ -588,7 +591,7 @@ impl Game<'_> {
|
||||
let p = self.crystals[i].position;
|
||||
let b = [p.x.floor() as i32, p.y.floor() as i32, p.z.floor() as i32];
|
||||
if let Some(fire) = fire
|
||||
&& self.res.facts.is_air(self.world.block(b[0], b[1], b[2]))
|
||||
&& self.res.facts().is_air(self.world.block(b[0], b[1], b[2]))
|
||||
&& self.world.loaded(b[0], b[2])
|
||||
{
|
||||
let _ = self.level_set(b, fire);
|
||||
@@ -761,7 +764,7 @@ impl Game<'_> {
|
||||
let held = self.held().cloned();
|
||||
let modifiers = held
|
||||
.as_ref()
|
||||
.and_then(|h| self.res.items.get(&h.item))
|
||||
.and_then(|h| self.res.items().get(&h.item))
|
||||
.map(|i| (i.attack_damage, i.attack_speed))
|
||||
.unwrap_or((0.0, 0.0));
|
||||
let speed = (4.0 + modifiers.1).max(0.1);
|
||||
@@ -810,7 +813,7 @@ impl Game<'_> {
|
||||
(0..256)
|
||||
.rev()
|
||||
.find(|&y| {
|
||||
let f = self.res.facts.get(self.world.block(x, y, z));
|
||||
let f = self.res.facts().get(self.world.block(x, y, z));
|
||||
(f.full_collision
|
||||
|| f.legacy_solid
|
||||
|| f.fluid != horizon_client::blocks::Fluid::None)
|
||||
@@ -1254,7 +1257,7 @@ impl Game<'_> {
|
||||
let (x, z) = (head.x + look.x * 2.5, head.z + look.y * 2.5);
|
||||
let mut y = head.y + 0.5;
|
||||
while y > 0.0
|
||||
&& self.res.facts.is_air(self.world.block(
|
||||
&& self.res.facts().is_air(self.world.block(
|
||||
x.floor() as i32,
|
||||
y.floor() as i32,
|
||||
z.floor() as i32,
|
||||
@@ -1591,7 +1594,7 @@ impl Game<'_> {
|
||||
return;
|
||||
};
|
||||
let boxes = [d.part_box(0), d.part_box(1), d.part_box(2)];
|
||||
let tags = &self.res.items.block_tags;
|
||||
let tags = &self.res.items().block_tags;
|
||||
let transparent = tags
|
||||
.get("minecraft:dragon_transparent")
|
||||
.cloned()
|
||||
@@ -1607,8 +1610,8 @@ impl Game<'_> {
|
||||
for y in lo.y.floor() as i32..=hi.y.floor() as i32 {
|
||||
for z in lo.z.floor() as i32..=hi.z.floor() as i32 {
|
||||
let state = self.world.block(x, y, z);
|
||||
let name = &self.res.facts.get(state).name;
|
||||
if self.res.facts.is_air(state) || transparent.contains(&**name) {
|
||||
let name = &self.res.facts().get(state).name;
|
||||
if self.res.facts().is_air(state) || transparent.contains(&**name) {
|
||||
continue;
|
||||
}
|
||||
if griefing && !immune.contains(&**name) {
|
||||
@@ -1710,7 +1713,7 @@ impl Game<'_> {
|
||||
let y = (0..256)
|
||||
.rev()
|
||||
.find(|&y| {
|
||||
let f = self.res.facts.get(self.world.block(0, y, 0));
|
||||
let f = self.res.facts().get(self.world.block(0, y, 0));
|
||||
f.full_collision || f.legacy_solid
|
||||
})
|
||||
.map_or(64, |y| y + 1);
|
||||
@@ -1764,7 +1767,7 @@ impl Game<'_> {
|
||||
next.y.floor() as i32,
|
||||
next.z.floor() as i32,
|
||||
];
|
||||
let f = self.res.facts.get(self.world.block(p[0], p[1], p[2]));
|
||||
let f = self.res.facts().get(self.world.block(p[0], p[1], p[2]));
|
||||
f.full_collision || f.legacy_solid
|
||||
};
|
||||
let hit_player = player.is_some_and(|pb| {
|
||||
@@ -1866,9 +1869,9 @@ impl Game<'_> {
|
||||
batch.width as i32,
|
||||
batch.height as i32,
|
||||
&bars,
|
||||
&self.atlas.font,
|
||||
&self.gui.atlas.font,
|
||||
);
|
||||
hud_layout::paint(batch, &self.atlas, &draws);
|
||||
hud_layout::paint(batch, &self.gui.atlas, &draws);
|
||||
}
|
||||
/// The dragon fight's boss bar shows (`EnderDragonFight.dragonEvent`,
|
||||
/// with `setCreateWorldFog`).
|
||||
@@ -1906,7 +1909,13 @@ impl Game<'_> {
|
||||
return;
|
||||
};
|
||||
let a = alpha as f32;
|
||||
let sprite = |n: &str| self.atlas.sprites.get(n).map(|r| [r.u0, r.v0, r.u1, r.v1]);
|
||||
let sprite = |n: &str| {
|
||||
self.gui
|
||||
.atlas
|
||||
.sprites
|
||||
.get(n)
|
||||
.map(|r| [r.u0, r.v0, r.u1, r.v1])
|
||||
};
|
||||
let (Some(skin), Some(eyes)) = (
|
||||
sprite("entity/enderdragon/dragon"),
|
||||
sprite("entity/enderdragon/dragon_eyes"),
|
||||
@@ -2072,7 +2081,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// `submitRays`: the death rays from a fixed seed, fading in white to magenta.
|
||||
fn dragon_rays(&self, base: glam::Mat4, t: f32, out: &mut Vec<Vertex>) {
|
||||
let white = self.atlas.font.white();
|
||||
let white = self.gui.atlas.font.white();
|
||||
let uv = [white.u0, white.v0];
|
||||
let over = if t > 0.8 {
|
||||
((t - 0.8) / 0.2).min(1.0)
|
||||
@@ -2128,6 +2137,7 @@ impl Game<'_> {
|
||||
out: &mut Vec<Vertex>,
|
||||
) {
|
||||
let Some(s) = self
|
||||
.gui
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/end_crystal/end_crystal_beam")
|
||||
@@ -2189,6 +2199,7 @@ impl Game<'_> {
|
||||
out: &mut Vec<Vertex>,
|
||||
) {
|
||||
let Some(s) = self
|
||||
.gui
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/enderdragon/dragon_fireball")
|
||||
@@ -2301,6 +2312,7 @@ impl Crystal {
|
||||
pub(super) fn from_nbt(tag: &Tag, time: i32) -> Option<Self> {
|
||||
let (position, _, _) = horizon_client::entity_nbt::boat_from_nbt(tag)?;
|
||||
Some(Self {
|
||||
id: 0,
|
||||
position,
|
||||
show_bottom: !matches!(tag.get("ShowBottom"), Some(Tag::Byte(0))),
|
||||
time,
|
||||
@@ -2377,7 +2389,7 @@ impl Game<'_> {
|
||||
}
|
||||
let name = self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(hit.pos[0], hit.pos[1], hit.pos[2]))
|
||||
.name
|
||||
.clone();
|
||||
@@ -2387,7 +2399,7 @@ impl Game<'_> {
|
||||
let above = [hit.pos[0], hit.pos[1] + 1, hit.pos[2]];
|
||||
if !self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.is_air(self.world.block(above[0], above[1], above[2]))
|
||||
{
|
||||
return false;
|
||||
@@ -2403,6 +2415,7 @@ impl Game<'_> {
|
||||
}
|
||||
let time = self.world.random.next_int_bound(100_000).unwrap_or(0);
|
||||
self.crystals.push(Crystal {
|
||||
id: 0,
|
||||
position: Vec3::new(x + 0.5, y, z + 0.5),
|
||||
show_bottom: false,
|
||||
time,
|
||||
@@ -2507,7 +2520,7 @@ impl Game<'_> {
|
||||
}
|
||||
fn block_name_at(&self, p: [i32; 3]) -> std::sync::Arc<str> {
|
||||
self.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(p[0], p[1], p[2]))
|
||||
.name
|
||||
.clone()
|
||||
@@ -2609,7 +2622,7 @@ impl Game<'_> {
|
||||
for y in h - 10..=h + 10 {
|
||||
for z in cz - 10..=cz + 10 {
|
||||
for x in cx - 10..=cx + 10 {
|
||||
if !self.res.facts.is_air(self.world.block(x, y, z)) {
|
||||
if !self.res.facts().is_air(self.world.block(x, y, z)) {
|
||||
let _ = self.level_set([x, y, z], air);
|
||||
}
|
||||
}
|
||||
@@ -2631,7 +2644,7 @@ impl Game<'_> {
|
||||
if &*self.block_name_at([x, y, z]) != "minecraft:obsidian" {
|
||||
let _ = self.set_state_named([x, y, z], "minecraft:obsidian", &[]);
|
||||
}
|
||||
} else if y > 65 && !self.res.facts.is_air(self.world.block(x, y, z)) {
|
||||
} else if y > 65 && !self.res.facts().is_air(self.world.block(x, y, z)) {
|
||||
let _ = self.level_set([x, y, z], air);
|
||||
}
|
||||
}
|
||||
@@ -2665,6 +2678,7 @@ impl Game<'_> {
|
||||
.retain(|c| c.position.distance_squared(at) > 0.01);
|
||||
let time = self.world.random.next_int_bound(100_000).unwrap_or(0);
|
||||
self.crystals.push(Crystal {
|
||||
id: 0,
|
||||
position: at,
|
||||
show_bottom: true,
|
||||
time,
|
||||
|
||||
@@ -16,7 +16,7 @@ impl Game<'_> {
|
||||
let held = self.inventory[self.selected].as_ref();
|
||||
speed += self
|
||||
.res
|
||||
.stations
|
||||
.stations()
|
||||
.enchantments
|
||||
.attribute_add(held, "minecraft:mining_efficiency") as f32;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ impl Game<'_> {
|
||||
pub(super) fn submerged_mining_speed(&self) -> f32 {
|
||||
let mut total = 0.0;
|
||||
for stack in self.armor.iter().flatten() {
|
||||
for (attr, _, amount, op) in self.res.stations.enchantments.attributes(stack) {
|
||||
for (attr, _, amount, op) in self.res.stations().enchantments.attributes(stack) {
|
||||
if attr == "minecraft:submerged_mining_speed" && op == "add_multiplied_total" {
|
||||
total += amount;
|
||||
}
|
||||
@@ -36,13 +36,13 @@ impl Game<'_> {
|
||||
}
|
||||
/// `EnchantmentHelper.processDurabilityChange` (unbreaking) for `amount` points.
|
||||
pub(super) fn durability_loss(&mut self, stack: &ItemStack, amount: u32) -> u32 {
|
||||
let e = &self.res.stations.enchantments;
|
||||
let e = &self.res.stations().enchantments;
|
||||
if !e.has_component(stack, "minecraft:item_damage") {
|
||||
return amount;
|
||||
}
|
||||
let ctx = EffectContext {
|
||||
tool: Some(&stack.item),
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
e.modify_value(
|
||||
@@ -65,10 +65,10 @@ impl Game<'_> {
|
||||
direct_attacker: Some("minecraft:player"),
|
||||
is_direct: true,
|
||||
damage_type: Some("minecraft:player_attack"),
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
self.res.stations.enchantments.modify_value(
|
||||
self.res.stations().enchantments.modify_value(
|
||||
Some(&held),
|
||||
"minecraft:damage",
|
||||
&ctx,
|
||||
@@ -96,10 +96,10 @@ impl Game<'_> {
|
||||
attacker: Some("minecraft:player"),
|
||||
direct_attacker: Some("minecraft:player"),
|
||||
is_direct: true,
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
let knockback = self.res.stations.enchantments.modify_value(
|
||||
let knockback = self.res.stations().enchantments.modify_value(
|
||||
Some(&held),
|
||||
"minecraft:knockback",
|
||||
&ctx,
|
||||
@@ -130,7 +130,7 @@ impl Game<'_> {
|
||||
// minecraft:post_attack ignite effects of the attacker's weapon (fire aspect).
|
||||
let mut ignite = 0.0f32;
|
||||
for (id, level) in held.enchantments() {
|
||||
let Some(def) = self.res.stations.enchantments.get(id) else {
|
||||
let Some(def) = self.res.stations().enchantments.get(id) else {
|
||||
continue;
|
||||
};
|
||||
for effect in def.effects["minecraft:post_attack"]
|
||||
@@ -145,7 +145,7 @@ impl Game<'_> {
|
||||
let mut random = self.world.random.clone();
|
||||
let ok = effect.get("requirements").is_none_or(|r| {
|
||||
self.res
|
||||
.stations
|
||||
.stations()
|
||||
.enchantments
|
||||
.condition(r, *level, &ctx, &mut random)
|
||||
});
|
||||
@@ -182,13 +182,13 @@ impl Game<'_> {
|
||||
attacker: Some("minecraft:player"),
|
||||
direct_attacker: Some("minecraft:player"),
|
||||
is_direct: true,
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
direct_motion: Some(motion),
|
||||
..Default::default()
|
||||
};
|
||||
let mut bursts = Vec::new();
|
||||
for (id, level) in held.enchantments() {
|
||||
let Some(def) = self.res.stations.enchantments.get(id) else {
|
||||
let Some(def) = self.res.stations().enchantments.get(id) else {
|
||||
continue;
|
||||
};
|
||||
for effect in def.effects["minecraft:post_attack"]
|
||||
@@ -205,7 +205,7 @@ impl Game<'_> {
|
||||
continue;
|
||||
}
|
||||
let ok = effect.get("requirements").is_none_or(|r| {
|
||||
self.res.stations.enchantments.condition(
|
||||
self.res.stations().enchantments.condition(
|
||||
r,
|
||||
*level,
|
||||
&ctx,
|
||||
@@ -254,16 +254,16 @@ impl Game<'_> {
|
||||
if level == 0 {
|
||||
continue;
|
||||
}
|
||||
let Some(def) = self.res.stations.enchantments.get("minecraft:thorns") else {
|
||||
let Some(def) = self.res.stations().enchantments.get("minecraft:thorns") else {
|
||||
continue;
|
||||
};
|
||||
let effect = def.effects["minecraft:post_attack"][0].clone();
|
||||
let ctx = EffectContext {
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut random = self.world.random.clone();
|
||||
let ok = self.res.stations.enchantments.condition(
|
||||
let ok = self.res.stations().enchantments.condition(
|
||||
&effect["requirements"],
|
||||
level,
|
||||
&ctx,
|
||||
@@ -286,7 +286,7 @@ impl Game<'_> {
|
||||
s.damage += 2;
|
||||
if self
|
||||
.res
|
||||
.items
|
||||
.items()
|
||||
.get(&s.item)
|
||||
.is_some_and(|i| s.damage >= i.max_damage)
|
||||
{
|
||||
@@ -330,10 +330,10 @@ impl Game<'_> {
|
||||
};
|
||||
let Some(stack) = stack else { return amount };
|
||||
let ctx = EffectContext {
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
let to_repair_xp = self.res.stations.enchantments.modify_value(
|
||||
let to_repair_xp = self.res.stations().enchantments.modify_value(
|
||||
Some(&stack),
|
||||
"minecraft:repair_with_xp",
|
||||
&ctx,
|
||||
@@ -364,11 +364,11 @@ impl Game<'_> {
|
||||
let Some(bow) = self.inventory[self.selected].clone() else {
|
||||
return (0.0, false);
|
||||
};
|
||||
let e = &self.res.stations.enchantments;
|
||||
let e = &self.res.stations().enchantments;
|
||||
let ctx = EffectContext {
|
||||
direct_attacker: Some("minecraft:arrow"),
|
||||
attacker: Some("minecraft:player"),
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
let power = e.modify_value(
|
||||
@@ -380,7 +380,7 @@ impl Game<'_> {
|
||||
);
|
||||
let ammo_ctx = EffectContext {
|
||||
tool: Some("minecraft:arrow"),
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
let infinity = e.has_component(&bow, "minecraft:ammo_use")
|
||||
@@ -399,12 +399,12 @@ impl Game<'_> {
|
||||
let bow = self.inventory[self.selected].clone()?;
|
||||
let ctx = EffectContext {
|
||||
this: Some("minecraft:arrow"),
|
||||
items: Some(&self.res.items),
|
||||
items: Some(self.res.items()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut ignite: Option<f32> = None;
|
||||
for (id, level) in bow.enchantments() {
|
||||
let Some(def) = self.res.stations.enchantments.get(id) else {
|
||||
let Some(def) = self.res.stations().enchantments.get(id) else {
|
||||
continue;
|
||||
};
|
||||
for effect in def.effects["minecraft:projectile_spawned"]
|
||||
@@ -416,7 +416,7 @@ impl Game<'_> {
|
||||
continue;
|
||||
}
|
||||
let ok = effect.get("requirements").is_none_or(|r| {
|
||||
self.res.stations.enchantments.condition(
|
||||
self.res.stations().enchantments.condition(
|
||||
r,
|
||||
*level,
|
||||
&ctx,
|
||||
@@ -436,7 +436,7 @@ impl Game<'_> {
|
||||
pub(super) fn apply_enchantment_attributes(&mut self) {
|
||||
let mut wanted: Vec<(String, String, f64, String)> = Vec::new();
|
||||
for stack in self.armor.iter().flatten() {
|
||||
wanted.extend(self.res.stations.enchantments.attributes(stack));
|
||||
wanted.extend(self.res.stations().enchantments.attributes(stack));
|
||||
}
|
||||
let Some(p) = self.player.as_mut() else {
|
||||
return;
|
||||
|
||||
@@ -132,9 +132,9 @@ impl Game<'_> {
|
||||
/// The environment attributes of the current dimension.
|
||||
pub(super) fn dim_environment(&self) -> &Environment {
|
||||
match self.dim {
|
||||
Dim::Overworld => &self.res.environment,
|
||||
Dim::Nether => &self.res.nether_environment,
|
||||
Dim::End => &self.res.end_environment,
|
||||
Dim::Overworld => self.res.environment(),
|
||||
Dim::Nether => self.res.nether_environment(),
|
||||
Dim::End => self.res.end_environment(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ impl Game<'_> {
|
||||
/// tinted 0x282828. The atlas does not wrap, so each face is 16×16 quads.
|
||||
pub(super) fn end_sky_geometry(&self) -> Vec<Vertex> {
|
||||
let mut out = Vec::with_capacity(6 * 256 * 4);
|
||||
let Some(r) = self.atlas.sprites.get("environment/end_sky").copied() else {
|
||||
let Some(r) = self.gui.atlas.sprites.get("environment/end_sky").copied() else {
|
||||
return out;
|
||||
};
|
||||
use std::f32::consts::FRAC_PI_2;
|
||||
@@ -184,6 +184,7 @@ impl Game<'_> {
|
||||
let intensity = self.end.flash.intensity(self.clock.fraction() as f32);
|
||||
if intensity > 1e-5
|
||||
&& let Some(r) = self
|
||||
.gui
|
||||
.atlas
|
||||
.sprites
|
||||
.get("environment/celestial/end_flash")
|
||||
@@ -224,7 +225,7 @@ impl Game<'_> {
|
||||
|
||||
pub(super) fn block_name(&self, p: [i32; 3]) -> std::sync::Arc<str> {
|
||||
self.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(p[0], p[1], p[2]))
|
||||
.name
|
||||
.clone()
|
||||
@@ -561,7 +562,7 @@ impl Game<'_> {
|
||||
let mut y = (0..256)
|
||||
.rev()
|
||||
.find(|&y| {
|
||||
let f = self.res.facts.get(self.world.block(0, y, 0));
|
||||
let f = self.res.facts().get(self.world.block(0, y, 0));
|
||||
(f.full_collision || f.fluid != horizon_client::blocks::Fluid::None)
|
||||
&& !f.name.ends_with("_leaves")
|
||||
})
|
||||
@@ -783,7 +784,7 @@ impl Game<'_> {
|
||||
let mut y = 255;
|
||||
while y > floor {
|
||||
let p = [around[0] + xd, y, around[2] + zd];
|
||||
let f = self.res.facts.get(self.world.block(p[0], p[1], p[2]));
|
||||
let f = self.res.facts().get(self.world.block(p[0], p[1], p[2]));
|
||||
if f.full_collision && (allow_bedrock || &*f.name != "minecraft:bedrock") {
|
||||
tallest = Some(p);
|
||||
break;
|
||||
@@ -839,12 +840,12 @@ impl Game<'_> {
|
||||
if &*self.block_name([x, y, z]) != "minecraft:end_stone"
|
||||
|| self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(x, y + 1, z))
|
||||
.full_collision
|
||||
|| self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(x, y + 2, z))
|
||||
.full_collision
|
||||
{
|
||||
@@ -920,7 +921,8 @@ impl Game<'_> {
|
||||
fn end_crystal_geometry(&self, camera: glam::DVec3, out: &mut Vec<Vertex>) {
|
||||
let (Some(model), Some(r)) = (
|
||||
self.crystal_model.as_ref(),
|
||||
self.atlas
|
||||
self.gui
|
||||
.atlas
|
||||
.sprites
|
||||
.get("entity/end_crystal/end_crystal")
|
||||
.copied(),
|
||||
@@ -1073,7 +1075,7 @@ impl Game<'_> {
|
||||
|
||||
/// ThrownItemRenderer: the ender eye item facing the camera.
|
||||
fn eye_geometry(&self, camera: glam::DVec3, out: &mut Vec<Vertex>) {
|
||||
let Some(r) = self.atlas.sprites.get("item/ender_eye").copied() else {
|
||||
let Some(r) = self.gui.atlas.sprites.get("item/ender_eye").copied() else {
|
||||
return;
|
||||
};
|
||||
let alpha = self.clock.fraction();
|
||||
|
||||
@@ -21,7 +21,7 @@ impl Game<'_> {
|
||||
&& self.settings.resource_packs.iter().all(|id| id == "vanilla")
|
||||
&& self.player.is_some()
|
||||
&& !self.spectator()
|
||||
&& !opaque(self.res.facts.get(self.world.block(at[0], at[1], at[2]))))
|
||||
&& !opaque(self.res.facts().get(self.world.block(at[0], at[1], at[2]))))
|
||||
.then(|| Culler::new(camera.to_array(), 8_192));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ impl Game<'_> {
|
||||
if let Some(culler) = &self.entity_culler {
|
||||
culler.cull_vertices(vertices, start, |pos| {
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
if !opaque(self.res.facts.get(state)) {
|
||||
if !opaque(self.res.facts().get(state)) {
|
||||
return false;
|
||||
}
|
||||
let Some(y) = pos[1].checked_sub(MIN_Y) else {
|
||||
@@ -49,3 +49,64 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Entity.shouldRenderAtSqrDistance's default range: 64 times the bounding
|
||||
/// box's mean edge, scaled by the entity distance option.
|
||||
pub(super) fn default_range(size: glam::DVec3, view_scale: f32) -> f64 {
|
||||
let edge = (size.x + size.y + size.z) / 3.0;
|
||||
let edge = if edge.is_nan() { 1.0 } else { edge };
|
||||
edge * 64.0 * f64::from(view_scale)
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// EntityRenderer.shouldRender: the entity within `range` blocks of the
|
||||
/// camera, measured from its current `position`, and its culling box
|
||||
/// (`lo`..`hi`, interpolated, in world space) grown by 0.5 in the view.
|
||||
pub(super) fn entity_in_view(
|
||||
&self,
|
||||
camera: glam::DVec3,
|
||||
position: glam::DVec3,
|
||||
range: f64,
|
||||
lo: glam::DVec3,
|
||||
hi: glam::DVec3,
|
||||
) -> bool {
|
||||
if (position - camera).length_squared() >= range * range {
|
||||
return false;
|
||||
}
|
||||
self.view_frustum.as_ref().is_none_or(|view| {
|
||||
view.intersects(
|
||||
(lo - camera - glam::DVec3::splat(0.5)).as_vec3(),
|
||||
(hi - camera + glam::DVec3::splat(0.5)).as_vec3(),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// An entity's position as a `DVec3`.
|
||||
pub(super) fn at(p: horizon_core::geometry::Vec3) -> glam::DVec3 {
|
||||
glam::DVec3::new(p.x, p.y, p.z)
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// `entity_in_view` for an entity whose box stands on its position,
|
||||
/// `width` wide and `height` tall, interpolated by `alpha` and grown by
|
||||
/// `grow` (a renderer's getBoundingBoxForCulling).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn standing_entity_in_view(
|
||||
&self,
|
||||
camera: glam::DVec3,
|
||||
previous: glam::DVec3,
|
||||
position: glam::DVec3,
|
||||
alpha: f64,
|
||||
width: f64,
|
||||
height: f64,
|
||||
range: f64,
|
||||
grow: f64,
|
||||
) -> bool {
|
||||
let p = previous.lerp(position, alpha);
|
||||
let half = glam::DVec3::new(width / 2.0 + grow, grow, width / 2.0 + grow);
|
||||
let lo = p - half;
|
||||
let hi = p + glam::DVec3::new(half.x, height + grow, half.z);
|
||||
self.entity_in_view(camera, position, range, lo, hi)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,11 @@ impl Game<'_> {
|
||||
Snapshot {
|
||||
screen: self.screen_label(),
|
||||
dimension: self.dim.id().to_string(),
|
||||
chat: self.ui.chat.received,
|
||||
// A remote client counts the server's lines itself.
|
||||
chat: self
|
||||
.remote
|
||||
.as_ref()
|
||||
.map_or(self.ui.chat.received, |r| r.chat_received),
|
||||
counts: if world.is_some() {
|
||||
self.inventory_counts()
|
||||
} else {
|
||||
@@ -189,8 +193,19 @@ impl Game<'_> {
|
||||
if let Some(before) = &self.events.last
|
||||
&& *before != now
|
||||
{
|
||||
let new_chat = (now.chat - before.chat).min(100) as usize;
|
||||
let lines = self.ui.chat.recent_lines(new_chat);
|
||||
// Joining or leaving a server starts another count.
|
||||
let new_chat = now.chat.saturating_sub(before.chat).min(100) as usize;
|
||||
// Newest first; the remote client keeps its lines oldest first.
|
||||
let lines = match &self.remote {
|
||||
Some(r) => r
|
||||
.chat
|
||||
.iter()
|
||||
.rev()
|
||||
.take(new_chat)
|
||||
.map(|(t, _)| t.clone())
|
||||
.collect(),
|
||||
None => self.ui.chat.recent_lines(new_chat),
|
||||
};
|
||||
for event in diff(before, &now, &lines) {
|
||||
self.events.push(self.ticks, event);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ impl Game<'_> {
|
||||
break;
|
||||
}
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
let f = self.res.facts.get(state);
|
||||
let f = self.res.facts().get(state);
|
||||
let fluid = if f.fluid != Fluid::None {
|
||||
100.0f32
|
||||
} else {
|
||||
@@ -206,7 +206,7 @@ impl Game<'_> {
|
||||
Some((at, resistance)) if at == pos => {
|
||||
power -= (resistance + 0.3) * 0.3;
|
||||
}
|
||||
_ if !self.res.facts.is_air(state) || f.fluid != Fluid::None => {
|
||||
_ if !self.res.facts().is_air(state) || f.fluid != Fluid::None => {
|
||||
power -= (f.explosion_resistance.max(fluid) + 0.3) * 0.3;
|
||||
}
|
||||
_ => {}
|
||||
@@ -450,11 +450,11 @@ impl Game<'_> {
|
||||
if self.world.random.next_int_bound(3).unwrap_or(1) == 0
|
||||
&& self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.is_air(self.world.block(pos[0], pos[1], pos[2]))
|
||||
&& self
|
||||
.res
|
||||
.facts
|
||||
.facts()
|
||||
.get(self.world.block(pos[0], pos[1] - 1, pos[2]))
|
||||
.solid_render
|
||||
{
|
||||
@@ -475,7 +475,7 @@ impl Game<'_> {
|
||||
} else {
|
||||
targets.len()
|
||||
};
|
||||
let (world, facts) = (&self.world, &self.res.facts);
|
||||
let (world, facts) = (&self.world, self.res.facts());
|
||||
self.particles.explosion(center, radius, block_count, &|b| {
|
||||
facts.is_air(world.block(b[0], b[1], b[2]))
|
||||
});
|
||||
@@ -490,10 +490,10 @@ impl Game<'_> {
|
||||
stacks: &mut Vec<([i32; 3], ItemStack)>,
|
||||
) -> Result<()> {
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
if self.res.facts.is_air(state) {
|
||||
if self.res.facts().is_air(state) {
|
||||
return Ok(());
|
||||
}
|
||||
let name = self.res.facts.get(state).name.clone();
|
||||
let name = self.res.facts().get(state).name.clone();
|
||||
let is_tnt = &*name == "minecraft:tnt";
|
||||
// Block.onExplosionHit: the drops copy from the block entity, which
|
||||
// then spills its contents as the block turns to air.
|
||||
@@ -510,7 +510,7 @@ impl Game<'_> {
|
||||
// tables' survives_explosion and explosion_decay draw from their
|
||||
// random sequence.
|
||||
let decay = (interaction == BlockInteraction::DestroyWithDecay).then_some(radius);
|
||||
let drops = self.res.items.block_drops_exploded(
|
||||
let drops = self.res.items().block_drops_exploded(
|
||||
self.pack.assets.registry,
|
||||
state,
|
||||
None,
|
||||
|
||||
@@ -188,7 +188,7 @@ impl Game<'_> {
|
||||
let radius = ((reach / 16.0).ceil() as i32 + 1).min(self.settings.render_distance.max(2));
|
||||
self.extras.minimap.update(
|
||||
&self.world,
|
||||
&self.res.facts,
|
||||
self.res.facts(),
|
||||
(bx >> 4, bz >> 4),
|
||||
radius,
|
||||
layer,
|
||||
@@ -197,10 +197,10 @@ impl Game<'_> {
|
||||
if !self.extras.minimap.compose(view) {
|
||||
return;
|
||||
}
|
||||
let Some(rect) = self.atlas.sprites.get(MINIMAP_SPRITE).copied() else {
|
||||
let Some(rect) = self.gui.atlas.sprites.get(MINIMAP_SPRITE).copied() else {
|
||||
return;
|
||||
};
|
||||
let (w, h) = (self.atlas.width as f32, self.atlas.height as f32);
|
||||
let (w, h) = (self.gui.atlas.width as f32, self.gui.atlas.height as f32);
|
||||
self.map_patches.push(horizon_client::font::Patch {
|
||||
x: (rect.u0 * w).round() as u32,
|
||||
y: (rect.v0 * h).round() as u32,
|
||||
@@ -246,7 +246,7 @@ impl Game<'_> {
|
||||
let (map_corner, map_size) = (e.minimap_corner, f32::from(e.minimap_size));
|
||||
let visible = |corner| !(self.debug && corner == Corner::TopLeft);
|
||||
let mut corners = Corners::new(batch.width, batch.height, self.effect_rows_height());
|
||||
let atlas = &self.atlas;
|
||||
let atlas = &self.gui.atlas;
|
||||
if let Some(view) = self.minimap_view()
|
||||
&& visible(map_corner)
|
||||
&& !self.extras.minimap.image.is_empty()
|
||||
@@ -290,7 +290,7 @@ impl Game<'_> {
|
||||
use_: self.extras.mouse[1],
|
||||
cps,
|
||||
};
|
||||
extras_hud::draw_keystrokes(batch, &self.atlas, &mut corners, keys_corner, &k);
|
||||
extras_hud::draw_keystrokes(batch, &self.gui.atlas, &mut corners, keys_corner, &k);
|
||||
}
|
||||
if mod_panels {
|
||||
self.draw_mod_panels(batch, &mut corners);
|
||||
|
||||
@@ -6,7 +6,7 @@ use horizon_world::level::LevelEvent;
|
||||
|
||||
impl Game<'_> {
|
||||
pub(super) fn finish_falling_block(&mut self, mut block: FallingBlock, pos: [i32; 3]) {
|
||||
let anvil = self.res.facts.get(block.state).name.ends_with("anvil");
|
||||
let anvil = self.res.facts().get(block.state).name.ends_with("anvil");
|
||||
if let Some(impact) = block.damage.impact(block.fall_distance) {
|
||||
if impact.amount > 0.0 {
|
||||
falling_block::hurt_mobs(&mut self.mobs, block.position, impact.amount);
|
||||
@@ -80,7 +80,7 @@ impl Game<'_> {
|
||||
&& block.drop_item
|
||||
&& self.ui.rules.bool("entity_drops")
|
||||
{
|
||||
let item = self.res.facts.get(block.state).item.clone();
|
||||
let item = self.res.facts().get(block.state).item.clone();
|
||||
if &*item != "minecraft:air" {
|
||||
self.pop_resource(
|
||||
pos,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user