|
@@ -189,12 +189,8 @@ void Dimension::thread()
|
|
|
{
|
|
|
if (chunk)
|
|
|
{
|
|
|
- int x = position.x % CHUNK_SIZE;
|
|
|
- int y = position.y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
- unsigned char* light
|
|
|
- = chunk->getLightData(Vec3<int>(x, y, position.z));
|
|
|
+ Vec3<int> chunkPos = chunkCoordinates(position);
|
|
|
+ unsigned char* light = chunk->getLightData(chunkPos);
|
|
|
unsigned char dayLight[6] = {255, 255, 255, 0, 0, 0};
|
|
|
unsigned char noLight[6] = {0, 0, 0, 0, 0, 0};
|
|
|
unsigned char newLight[6] = {0, 0, 0, 0, 0, 0};
|
|
@@ -217,13 +213,9 @@ void Dimension::thread()
|
|
|
Chunk* neighborChunk
|
|
|
= zChunk(Game::INSTANCE->getChunkCenter(
|
|
|
neighborPos.x, neighborPos.y));
|
|
|
- int x = neighborPos.x % CHUNK_SIZE;
|
|
|
- int y = neighborPos.y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
if (neighborChunk)
|
|
|
neighborLeight = neighborChunk->getLightData(
|
|
|
- Vec3<int>(x, y, neighborPos.z));
|
|
|
+ chunkCoordinates(neighborPos));
|
|
|
else
|
|
|
neighborLeight = noLight;
|
|
|
}
|
|
@@ -248,7 +240,7 @@ void Dimension::thread()
|
|
|
{
|
|
|
if (newLight[i] != light[i])
|
|
|
{
|
|
|
- chunk->setLightData(Vec3<int>(x, y, position.z),
|
|
|
+ chunk->setLightData(chunkPos,
|
|
|
newLight,
|
|
|
isForeground);
|
|
|
for (int j = 0; j < 6; j++)
|
|
@@ -329,11 +321,8 @@ Framework::Either<Block*, int> Dimension::zBlock(Vec3<int> location)
|
|
|
Chunk* c = zChunk(Game::INSTANCE->getChunkCenter(location.x, location.y));
|
|
|
if (c)
|
|
|
{
|
|
|
- int x = location.x % CHUNK_SIZE;
|
|
|
- int y = location.y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
- return c->zBlockAt(Vec3<int>(x, y, location.z));
|
|
|
+ location = chunkCoordinates(location);
|
|
|
+ return c->zBlockAt(location);
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
@@ -343,12 +332,9 @@ Block* Dimension::zRealBlockInstance(Framework::Vec3<int> location)
|
|
|
Chunk* c = zChunk(Game::INSTANCE->getChunkCenter(location.x, location.y));
|
|
|
if (c)
|
|
|
{
|
|
|
- int x = location.x % CHUNK_SIZE;
|
|
|
- int y = location.y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
- c->instantiateBlock(Vec3<int>(x, y, location.z));
|
|
|
- auto result = c->zBlockAt(Vec3<int>(x, y, location.z));
|
|
|
+ location = chunkCoordinates(location);
|
|
|
+ c->instantiateBlock(location);
|
|
|
+ auto result = c->zBlockAt(location);
|
|
|
return result.isA() ? result.getA() : 0;
|
|
|
}
|
|
|
return 0;
|
|
@@ -359,11 +345,8 @@ const Block* Dimension::zBlockOrDefault(Framework::Vec3<int> location)
|
|
|
Chunk* c = zChunk(Game::INSTANCE->getChunkCenter(location.x, location.y));
|
|
|
if (c)
|
|
|
{
|
|
|
- int x = location.x % CHUNK_SIZE;
|
|
|
- int y = location.y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
- return c->zBlockConst(Vec3<int>(x, y, location.z));
|
|
|
+ location = chunkCoordinates(location);
|
|
|
+ return c->zBlockConst(location);
|
|
|
}
|
|
|
return &NoBlock::INSTANCE;
|
|
|
}
|
|
@@ -374,16 +357,13 @@ void Dimension::placeBlock(
|
|
|
Chunk* c = zChunk(Game::getChunkCenter(location.x, location.y));
|
|
|
if (c)
|
|
|
{
|
|
|
- int x = location.x % CHUNK_SIZE;
|
|
|
- int y = location.y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
+ location = chunkCoordinates(location);
|
|
|
if (block.isA())
|
|
|
- c->putBlockAt(Vec3<int>(x, y, location.z), block);
|
|
|
+ c->putBlockAt(location, block);
|
|
|
else
|
|
|
{
|
|
|
- c->putBlockAt(Vec3<int>(x, y, location.z), 0);
|
|
|
- c->putBlockTypeAt(Vec3<int>(x, y, location.z), block);
|
|
|
+ c->putBlockAt(location, 0);
|
|
|
+ c->putBlockTypeAt(location, block);
|
|
|
}
|
|
|
}
|
|
|
else if (block.isA())
|
|
@@ -395,11 +375,8 @@ void Dimension::sendBlockInfo(Framework::Vec3<int> location)
|
|
|
Chunk* c = zChunk(Game::getChunkCenter(location.x, location.y));
|
|
|
if (c)
|
|
|
{
|
|
|
- int x = location.x % CHUNK_SIZE;
|
|
|
- int y = location.y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
- c->sendBlockInfo(Vec3<int>(x, y, location.z));
|
|
|
+ location = chunkCoordinates(location);
|
|
|
+ c->sendBlockInfo(location);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -902,16 +879,16 @@ void Dimension::updateMap(int x, int y, int height)
|
|
|
ChunkMap* cMap = map->getMap(addr, 8, center);
|
|
|
if (cMap)
|
|
|
{
|
|
|
- x = x % CHUNK_SIZE;
|
|
|
- y = y % CHUNK_SIZE;
|
|
|
- if (x < 0) x += CHUNK_SIZE;
|
|
|
- if (y < 0) y += CHUNK_SIZE;
|
|
|
- if (cMap->update(
|
|
|
- (char)x, (char)y, (unsigned char)(height / 2), color1, color2)
|
|
|
+ Framework::Vec3<int> chunkLocation = chunkCoordinates({x, y, height});
|
|
|
+ if (cMap->update((char)chunkLocation.x,
|
|
|
+ (char)chunkLocation.y,
|
|
|
+ (unsigned char)(chunkLocation.z / 2),
|
|
|
+ color1,
|
|
|
+ color2)
|
|
|
|| (h1 > 0
|
|
|
- && cMap->update((char)x,
|
|
|
- (char)y,
|
|
|
- (unsigned char)(height / 2) - 1,
|
|
|
+ && cMap->update((char)chunkLocation.x,
|
|
|
+ (char)chunkLocation.y,
|
|
|
+ (unsigned char)(chunkLocation.z / 2) - 1,
|
|
|
color1m,
|
|
|
color2m)))
|
|
|
{
|