/** * Calculates the lookup coordinates. */ public void CalculateLookupCoordinates() { this.poweredBlockCoords = new List <Vector3i>(); this.heatedBlockCoords = new List <Vector3i>(); this.nearbyBlockCoords = new List <Vector3i>(); World world = GameManager.Instance.World; Vector3i tileEntityPos = this.ToWorldPos(); this.poweredBlockCoords = CoordinateHelper.GetCoOrdinatesAround(tileEntityPos, true, 1, 1, 1); this.heatedBlockCoords.Add(CoordinateHelper.GetCoordinateBelow(tileEntityPos)); this.nearbyBlockCoords = CoordinateHelper.GetCoOrdinatesAround(tileEntityPos, this.nearbyBlockRange); }
/** * Checks if block is powered. It is required to be next to an electric wire relay. */ private bool IsPowered() { if (!this.requiresPower) { return(true); } World world = GameManager.Instance.World; Vector3i tileEntityPos = this.ToWorldPos(); List <Vector3i> nearby = CoordinateHelper.GetCoOrdinatesAround(tileEntityPos, true, 1, 1, 1); if (nearby.Count == 0) { return(false); } Dictionary <Vector3i, TileEntity> tileEntitiesNearby = CoordinateHelper.GetTileEntitiesInCoordinates(world, nearby, TileEntityType.Powered); if (tileEntitiesNearby.Count == 0) { return(false); } foreach (KeyValuePair <Vector3i, TileEntity> entry in tileEntitiesNearby) { TileEntityPowered otherTileEntity = entry.Value as TileEntityPowered; Vector3i otherTileEntityPos = entry.Key; foreach (string powerSource in this.powerSources) { string name = CoordinateHelper.GetBlockNameAtCoordinate(world, otherTileEntityPos); if (!CoordinateHelper.BlockAtCoordinateIs(world, otherTileEntityPos, powerSource)) { continue; } if (otherTileEntity.IsPowered) { return(true); } } } return(false); }
/** * Executing the upgrades */ public override void Execute(MinEventParams _params) { if (GameManager.Instance.World == null) { return; } World world = GameManager.Instance.World; for (int i = 0; i < this.targets.Count; i++) { Log.Out("Checking for Entity"); if (this.targets[i] as Entity == null) { Log.Out("Null, continue"); continue; } Vector3i currentPosition = new Vector3i(this.targets[i].GetPosition()); Dictionary <Vector3i, Block> blockPositions = CoordinateHelper.GetBlocksFromCoordinates(world, CoordinateHelper.GetCoOrdinatesAround(currentPosition, this.range)); foreach (KeyValuePair <Vector3i, Block> entry in blockPositions) { Block blockToCheck = entry.Value; if (blockToCheck.GetBlockName() != this.blockName) { continue; } BlockHelpers.DoBlockUpgrade(entry.Key, this.targets[i], this.requireMaterials); } } }