Skip to content

Fix wall lights/torches dropped when pasting a blueprint - #44

Open
IonatanPerez wants to merge 1 commit into
fluffy-mods:1.5from
IonatanPerez:fix/wall-attachment-placement-order
Open

Fix wall lights/torches dropped when pasting a blueprint#44
IonatanPerez wants to merge 1 commit into
fluffy-mods:1.5from
IonatanPerez:fix/wall-attachment-placement-order

Conversation

@IonatanPerez

Copy link
Copy Markdown

Problem

When pasting a saved blueprint, wall-mounted lights and torches are sometimes missing from the built copy — and which ones go missing depends on their orientation/position, so a symmetric room comes out lopsided. The blueprint saves the lamps correctly; they are dropped at paste time.

Root cause

Designator_Blueprint.DesignateSingleCell iterates the blueprint contents in a single pass, designating each item only if CanPlace(origin) succeeds at that moment:

foreach (BuildableInfo item in Blueprint.AvailableContents) {
    var placementReport = item.CanPlace(origin);
    if (!planningMode && placementReport == PlacementReport.CanPlace) {
        item.Designate(origin);
    }
}

Wall lamps / torches are wall attachments (isAttachment, PlaceWorker_AttachedToWall): they occupy a floor cell next to a wall and require the supporting wall to already exist to be placeable. Because everything is placed in one unordered pass, any attachment stored before its supporting wall fails CanPlace (the wall's blueprint isn't down yet) and is silently skipped — never queued.

An attachment stored after its wall places fine, which is why the loss looks orientation-dependent.

Concrete repro (RimWorld 1.6 fork, but same code path here)

A 4-bedroom blueprint with 8 wall lamps on the central wall — 4 facing north (below the wall), 4 facing south (above it):

Lamp Index in blueprint Supporting wall index Result on paste
North ×4 39–49 53–82 (later) ❌ dropped
South ×4 87–98 53–82 (earlier) ✅ placed

The north lamps come before their wall in the stored order → dropped. Verified against the saved blueprint data and the resulting map.

Fix

Repeat the placement pass until a full pass places nothing new. Walls/edifices get designated first, then a subsequent pass places the attachments that depend on them. Planning (shift) mode keeps its original single-pass behaviour.

Terminates because every placed/already-placed item is removed from the pending list each pass (worst case O(n²), n = item count — trivial in practice).

Testing

The equivalent change compiles cleanly and was tested in-game on RimWorld 1.6 (via the community fork that shares this code): re-pasting the repro blueprint now places all 8 lamps. Since the master/1.x branches have the identical single-pass logic, the fix applies unchanged aside from the AvailableContents accessor name.

Also usable as a workaround without this patch: stamping the same blueprint twice places the previously-dropped attachments on the second stamp (their walls exist by then) — which is exactly what this change does automatically in one stamp.

DesignateSingleCell placed items in a single pass, designating each only
if CanPlace succeeded at that moment. Wall attachments (wall lamps,
torches) require their supporting wall to already exist, so any
attachment stored before its wall in the blueprint was silently skipped
and never queued. Pasted copies came out missing lights, depending on
item ordering/orientation.

Repeat placement passes until a full pass places nothing new, so walls
are designated before the attachments that depend on them. Planning
(shift) mode keeps its original single-pass behaviour.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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