public void SetBlock(Pos.BlockPos pos, Block b) //sets a block relative to a chunk { if (empty) { return; } pos = pos.Normalize(); blocks[pos.X, pos.Y, pos.Z] = b; }
public Block GetBlock(Pos.BlockPos pos) //returns a relative block from a chunk { if (empty) { return(null); } pos = pos.Normalize(); return(blocks[pos.X, pos.Y, pos.Z]); }
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 void DrawBlock(Pos.BlockPos p) //renders an individual block at coordinates p { GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); GL.Translate(p.X, p.Y, p.Z); for (int i = 0; i < 6; i++) { if (GetBlock(p + Pos.DIRECTIONS[i]) == null) //later will be IF NOT OPAQUE { Draw.DrawFace(i); } } GL.PopMatrix(); }
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); }