This commit is contained in:
Rainer 2026-02-12 12:21:21 +01:00
commit 53466eed17
18 changed files with 687 additions and 0 deletions

70
switch.lua Normal file
View file

@ -0,0 +1,70 @@
local switch_box = { type = "fixed", fixed = { { -6/32, -6/32, 14/32, 6/32, 6/32, 16/32} } }
minetest.register_node("smart_light:switch", {
description = "Smart Light Switch",
tiles = {
"smart_light_case.png", "smart_light_case.png",
"smart_light_case.png", "smart_light_case.png",
"smart_light_case.png", "smart_light_case.png^smart_light_button_off.png",
},
drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir",
sunlight_propagates = true, groups = {cracky=2, crumbly=2},
node_box = switch_box,
on_punch = function(pos, node, puncher)
if not puncher:get_player_control().sneak then return end
local meta = minetest.get_meta(pos)
local area, chan = meta:get_string("sl_area"), meta:get_string("sl_chan")
if area ~= "" and chan ~= "" and smart_light.registry.areas[area] and smart_light.registry.areas[area].channels[chan] then
local count = smart_light.get_count(area, chan)
local status = smart_light.get_status_text(area, chan)
local last_lvl = smart_light.registry.areas[area].channels[chan].last_level or "max"
local subfs = "size[4,5.5]label[0.5,0.2;Channel: " .. chan .. "]" ..
"label[0.5,0.7;Anzahl Leuchten: " .. count .. "]" ..
"label[0.5,1.2;Status: " .. status .. "]" ..
"label[0.5,1.7;Dimmlevel: " .. last_lvl .. "]" ..
"button[0.5,2.5;1.5,0.8;sub_"..chan.."_on;An]" ..
"button[2.2,2.5;1.0,0.8;sub_"..chan.."_up;D+]" ..
"button[0.5,3.5;1.5,0.8;sub_"..chan.."_off;Aus]" ..
"button[2.2,3.5;1.0,0.8;sub_"..chan.."_down;D-]" ..
"button_exit[0.5,4.7;3,0.6;exit;Schließen]"
minetest.show_formspec(puncher:get_player_name(), "smart_light:sub_" .. minetest.pos_to_string(pos), subfs)
end
end,
on_rightclick = function(pos, node, clicker)
local meta = minetest.get_meta(pos)
local area, chan = meta:get_string("sl_area"), meta:get_string("sl_chan")
if area ~= "" and chan ~= "" and smart_light.registry.areas[area] and smart_light.registry.areas[area].channels[chan] then
local status = smart_light.get_status_text(area, chan)
smart_light.switch_channel(area, chan, (status == "AUS") and "on" or "off")
end
end,
after_dig_node = function(pos, oldnode, oldmetadata)
local area, chan = oldmetadata.fields.sl_area, oldmetadata.fields.sl_chan
if area and chan and smart_light.registry.areas[area] and smart_light.registry.areas[area].channels[chan] then
if smart_light.registry.areas[area].channels[chan].switches then
smart_light.registry.areas[area].channels[chan].switches[minetest.pos_to_string(pos)] = nil
smart_light.save()
end
end
end,
})
minetest.register_node("smart_light:switch_active", {
description = "Smart Light Switch",
tiles = {
"smart_light_case.png", "smart_light_case.png",
"smart_light_case.png", "smart_light_case.png",
"smart_light_case.png", "smart_light_case.png^smart_light_button_on.png",
},
drawtype = "nodebox", paramtype = "light", paramtype2 = "facedir",
sunlight_propagates = true, groups = {cracky=2, crumbly=2, not_in_creative_inventory=1},
node_box = switch_box, drop = "smart_light:switch",
on_punch = minetest.registered_nodes["smart_light:switch"].on_punch,
on_rightclick = minetest.registered_nodes["smart_light:switch"].on_rightclick,
after_dig_node = minetest.registered_nodes["smart_light:switch"].after_dig_node,
})