Skip to content

Commit b8d1760

Browse files
committed
fix world-change events not working in freshly-constructed buildings
1 parent 61084ff commit b8d1760

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

docs/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* The installer now deletes Error Handler automatically if it's at the default path.
88
* Updated mod compatibility list.
99

10+
* For mod authors:
11+
* Fixed world-changed events (e.g. `ObjectListChanged`) not working correctly inside freshly-constructed building.
12+
1013
## 4.0.4
1114
Released 29 March 2024 for Stardew Valley 1.6.0 or later.
1215

src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ public void Update()
102102
}
103103

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

109-
if (oldIndoors != null)
110-
this.Added.Add(oldIndoors);
111-
if (newIndoors != null)
112-
this.Removed.Add(newIndoors);
111+
this.Remove(oldIndoors);
112+
this.Add(newIndoors);
113+
114+
this.BuildingIndoors[building] = newIndoors;
113115
}
114116
}
115117

0 commit comments

Comments
 (0)