From 2e2d0b49ead4abe88a9252c9a6a503c3560334ed Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:07:37 +0000 Subject: [PATCH 1/8] performance fix in mcl_skins --- mods/PLAYER/mcl_skins/init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_skins/init.lua b/mods/PLAYER/mcl_skins/init.lua index b1d1feef8..0bff9cb18 100644 --- a/mods/PLAYER/mcl_skins/init.lua +++ b/mods/PLAYER/mcl_skins/init.lua @@ -7,6 +7,8 @@ mcl_skins = { } local S = minetest.get_translator("mcl_skins") +local has_mcl_armor = minetest.get_modpath("mcl_armor") +local has_mcl_inventory = minetest.get_modpath("mcl_inventory") -- load skin list and metadata local id, f, data, skin = 0 @@ -105,11 +107,11 @@ mcl_skins.set_player_skin = function(player, skin_id) mcl_skins.previews[playername] = preview player:get_meta():set_string("mcl_skins:skin_id", tostring(skin_id)) mcl_skins.update_player_skin(player) - if minetest.get_modpath("mcl_armor") then + if has_mcl_armor then armor.textures[playername].skin = skin_file armor:update_player_visuals(player) end - if minetest.get_modpath("mcl_inventory") then + if has_mcl_inventory then mcl_inventory.update_inventory_formspec(player) end for i=1, #mcl_skins.registered_on_set_skins do From 9819b713c9b69136536009b4aa48bd7885344df9 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:24:03 +0000 Subject: [PATCH 2/8] replace pairs() by ipairs() --- mods/ENVIRONMENT/mcl_weather/rain.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/rain.lua b/mods/ENVIRONMENT/mcl_weather/rain.lua index 9b4210060..0afbb5539 100644 --- a/mods/ENVIRONMENT/mcl_weather/rain.lua +++ b/mods/ENVIRONMENT/mcl_weather/rain.lua @@ -36,7 +36,7 @@ mcl_weather.rain.set_sky_box = function() {r=85, g=86, b=98}, {r=0, g=0, b=0}}) mcl_weather.skycolor.active = true - for _, player in pairs(minetest.get_connected_players()) do + for _, player in ipairs(minetest.get_connected_players()) do player:set_clouds({color="#5D5D5FE8"}) end end From 63d1661e08354784c35df4a5726be7194f921d7a Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:25:30 +0000 Subject: [PATCH 3/8] replace pairs() by ipairs() (2) --- mods/ENVIRONMENT/mcl_weather/snow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/snow.lua b/mods/ENVIRONMENT/mcl_weather/snow.lua index 986d38d43..afe23c150 100644 --- a/mods/ENVIRONMENT/mcl_weather/snow.lua +++ b/mods/ENVIRONMENT/mcl_weather/snow.lua @@ -37,7 +37,7 @@ mcl_weather.snow.set_sky_box = function() {r=85, g=86, b=86}, {r=0, g=0, b=0}}) mcl_weather.skycolor.active = true - for _, player in pairs(minetest.get_connected_players()) do + for _, player in ipairs(minetest.get_connected_players()) do player:set_clouds({color="#ADADADE8"}) end mcl_weather.skycolor.active = true From 35d55376a9a68324b2c7650cfcadd93a28083809 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:26:09 +0000 Subject: [PATCH 4/8] replace pairs() by ipairs() (3) --- mods/ENVIRONMENT/mcl_weather/thunder.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/thunder.lua b/mods/ENVIRONMENT/mcl_weather/thunder.lua index b1837f023..7da3308db 100644 --- a/mods/ENVIRONMENT/mcl_weather/thunder.lua +++ b/mods/ENVIRONMENT/mcl_weather/thunder.lua @@ -25,7 +25,7 @@ minetest.register_globalstep(function(dtime) {r=40, g=40, b=40}, {r=0, g=0, b=0}}) mcl_weather.skycolor.active = true - for _, player in pairs(minetest.get_connected_players()) do + for _, player in ipairs(minetest.get_connected_players()) do player:set_clouds({color="#3D3D3FE8"}) end mcl_weather.thunder.init_done = true From 0531aae6872c2a5474ee8d0634a43861fed559fb Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:27:50 +0000 Subject: [PATCH 5/8] replace pairs() by ipairs() in mcl_playerplus --- mods/PLAYER/mcl_playerplus/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index dec3771da..af735f2c9 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -19,7 +19,7 @@ minetest.register_globalstep(function(dtime) -- Update jump status immediately since we need this info in real time. -- WARNING: This section is HACKY as hell since it is all just based on heuristics. - for _,player in pairs(minetest.get_connected_players()) do + for _,player in ipairs(minetest.get_connected_players()) do local controls = player:get_player_control() name = player:get_player_name() @@ -118,7 +118,7 @@ minetest.register_globalstep(function(dtime) time = 0 -- check players - for _,player in pairs(minetest.get_connected_players()) do + for _,player in ipairs(minetest.get_connected_players()) do -- who am I? local name = player:get_player_name() From 25653e6178ea5261459b8e51d03dbf45fd9cbd43 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:31:13 +0000 Subject: [PATCH 6/8] replace pairs() by ipairs() in mcl_playerinfo --- mods/PLAYER/mcl_playerinfo/init.lua | 182 ++++++++++++++-------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/mods/PLAYER/mcl_playerinfo/init.lua b/mods/PLAYER/mcl_playerinfo/init.lua index 31dad39a6..4c1454d95 100644 --- a/mods/PLAYER/mcl_playerinfo/init.lua +++ b/mods/PLAYER/mcl_playerinfo/init.lua @@ -1,91 +1,91 @@ --- Player state for public API -mcl_playerinfo = {} - --- Get node but use fallback for nil or unknown -local function node_ok(pos, fallback) - - fallback = fallback or "air" - - local node = minetest.get_node_or_nil(pos) - - if not node then - return fallback - end - - if minetest.registered_nodes[node.name] then - return node.name - end - - return fallback -end - -local time = 0 - -local get_player_nodes = function(player_pos) - local work_pos = table.copy(player_pos) - - -- what is around me? - work_pos.y = work_pos.y - 0.1 -- standing on - local node_stand = node_ok(work_pos) - local node_stand_below = node_ok({x=work_pos.x, y=work_pos.y-1, z=work_pos.z}) - - work_pos.y = work_pos.y + 1.5 -- head level - local node_head = node_ok(work_pos) - - work_pos.y = work_pos.y - 1.2 -- feet level - local node_feet = node_ok(work_pos) - - return node_stand, node_stand_below, node_head, node_feet -end - -minetest.register_globalstep(function(dtime) - - time = time + dtime - - -- Run the rest of the code every 0.5 seconds - if time < 0.5 then - return - end - - -- reset time for next check - -- FIXME: Make sure a regular check interval applies - time = 0 - - -- check players - for _,player in pairs(minetest.get_connected_players()) do - -- who am I? - local name = player:get_player_name() - - -- where am I? - local pos = player:get_pos() - - -- what is around me? - local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos) - mcl_playerinfo[name].node_stand = node_stand - mcl_playerinfo[name].node_stand_below = node_stand_below - mcl_playerinfo[name].node_head = node_head - mcl_playerinfo[name].node_feet = node_feet - - end - -end) - --- set to blank on join (for 3rd party mods) -minetest.register_on_joinplayer(function(player) - local name = player:get_player_name() - - mcl_playerinfo[name] = { - node_head = "", - node_feet = "", - node_stand = "", - node_stand_below = "", - } - -end) - --- clear when player leaves -minetest.register_on_leaveplayer(function(player) - local name = player:get_player_name() - - mcl_playerinfo[name] = nil -end) +-- Player state for public API +mcl_playerinfo = {} + +-- Get node but use fallback for nil or unknown +local function node_ok(pos, fallback) + + fallback = fallback or "air" + + local node = minetest.get_node_or_nil(pos) + + if not node then + return fallback + end + + if minetest.registered_nodes[node.name] then + return node.name + end + + return fallback +end + +local time = 0 + +local get_player_nodes = function(player_pos) + local work_pos = table.copy(player_pos) + + -- what is around me? + work_pos.y = work_pos.y - 0.1 -- standing on + local node_stand = node_ok(work_pos) + local node_stand_below = node_ok({x=work_pos.x, y=work_pos.y-1, z=work_pos.z}) + + work_pos.y = work_pos.y + 1.5 -- head level + local node_head = node_ok(work_pos) + + work_pos.y = work_pos.y - 1.2 -- feet level + local node_feet = node_ok(work_pos) + + return node_stand, node_stand_below, node_head, node_feet +end + +minetest.register_globalstep(function(dtime) + + time = time + dtime + + -- Run the rest of the code every 0.5 seconds + if time < 0.5 then + return + end + + -- reset time for next check + -- FIXME: Make sure a regular check interval applies + time = 0 + + -- check players + for _,player in ipairs(minetest.get_connected_players()) do + -- who am I? + local name = player:get_player_name() + + -- where am I? + local pos = player:get_pos() + + -- what is around me? + local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos) + mcl_playerinfo[name].node_stand = node_stand + mcl_playerinfo[name].node_stand_below = node_stand_below + mcl_playerinfo[name].node_head = node_head + mcl_playerinfo[name].node_feet = node_feet + + end + +end) + +-- set to blank on join (for 3rd party mods) +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + + mcl_playerinfo[name] = { + node_head = "", + node_feet = "", + node_stand = "", + node_stand_below = "", + } + +end) + +-- clear when player leaves +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + + mcl_playerinfo[name] = nil +end) From 4c3954959cd219f377588b6be9f2dac05597b632 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:32:15 +0000 Subject: [PATCH 7/8] replace pairs() by ipairs() in mcl_player --- mods/PLAYER/mcl_player/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index a94e3dfe1..e39e8f956 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -137,7 +137,7 @@ local player_attached = mcl_player.player_attached -- Check each player and apply animations minetest.register_globalstep(function(dtime) - for _, player in pairs(minetest.get_connected_players()) do + for _, player in ipairs(minetest.get_connected_players()) do local name = player:get_player_name() local model_name = player_model[name] local model = model_name and models[model_name] From fa0ea94433a3a0541b15ce429f2ea344c63a3930 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 18 Feb 2021 15:35:52 +0000 Subject: [PATCH 8/8] replace pairs() by ipairs() in mcl_bow --- mods/ITEMS/mcl_bows/bow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 87820071d..4ea2066b0 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -341,7 +341,7 @@ controls.register_on_hold(function(player, key, time) end) minetest.register_globalstep(function(dtime) - for _, player in pairs(minetest.get_connected_players()) do + for _, player in ipairs(minetest.get_connected_players()) do local name = player:get_player_name() local wielditem = player:get_wielded_item() local wieldindex = player:get_wield_index()