Please add a save function!
![Very Happy](images/smiles/icon_biggrin.gif)
struct mc_chunk = {
int8_t pos; // Position from center chunk, signed 8 bit int, -128 to 127, exists solely to be used during un/loading
uint8_t[150][25] chunk; // Matrix to store chunk itself
}
mc_chunk[9] world;
function unloadChunk(bool right) { // unloads chunk, default left chunk, right if passed true.
// Do C toolchain weird thingy to store world[right ? 0 : 8] in your world appvar
For (int i = right ? 0 : 8;right ? i>7 : i<1;right ? i++ : i--) {
world[right ? i+1 : i-1] = world[i];
}
world[right ? 0 : 8] = [empty chunk];
}
function loadChunk(int pos, bool right) { // pos corresponds to pos in chunk struct, loads chunk to the right by default
// C toolchain thingy to load chunk from world appvar, assuming the var is named just 'chunk'
unloadChunk(right);
world[right ? 0 : 8] = chunk;
}
// To see block in world from coord (more pseudo than code than above) (assuming chunk is loaded)
int x = whatever
int y = whatever
int chunkPos = int((x - (world[0].pos * 25))/25)
int blockID = world[y][x - chunkPos*25]
// It should be easy to adapt to writing blocks, now just dynamically load and unload chunks based on where the player is going and voila.
Advertisement