2 using System.Collections.Concurrent;
3 using System.Collections.Generic;
7 using System.Text.RegularExpressions;
8 using System.Threading;
11 using Hjg.Pngcs.Chunks;
13 using Newtonsoft.Json;
15 using Vintagestory.API.Client;
16 using Vintagestory.API.Common;
17 using Vintagestory.API.Config;
18 using Vintagestory.API.Datastructures;
19 using Vintagestory.API.MathTools;
20 using Vintagestory.Common;
24 public class AutomapSystem
26 private Thread cartographer_thread;
27 private ICoreClientAPI ClientAPI { get; set; }
28 private ILogger Logger { get; set; }
29 private IChunkRenderer ChunkRenderer { get; set; }
31 private const string _mapPath = @"Maps";
32 private const string _chunkPath = @"Chunks";
33 private const string _domain = @"automap";
34 private const string chunkFile_filter = @"*_*.png";
35 private static Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\d]+).png", RegexOptions.Singleline);
37 private ConcurrentDictionary<Vec2i, uint> columnCounter = new ConcurrentDictionary<Vec2i, uint>(3, 150);
38 private ColumnsMetadata chunkTopMetadata;
39 private PointsOfInterest POIs = new PointsOfInterest();
40 private EntitiesOfInterest EOIs = new EntitiesOfInterest();
42 internal Dictionary<int, BlockDesignator> BlockID_Designators { get; private set; }
43 internal Dictionary<AssetLocation, EntityDesignator> Entity_Designators { get; private set; }
44 internal Dictionary<int, string> RockIdCodes { get; private set; }
46 internal CommandType CurrentState { get; set; }
47 //Run status, Chunks processed, stats, center of map....
48 private uint nullChunkCount, updatedChunksTotal;
49 private Vec2i startChunkColumn;
51 private readonly int chunkSize;
53 private IAsset staticMap;
54 private PersistedConfiguration configuration;
57 public static string AutomapStatusEventKey = @"AutomapStatus";
58 public static string AutomapCommandEventKey = @"AutomapCommand";
59 PersistedConfiguration cachedConfiguration;
61 public AutomapSystem(ICoreClientAPI clientAPI, ILogger logger, PersistedConfiguration config)
63 this.ClientAPI = clientAPI;
65 chunkSize = ClientAPI.World.BlockAccessor.ChunkSize;
66 ClientAPI.Event.LevelFinalize += EngageAutomap;
67 configuration = config;
71 //TODO:Choose which one from GUI
72 this.ChunkRenderer = new StandardRenderer(clientAPI, logger);
74 //Listen on bus for commands
75 ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey);
77 if (configuration.Autostart)
79 CurrentState = CommandType.Run;
80 Logger.Debug("Autostart is Enabled.");
87 private void EngageAutomap()
89 path = ClientAPI.GetOrCreateDataPath(_mapPath);
90 path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));//Add name of World too...'ServerApi.WorldManager.CurrentWorldName'
93 string mapFilename = Path.Combine(path, "automap.html");
94 StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
96 staticMap = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap.html"));
97 outputText.Write(staticMap.ToText());
100 Prefill_POI_Designators();
101 startChunkColumn = new Vec2i((ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.X / chunkSize), (ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Z / chunkSize));
102 chunkTopMetadata = new ColumnsMetadata(startChunkColumn);
104 Logger.Notification("AUTOMAP Start {0}", startChunkColumn);
107 ClientAPI.Event.ChunkDirty += ChunkAChanging;
109 cartographer_thread = new Thread(Cartographer)
111 Name = "Cartographer",
112 Priority = ThreadPriority.Lowest,
116 ClientAPI.Event.RegisterGameTickListener(AwakenCartographer, 6000);
119 private void ChunkAChanging(Vec3i chunkCoord, IWorldChunk chunk, EnumChunkDirtyReason reason)
121 Vec2i topPosition = new Vec2i(chunkCoord.X, chunkCoord.Z);
123 columnCounter.AddOrUpdate(topPosition, 1, (key, colAct) => colAct + 1);
126 private void AwakenCartographer(float delayed)
129 if (CurrentState == CommandType.Run && (ClientAPI.IsGamePaused != false || ClientAPI.IsShuttingDown != true))
132 Logger.VerboseDebug("Cartographer re-trigger from [{0}]", cartographer_thread.ThreadState);
135 if (cartographer_thread.ThreadState.HasFlag(ThreadState.Unstarted))
137 cartographer_thread.Start();
139 else if (cartographer_thread.ThreadState.HasFlag(ThreadState.WaitSleepJoin))
141 //Time to (re)write chunk shards
142 cartographer_thread.Interrupt();
145 //ClientAPI.TriggerChatMessage($"Automap {updatedChunksTotal} Updates - MAX (N:{chunkTopMetadata.North_mostChunk},S:{chunkTopMetadata.South_mostChunk},E:{chunkTopMetadata.East_mostChunk}, W:{chunkTopMetadata.West_mostChunk} - TOTAL: {chunkTopMetadata.Count})");
148 else if (CurrentState == CommandType.Snapshot)
150 //TODO: Snapshot generator second thread...
156 private void Cartographer()
159 Logger.VerboseDebug("Cartographer thread awoken");
163 uint ejectedItem = 0;
164 uint updatedChunks = 0;
165 uint updatedPixels = 0;
167 //-- Should dodge enumerator changing underfoot....at a cost.
168 if (!columnCounter.IsEmpty)
170 var tempSet = columnCounter.ToArray().OrderByDescending(kvp => kvp.Value);
171 UpdateEntityMetadata( );
173 foreach (var mostActiveCol in tempSet)
175 var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key);
177 if (mapChunk == null)
179 Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key);
181 columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
185 ColumnMeta chunkMeta;
186 if (chunkTopMetadata.Contains(mostActiveCol.Key)) {
187 chunkMeta = chunkTopMetadata[mostActiveCol.Key];
190 chunkMeta = CreateColumnMetadata(mostActiveCol, mapChunk);
193 ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
195 PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, chunkMeta);
196 ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out updatedPixels);
198 if (updatedPixels > 0)
202 Logger.VerboseDebug("Wrote chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels);
205 chunkTopMetadata.Update(chunkMeta);
206 columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
210 columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
211 Logger.VerboseDebug("Un-painted chunk: ({0}) ", mostActiveCol.Key);
217 UpdateStatus(this.updatedChunksTotal, this.nullChunkCount, updatedChunks);
219 if (updatedChunks > 0)
221 //What about chunk updates themselves; a update bitmap isn't kept...
222 updatedChunksTotal += updatedChunks;
223 GenerateJSONMetadata();
227 //Then sleep until interupted again, and repeat
229 Logger.VerboseDebug("Thread '{0}' about to sleep indefinitely.", Thread.CurrentThread.Name);
231 Thread.Sleep(Timeout.Infinite);
234 catch (ThreadInterruptedException)
237 Logger.VerboseDebug("Thread '{0}' interupted [awoken]", Thread.CurrentThread.Name);
241 catch (ThreadAbortException)
243 Logger.VerboseDebug("Thread '{0}' aborted.", Thread.CurrentThread.Name);
248 Logger.VerboseDebug("Thread '{0}' executing finally block.", Thread.CurrentThread.Name);
252 private void UpdateStatus(uint totalUpdates, uint voidChunks, uint delta)
254 StatusData updateData = new StatusData(totalUpdates, voidChunks, delta, CommandType.Run);
256 this.ClientAPI.Event.PushEvent(AutomapStatusEventKey, updateData);
259 private void Prefill_POI_Designators()
262 this.BlockID_Designators = new Dictionary<int, BlockDesignator>();
263 this.Entity_Designators = new Dictionary<AssetLocation, EntityDesignator>();
264 this.RockIdCodes = Helpers.ArbitrarytBlockIdHunter(ClientAPI, new AssetLocation(GlobalConstants.DefaultDomain, "rock-"), EnumBlockMaterial.Stone);
266 //Add special marker types for BlockID's of "Interest", overwrite colour, and method
268 Reload_POI_Designators();
271 private void Reload_POI_Designators()
273 Logger.VerboseDebug("Connecting {0} Configured Block-Designators", configuration.BlockDesignators.Count);
274 foreach (var designator in configuration.BlockDesignators)
276 var blockIDs = Helpers.ArbitrarytBlockIdHunter(ClientAPI, designator.Pattern, designator.Material);
277 if (blockIDs.Count > 0) { Logger.VerboseDebug("Designator {0} has {1} associated blockIDs", designator.ToString(), blockIDs.Count); }
278 foreach (var entry in blockIDs)
280 BlockID_Designators.Add(entry.Key, designator);
283 this.ChunkRenderer.BlockID_Designators = BlockID_Designators;
286 Logger.VerboseDebug("Connecting {0} Configured Entity-Designators", configuration.EntityDesignators.Count);
287 foreach (var designator in configuration.EntityDesignators)
289 //Get Variants first, from EntityTypes...better be populated!
290 var matched = ClientAPI.World.EntityTypes.FindAll(entp => entp.Code.BeginsWith(designator.Pattern.Domain, designator.Pattern.Path));
292 foreach (var match in matched)
294 Logger.VerboseDebug("Linked Entity: {0} Designator: {1}", match.Code, designator);
295 this.Entity_Designators.Add(match.Code, designator);
300 //EntityProperties props = ClientAPI.World.GetEntityType(designator.Pattern);
306 //TODO: Rewrite as Newtonsoft JsonTextWriter !!!
308 /// Generates the JSON Metadata. (in Map object format )
310 private void GenerateJSONMetadata()
312 string jsonFilename = Path.Combine(path, "Metadata.js");
314 StreamWriter stream = new StreamWriter(jsonFilename, false, Encoding.UTF8);
317 JsonTextWriter jsonWriter = new JsonTextWriter(stream);
319 jsonWriter.Formatting = Formatting.None;
320 jsonWriter.StringEscapeHandling = StringEscapeHandling.EscapeHtml;
321 jsonWriter.Indentation = 0;
322 //jsonWriter.AutoCompleteOnClose = true;
323 jsonWriter.QuoteChar = '\'';
324 jsonWriter.DateFormatHandling = DateFormatHandling.IsoDateFormat;
325 jsonWriter.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
329 jsonWriter.WriteRaw("ViewFrame.chunks={};\n");
330 jsonWriter.WriteRaw("ViewFrame.chunks.worldSeedNum=" );
331 jsonWriter.WriteValue(ClientAPI.World.Seed);
332 jsonWriter.WriteRaw(";\n");
334 jsonWriter.WriteRaw("ViewFrame.chunks.genTime=");
335 jsonWriter.WriteValue(DateTimeOffset.UtcNow);
336 jsonWriter.WriteRaw(";\n");
338 jsonWriter.WriteRaw("ViewFrame.chunks.startCoords=");
339 jsonWriter.WriteStartArray( );
340 jsonWriter.WriteValue(startChunkColumn.X);
341 jsonWriter.WriteValue(startChunkColumn.Y);
342 jsonWriter.WriteEndArray( );
343 jsonWriter.WriteRaw(";\n");
345 jsonWriter.WriteRaw("ViewFrame.chunks.chunkSize=");
346 jsonWriter.WriteValue(chunkSize);
347 jsonWriter.WriteRaw(";\n");
349 jsonWriter.WriteRaw("ViewFrame.chunks.northMostChunk=");
350 jsonWriter.WriteValue(chunkTopMetadata.North_mostChunk);
351 jsonWriter.WriteRaw(";\n");
353 jsonWriter.WriteRaw("ViewFrame.chunks.southMostChunk=");
354 jsonWriter.WriteValue(chunkTopMetadata.South_mostChunk);
355 jsonWriter.WriteRaw(";\n");
357 jsonWriter.WriteRaw("ViewFrame.chunks.westMostChunk=");
358 jsonWriter.WriteValue(chunkTopMetadata.West_mostChunk);
359 jsonWriter.WriteRaw(";\n");
361 jsonWriter.WriteRaw("ViewFrame.chunks.eastMostChunk=");
362 jsonWriter.WriteValue(chunkTopMetadata.East_mostChunk);
363 jsonWriter.WriteRaw(";\n");
366 //MAP object format - [key, value]: key is "x_y"
367 jsonWriter.WriteRaw("ViewFrame.chunks.chunkMetadata=");
368 jsonWriter.WriteStartConstructor("Map");
369 jsonWriter.WriteStartArray( );//An array of... 2-component arrays
372 foreach (var shard in chunkTopMetadata)
374 jsonWriter.WriteStartArray( );//Start tuple
375 jsonWriter.WriteValue($"{shard.Location.X}_{shard.Location.Y}");//Key of Tuple
377 jsonWriter.WriteStartObject( );
378 jsonWriter.WritePropertyName("prettyCoord");
379 jsonWriter.WriteValue( shard.Location.PrettyCoords(ClientAPI));
381 jsonWriter.WritePropertyName("chunkAge");
382 jsonWriter.WriteValue(shard.ChunkAge);
384 jsonWriter.WritePropertyName("temp");
385 jsonWriter.WriteValue(shard.Temperature);
387 jsonWriter.WritePropertyName("YMax");
388 jsonWriter.WriteValue(shard.YMax);
390 jsonWriter.WritePropertyName("fert");
391 jsonWriter.WriteValue(shard.Fertility);
393 jsonWriter.WritePropertyName("forestDens");
394 jsonWriter.WriteValue( shard.ForestDensity);
396 jsonWriter.WritePropertyName("rain");
397 jsonWriter.WriteValue( shard.Rainfall);
399 jsonWriter.WritePropertyName("shrubDens");
400 jsonWriter.WriteValue( shard.ShrubDensity);
402 jsonWriter.WritePropertyName("airBlocks");
403 jsonWriter.WriteValue( shard.AirBlocks);
405 jsonWriter.WritePropertyName("nonAirBlocks");
406 jsonWriter.WriteValue( shard.NonAirBlocks);
409 //Start rockMap ; FOR a Ratio....on tooltip GUI
410 jsonWriter.WritePropertyName("rockRatio");
411 jsonWriter.WriteStartConstructor("Map");
412 jsonWriter.WriteStartArray( );
413 foreach (var rockEntry in shard.RockRatio) {
414 var rockBlock = ClientAPI.World.GetBlock(rockEntry.Key);
415 jsonWriter.WriteStartArray( );
416 jsonWriter.WriteValue(rockBlock.Code.Path);
417 jsonWriter.WriteValue(rockEntry.Value);//Total per chunk-column
418 jsonWriter.WriteEndArray( );
420 jsonWriter.WriteEndArray( );
421 jsonWriter.WriteEndConstructor( );//end rock-map
423 jsonWriter.WriteEndObject( );//end Map value: {Object}
424 jsonWriter.WriteEndArray( );//end Tuple
427 jsonWriter.WriteEndArray( );//Enclose tuples of chunkMetadata
428 jsonWriter.WriteEndConstructor( );//Close constructor of Map (chunkMetadata)
429 jsonWriter.WriteRaw(";\n");
431 jsonWriter.WriteRaw("ViewFrame.chunks.pointsOfInterest=");
432 jsonWriter.WriteStartConstructor("Map");
433 jsonWriter.WriteStartArray( );//An array of... 2-component arrays
435 foreach (var poi in POIs)
437 jsonWriter.WriteStartArray( );
438 jsonWriter.WriteValue($"{poi.Location.X}_{poi.Location.Z}");
440 jsonWriter.WriteStartObject();
441 jsonWriter.WritePropertyName("prettyCoord");
442 jsonWriter.WriteValue(poi.Location.PrettyCoords(ClientAPI) );
444 jsonWriter.WritePropertyName("notes");
445 jsonWriter.WriteValue(poi.Notes);//Encoded to HTML Entities
447 jsonWriter.WritePropertyName("time");
448 jsonWriter.WriteValue(poi.Timestamp);
450 jsonWriter.WritePropertyName("chunkPos");
451 jsonWriter.WriteValue($"{(poi.Location.X / chunkSize)}_{(poi.Location.Z / chunkSize)}");
453 jsonWriter.WriteEndObject( );
454 jsonWriter.WriteEndArray( );
457 foreach (var poi in EOIs)
459 jsonWriter.WriteStartArray( );
460 jsonWriter.WriteValue($"{poi.Location.X}_{poi.Location.Z}");
462 jsonWriter.WriteStartObject( );
463 jsonWriter.WritePropertyName("prettyCoord");
464 jsonWriter.WriteValue(poi.Location.PrettyCoords(ClientAPI));
466 jsonWriter.WritePropertyName("notes");
467 jsonWriter.WriteValue(poi.Notes);//Encoded to HTML Entities
469 jsonWriter.WritePropertyName("time");
470 jsonWriter.WriteValue(poi.Timestamp);
472 jsonWriter.WritePropertyName("chunkPos");
473 jsonWriter.WriteValue($"{(poi.Location.X / chunkSize)}_{(poi.Location.Z / chunkSize)}");
475 jsonWriter.WriteEndObject( );
476 jsonWriter.WriteEndArray( );
479 jsonWriter.WriteEndArray( );
480 jsonWriter.WriteEndConstructor( );
481 jsonWriter.WriteRaw(";\n");
483 jsonWriter.WriteWhitespace("\n");
484 jsonWriter.WriteComment("============= BlockID's for Rockmap / Rock-ratios ===============");
485 jsonWriter.WriteWhitespace("\n");
487 jsonWriter.WriteRaw("ViewFrame.chunks.rock_Lookup =");
488 jsonWriter.WriteStartConstructor("Map");
489 jsonWriter.WriteStartArray( );//An array of... 2-component arrays
491 foreach (var entry in RockIdCodes) {
492 var block = ClientAPI.World.GetBlock(entry.Key);
494 jsonWriter.WriteStartArray( );
495 jsonWriter.WriteValue(block.Code.Path);
497 jsonWriter.WriteStartObject( );
498 jsonWriter.WritePropertyName("assetCode");
499 jsonWriter.WriteValue(entry.Value);
501 jsonWriter.WritePropertyName("name");
502 jsonWriter.WriteValue(Lang.GetUnformatted(block.Code.Path));
505 jsonWriter.WriteEndObject( );
506 jsonWriter.WriteEndArray( );
508 jsonWriter.WriteEndArray( );
509 jsonWriter.WriteEndConstructor();
511 jsonWriter.WriteRaw(";\n");
520 private ColumnMeta CreateColumnMetadata(KeyValuePair<Vec2i, uint> mostActiveCol, IMapChunk mapChunk)
522 ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), ( byte )chunkSize);
523 BlockPos equivBP = new BlockPos(mostActiveCol.Key.X * chunkSize,
525 mostActiveCol.Key.Y * chunkSize);
527 var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP);
528 data.UpdateFieldsFrom(climate, mapChunk, TimeSpan.FromHours(ClientAPI.World.Calendar.TotalHours));
534 /// Reload chunk bounds from chunk shards
536 /// <returns>The metadata.</returns>
537 private void Reload_Metadata()
539 var worldmapDir = new DirectoryInfo(path);
541 if (worldmapDir.Exists)
544 var files = worldmapDir.GetFiles(chunkFile_filter);
546 if (files.Length > 0)
549 Logger.VerboseDebug("{0} Existing world chunk shards", files.Length);
552 foreach (var shardFile in files) {
554 if (shardFile.Length < 1024) continue;
555 var result = chunkShardRegex.Match(shardFile.Name);
556 if (result.Success) {
557 int X_chunk_pos = int.Parse(result.Groups["X"].Value);
558 int Z_chunk_pos = int.Parse(result.Groups["Z"].Value);
562 using (var fileStream = shardFile.OpenRead( )) {
564 PngReader pngRead = new PngReader(fileStream);
565 pngRead.ReadSkippingAllRows( );
567 //Parse PNG chunks for METADATA in shard
568 PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk;
570 chunkTopMetadata.Add(metadataFromPng.ChunkMetadata);
574 catch (PngjException someEx)
576 Logger.Error("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx);
589 Logger.VerboseDebug("Could not open world map directory");
597 private PngWriter SetupPngImage(Vec2i coord, ColumnMeta metadata)
599 ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false);
601 string filename = $"{coord.X}_{coord.Y}.png";
602 filename = Path.Combine(path, filename);
604 PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true);
605 PngMetadata meta = pngWriter.GetMetadata();
607 meta.SetText("Chunk_X", coord.X.ToString("D"));
608 meta.SetText("Chunk_Y", coord.Y.ToString("D"));
609 //Setup specialized meta-data PNG chunks here...
610 PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo)
612 ChunkMetadata = metadata
614 pngWriter.GetChunksList().Queue(pngChunkMeta);
615 pngWriter.CompLevel = 9;// 9 is the maximum compression
616 pngWriter.CompressionStrategy = Hjg.Pngcs.Zlib.EDeflateCompressStrategy.Huffman;
622 /// Does the heavy lifting of Scanning columns of chunks - scans for BlockEntity, creates Heightmap and stats...
624 /// <param name="key">Chunk Coordinate</param>
625 /// <param name="mapChunk">Map chunk.</param>
626 /// <param name="chunkMeta">Chunk metadata</param>
627 private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ref ColumnMeta chunkMeta)
630 int targetChunkY = mapChunk.YMax / chunkSize;//Surface ...
631 for (; targetChunkY > 0; targetChunkY--)
633 WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk;
635 if (chunkData == null || chunkData.BlockEntities == null) {
637 Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y);
642 /*************** Chunk Entities Scanning *********************/
643 if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0)
646 Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length);
649 foreach (var blockEnt in chunkData.BlockEntities)
652 if (blockEnt != null && blockEnt.Block != null && BlockID_Designators.ContainsKey(blockEnt.Block.BlockId))
654 var designator = BlockID_Designators[blockEnt.Block.BlockId];
655 designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy(), blockEnt.Block);
660 /********************* Chunk/Column BLOCKs scanning ****************/
661 //Heightmap, Stats, block tally
664 int X_index, Y_index, Z_index;
665 X_index = Y_index = Z_index = 0;
673 /* Encode packed indicie
674 (y * chunksize + z) * chunksize + x
676 var indicie = Helpers.ChunkBlockIndicie16(X_index, Y_index, Z_index);
677 int aBlockId = chunkData.Blocks[indicie];
681 chunkMeta.AirBlocks++;
685 if (RockIdCodes.ContainsKey(aBlockId))
687 if (chunkMeta.RockRatio.ContainsKey(aBlockId)) { chunkMeta.RockRatio[aBlockId]++; } else { chunkMeta.RockRatio.Add(aBlockId, 1); }
690 chunkMeta.NonAirBlocks++;
693 if (chunkMeta.HeightMap[X_index, Z_index] == 0)
694 { chunkMeta.HeightMap[X_index, Z_index] = (ushort) (Y_index + (targetChunkY * chunkSize)); }
697 while (X_index++ < (chunkSize - 1));
700 while (Z_index++ < (chunkSize - 1));
703 while (Y_index++ < (chunkSize - 1));
708 private void UpdateEntityMetadata()
710 Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count);
711 //Mabey scan only for 'new' entities by tracking ID in set?
712 foreach (var loadedEntity in ClientAPI.World.LoadedEntities.ToArray())
716 //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<");
719 var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code));
720 if (dMatch.Value != null)
722 dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy(), loadedEntity.Value);
730 private void AddNote(string notation)
732 var playerNodePoi = new PointOfInterest()
734 Location = ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Copy(),
736 Timestamp = DateTimeOffset.UtcNow,
739 this.POIs.AddReplace(playerNodePoi);
744 private void CommandListener(string eventName, ref EnumHandling handling, IAttribute data)
746 Logger.VerboseDebug("MsgBus RX: AutomapCommandMsg: {0}", data.ToJsonToken());
748 CommandData cmdData = data as CommandData;
751 if (CurrentState != CommandType.Snapshot)
753 switch (cmdData.State)
755 case CommandType.Run:
756 CurrentState = cmdData.State;
757 AwakenCartographer(0.0f);
760 case CommandType.Stop:
761 CurrentState = cmdData.State;
764 case CommandType.Snapshot:
765 CurrentState = CommandType.Stop;
766 //Snapshot starts a second thread/process...
770 case CommandType.Notation:
771 //Add to POI list where player location
772 AddNote(cmdData.Notation);
778 if (CurrentState != cmdData.State)
780 CurrentState = cmdData.State;
781 AwakenCartographer(0.0f);
785 ClientAPI.TriggerChatMessage($"Automap commanded to: {cmdData.State} ");