Add EnvRef:get_node_light(pos, timeofday)
authorPerttu Ahola <celeron55@gmail.com>
Sun, 4 Dec 2011 13:55:37 +0000 (15:55 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 4 Dec 2011 13:55:37 +0000 (15:55 +0200)
data/mods/default/init.lua
src/scriptapi.cpp

index 7f0614e20ac674e59a6f347cc9b2dce8e444a3bc..1bd1eba4a7e73f4e4afe008b84b869e50296d5c7 100644 (file)
 --   ^ Returns {name="ignore", ...} for unloaded area
 -- - get_node_or_nil(pos)
 --   ^ Returns nil for unloaded area
+-- - get_node_light(pos, timeofday) -> 0...15 or nil
+--   ^ timeofday: nil = current time, 0 = night, 0.5 = day
 -- - add_luaentity(pos, name)
 -- - add_item(pos, itemstring)
 -- - add_rat(pos)
index ffbce916797d1e11ba9b66ef876cb6e12d3c6794..9b37c53b4cb1aad5a9000c02602ef73e112701d8 100644 (file)
@@ -2402,6 +2402,34 @@ private:
                }
        }
 
+       // EnvRef:get_node_light(pos, timeofday)
+       // pos = {x=num, y=num, z=num}
+       // timeofday: nil = current time, 0 = night, 0.5 = day
+       static int l_get_node_light(lua_State *L)
+       {
+               EnvRef *o = checkobject(L, 1);
+               ServerEnvironment *env = o->m_env;
+               if(env == NULL) return 0;
+               // Do it
+               v3s16 pos = readpos(L, 2);
+               u32 time_of_day = env->getTimeOfDay();
+               if(lua_isnumber(L, 3))
+                       time_of_day = 24000.0 * lua_tonumber(L, 3);
+               time_of_day %= 24000;
+               u32 dnr = time_to_daynight_ratio(time_of_day);
+               MapNode n = env->getMap().getNodeNoEx(pos);
+               try{
+                       MapNode n = env->getMap().getNode(pos);
+                       INodeDefManager *ndef = env->getGameDef()->ndef();
+                       lua_pushinteger(L, n.getLightBlend(dnr, ndef));
+                       return 1;
+               } catch(InvalidPositionException &e)
+               {
+                       lua_pushnil(L);
+                       return 1;
+               }
+       }
+
        // EnvRef:add_luaentity(pos, entityname)
        // pos = {x=num, y=num, z=num}
        static int l_add_luaentity(lua_State *L)
@@ -2571,6 +2599,7 @@ const luaL_reg EnvRef::methods[] = {
        method(EnvRef, remove_node),
        method(EnvRef, get_node),
        method(EnvRef, get_node_or_nil),
+       method(EnvRef, get_node_light),
        method(EnvRef, add_luaentity),
        method(EnvRef, add_item),
        method(EnvRef, add_rat),