+ getServer(L)->setSky(player, skybox_params);
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+// get_sky(self)
+int ObjectRef::l_get_sky(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+
+ if (!player)
+ return 0;
+ SkyboxParams skybox_params;
+ skybox_params = player->getSkyParams();
+
+ push_ARGB8(L, skybox_params.bgcolor);
+ lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
+
+ lua_newtable(L);
+ s16 i = 1;
+ for (const std::string& texture : skybox_params.textures) {
+ lua_pushlstring(L, texture.c_str(), texture.size());
+ lua_rawseti(L, -2, i++);
+ }
+ lua_pushboolean(L, skybox_params.clouds);
+ return 4;
+}
+
+// get_sky_color(self)
+int ObjectRef::l_get_sky_color(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+
+ if (!player)
+ return 0;
+
+ const SkyboxParams& skybox_params = player->getSkyParams();
+
+ lua_newtable(L);
+ if (skybox_params.type == "regular") {
+ push_ARGB8(L, skybox_params.sky_color.day_sky);
+ lua_setfield(L, -2, "day_sky");
+ push_ARGB8(L, skybox_params.sky_color.day_horizon);
+ lua_setfield(L, -2, "day_horizon");
+ push_ARGB8(L, skybox_params.sky_color.dawn_sky);
+ lua_setfield(L, -2, "dawn_sky");
+ push_ARGB8(L, skybox_params.sky_color.dawn_horizon);
+ lua_setfield(L, -2, "dawn_horizon");
+ push_ARGB8(L, skybox_params.sky_color.night_sky);
+ lua_setfield(L, -2, "night_sky");
+ push_ARGB8(L, skybox_params.sky_color.night_horizon);
+ lua_setfield(L, -2, "night_horizon");
+ push_ARGB8(L, skybox_params.sky_color.indoors);
+ lua_setfield(L, -2, "indoors");
+ }
+ push_ARGB8(L, skybox_params.sun_tint);
+ lua_setfield(L, -2, "sun_tint");
+ push_ARGB8(L, skybox_params.moon_tint);
+ lua_setfield(L, -2, "moon_tint");
+ lua_pushstring(L, skybox_params.tint_type.c_str());
+ lua_setfield(L, -2, "tint_type");
+ return 1;
+}
+
+// set_sun(self, {visible, texture=, tonemap=, sunrise=, rotation=, scale=})
+int ObjectRef::l_set_sun(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (!player)
+ return 0;
+
+ if (!lua_istable(L, 2))
+ return 0;
+
+ SunParams sun_params = player->getSunParams();
+
+ sun_params.visible = getboolfield_default(L, 2,
+ "visible", sun_params.visible);
+ sun_params.texture = getstringfield_default(L, 2,
+ "texture", sun_params.texture);
+ sun_params.tonemap = getstringfield_default(L, 2,
+ "tonemap", sun_params.tonemap);
+ sun_params.sunrise = getstringfield_default(L, 2,
+ "sunrise", sun_params.sunrise);
+ sun_params.sunrise_visible = getboolfield_default(L, 2,
+ "sunrise_visible", sun_params.sunrise_visible);
+ sun_params.scale = getfloatfield_default(L, 2,
+ "scale", sun_params.scale);
+
+ getServer(L)->setSun(player, sun_params);
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+//get_sun(self)
+int ObjectRef::l_get_sun(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (!player)
+ return 0;
+ const SunParams &sun_params = player->getSunParams();
+
+ lua_newtable(L);
+ lua_pushboolean(L, sun_params.visible);
+ lua_setfield(L, -2, "visible");
+ lua_pushstring(L, sun_params.texture.c_str());
+ lua_setfield(L, -2, "texture");
+ lua_pushstring(L, sun_params.tonemap.c_str());
+ lua_setfield(L, -2, "tonemap");
+ lua_pushstring(L, sun_params.sunrise.c_str());
+ lua_setfield(L, -2, "sunrise");
+ lua_pushboolean(L, sun_params.sunrise_visible);
+ lua_setfield(L, -2, "sunrise_visible");
+ lua_pushnumber(L, sun_params.scale);
+ lua_setfield(L, -2, "scale");