public ChunkData Get(int x, int y) { if (lastChunk != null && lastChunkX == x && lastChunkY == y) { return(lastChunk); } ulong hashKey = BuildKey(x, y); ChunkData chunk = cache[hashKey] as ChunkData; if (chunk == null) { Console.WriteLine("[ChunkCache] Loading {0}, {1}", x, y); chunk = source.Load(x, y); // Failed to load chunk, generate a new one if (chunk == null) { chunk = generator.GenerateNewChunk(x, y); } cache[hashKey] = chunk; } lastChunkX = x; lastChunkY = y; lastChunk = chunk; return(chunk); }