XtreemNodes/MapBlock.cpp

78 lines
1.6 KiB
C++

#include "MapBlock.h"
int mapBlock[65536];
MapBlock::MapBlock()
{
}
void BlockManager::addNode(int id, int meta, int x, int y, int z)
{
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
int localX = x - block.x * 16;
int localZ = z - block.z * 16;
mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX] = id;
}
MapBlock mapBlocks[16][16];
BlockManager::BlockManager()
{
}
int BlockManager::getNodeAt(int x, int y, int z)
{
// Math explanation for future reference:
// The x and z coordinates need to be have block.[AXIS] * 16 subtracted from them
// so that the coordinates passed to the function are local block coordinates instead
// of global node coordinates (e.g. 1, and not 17)
if(x < 0 || y < 0 || z < 0)
{
return 0;
}
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
int localX = x - block.x * 16;
int localZ = z - block.z * 16;
return mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX];
}
bool BlockManager::isAir(int x, int y, int z)
{
return getNodeAt(x, y, z) == 0;
}
bool BlockManager::isNodeClear(int x, int y, int z)
{
if(getNodeAt(x, y, z) == 0)
return true;
if(getNodeAt(x, y, z) == 20)
return true;
return false;
}
BlockUtilities::BlockUtilities()
{
}
Position2D BlockUtilities::getBlockFromNodeCoordinates(int x, int z)
{
Position2D pos2d;
//pos2d.x = floor(x / 16);
//pos2d.z = floor(z / 16);
pos2d.x = x >> 4;
pos2d.z = z >> 4;
return pos2d;
}