[PR #7571] A random spread whose separation reaches its spacing is refused #7681

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

📋 Pull Request Information

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

Base: main ← Head: fix/random-spread-validation


📝 Commits (3)

  • c41c59c fix: a random spread whose separation reaches its spacing is refused
  • 454a701 test: a refused random spread and an out of range frequency
  • 4cfe0d1 port_map: the random spread row is a port, and locate keeps its offset

📊 Changes

2 files changed (+79 additions, -8 deletions)

View changed files

📝 crates/horizon-world/src/worldgen/structure/start.rs (+77 -6)
📝 tools/port_map/game2-021.tsv (+2 -2)

📄 Description

A structure set can reach the spread with spacing - separation of 0 or less, and Horizon then puts a start in every grid-corner chunk where vanilla refuses the set.

Vanilla

net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement:

  private static DataResult<RandomSpreadStructurePlacement> validate(RandomSpreadStructurePlacement p);
     0: aload_0
     1: getfield      #1   // Field spacing:I
     4: aload_0
     5: getfield      #7   // Field separation:I
     8: if_icmpgt     20
    11: invokedynamic #10  // InvokeDynamic #0:get:()Ljava/util/function/Supplier;
    16: invokestatic  #14  // DataResult.error
    19: areturn
    20: aload_0
    21: invokestatic  #20  // DataResult.success

with the message Spacing has to be larger than separation, and the codec:

  0: aload_0
  4: aload_0
  5: iconst_0
  6: sipush        4096
 12: ldc           #122 // String spacing
 ...
 27: iconst_0
 28: sipush        4096
 34: ldc           #137 // String separation

So both fields are Codec.intRange(0, 4096) and spacing <= separation is a decode error. AbstractSpreadingStructurePlacement.noiseCodec-side fields: frequency is fconst_0 .. fconst_1 (Codec.floatRange(0.0F, 1.0F)) with default 1.0.

What Horizon got wrong

StructureRegistry::new (crates/horizon-world/src/worldgen/structure/start.rs) read spacing and separation as plain ints and frequency as a plain float. A set with separation >= spacing reached Placement::RandomSpread, where RandomSpreadStructurePlacement.getPotentialStructureChunk's int i = spacing - separation becomes 0 or negative: next_int_bound(0) fails, the unwrap_or(0) fallback makes both spread values 0, and the set places a start in every chunk (gx * spacing, gz * spacing) — a dense grid, where vanilla drops the set. Out of range spacing, separation and frequency decoded too.

Now StructureRegistry::new refuses a random-spread set the way the codec does: spacing and separation must be in 0..=4096, spacing must be larger than separation, and frequency must be a fraction. The rest of the bundle is untouched, so a valid set decodes exactly as before.

Proven

cargo test -p horizon-world --lib with the two new tests:

  • a_random_spread_needs_more_spacing_than_separation: without the checks, spacing 8 / separation 8 decodes (Ok) and the test panics on separation == spacing; so do 4/8, 0/0, 4097/0 and 8/-1. With the fix all five fail to decode, while 8/7 and 4096/0 still decode.
  • a_structure_set_frequency_is_a_fraction: without the check, frequency: 1.5 decodes; with it, 1.5 and -0.25 fail and 1.0 and 0.0 decode.

cargo test -p horizon-world and cargo test -p horizon-port-pack pass with the checks in place (320 lib tests plus the integration suites), so no fixture in the tree carries an out of range set. cargo clippy -q -p horizon-world --lib prints nothing; rustfmt --edition 2024 --check is clean.

Not proven

  • A world that actually ships such a set: vanilla's own structure sets are all in range, so the difference shows only on a data pack that breaks the rule, which the unit tests model.
  • The ledger map-check of the two changed tools/port_map/game2-021.tsv rows: the VM was unreachable when this was written. VM queue, CI will run it.
  • salt, locate_offset and spread_type keep their existing lenient decoding (no error path changed for them); only the three fields above are checked.

🔄 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/7571 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/random-spread-validation` --- ### 📝 Commits (3) - [`c41c59c`](https://github.com/horizon-rust/horizon/commit/c41c59c610e084af162cb01e4bb0c718826fb35f) fix: a random spread whose separation reaches its spacing is refused - [`454a701`](https://github.com/horizon-rust/horizon/commit/454a701a7e7bcbdfb3f9d2e810ba525e00983857) test: a refused random spread and an out of range frequency - [`4cfe0d1`](https://github.com/horizon-rust/horizon/commit/4cfe0d1b4a2909c0f3e9e7cf90a74bd3e7aad584) port_map: the random spread row is a port, and locate keeps its offset ### 📊 Changes **2 files changed** (+79 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/worldgen/structure/start.rs` (+77 -6) 📝 `tools/port_map/game2-021.tsv` (+2 -2) </details> ### 📄 Description A structure set can reach the spread with `spacing - separation` of 0 or less, and Horizon then puts a start in every grid-corner chunk where vanilla refuses the set. ## Vanilla `net.minecraft.world.level.levelgen.structure.placement.RandomSpreadStructurePlacement`: ``` private static DataResult<RandomSpreadStructurePlacement> validate(RandomSpreadStructurePlacement p); 0: aload_0 1: getfield #1 // Field spacing:I 4: aload_0 5: getfield #7 // Field separation:I 8: if_icmpgt 20 11: invokedynamic #10 // InvokeDynamic #0:get:()Ljava/util/function/Supplier; 16: invokestatic #14 // DataResult.error 19: areturn 20: aload_0 21: invokestatic #20 // DataResult.success ``` with the message `Spacing has to be larger than separation`, and the codec: ``` 0: aload_0 4: aload_0 5: iconst_0 6: sipush 4096 12: ldc #122 // String spacing ... 27: iconst_0 28: sipush 4096 34: ldc #137 // String separation ``` So both fields are `Codec.intRange(0, 4096)` and `spacing <= separation` is a decode error. `AbstractSpreadingStructurePlacement.noiseCodec`-side fields: `frequency` is `fconst_0` .. `fconst_1` (`Codec.floatRange(0.0F, 1.0F)`) with default 1.0. ## What Horizon got wrong `StructureRegistry::new` (`crates/horizon-world/src/worldgen/structure/start.rs`) read `spacing` and `separation` as plain ints and `frequency` as a plain float. A set with `separation >= spacing` reached `Placement::RandomSpread`, where `RandomSpreadStructurePlacement.getPotentialStructureChunk`'s `int i = spacing - separation` becomes 0 or negative: `next_int_bound(0)` fails, the `unwrap_or(0)` fallback makes both spread values 0, and the set places a start in every chunk `(gx * spacing, gz * spacing)` — a dense grid, where vanilla drops the set. Out of range spacing, separation and frequency decoded too. Now `StructureRegistry::new` refuses a random-spread set the way the codec does: `spacing` and `separation` must be in `0..=4096`, `spacing` must be larger than `separation`, and `frequency` must be a fraction. The rest of the bundle is untouched, so a valid set decodes exactly as before. ## Proven `cargo test -p horizon-world --lib` with the two new tests: - `a_random_spread_needs_more_spacing_than_separation`: without the checks, `spacing 8 / separation 8` decodes (`Ok`) and the test panics on `separation == spacing`; so do `4/8`, `0/0`, `4097/0` and `8/-1`. With the fix all five fail to decode, while `8/7` and `4096/0` still decode. - `a_structure_set_frequency_is_a_fraction`: without the check, `frequency: 1.5` decodes; with it, `1.5` and `-0.25` fail and `1.0` and `0.0` decode. `cargo test -p horizon-world` and `cargo test -p horizon-port-pack` pass with the checks in place (320 lib tests plus the integration suites), so no fixture in the tree carries an out of range set. `cargo clippy -q -p horizon-world --lib` prints nothing; `rustfmt --edition 2024 --check` is clean. ## Not proven - A world that actually ships such a set: vanilla's own structure sets are all in range, so the difference shows only on a data pack that breaks the rule, which the unit tests model. - The ledger map-check of the two changed `tools/port_map/game2-021.tsv` rows: the VM was unreachable when this was written. VM queue, CI will run it. - `salt`, `locate_offset` and `spread_type` keep their existing lenient decoding (no error path changed for them); only the three fields above are checked. --- <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#7681
No description provided.