#include "chunk.h"

vector3 index_to_coord(int i) {
	vector3 pos;
	pos.x = i % WIDTH;
	pos.z = (i / WIDTH) % WIDTH;
	pos.y = i / (WIDTH * WIDTH);

	return pos;
}

int coord_to_index(vector3 coord) {
	int index = coord.x + coord.z * WIDTH + coord.y * WIDTH * WIDTH;
	return index;
}

int get_block_at(int* chunk, vector3 pos) {
	if (pos.x < 0 || pos.x >= WIDTH || pos.z < 0 || pos.z >= WIDTH || pos.y < 0 || pos.y >= HEIGHT) return 0;
	return chunk[coord_to_index(pos)];
}
