private static List <Chunk> zdirFunction(int zdir, int3 offset) { List <Chunk> chunksToBeDrawn = new List <Chunk>(); if (zdir >= 1) { for (int i = 0; i < zdir; i++) { ChunkWorldPositionOffset.z += 1; for (int x = 0; x < worldChunkSize.x; x++) { for (int y = 0; y < worldChunkSize.y; y++) { for (int z = 0; z < worldChunkSize.z; z++) { if (z == 0) { //MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]); MeshGeneration.AddToRemoveQueue(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z + 1].AddChunkDrawdataToMeshQueue)); } else if (z == worldChunkSize.z - 1) { int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z); WorldInitializer.setChunk(x, y, z, new Chunk(pos, offset)); if (!WorldInitializer.getChunk(x, y, z).anyNonAir) { continue; } chunksToBeDrawn.Add(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z - 1].AddChunkDrawdataToMeshQueue)); } else { //chunks[x, y, z] = chunks[x, y, z + 1]; WorldInitializer.setChunk(x, y, z, WorldInitializer.getChunk(x, y, z + 1)); } } } } } } else if (zdir <= -1) { for (int i = 0; i > zdir; i--) { ChunkWorldPositionOffset.z -= 1; for (int x = worldChunkSize.x - 1; x >= 0; x--) { for (int y = worldChunkSize.y - 1; y >= 0; y--) { for (int z = worldChunkSize.z - 1; z >= 0; z--) { if (z == (worldChunkSize.z - 1)) { //MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]); MeshGeneration.AddToRemoveQueue(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z - 1].AddChunkDrawdataToMeshQueue)); } else if (z == 0) { int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z); WorldInitializer.setChunk(x, y, z, new Chunk(pos, offset)); if (!WorldInitializer.getChunk(x, y, z).anyNonAir) { continue; } chunksToBeDrawn.Add(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z + 1].AddChunkDrawdataToMeshQueue)); } else { //chunks[x, y, z] = chunks[x, y, z - 1]; WorldInitializer.setChunk(x, y, z, WorldInitializer.getChunk(x, y, z - 1)); } } } } } } return(chunksToBeDrawn); }
private BlockType[] getNeighbourBlocks(int x, int y, int z) { int3 offset = InfiniteWorld.ChunkWorldPositionOffset; int3 arrayBasedChunkPos = new int3(chunkPosWorld.x - offset.x, chunkPosWorld.y - offset.y, chunkPosWorld.z - offset.z); BlockType x_minus; BlockType x_plus; BlockType y_minus; BlockType y_plus; BlockType z_minus; BlockType z_plus; int xKey, yKey, zKey; //Xminus if (x - 1 >= 0) { //x_minus = blocks[x - 1, y, z].blockType; x_minus = getBlock(x - 1, y, z); } else { //key = new int3(arrayBasedChunkPos.x - 1, arrayBasedChunkPos.y, arrayBasedChunkPos.z); xKey = arrayBasedChunkPos.x - 1; yKey = arrayBasedChunkPos.y; zKey = arrayBasedChunkPos.z; if (WorldInitializer.chunkArrayContainsKey(xKey, yKey, zKey)) { x_minus = WorldInitializer.getChunk(xKey, yKey, zKey).getBlock(CONST.chunkSize.x - 1, y, z); } else { x_minus = BlockType.Air; } } //Xplus if (x + 1 <= CONST.chunkSize.x - 1) { x_plus = getBlock(x + 1, y, z); } else { xKey = arrayBasedChunkPos.x + 1; yKey = arrayBasedChunkPos.y; zKey = arrayBasedChunkPos.z; if (WorldInitializer.chunkArrayContainsKey(xKey, yKey, zKey)) { x_plus = WorldInitializer.getChunk(xKey, yKey, zKey).getBlock(0, y, z); } else { x_plus = BlockType.Air; } } //Yminus if (y - 1 >= 0) { y_minus = getBlock(x, y - 1, z); } else { xKey = arrayBasedChunkPos.x; yKey = arrayBasedChunkPos.y - 1; zKey = arrayBasedChunkPos.z; if (WorldInitializer.chunkArrayContainsKey(xKey, yKey, zKey)) { y_minus = WorldInitializer.getChunk(xKey, yKey, zKey).getBlock(x, CONST.chunkSize.y - 1, z); } else { y_minus = BlockType.Air; } } //Yplus if (y + 1 <= CONST.chunkSize.y - 1) { y_plus = getBlock(x, y + 1, z); } else { xKey = arrayBasedChunkPos.x; yKey = arrayBasedChunkPos.y + 1; zKey = arrayBasedChunkPos.z; if (WorldInitializer.chunkArrayContainsKey(xKey, yKey, zKey)) { y_plus = WorldInitializer.getChunk(xKey, yKey, zKey).getBlock(x, 0, z); } else { y_plus = BlockType.Air; } } //Zminus if (z - 1 >= 0) { z_minus = getBlock(x, y, z - 1); } else { xKey = arrayBasedChunkPos.x; yKey = arrayBasedChunkPos.y; zKey = arrayBasedChunkPos.z - 1; if (WorldInitializer.chunkArrayContainsKey(xKey, yKey, zKey)) { z_minus = WorldInitializer.getChunk(xKey, yKey, zKey).getBlock(x, y, CONST.chunkSize.z - 1); } else { z_minus = BlockType.Air; } } //Zplus if (z + 1 <= CONST.chunkSize.z - 1) { z_plus = getBlock(x, y, z + 1); } else { xKey = arrayBasedChunkPos.x; yKey = arrayBasedChunkPos.y; zKey = arrayBasedChunkPos.z + 1; if (WorldInitializer.chunkArrayContainsKey(xKey, yKey, zKey)) { z_plus = WorldInitializer.getChunk(xKey, yKey, zKey).getBlock(x, y, 0); } else { z_plus = BlockType.Air; } } BlockType[] neighbours = new BlockType[6]; neighbours[0] = x_minus; neighbours[1] = x_plus; neighbours[2] = y_minus; neighbours[3] = y_plus; neighbours[4] = z_minus; neighbours[5] = z_plus; return(neighbours); }