From 38b219de625c6c334b1b900c911886f5469a1720 Mon Sep 17 00:00:00 2001 From: faketruth Date: Fri, 16 Mar 2012 15:48:40 +0000 Subject: Exposed a function to Lua to get a block's sky light value git-svn-id: http://mc-server.googlecode.com/svn/trunk@416 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Bindings.cpp | 70 ++++++++++++++++++++++++++++++---------------------- source/Bindings.h | 2 +- source/cChunkMap.cpp | 20 ++++++++++++++- source/cChunkMap.h | 1 + source/cWorld.cpp | 9 +++++++ source/cWorld.h | 3 ++- 6 files changed, 72 insertions(+), 33 deletions(-) diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 8e524beb2..8e3c4bd96 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 03/09/12 14:38:38. +** Generated automatically by tolua++-1.0.92 on 03/11/12 17:55:41. */ #ifndef __cplusplus @@ -9546,34 +9546,6 @@ static int tolua_AllToLua_cServer_SendMessage00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: GetWorld of class cWorld */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetWorld00 -static int tolua_AllToLua_cWorld_GetWorld00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertable(tolua_S,1,"cWorld",0,&tolua_err) || - !tolua_isnoobj(tolua_S,2,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - { - cWorld* tolua_ret = (cWorld*) cWorld::GetWorld(); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWorld"); - } - } - return 1; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'GetWorld'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetTime of class cWorld */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetTime00 static int tolua_AllToLua_cWorld_GetTime00(lua_State* tolua_S) @@ -10168,6 +10140,44 @@ tolua_lerror: } #endif //#ifndef TOLUA_DISABLE +/* method: GetBlockSkyLight of class cWorld */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetBlockSkyLight00 +static int tolua_AllToLua_cWorld_GetBlockSkyLight00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnumber(tolua_S,4,0,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0); + int a_X = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Y = ((int) tolua_tonumber(tolua_S,3,0)); + int a_Z = ((int) tolua_tonumber(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetBlockSkyLight'", NULL); +#endif + { + char tolua_ret = (char) self->GetBlockSkyLight(a_X,a_Y,a_Z); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetBlockSkyLight'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: DigBlock of class cWorld */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_DigBlock00 static int tolua_AllToLua_cWorld_DigBlock00(lua_State* tolua_S) @@ -17888,7 +17898,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_endmodule(tolua_S); tolua_cclass(tolua_S,"cWorld","cWorld","",NULL); tolua_beginmodule(tolua_S,"cWorld"); - tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cWorld_GetWorld00); tolua_function(tolua_S,"GetTime",tolua_AllToLua_cWorld_GetTime00); tolua_function(tolua_S,"GetGameMode",tolua_AllToLua_cWorld_GetGameMode00); tolua_function(tolua_S,"SetWorldTime",tolua_AllToLua_cWorld_SetWorldTime00); @@ -17906,6 +17915,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"GetBlockMeta",tolua_AllToLua_cWorld_GetBlockMeta01); tolua_function(tolua_S,"SetBlockMeta",tolua_AllToLua_cWorld_SetBlockMeta00); tolua_function(tolua_S,"SetBlockMeta",tolua_AllToLua_cWorld_SetBlockMeta01); + tolua_function(tolua_S,"GetBlockSkyLight",tolua_AllToLua_cWorld_GetBlockSkyLight00); tolua_function(tolua_S,"DigBlock",tolua_AllToLua_cWorld_DigBlock00); tolua_function(tolua_S,"SendBlockTo",tolua_AllToLua_cWorld_SendBlockTo00); tolua_function(tolua_S,"GetSpawnX",tolua_AllToLua_cWorld_GetSpawnX00); diff --git a/source/Bindings.h b/source/Bindings.h index 78f6cf818..c100812cf 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 03/09/12 14:38:39. +** Generated automatically by tolua++-1.0.92 on 03/11/12 17:55:42. */ /* Exported function */ diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp index 97f6a659f..c36f2610f 100644 --- a/source/cChunkMap.cpp +++ b/source/cChunkMap.cpp @@ -557,7 +557,25 @@ BLOCKTYPE cChunkMap::GetBlockMeta(int a_X, int a_Y, int a_Z) -void cChunkMap::SetBlockMeta(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockMeta) +BLOCKTYPE cChunkMap::GetBlockSkyLight(int a_X, int a_Y, int a_Z) +{ + int ChunkX, ChunkZ; + cChunkDef::AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkZ ); + + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ ); + if ((Chunk != NULL) && Chunk->IsValid() ) + { + return cChunk::GetNibble( Chunk->pGetSkyLight(), a_X, a_Y, a_Z ); + } + return 0; +} + + + + + +void cChunkMap::SetBlockMeta(int a_X, int a_Y, int a_Z, char a_BlockMeta) { int ChunkX, ChunkZ; cChunkDef::AbsoluteToRelative( a_X, a_Y, a_Z, ChunkX, ChunkZ ); diff --git a/source/cChunkMap.h b/source/cChunkMap.h index 10fe1e70a..f2d55b6b8 100644 --- a/source/cChunkMap.h +++ b/source/cChunkMap.h @@ -87,6 +87,7 @@ public: void CollectPickupsByPlayer(cPlayer * a_Player); BLOCKTYPE GetBlock (int a_X, int a_Y, int a_Z); BLOCKTYPE GetBlockMeta (int a_X, int a_Y, int a_Z); + BLOCKTYPE GetBlockSkyLight (int a_X, int a_Y, int a_Z); void SetBlockMeta (int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockMeta); void SetBlock (int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta); bool DigBlock (int a_X, int a_Y, int a_Z, cItem & a_PickupItem); diff --git a/source/cWorld.cpp b/source/cWorld.cpp index bb5fbfdeb..daf72ac69 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -896,6 +896,15 @@ void cWorld::SetBlockMeta( int a_X, int a_Y, int a_Z, char a_MetaData ) +char cWorld::GetBlockSkyLight( int a_X, int a_Y, int a_Z ) +{ + return m_ChunkMap->GetBlockSkyLight(a_X, a_Y, a_Z); +} + + + + + bool cWorld::DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem ) { bool res = m_ChunkMap->DigBlock(a_X, a_Y, a_Z, a_PickupItem); diff --git a/source/cWorld.h b/source/cWorld.h index c2f3d3fcf..56c63502b 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -49,7 +49,7 @@ class cWorld //tolua_export { //tolua_export public: - OBSOLETE static cWorld* GetWorld(); //tolua_export + OBSOLETE static cWorld* GetWorld(); // Return time in seconds inline static float GetTime() //tolua_export @@ -187,6 +187,7 @@ public: char GetBlockMeta( const Vector3i & a_Pos ) { return GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z ); } //tolua_export void SetBlockMeta( int a_X, int a_Y, int a_Z, char a_MetaData ); //tolua_export void SetBlockMeta( const Vector3i & a_Pos, char a_MetaData ) { SetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z, a_MetaData ); } //tolua_export + char GetBlockSkyLight( int a_X, int a_Y, int a_Z ); //tolua_export bool DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem ); //tolua_export void SendBlockTo( int a_X, int a_Y, int a_Z, cPlayer* a_Player ); //tolua_export -- cgit v1.2.3