#ifndef MAPBLOCK_H #define MAPBLOCK_H #include "Base.h" #include #include class MapBlock { public: int mapBlock[65536]; MapBlock() { } int getNodeAt(int x, int y, int z) // Deprecated; only used internally. { return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0; } void addNode(int id, int meta, int x, int y, int z) { mapBlock[256 * y + z * 16 + x] = id; } }; class BlockUtilities { public: BlockUtilities() { } static Position2D getBlockFromNodeCoordinates(int x, int z) { Position2D pos2d; pos2d.x = floor(x / 16); pos2d.z = floor(z / 16); return pos2d; } }; class BlockManager { public: MapBlock mapBlocks[16][16]; // 16 x 16 blocks BlockManager() { } int getNodeAt(int x, int y, int z) { //if(x < 16 && x >= 0 && z < 16 && z >= 0) //{ if(x < 0 || y < 0 || z < 0) { return 0; } Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); //printf("\n\nold x: %i, old z: %i", x, z); int localX = x - block.x * 16; int localZ = z - block.z * 16; //printf("\nnew x: %i, new z: %i", x, z); return mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX]; //return mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16); } bool isAir(int x, int y, int z) { return getNodeAt(x, y, z) == 0; } private: }; #endif