public void Event_Noise(Position pos, NoiseType type) { long range = NoiseRanges[type]; foreach (Entitys.Entity e in GetEntitys_Range(pos, range)) { e.Event_Noise(pos, 1 - pos.Distance(e.Pos) / range); } }
public List<Entitys.Entity> GetEntitys_Range(Position pos, long range) { List<Entitys.Entity> Entitys = new List<Entitys.Entity>(); List<Position> ChunksInRange = new List<Position>(); Position Chunk_Start = GetChunkPosition(pos.translate(-range, -range, -range)); Position Chunk_End = GetChunkPosition(pos.translate(range, range, range)); //Get all chunks in range for (long x = Chunk_Start.x; x <= Chunk_End.x; x++) { for (long y = Chunk_Start.y; y <= Chunk_End.y; y++) { for (long z = Chunk_Start.z; z <= Chunk_End.z; z++) { ChunksInRange.Add(new Position(x, y, z)); } } } //Get all entitys in range foreach (Position p in ChunksInRange) { List<Entitys.Entity> ChunkEntitys = GetChunk(p).Entitys; foreach (Entitys.Entity e in ChunkEntitys) { if (pos.Distance(e.Pos) <= range) { Entitys.Add(e); } } } return Entitys; }