diff --git a/.github/workflows/parity-main.yml b/.github/workflows/parity-main.yml
index 1debcc694..c47005ab0 100644
--- a/.github/workflows/parity-main.yml
+++ b/.github/workflows/parity-main.yml
@@ -23,9 +23,11 @@ env:
jobs:
parity-main:
- # The Mac mini's runners only: a desktop job slowed down because the maintainer came back could time out, and a
- # failure here bisects and comments on merges.
- runs-on: [self-hosted, horizon-game, macOS]
+ # A Mac mini runner of its own (ludovics-mac-mini-2 holds only this label since 2026-10-26): behind PR parity jobs
+ # this run waited 2 h while every merge replaced the pending one, and on the release runner a release then waited
+ # behind the next run. PR parity jobs have ludovics-mac-mini and the desktop. Not the desktop: a job slowed down
+ # because the maintainer came back could time out, and a failure here bisects and comments on merges.
+ runs-on: [self-hosted, macOS, horizon-parity-main]
timeout-minutes: 240 # a core-crate batch reruns ~300 harnesses (~60-90 min), a bisect a few rounds of the failures
steps:
- uses: actions/checkout@v4
diff --git a/.github/workflows/parity.yml b/.github/workflows/parity.yml
index 577380338..b48be1d05 100644
--- a/.github/workflows/parity.yml
+++ b/.github/workflows/parity.yml
@@ -36,7 +36,19 @@ jobs:
- name: Tools from the runner
run: bash tools/ci/runner-env.sh
- name: Vanilla data, and resources prepared by this preparer
- run: bash tools/ci/vanilla-data.sh
+ env:
+ BASE_SHA: ${{ inputs.base }}
+ run: |
+ # main's script: one written before a fix to it left a real .local/horizon-client without sounds.json on
+ # the runner, and every later job there failed `subtitle`. A branch that changes the script runs its own.
+ set -euo pipefail
+ if git rev-parse --verify -q origin/main >/dev/null \
+ && git diff --quiet "$(git merge-base "$BASE_SHA" HEAD)" HEAD -- tools/ci/vanilla-data.sh; then
+ git show origin/main:tools/ci/vanilla-data.sh > "$RUNNER_TEMP/vanilla-data.sh"
+ bash "$RUNNER_TEMP/vanilla-data.sh"
+ else
+ bash tools/ci/vanilla-data.sh
+ fi
- name: The prepared output is the one the preparer's OUTPUT_VERSION says
env:
BASE_SHA: ${{ inputs.base }}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 05f590096..d879f0d61 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -79,9 +79,50 @@ jobs:
# A dry run builds whatever the decision, to test the builds.
if [[ "${{ steps.mode.outputs.dry_run }}" == true ]]; then echo "release=true" >> "$GITHUB_OUTPUT"; fi
- build:
+ exporters:
needs: decide
if: needs.decide.outputs.release == 'true'
+ # This runner holds the maintainer's own pinned Minecraft jars. Only our classes leave it.
+ runs-on: ${{ vars.MAC_RUNNER || 'ludovics-mac-mini' }}
+ # Three full preparations (two isolated, one batched) besides the compile.
+ timeout-minutes: 60
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ ref: ${{ needs.decide.outputs.head }}
+ persist-credentials: false
+ clean: true
+ - uses: dtolnay/rust-toolchain@stable
+ - run: bash tools/ci/runner-env.sh
+ - run: bash tools/ci/vanilla-data.sh
+ - name: Compile and validate original exporters against the pinned jars
+ shell: bash
+ run: |
+ set -euo pipefail
+ # target/ is gone after the clean checkout, and vanilla-data.sh builds the preparer only when it
+ # prepares afresh.
+ cargo build --release --locked -p horizon-prepare
+ # Compiled here, never taken from the runner's shared preparations: pull requests' parity jobs
+ # write those (vanilla-data.sh links .local/exporters to them).
+ rm -rf .local/exporters
+ bundle=$(target/release/horizon-prepare compile-exporters --root "$PWD" | tail -1)
+ mkdir -p exporters
+ cp -R "$bundle/server" "$bundle/client" "$bundle/manifest.json" exporters/
+ # Only our classes and their manifest leave this runner.
+ stray=$(find exporters -type f ! -path exporters/manifest.json \
+ ! \( -name '*.class' \( -path 'exporters/server/dev/horizonlab/parity/*' -o -path 'exporters/client/dev/horizonlab/parity/*' \) \))
+ [ -z "$stray" ] || { echo "::error::not one of our classes: $stray"; exit 1; }
+ python3 tools/check_prepare_exporters.py --binary target/release/horizon-prepare
+ - uses: actions/upload-artifact@v4
+ with:
+ name: original-exporters
+ path: exporters/
+ if-no-files-found: error
+ retention-days: 3
+
+ build:
+ needs: [decide, exporters]
+ if: needs.decide.outputs.release == 'true'
name: build ${{ matrix.name }}
strategy:
fail-fast: false
@@ -220,6 +261,10 @@ jobs:
path: ${{ runner.temp }}/smoke-test.json
if-no-files-found: error
retention-days: 3
+ - uses: actions/download-artifact@v4
+ with:
+ name: original-exporters
+ path: exporters
- name: Package
run: |
set -euo pipefail
diff --git a/.gitignore b/.gitignore
index 7fffd6a99..6bdae649a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,3 +31,6 @@
/.horizon-cache/
/crash-reports/
/debug/
+
+# Release-only compiled original exporter bundle.
+/exporters/
diff --git a/Cargo.lock b/Cargo.lock
index 30c0b14d7..1a2aad855 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -20,9 +20,9 @@ checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
[[package]]
name = "addr2line"
-version = "0.25.1"
+version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b"
+checksum = "59317f77929f0e679d39364702289274de2f0f0b22cbf50b2b8cff2169a0b27a"
dependencies = [
"gimli",
]
@@ -187,6 +187,17 @@ dependencies = [
"libloading",
]
+[[package]]
+name = "async-trait"
+version = "0.1.92"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.6",
+]
+
[[package]]
name = "atomic-waker"
version = "1.1.2"
@@ -531,7 +542,7 @@ dependencies = [
"jni 0.21.1",
"js-sys",
"libc",
- "mach2",
+ "mach2 0.4.3",
"ndk",
"ndk-context",
"num-derive",
@@ -545,6 +556,15 @@ dependencies = [
"windows 0.54.0",
]
+[[package]]
+name = "cpp_demangle"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0667304c32ea56cb4cd6d2d7c0cfe9a2f8041229db8c033af7f8d69492429def"
+dependencies = [
+ "cfg-if",
+]
+
[[package]]
name = "cpufeatures"
version = "0.2.17"
@@ -556,46 +576,48 @@ dependencies = [
[[package]]
name = "cranelift-assembler-x64"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9e92993516bcc43fd4e511b31d2e0c0c24f6b7ac18bb39e32cac2bfc05ea378e"
+checksum = "e6071a4f1df4837aa03d1e4d53067784acafe270ffc7dad66a7f39832204da3f"
dependencies = [
"cranelift-assembler-x64-meta",
]
[[package]]
name = "cranelift-assembler-x64-meta"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97eeeb61b08ec484f274119faf3a8a1b80dd300b0208c0247d16d05982fc89fe"
+checksum = "5e3b92a9cc90388fe70e63640af30b734387449445aef0176ab2028e9892d70e"
dependencies = [
"cranelift-srcgen",
]
[[package]]
name = "cranelift-bforest"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "782eb44158681a105d157cb0ce63e3dc83f78ef5674266c12234f49da3f5c6e8"
+checksum = "f45c85646c4425cc85b868effaf20c302b437a3fb79bb27a64513dd522f07411"
dependencies = [
"cranelift-entity",
+ "wasmtime-internal-core",
]
[[package]]
name = "cranelift-bitset"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "edd59af193204c4f025fb2c2d9ee0aeb1f60929edf000b0dfa3d45543a62f264"
+checksum = "94f56b5c7d564cfa03aa269a6b98c916cab4d545196a391d31403a23ef39333a"
dependencies = [
"serde",
"serde_derive",
+ "wasmtime-internal-core",
]
[[package]]
name = "cranelift-codegen"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b1c29bd985057d790db25f6bc60b369b311aa2d75c2f496a7e9993585bfc7d60"
+checksum = "2c073641ce6e382814a8220331cc1ea2c782a9ea5d5da6d0f7f7c0541192693e"
dependencies = [
"bumpalo",
"cranelift-assembler-x64",
@@ -607,22 +629,26 @@ dependencies = [
"cranelift-entity",
"cranelift-isle",
"gimli",
- "hashbrown 0.15.5",
+ "hashbrown 0.17.1",
+ "libm",
"log",
+ "postcard",
"pulley-interpreter",
"regalloc2",
"rustc-hash 2.1.3",
"serde",
+ "serde_derive",
+ "sha2",
"smallvec",
"target-lexicon",
- "wasmtime-internal-math",
+ "wasmtime-internal-core",
]
[[package]]
name = "cranelift-codegen-meta"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9ef8a8495f19212f92db8425f768ffc67000c5cb417a0664475a8d09596700f"
+checksum = "db226fafea5194921de10dccf35ac2863500313990f770cbe8b26c51eebec4d4"
dependencies = [
"cranelift-assembler-x64-meta",
"cranelift-codegen-shared",
@@ -633,37 +659,39 @@ dependencies = [
[[package]]
name = "cranelift-codegen-shared"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3aa5099097666baf45bd68ef036327c8f29d8785fffaaa7db3b3b6b7e94bcc6"
+checksum = "cf8ac46b2c8e328ca979810426ea635ef90ecc8c54fd3296bde31ab470a48a1d"
[[package]]
name = "cranelift-control"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "26f67f4f4e92c2934f40c2ff4574400bd27326932aad937a438b7fb459f60a63"
+checksum = "6754e0ab97915209ea6ce6549f6443b018e1338142ada4c856cec213ee82e4b8"
dependencies = [
"arbitrary",
]
[[package]]
name = "cranelift-entity"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8393d09f0abaa504896069e79f4eb6f15eb1853e5645732b082dac1ed292aaa8"
+checksum = "774d25e36df18696f63a284e9c4ea43455e2ebcca6308e0e02301f18c8e777e2"
dependencies = [
"cranelift-bitset",
"serde",
"serde_derive",
+ "wasmtime-internal-core",
]
[[package]]
name = "cranelift-frontend"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "580cfaecbd11476dd82f6a393123dcbd9dfe583467df8d0c8441c641444d4985"
+checksum = "69cfcb31405e2de2a48e5a6de8e07a3d8b77f35caa3e944d627780734b36c138"
dependencies = [
"cranelift-codegen",
+ "hashbrown 0.17.1",
"log",
"smallvec",
"target-lexicon",
@@ -671,15 +699,15 @@ dependencies = [
[[package]]
name = "cranelift-isle"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c044843adb7d94b1facebaad846c0a762f79a77953417e3f0182093bcbbdc38"
+checksum = "2f5a26df22db546ab92be6feaf21835ae91082af0a32bbb398b277df3765412f"
[[package]]
name = "cranelift-native"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9d4c1707214e53f2040e4d13430069ea22623287b2750ed6d62e40eba88d91a"
+checksum = "19f258c08e590f90dcaf9904d25ba142ee2980c3aaeac4bb45f1452b1a407c2a"
dependencies = [
"cranelift-codegen",
"libc",
@@ -688,9 +716,9 @@ dependencies = [
[[package]]
name = "cranelift-srcgen"
-version = "0.123.18"
+version = "0.135.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d355a35edc49f628db7b793f3527eed31b560e77c3e8ed0e5258aad8df8a5249"
+checksum = "67055b4f315e8f6af3e8eccec74ad38f7407f0fd854adbd49b4b3b27bdb2e3be"
[[package]]
name = "crc32fast"
@@ -895,12 +923,6 @@ version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b5343afd4a8365a643ac588dab4cf234a190c7f6c88c9f6dd6ffe00837661b7"
-[[package]]
-name = "fallible-iterator"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
-
[[package]]
name = "fdeflate"
version = "0.3.7"
@@ -1000,12 +1022,48 @@ dependencies = [
"horizon-mod-sdk",
]
+[[package]]
+name = "futures"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3"
+dependencies = [
+ "futures-channel",
+ "futures-core",
+ "futures-io",
+ "futures-sink",
+ "futures-task",
+ "futures-util",
+]
+
+[[package]]
+name = "futures-channel"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
+dependencies = [
+ "futures-core",
+ "futures-sink",
+]
+
[[package]]
name = "futures-core"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
+[[package]]
+name = "futures-io"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed"
+
+[[package]]
+name = "futures-sink"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d"
+
[[package]]
name = "futures-task"
version = "0.3.34"
@@ -1018,8 +1076,12 @@ version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
dependencies = [
+ "futures-channel",
"futures-core",
+ "futures-io",
+ "futures-sink",
"futures-task",
+ "memchr",
"pin-project-lite",
"slab",
]
@@ -1114,11 +1176,12 @@ dependencies = [
[[package]]
name = "gimli"
-version = "0.32.3"
+version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
+checksum = "0bf7f043f89559805f8c7cacc432749b2fa0d0a0a9ee46ce47164ed5ba7f126c"
dependencies = [
- "fallible-iterator",
+ "fnv",
+ "hashbrown 0.16.1",
"indexmap",
"stable_deref_trait",
]
@@ -1194,7 +1257,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"foldhash 0.1.5",
- "serde",
]
[[package]]
@@ -1215,6 +1277,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
dependencies = [
"foldhash 0.2.0",
+ "serde",
+ "serde_core",
]
[[package]]
@@ -1307,6 +1371,7 @@ dependencies = [
"horizon-mods",
"horizon-protocol",
"horizon-server-files",
+ "horizon-shader-api",
"horizon-shaders",
"horizon-telemetry",
"horizon-theme",
@@ -1365,7 +1430,7 @@ dependencies = [
name = "horizon-mod-sdk"
version = "0.1.0"
dependencies = [
- "wit-bindgen",
+ "wit-bindgen 0.60.0",
]
[[package]]
@@ -1379,8 +1444,8 @@ dependencies = [
"sha2",
"toml",
"wasmtime",
- "wit-component 0.239.0",
- "wit-parser 0.239.0",
+ "wit-component",
+ "wit-parser",
"zip",
]
@@ -1415,6 +1480,8 @@ dependencies = [
name = "horizon-prepare"
version = "0.1.0"
dependencies = [
+ "crc32fast",
+ "libc",
"regex",
"sha1",
"sha2",
@@ -1985,6 +2052,12 @@ dependencies = [
"libc",
]
+[[package]]
+name = "mach2"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dae608c151f68243f2b000364e1f7b186d9c29845f7d2d85bd31b9ad77ad552b"
+
[[package]]
name = "memchr"
version = "2.8.3"
@@ -2520,12 +2593,12 @@ dependencies = [
[[package]]
name = "object"
-version = "0.37.3"
+version = "0.39.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
+checksum = "2e5a6c098c7a3b6547378093f5cc30bc54fd361ce711e05293a5cc589562739b"
dependencies = [
"crc32fast",
- "hashbrown 0.15.5",
+ "hashbrown 0.17.1",
"indexmap",
"memchr",
]
@@ -2796,21 +2869,21 @@ checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5"
[[package]]
name = "pulley-interpreter"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "334ae8982dcf354e5f28e79fc6f935601e028b729cc174d3937eeeaa859057b8"
+checksum = "2b8187c8e7db87d085865fc106502e7b34d5c25f8ce4c272945b21503371f6a0"
dependencies = [
"cranelift-bitset",
"log",
"pulley-macros",
- "wasmtime-internal-math",
+ "wasmtime-internal-core",
]
[[package]]
name = "pulley-macros"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9cd207bca4bc5e46cb4fcea87196dcbd78befc628c64c67d11dc99fce5cd5369"
+checksum = "7f98ce0e381d9e45e63ea1d20bba3cf131797086077f43af9203f1fb7de0ed6b"
dependencies = [
"proc-macro2",
"quote",
@@ -2909,15 +2982,16 @@ dependencies = [
[[package]]
name = "regalloc2"
-version = "0.12.2"
+version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5216b1837de2149f8bc8e6d5f88a9326b63b8c836ed58ce4a0a29ec736a59734"
+checksum = "757712e8e61590d6d4f5d563483755538b5aa13467837a3b41cd9832509a7f85"
dependencies = [
"allocator-api2",
"bumpalo",
- "hashbrown 0.15.5",
+ "hashbrown 0.17.1",
"log",
"rustc-hash 2.1.3",
+ "serde",
"smallvec",
]
@@ -2970,6 +3044,12 @@ dependencies = [
"windows-sys 0.52.0",
]
+[[package]]
+name = "rustc-demangle"
+version = "0.1.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b74b56ffa8bb2830709a538c2cbcae9aa062db0d2a42563bfb09bdaae44020eb"
+
[[package]]
name = "rustc-hash"
version = "1.1.0"
@@ -3753,7 +3833,7 @@ version = "1.0.4+wasi-0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
dependencies = [
- "wit-bindgen",
+ "wit-bindgen 0.57.1",
]
[[package]]
@@ -3814,124 +3894,66 @@ dependencies = [
[[package]]
name = "wasm-encoder"
-version = "0.236.1"
+version = "0.254.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "724fccfd4f3c24b7e589d333fc0429c68042897a7e8a5f8694f31792471841e7"
+checksum = "ebaca0b540bdb15d195ff34fb23074255948708b8916a11a339ba4513dc61906"
dependencies = [
"leb128fmt",
- "wasmparser 0.236.1",
-]
-
-[[package]]
-name = "wasm-encoder"
-version = "0.239.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5be00faa2b4950c76fe618c409d2c3ea5a3c9422013e079482d78544bb2d184c"
-dependencies = [
- "leb128fmt",
- "wasmparser 0.239.0",
-]
-
-[[package]]
-name = "wasm-encoder"
-version = "0.247.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30b6733b8b91d010a6ac5b0fb237dc46a19650bc4c67db66857e2e787d437204"
-dependencies = [
- "leb128fmt",
- "wasmparser 0.247.0",
+ "wasmparser",
]
[[package]]
name = "wasm-metadata"
-version = "0.239.0"
+version = "0.254.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "20b3ec880a9ac69ccd92fbdbcf46ee833071cf09f82bb005b2327c7ae6025ae2"
+checksum = "5d1880dd9a848aa68f387966256c34ad49abb4607e3cfa35720d2723d0591cd3"
dependencies = [
"anyhow",
"indexmap",
- "wasm-encoder 0.239.0",
- "wasmparser 0.239.0",
-]
-
-[[package]]
-name = "wasm-metadata"
-version = "0.247.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "665fe59e56cc9b419ca6fcca56673e3421d1a5011e3b65caf6b726fd9e041d10"
-dependencies = [
- "anyhow",
- "indexmap",
- "wasm-encoder 0.247.0",
- "wasmparser 0.247.0",
+ "wasm-encoder",
+ "wasmparser",
]
[[package]]
name = "wasmparser"
-version = "0.236.1"
+version = "0.254.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9b1e81f3eb254cf7404a82cee6926a4a3ccc5aad80cc3d43608a070c67aa1d7"
+checksum = "c5ff8685b587722894b6f25958fc608d315b93b8d23647bfb567664e7006d757"
dependencies = [
"bitflags 2.13.2",
- "hashbrown 0.15.5",
+ "hashbrown 0.17.1",
"indexmap",
"semver",
"serde",
]
-[[package]]
-name = "wasmparser"
-version = "0.239.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c9d90bb93e764f6beabf1d02028c70a2156a6583e63ac4218dd07ef733368b0"
-dependencies = [
- "bitflags 2.13.2",
- "hashbrown 0.15.5",
- "indexmap",
- "semver",
-]
-
-[[package]]
-name = "wasmparser"
-version = "0.247.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e6fb4c2bee46c5ea4d40f8cdb5c131725cd976718ec56f1c8e82fbde5fa2a80"
-dependencies = [
- "bitflags 2.13.2",
- "hashbrown 0.17.1",
- "indexmap",
- "semver",
-]
-
[[package]]
name = "wasmprinter"
-version = "0.236.1"
+version = "0.254.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2df225df06a6df15b46e3f73ca066ff92c2e023670969f7d50ce7d5e695abbb1"
+checksum = "8b03c8f270f3f384f70f42869b5ff7f6253fe4f0aa8590f7edd332c1943e5f51"
dependencies = [
"anyhow",
"termcolor",
- "wasmparser 0.236.1",
+ "wasmparser",
]
[[package]]
name = "wasmtime"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "70095b9fe63cc2a87ed206729e11544610decc184c62898c5d201ff1d666d82e"
+checksum = "12300d040e8bea7e7ccde75b9919d27ebba47a217a64b09ba058ae8d3b4290b6"
dependencies = [
"addr2line",
- "anyhow",
+ "async-trait",
"bitflags 2.13.2",
"bumpalo",
"cc",
- "cfg-if",
"encoding_rs",
- "hashbrown 0.15.5",
- "indexmap",
+ "futures",
"libc",
"log",
- "mach2",
+ "mach2 0.6.0",
"memfd",
"object",
"once_cell",
@@ -3943,62 +3965,56 @@ dependencies = [
"serde_derive",
"smallvec",
"target-lexicon",
- "wasmparser 0.236.1",
+ "wasmparser",
"wasmtime-environ",
- "wasmtime-internal-asm-macros",
"wasmtime-internal-component-macro",
"wasmtime-internal-component-util",
+ "wasmtime-internal-core",
"wasmtime-internal-cranelift",
"wasmtime-internal-fiber",
"wasmtime-internal-jit-debug",
"wasmtime-internal-jit-icache-coherence",
- "wasmtime-internal-math",
- "wasmtime-internal-slab",
"wasmtime-internal-unwinder",
"wasmtime-internal-versioned-export-macros",
- "wasmtime-internal-winch",
- "windows-sys 0.60.2",
+ "windows-sys 0.61.2",
]
[[package]]
name = "wasmtime-environ"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a67ea8904b6e369e2218780bd1f9186f1980cb616445eb2c1f3c4e45c8397865"
+checksum = "805d6554eb6dd6e62891061a31383a89d69fd891f785e5ae68f0835a554b7a2a"
dependencies = [
"anyhow",
+ "cpp_demangle",
+ "cranelift-bforest",
"cranelift-bitset",
"cranelift-entity",
"gimli",
+ "hashbrown 0.17.1",
"indexmap",
"log",
"object",
"postcard",
+ "rustc-demangle",
"semver",
"serde",
"serde_derive",
+ "sha2",
"smallvec",
"target-lexicon",
- "wasm-encoder 0.236.1",
- "wasmparser 0.236.1",
+ "wasm-encoder",
+ "wasmparser",
"wasmprinter",
"wasmtime-internal-component-util",
-]
-
-[[package]]
-name = "wasmtime-internal-asm-macros"
-version = "36.0.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d0488a52ae93e654baecb08ce04d15d478756eb2168c2bdab7915710109161ce"
-dependencies = [
- "cfg-if",
+ "wasmtime-internal-core",
]
[[package]]
name = "wasmtime-internal-component-macro"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "377e406c3f8e7bea64db3cb3ee0d406c331e8fc09d8cb2e7bf9ad74cb5d3b31a"
+checksum = "b832b80853365d9d3a741681044554be291a4f977aae074b318b55c7a4835f83"
dependencies = [
"anyhow",
"proc-macro2",
@@ -4006,23 +4022,32 @@ dependencies = [
"syn 2.0.119",
"wasmtime-internal-component-util",
"wasmtime-internal-wit-bindgen",
- "wit-parser 0.236.1",
+ "wit-parser",
]
[[package]]
name = "wasmtime-internal-component-util"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97c24503bb712afe2c797dc291b96e57556ee62c35fd951f87e96088324de37c"
+checksum = "4c8a11aaf68d8945991429d45950f32490a30ddcdcdb56629816cb41a255d8fe"
+
+[[package]]
+name = "wasmtime-internal-core"
+version = "48.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ea266d6cfb31c324c075c8432386654bcbb1559aa8d29be9d47eacf7dcc41012"
+dependencies = [
+ "hashbrown 0.17.1",
+ "libm",
+ "serde",
+]
[[package]]
name = "wasmtime-internal-cranelift"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f63ea7ee133de9109a4a1fc63dae3afc9ea32e92b8dada824fa4595dbf175f80"
+checksum = "d427759553b07c296c8ed7bff8ac930a94b9ba99e6a79243ea79bcc51aa58d96"
dependencies = [
- "anyhow",
- "cfg-if",
"cranelift-codegen",
"cranelift-control",
"cranelift-entity",
@@ -4036,33 +4061,32 @@ dependencies = [
"smallvec",
"target-lexicon",
"thiserror 2.0.21",
- "wasmparser 0.236.1",
+ "wasmparser",
"wasmtime-environ",
- "wasmtime-internal-math",
+ "wasmtime-internal-core",
+ "wasmtime-internal-unwinder",
"wasmtime-internal-versioned-export-macros",
]
[[package]]
name = "wasmtime-internal-fiber"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "69662a0a4dbe9784d1e8add9e3c5d2db0ca348085c624c27a70992dbe2eff4a3"
+checksum = "b54c8c5b02ea985149a90f917e1761af99734c6c27e6d7fdd5b6f69fc1db3950"
dependencies = [
- "anyhow",
"cc",
- "cfg-if",
"libc",
"rustix 1.1.5",
- "wasmtime-internal-asm-macros",
+ "wasmtime-environ",
"wasmtime-internal-versioned-export-macros",
- "windows-sys 0.60.2",
+ "windows-sys 0.61.2",
]
[[package]]
name = "wasmtime-internal-jit-debug"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00cb07d23903c0be359d6b920d94774ea322759c3f4d6721b61afa03602e4804"
+checksum = "72bb10c94724f072b6eca515085033e61da9efae65d054545126df37a15530c3"
dependencies = [
"cc",
"wasmtime-internal-versioned-export-macros",
@@ -4070,83 +4094,50 @@ dependencies = [
[[package]]
name = "wasmtime-internal-jit-icache-coherence"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "aa2b47c37a6d026e2755fe2cf7ec5c1f4b0fba62e448ea910cdf6a07a4982c6a"
+checksum = "1b781a27e8958fd07fd3135c0be216f77301efecd15cbf4f14ff210cdad5f169"
dependencies = [
- "anyhow",
- "cfg-if",
"libc",
- "windows-sys 0.60.2",
+ "wasmtime-internal-core",
+ "windows-sys 0.61.2",
]
-[[package]]
-name = "wasmtime-internal-math"
-version = "36.0.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b269f0ba44102c57fd5f94f1bf4395ccd4fc2b84698fc78f627a6f2a47131a62"
-dependencies = [
- "libm",
-]
-
-[[package]]
-name = "wasmtime-internal-slab"
-version = "36.0.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0e35ac9d503d503703cd24d532e53e2e93c86109b451df40a9801500045aee25"
-
[[package]]
name = "wasmtime-internal-unwinder"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "83ce1d0930da44ed375701e6b4f187b46249f7efe2b1d8c1c77229a4adc82de9"
+checksum = "121188de1b2741b8e35530a9b0c8adf525b3aa5913a2ca3d4522509cfbc0494a"
dependencies = [
- "anyhow",
- "cfg-if",
"cranelift-codegen",
"log",
"object",
+ "wasmtime-environ",
]
[[package]]
name = "wasmtime-internal-versioned-export-macros"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3b6633be262400bd7abab4ff767a16e8b6a41ff117be54bf76dabecea9f96225"
+checksum = "933f1990e4e5177547a4abd51dcfa5cb7616fe42b9fb6f0f2b7423627758223c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
-[[package]]
-name = "wasmtime-internal-winch"
-version = "36.0.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "509d1e1cf8e3b3306f291407c92bca8381d9294f8c54ad74b692538f1f5b23c7"
-dependencies = [
- "anyhow",
- "cranelift-codegen",
- "gimli",
- "object",
- "target-lexicon",
- "wasmparser 0.236.1",
- "wasmtime-environ",
- "wasmtime-internal-cranelift",
- "winch-codegen",
-]
-
[[package]]
name = "wasmtime-internal-wit-bindgen"
-version = "36.0.18"
+version = "48.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a6d9a5b51b3400b4df1055724c4536ad5aa58fafe83cea5ca94f88cc9eb97563"
+checksum = "417ebd61d2581d86d65413517f3a41294a9ad105da26f0dc7039912a0d97e1ed"
dependencies = [
"anyhow",
"bitflags 2.13.2",
"heck",
"indexmap",
- "wit-parser 0.236.1",
+ "wit-component",
+ "wit-parser",
]
[[package]]
@@ -4482,26 +4473,6 @@ dependencies = [
"windows-sys 0.61.2",
]
-[[package]]
-name = "winch-codegen"
-version = "36.0.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e470d7e674c41ad32dddc02d8d8a94983e0a4c516028bda60747e6dd862a567"
-dependencies = [
- "anyhow",
- "cranelift-assembler-x64",
- "cranelift-codegen",
- "gimli",
- "regalloc2",
- "smallvec",
- "target-lexicon",
- "thiserror 2.0.21",
- "wasmparser 0.236.1",
- "wasmtime-environ",
- "wasmtime-internal-cranelift",
- "wasmtime-internal-math",
-]
-
[[package]]
name = "windows"
version = "0.54.0"
@@ -4959,42 +4930,48 @@ name = "wit-bindgen"
version = "0.57.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
+
+[[package]]
+name = "wit-bindgen"
+version = "0.60.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a301904d6657d6364c758d869e5389d05d393b16d5b65db60b4f03cbe71bb80d"
dependencies = [
"wit-bindgen-rust-macro",
]
[[package]]
name = "wit-bindgen-core"
-version = "0.57.1"
+version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "02dee27a2dc20d1008016c742ec9fc6ea498492994ba3750be7454cbc97ff04c"
+checksum = "48521bb96e56cbb9e031ad306c80dc20e89e69e49ada02781ee06f60fbcb545f"
dependencies = [
"anyhow",
"heck",
- "wit-parser 0.247.0",
+ "wit-parser",
]
[[package]]
name = "wit-bindgen-rust"
-version = "0.57.1"
+version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5007dae772945b7a5003d69d90a3a4a78929d41f19d004e980c4259a6af4484"
+checksum = "3df3fe9b9a0066f82fd0c2f07f79d0ffc0f85c53fa5f998516d8722712479042"
dependencies = [
"anyhow",
"heck",
"indexmap",
"prettyplease",
"syn 2.0.119",
- "wasm-metadata 0.247.0",
+ "wasm-metadata",
"wit-bindgen-core",
- "wit-component 0.247.0",
+ "wit-component",
]
[[package]]
name = "wit-bindgen-rust-macro"
-version = "0.57.1"
+version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af9237d678e3513ad24e96fe98beacdc0db6405284ba2a2400418cf0d42caa89"
+checksum = "d689c4bc9d6af067c651cfba444766343c9a4bdef15fad1e2efab95c0c277af0"
dependencies = [
"anyhow",
"prettyplease",
@@ -5007,9 +4984,9 @@ dependencies = [
[[package]]
name = "wit-component"
-version = "0.239.0"
+version = "0.254.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "88a866b19dba2c94d706ec58c92a4c62ab63e482b4c935d2a085ac94caecb136"
+checksum = "1c96b3cea6838dbea55173baa56991fcb087896c321b0a770db201e5a0bd3506"
dependencies = [
"anyhow",
"bitflags 2.13.2",
@@ -5018,72 +4995,17 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
- "wasm-encoder 0.239.0",
- "wasm-metadata 0.239.0",
- "wasmparser 0.239.0",
- "wit-parser 0.239.0",
-]
-
-[[package]]
-name = "wit-component"
-version = "0.247.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d567162a6b9843080e5e0053f696623ff694bae8ae017c9ec536d1873bbe3d8"
-dependencies = [
- "anyhow",
- "bitflags 2.13.2",
- "indexmap",
- "log",
- "serde",
- "serde_derive",
- "serde_json",
- "wasm-encoder 0.247.0",
- "wasm-metadata 0.247.0",
- "wasmparser 0.247.0",
- "wit-parser 0.247.0",
+ "wasm-encoder",
+ "wasm-metadata",
+ "wasmparser",
+ "wit-parser",
]
[[package]]
name = "wit-parser"
-version = "0.236.1"
+version = "0.254.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "16e4833a20cd6e85d6abfea0e63a399472d6f88c6262957c17f546879a80ba15"
-dependencies = [
- "anyhow",
- "id-arena",
- "indexmap",
- "log",
- "semver",
- "serde",
- "serde_derive",
- "serde_json",
- "unicode-xid",
- "wasmparser 0.236.1",
-]
-
-[[package]]
-name = "wit-parser"
-version = "0.239.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "55c92c939d667b7bf0c6bf2d1f67196529758f99a2a45a3355cc56964fd5315d"
-dependencies = [
- "anyhow",
- "id-arena",
- "indexmap",
- "log",
- "semver",
- "serde",
- "serde_derive",
- "serde_json",
- "unicode-xid",
- "wasmparser 0.239.0",
-]
-
-[[package]]
-name = "wit-parser"
-version = "0.247.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ffe4064318cdf3c08cb99343b44c039fcefe61ccdf58aa9975285f13d74d1fc"
+checksum = "22672d61bfb9df46a16b46ce38522293aee1cc4749fc84a3464ce4083b3d5fd6"
dependencies = [
"anyhow",
"hashbrown 0.17.1",
@@ -5094,8 +5016,8 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
- "unicode-xid",
- "wasmparser 0.247.0",
+ "unicode-ident",
+ "wasmparser",
]
[[package]]
diff --git a/README.md b/README.md
index ceee29249..65078464e 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Horizon is Minecraft: Java Edition 26.3 rewritten in Rust: a native game that re
Horizon is installed through **the Horizon launcher**. Get it from [playhorizon.dev](https://playhorizon.dev) (the Download button picks your system) or from [the launcher releases](https://github.com/ludovic111/horizon/releases?q=launcher-v&expanded=true), for Linux x86-64, macOS on Apple Silicon or Windows x64. The launcher installs and updates the game, prepares its files from your own copy of Minecraft, and updates itself.
-**You need** Minecraft: Java Edition 26.3, played once (the official launcher, Prism, MultiMC and other launchers all work); a Java 25 JDK, for the one-time preparation; and a GPU with Vulkan on Linux and Windows, or any Apple Silicon Mac. Step by step, with macOS's first-open prompt and the first launch: [Install and first launch](https://playhorizon.dev/docs/install).
+**You need** Minecraft: Java Edition 26.3, played once (the official launcher, Prism, MultiMC and other launchers all work); a Java 25 runtime, for the one-time preparation; and a GPU with Vulkan on Linux and Windows, or any Apple Silicon Mac. Step by step, with macOS's first-open prompt and the first launch: [Install and first launch](https://playhorizon.dev/docs/install).
diff --git a/crates/cargo-horizon-mod/src/main.rs b/crates/cargo-horizon-mod/src/main.rs
index a4585f680..b82c6d07f 100644
--- a/crates/cargo-horizon-mod/src/main.rs
+++ b/crates/cargo-horizon-mod/src/main.rs
@@ -6,12 +6,15 @@
//! `assets/` and `data/`; a folder without `Cargo.toml` is content only.
//! - `run [--game ] [-- ]`: build, then play with
//! the mod; run `build` again and the game reloads it.
+//! - `test [--debug] [--hmod ] []`: build, then run the mod's
+//! `tests/*.toml` scripts in the sandbox, with no game.
//! - `check [--json]`: what the registry checks of a submission
//! (`.hmod`, `.hpack`, resource pack `.zip`), with a trial run for a mod.
//! - `registry build|review|check|list`: the registry repository's CI.
use horizon_mods::{
Capability, Content, Manifest, Package,
manifest::{MANIFEST, component_imports, componentize},
+ testing::{Script, TestGame},
};
mod check;
mod registry;
@@ -36,9 +39,10 @@ fn main() -> ExitCode {
println!("Built {}", p.display());
}),
Some("run") => run(&args[1..]),
+ Some("test") => test(&args[1..]),
Some("check") => check(&args[1..]),
Some("registry") => registry::main(&args[1..]),
- _ => Err("usage: cargo horizon-mod new [--template code|content] | build [--debug] | run [--game ] [-- ] | check [--kind ] [--key --signature ] [--json] | registry build|review|check|list".into()),
+ _ => Err("usage: cargo horizon-mod new [--template code|content] | build [--debug] | run [--game ] [-- ] | test [--debug] [--hmod ] [] | check [--kind ] [--key --signature ] [--json] | registry build|review|check|list".into()),
};
match result {
Ok(()) => ExitCode::SUCCESS,
@@ -97,6 +101,10 @@ fn new(args: &[String]) -> Result<(), String> {
(MANIFEST, include_str!("../template/horizon-mod.toml")),
("src/lib.rs", include_str!("../template/src/lib.rs")),
(".gitignore", include_str!("../template/gitignore")),
+ (
+ "tests/hello.toml",
+ include_str!("../template/tests/hello.toml"),
+ ),
];
// A block copying a vanilla one, with its model, name, loot, recipe and tag.
let content = [
@@ -270,6 +278,63 @@ fn check(args: &[String]) -> Result<(), String> {
Ok(())
}
+/// `test`: every `tests/*.toml` script (those whose name holds ``)
+/// against the built mod, or the `.hmod` given with `--hmod`.
+fn test(args: &[String]) -> Result<(), String> {
+ let hmod = match flag(args, "--hmod") {
+ Some(p) => PathBuf::from(p),
+ None => build(!args.iter().any(|a| a == "--debug"))?,
+ };
+ let filter = args
+ .iter()
+ .enumerate()
+ .find(|(i, a)| !a.starts_with("--") && (*i == 0 || args[i - 1] != "--hmod"))
+ .map(|(_, a)| a.as_str());
+ let mut scripts: Vec = std::fs::read_dir("tests")
+ .map_err(|e| {
+ format!(
+ "tests/: {e} (a mod's tests are tests/.toml: docs/mods.md, \"Testing a mod\")"
+ )
+ })?
+ .filter_map(|e| Some(e.ok()?.path()))
+ .filter(|p| p.extension().is_some_and(|e| e == "toml"))
+ .filter(|p| filter.is_none_or(|f| p.to_string_lossy().contains(f)))
+ .collect();
+ scripts.sort();
+ if scripts.is_empty() {
+ return Err("no tests/*.toml to run".into());
+ }
+ println!(
+ "running {} scripts against {}",
+ scripts.len(),
+ hmod.display()
+ );
+ let mut failed = 0;
+ for path in &scripts {
+ let result = std::fs::read_to_string(path)
+ .map_err(|e| e.to_string())
+ .and_then(|text| Script::parse(&text))
+ .and_then(|script| {
+ let mut game = TestGame::load(&hmod)?;
+ script.run(&mut game)?;
+ Ok(script.steps.len())
+ });
+ match result {
+ Ok(steps) => println!("test {} ... ok ({steps} steps)", path.display()),
+ Err(e) => {
+ failed += 1;
+ println!("test {} ... FAILED\n {e}", path.display());
+ }
+ }
+ }
+ let passed = scripts.len() - failed;
+ if failed > 0 {
+ return Err(format!("{failed} failed, {passed} passed"));
+ }
+ println!("test result: ok. {passed} passed");
+ Ok(())
+}
+
fn run(args: &[String]) -> Result<(), String> {
let path = build(true)?;
let game = flag(args, "--game")
@@ -312,6 +377,8 @@ mod tests {
);
let cargo = std::fs::read_to_string(path.join("Cargo.toml")).unwrap();
assert!(cargo.contains("name = \"my-mod\"") && cargo.contains(SDK_GIT));
+ let script = std::fs::read_to_string(path.join("tests/hello.toml")).unwrap();
+ assert_eq!(Script::parse(&script).unwrap().steps.len(), 3);
assert!(
new(&[path.display().to_string()]).is_err(),
"never overwrites"
diff --git a/crates/cargo-horizon-mod/template/tests/hello.toml b/crates/cargo-horizon-mod/template/tests/hello.toml
new file mode 100644
index 000000000..17afd7e65
--- /dev/null
+++ b/crates/cargo-horizon-mod/template/tests/hello.toml
@@ -0,0 +1,14 @@
+# `cargo horizon-mod test` runs every tests/*.toml against the built mod, with no game:
+# steps happen in order, and `expect` checks what the mod showed during the step.
+# Every key: docs/mods.md, "Testing a mod".
+
+[[step]]
+expect.commands = ["hello"]
+
+[[step]]
+command = "hello world"
+expect.chat = ["Hello world! (1 so far)"]
+
+[[step]]
+command = "hello again"
+expect.chat = ["Hello again! (2 so far)"]
diff --git a/crates/horizon-client/Cargo.toml b/crates/horizon-client/Cargo.toml
index 7ebe75664..d7c6d812b 100644
--- a/crates/horizon-client/Cargo.toml
+++ b/crates/horizon-client/Cargo.toml
@@ -18,6 +18,8 @@ horizon-protocol = { path = "../horizon-protocol" }
horizon-server-files = { path = "../horizon-server-files" }
# Shader packs: reading them and turning their GLSL into naga modules.
horizon-shaders = { path = "../horizon-shaders" }
+# Horizon's own shader packs: the format, the stages and the check (docs/shaders.md).
+horizon-shader-api = { path = "../horizon-shader-api" }
horizon-friends = { path = "../horizon-friends" }
# Horizon mods: sandboxed WebAssembly components, off unless installed and turned on (docs/mods.md).
# Their runtime is the `mods` feature.
diff --git a/crates/horizon-client/examples/probe/block_entity_render_fixture.rs b/crates/horizon-client/examples/probe/block_entity_render_fixture.rs
index a0e3471bc..1db978b77 100644
--- a/crates/horizon-client/examples/probe/block_entity_render_fixture.rs
+++ b/crates/horizon-client/examples/probe/block_entity_render_fixture.rs
@@ -367,6 +367,7 @@ pub fn main() -> Result<()> {
lid: &|_| open,
sign: &|_| sign.as_ref(),
banner: &|_| layers.clone(),
+ skull: &|_| None,
glyph: &|c| atlas.glyph_cell(c),
};
let mut verts = Vec::new();
diff --git a/crates/horizon-client/examples/probe/chat_screen_fixture.rs b/crates/horizon-client/examples/probe/chat_screen_fixture.rs
index 229d8d861..db334797d 100644
--- a/crates/horizon-client/examples/probe/chat_screen_fixture.rs
+++ b/crates/horizon-client/examples/probe/chat_screen_fixture.rs
@@ -7,7 +7,7 @@
//! usage: chat_screen_fixture RESOURCES REGISTRIES CASES OUTPUT
use crate::pack_screen_fixture;
use horizon_client::{
- chat::{ChatAction, ChatScreen, Commands},
+ chat::{ChatAbilities, ChatAction, ChatScreen, ChatVisibility, Commands},
command::vanilla,
hud::HudAtlas,
lang,
@@ -53,6 +53,7 @@ pub fn main() -> horizon_client::Result<()> {
history.len(),
w,
h,
+ ChatAbilities::new(ChatVisibility::Full),
);
screen.auto_suggestions = case["autoSuggest"] == true;
let mut closed = false;
diff --git a/crates/horizon-client/examples/probe/hud_fixture/kinds.rs b/crates/horizon-client/examples/probe/hud_fixture/kinds.rs
index d1450f2e1..9ba66abe1 100644
--- a/crates/horizon-client/examples/probe/hud_fixture/kinds.rs
+++ b/crates/horizon-client/examples/probe/hud_fixture/kinds.rs
@@ -319,6 +319,7 @@ fn chat(c: &Value, h: i32, atlas: &HudAtlas) -> Vec {
atlas,
comp(&m["text"]),
indicator,
+ horizon_client::chat::ChatSource::Client,
m["at"].as_u64().unwrap_or(0),
false,
);
diff --git a/crates/horizon-client/src/block_entity_render.rs b/crates/horizon-client/src/block_entity_render.rs
index af4168307..10c5e2509 100644
--- a/crates/horizon-client/src/block_entity_render.rs
+++ b/crates/horizon-client/src/block_entity_render.rs
@@ -730,6 +730,10 @@ pub struct Scene<'a> {
pub sign: &'a dyn Fn([i32; 3]) -> Option<&'a crate::signs::SignData>,
/// Banner layers at a position: pattern texture and RGB tint, bottom first.
pub banner: &'a dyn Fn([i32; 3]) -> Vec<(String, u32)>,
+ /// The skin sprite a `player_head` shows at a position (`SkullBlockRenderer`
+ /// profile → skin): a downloaded `skins/` slot or the profile's
+ /// `DefaultPlayerSkin` fallback; None keeps `SKIN_BY_TYPE` (`DefaultPlayerSkin.getDefaultTexture`, slim steve).
+ pub skull: &'a dyn Fn([i32; 3]) -> Option<&'a str>,
/// Font glyph cell (none for blank glyphs such as the space) and advance.
pub glyph: &'a dyn Fn(char) -> (Option, f32),
}
@@ -1279,6 +1283,13 @@ impl BlockEntityRenderer {
SkullType::Piglin => ("piglin_head", "entity/piglin/piglin"),
SkullType::Player => ("player_head", "entity/player/slim/steve"),
};
+ // SkullBlockRenderer.getRenderType: the profile's skin when it
+ // resolves, `SKIN_BY_TYPE` (steve) otherwise.
+ let texture = if *kind == SkullType::Player {
+ (scene.skull)(pos).unwrap_or(texture)
+ } else {
+ texture
+ };
let (Some(model), Some(paint)) =
(self.models.get(model), paint(texture, 0xFFFFFF, packed))
else {
@@ -1886,6 +1897,7 @@ mod tests {
lid: &|_| 0.0,
sign: &|_| None,
banner: &|_| Vec::new(),
+ skull: &|_| None,
glyph: &|_| (None, 0.0),
};
// Compare the cached world path with the original model renderer,
diff --git a/crates/horizon-client/src/cauldron.rs b/crates/horizon-client/src/cauldron.rs
index 9fbe1179f..03fb0676d 100644
--- a/crates/horizon-client/src/cauldron.rs
+++ b/crates/horizon-client/src/cauldron.rs
@@ -87,6 +87,19 @@ fn filled(player: &mut dyn Player, new: ItemStack, limit_creative: bool) {
}
}
+/// `LayeredCauldronBlock.handleEntityOnFireInside`: a burning entity in a
+/// water cauldron lowers it a level; a powder snow cauldron becomes a water
+/// cauldron of its level first, then lowers.
+pub fn extinguished(cauldron: &BlockState) -> BlockState {
+ if cauldron.name == "minecraft:powder_snow_cauldron" {
+ let mut water = cauldron.clone();
+ water.name = "minecraft:water_cauldron".into();
+ lowered(&water)
+ } else {
+ lowered(cauldron)
+ }
+}
+
/// `LayeredCauldronBlock.lowerFillLevel`.
fn lowered(cauldron: &BlockState) -> BlockState {
let level: u8 = cauldron
@@ -296,3 +309,24 @@ pub fn interact(
_ => pass(),
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn a_burning_entity_lowers_water_and_melts_powder_snow() {
+ let water = |l| state("minecraft:water_cauldron", Some(l));
+ assert_eq!(extinguished(&water(3)), water(2));
+ assert_eq!(extinguished(&water(1)), state("minecraft:cauldron", None));
+ // Powder snow turns to water of its level, then lowers.
+ assert_eq!(
+ extinguished(&state("minecraft:powder_snow_cauldron", Some(3))),
+ water(2)
+ );
+ assert_eq!(
+ extinguished(&state("minecraft:powder_snow_cauldron", Some(1))),
+ state("minecraft:cauldron", None)
+ );
+ }
+}
diff --git a/crates/horizon-client/src/chat.rs b/crates/horizon-client/src/chat.rs
index 273b87153..04b9d486c 100644
--- a/crates/horizon-client/src/chat.rs
+++ b/crates/horizon-client/src/chat.rs
@@ -19,6 +19,92 @@ mod tests;
/// GuiMessageTag.systemSinglePlayer's indicator colour.
pub const SYSTEM_INDICATOR: u32 = 0xD0D0D0;
+/// `ChatVisiblity`: the Chat option's three values.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum ChatVisibility {
+ Full,
+ System,
+ Hidden,
+}
+impl ChatVisibility {
+ /// Options.chatVisibility's saved value (0 full, 1 system, 2 hidden).
+ pub fn from_option(value: u8) -> Self {
+ match value {
+ 0 => Self::Full,
+ 1 => Self::System,
+ _ => Self::Hidden,
+ }
+ }
+}
+
+/// `ChatAbilities`: what the Chat option allows, as `Minecraft.computeChatAbilities`
+/// derives it from the visibility alone (`ChatRestriction`).
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct ChatAbilities {
+ pub send_messages: bool,
+ pub send_commands: bool,
+ pub receive_player_messages: bool,
+ pub receive_system_messages: bool,
+}
+impl ChatAbilities {
+ /// `ChatRestriction.CHAT_AND_COMMANDS_DISABLED_BY_OPTIONS` (Hidden) takes
+ /// chat, commands, player messages and system messages;
+ /// `CHAT_DISABLED_BY_OPTIONS` (System) takes the chat and player messages.
+ pub fn new(visibility: ChatVisibility) -> Self {
+ match visibility {
+ ChatVisibility::Full => Self {
+ send_messages: true,
+ send_commands: true,
+ receive_player_messages: true,
+ receive_system_messages: true,
+ },
+ ChatVisibility::System => Self {
+ send_messages: false,
+ send_commands: true,
+ receive_player_messages: false,
+ receive_system_messages: true,
+ },
+ ChatVisibility::Hidden => Self {
+ send_messages: false,
+ send_commands: false,
+ receive_player_messages: false,
+ receive_system_messages: false,
+ },
+ }
+ }
+ /// `visibleMessagesFilter`: the client's own lines always show.
+ pub fn shows(&self, source: ChatSource) -> bool {
+ match source {
+ ChatSource::Player => self.receive_player_messages,
+ ChatSource::Server => self.receive_system_messages,
+ ChatSource::Client => true,
+ }
+ }
+ /// Whether the chat screen may send `input` (`hasAllowedInput`).
+ pub fn allows(&self, input: &str) -> bool {
+ if input.starts_with('/') {
+ self.send_commands
+ } else {
+ self.send_messages
+ }
+ }
+}
+
+impl Default for ChatAbilities {
+ fn default() -> Self {
+ Self::new(ChatVisibility::Full)
+ }
+}
+
+/// Where a chat line came from (`GuiMessageSource`): the visibility filters
+/// player messages and the server's, while the client's own always show.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum ChatSource {
+ Player,
+ Server,
+ Client,
+}
+
/// The chat options (doubles, as vanilla keeps them).
#[derive(Clone, Copy, Debug)]
pub struct ChatOptions {
@@ -71,6 +157,7 @@ struct Message {
added: u64,
content: Text,
indicator: Option,
+ source: ChatSource,
}
/// A wrapped line (`GuiMessage.Line`).
#[derive(Clone, Debug)]
@@ -105,6 +192,8 @@ pub struct Chat {
pub log: bool,
/// Messages added since the start, for the control socket's events.
pub received: u64,
+ /// The Chat option's `visibleMessageFilter` (`set_abilities`).
+ abilities: ChatAbilities,
}
impl Chat {
pub fn lines_per_page(&self, focused: bool) -> usize {
@@ -114,16 +203,32 @@ impl Chat {
fn max_width(&self) -> i32 {
(f64::from(self.options.width_px()) / self.options.scale).floor() as i32
}
- /// ChatComponent.addMessage: wrap, prepend and trim to 100 lines.
+ /// ChatComponent.addMessage: wrap, prepend and trim to 100 lines. A
+ /// message the Chat option hides is dropped, unlogged.
pub fn add(
&mut self,
atlas: &HudAtlas,
content: Text,
indicator: Option,
+ source: ChatSource,
ticks: u64,
focused: bool,
) {
- // ChatComponent.logChatMessage: every message is in the log.
+ self.add_message(&atlas.font, content, indicator, source, ticks, focused);
+ }
+ fn add_message(
+ &mut self,
+ font: &crate::font::Font,
+ content: Text,
+ indicator: Option,
+ source: ChatSource,
+ ticks: u64,
+ focused: bool,
+ ) {
+ if !self.abilities.shows(source) {
+ return;
+ }
+ // ChatComponent.logChatMessage: every message shown is in the log.
crate::logging::write_only(log::Level::Info, &format!("[CHAT] {}", content.plain()));
if self.log {
println!("[CHAT] {}", content.plain());
@@ -132,16 +237,17 @@ impl Chat {
added: ticks,
content,
indicator,
+ source,
};
- self.add_lines(atlas, &message, focused);
+ self.add_lines(font, &message, focused);
self.messages.insert(0, message);
self.messages.truncate(100);
self.received += 1;
}
- fn add_lines(&mut self, atlas: &HudAtlas, message: &Message, focused: bool) {
+ fn add_lines(&mut self, font: &crate::font::Font, message: &Message, focused: bool) {
let width = self.max_width();
let content = self.displayed(&message.content);
- for line in atlas.font.wrap_components(&content, width) {
+ for line in font.wrap_components(&content, width) {
if focused && self.scroll > 0 {
self.new_since_scroll = true;
self.scroll_by(1, focused);
@@ -167,16 +273,38 @@ impl Chat {
content.strip_legacy()
}
}
- /// Re-wrap after a width or scale change (ChatComponent.rescaleChat).
+ /// Re-wrap after a width or scale change (ChatComponent.rescaleChat),
+ /// keeping only the messages the Chat option shows.
pub fn rescale(&mut self, atlas: &HudAtlas) {
+ self.rewrap(&atlas.font);
+ }
+ fn rewrap(&mut self, font: &crate::font::Font) {
self.scroll = 0;
self.new_since_scroll = false;
self.lines.clear();
- let messages: Vec = self.messages.iter().rev().cloned().collect();
+ let messages: Vec = self
+ .messages
+ .iter()
+ .rev()
+ .filter(|m| self.abilities.shows(m.source))
+ .cloned()
+ .collect();
for m in &messages {
- self.add_lines(atlas, m, false);
+ self.add_lines(font, m, false);
}
}
+ /// `ChatComponent.setVisibleMessageFilter`: the Chat option changed;
+ /// the messages it now hides leave the chat, those it shows again return.
+ pub fn set_abilities(&mut self, font: &crate::font::Font, abilities: ChatAbilities) {
+ if self.abilities != abilities {
+ self.abilities = abilities;
+ self.rewrap(font);
+ }
+ }
+ /// Whether a message from `source` would show (`visibleMessagesFilter`).
+ pub fn shows(&self, source: ChatSource) -> bool {
+ self.abilities.shows(source)
+ }
pub fn clear(&mut self) {
self.messages.clear();
self.lines.clear();
@@ -437,6 +565,8 @@ pub struct ChatScreen {
allow_suggestions: bool,
keep_suggestions: bool,
pub auto_suggestions: bool,
+ /// `CommandSuggestions.setRestrictions`: what the Chat option allows.
+ pub abilities: ChatAbilities,
}
/// Local completions waiting for the server's reply to request `id`.
struct Awaiting {
@@ -482,6 +612,7 @@ impl ChatScreen {
history_len: usize,
width: i32,
height: i32,
+ abilities: ChatAbilities,
) -> Self {
let mut input = TextField::new(4, height - 12, width - 4, 12);
input.max_length = 256;
@@ -505,6 +636,7 @@ impl ChatScreen {
allow_suggestions: false,
keep_suggestions: false,
auto_suggestions: true,
+ abilities,
};
s.update_command_info(m, c);
s
@@ -522,7 +654,8 @@ impl ChatScreen {
if (width, height) != (self.width, self.height) {
let value = self.input.value.clone();
let auto = self.auto_suggestions;
- *self = Self::new(m, c, &value, self.history_pos, width, height);
+ let abilities = self.abilities;
+ *self = Self::new(m, c, &value, self.history_pos, width, height, abilities);
self.auto_suggestions = auto;
}
}
@@ -604,6 +737,14 @@ impl ChatScreen {
self.pending = Some((range.0, list));
self.usage_width = 0;
self.usage_position = 0;
+ // CommandSuggestions.updateCommandInfo: the Chat option may take
+ // the messages.
+ if !self.abilities.send_messages {
+ let line =
+ Text::translate("chat_screen.messages_not_allowed", &[]).with_color(text::RED);
+ self.usage_width = m.width(&line);
+ self.usage.push(line);
+ }
} else {
self.awaiting = None;
self.pending = None;
@@ -708,6 +849,15 @@ impl ChatScreen {
}
self.usage.extend(entries);
}
+ // CommandSuggestions.updateUsageInfo: the Chat option may take the
+ // commands, under the usage. (Vanilla also counts a command with a
+ // message argument, `/say hi`, as a message; Horizon's parse keeps no
+ // argument kinds, so only a bare message does.)
+ if !self.abilities.send_commands {
+ self.usage.push(
+ Text::translate("chat_screen.commands_not_allowed", &[]).with_color(text::RED),
+ );
+ }
self.usage_width = self.usage.iter().map(|u| m.width(u)).max().unwrap_or(0);
self.usage_position = if self.usage.is_empty() {
0
@@ -842,7 +992,14 @@ impl ChatScreen {
}
match key {
K::Escape => return ChatAction::Close,
- K::Enter | K::NumpadEnter => return ChatAction::Submit(self.normalized()),
+ K::Enter | K::NumpadEnter => {
+ // ChatScreen.keyPressed: without `hasAllowedInput` the input
+ // stays, unsent, and the screen stays open.
+ if !self.abilities.allows(&self.input.value) {
+ return ChatAction::None;
+ }
+ return ChatAction::Submit(self.normalized());
+ }
K::ArrowUp => self.move_in_history(m, c, history, -1),
K::ArrowDown => self.move_in_history(m, c, history, 1),
_ => {
diff --git a/crates/horizon-client/src/chat_tests.rs b/crates/horizon-client/src/chat_tests.rs
index d0ce3f458..6b058c0fb 100644
--- a/crates/horizon-client/src/chat_tests.rs
+++ b/crates/horizon-client/src/chat_tests.rs
@@ -2,6 +2,11 @@ use super::*;
use crate::{font::Font, hud::Rect};
use std::{collections::HashMap, path::Path};
+/// The Chat option's default: no restriction.
+fn full() -> ChatAbilities {
+ ChatAbilities::new(ChatVisibility::Full)
+}
+
fn font() -> Font {
// The missing-glyph metrics let these tests run without game assets.
Font::load(
@@ -139,7 +144,7 @@ fn locate_coordinates_fill_chat_with_teleport_without_submitting() {
assert_eq!(link.component()["click_event"]["command"], expected);
let mut chat = Chat::default();
add(&mut chat, &font, Text::literal("Found at ").append(link));
- let mut screen = ChatScreen::new(&m, &commands, "draft", 0, 640, 360);
+ let mut screen = ChatScreen::new(&m, &commands, "draft", 0, 640, 360, full());
let x = 4.0 + f64::from(font.width("Found at "));
assert!(!screen.click(&m, &commands, x, 315.0));
let Some(ClickEvent::SuggestCommand(command)) = chat.click_at(&font, 360, x, 315.0) else {
@@ -176,7 +181,15 @@ fn history_arrows_recall_messages_and_restore_the_draft() {
registries: ®istries,
};
let history = vec!["first message".to_owned(), "latest message".to_owned()];
- let mut screen = ChatScreen::new(&m, &commands, "unfinished draft", history.len(), 640, 360);
+ let mut screen = ChatScreen::new(
+ &m,
+ &commands,
+ "unfinished draft",
+ history.len(),
+ 640,
+ 360,
+ full(),
+ );
for (key, expected) in [
(ArrowUp, "latest message"),
(ArrowUp, "first message"),
@@ -213,7 +226,7 @@ fn mod_commands_are_coloured_and_complete_like_vanilla_ones() {
dispatcher,
registries: ®istries,
};
- let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360);
+ let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360, full());
screen.type_text(&m, &c, line);
screen
};
@@ -259,7 +272,7 @@ fn ask_server_nodes_wait_for_the_servers_completions() {
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);
+ let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360, full());
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");
@@ -281,7 +294,7 @@ fn ask_server_nodes_wait_for_the_servers_completions() {
dispatcher: local,
registries: ®istries,
};
- let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360);
+ let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360, full());
screen.type_text(&m, &c, "/bossbar get pt");
assert_eq!(screen.take_request(), None);
}
@@ -327,3 +340,99 @@ fn a_server_component_keeps_its_click_and_hover_events() {
let past = 4.0 + f64::from(font.width("CLICK")) + 20.0;
assert!(chat.hover_at(&font, 360, past, 315.0).is_none());
}
+
+/// `ChatVisiblity`: Commands Only keeps the chat out, Hidden takes the
+/// commands too (`ChatAbilities`), and Enter sends nothing the option hides.
+#[test]
+fn the_chat_option_decides_what_may_be_sent() {
+ let font = font();
+ let m = Measure(&font);
+ let registries = Registries::default();
+ let c = Commands {
+ dispatcher: crate::command::vanilla::game_dispatcher(),
+ registries: ®istries,
+ };
+ let enter = |screen: &mut ChatScreen| {
+ screen.key(&m, &c, &[], winit::keyboard::KeyCode::Enter, false, false)
+ };
+ for (visibility, chat, command) in [
+ (ChatVisibility::Full, true, true),
+ (ChatVisibility::System, false, true),
+ (ChatVisibility::Hidden, false, false),
+ ] {
+ let abilities = ChatAbilities::new(visibility);
+ assert_eq!(abilities.allows("hi"), chat, "{visibility:?}");
+ assert_eq!(abilities.allows("/time set day"), command, "{visibility:?}");
+ for (line, allowed) in [("hi", chat), ("/time set day", command)] {
+ let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360, abilities);
+ screen.type_text(&m, &c, line);
+ match enter(&mut screen) {
+ ChatAction::Submit(sent) => {
+ assert!(allowed, "{visibility:?} sent {sent}");
+ assert_eq!(sent, line);
+ }
+ ChatAction::None => assert!(!allowed, "{visibility:?} kept {line}"),
+ ChatAction::Close => panic!("Enter does not close the chat"),
+ }
+ }
+ }
+}
+
+/// The restriction the option sets is a usage line: red, under the input, for
+/// a command the Chat option takes and for a message it takes.
+#[test]
+fn restricted_input_says_why_it_will_not_send() {
+ let font = font();
+ let m = Measure(&font);
+ let registries = Registries::default();
+ let c = Commands {
+ dispatcher: crate::command::vanilla::game_dispatcher(),
+ registries: ®istries,
+ };
+ let usage = |visibility, line: &str| {
+ let mut screen = ChatScreen::new(&m, &c, "", 0, 640, 360, ChatAbilities::new(visibility));
+ screen.type_text(&m, &c, line);
+ screen.usage.iter().map(|t| t.plain()).collect::>()
+ };
+ assert_eq!(usage(ChatVisibility::Full, "hi"), Vec::::new());
+ // The font has no language files here, so the line is its key.
+ assert_eq!(
+ usage(ChatVisibility::System, "hi"),
+ ["chat_screen.messages_not_allowed"]
+ );
+ // A command the option allows says nothing about the restriction.
+ assert!(
+ !usage(ChatVisibility::System, "/time set day")
+ .iter()
+ .any(|line| line == "chat_screen.commands_not_allowed")
+ );
+ assert!(
+ usage(ChatVisibility::Hidden, "/time set day")
+ .iter()
+ .any(|line| line == "chat_screen.commands_not_allowed")
+ );
+}
+
+/// `ChatComponent.setVisibleMessageFilter`: a message the Chat option hides
+/// on arrival is dropped; one already in the chat leaves it while the option
+/// hides its kind and comes back when it shows it again.
+#[test]
+fn the_chat_option_filters_the_lines_both_ways() {
+ let font = font();
+ let mut chat = Chat::default();
+ let says = |chat: &mut Chat, text: &str, source| {
+ chat.add_message(&font, Text::literal(text), None, source, 0, false);
+ };
+ let shown =
+ |chat: &Chat| -> Vec { chat.lines.iter().map(|l| l.content.plain()).collect() };
+ says(&mut chat, "player", ChatSource::Player);
+ says(&mut chat, "server", ChatSource::Server);
+ chat.set_abilities(&font, ChatAbilities::new(ChatVisibility::System));
+ assert_eq!(shown(&chat), ["server"]);
+ says(&mut chat, "dropped", ChatSource::Player);
+ chat.set_abilities(&font, ChatAbilities::new(ChatVisibility::Hidden));
+ says(&mut chat, "client", ChatSource::Client);
+ assert_eq!(shown(&chat), ["client"]);
+ chat.set_abilities(&font, ChatAbilities::new(ChatVisibility::Full));
+ assert_eq!(shown(&chat), ["client", "server", "player"]);
+}
diff --git a/crates/horizon-client/src/collisions.rs b/crates/horizon-client/src/collisions.rs
index 3ff2cfdd6..7c32bd829 100644
--- a/crates/horizon-client/src/collisions.rs
+++ b/crates/horizon-client/src/collisions.rs
@@ -92,6 +92,13 @@ impl BlockCollisionWorld for EntityCollisions<'_, W> {
) -> std::result::Result {
self.blocks.is_suffocating(chunk, block, p)
}
+ fn may_reach_out(
+ &mut self,
+ chunk: Self::Chunk,
+ section_y: i32,
+ ) -> std::result::Result {
+ self.blocks.may_reach_out(chunk, section_y)
+ }
fn context_shape(
&mut self,
block: CollisionBlock,
@@ -262,6 +269,17 @@ impl<'w> BlockCollisionWorld for SceneCollisions<'w, '_> {
fn collision_block(&mut self, chunk: Self::Chunk, p: BlockPos) -> io::Result {
self.binding.collision_block(chunk.block(p.x, p.y, p.z))
}
+ /// From the section's palette, without reading its blocks; a palette
+ /// of the whole registry reads every cell.
+ fn may_reach_out(&mut self, chunk: Self::Chunk, section_y: i32) -> io::Result {
+ let blocks = usize::try_from(section_y - (crate::chunk::MIN_Y >> 4))
+ .ok()
+ .and_then(|s| chunk.sections.get(s))
+ .map(|section| §ion.blocks);
+ Ok(blocks.is_none_or(|blocks| {
+ blocks.is_global() || blocks.maybe_has(|v| self.binding.reaches_out(BlockStateId(v)))
+ }))
+ }
fn is_suffocating(
&mut self,
_: Self::Chunk,
diff --git a/crates/horizon-client/src/containers.rs b/crates/horizon-client/src/containers.rs
index 26ca193a2..d13c5e45b 100644
--- a/crates/horizon-client/src/containers.rs
+++ b/crates/horizon-client/src/containers.rs
@@ -83,6 +83,60 @@ pub enum BlockEntity {
Beehive(Box),
/// `CommandBlockEntity` of the three command blocks (`crate::command_block`).
CommandBlock(Box),
+ /// `SkullBlockEntity` of every skull and head block.
+ Skull(Skull),
+}
+/// `SkullBlockEntity`: the player profile the head shows (kept as loaded:
+/// a compound, or a string when it names a player only), the note block
+/// sound and `custom_name`.
+#[derive(Clone, Debug, Default)]
+pub struct Skull {
+ pub profile: Option,
+ pub note_block_sound: Option,
+ pub custom_name: Option,
+ /// What `profile` draws, read from it once rather than every frame.
+ pub skin: Option,
+}
+impl Skull {
+ pub fn new(
+ profile: Option,
+ note_block_sound: Option,
+ custom_name: Option,
+ ) -> Self {
+ let skin = profile.as_ref().map(SkullSkin::of);
+ Self {
+ profile,
+ note_block_sound,
+ custom_name,
+ skin,
+ }
+ }
+}
+/// `SkullBlockRenderer.getPlayerSkin` of a head's profile: its skin's URL
+/// with the `skins/` sprite it downloads to, and the
+/// `DefaultPlayerSkin` drawn until that sprite is there (steve for a
+/// profile with no id).
+#[derive(Clone, Debug)]
+pub struct SkullSkin {
+ pub download: Option<(String, String)>,
+ pub fallback: &'static str,
+}
+impl SkullSkin {
+ pub fn of(profile: &horizon_world::nbt::Tag) -> Self {
+ let download = crate::skins::profile_skin_url_nbt(profile).and_then(|url| {
+ let location = crate::skins::skin_location(&crate::skins::texture_hash(&url)?);
+ Some((url, location))
+ });
+ // DefaultPlayerSkin.get(id), or getDefaultSkin (slim steve) without an id.
+ let fallback = crate::skins::profile_uuid_nbt(profile)
+ .map_or("entity/player/slim/steve", crate::tab_list::default_skin);
+ Self { download, fallback }
+ }
+}
+/// The skull and head blocks (`SkullBlock`, `WallSkullBlock`): every
+/// `*_skull` and `*_head` but the piston's head.
+fn is_skull(name: &str) -> bool {
+ name.ends_with("_skull") || (name.ends_with("_head") && name != "minecraft:piston_head")
}
/// `CrafterBlockEntity`: nine slots that can be disabled, the powered flag
/// and the ticks left in the crafting animation.
@@ -238,6 +292,9 @@ impl BlockEntity {
if name.ends_with("_banner") {
return Some(Self::Banner(Banner::default()));
}
+ if is_skull(name) {
+ return Some(Self::Skull(Skull::default()));
+ }
if name == "minecraft:beacon" {
return Some(Self::Beacon(Box::new(Beacon {
last_check_y: i32::MIN / 2,
@@ -283,6 +340,7 @@ impl BlockEntity {
Self::Vault(_) => "minecraft:vault",
Self::Beehive(_) => "minecraft:beehive",
Self::CommandBlock(_) => "minecraft:command_block",
+ Self::Skull(_) => "minecraft:skull",
}
}
pub fn contents(&self) -> Vec {
@@ -298,7 +356,8 @@ impl BlockEntity {
| Self::TrialSpawner(_)
| Self::Vault(_)
| Self::Beehive(_)
- | Self::CommandBlock(_) => Vec::new(),
+ | Self::CommandBlock(_)
+ | Self::Skull(_) => Vec::new(),
Self::Lectern(l) => l.book.iter().cloned().collect(),
Self::Sculk(_) => Vec::new(),
Self::Banner(_) => Vec::new(),
@@ -315,7 +374,8 @@ impl BlockEntity {
| Self::Beacon(_)
| Self::Lectern(_)
| Self::Sculk(_)
- | Self::Banner(_) => &[],
+ | Self::Banner(_)
+ | Self::Skull(_) => &[],
Self::Crafter(c) => &c.items,
Self::CreakingHeart(_)
| Self::Spawner(_)
@@ -335,7 +395,8 @@ impl BlockEntity {
| Self::Beacon(_)
| Self::Lectern(_)
| Self::Sculk(_)
- | Self::Banner(_) => &mut [],
+ | Self::Banner(_)
+ | Self::Skull(_) => &mut [],
Self::Crafter(c) => &mut c.items,
Self::CreakingHeart(_)
| Self::Spawner(_)
diff --git a/crates/horizon-client/src/cooldowns.rs b/crates/horizon-client/src/cooldowns.rs
new file mode 100644
index 000000000..31e882712
--- /dev/null
+++ b/crates/horizon-client/src/cooldowns.rs
@@ -0,0 +1,174 @@
+//! `Player.getCooldowns()` (`ItemCooldowns`) as the game keeps it: the
+//! `use_cooldown` component's entries by cooldown group, counted down once a
+//! tick, and the percent `GuiGraphicsExtractor.itemCooldown` shades a slot
+//! by. The world crate's `item_cooldowns` models vanilla's hash map and its
+//! observers for the parity harness; this is the same data with the lookup a
+//! slot needs, and no observer (vanilla's own player uses the plain class).
+use crate::items::ItemStack;
+use horizon_world::nbt::Tag;
+use std::collections::HashMap;
+use std::sync::Arc;
+
+/// A stack's `minecraft:use_cooldown` component.
+#[derive(Clone, Debug, PartialEq)]
+pub struct UseCooldown {
+ pub seconds: f32,
+ /// `cooldown_group`: the group the entry is filed under, else the item.
+ pub group: Option>,
+}
+impl UseCooldown {
+ /// `UseCooldown.ticks`: the seconds in ticks, truncated.
+ pub fn ticks(&self) -> i32 {
+ (self.seconds * 20.0) as i32
+ }
+ /// The component as `items.json` holds it.
+ pub fn from_json(v: &serde_json::Value) -> Option {
+ let seconds = v.get("seconds")?.as_f64()? as f32;
+ Some(Self {
+ seconds,
+ group: v
+ .get("cooldown_group")
+ .and_then(|g| g.as_str())
+ .map(Arc::from),
+ })
+ }
+ /// The component as a stack's saved `components` holds it.
+ pub fn from_tag(t: &Tag) -> Option {
+ let Tag::Compound(c) = t else {
+ return None;
+ };
+ let text = |k: &str| match c.get(&horizon_world::nbt::JavaString::from(k)) {
+ Some(Tag::String(s)) => Some(s.to_string_lossy()),
+ _ => None,
+ };
+ let seconds = match c.get(&horizon_world::nbt::JavaString::from("seconds")) {
+ Some(Tag::Float(bits)) => f32::from_bits(*bits),
+ Some(Tag::Double(bits)) => f64::from_bits(*bits) as f32,
+ _ => return None,
+ };
+ Some(Self {
+ seconds,
+ group: text("cooldown_group").map(Arc::from),
+ })
+ }
+}
+
+/// The component a stack carries: its own patch first (`ItemStack.get`), then
+/// the item's default from `items.json` (`ItemInfo::use_cooldown`).
+pub fn component(stack: &ItemStack, default: Option<&UseCooldown>) -> Option {
+ stack
+ .data()
+ .and_then(|d| d.other("minecraft:use_cooldown"))
+ .and_then(UseCooldown::from_tag)
+ .or_else(|| default.cloned())
+}
+
+/// `ItemCooldowns.getCooldownGroup`: the component's group, else the item id.
+pub fn group(stack: &ItemStack, default: Option<&UseCooldown>) -> Arc {
+ component(stack, default)
+ .and_then(|c| c.group)
+ .unwrap_or_else(|| Arc::clone(&stack.item))
+}
+
+/// `ItemCooldowns`: start and end ticks by group, and the tick counter.
+#[derive(Clone, Debug, Default)]
+pub struct Cooldowns {
+ tick_count: i32,
+ entries: HashMap, (i32, i32)>,
+}
+impl Cooldowns {
+ /// `getCooldownPercent`: what is left of the entry, from 1 to 0.
+ pub fn percent(&self, group: &str, partial_tick: f32) -> f32 {
+ let Some((start, end)) = self.entries.get(group) else {
+ return 0.0;
+ };
+ let duration = end.wrapping_sub(*start) as f32;
+ let remaining = *end as f32 - (self.tick_count as f32 + partial_tick);
+ (remaining / duration).clamp(0.0, 1.0)
+ }
+ /// `isOnCooldown`: whether the group still has time to run.
+ pub fn is_on_cooldown(&self, group: &str) -> bool {
+ self.percent(group, 0.0) > 0.0
+ }
+ /// `addCooldown`.
+ pub fn add(&mut self, group: Arc, ticks: i32) {
+ self.entries.insert(
+ group,
+ (self.tick_count, self.tick_count.wrapping_add(ticks)),
+ );
+ }
+ /// `ItemCooldowns.tick`: the counter, then every entry that has run out,
+ /// which it hands back (`onCooldownEnded`).
+ pub fn tick(&mut self) -> Vec> {
+ self.tick_count = self.tick_count.wrapping_add(1);
+ let done: Vec> = self
+ .entries
+ .iter()
+ .filter(|(_, (_, end))| *end <= self.tick_count)
+ .map(|(group, _)| Arc::clone(group))
+ .collect();
+ self.entries.retain(|_, (_, end)| *end > self.tick_count);
+ done
+ }
+ /// `removeCooldown`.
+ pub fn remove(&mut self, group: &str) {
+ self.entries.remove(group);
+ }
+ pub fn is_empty(&self) -> bool {
+ self.entries.is_empty()
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+
+ fn stack(item: &str) -> ItemStack {
+ ItemStack::new(item, 1)
+ }
+
+ #[test]
+ fn the_percent_falls_from_one_to_zero_over_the_entry() {
+ let mut c = Cooldowns::default();
+ c.add(Arc::from("minecraft:ender_pearl"), 20);
+ assert!(c.is_on_cooldown("minecraft:ender_pearl"));
+ assert_eq!(c.percent("minecraft:ender_pearl", 0.0), 1.0);
+ for _ in 0..10 {
+ assert!(c.tick().is_empty());
+ }
+ assert_eq!(c.percent("minecraft:ender_pearl", 0.0), 0.5);
+ // The partial tick moves it within the tick.
+ assert_eq!(c.percent("minecraft:ender_pearl", 0.5), 0.475);
+ for _ in 0..9 {
+ c.tick();
+ }
+ assert!(c.is_on_cooldown("minecraft:ender_pearl"));
+ // ItemCooldowns.tick drops the entry at its end tick, and says so.
+ assert_eq!(c.tick(), [Arc::::from("minecraft:ender_pearl")]);
+ assert!(!c.is_on_cooldown("minecraft:ender_pearl"));
+ assert!(c.is_empty());
+ assert_eq!(c.percent("minecraft:ender_pearl", 0.0), 0.0);
+ }
+
+ #[test]
+ fn the_group_comes_from_the_stack_then_the_item() {
+ let pearl = stack("minecraft:ender_pearl");
+ let default = UseCooldown::from_json(&json!({"seconds": 1.0})).expect("the component");
+ assert_eq!(&*group(&pearl, Some(&default)), "minecraft:ender_pearl");
+ // A stack's own component overrides the item's, group included.
+ let mut grouped = stack("minecraft:ender_pearl");
+ grouped.data_mut().set_other(
+ "minecraft:use_cooldown",
+ Some(Tag::compound([
+ ("seconds", Tag::Float(2.0f32.to_bits())),
+ ("cooldown_group", Tag::String("minecraft:pearls".into())),
+ ])),
+ );
+ let c = component(&grouped, Some(&default)).expect("the stack's component");
+ assert_eq!(c.ticks(), 40);
+ assert_eq!(&*group(&grouped, Some(&default)), "minecraft:pearls");
+ // An item without the component has no cooldown.
+ assert!(component(&stack("minecraft:dirt"), None).is_none());
+ }
+}
diff --git a/crates/horizon-client/src/debug_overlay.rs b/crates/horizon-client/src/debug_overlay.rs
index 3448ea411..7140905a8 100644
--- a/crates/horizon-client/src/debug_overlay.rs
+++ b/crates/horizon-client/src/debug_overlay.rs
@@ -84,6 +84,33 @@ impl Displayer {
}
}
+/// Horizon's own lines: the shader pack's GPU time, then its costliest passes (`passes`: each
+/// pass's median milliseconds, in the order they run).
+pub fn shader_pass_lines(passes: &[(String, f32)]) -> Vec {
+ const SHOWN: usize = 8;
+ if passes.is_empty() {
+ return Vec::new();
+ }
+ let total: f32 = passes.iter().map(|p| p.1).sum();
+ let mut lines = vec![format!(
+ "Shader pack GPU: {total:.2} ms in {} passes",
+ passes.len()
+ )];
+ let mut costliest: Vec<&(String, f32)> = passes.iter().collect();
+ costliest.sort_by(|a, b| b.1.total_cmp(&a.1));
+ lines.extend(
+ costliest
+ .iter()
+ .take(SHOWN)
+ .map(|(name, ms)| format!("{name}: {ms:.2} ms")),
+ );
+ if costliest.len() > SHOWN {
+ let rest: f32 = costliest[SHOWN..].iter().map(|p| p.1).sum();
+ lines.push(format!("{} more: {rest:.2} ms", costliest.len() - SHOWN));
+ }
+ lines
+}
+
/// `Mth.wrapDegrees`.
fn wrap_degrees(angle: f32) -> f32 {
let wrapped = angle % 360.0;
@@ -337,4 +364,15 @@ mod tests {
(1.0, [640, 360])
);
}
+
+ #[test]
+ fn shader_pass_lines_list_the_costliest_passes_first() {
+ assert!(shader_pass_lines(&[]).is_empty());
+ let passes: Vec<(String, f32)> = (0..10).map(|i| (format!("p{i}"), i as f32)).collect();
+ let lines = shader_pass_lines(&passes);
+ assert_eq!(lines[0], "Shader pack GPU: 45.00 ms in 10 passes");
+ assert_eq!(lines[1], "p9: 9.00 ms");
+ assert_eq!(lines[8], "p2: 2.00 ms");
+ assert_eq!(lines[9], "2 more: 1.00 ms");
+ }
}
diff --git a/crates/horizon-client/src/dialog.rs b/crates/horizon-client/src/dialog.rs
new file mode 100644
index 000000000..7acd3e86a
--- /dev/null
+++ b/crates/horizon-client/src/dialog.rs
@@ -0,0 +1,794 @@
+//! Server dialogs (`net.minecraft.server.dialog`): what `Dialog.DIRECT_CODEC`
+//! decodes from a `show_dialog` packet, the values its inputs hold, and the
+//! click event an action makes of them (`Action.createAction`).
+use crate::text::Text;
+use horizon_world::nbt::Tag;
+use serde_json::{Value, json};
+
+/// `CommonDialogData` and the type's own fields.
+#[derive(Clone, Debug)]
+pub struct Dialog {
+ pub kind: Kind,
+ pub title: Text,
+ pub external_title: Option,
+ pub can_close_with_escape: bool,
+ pub pause: bool,
+ pub after_action: AfterAction,
+ pub body: Vec,
+ pub inputs: Vec,
+}
+
+/// The dialog types (`DialogTypes`).
+#[derive(Clone, Debug)]
+pub enum Kind {
+ /// `NoticeDialog`: one button, "OK" when the server names none.
+ Notice(Button),
+ Confirmation {
+ yes: Button,
+ no: Button,
+ },
+ MultiAction {
+ actions: Vec