/** * Checks if block is powered. It is required to be next to a TileEntityPowered type of block in any cardinal direction. */ public bool IsPowered() { if (!this.CanTick()) { return(this.hasPower); } if (!this.requiresPower) { return(this.hasPower = true); } if (this.poweredBlockCoords.Count == 0) { return(this.hasPower = false); } World world = GameManager.Instance.World; Dictionary <Vector3i, TileEntity> tileEntitiesNearby = CoordinateHelper.GetTileEntitiesInCoordinatesWithType(world, this.poweredBlockCoords, TileEntityType.Powered); if (tileEntitiesNearby.Count == 0) { return(this.hasPower = 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(this.hasPower = true); } } } return(this.hasPower = false); }
/** * 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); }