mesecon_lights lua

This commit is contained in:
rnd1 2016-05-07 18:03:11 +02:00
parent 7b146ef614
commit 7df4aaa853

52
mesecon_lights.lua Normal file
View File

@ -0,0 +1,52 @@
-- make other light blocks toggle able:
local function enable_toggle_ligth(name)
local table = minetest.registered_nodes[name]; if not table then return end
local table2 = {}
for i,v in pairs(table) do
table2[i] = v
end
if table2.mesecons then return end -- we dont want to overwrite existing stuff!
local offname = "basic_machines:"..string.gsub(name, ":", "_").. "_OFF";
table2.mesecons = {effector = { -- action to toggle light off
action_off = function (pos,node,ttl)
if ttl<0 then return end
minetest.swap_node(pos,{name = offname});
end
}
};
minetest.register_node(":"..name, table2) -- redefine item
-- STRANGE BUG1: if you dont make new table table3 and reuse table2 definition original node (definition one line above) is changed by below code too!???
-- STRANGE BUG2: if you dont make new table3.. original node automatically changes to OFF node when placed ????
local table3 = {}
for i,v in pairs(table) do
table3[i] = v
end
table3.light_source = 0; -- off block has light off
table3.mesecons = {effector = {
action_on = function (pos,node,ttl)
if ttl<0 then return end
minetest.swap_node(pos,{name = name});
end
}
};
-- REGISTER OFF BLOCK
minetest.register_node(":"..offname, table3);
end
enable_toggle_ligth("xdecor:wooden_lightbox");
enable_toggle_ligth("xdecor:iron_lightbox");
enable_toggle_ligth("moreblocks:slab_meselamp_1");
enable_toggle_ligth("moreblocks:slab_super_glow_glass");