summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-21 14:44:06 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-21 14:44:06 +0100
commitda4afc0cf3428dd63c3c7b6ba8fe7bab762254a8 (patch)
treea9d9a4e7c35d6139120b40048a9d6c3d064cb27a
parentFixed block-getting so that simulators work again (diff)
downloadcuberite-da4afc0cf3428dd63c3c7b6ba8fe7bab762254a8.tar
cuberite-da4afc0cf3428dd63c3c7b6ba8fe7bab762254a8.tar.gz
cuberite-da4afc0cf3428dd63c3c7b6ba8fe7bab762254a8.tar.bz2
cuberite-da4afc0cf3428dd63c3c7b6ba8fe7bab762254a8.tar.lz
cuberite-da4afc0cf3428dd63c3c7b6ba8fe7bab762254a8.tar.xz
cuberite-da4afc0cf3428dd63c3c7b6ba8fe7bab762254a8.tar.zst
cuberite-da4afc0cf3428dd63c3c7b6ba8fe7bab762254a8.zip
Diffstat (limited to '')
-rw-r--r--source/cChunk.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/source/cChunk.cpp b/source/cChunk.cpp
index 9f64716d0..5ac0a991c 100644
--- a/source/cChunk.cpp
+++ b/source/cChunk.cpp
@@ -543,9 +543,11 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
int cChunk::GetHeight( int a_X, int a_Z )
{
- if( a_X >= 0 && a_X < 16 && a_Z >= 0 && a_Z < 16 )
+ ASSERT((a_X >= 0) && (a_X < 16) && (a_Z >= 0) && (a_Z < 16));
+
+ if ((a_X >= 0) && (a_X < 16) && (a_Z >= 0) && (a_Z < 16))
{
- return m_HeightMap[a_X + a_Z*16];
+ return m_HeightMap[a_X + a_Z * 16];
}
return 0;
}
@@ -840,6 +842,7 @@ void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block
char OldBlockType = m_BlockType[index];
m_BlockType[index] = a_BlockType;
+ // It's called SetLight(), but it sets the Meta when passed the BlockMeta workspace
SetLight( m_BlockMeta, index, a_BlockMeta );
if ((OldBlockType == a_BlockType) && (OldBlockMeta == a_BlockMeta))
@@ -849,8 +852,26 @@ void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block
MarkDirty();
- cCSLock Lock(m_CSBlockLists);
- m_PendingSendBlocks.push_back( index );
+ {
+ cCSLock Lock(m_CSBlockLists);
+ m_PendingSendBlocks.push_back( index );
+ }
+
+ // ONLY recalculate lighting if it's necessary!
+ if(
+ (g_BlockLightValue[ OldBlockType ] != g_BlockLightValue[ a_BlockType ]) ||
+ (g_BlockSpreadLightFalloff[ OldBlockType ] != g_BlockSpreadLightFalloff[ a_BlockType ]) ||
+ (g_BlockTransparent[ OldBlockType ] != g_BlockTransparent[ a_BlockType ] )
+ )
+ {
+ RecalculateLighting();
+ }
+
+ // Update heightmap, if needed:
+ if (a_Y >= m_HeightMap[a_X + a_Z * 16])
+ {
+ m_HeightMap[a_X + a_Z * 16] = (a_BlockType == E_BLOCK_AIR) ? (a_Y - 1) : a_Y;
+ }
m_ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z ) ]++;
m_ToTickBlocks[ MakeIndex( a_X+1, a_Y, a_Z ) ]++;
@@ -860,7 +881,7 @@ void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block
m_ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z+1 ) ]++;
m_ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z-1 ) ]++;
- cBlockEntity* BlockEntity = GetBlockEntity( a_X + m_PosX*16, a_Y+m_PosY*128, a_Z+m_PosZ*16 );
+ cBlockEntity* BlockEntity = GetBlockEntity( a_X + m_PosX * 16, a_Y + m_PosY * 128, a_Z + m_PosZ * 16 );
if( BlockEntity )
{
BlockEntity->Destroy();
@@ -927,8 +948,11 @@ void cChunk::FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_B
RecalculateLighting();
}
- // Recalculate next tick
- RecalculateHeightmap();
+ // Update heightmap, if needed:
+ if (a_Y >= m_HeightMap[a_X + a_Z * 16])
+ {
+ m_HeightMap[a_X + a_Z * 16] = (a_BlockType == E_BLOCK_AIR) ? (a_Y - 1) : a_Y;
+ }
}