1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add minetest.get_artificial_light and minetest.get_natural_light (#5680)

Add more detailed light detection functions, a function to get the artificial light (torches) and a function to get the sunlight as seen by the player (you can specify timeofday).

Co-authored-by: rubenwardy <rw@rubenwardy.com>
This commit is contained in:
HybridDog 2020-10-06 20:49:46 +02:00 committed by GitHub
parent e80fc22dd9
commit 2f4037752b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 180 additions and 0 deletions

View file

@ -407,6 +407,46 @@ int ModApiEnvMod::l_get_node_light(lua_State *L)
return 1;
}
// get_natural_light(pos, timeofday)
// pos = {x=num, y=num, z=num}
// timeofday: nil = current time, 0 = night, 0.5 = day
int ModApiEnvMod::l_get_natural_light(lua_State *L)
{
GET_ENV_PTR;
v3s16 pos = read_v3s16(L, 1);
bool is_position_ok;
MapNode n = env->getMap().getNode(pos, &is_position_ok);
if (!is_position_ok)
return 0;
// If the daylight is 0, nothing needs to be calculated
u8 daylight = n.param1 & 0x0f;
if (daylight == 0) {
lua_pushinteger(L, 0);
return 1;
}
u32 time_of_day;
if (lua_isnumber(L, 2)) {
time_of_day = 24000.0 * lua_tonumber(L, 2);
time_of_day %= 24000;
} else {
time_of_day = env->getTimeOfDay();
}
u32 dnr = time_to_daynight_ratio(time_of_day, true);
// If it's the same as the artificial light, the sunlight needs to be
// searched for because the value may not emanate from the sun
if (daylight == n.param1 >> 4)
daylight = env->findSunlight(pos);
lua_pushinteger(L, dnr * daylight / 1000);
return 1;
}
// place_node(pos, node)
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_place_node(lua_State *L)
@ -1358,6 +1398,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
API_FCT(get_node);
API_FCT(get_node_or_nil);
API_FCT(get_node_light);
API_FCT(get_natural_light);
API_FCT(place_node);
API_FCT(dig_node);
API_FCT(punch_node);