From 3470687be0af7254aca478ead1e9c72757edf070 Mon Sep 17 00:00:00 2001 From: orwell Date: Tue, 27 May 2025 21:17:10 +0200 Subject: Add CH dependencies temporarily. Before merge to master should remove them again and split out util functions (e.g. formspec lib) --- ch_core/wielded_light.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ch_core/wielded_light.lua (limited to 'ch_core/wielded_light.lua') diff --git a/ch_core/wielded_light.lua b/ch_core/wielded_light.lua new file mode 100644 index 0000000..6059474 --- /dev/null +++ b/ch_core/wielded_light.lua @@ -0,0 +1,32 @@ +ch_core.open_submod("wielded_light", {data = true, lib = true, nodes = true}) + +local valid_numbers = {} + +for i = 0, minetest.LIGHT_MAX do + valid_numbers[i] = true +end + +function ch_core.set_player_light(player_name, slot, light_level) + local ll_1 = light_level or minetest.LIGHT_MAX + local ll = tonumber(ll_1) + if not ll then + minetest.log("warning", "Invalid light_level: "..ll_1) + return false + end + local online_charinfo = ch_data.online_charinfo[player_name] + if not online_charinfo or not valid_numbers[ll] then + return false + end + local slots = online_charinfo.wielded_lights + if not slots then + slots = {} + online_charinfo.wielded_lights = slots + end + if ll == 0 then + slots[slot] = nil + else + slots[slot] = ll + end +end + +ch_core.close_submod("wielded_light") -- cgit v1.2.3