2022-10-22 17:03:43 +02:00
|
|
|
#ifndef MAPBLOCK_H
|
|
|
|
#define MAPBLOCK_H
|
|
|
|
#include "Base.h"
|
2022-10-23 23:44:58 +02:00
|
|
|
#include <math.h>
|
2022-10-30 20:43:20 +01:00
|
|
|
#include <cstdio>
|
2022-10-23 23:44:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
|
2022-10-30 16:53:41 +01:00
|
|
|
class MapBlock
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-10-30 17:56:14 +01:00
|
|
|
int mapBlock[65536];
|
2022-10-22 17:03:43 +02:00
|
|
|
|
2022-10-30 16:53:41 +01:00
|
|
|
MapBlock()
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
|
|
|
|
2022-10-23 23:44:58 +02:00
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
2022-10-23 23:44:58 +02:00
|
|
|
|
2022-10-30 20:43:20 +01:00
|
|
|
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;
|
|
|
|
}
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
void addNode(int id, int meta, int x, int y, int z)
|
|
|
|
{
|
|
|
|
mapBlock[256 * y + z * 16 + x] = id;
|
|
|
|
}
|
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class BlockUtilities
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BlockUtilities()
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 17:56:14 +01:00
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
static Position2D getBlockFromNodeCoordinates(int x, int z)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 17:56:14 +01:00
|
|
|
Position2D pos2d;
|
|
|
|
pos2d.x = floor(x / 16);
|
|
|
|
pos2d.z = floor(z / 16);
|
|
|
|
return pos2d;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-23 23:44:58 +02:00
|
|
|
class BlockManager
|
|
|
|
{
|
2022-10-26 23:13:48 +02:00
|
|
|
public:
|
2022-10-30 17:56:14 +01:00
|
|
|
MapBlock mapBlocks[16][16]; // 16 x 16 blocks
|
2022-10-26 23:13:48 +02:00
|
|
|
|
2022-10-29 05:47:09 +02:00
|
|
|
BlockManager()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
int getNodeAt(int x, int y, int z)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 17:56:14 +01:00
|
|
|
//if(x < 16 && x >= 0 && z < 16 && z >= 0)
|
|
|
|
//{
|
2022-10-30 22:05:11 +01:00
|
|
|
if(x < 0 || y < 0 || z < 0)
|
2022-10-30 20:43:20 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2022-10-30 17:56:14 +01:00
|
|
|
|
2022-10-30 20:43:20 +01:00
|
|
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
|
|
|
//printf("\n\nold x: %i, old z: %i", x, z);
|
2022-10-30 22:05:11 +01:00
|
|
|
int localX = x - block.x * 16;
|
|
|
|
int localZ = z - block.z * 16;
|
2022-10-30 20:43:20 +01:00
|
|
|
//printf("\nnew x: %i, new z: %i", x, z);
|
2022-10-30 22:05:11 +01:00
|
|
|
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);
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
bool isAir(int x, int y, int z)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 17:56:14 +01:00
|
|
|
return getNodeAt(x, y, z) == 0;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
2022-10-23 23:44:58 +02:00
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
private:
|
2022-10-23 23:44:58 +02:00
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
};
|
2022-10-23 23:44:58 +02:00
|
|
|
|
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
#endif
|