Exemplo n.º 1
0
        public Block GetBlock(Vector3i Location)
        {
            MemoryCoordinate coords = new MemoryCoordinate(Location);
            MemoryChunk Return;

            if (Cache != null && Cache.Location == coords.ChunkCoord) {
                return Cache[coords.LocalCoords];
            }

            if (Blocks.TryGetValue(coords.ChunkCoord, out Return)) {
                Cache = Return;
                return Return[coords.LocalCoords];
            } else {
                return null;
            }
        }
Exemplo n.º 2
0
        public void SetBlock(Vector3i Location, Block Data)
        {
            MemoryCoordinate coords = new MemoryCoordinate(Location);
            MemoryChunk Return;

            if (Cache != null && Cache.Location == coords.ChunkCoord) {
                Cache[coords.LocalCoords] = Data;
                return;
            }

            if (Blocks.TryGetValue(coords.ChunkCoord, out Return)) {
                Return[coords.LocalCoords] = Data;
            } else {
                Return = new MemoryChunk(coords.ChunkCoord);
                Blocks[coords.ChunkCoord] = Return;
                Return[coords.LocalCoords] = Data;
            }
            Cache = Return;

            if (OnBlockChanged != null) {
                OnBlockChanged(Location);
            }
        }