Skip to content

Walk structure regions in one place: structure::scan - #22

Merged
byRandom merged 1 commit into
mainfrom
refactor/structure-scan
Nov 13, 2026
Merged

byRandom merged 1 commit into
mainfrom
refactor/structure-scan

Conversation

@byRandom

Copy link
Copy Markdown
Owner

The first step of the architecture review: the map, the seed finder and the structures example each walked a set's regions on their own. Now there is one scan module, so they cannot disagree on which chunks they look at, and mineshafts (0.6) need changes in only one place.

What changes

  • New mc_core::structure::scan:
    • candidates(set, seed, ChunkRect): the chunks where a set tries to place a structure. This only runs the placement checks, so it is cheap.
    • StructureGenerator::hit(&SetFilter, candidate): whether the structure generates and passes the filter. A SetFilter can keep only some structures of the set (for example bastions) or only end cities with a ship.
    • StructureGenerator::hits(&SetFilter, rect): both steps for every candidate in an area.
  • The finder keeps its two passes: a cheap count first, then validation nearest first. StructureFilter now holds a SetFilter (select) instead of separate set, only and ship fields.
  • The app's markers() is now a map over hits().
  • GLOSSARY.md names the terms used here: candidate, attempt, hit, chunk rectangle, layer.

No behaviour change, so this needs no release.

Tests

  • New tests/structure_scan.rs compares the scan with a separate check of every chunk in the rectangle. It covers every random-spread set, 4 seeds, and rectangles that cross region edges, the origin and the world border. It also checks that hits are exactly the candidates that generate, including filtering by name prefix.
  • The finder tests keep their own region loops as an independent reference.
  • Mutation testing:
    • Breaking the region bounds makes the new test fail.
    • Treating one-chunk regions like any other region gives the same result. This equivalent mutation is recorded in docs/PARITY.md.

Generated by Claude Code

The map, the seed finder and the structures example each had their own
copy of the region loop (candidate chunk per region, placement checks,
locate position) and of the filters on top (bastions vs fortresses, end
cities with a ship), with the one-chunk-region case handled differently
in each. They now share mc_core::structure::scan:

- candidates(set, seed, ChunkRect): the chunks where a set tries to place
  a structure (placement only, cheap);
- StructureGenerator::hit(&SetFilter, candidate): whether it generates and
  passes the filter, with the end city ship;
- StructureGenerator::hits(&SetFilter, rect): both, for an area.

StructureFilter now holds a SetFilter instead of its own set, only and
ship fields. A new test compares the scan with a check of every chunk on
its own, for every random-spread set, on rectangles that straddle region
edges, the origin and the world border. GLOSSARY.md names the terms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SenGxDDRwLejx8nir8GXKG

Copy link
Copy Markdown
Owner Author

CI did not run on this PR: all three jobs (Test, JDK parity, Game parity) stopped before their first step with "The job was not started because your account is locked due to a billing issue." None of the PR's code ran in CI. Locally, cargo fmt --all --check, cargo clippy --all-targets -- -D warnings and cargo test all pass. Once the billing lock is lifted, re-run the workflow.


Generated by Claude Code

@byRandom
byRandom merged commit 781b30f into main Nov 13, 2026
3 of 6 checks passed
@byRandom
byRandom deleted the refactor/structure-scan branch November 15, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant