Try to fix EntityList deadlocks again (Thanks UnknownShadow200)

This commit is contained in:
Goodlyay 2025-07-04 22:53:53 -07:00
parent 001c960395
commit af8fd02659
2 changed files with 7 additions and 3 deletions

View File

@ -182,7 +182,6 @@ namespace MCGalaxy
string model = Chat.Format(m, pl, true, false); string model = Chat.Format(m, pl, true, false);
OnSendingModelEvent.Call(e, ref model, pl);
pl.EntityList.SendModel(e, model); pl.EntityList.SendModel(e, model);
pl.EntityList.SendScales(e); pl.EntityList.SendScales(e);
} }

View File

@ -199,12 +199,14 @@ namespace MCGalaxy {
} }
/// <summary> /// <summary>
/// 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. /// If this returns false and tabList is true, once the entity spawns, it will be added to the tab list.
/// </summary> /// </summary>
public bool Add(Entity e, Position pos, Orientation rot, string skin, string name, string model, bool tabList) { public bool Add(Entity e, Position pos, Orientation rot, string skin, string name, string model, bool tabList) {
bool self = e == p; bool self = e == p;
OnSendingModelEvent.Call(e, ref model, p);
lock (locker) { lock (locker) {
if (freeIDs.Count > 0 || self) { if (freeIDs.Count > 0 || self) {
VisibleEntity vis; VisibleEntity vis;
@ -294,7 +296,11 @@ namespace MCGalaxy {
p.Session.SendRemoveEntity(vis.id); p.Session.SendRemoveEntity(vis.id);
} }
/// <summary>
/// Calls OnSendingModelEvent and changes the model of the given entity.
/// </summary>
public void SendModel(Entity e, string model) { public void SendModel(Entity e, string model) {
OnSendingModelEvent.Call(e, ref model, p);
lock (locker) { lock (locker) {
VisibleEntity vis; VisibleEntity vis;
if (!visible.TryGetValue(e, out vis)) return; if (!visible.TryGetValue(e, out vis)) return;
@ -303,7 +309,6 @@ namespace MCGalaxy {
} }
void _SendModel(VisibleEntity vis, string model, bool spawning) { void _SendModel(VisibleEntity vis, string model, bool spawning) {
if (p.hasChangeModel) { if (p.hasChangeModel) {
OnSendingModelEvent.Call(vis.e, ref model, p);
if (!(spawning && model.CaselessEq("humanoid"))) p.Session.SendChangeModel(vis.id, model); if (!(spawning && model.CaselessEq("humanoid"))) p.Session.SendChangeModel(vis.id, model);
} }
} }