OSDN Git Service

2nd Entity processing fix attempt
[automap/automap.git] / Automap / Subsystems / AutomapSystem.cs
index 2997ec6..32cda38 100644 (file)
@@ -9,11 +9,12 @@ using System.Text.RegularExpressions;
 using System.Threading;
 
 using Hjg.Pngcs;
-
+using Mono.Collections.Generic;
 using ProtoBuf;
 
 using Vintagestory.API.Client;
 using Vintagestory.API.Common;
+using Vintagestory.API.Common.Entities;
 using Vintagestory.API.Config;
 using Vintagestory.API.Datastructures;
 using Vintagestory.API.MathTools;
@@ -346,14 +347,24 @@ namespace Automap
 
                        var airBlocksQuery = from airyBlock in ClientAPI.World.Blocks
                                                         where airyBlock.MatterState == EnumMatterState.Solid
-                                                        where airyBlock.BlockMaterial == EnumBlockMaterial.Plant || airyBlock.BlockMaterial == EnumBlockMaterial.Leaves
-                                                        where airyBlock.CollisionBoxes == null || airyBlock.CollisionBoxes.Length == 0 ||airyBlock.RainPermeable == true                                                        
-                                                        select airyBlock;                      
-                       //^^ 'Solid' phase - 'Plant' Blocks without any boundg box ? Except water...
-                       this.AiryIdCodes = airBlocksQuery.ToDictionary(aBlk => aBlk.BlockId, aBlk => aBlk.Code.Path);
-
-                       //Add special marker types for BlockID's of "Interest", overwrite colour, and method
-                       Reload_POI_Designators();
+                                                        where airyBlock.BlockMaterial == EnumBlockMaterial.Plant || airyBlock.BlockMaterial == EnumBlockMaterial.Leaves 
+                                                        where airyBlock.CollisionBoxes == null || airyBlock.CollisionBoxes.Length == 0 || airyBlock.RainPermeable == true                                       
+                                                               select airyBlock;                       
+                       //^^ 'Solid' phase - 'Plant' Blocks without any bounding-box; OR 'Invisible' shapes...
+                       var invisibleBlocksQuery = from novisBlock in ClientAPI.World.Blocks                                                                       
+                                                                          where novisBlock.Shape == null || novisBlock.Shape.Base.EndsWith(GlobalConstants.DefaultDomain, @"invisible")   //Whaat! [ base: "block/basic/invisible" ]
+                                                                               select novisBlock;                      
+                       this.AiryIdCodes = airBlocksQuery.Union(invisibleBlocksQuery).ToDictionary(aBlk => aBlk.BlockId, aBlk => aBlk.Code.Path);
+
+                       #if DEBUG
+                       foreach (var fluffBlock in AiryIdCodes) {
+                       Logger.VerboseDebug("ID#\t{0}:\t{1} IGNORED", fluffBlock.Key, fluffBlock.Value);
+                       }
+                       Logger.VerboseDebug("Ignoring {0} blocks", AiryIdCodes.Count);
+                       #endif
+
+               //Add special marker types for BlockID's of "Interest", overwrite colour, and method
+               Reload_POI_Designators();
                }
 
                private void Reload_POI_Designators()
@@ -714,26 +725,30 @@ namespace Automap
 
                private void UpdateEntityMetadata()
                {
-                       #if DEBUG
-                       Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count);
-                       #endif
-                       //Mabey scan only for 'new' entities by tracking ID in set?
-                       foreach (var loadedEntity in ClientAPI.World.LoadedEntities.ToArray())
-                       {
+               #if DEBUG
+               Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count);
+               #endif
+
+               var keyList = new long[ClientAPI.World.LoadedEntities.Keys.Count];
+               ClientAPI.World.LoadedEntities.Keys.CopyTo(keyList, 0);
 
+            //'ElementAt'; worse! instead; walk fixed list...
+               Entity loadedEntity;
+               foreach (var key in keyList)
+                       {
+                       if (ClientAPI.World.LoadedEntities.TryGetValue(key, out loadedEntity))
+                               {               
                                #if DEBUG
                                //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos}    <<<<<<<<<<<<");
                                #endif
 
-                               var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code));
-                               if (dMatch.Value != null)
-                               {
-                                       dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.Pos.AsBlockPos.Copy(), loadedEntity.Value);
-                               }
-
+                               var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Code));
+                               if (dMatch.Value != null) 
+                                       {
+                                       dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Pos.AsBlockPos.Copy( ), loadedEntity);
+                                       }
+                               }                               
                        }
-
-
                }
 
                private void AddNote(string notation)