Skip to content

Commit

Permalink
fix world-change events not working in freshly-constructed buildings
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Apr 6, 2024
1 parent 61084ff commit b8d1760
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* The installer now deletes Error Handler automatically if it's at the default path.
* Updated mod compatibility list.

* For mod authors:
* Fixed world-changed events (e.g. `ObjectListChanged`) not working correctly inside freshly-constructed building.

## 4.0.4
Released 29 March 2024 for Stardew Valley 1.6.0 or later.

Expand Down
12 changes: 7 additions & 5 deletions src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ public void Update()
}

// detect building interiors changed (e.g. construction completed)
foreach ((Building building, GameLocation? oldIndoors) in this.BuildingIndoors.Where(p => !object.Equals(p.Key.indoors.Value, p.Value)))
foreach ((Building building, GameLocation? oldIndoors) in this.BuildingIndoors)
{
GameLocation? newIndoors = building.indoors.Value;
if (object.ReferenceEquals(oldIndoors, newIndoors))
continue;

if (oldIndoors != null)
this.Added.Add(oldIndoors);
if (newIndoors != null)
this.Removed.Add(newIndoors);
this.Remove(oldIndoors);
this.Add(newIndoors);

this.BuildingIndoors[building] = newIndoors;
}
}

Expand Down

0 comments on commit b8d1760

Please sign in to comment.