public BCMTileEntitySign(Vector3i pos, [NotNull] TileEntitySign te) : base(pos, te) { Owner = te.GetOwner(); Users = te.GetUsers(); HasPassword = te.HasPassword(); IsLocked = te.IsLocked(); Text = te.GetText(); }
public void SetupAutoPathingBlocks() { if (this.Buffs.HasCustomVar("PathingCode")) { return; } // Check if pathing blocks are defined. List <string> Blocks = EntityUtilities.ConfigureEntityClass(this.entityId, "PathingBlocks"); if (Blocks.Count == 0) { Blocks = new List <string>() { "PathingCube" } } ; //Scan for the blocks in the area List <Vector3> PathingVectors = ModGeneralUtilities.ScanForTileEntityInChunksListHelper(this.position, Blocks, this.entityId); if (PathingVectors == null || PathingVectors.Count == 0) { return; } // Find the nearest block, and if its a sign, read its code. Vector3 target = ModGeneralUtilities.FindNearestBlock(this.position, PathingVectors); TileEntitySign tileEntitySign = GameManager.Instance.World.GetTileEntity(0, new Vector3i(target)) as TileEntitySign; if (tileEntitySign == null) { return; } // Since signs can have multiple codes, splite with a ,, parse each one. String text = tileEntitySign.GetText(); float code = 0f; // Defined here as DMT compiler doesn't like inlining it. foreach (String temp in text.Split(',')) { if (StringParsers.TryParseFloat(temp, out code)) { this.Buffs.AddCustomVar("PathingCode", code); return; } } }
// The method will scan a distance of MaxDistance around the entity, finding the nearest block that matches in the list. public static List <Vector3> ScanForBlockInListHelper(Vector3 centerPosition, List <String> lstBlocks, int MaxDistance, int EntityID = -1) { if (lstBlocks.Count == 0) { return(null); } List <Vector3> localLists = new List <Vector3>(); Vector3i TargetBlockPosition = new Vector3i(); if (EntityID < 0) { return(null); } EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive; if (myEntity == null) { return(null); } // Check if the entity has a PathingCode already. If it doesn't, use a default of 0. float code = 0; if (myEntity.Buffs.HasCustomVar("PathingCode")) { code = EntityUtilities.GetCVarValue(EntityID, "PathingCode"); } else { myEntity.Buffs.AddCustomVar("PathingCode", 0f); } for (var x = (int)centerPosition.x - MaxDistance; x <= centerPosition.x + MaxDistance; x++) { for (var z = (int)centerPosition.z - MaxDistance; z <= centerPosition.z + MaxDistance; z++) { for (var y = (int)centerPosition.y - MaxDistance; y <= centerPosition.y + MaxDistance; y++) { TargetBlockPosition.x = x; TargetBlockPosition.y = y; TargetBlockPosition.z = z; BlockValue block = GameManager.Instance.World.GetBlock(TargetBlockPosition); if (block.ischild) { continue; } // if its not a listed block, then keep searching. if (!lstBlocks.Contains(block.Block.GetBlockName())) { continue; } TileEntitySign tileEntitySign = GameManager.Instance.World.GetTileEntity(0, TargetBlockPosition) as TileEntitySign; if (tileEntitySign != null) { // If the sign is empty and the code is 0, then accept it as a path String text = tileEntitySign.GetText(); if (String.IsNullOrEmpty(text) && code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); continue; } foreach (String temp in text.Split(',')) { if (code.ToString() == temp || code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); break; } } continue; } localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); } } } return(localLists); }
// The method will scan a distance of MaxDistance around the entity, finding the nearest block that matches in the list. public static List <Vector3> ScanForTileEntityInChunksListHelper(Vector3 centerPosition, List <String> lstBlocks, int EntityID = -1) { if (lstBlocks == null || lstBlocks.Count == 0) { lstBlocks = new List <string>() { "PathingCube" } } ; if (EntityID < 0) { return(null); } EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive; if (myEntity == null) { return(null); } // Check if the entity has a PathingCode already. If it doesn't, use a default of 0. float code = 0f; if (myEntity.Buffs.HasCustomVar("PathingCode")) { code = EntityUtilities.GetCVarValue(EntityID, "PathingCode"); } else { myEntity.Buffs.AddCustomVar("PathingCode", 0f); } List <Vector3> localLists = new List <Vector3>(); Vector3i TargetBlockPosition; Vector3i blockPosition = new Vector3i(centerPosition); int num = World.toChunkXZ(blockPosition.x); int num2 = World.toChunkXZ(blockPosition.z); for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { Chunk chunk = (Chunk)GameManager.Instance.World.GetChunkSync(num + j, num2 + i); if (chunk != null) { DictionaryList <Vector3i, TileEntity> tileEntities = chunk.GetTileEntities(); for (int k = 0; k < tileEntities.list.Count; k++) { TileEntity tileEntity = tileEntities.list[k]; TargetBlockPosition = tileEntity.ToWorldPos(); // If it's a sign, check to see if there's a code on it. TileEntitySign tileEntitySign = tileEntity as TileEntitySign; if (tileEntitySign != null) { // If the sign is empty and the code is 0, then accept it as a path String text = tileEntitySign.GetText(); if (String.IsNullOrEmpty(text) && code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); continue; } foreach (String temp in text.Split(',')) { if (code.ToString() == temp || code == 0) { localLists.Add(TargetBlockPosition.ToVector3() + Vector3.up); break; } } continue; } BlockValue block = GameManager.Instance.World.GetBlock(TargetBlockPosition); if (block.ischild) { continue; } // if its not a listed block, then keep searching. if (!lstBlocks.Contains(block.Block.GetBlockName())) { continue; } localLists.Add(TargetBlockPosition.ToVector3()); } } } } return(localLists); }