Merge pull request #2478 from kacpherek/feat/far-view-mod-api

🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19). Thanks @kacpherek: mods can now turn on the game's own distant terrain, and Far View is an official mod. I merged main into the branch. render.set-far-terrain is now API level 7, because main added levels 4 to 6 (world, recipes, browser) in the meantime. The horizon-mods sandbox tests (32), the far-view wasm build, and clippy with the mods feature all pass. Without the mods feature, the LOD path is unchanged.
This commit is contained in:
Ludovic Marie
2026-10-27 08:54:55 +01:00
committed by GitHub
17 changed files with 263 additions and 27 deletions
Generated
+7
View File
@@ -930,6 +930,13 @@ version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b5343afd4a8365a643ac588dab4cf234a190c7f6c88c9f6dd6ffe00837661b7"
[[package]]
name = "far-view"
version = "1.0.0"
dependencies = [
"horizon-mod-sdk",
]
[[package]]
name = "fdeflate"
version = "0.3.7"
+1
View File
@@ -35,6 +35,7 @@ members = [
"crates/horizon-mod-sdk/examples/beacons",
"mods/official/fps-overlay",
"mods/official/keystrokes",
"mods/official/far-view",
"mods/official/minimap",
"mods/official/zoom",
"xtask",
+25 -9
View File
@@ -11586,11 +11586,28 @@ impl Game<'_> {
}
Ok(())
}
/// LOD Distance as far terrain uses it (`Graphics::lod_distance_on`).
/// LOD Distance and Far Detail Reduced as chosen: the player's LOD
/// Distance when it is on, else a mod's far terrain
/// (`render.set-far-terrain`).
fn far_terrain_choice(&self) -> (u32, bool) {
let g = &self.settings.horizon;
let reduced = g.far_detail == horizon_client::graphics::FarDetail::Reduced;
if g.lod_distance > 0 {
return (g.lod_distance, reduced);
}
match self.mod_far_terrain() {
Some(f) => (f.distance, reduced || f.reduced),
None => (0, reduced),
}
}
/// LOD Distance as far terrain uses it (`graphics::lod_distance_capped`).
fn lod_distance(&self) -> u32 {
let (distance, _) = self.far_terrain_choice();
match &self.renderer {
Some(renderer) => self.settings.horizon.lod_distance_on(&renderer.info),
None => self.settings.horizon.lod_distance.min(1024),
Some(renderer) => {
horizon_client::graphics::lod_distance_capped(distance, &renderer.info)
}
None => distance.min(1024),
}
}
/// Only enabled LOD worlds extend the renderer's range, never simulation.
@@ -11611,7 +11628,7 @@ impl Game<'_> {
}
}
fn prepare_lod(&mut self) {
let enabled = self.settings.horizon.lod_distance > 0
let enabled = self.far_terrain_choice().0 > 0
&& self.renderer.is_some()
&& self.player.is_some()
&& self.title.is_none()
@@ -11708,6 +11725,7 @@ impl Game<'_> {
{
log::warn!("Horizon: failed to save unloaded chunks: {e}");
}
let (far_distance, far_reduced) = self.far_terrain_choice();
if let Some(renderer) = self.renderer.as_mut() {
let g = &self.settings.horizon;
let budgeted = g.chunk_updates > 0 || g.upload_budget_kib > 0;
@@ -11761,12 +11779,10 @@ impl Game<'_> {
}
renderer.remove_columns(unloaded.iter().map(|c| (c.x, c.z)));
if let (Some(lod), Some(player)) = (&mut self.lod, &self.player) {
let lod_distance = self.settings.horizon.lod_distance_on(&renderer.info);
let lod_distance =
horizon_client::graphics::lod_distance_capped(far_distance, &renderer.info);
lod.set_near_loading(self.streaming.busy());
lod.set_reduced_detail(
self.settings.horizon.far_detail
== horizon_client::graphics::FarDetail::Reduced,
);
lod.set_reduced_detail(far_reduced);
// The covered columns change only with the complete ones and
// the render area: rebuilt then, not every frame.
let at = (
@@ -31,6 +31,9 @@ impl Game<'_> {
pub(super) fn mod_minimap(&self) -> Option<ModMinimap> {
None
}
pub(super) fn mod_far_terrain(&self) -> Option<ModFarTerrain> {
None
}
}
/// A mod's zoom (`render.set-zoom`), clamped by the runtime.
@@ -51,6 +54,13 @@ pub(super) struct ModMinimap {
pub(super) round: bool,
}
/// A mod's far terrain (`render.set-far-terrain`), clamped by the runtime.
#[derive(Clone, Copy)]
pub(super) struct ModFarTerrain {
pub(super) distance: u32,
pub(super) reduced: bool,
}
#[cfg(feature = "mods")]
impl Game<'_> {
/// The main hand's stack as `input` shows it; none when it is empty.
@@ -190,4 +200,12 @@ impl Game<'_> {
round: m.round,
})
}
/// The far terrain the first mod drawing one asks for.
pub(super) fn mod_far_terrain(&self) -> Option<ModFarTerrain> {
let f = self.mods.mods.far_terrain()?;
Some(ModFarTerrain {
distance: f.distance,
reduced: f.reduced,
})
}
}
+10 -6
View File
@@ -216,15 +216,19 @@ pub const INTEGRATED_LOD_DISTANCE: u32 = 128;
pub fn lod_capped(info: &wgpu::AdapterInfo) -> bool {
info.device_type == wgpu::DeviceType::IntegratedGpu && !info.name.starts_with("Apple")
}
/// A LOD distance as far terrain uses it on this adapter.
pub fn lod_distance_capped(distance: u32, info: &wgpu::AdapterInfo) -> u32 {
let distance = distance.min(1024);
if lod_capped(info) {
distance.min(INTEGRATED_LOD_DISTANCE)
} else {
distance
}
}
impl Graphics {
/// `lod_distance` as far terrain uses it on this adapter.
pub fn lod_distance_on(&self, info: &wgpu::AdapterInfo) -> u32 {
let distance = self.lod_distance.min(1024);
if lod_capped(info) {
distance.min(INTEGRATED_LOD_DISTANCE)
} else {
distance
}
lod_distance_capped(self.lod_distance, info)
}
}
#[derive(Clone, Debug, PartialEq)]
+17
View File
@@ -412,6 +412,23 @@ interface render {
/// own frame budget; hidden, they are dropped. One map shows at a time:
/// the first loaded mod's.
set-minimap: func(minimap: option<minimap>);
record far-terrain {
/// How far the distant terrain reaches, in chunks: 64 to 1024. On
/// integrated graphics other than Apple's the game caps it lower.
distance: u32,
/// Coarser far tiles, as the Far Detail setting's Reduced: 2 to 4 ms
/// less GPU time per frame on integrated graphics.
reduced: bool,
}
/// Draws the world beyond the render distance as distant terrain, out to
/// `distance` chunks, until the next call (none ends it). The game builds
/// it on its own workers, from the chunks already loaded or saved and,
/// where nobody has been, from the world's generator; the simulation
/// distance doesn't change. Only worlds whose generator the game has
/// (single player and a LAN world you host) show it. The player's own LOD
/// Distance setting, when on, wins. One far terrain shows at a time: the
/// first loaded mod's.
set-far-terrain: func(far-terrain: option<far-terrain>);
}
/// What the game calls. Only the hooks `init` asks for are ever called.
+3 -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 = 6;
pub const LEVEL: u32 = 7;
/// 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); 45] = [
pub const FUNCTIONS: [(&str, u32); 46] = [
("log.write", 0),
("game.get-player", 0),
("game.get-clock", 0),
@@ -59,6 +59,7 @@ pub const FUNCTIONS: [(&str, u32); 45] = [
("browser.set-recipes", 6),
("recipes.place", 6),
("recipes.give", 6),
("render.set-far-terrain", 7),
];
/// What the game's program carries so the launcher can read its level
+22 -3
View File
@@ -78,9 +78,9 @@ use render_bindings::horizon::mods::input;
pub use render_bindings::horizon::mods::input::{Event as InputEvent, HeldItem, ItemUse};
/// What capability `render` asks the game to draw (WIT `interface render`).
pub use render_bindings::horizon::mods::render::{
Corner as RenderCorner, FillShape, FrameRate, ItemShape, Minimap as ModMinimap,
Point as RenderPoint, QuadShape, Rect as RenderRect, Shape, SpriteShape, TextShape,
Zoom as ModZoom,
Corner as RenderCorner, FarTerrain as ModFarTerrain, FillShape, FrameRate, ItemShape,
Minimap as ModMinimap, Point as RenderPoint, QuadShape, Rect as RenderRect, Shape, SpriteShape,
TextShape, Zoom as ModZoom,
};
use render_bindings::{RenderHost, horizon::mods::render};
/// Capability `recipes`'s imports (docs/mods.md): the game's recipes and items.
@@ -414,6 +414,8 @@ struct State {
zoom: Option<ModZoom>,
/// Capability `render`'s minimap, when the mod shows one.
minimap: Option<ModMinimap>,
/// Capability `render`'s far terrain, when the mod draws one.
far_terrain: Option<ModFarTerrain>,
input: InputState,
browser: BrowserState,
/// Capability `storage`'s folder; made on first `set`.
@@ -616,6 +618,7 @@ impl Mods {
corner: None,
zoom: None,
minimap: None,
far_terrain: None,
input: InputState::default(),
browser: BrowserState::default(),
data_dir,
@@ -1170,6 +1173,12 @@ impl Mods {
.iter()
.find_map(|e| e.run.as_ref()?.store.data().minimap)
}
/// The far terrain the first running mod draws (capability `render`).
pub fn far_terrain(&self) -> Option<ModFarTerrain> {
self.entries
.iter()
.find_map(|e| e.run.as_ref()?.store.data().far_terrain)
}
fn inputs(&self) -> impl Iterator<Item = &InputState> {
self.entries
.iter()
@@ -1723,6 +1732,8 @@ const TURN_MIN: f32 = 0.05;
/// `set-minimap`'s side in GUI pixels and its blocks per map pixel.
const MINIMAP_SIZE: (f32, f32) = (16.0, 256.0);
const MINIMAP_SCALE: (f32, f32) = (0.5, 4.0);
/// `set-far-terrain`'s distance in chunks, as the LOD Distance setting's.
const FAR_TERRAIN_DISTANCE: (u32, u32) = (64, 1024);
/// A mod's corner panel: shapes in a `width` × `height` box the game
/// places in `corner`, stacked with the other overlays.
@@ -1812,6 +1823,14 @@ impl render::Host for State {
..m
});
}
fn set_far_terrain(&mut self, far_terrain: Option<ModFarTerrain>) {
self.far_terrain = far_terrain.map(|f| ModFarTerrain {
distance: f
.distance
.clamp(FAR_TERRAIN_DISTANCE.0, FAR_TERRAIN_DISTANCE.1),
..f
});
}
fn frame_stats(&mut self) -> FrameRate {
let (fps, min, low) = self.snapshot.frame;
FrameRate { fps, min, low }
+18 -3
View File
@@ -205,7 +205,7 @@ fn undeclared_capabilities_are_refused() {
/// from the functions they import.
#[test]
fn a_mod_for_a_newer_horizon_is_refused() {
use horizon_mods::api_level::{imports, needed};
use horizon_mods::api_level::{LEVEL, imports, needed};
use wit_parser::{ManglingAndAbi, Resolve};
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let wit = std::fs::read_to_string(root.join("crates/horizon-mod-sdk/wit/horizon.wit"))
@@ -255,8 +255,8 @@ experimental = ["ui", "render", "input", "recipes"]
needed(imports(&wasm).unwrap().iter().map(String::as_str)).0
};
assert_eq!(level("coords_hud.hmod"), 0);
// The UI guest fills a browser panel (`browser`, level 6).
assert_eq!(level("horizon_mods_test_ui_guest.hmod"), 6);
// The UI guest draws far terrain (`render.set-far-terrain`).
assert_eq!(level("horizon_mods_test_ui_guest.hmod"), LEVEL);
}
#[test]
@@ -725,6 +725,21 @@ fn render_minimap_is_clamped_and_hidden() {
assert_eq!(map(&mut mods, "off"), None);
}
#[test]
fn render_far_terrain_is_clamped_and_ended() {
let mut mods = load("horizon_mods_test_ui_guest.hmod");
let far = |mods: &mut Mods, args: &str| {
assert!(mods.command(&format!("far_terrain {args}")));
mods.far_terrain().map(|f| (f.distance, f.reduced))
};
assert!(mods.far_terrain().is_none());
assert_eq!(far(&mut mods, "256 1"), Some((256, true)));
// The distance is clamped to LOD Distance's 64 to 1024 chunks.
assert_eq!(far(&mut mods, "8 0"), Some((64, false)));
assert_eq!(far(&mut mods, "99999 0"), Some((1024, false)));
assert_eq!(far(&mut mods, "off"), None);
}
/// `game.raycast`: the view's hit the game worked out, up to the distance
/// asked for; the game works it out only while a mod imports the call.
#[test]
@@ -112,6 +112,7 @@ impl Mod for Guest {
"input_wheel",
"zoom",
"minimap",
"far_terrain",
"raycast",
"quiet",
"quiet_many",
@@ -242,6 +243,15 @@ impl Mod for Guest {
});
render::set_minimap(map);
}
// `far_terrain off`, or `far_terrain DISTANCE REDUCED`.
"far_terrain" => {
let words: Vec<&str> = args.split(' ').collect();
let far = (args != "off").then(|| render::FarTerrain {
distance: words.first().and_then(|w| w.parse().ok()).unwrap_or(0),
reduced: words.get(1) == Some(&"1"),
});
render::set_far_terrain(far);
}
"quiet" => command::run_quiet(&args.split(';').map(str::to_owned).collect::<Vec<_>>()),
"quiet_many" => {
let n: usize = args.parse().unwrap_or(0);
+8
View File
@@ -435,6 +435,13 @@ Any four-cornered shape (a wheel's segment, an arrow): the corners in order roun
| `rotate` | `bool` | The map turns with the player, who faces up, and an N on its rim marks north. Otherwise north is up and the player's arrow turns. |
| `round` | `bool` | Round, the corners left clear; otherwise square. |
### record `far-terrain`
| Field | Type | |
| --- | --- | --- |
| `distance` | `u32` | How far the distant terrain reaches, in chunks: 64 to 1024. On integrated graphics other than Apple's the game caps it lower. |
| `reduced` | `bool` | Coarser far tiles, as the Far Detail setting's Reduced: 2 to 4 ms less GPU time per frame on integrated graphics. |
| Function | Signature | What it does |
| --- | --- | --- |
| `set-hud` | `func(shapes: list<shape>)` | Replaces the mod's HUD shapes: up to 1024, drawn every frame in order over the HUD (after the hotbar, under chat and screens), hidden with the HUD (F1). An empty list removes them. |
@@ -446,6 +453,7 @@ Any four-cornered shape (a wheel's segment, an arrow): the corners in order roun
| `frame-stats` | `func() -> frame-rate` | The game's frame counter, recomputed twice a second. |
| `set-zoom` | `func(zoom: zoom)` | Zooms the camera until the next call (`factor` 1 ends it), only while playing: a screen opening or the spyglass's own view (which wins) leave the camera vanilla's. With several mods, the strongest zoom counts. |
| `set-minimap` | `func(minimap: option<minimap>)` | Shows a map of the world around the player in `corner`, stacked with the game's overlays and the mods' panels, until the next call (none hides it). It looks like a map item: vanilla's map colours with their height shading and water depth, and the player's arrow. Underground, under a roof and in the Nether it maps the floor around the player's height. The game keeps the map's tiles and refreshes them within its own frame budget; hidden, they are dropped. One map shows at a time: the first loaded mod's. |
| `set-far-terrain` | `func(far-terrain: option<far-terrain>)` | Draws the world beyond the render distance as distant terrain, out to `distance` chunks, until the next call (none ends it). The game builds it on its own workers, from the chunks already loaded or saved and, where nobody has been, from the world's generator; the simulation distance doesn't change. Only worlds whose generator the game has (single player and a LAN world you host) show it. The player's own LOD Distance setting, when on, wins. One far terrain shows at a time: the first loaded mod's. |
## `events`
+6 -1
View File
@@ -38,7 +38,7 @@ don't import it); faster, or fixing behaviour to what the reference already says
A new WIT function doesn't break older mods, but a mod that calls it can't run on a Horizon from before it. So every
function the game offers mods has an **API level**, the one it arrived at (`crates/horizon-mods/src/api_level.rs`):
level 0 is the contract of Horizon 0.2.67 to 0.2.69, level 1 adds `render.set-minimap` and server mods' `players`, level 2 `game.raycast`, level 3 `command.run-quiet`, level 4 server mods' `world`, level 5 `recipes` (`items`, `all`, `known`), level 6 `browser` (`set-items`, `poll`, `set-recipes`) and `recipes.place` and `recipes.give`. A mod needs the level of
level 0 is the contract of Horizon 0.2.67 to 0.2.69, level 1 adds `render.set-minimap` and server mods' `players`, level 2 `game.raycast`, level 3 `command.run-quiet`, level 4 server mods' `world`, level 5 `recipes` (`items`, `all`, `known`), level 6 `browser` (`set-items`, `poll`, `set-recipes`) and `recipes.place` and `recipes.give`, level 7 `render.set-far-terrain`. A mod needs the level of
the newest function it imports (a component imports only the functions it calls). The level is read from the file,
never declared:
@@ -134,3 +134,8 @@ Deprecations and breaking changes are in bold. The release notes of the game rel
for a map image costs too much through hook calls, so the game keeps the tiles (vanilla's map colours) and the mod
picks the corner, side, scale and shape. One map shows at a time, the first loaded mod's. It is a new function and a
new type, so mods built before it keep loading.
- **`render.set-far-terrain`** turns on the game's own distant terrain, not one a mod builds: sampling the generator
and meshing thousands of far tiles runs on the game's workers within its frame and upload budgets, which no hook
call could match. The mod picks the distance (64 to 1024 chunks, capped lower on integrated graphics as LOD Distance
is) and Far Detail's Reduced. The player's own LOD Distance, when on, wins; one far terrain shows at a time, the
first loaded mod's.
+1 -1
View File
@@ -47,7 +47,7 @@ Coverage and detail improve progressively; a large selected radius does not mean
Ordinary Overworld atmospheric fog extends with the selected LOD distance. Fog Off disables distance haze at large ranges too; fluid, darkness and boss fog retain their limits.
The setting is stored as `lodDistance` in `horizon-graphics.txt`; `0` disables it. Existing `renderDistance` in `options.txt` keeps its normal meaning for full chunks.
The setting is stored as `lodDistance` in `horizon-graphics.txt`; `0` disables it. The official Far View mod (`mods/official/far-view`, [mods.md](mods.md)) turns the same distant terrain on from the mod browser, with its own distance and detail; the setting, when on, wins. Existing `renderDistance` in `options.txt` keeps its normal meaning for full chunks.
Not implemented: anisotropic filtering (wgpu needs linear magnification for it, which blurs close blocks), MSAA (FXAA instead) and exclusive fullscreen (fullscreen is borderless).
+3 -2
View File
@@ -15,7 +15,7 @@ folder, loads no runtime and plays exactly like vanilla 26.3.
| The contract (WIT) | `crates/horizon-mod-sdk/wit/horizon.wit` | 0.1: log, game-read, chat, hud, storage, command, ui; tick, frame, chat and command hooks |
| SDK for mod authors | `crates/horizon-mod-sdk` | 0.1 |
| Example mods | `crates/horizon-mod-sdk/examples/coords-hud`, `examples/predator-missile` | coordinates, facing and time HUD, `/where`, `/coords`; `/missile`, a guided missile from vanilla commands |
| Horizon's official mods | `mods/official/` | the extras moving to the registry: FPS Counter (`fps-overlay`), Keystrokes, Zoom, Minimap; and Recipes, a recipe viewer |
| Horizon's official mods | `mods/official/` | the extras moving to the registry: FPS Counter (`fps-overlay`), Keystrokes, Zoom, Minimap; Far View (`far-view`), distant terrain; and Recipes, a recipe viewer |
| Runtime | `crates/horizon-mods` | wasmtime 48 LTS, component model |
| Authoring tool | `crates/cargo-horizon-mod` | `cargo horizon-mod new [--template code\|content] / build / run / test / check`, and the registry's CI (`registry build / review / list`) |
| In the game | `crates/horizon-client/src/game/mods.rs`, Options > Mods | client mods |
@@ -89,7 +89,7 @@ folder, loads no runtime and plays exactly like vanilla 26.3.
| `storage` | `storage` | `get(key)`, `set(key, value)`, `delete(key)`: a per-mod folder of up to 64 files, 4 MiB total, at most 1 MiB written per call |
| `command` | `command` | `run(line)`: a vanilla command run as the player, with the player's permissions, after the hook returns (8 per call); mods' own commands are not run. `run-quiet(lines)`: up to 256 a call, the same rights, nothing in the chat (single player and Horizon's servers run them 64 a tick and log one line a batch; elsewhere they go as chat commands and their feedback shows) |
| `ui` | `ui` | `open-screen`, `close-screen`, `set-settings`: a screen the mod owns and a page in Options > Mods, of text, button, item and list widgets the game lays out and draws with its own menus' code; `browser.set-items`, `browser.poll`: a recipe viewer's panel of items right of the inventory and container screens (not the creative one), which the game pages and draws with its own slots and search box, and the mod hears its clicks, its searches and the mod's own keys (`input.register-key`) pressed over any item on the screen; `browser.set-recipes`: recipes in the panel's place (crafting grids, cooking, stonecutting, smithing and brewing layouts, their slots cycling through their stacks, a note and an action button each), paged by the game, with clicks on their slots, action buttons, page turns and a back button. **Experimental:** the manifest needs `experimental = ["ui"]` |
| `render` | `render` | `set-hud(shapes)`: up to 1024 fills, four-cornered shapes, GUI sprites, items and text, kept on the HUD (over the hotbar, under chat and screens, hidden with F1) until replaced; `set-corner(corner, w, h, shapes)`: a box the game places in a corner, stacked with its overlays and other panels, as `hud`'s panels are; `text-width(text)`; `frame-stats()`: the game's FPS, min and 1% low; `gui-size()`; `shake(strength, seconds)`: the view turns, the player doesn't, scaled by Distortion Effects; `set-zoom(zoom)`: the field of view divided by up to 10, eased or at once, with slower turning, while playing and not through a spyglass (the strongest of several mods' zooms counts); `set-minimap(minimap)`: a map of the world around the player in a corner, as a map item colours it (the floor underground and under roofs), square or round, turning with the player or north up, with the player's arrow; the game keeps its tiles within its own frame budget (one map at a time, the first loaded mod's). The game's own HUD renderer draws them: a mod never supplies shader code. **Experimental:** `experimental = ["render"]` |
| `render` | `render` | `set-hud(shapes)`: up to 1024 fills, four-cornered shapes, GUI sprites, items and text, kept on the HUD (over the hotbar, under chat and screens, hidden with F1) until replaced; `set-corner(corner, w, h, shapes)`: a box the game places in a corner, stacked with its overlays and other panels, as `hud`'s panels are; `text-width(text)`; `frame-stats()`: the game's FPS, min and 1% low; `gui-size()`; `shake(strength, seconds)`: the view turns, the player doesn't, scaled by Distortion Effects; `set-zoom(zoom)`: the field of view divided by up to 10, eased or at once, with slower turning, while playing and not through a spyglass (the strongest of several mods' zooms counts); `set-minimap(minimap)`: a map of the world around the player in a corner, as a map item colours it (the floor underground and under roofs), square or round, turning with the player or north up, with the player's arrow; the game keeps its tiles within its own frame budget (one map at a time, the first loaded mod's); `set-far-terrain(far-terrain)`: the world past the render distance as distant terrain, out to 64 to 1024 chunks, built by the game's own workers (the player's LOD Distance, when on, wins; the first loaded mod's). The game's own HUD renderer draws them: a mod never supplies shader code. **Experimental:** `experimental = ["render"]` |
| `input` | `input` | `claim-items(ids)`: the use button on those items is the mod's (`use-start`, `use-stop` with the ticks held; the game doesn't place, eat or swing); `register-key(name, label, key)`: up to 16 keys (`key.keyboard.r`), heard while playing as `key-down` / `key-up` (the game's own mapping on that key still runs; a screen opening lets held keys up), mouse buttons as `key.mouse.4`. The player rebinds them on the mod's page in Options > Mods, where the game lists them first as Key Binds rows (click, then press a key or mouse button; Esc binds none), even for a mod without `ui`; the choice is kept in `horizon-mods.txt` (`key.<mod>.<name>:key.keyboard.z`) and wins over `register-key`'s default; `claim-wheel(on)`: the wheel's steps become `wheel` events and the hotbar doesn't move (the one input a mod takes from the game; a mod's keys never do); `held()`; `mapping(name)`: a movement or click mapping's key label and whether it is held; `clicks-per-second()`; `poll()` returns the events, at most 256 kept. **Experimental:** `experimental = ["input"]` |
| `recipes` | `recipes` | `items()`: every item in the registry's order, with its name in the player's language and its tags; `all()`: every recipe (crafting, smelting, blasting, smoking, campfire, stonecutting, smithing, brewing), its slots as the stacks that fit each, its results, cooking time and experience, and the recipe book's id for it; `known()`: the book ids the player's recipe book holds; `place(book-id, all)`: the recipe book's click on a recipe, in the open inventory's or crafting table's grid (refused for a recipe the player's book doesn't hold, as vanilla's server refuses it); `give(stack)`: in creative mode, the stack into the player's inventory, as from the creative inventory. The recipes are the world's in single player and on Horizon's servers, vanilla 26.3's on any other server (a client is sent no others), while `known` follows that server's book. The game makes the tables once, when a mod first reads them. **Experimental:** `experimental = ["recipes"]` |
@@ -611,6 +611,7 @@ so the same rustc and `Cargo.lock` give the same file.
| Keystrokes | `keystrokes` | Extras > Keystrokes | `corner`: as above, default `top_left`; `cps`: `true` (default), `false` |
| Zoom | `zoom` | Extras > Zoom | `level`: `2`, `3`, `4` (default), `6`, `8`, `10`; `smooth`: `true` (default), `false`; `sensitivity` (slower turning): `true` (default), `false`. The key is the game's: `key.zoom.zoom` in `horizon-mods.txt`, default `key.keyboard.z` |
| Minimap | `minimap` | Extras > Minimap | `corner`: as above, default `top_right`; `size`: `64`, `96` (default), `128`; `shape`: `square` (default), `round`; `zoom` (blocks per pixel): `0.5`, `1` (default), `2`, `4`; `rotate`: `false` (default), `true`. The game draws the map (`render.set-minimap`) |
| Far View | `far_view` | Graphics > LOD Distance and Far Detail | `distance` (chunks): `64`, `128`, `256` (default), `512`, `1024`; `detail`: `full` (default), `reduced`. The game builds and draws the distant terrain (`render.set-far-terrain`); the player's LOD Distance, when on, wins |
| Recipes | `recipes` | nothing (new) | `give` (a click on the item panel gives the item in creative mode: one, a stack with a right click): `false` (default), `true`. The keys are the game's: `key.recipes.recipe` (default `key.keyboard.r`) and `key.recipes.uses` (default `key.keyboard.u`) in `horizon-mods.txt`. Every item sits in the item panel (`browser`) with a search box (words in the name or id, `@namespace`, `#tag`); R or a click shows an item's recipes, U or a right click its uses, a tab per station, and + fills the grid with a recipe the player knows (`recipes.place`). On servers that are not Horizon it shows the game's own 26.3 recipes; known recipes and + follow the server's recipe book |
## Versions and compatibility
+16
View File
@@ -0,0 +1,16 @@
[package]
name = "far-view"
version = "1.0.0"
edition.workspace = true
license.workspace = true
publish = false
description = "Horizon's official far view: distant terrain past the render distance."
[lib]
crate-type = ["cdylib"]
[dependencies]
horizon-mod-sdk = { path = "../../../crates/horizon-mod-sdk" }
[lints]
workspace = true
+9
View File
@@ -0,0 +1,9 @@
id = "far_view"
name = "Far View"
version = "1.0.0"
description = "See much farther: the world past your render distance drawn as simplified distant terrain, out to 1024 chunks, without loading or simulating more chunks."
authors = ["Horizon"]
api = "0.1"
side = "client"
capabilities = ["render", "ui", "storage"]
experimental = ["render", "ui"]
+89
View File
@@ -0,0 +1,89 @@
//! Horizon's official far view: the world past the render distance drawn as
//! distant terrain (`render.set-far-terrain`; the game builds the tiles on
//! its own workers). Its settings page picks how far it reaches and the far
//! tiles' detail, kept in the mod's storage (`distance`, `detail`). The
//! player's own LOD Distance setting, when on, wins over the mod.
use horizon_mod_sdk::{
Mod, Registration,
render::{self, FarTerrain},
storage,
ui::{self, ButtonWidget, Widget},
};
/// Distances in chunks, as LOD Distance offers them.
const DISTANCES: [u32; 5] = [64, 128, 256, 512, 1024];
/// Settings page buttons.
const DISTANCE_BUTTON: u32 = 1;
const DETAIL_BUTTON: u32 = 2;
/// An index into [`DISTANCES`] and Far Detail's Reduced.
struct FarView {
distance: usize,
reduced: bool,
}
impl FarView {
fn show(&self) {
render::set_far_terrain(Some(FarTerrain {
distance: DISTANCES[self.distance],
reduced: self.reduced,
}));
}
fn page(&self) {
let button = |id, label: String| Widget::Button(ButtonWidget { id, label });
ui::set_settings(&[
button(
DISTANCE_BUTTON,
format!("Distance: {} chunks", DISTANCES[self.distance]),
),
button(
DETAIL_BUTTON,
format!(
"Far detail: {}",
if self.reduced { "Reduced" } else { "Full" }
),
),
]);
}
fn save(&self) {
let _ = storage::set("distance", DISTANCES[self.distance].to_string().as_bytes());
let _ = storage::set("detail", if self.reduced { b"reduced" } else { b"full" });
}
}
fn stored(key: &str) -> Option<String> {
storage::get(key)
.and_then(|v| String::from_utf8(v).ok())
.map(|v| v.trim().to_owned())
}
impl Mod for FarView {
fn init() -> Result<(Self, Registration), String> {
// 256 chunks and full detail, as the docs suggest; an unknown value
// keeps the default.
let far = FarView {
distance: stored("distance")
.and_then(|v| DISTANCES.iter().position(|d| d.to_string() == v))
.unwrap_or(2),
reduced: stored("detail").as_deref() == Some("reduced"),
};
far.show();
far.page();
Ok((far, Registration::new()))
}
fn ui_select(&mut self, id: u32, _row: u32) {
match id {
DISTANCE_BUTTON => self.distance = (self.distance + 1) % DISTANCES.len(),
DETAIL_BUTTON => self.reduced = !self.reduced,
_ => return,
}
self.save();
self.show();
self.page();
}
fn ui_settings_opened(&mut self) {
self.page();
}
}
horizon_mod_sdk::export_mod!(FarView);