game.world-seed (API 25)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 03:20:06 +03:00
committed by airdef
parent 734f632cbf
commit 3de52c252c
5 changed files with 17 additions and 2 deletions
+3
View File
@@ -599,6 +599,9 @@ impl Game<'_> {
.is_some()
.then(|| self.mods.world_id.clone())
.flatten(),
world_seed: (self.player.is_some()
&& self.mods.world_id.as_deref().is_some_and(|w| w.starts_with("world:")))
.then_some(self.level.seed),
}
}
/// The first block along the player's view within
+4
View File
@@ -51,6 +51,10 @@ interface game {
/// world, `server:<address>` on a server; none on the title screen.
/// Mods keep their state apart by it.
world-id: func() -> option<string>;
/// The open saved world's seed (AirDef fork, API level 25): with the
/// folder name it tells a new world from an old one that had the same
/// name. None on the title screen and on a server.
world-seed: func() -> option<s64>;
/// A block along the player's view.
record hit {
/// The block hit.
+4 -2
View File
@@ -7,13 +7,13 @@
//! version's level so the launcher can tell before it installs.
/// The newest level this Horizon serves.
pub const LEVEL: u32 = 24;
pub const LEVEL: u32 = 25;
/// Every function the game offers mods, as `interface.function`, with its
/// level. Level 0 is the contract of Horizon 0.2.67 to 0.2.69. A new
/// function takes the next level and raises [`LEVEL`] (the `api_reference`
/// test fails until it is listed here).
pub const FUNCTIONS: [(&str, u32); 90] = [
pub const FUNCTIONS: [(&str, u32); 91] = [
("log.write", 0),
("game.get-player", 0),
("game.get-clock", 0),
@@ -118,6 +118,8 @@ pub const FUNCTIONS: [(&str, u32); 90] = [
("render.set-canvas", 24),
("render.canvas-events", 24),
("render.canvas-open", 24),
// AirDef fork: the open world's seed, so a new world is not an old one of the same name.
("game.world-seed", 25),
];
/// What the game's program carries so the launcher can read its level
+5
View File
@@ -189,6 +189,8 @@ pub struct Snapshot {
pub creative: bool,
/// The open world (`game.world-id`, AirDef fork).
pub world: Option<String>,
/// The open saved world's seed (`game.world-seed`, AirDef fork).
pub world_seed: Option<i64>,
}
/// Capability `recipes`'s tables: `items` in the registry's order, which
@@ -1930,6 +1932,9 @@ impl game::Host for State {
fn world_id(&mut self) -> Option<String> {
self.snapshot.world.clone()
}
fn world_seed(&mut self) -> Option<i64> {
self.snapshot.world_seed
}
fn raycast(&mut self, distance: f32) -> Option<Hit> {
let (at, hit) = self.snapshot.view_hit.as_ref()?;
// NaN compares false: no hit.
+1
View File
@@ -126,6 +126,7 @@ A block along the player's view.
| `get-player` | `func() -> option<player>` | None on the title screen. |
| `get-clock` | `func() -> option<clock>` | None on the title screen. |
| `world-id` | `func() -> option<string>` | Which world is open (AirDef fork): `world:<folder>` for a saved world, `server:<address>` on a server; none on the title screen. Mods keep their state apart by it. |
| `world-seed` | `func() -> option<s64>` | The open saved world's seed (AirDef fork, API level 25): with the folder name it tells a new world from an old one that had the same name. None on the title screen and on a server. |
| `raycast` | `func(distance: f32) -> option<hit>` | The first block along the player's view (fluids pass), up to `distance` blocks (at most 1024; past the loaded chunks, across the distant terrain when LOD Distance is on), as of this tick. None when nothing is hit, and on the title screen. |
## `chat`