OSDN Git Service

W.I.P. III: Translocator working Via BlockEntity scan (surface only, for now)
authormelchior <melchior@users.osdn.me>
Thu, 30 Jan 2020 00:16:26 +0000 (19:16 -0500)
committermelchior <melchior@users.osdn.me>
Thu, 30 Jan 2020 00:16:26 +0000 (19:16 -0500)
Automap/Designators/DefaultDesignators.cs
Automap/Subsystems/AutomapSystem.cs

index d6d9fd7..8c88a89 100644 (file)
@@ -1,7 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Drawing;
-
+using System.Text;
 using Vintagestory.API.Client;
 using Vintagestory.API.Common;
 using Vintagestory.API.Common.Entities;
@@ -46,9 +46,9 @@ namespace Automap
                public static BlockDesignator Translocators =
                         new BlockDesignator(
                                new AssetLocation("game", "statictranslocator-normal"),
-                               Color.Violet,
-                               EnumBlockMaterial.Metal
-                               //DecodeTranslocator
+                               Color.SteelBlue,
+                               EnumBlockMaterial.Metal,
+                               DecodeTranslocator
                        );
 
                public static EntityDesignator Traders =
@@ -59,7 +59,10 @@ namespace Automap
                                KeepTrackOfMerchant
                        );
 
-
+               /// <summary>
+               /// Not just blocks, but block-entities as well!
+               /// </summary>
+               /// <returns>The block designators.</returns>
                public static List<BlockDesignator>  DefaultBlockDesignators( )
                {
                return  new List<BlockDesignator>{
@@ -67,6 +70,7 @@ namespace Automap
                                DefaultDesignators.GroundSigns,
                                DefaultDesignators.WallSigns,
                                DefaultDesignators.PostSigns,
+                               DefaultDesignators.Translocators,
                                };
                }
 
@@ -129,6 +133,33 @@ namespace Automap
                }
                poi.Upsert(entity, message);
                }
+
+               internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block)
+               {
+               clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!");
+               //Where to? and from!
+               
+               BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator;
+
+               if (te != null ) {
+
+               StringBuilder textTarget = new StringBuilder( );
+               //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget);
+
+               textTarget.Append(te.Activated ? "Online " : "offline ");
+               textTarget.Append(" Dest.: ");
+               textTarget.Append(te.TargetLocation != null ? te.TargetLocation.PrettyCoords(clientAPI) : "???");//Or ABS coords?               
+
+               poi.AddReplace(
+                                       new PointOfInterest {
+                                               Location = posn.Copy( ),
+                                               Notes = textTarget.ToString(),
+                                               Timestamp = DateTimeOffset.UtcNow,
+                                       }
+                                       );
+
+               }
+               }
        }
 }
 
index 4d71bc8..200015b 100644 (file)
@@ -112,7 +112,9 @@ namespace Automap
                //Time to (re)write chunk shards
                cartographer_thread.Interrupt( );
                }
+               #if DEBUG
                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})");
+               #endif
                }
 
                }
@@ -408,16 +410,16 @@ namespace Automap
                tableWriter.RenderBeginTag(HtmlTextWriterTag.Ul);
                foreach (var poi in this.POIs) {
                tableWriter.RenderBeginTag(HtmlTextWriterTag.Li);
-               tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI));
-               tableWriter.WriteEncodedText(poi.Notes);
+               tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI)+"\t");
+               tableWriter.WriteEncodedText(poi.Notes+ "\t");
                tableWriter.WriteEncodedText(poi.Timestamp.ToString("u"));
                tableWriter.RenderEndTag( );
                }
 
                foreach (var eoi in this.EOIs.PointsList) {
                tableWriter.RenderBeginTag(HtmlTextWriterTag.Li);
-               tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI));
-               tableWriter.WriteEncodedText(eoi.Notes);
+               tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI)+ "\t");
+               tableWriter.WriteEncodedText(eoi.Notes+ "\t");
                tableWriter.WriteEncodedText(eoi.Timestamp.ToString("u") );
                tableWriter.RenderEndTag( );
                }
@@ -528,17 +530,30 @@ namespace Automap
                }
 
                /// <summary>
-               /// Does the heavy lifting of Scanning the whole (surface) chunk - creates Heightmap and Processes POIs, Entities, and stats...
+               /// Does the heavy lifting of Scanning columns of chunks - creates Heightmap and Processes POIs, Entities, and stats...
                /// </summary>
                /// <param name="key">Chunk Coordinate</param>
                /// <param name="mapChunk">Map chunk.</param>
                /// <param name="chunkMeta">Chunk metadata</param>
                private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ColumnMeta chunkMeta)
                {
+               //TODO: build stack of chunk(s) - surface down to bedrock
                int topChunkY = mapChunk.YMax / chunkSize;
                WorldChunk chunkData = ( Vintagestory.Common.WorldChunk )ClientAPI.World.BlockAccessor.GetChunk(key.X, topChunkY, key.Y);
 
-               
+               if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0) {
+               #if DEBUG
+               Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length);
+
+               foreach (var blockEnt in chunkData.BlockEntities) {             
+                       if (BlockID_Designators.ContainsKey(blockEnt.Block.BlockId)) 
+                       {
+                       var designator = BlockID_Designators[blockEnt.Block.BlockId];
+                       designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy(), blockEnt.Block);
+                       }
+               }
+               #endif
+               }
 
                }