Skip to content

#110 Refresh signs on chunk load#142

Merged
tpwalke2 merged 5 commits into
mainfrom
feature/tpwalke2/110-chunk-load
Jul 17, 2026
Merged

#110 Refresh signs on chunk load#142
tpwalke2 merged 5 commits into
mainfrom
feature/tpwalke2/110-chunk-load

Conversation

@tpwalke2

Copy link
Copy Markdown
Owner

What

Detect and remove sign markers whose sign block no longer exists in the world when its chunk reloads — closing the last gap in stale-marker cleanup (issue #110).

Why

The existing removal mixin only fires for an in-game block change on a loaded chunk. A sign that vanishes any other way (external region-file deletion/regen, backup restore, manual NBT edit) leaves its cache entry and BlueMap marker orphaned forever. #109's region-sharded storage was built specifically so this follow-up would have something cheap to query against.

Changes

  • SignChunkKey/SignChunkIndex (new, core/signs, plain Java) — chunk-granularity (16-block) lookup from chunk → tracked sign keys, so reconciliation never scans the full sign cache. Kept separate from the persistence-layer SignRegionKey (512-block region math is a file-layout concern, not a runtime lookup one).
  • SignManager — maintains chunkIndex alongside the existing flat cache (add/remove/reload hooks); exposes getKeysInChunk(...).
  • BlueMapSignMarkersMod — registers ServerChunkEvents.CHUNK_LOAD; on load, checks each tracked sign in that chunk still has a live SignBlockEntity, and removes (via the existing SignManager.remove) any that don't, logged at INFO since it signals an unattended/external change. Deliberately does not skip newly-generated chunks — that's exactly the "region file deleted externally" case this targets.
  • Two plans/docs: the design plan for this feature, and an earlier reviewed-and-rejected refactor options doc for SignManager's in-memory storage (kept flat, per that doc's recommendation).
  • No persistence/version bump — runtime-only change.

Testing

  • ./gradlew test — new SignChunkKeyTest (12 cases) and SignChunkIndexTest cover chunk-boundary math and index add/remove/isolation/clear behavior.
  • ./gradlew build — full build passes.
  • Manual (./gradlew runServer, not automatable — touches live Minecraft/Fabric types):
    a. Place a sign, restart the server, confirm the marker is unchanged and no spurious removal is logged.
    b. Place a sign, stop the server, delete that sign's chunk region file (forces a regen) or remove the block via NBT editor, restart, walk into the chunk — confirm the INFO log line appears and the stale marker disappears from BlueMap.
    c. Repeat with signs in two dimensions at the same x/z to confirm dimension isolation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR closes the stale-marker cleanup gap by reconciling tracked signs when their chunk loads: if a cached sign key no longer corresponds to a live SignBlockEntity in that chunk (e.g., chunk regen / external edits), the marker is removed using existing SignManager.remove(...) logic.

Changes:

  • Add a chunk-granularity secondary index (SignChunkKey / SignChunkIndex) to map chunk → tracked SignEntryKeys for O(1) lookup.
  • Update SignManager to maintain the chunk index alongside the existing flat signCache, and expose getKeysInChunk(...).
  • Register ServerChunkEvents.CHUNK_LOAD to detect and remove stale markers on chunk load; add unit tests for the new index/key utilities.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/com/tpwalke2/bluemapsignmarkers/core/signs/SignChunkKey.java Defines chunk key computation (16-block chunk math) for indexing signs by chunk.
src/main/java/com/tpwalke2/bluemapsignmarkers/core/signs/SignChunkIndex.java Implements the chunk→keys index used to avoid scanning the full sign cache on chunk load.
src/main/java/com/tpwalke2/bluemapsignmarkers/core/signs/SignManager.java Maintains the new chunk index during add/remove/reload and exposes chunk-key querying.
src/main/java/com/tpwalke2/bluemapsignmarkers/BlueMapSignMarkersMod.java Hooks chunk-load event and removes tracked entries that no longer have a sign block entity.
src/test/java/com/tpwalke2/bluemapsignmarkers/core/signs/SignChunkKeyTest.java Unit tests for chunk-key math (origin, boundaries, negative coords, dimension isolation).
src/test/java/com/tpwalke2/bluemapsignmarkers/core/signs/SignChunkIndexTest.java Unit tests for index add/remove/query/clear behavior across chunks and dimensions.
plans/sign-storage-refactor-options.md Documents why in-memory sign storage stays flat and evaluates alternative layouts.
plans/chunk-load-sign-reconciliation-plan.md Design plan documenting the chunk-load reconciliation approach and performance constraints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread plans/sign-storage-refactor-options.md Outdated
Comment thread plans/sign-storage-refactor-options.md Outdated
Comment thread src/test/java/com/tpwalke2/bluemapsignmarkers/core/signs/SignChunkIndexTest.java Outdated
@tpwalke2
tpwalke2 merged commit d7bdcfe into main Jul 17, 2026
1 check passed
@tpwalke2
tpwalke2 deleted the feature/tpwalke2/110-chunk-load branch July 17, 2026 21:46
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.

2 participants