Terrain Diffusion Horizons

An LOD generation accelerator for Distant Horizons, powered by Terrain Diffusion.

Terrain Diffusion Horizons (TDH)

https://github.com/xandergos/terrain-diffusion-mc/issues/260

An LOD generation accelerator for Distant Horizons, powered by Terrain Diffusion.

Uses Terrain Diffusion's AI terrain model as the LOD data source for Distant Horizons. Distant terrain no longer depends on real chunk generation; it is queried and translated directly from the terrain model.

Voxy is not supported: the existing 1.20.1 build is unstable in my experience, and its ARR license is a hassle; accelerating Voxy would mean I'd have to write a 1.20.1, self-generating Voxy—and even a partial implementation means digesting the existing forks—so the workload is not realistic. A switch to Voxy is unlikely for versions after 1.20.1 as well.

Performance

Measured (Ryzen 5 5600X + NVIDIA CMP 30HX, vanilla render distance 5 + DH render distance 512):

TD world scale 2 + DH quality 4 / load 4:

  • Full LOD generation in about 30 minutes
  • About 500 chunks/s, sustaining that speed about 87% of the time

TD world scale 6: about 700 chunks/s steady state, about 1500 chunks/s peak.

When a world is freshly created, DH needs a warm-up: a large batch of chunks is enqueued and preprocessed (no LOD will be generated during this phase), then comes a brief low-speed phase, and full speed after that.

Features

TDH (this mod) generates terrain first by default, which is the fast part; structures and features generate asynchronously at the same time — once a LOD block finishes generating, it gets updated, and only then do structures and features appear. Feature generation is very, very slow compared to terrain; switching to sync mode would let it drag the whole pipeline down badly.

Much of the terrain layer is guesswork — that's just how it is, so mismatches with vanilla are normal.

Once the feature layer is done, a chunk is "basically" the same as vanilla, though deviations remain. Structures can be placed at the same positions as actual generation, essentially a 1:1 block-for-block match; features (flowers, grass, trees) are the hard part — block-for-block parity would basically require actually generating that chunk. Vanilla DH presumably (?) does it that way too, but that is obviously far too slow — so slow the whole point of writing TDH would be gone. The obvious downside: LOD shapes differ from the actually generated ones; plus a lesser issue — the features on the "real chunk" side and the "LOD chunk" side don't match, leaving a clearly visible seam between them; that one should be fixable.

No mixins, no Access Transformers; DH via its public API, TD via a reflection bridge (resolved once at init). The reflection will be dropped once terrain-diffusion-plus (TDP) has been ported to every version.

Dependencies

Since 1.1.0 TDH ships a multi-version matrix: 1.20.1 / 1.21.1 / 1.21.11, with fabric + forge on 1.20.1 and fabric + neoforge on 1.21.x — six nodes in total. Distant Horizons 3.3.3 is shared across all nodes. On the Terrain Diffusion side, LMaxRouterCN's terrain-diffusion-plus fork (upstream: derekvawdrey/terrain-diffusion-plus) is required; its source lives on the LMax-master branch (covering 1.20.1 / 1.21.1 / 1.21.11) and no jars are published yet — build it from source. Upstream Terrain Diffusion also runs, in degraded mode (no river water surface / biome tint). Tested setup: 1.20.1 Forge.

Node Minecraft Loader Distant Horizons Terrain Diffusion
fabric 1.20.1 1.20.1 Fabric Loader 0.19.2 3.3.3 2.3.0
forge 1.20.1 1.20.1 Forge 47.2.30 3.3.3 2.3.0
fabric 1.21.1 1.21.1 Fabric Loader 0.19.2 3.3.3 2.3.0
neoforge 1.21.1 1.21.1 NeoForge 21.1.213 3.3.3 2.3.0
fabric 1.21.11 1.21.11 Fabric Loader 0.19.2 3.3.3 2.3.0
neoforge 1.21.11 1.21.11 NeoForge 21.11.48 3.3.3 2.3.0

TDH is developed and tested against DH 3.3.3; other versions are untested.

Installation

  1. Forge 47.2.30 (1.20.1)
  2. Drop three jars into mods/: Distant Horizons, Terrain Diffusion, TDH
  3. Create a world the Terrain Diffusion way; on world load TDH takes over distant generation automatically (the log line TDH 生成器注册完成 marks it); non-TD worlds fall back to DH's native generation
  4. Make sure DH's Distant Generation is enabled

Configuration

Config file: config/terrain-diffusion-mc/terrain-diffusion-horizons.toml (generated on first run, with comments explaining each key)

Key Default Description
general.enabled true Master switch; false = TDH off, DH generates distant terrain on its own
terrain.surfaceBlock minecraft:stone Fallback surface block (used when biome surface is off or resolution fails)
terrain.fillerBiome minecraft:plains Fallback biome (used when biome surface is off; affects distant grass color)
terrain.useBiomeSurface true Biome-driven surface blocks, as in vanilla; false = off (saves memory, fallback block everywhere; flower speckle turns off too)
terrain.surfaceBlockOverrides {} Per-biome surface block overrides (unlisted biomes use the default)
vegetation.coloring true Flower speckle: distant grassland gets flower colors at the biome's natural flower density (color only, height unchanged)
vegetation.grassColoring false Grass speckle (off by default: distant tall grass and grass blocks already share one color)
structure.enabled true Distant structures master switch
structure.async true Async: terrain appears first, structures fill in when done; false = wait for structures
structure.pad_chunks 16 Scan padding (chunks): keeps large structures straddling borders from being clipped
structure.surface_blend_depth 3 Buried-structure recolor depth, only for structures that reshape the surface (roads, farmland); negative = off
features.enabled true Distant vegetation master switch (flower speckle above has its own switch)
features.async true Same as structure.async
features.decoration_steps ["vegetal_decoration", "top_layer_modification"] Generation steps to run (valid values in the config file comments, case-insensitive); empty array disables vegetation; vegetation renders only at the nearest detail level (farther levels span too much ground for single-block plants)
features.decoration_prefetch true Height fix: fixes grid-shaped artifacts and misplaced trees at distance; false = off
features.decoration_water_background true Water check: fixes trees and flowers floating on lakes; needs the height fix on
[general]
enabled = true

[terrain]
surfaceBlock = "minecraft:stone"
fillerBiome = "minecraft:plains"
useBiomeSurface = true

# sparse biome-key to surface-block overrides (optional):
# [terrain.surfaceBlockOverrides]
# "minecraft:plains" = "minecraft:snow_block"

[vegetation]
coloring = true
grassColoring = false

[structure]
enabled = true
async = true
pad_chunks = 16
surface_blend_depth = 3

[features]
enabled = true
async = true
decoration_steps = ["vegetal_decoration", "top_layer_modification"]
decoration_prefetch = true
decoration_water_background = true

Memory note: useBiomeSurface=true is about 520MB, false about 150MB (measured). If new keys added by an upgrade do not show up in the file, delete the toml and it regenerates. Config changes take effect after restarting the game.

Building from Source

gradlew buildAndCollect

Artifacts land in the root build/libs/ (one dev jar per node). JDK 25 runs Gradle; node compilation needs JDK 17 and 21. Toolchain resolution trusts org.gradle.java.installations.paths (comma-separated, forward slashes) — spell them out in %USERPROFILE%\.gradle\gradle.properties. Keep 32-bit JDKs out of that list: the pipeline's decompile step pins -Xmx4G, and a 32-bit JVM dies there with a deeply misleading The specified size exceeds the maximum representable size — that is the address-space ceiling, not a typo in the flag.

Gradle's own JVM follows JAVA_HOME — the paths list does not govern it: the daemon starts on whatever JAVA_HOME points to. If that is a JDK below 25 (17 is the common case), the build dies in the settings.gradle.kts plugin-resolution stage — the stonecutter plugin needs JVM 25+ and fails to resolve on a lower daemon; listing 25 in paths does not save this step, that list only feeds the node-compilation toolchains. set JAVA_HOME=<path to JDK 25> before building, or pin it on the command line with -Porg.gradle.java.home=<path> — the latter overrides every other property source.

Whatever version the paths list omits, foojay will try to download online: settings.gradle.kts carries the org.gradle.toolchains.foojay-resolver-convention; when a toolchain gap appears it defaults to fetching one from api.foojay.io. On networks that cannot reach foojay, that is a stall until timeout — the Resolve stage goes silent for a long stretch and ends in connection failures. List all three (17 / 21 / 25) in paths and no gap appears, so foojay never fires.

Networks where maven.neoforged.net is unreachable

Symptoms: Could not resolve net.neoforged:..., or an NFRT process dying on connection resets to that host. Three-part kit:

  1. forgecdn repository (already built in, zero action): build.forge.gradle.kts / build.neoforge.gradle.kts declare NeoForged's official file CDN neoforged.forgecdn.net/releases (same source as the official releases repo); net.neoforged / net.minecraftforge artifacts resolve through it.
  2. init script (covers the umbrella pom no public mirror carries): net.neoforged:minecraft-dependencies is only published on the dead host; the in-repo maven-mirror/ holds its pom/module (1.20.1 / 1.21.1 / 1.21.11). Enable with:
set TD_MIRROR=1
gradlew -I scripts/td-mirror.init.gradle buildAndCollect

The script strips each project's dead repos and front-inserts maven-mirror/. For an always-on setup, copy it into <GRADLE_USER_HOME>/init.d/. 3. NFRT cache pre-fill (forge node only): createMinecraftArtifacts runs as a separate NeoForm Runtime process that fetches a few build inputs itself, outside Gradle repositories; a cold cache stalls on maven.neoforged.net. Drop these five files into <GRADLE_USER_HOME>\caches\neoformruntime\artifacts (URL = https://neoforged.forgecdn.net/releases/ + the relative path below; SHA256 verified against the official repo):

Artifact Path under artifacts Size
mcp_config de/oceanlabs/mcp/mcp_config/1.20.1-20230612.114412/mcp_config-1.20.1-20230612.114412.zip 1.7 MB
mergetool net/minecraftforge/mergetool/1.1.7/mergetool-1.1.7-api.jar 2.6 KB
ForgeAutoRenamingTool net/minecraftforge/ForgeAutoRenamingTool/1.0.2/ForgeAutoRenamingTool-1.0.2-all.jar 0.4 MB
forgeflower net/minecraftforge/forgeflower/2.0.629.0/forgeflower-2.0.629.0.jar 0.9 MB
annotations org/jetbrains/annotations/24.0.1/annotations-24.0.1.jar 30 KB

The 1.21.x neoforge nodes need no pre-fill: their tool artifacts resolve at the Gradle layer (covered by item 1) and get injected into NFRT. Mojang piston data and Forge maven downloads remain directly reachable on such networks.

With a global proxy, ignore all of the above.

How It Works

Architecture: a pure bridge layer

No mixins, no Access Transformers. The DH side goes through its public API (DhApi.worldGenOverrides); the TD side is a reflection bridge (TdHostBridge) — init-time Class.forName capability probing plus one-time MethodHandle resolution, zero reflective lookups at runtime, silent degradation when TD is absent. 28 classes across seven packages, orthogonal responsibilities:

Package Responsibility
root shared bootstrap (Bootstrap) + seeded TOML config (TdConfig)
dh DH registration and lifecycle (DhCompat), LOD translation core (TdDhWorldGenerator), coordinate translator (TdLodTranslator), biome surface/flower tables (TdSurfaceBlockMap / TdFlowerMap), lane refresh hook (DhRefreshHook)
dh.lane async lane skeleton: pure-function core + scheduling shell + payloads and cache keys
dh.structure structure spread (vanilla same-seed math), silent-world assembly, biome decoration
platform loader shells (FabricMod / ForgeMod): entry + config-dir injection into the shared Bootstrap
td TD reflection bridge (TdHostBridge) + tile POJOs (TdRiverTile / TdHeightmapTile)

Registration chain: the mod constructor hooks DhApiLevelLoadEvent, then the world-load callback runs a triple guard (overworld / TD world active / seed obtainable) and calls registerWorldGeneratorOverride. There is no unregister API on world unload; the generator clears its own references in close(). Overworld only (hard boundary).

Data flow

DH generation queue → generateLod(posX, posZ, dl0) → runAsync shell onto a DH pool thread → TD getRiverTerrainData(block rectangle, withBiomes) pulls a whole 64×64 block at once (four arrays: elevation in meters / waterMask water intensity 0-255 / waterSurface water level in meters / biomeIndexes biome indices) plus structure/decoration lane column segments (terrain publishes first, lanes refresh in when done) → a double loop translates each column into several DhApiTerrainDataPoints (bed/surface, folded structure, water, flower cap, air; seamlessly tiled per column) → setApiDataPointColumn → resultConsumer called exactly once.

API dl0 only (one block per column, 64×64 per data source, i.e. core-level dl6); coarser levels come from DH's native DOWN_SAMPLED downsampling.

Coordinate semantics (three settled points)

Get any of these wrong and the render shifts wholesale or erupts into sky pillars:

  1. TD's HeightConverter.convertToMinecraftHeight returns the y of the first air block (density-function math, FeaturePlacer posture, mixin comments, DH half-open intervals, measured one block high—five independent confirmations). The early +1 was double compensation and has been removed.
  2. DH's storage layer y is 12-bit unsigned (0-4095), negatives wrap around: an overworld minY=-64 gets stored as 4032; segment bottom (4032) above segment top (~70) inverts the geometry—the main render path draws sky pillars from y70 to y4032, and the neighbor path spams 10MB/min of Negative y size errors.
  3. DH's y is really an offset from the world bottom (relative y): store absolute coordinates and the whole terrain sits 64 blocks short (= |minY|).

Conclusion: all y values are normalized to relative coordinates, yRel = yAbs − minY; dataBottom = 0 is the world floor.

Water determination (dual channel)

  • Rivers (fluvial): waterMask encodes water intensity 0-255; values below 8 mark sub-block anti-aliasing edge cells (skipped on TD's chunk side too); waterSurface is NaN when dry (decoded from a Short.MIN_VALUE sentinel). Pool condition = intensity ≥8 AND finite water level AND level above terrain—all three required.
  • Oceans: negative elevation in a TD cell is seabed depth; the water segment fills [seabed, sea level y63]. Fluvial and ocean are mutually exclusive on the TD side; the code defensively takes the higher surface.
  • Ice caps: frozen river/ocean biomes get their water segment replaced with ice.

Biome-driven surface

TD's chunk-side surface block = vanilla SurfaceSystem.buildSurface × the TD BiomeSource, and the BiomeSource reads the very same tile biomeIndexes the LOD query uses—data and rules share one source. TdSurfaceBlockMap prunes the LOD-reachable branches of the vanilla overworld surface rules into a 65-biome table (primary surface / underwater top / ice cap, three fields), eliminating systematic bias; what remains is only the inherent blur of 64-block downsampling.

Fidelity boundaries (deliberate trade-offs): noise patches smaller than a sample cell (coarse dirt, granite blobs, badlands banding) are not reproduced; approximations such as old_growth podzol and snow-block snow cover are documented in the table's comments.

Riverbed material is tiered by water intensity with deterministic spatial hashing (key = world block coordinates, stable across data sources; ratios are empirical):

  • Weak water (intensity <72): sand 62.5% / gravel 37.5%
  • Strong water (≥72): gravel 85.2% / clay 14.8%

Vegetation (L1 flower speckle)

With vegetation.coloring enabled, dry column tops get deterministic-hash color swaps by biome flower-pool density—hit columns take the flower color on top while the column height stays unchanged (flowers/grass are cross blocks; only the top-face tint changes). The same column never flickers. Columns covered by the L4 decoration lane hand over to real decoration (the cap yields automatically); the rest keep this layer as visual fallback. Statistical approximation, not same-source with chunk generation.

Structure & feature lanes

Two lanes (structure / features): pure-function compute cores behind a scheduling shell that picks sync or async (default async—terrain LOD publishes first, and a refresh hook asks DH to re-pull each region once the lane finishes; sync mode renders once, no flicker).

  • Structures: same-seed placement math as vanilla (padded scan guards cross-region clipping); hits run the real structure generator inside a silent world (in-memory ProtoChunk, zero side effects), folded into column segments; near-surface segments recolor the top block (surface_blend_depth).
  • Decoration: replays vanilla's per-chunk biome decoration loop (same setDecorationSeed deterministic stream), placing trees, flowers and snow through a decoration view (three-state background: bed / water / air, writes take priority); runs at dl0 only.

Performance design

  • Lock-free caching: biome styles in a ConcurrentHashMap; concurrent duplicate construction is harmless, so no locks
  • Wrappers (block/biome objects) are lazily fetched once on first use, then served from cache
  • Per-column ArrayList(3) preallocation (a capacity hint, not a segment cap; with lane column chains merged in, a column can carry a dozen-plus segments)
  • Constants like sea level y63 hoisted out of loops
  • TD pulls the whole block rectangle per query, avoiding per-column round trips

License

MPL-2.0

Terrain Diffusion Horizons Team

profile avatar
  • 5
    Projects
  • 12.8K
    Downloads

More from LMaxRouterCNView all

  • VS2 Sentinel Guard Fix project image

    VS2 Sentinel Guard Fix

    Fixes the Valkyrien Skies 2 sentinel-coordinate leak that freezes servers running synchronous BiomeSource mods (e.g. Terrain Diffusion)

    • 12
    • December 4, 2026
  • TACZ: Sustained Fire project image

    TACZ: Sustained Fire

    An addon for TACZ: 5 gun enchantments, a placeable 36-slot ammo crate, and an optional Sophisticated Backpacks integration.

    • 26
    • December 4, 2026
  • LogFilter project image

    LogFilter

    A lightweight log filtering mod designed to reduce spam in the console and log files, allowing developers and players to focus on critical errors and save disk space.

    • 216
    • November 4, 2026
  • VS Addition continue project image

    VS Addition continue

    vsadd's continued update version

    • 12.5K
    • December 18, 2025
  • VS2 Sentinel Guard Fix project image

    VS2 Sentinel Guard Fix

    Fixes the Valkyrien Skies 2 sentinel-coordinate leak that freezes servers running synchronous BiomeSource mods (e.g. Terrain Diffusion)

    • 12
    • December 4, 2026
  • TACZ: Sustained Fire project image

    TACZ: Sustained Fire

    An addon for TACZ: 5 gun enchantments, a placeable 36-slot ammo crate, and an optional Sophisticated Backpacks integration.

    • 26
    • December 4, 2026
  • LogFilter project image

    LogFilter

    A lightweight log filtering mod designed to reduce spam in the console and log files, allowing developers and players to focus on critical errors and save disk space.

    • 216
    • November 4, 2026
  • VS Addition continue project image

    VS Addition continue

    vsadd's continued update version

    • 12.5K
    • December 18, 2025