From af8fd0265928b0218595b8609e86ed978176ae17 Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Fri, 4 Jul 2025 22:53:53 -0700 Subject: [PATCH] Try to fix EntityList deadlocks again (Thanks UnknownShadow200) --- MCGalaxy/Entity/Entities.cs | 1 - MCGalaxy/Entity/EntityList.cs | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/MCGalaxy/Entity/Entities.cs b/MCGalaxy/Entity/Entities.cs index b5ba8f8cc..1e5d489c6 100644 --- a/MCGalaxy/Entity/Entities.cs +++ b/MCGalaxy/Entity/Entities.cs @@ -182,7 +182,6 @@ namespace MCGalaxy string model = Chat.Format(m, pl, true, false); - OnSendingModelEvent.Call(e, ref model, pl); pl.EntityList.SendModel(e, model); pl.EntityList.SendScales(e); } diff --git a/MCGalaxy/Entity/EntityList.cs b/MCGalaxy/Entity/EntityList.cs index 49d7b893f..69f0fcb51 100644 --- a/MCGalaxy/Entity/EntityList.cs +++ b/MCGalaxy/Entity/EntityList.cs @@ -199,12 +199,14 @@ namespace MCGalaxy { } /// - /// Adds the given entity. Returns true if an entity was spawned, otherwise false if it could not immediately be spawned (it will spawn later if enough are removed) + /// Adds the given entity and calls OnSendingModelEvent. Returns true if an entity was spawned, otherwise false if it could not immediately be spawned (it will spawn later if enough are removed) /// If this returns false and tabList is true, once the entity spawns, it will be added to the tab list. /// public bool Add(Entity e, Position pos, Orientation rot, string skin, string name, string model, bool tabList) { bool self = e == p; + OnSendingModelEvent.Call(e, ref model, p); + lock (locker) { if (freeIDs.Count > 0 || self) { VisibleEntity vis; @@ -294,7 +296,11 @@ namespace MCGalaxy { p.Session.SendRemoveEntity(vis.id); } + /// + /// Calls OnSendingModelEvent and changes the model of the given entity. + /// public void SendModel(Entity e, string model) { + OnSendingModelEvent.Call(e, ref model, p); lock (locker) { VisibleEntity vis; if (!visible.TryGetValue(e, out vis)) return; @@ -303,7 +309,6 @@ namespace MCGalaxy { } void _SendModel(VisibleEntity vis, string model, bool spawning) { if (p.hasChangeModel) { - OnSendingModelEvent.Call(vis.e, ref model, p); if (!(spawning && model.CaselessEq("humanoid"))) p.Session.SendChangeModel(vis.id, model); } }