public static Chunk LoadChunkImmediate(Chunk chunk) { FileStream chunkStream = File.OpenRead(GetChunkFilename(chunk.Index)); for (int x = 0; x < Constants.World.ChunkSize; x++) { for (int y = 0; y < Constants.World.ChunkSize; y++) { for (int z = 0; z < Constants.World.ChunkSize; z++) { chunk[x, y, z] = new Block((byte)chunkStream.ReadByte()); } } } return chunk; }
public static void SetBlock(BlockIndex index, Block block) { Chunk chunk = GetChunk(new ChunkIndex(index)); if (chunk == null) { throw new Exception("You stupid asshole!"); } chunk[EuclideanModulo(index.X, Constants.World.ChunkSize), EuclideanModulo(index.Y, Constants.World.ChunkSize), EuclideanModulo(index.Z, Constants.World.ChunkSize)] = block; ChunkIndex? actualIndex = GetArrayIndex(chunk.Index); if (actualIndex.HasValue) { GL.BindTexture(TextureTarget.Texture3D, DataID); GL.TexSubImage3D(TextureTarget.Texture3D, 0, actualIndex.Value.X * Constants.World.ChunkSize + EuclideanModulo(index.X, Constants.World.ChunkSize), actualIndex.Value.Y * Constants.World.ChunkSize + EuclideanModulo(index.Y, Constants.World.ChunkSize), actualIndex.Value.Z * Constants.World.ChunkSize + EuclideanModulo(index.Z, Constants.World.ChunkSize), 1, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Luminance, PixelType.UnsignedByte, new byte[,,] { { { block.ByteValue } } }); } }
public void SetBlock(BlockIndex index, Block value, bool updateAdjacentChunks) { if (index.X >= 0 && index.X < Constants.World.ChunkSize && index.Y >= 0 && index.Y < Constants.World.ChunkSize && index.Z >= 0 && index.Z < Constants.World.ChunkSize) { Data[index.Z, index.Y, index.X] = value; if (updateAdjacentChunks) { if (index.X == 0) { Chunk chunk = ChunkManager.GetChunk(Index - ChunkIndex.UnitX); } else if (index.X == Constants.World.ChunkSize - 1) { Chunk chunk = ChunkManager.GetChunk(Index + ChunkIndex.UnitX); } if (index.Y == 0) { Chunk chunk = ChunkManager.GetChunk(Index - ChunkIndex.UnitY); } else if (index.Y == Constants.World.ChunkSize - 1) { Chunk chunk = ChunkManager.GetChunk(Index + ChunkIndex.UnitY); } if (index.Z == 0) { Chunk chunk = ChunkManager.GetChunk(Index - ChunkIndex.UnitZ); } else if (index.Z == Constants.World.ChunkSize - 1) { Chunk chunk = ChunkManager.GetChunk(Index + ChunkIndex.UnitZ); } } } }