summaryrefslogtreecommitdiffstats
path: root/source/Chunk.cpp
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2013-10-21 22:38:38 +0200
committerSamuel Barney <samjbarney@gmail.com>2013-10-21 22:38:38 +0200
commit6e361f195fa61ff6585f78dd7cd7302b1dba5619 (patch)
tree78d6964621093b963a48dc9d870028d5775df862 /source/Chunk.cpp
parentSwapped which block is checked for light first. (diff)
downloadcuberite-6e361f195fa61ff6585f78dd7cd7302b1dba5619.tar
cuberite-6e361f195fa61ff6585f78dd7cd7302b1dba5619.tar.gz
cuberite-6e361f195fa61ff6585f78dd7cd7302b1dba5619.tar.bz2
cuberite-6e361f195fa61ff6585f78dd7cd7302b1dba5619.tar.lz
cuberite-6e361f195fa61ff6585f78dd7cd7302b1dba5619.tar.xz
cuberite-6e361f195fa61ff6585f78dd7cd7302b1dba5619.tar.zst
cuberite-6e361f195fa61ff6585f78dd7cd7302b1dba5619.zip
Diffstat (limited to 'source/Chunk.cpp')
-rw-r--r--source/Chunk.cpp111
1 files changed, 100 insertions, 11 deletions
diff --git a/source/Chunk.cpp b/source/Chunk.cpp
index 5a54371ad..ea6fed50c 100644
--- a/source/Chunk.cpp
+++ b/source/Chunk.cpp
@@ -539,17 +539,10 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner)
// MG TODO: fix the "light" thing, I'm pretty sure that UnboundedRelGetBlock s not returning the right thing
// MG TODO : check that "Level" really means Y
- NIBBLETYPE SkyLight = GetSkyLight(Try_X, Try_Y, Try_Z);
- if (!SkyLight)
- SkyLight = GetSkyLight(Try_X, Try_Y + 1, Try_Z);
- if (!SkyLight)
- SkyLight = GetSkyLight(Try_X, Try_Y - 1, Try_Z);
-
- NIBBLETYPE BlockLight = GetBlockLight(Try_X, Try_Y, Try_Z);
- if (!BlockLight)
- BlockLight = GetBlockLight(Try_X, Try_Y + 1, Try_Z);
- if (!BlockLight)
- BlockLight = GetBlockLight(Try_X, Try_Y - 1, Try_Z);
+
+ NIBBLETYPE SkyLight = UnboundedRelGetSkyLight(Try_X, Try_Y, Try_Z);
+
+ NIBBLETYPE BlockLight = UnboundedRelGetBlockLight(Try_X, Try_Y, Try_Z);
if (IsLightValid())
{
@@ -1363,6 +1356,102 @@ void cChunk::UnboundedQueueTickBlock(int a_RelX, int a_RelY, int a_RelZ)
+NIBBLETYPE cChunk::UnboundedRelGetSkyLight(int a_RelX, int a_RelY, int a_RelZ)
+{
+if ((a_RelY < 0) || (a_RelY > cChunkDef::Height))
+ {
+ LOGWARNING("UnboundedRelGetSkyLight(): requesting a block with a_RelY out of range: %d", a_RelY);
+ return -1;
+ }
+
+ // Is it in this chunk?
+ if ((a_RelX >= 0) && (a_RelX < cChunkDef::Width) && (a_RelZ >= 0) && (a_RelZ < cChunkDef::Width))
+ {
+ if (!IsValid())
+ {
+ return -1;
+ }
+ return GetSkyLight(a_RelX, a_RelY, a_RelZ);
+ }
+
+ // Not in this chunk, try walking the neighbors first:
+ if ((a_RelX < 0) && (m_NeighborXM != NULL))
+ {
+ return m_NeighborXM->UnboundedRelGetSkyLight(a_RelX + cChunkDef::Width, a_RelY, a_RelZ);
+ }
+ if ((a_RelX >= cChunkDef::Width) && (m_NeighborXP != NULL))
+ {
+ return m_NeighborXP->UnboundedRelGetSkyLight(a_RelX - cChunkDef::Width, a_RelY, a_RelZ);
+ }
+ if ((a_RelZ < 0) && (m_NeighborZM != NULL))
+ {
+ return m_NeighborZM->UnboundedRelGetSkyLight(a_RelX, a_RelY, a_RelZ + cChunkDef::Width);
+ }
+ if ((a_RelZ >= cChunkDef::Width) && (m_NeighborZP != NULL))
+ {
+ return m_NeighborZP->UnboundedRelGetSkyLight(a_RelX, a_RelY, a_RelZ - cChunkDef::Width);
+ }
+
+ // Neighbors not available, use the chunkmap to locate the chunk:
+ return m_ChunkMap->GetBlockSkyLight(
+ m_PosX * cChunkDef::Width + a_RelX,
+ ZERO_CHUNK_Y * cChunkDef::Height + a_RelY,
+ m_PosZ * cChunkDef::Width + a_RelZ
+ );
+}
+
+
+
+
+
+NIBBLETYPE cChunk::UnboundedRelGetBlockLight(int a_RelX, int a_RelY, int a_RelZ)
+{
+if ((a_RelY < 0) || (a_RelY > cChunkDef::Height))
+ {
+ LOGWARNING("UnboundedRelGetBlockLight(): requesting a block with a_RelY out of range: %d", a_RelY);
+ return -1;
+ }
+
+ // Is it in this chunk?
+ if ((a_RelX >= 0) && (a_RelX < cChunkDef::Width) && (a_RelZ >= 0) && (a_RelZ < cChunkDef::Width))
+ {
+ if (!IsValid())
+ {
+ return -1;
+ }
+ return GetBlockLight(a_RelX, a_RelY, a_RelZ);
+ }
+
+ // Not in this chunk, try walking the neighbors first:
+ if ((a_RelX < 0) && (m_NeighborXM != NULL))
+ {
+ return m_NeighborXM->UnboundedRelGetBlockLight(a_RelX + cChunkDef::Width, a_RelY, a_RelZ);
+ }
+ if ((a_RelX >= cChunkDef::Width) && (m_NeighborXP != NULL))
+ {
+ return m_NeighborXP->UnboundedRelGetBlockLight(a_RelX - cChunkDef::Width, a_RelY, a_RelZ);
+ }
+ if ((a_RelZ < 0) && (m_NeighborZM != NULL))
+ {
+ return m_NeighborZM->UnboundedRelGetBlockLight(a_RelX, a_RelY, a_RelZ + cChunkDef::Width);
+ }
+ if ((a_RelZ >= cChunkDef::Width) && (m_NeighborZP != NULL))
+ {
+ return m_NeighborZP->UnboundedRelGetBlockLight(a_RelX, a_RelY, a_RelZ - cChunkDef::Width);
+ }
+
+ // Neighbors not available, use the chunkmap to locate the chunk:
+ return m_ChunkMap->GetBlockBlockLight(
+ m_PosX * cChunkDef::Width + a_RelX,
+ ZERO_CHUNK_Y * cChunkDef::Height + a_RelY,
+ m_PosZ * cChunkDef::Width + a_RelZ
+ );
+}
+
+
+
+
+
int cChunk::GetHeight( int a_X, int a_Z )
{
ASSERT((a_X >= 0) && (a_X < Width) && (a_Z >= 0) && (a_Z < Width));