From 24a33e7a193a13dbcfc8a13da8803adbd345c033 Mon Sep 17 00:00:00 2001 From: SFENCE Date: Sun, 15 Jun 2025 19:46:34 +0200 Subject: [PATCH] Apply review. --- doc/lua_api.md | 8 +++---- src/script/lua_api/l_object.cpp | 37 +++++++++++++-------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 7c746c439..a525b2452 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9050,16 +9050,16 @@ child will follow movement and rotation of that bone. * Currently, bloom `intensity` and `strength_factor` affect volumetric lighting `strength` and vice versa. This behavior is to be changed in the future, do not rely on it. - * `vision_effects`: is a table that controls vision effects - * `color_transform_matrix`: is a matrix with default value (identity matrix): + * `color_transform_matrix`: is a matrix with default value (identity matrix): ```lua { {1.0, 0.0, 0.0}, -- r {0.0, 1.0, 0.0}, -- g {0.0, 0.0, 1.0}} -- b ``` - * Work as `transformed_color_RGB = color_transform_matrix * color_RGB` - * Can be used for creation color blind effect, base for night vision effect etc. + * Work as `transformed_color_RGB = color_transform_matrix * color_RGB` + * Can be used for creation color blind effect, base for night vision effect etc. + * Request client with protocol version 49 or higger. ```lua -- example of night vision like transform diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index f55153f4a..f6bc81eb4 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -2695,37 +2695,30 @@ int ObjectRef::l_set_lighting(lua_State *L) } lua_pop(L, 1); // bloom - lua_getfield(L, 2, "vision_effects"); + lua_getfield(L, 2, "color_transform_matrix"); + + // if none or nil, keep color transform matrix unchanged if (!lua_isnoneornil(L, -1)) { if (!lua_istable(L, -1)) - throw LuaError("vision_effects is not a table"); + throw LuaError("vision_effects.color_transform_matrix is not a table"); - lua_getfield(L, 3, "color_transform_matrix"); - - // if none or nil, keep color transform matrix unchanged - if (!lua_isnoneornil(L, -1)) { + for (int row = 1; row <= 3; ++row) { + lua_rawgeti(L, -1, row); if (!lua_istable(L, -1)) - throw LuaError("vision_effects.color_transform_matrix is not a table"); + throw LuaError("color_transform_matrix should be in format {{a, b, c},{d, e, f},{g, a, h}}"); - for (int row = 1; row <= 3; ++row) { - lua_rawgeti(L, -1, row); - if (!lua_istable(L, -1)) + for (int col = 1; col <= 3; ++col) { + lua_rawgeti(L, -1, col); + if (!lua_isnumber(L, -1)) throw LuaError("color_transform_matrix should be in format {{a, b, c},{d, e, f},{g, a, h}}"); - for (int col = 1; col <= 3; ++col) { - lua_rawgeti(L, -1, col); - if (!lua_isnumber(L, -1)) - throw LuaError("color_transform_matrix should be in format {{a, b, c},{d, e, f},{g, a, h}}"); - - lighting.vision_effects.color_transform_matrix[(row - 1) * 3 + (col - 1)] = (float)lua_tonumber(L, -1); - lua_pop(L, 1); // Pop the value at [row][col] - } - lua_pop(L, 1); // Pop the row table + lighting.vision_effects.color_transform_matrix[(row - 1) * 3 + (col - 1)] = (float)lua_tonumber(L, -1); + lua_pop(L, 1); // Pop the value at [row][col] } + lua_pop(L, 1); // Pop the row table } - lua_pop(L, 1); // color_transform_matrix } - lua_pop(L, 1); // vision_effects + lua_pop(L, 1); // color_transform_matrix } getServer(L)->setLighting(player, lighting); @@ -2778,7 +2771,6 @@ int ObjectRef::l_get_lighting(lua_State *L) lua_pushnumber(L, lighting.bloom_radius); lua_setfield(L, -2, "radius"); lua_setfield(L, -2, "bloom"); - lua_newtable(L); // "vision_effects" lua_newtable(L); // "color_transform_matrix" // Create the nested table structure {{a, b, c}, {d, e, f}, {g, h, i}} for (int row = 0; row < 3; row++) { @@ -2790,7 +2782,6 @@ int ObjectRef::l_get_lighting(lua_State *L) lua_rawseti(L, -2, row + 1); // Set inner table in the outer matrix table } lua_setfield(L, -2, "color_transform_matrix"); - lua_setfield(L, -2, "vision_effects"); return 1; }