public void LoadChunk(Pos.ChunkPos pos) { Pos.ChunkPos regionPos = new Pos.BlockPos(pos.X, pos.Y, pos.Z).ToChunk(); string region = regionPos.X.ToString() + "." + regionPos.Y.ToString() + "." + regionPos.Z.ToString(); if (!Regions.ContainsKey(region)) { LoadRegion(region); } if (Regions[region].GetChunk(pos) == null) { Regions[region].SetChunk(pos, GenerateChunk(pos)); } }
public Block GetBlock(Pos.BlockPos pos) //retrieves a block from anywhere in the world { Pos.ChunkPos p = pos.ToChunk(); Pos.ChunkPos regionPos = new Pos.BlockPos(p.X, p.Y, p.Z).ToChunk(); string region = regionPos.X.ToString() + "." + regionPos.Y.ToString() + "." + regionPos.Z.ToString(); if (Regions.ContainsKey(region)) { Chunk c = Regions[region].GetChunk(p.Normalize()); if (c != null) { return(c.GetBlock(pos.Normalize())); } } return(null); }
public Chunk GenerateChunk(Pos.ChunkPos pos) { Chunk c = new Chunk(); for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { if (pos.Y < 0) { c.SetBlock(new Pos.BlockPos(x, y, z), new Block() { id = 1 }); } } } } return(c); }
public void SetChunk(Pos.ChunkPos pos, Chunk c) { pos = pos.Normalize(); Chunks[pos.X, pos.Y, pos.Z] = c; }
public Chunk GetChunk(Pos.ChunkPos pos) { pos = pos.Normalize(); return(Chunks[pos.X, pos.Y, pos.Z]); }