-- SPDX-FileCopyrightText: 2024 Tuxilio <mail@tuxil.io> -- -- SPDX-License-Identifier: GPL-3.0-or-later local modname = core.get_current_modname() local modpath = core.get_modpath(modname) local data = { url = "mqtt.felix-zauberer.de", clientId = "ledtree_luanti", username = "kalle1", password = "eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B", } local mqttBaseTopic = core.settings:get("ledtree_base_topic") or "ledtree" local client = mqtt.connect(data.url, data.clientId, data.username, data.password) local change_color = function(player, led_id) local formspec = "size[3,3]" .. "image_button[0,0;1,1;red.png;red;red;false;false;]" .. "image_button[1,0;1,1;green.png;gren;green;false;false;]" .. "image_button[2,0;1,1;blue.png;blue;blue;false;false;]" .. "image_button[0,1;1,1;yellow.png;yellow;yellow;false;false;]" .. "image_button[1,1;1,1;cyan.png;cyan;cyan;false;false;]" .. "image_button[2,1;1,1;magenta.png;magenta;magenta;false;false;]" .. "image_button[0,2;1,1;white.png;white;white;false;false;]" .. "image_button[1,2;1,1;black.png;black;black;false;false;]" .. "image_button[2,2;1,1;gray.png;gray;gray;false;false;]" core.show_formspec(player:get_player_name(), "ledtree:colorpicker", formspec) end local function send_mqtt(id, rgb) mqtt.publish(client, mqttBaseTopic.."/led/"..id, "["..rgb.."]") end for id=1, 10, 1 do core.register_node("ledtree:led"..id, { description = "LED"..id, --tiles = "", on_rightclick = function(pos, node, player, itemstack, pointed_thing) change_color(player, id) end, }) end core.register_on_player_receive_fields(function(player, formname, fields) if formname == "ledtree:colorpicker" then for color, _ in pairs(fields) do if color then local rgb = "" if color == "red" then rgb = "255,0,0" elseif color == "green" then rgb = "0,255,0" elseif color == "blue" then rgb = "0,0,255" elseif color == "yellow" then rgb = "255,255,0" elseif color == "cyan" then rgb = "0,255,255" elseif color == "magenta" then rgb = "255,0,255" elseif color == "white" then rgb = "255,255,255" elseif color == "black" then rgb = "0,0,0" elseif color == "gray" then rgb = "128,128,128" end if rgb ~= "" then core.chat_send_player(player:get_player_name(), "RGB: " .. rgb) send_mqtt(1, rgb) end end end end end)