2021-11-15 20:58:13 -05:00
|
|
|
#include "world.h"
|
|
|
|
|
|
|
|
World::World(){}
|
|
|
|
|
|
|
|
World::~World(){}
|
|
|
|
|
|
|
|
Array2d<Chunk*>& World::GetChunks() { return m_chunks; }
|
2021-11-15 21:39:50 -05:00
|
|
|
|
|
|
|
Chunk* World::ChunkAt(float x, float y, float z) const {
|
|
|
|
int cx = (int)x / CHUNK_SIZE_X;
|
|
|
|
int cz = (int)z / CHUNK_SIZE_Z;
|
|
|
|
|
2021-11-19 09:05:28 -05:00
|
|
|
if (x < 0 || y < 0 || z < 0 ||
|
2021-11-26 11:59:02 -05:00
|
|
|
x >= WORLD_SIZE_X * CHUNK_SIZE_X || z >= CHUNK_SIZE_Z * WORLD_SIZE_Y || y > CHUNK_SIZE_Y)
|
2021-11-19 09:06:09 -05:00
|
|
|
return 0;
|
2021-11-15 21:39:50 -05:00
|
|
|
|
|
|
|
return m_chunks.Get(cx, cz);
|
|
|
|
}
|
|
|
|
|
|
|
|
Chunk* World::ChunkAt(const Vector3f& pos) const { return ChunkAt(pos.x, pos.y, pos.z); }
|
|
|
|
|
|
|
|
BlockType World::BlockAt(float x, float y, float z, BlockType defaultBlockType) const {
|
|
|
|
Chunk* c = ChunkAt(x, y, z);
|
|
|
|
|
|
|
|
if (!c)
|
|
|
|
return defaultBlockType;
|
|
|
|
|
|
|
|
int bx = (int)x % CHUNK_SIZE_X;
|
|
|
|
int by = (int)y % CHUNK_SIZE_Y;
|
|
|
|
int bz = (int)z % CHUNK_SIZE_Z;
|
|
|
|
|
|
|
|
return c->GetBlock(bx, by, bz);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockType World::BlockAt(const Vector3f& pos, BlockType defaultBlockType) const {
|
|
|
|
return BlockAt(pos.x, pos.y, pos.z, defaultBlockType);
|
|
|
|
}
|
2021-11-30 19:55:11 -05:00
|
|
|
|