[PR #7605] A jigsaw structure's size and reach stay inside vanilla's bounds #7710

Open
opened 2026-11-03 07:22:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7605
Author: @MSedgeMC
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/jigsaw-range-bounds


📝 Commits (2)

  • dba1612 fix: a jigsaw structure's size and reach stay inside vanilla's bounds
  • 49bb317 test: the depths and reaches vanilla refuses on a jigsaw structure

📊 Changes

2 files changed (+125 additions, -24 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/structure/start.rs (+53 -24)
➕ crates/horizon-world/tests/jigsaw_bounds.rs (+72 -0)

📄 Description

StructureRegistry::new (crates/horizon-world/src/worldgen/structure/start.rs) read a minecraft:jigsaw structure's size and max_distance_from_center with no bound. Vanilla's codec bounds both, and the bounds decide how far a structure may spread: a pack carrying others never reaches a world in vanilla, but did here.

Vanilla

JigsawStructure.CODEC:

Codec.intRange(0, 20).fieldOf("size").forGetter(j -> j.maxDepth),
...
JigsawStructure.MaxDistance.CODEC.fieldOf("max_distance_from_center")

JigsawStructure.MaxDistance:

private static final Codec<Integer> HORIZONTAL_VALUE_CODEC = Codec.intRange(1, 128);
private static final Codec<MaxDistance> FULL_CODEC = RecordCodecBuilder.create(i -> i.group(
      HORIZONTAL_VALUE_CODEC.fieldOf("horizontal"),
      ExtraCodecs.intRange(1, DimensionType.Y_SIZE).optionalFieldOf("vertical", DimensionType.Y_SIZE)
   ).apply(i, MaxDistance::new));
public static final Codec<MaxDistance> CODEC =
   Codec.either(FULL_CODEC, HORIZONTAL_VALUE_CODEC).xmap(...);   // one number sets both

DimensionType.Y_SIZE is 4064, the default the vertical already took here. So size is 0 to 20, the horizontal reach 1 to 128 and the vertical 1 to 4064, in either the one-number or the two-field form.

The reach is not cosmetic: JigsawPlacement.addPieces builds the layout's free box from it —

new AABB(
   centerX - maxDistanceFromCenter.horizontal(),
   Math.max(centerY - maxDistanceFromCenter.vertical(), minY + dimensionPadding.bottom()), ...
   centerX + maxDistanceFromCenter.horizontal() + 1, ...

— and every child piece must fit in that box (childrenFree), so a horizontal of 129 or 0 is a structure vanilla refuses to register and Horizon laid out to a different shape.

What Horizon got wrong

max_depth: v["size"].as_i64().unwrap_or(0) as i32,
max_distance: pair(v.get("max_distance_from_center"), "horizontal", "vertical", 80, 4064),

pair returns the numbers as written: size: 200 became a depth of 200 (an exponential layout the generator then walked), max_distance_from_center: 0 a reach of 0 (children squeezed into the start's own box), 129 a reach past MAX_TOTAL_STRUCTURE_RANGE.

Now jigsaw_depth_and_reach keeps the same defaults (a structure without the fields still decodes with depth 0 and an 80 by 80 reach, as before) and jigsaw_reach_in_range bounds them; a structure outside them decodes to StructureKind::Unsupported, which is how this file already handles a data pack entry Horizon cannot use (horizon:formations), so one bad structure costs that structure and not the world's whole structure registry.

Proven

cargo test -p horizon-world --test jigsaw_bounds, both through StructureRegistry::new:

  • a_jigsaw_structures_size_stops_at_twenty: without the bound, "size": 21 decodes as a placing jigsaw — the test panics on that value. With the fix it is unsupported, and so are 200 and -1; 0, 20 and an absent field still place.
  • a_jigsaw_structures_reach_stays_inside_vanillas: without the bound, "max_distance_from_center": 0 decodes as a placing jigsaw — the test panics on it. With the fix it is unsupported, and so are 129, -8, {"horizontal": 0, "vertical": 100}, {"horizontal": 64, "vertical": 0} and {"horizontal": 128, "vertical": 4065}; 1, 128, {"horizontal": 1, "vertical": 1}, {"horizontal": 128, "vertical": 4064} and an absent field still place.

cargo test -q -p horizon-world passes (35 test binaries, lib 318 passed / 2 ignored); cargo clippy -q -p horizon-world --lib prints nothing; rustfmt --edition 2024 --check is clean.

Not proven

  • JigsawStructure.CODEC is also .validate(JigsawStructure::verifyRange): the horizontal plus 12 when the terrain adaptation is not none must not pass 128. That is left alone, because a structure that trips it is one Horizon's prepared bundle could carry today and dropping it is a bigger change than this PR's.
  • The one-number form of a malformed max_distance_from_center (a string, say) still falls back to the 80 default rather than failing; vanilla would refuse the structure. Kept as it was, since it is a leniency this file already had for absent fields.
  • No data pack in this repository ships a structure outside these ranges, so the reproduction is the two tests; vanilla's own structures (villages at 80, bastions at 116, ancient cities and outposts at depth 7 and below) all stay inside the bounds and still decode.
  • No port_map row changed: the verdict map has no row for a structure's codec bounds.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7605 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/jigsaw-range-bounds` --- ### 📝 Commits (2) - [`dba1612`](https://github.com/horizon-rust/horizon/commit/dba1612baf521c016842f14cdfc4d692df1f6296) fix: a jigsaw structure's size and reach stay inside vanilla's bounds - [`49bb317`](https://github.com/horizon-rust/horizon/commit/49bb31793193e922634b97784f6f238bae147155) test: the depths and reaches vanilla refuses on a jigsaw structure ### 📊 Changes **2 files changed** (+125 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/structure/start.rs` (+53 -24) ➕ `crates/horizon-world/tests/jigsaw_bounds.rs` (+72 -0) </details> ### 📄 Description `StructureRegistry::new` (`crates/horizon-world/src/worldgen/structure/start.rs`) read a `minecraft:jigsaw` structure's `size` and `max_distance_from_center` with no bound. Vanilla's codec bounds both, and the bounds decide how far a structure may spread: a pack carrying others never reaches a world in vanilla, but did here. ## Vanilla `JigsawStructure.CODEC`: ``` Codec.intRange(0, 20).fieldOf("size").forGetter(j -> j.maxDepth), ... JigsawStructure.MaxDistance.CODEC.fieldOf("max_distance_from_center") ``` `JigsawStructure.MaxDistance`: ```java private static final Codec<Integer> HORIZONTAL_VALUE_CODEC = Codec.intRange(1, 128); private static final Codec<MaxDistance> FULL_CODEC = RecordCodecBuilder.create(i -> i.group( HORIZONTAL_VALUE_CODEC.fieldOf("horizontal"), ExtraCodecs.intRange(1, DimensionType.Y_SIZE).optionalFieldOf("vertical", DimensionType.Y_SIZE) ).apply(i, MaxDistance::new)); public static final Codec<MaxDistance> CODEC = Codec.either(FULL_CODEC, HORIZONTAL_VALUE_CODEC).xmap(...); // one number sets both ``` `DimensionType.Y_SIZE` is 4064, the default the vertical already took here. So `size` is 0 to 20, the horizontal reach 1 to 128 and the vertical 1 to 4064, in either the one-number or the two-field form. The reach is not cosmetic: `JigsawPlacement.addPieces` builds the layout's free box from it — ```java new AABB( centerX - maxDistanceFromCenter.horizontal(), Math.max(centerY - maxDistanceFromCenter.vertical(), minY + dimensionPadding.bottom()), ... centerX + maxDistanceFromCenter.horizontal() + 1, ... ``` — and every child piece must fit in that box (`childrenFree`), so a horizontal of 129 or 0 is a structure vanilla refuses to register and Horizon laid out to a different shape. ## What Horizon got wrong ```rust max_depth: v["size"].as_i64().unwrap_or(0) as i32, max_distance: pair(v.get("max_distance_from_center"), "horizontal", "vertical", 80, 4064), ``` `pair` returns the numbers as written: `size: 200` became a depth of 200 (an exponential layout the generator then walked), `max_distance_from_center: 0` a reach of 0 (children squeezed into the start's own box), `129` a reach past `MAX_TOTAL_STRUCTURE_RANGE`. Now `jigsaw_depth_and_reach` keeps the same defaults (a structure without the fields still decodes with depth 0 and an 80 by 80 reach, as before) and `jigsaw_reach_in_range` bounds them; a structure outside them decodes to `StructureKind::Unsupported`, which is how this file already handles a data pack entry Horizon cannot use (`horizon:formations`), so one bad structure costs that structure and not the world's whole structure registry. ## Proven `cargo test -p horizon-world --test jigsaw_bounds`, both through `StructureRegistry::new`: - `a_jigsaw_structures_size_stops_at_twenty`: without the bound, `"size": 21` decodes as a placing jigsaw — the test panics on that value. With the fix it is unsupported, and so are `200` and `-1`; `0`, `20` and an absent field still place. - `a_jigsaw_structures_reach_stays_inside_vanillas`: without the bound, `"max_distance_from_center": 0` decodes as a placing jigsaw — the test panics on it. With the fix it is unsupported, and so are `129`, `-8`, `{"horizontal": 0, "vertical": 100}`, `{"horizontal": 64, "vertical": 0}` and `{"horizontal": 128, "vertical": 4065}`; `1`, `128`, `{"horizontal": 1, "vertical": 1}`, `{"horizontal": 128, "vertical": 4064}` and an absent field still place. `cargo test -q -p horizon-world` passes (35 test binaries, lib 318 passed / 2 ignored); `cargo clippy -q -p horizon-world --lib` prints nothing; `rustfmt --edition 2024 --check` is clean. ## Not proven - `JigsawStructure.CODEC` is also `.validate(JigsawStructure::verifyRange)`: the horizontal plus 12 when the terrain adaptation is not `none` must not pass 128. That is left alone, because a structure that trips it is one Horizon's prepared bundle could carry today and dropping it is a bigger change than this PR's. - The one-number form of a malformed `max_distance_from_center` (a string, say) still falls back to the 80 default rather than failing; vanilla would refuse the structure. Kept as it was, since it is a leniency this file already had for absent fields. - No data pack in this repository ships a structure outside these ranges, so the reproduction is the two tests; vanilla's own structures (villages at 80, bastions at 116, ancient cities and outposts at depth 7 and below) all stay inside the bounds and still decode. - No `port_map` row changed: the verdict map has no row for a structure's codec bounds. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7710
No description provided.