Reset player lighting when passing no arguments (#13525)

Co-authored-by: Zughy <4279489-marco_a@users.noreply.gitlab.com>
This commit is contained in:
Zughy 2023-05-26 13:47:16 +02:00 committed by GitHub
parent b60d38b7f9
commit d6eb6ff973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 24 deletions

@ -7676,8 +7676,9 @@ child will follow movement and rotation of that bone.
the client already has the block)
* Resource intensive - use sparsely
* `set_lighting(light_definition)`: sets lighting for the player
* Passing no arguments resets lighting to its default values.
* `light_definition` is a table with the following optional fields:
* `saturation` sets the saturation (vividness).
* `saturation` sets the saturation (vividness; default: `1.0`).
values > 1 increase the saturation
values in [0,1) decrease the saturation
* This value has no effect on clients who have the "Tone Mapping" shader disabled.
@ -7686,12 +7687,12 @@ child will follow movement and rotation of that bone.
* This value has no effect on clients who have the "Dynamic Shadows" shader disabled.
* `exposure` is a table that controls automatic exposure.
The basic exposure factor equation is `e = 2^exposure_correction / clamp(luminance, 2^luminance_min, 2^luminance_max)`
* `luminance_min` set the lower luminance boundary to use in the calculation
* `luminance_max` set the upper luminance boundary to use in the calculation
* `exposure_correction` correct observed exposure by the given EV value
* `speed_dark_bright` set the speed of adapting to bright light
* `speed_bright_dark` set the speed of adapting to dark scene
* `center_weight_power` set the power factor for center-weighted luminance measurement
* `luminance_min` set the lower luminance boundary to use in the calculation (default: `-3.0`)
* `luminance_max` set the upper luminance boundary to use in the calculation (default: `-3.0`)
* `exposure_correction` correct observed exposure by the given EV value (default: `0.0`)
* `speed_dark_bright` set the speed of adapting to bright light (default: `1000.0`)
* `speed_bright_dark` set the speed of adapting to dark scene (default: `1000.0`)
* `center_weight_power` set the power factor for center-weighted luminance measurement (default: `1.0`)
* `get_lighting()`: returns the current state of lighting for the player.
* Result is a table with the same fields as `light_definition` in `set_lighting`.

@ -2301,8 +2301,11 @@ int ObjectRef::l_set_lighting(lua_State *L)
if (player == nullptr)
return 0;
Lighting lighting;
if (!lua_isnoneornil(L, 2)) {
luaL_checktype(L, 2, LUA_TTABLE);
Lighting lighting = player->getLighting();
lighting = player->getLighting();
lua_getfield(L, 2, "shadows");
if (lua_istable(L, -1)) {
getfloatfield(L, -1, "intensity", lighting.shadow_intensity);
@ -2321,6 +2324,7 @@ int ObjectRef::l_set_lighting(lua_State *L)
lighting.exposure.center_weight_power = getfloatfield_default(L, -1, "center_weight_power", lighting.exposure.center_weight_power);
}
lua_pop(L, 1); // exposure
}
getServer(L)->setLighting(player, lighting);
return 0;