From 571066158ede74d0d73c729d8a3745f880cc741e Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 18 Oct 2026 09:54:31 +0200 Subject: [PATCH] Structure templates read without a node cap, as vanilla does Vanilla reads structure templates with NbtAccounter.unlimitedHeap() (TemplateSource.readStructure). Horizon used the default 1,000,000-node cap, so a template past it loaded as empty: YUNG's Better Ocean Monuments' start piece (115x64x126 blocks) never started. Limits::templates keeps the 256 MiB byte cap and drops the node cap, for worldgen and /place. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/commands/place.rs | 8 +----- crates/horizon-world/src/nbt.rs | 25 +++++++++++++++++++ .../horizon-world/src/worldgen/structure.rs | 6 +---- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/crates/horizon-client/src/game/commands/place.rs b/crates/horizon-client/src/game/commands/place.rs index 3e447a7fb..c2ea487ee 100644 --- a/crates/horizon-client/src/game/commands/place.rs +++ b/crates/horizon-client/src/game/commands/place.rs @@ -53,13 +53,7 @@ impl Game<'_> { let Ok(raw) = Compression::Gzip.decode(&bytes, 1 << 28) else { continue; }; - let Ok((named, _)) = nbt::read_named( - &raw, - Limits { - max_bytes: 1 << 28, - ..Limits::default() - }, - ) else { + let Ok((named, _)) = nbt::read_named(&raw, Limits::templates()) else { continue; }; return Some(Arc::new(StructureTemplate::from_nbt( diff --git a/crates/horizon-world/src/nbt.rs b/crates/horizon-world/src/nbt.rs index 2a8b11591..a8bed543a 100644 --- a/crates/horizon-world/src/nbt.rs +++ b/crates/horizon-world/src/nbt.rs @@ -110,6 +110,19 @@ impl Limits { max_depth: 512, } } + + /// Structure templates (`structure/*.nbt`): vanilla reads them with + /// `NbtAccounter.unlimitedHeap()` (TemplateSource.readStructure), and + /// mods ship templates past the default node cap (YUNG's Better Ocean + /// Monuments' start piece, 115x64x126 blocks, holds millions of tags). + /// The byte cap stays as the only guard on the decompressed file. + pub fn templates() -> Self { + Self { + max_bytes: 1 << 28, + max_nodes: usize::MAX, + max_depth: 512, + } + } } #[derive(Clone, Debug, PartialEq, Eq)] @@ -836,6 +849,18 @@ mod tests { assert!(read_network(&bytes, limits).is_err()); } #[test] + fn templates_read_past_the_default_node_cap() { + // A big mod template (YUNG's monument start) holds more tags than the + // default cap; vanilla reads templates with an unlimited accounter. + let root = NamedTag { + name: JavaString::default(), + tag: Tag::compound([("blocks", Tag::List(vec![Tag::Byte(1); 1_000_001]))]), + }; + let bytes = write_named(&root, Limits::templates()).unwrap(); + assert!(read_named(&bytes, Limits::default()).is_err()); + assert_eq!(read_named(&bytes, Limits::templates()).unwrap().0, root); + } + #[test] fn depth_boundary_and_every_truncated_prefix() { let mut tag = Tag::Int(1); for _ in 0..512 { diff --git a/crates/horizon-world/src/worldgen/structure.rs b/crates/horizon-world/src/worldgen/structure.rs index 361b2c1d0..de312c3cd 100644 --- a/crates/horizon-world/src/worldgen/structure.rs +++ b/crates/horizon-world/src/worldgen/structure.rs @@ -342,11 +342,7 @@ impl StructureResources { flate2::read::GzDecoder::new(bytes.as_slice()) .read_to_end(&mut raw) .ok()?; - let limits = Limits { - max_bytes: 1 << 28, - ..Limits::default() - }; - let tag = nbt::read_named(&raw, limits).ok()?.0.tag; + let tag = nbt::read_named(&raw, Limits::templates()).ok()?.0.tag; Some(Arc::new(StructureTemplate::from_nbt( &tag, self.registry,