No matter what I try GetBlock always has neochunk return null, despite neochunk equaling the WorldPos put into the chunks Dictonary. For ex one of the chunks has a key of (0, 0, 4), but even when newpos is (0, 0, 4) neochunk is null.
public Matrix4x4 id = Matrix4x4.identity;
Chunk chunk;
WorldPos pos;
public Material material;
public int ViewDist = 4;
FindChunk chunkHelp;
private int chunksize = Chunk.chunksize;
public Dictionary<WorldPos, Chunk> chunks = new Dictionary<WorldPos, Chunk>();
private void Start() {
chunkHelp = new FindChunk();
for (int x = 0; x < ViewDist; x++){
for (int y = 0; y < ViewDist; y++){
for (int z = 0; z < ViewDist; z++){
chunk = new Chunk(new WorldPos(x * chunksize, y * chunksize, z * chunksize), this);
chunk.GenerateChunkArray();
chunks.Add(chunk.pos, chunk);
}
}
}
foreach(WorldPos pos in chunks.Keys){
Debug.Log(pos.x);
Debug.Log(pos.y);
Debug.Log(pos.z);
Debug.Log("Next");
}
foreach(Chunk chunk in chunks.Values){
chunk.GetMesh();
}
}
private void Update() {
foreach(Chunk chunk in chunks.Values){
Graphics.DrawMesh(chunk.mesh, id, material, 0);
}
}
public Blocks GetBlock(WorldPos pos, int x, int y, int z) {
WorldPos newpos = chunkHelp.ChunkToChunk(pos, x, y, z);
Chunk neochunk;
chunks.TryGetValue(newpos, out neochunk);
if (neochunk == null){
Debug.Log(newpos.x);
Debug.Log(newpos.y);
Debug.Log(newpos.z);
Debug.Log("Null chunk spot");
return Blocks.Air;
}
WorldPos nnpos = chunkHelp.ChunkToBlock(x, y, z);
return neochunk.blocks[nnpos.x, nnpos.y, nnpos.z];
}