Automap (client) [VS plugin mod]
修订版 | 1c8849af29a916822885541c010ffc4b7bb90d5a (tree) |
---|---|
时间 | 2022-05-02 03:22:25 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
2nd Entity processing fix attempt
@@ -9,11 +9,12 @@ using System.Text.RegularExpressions; | ||
9 | 9 | using System.Threading; |
10 | 10 | |
11 | 11 | using Hjg.Pngcs; |
12 | - | |
12 | +using Mono.Collections.Generic; | |
13 | 13 | using ProtoBuf; |
14 | 14 | |
15 | 15 | using Vintagestory.API.Client; |
16 | 16 | using Vintagestory.API.Common; |
17 | +using Vintagestory.API.Common.Entities; | |
17 | 18 | using Vintagestory.API.Config; |
18 | 19 | using Vintagestory.API.Datastructures; |
19 | 20 | using Vintagestory.API.MathTools; |
@@ -728,21 +729,26 @@ namespace Automap | ||
728 | 729 | Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count); |
729 | 730 | #endif |
730 | 731 | |
731 | - //Handles mutations better than a plain Iterator | |
732 | - for (int entIndex = 0; entIndex < ClientAPI.World.LoadedEntities.Count; entIndex++ ) | |
732 | + var keyList = new long[ClientAPI.World.LoadedEntities.Keys.Count]; | |
733 | + ClientAPI.World.LoadedEntities.Keys.CopyTo(keyList, 0); | |
734 | + | |
735 | + //'ElementAt'; worse! instead; walk fixed list... | |
736 | + Entity loadedEntity; | |
737 | + foreach (var key in keyList) | |
733 | 738 | { |
734 | - var loadedEntity = ClientAPI.World.LoadedEntities.Values.ElementAt(entIndex); | |
735 | - | |
736 | - #if DEBUG | |
737 | - //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<"); | |
738 | - #endif | |
739 | + if (ClientAPI.World.LoadedEntities.TryGetValue(key, out loadedEntity)) | |
740 | + { | |
741 | + #if DEBUG | |
742 | + //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<"); | |
743 | + #endif | |
739 | 744 | |
740 | - var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Code)); | |
741 | - if (dMatch.Value != null) | |
742 | - { | |
743 | - dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Pos.AsBlockPos.Copy( ), loadedEntity); | |
744 | - } | |
745 | - } | |
745 | + var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Code)); | |
746 | + if (dMatch.Value != null) | |
747 | + { | |
748 | + dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Pos.AsBlockPos.Copy( ), loadedEntity); | |
749 | + } | |
750 | + } | |
751 | + } | |
746 | 752 | } |
747 | 753 | |
748 | 754 | private void AddNote(string notation) |