summaryrefslogtreecommitdiff
path: root/init.lua
blob: 0e140d75d58940eaa5e52aa98341384fe94ddc44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
rgblightstone = {}
rgblightstone.colors = {"off","black","blue","brown","cyan","darkblue","darkcyan","darkgray","darkgreen","darkmagenta","darkred","gray","green","magenta","red","white","yellow"}
function rgblightstone.add(name)
	minetest.register_node("rgblightstone:lightstone_" .. name, {
		tiles = name == "off" and {"jeija_lightstone_darkgray_off.png"} or {"rgblightstone_"..name..".png"},
		drop = "rgblightstone:lightstone_off",
		groups = name == "off" and {cracky=2} or {cracky=2,not_in_creative_inventory=1},
		description="RGB Lightstone ("..name..")",
		sounds = default.node_sound_stone_defaults(),
		on_construct = function(pos)
			local meta = minetest.get_meta(pos)
			meta:set_string("formspec", "field[channel;Channel;${channel}]")
		end,
		on_receive_fields = function(pos, formname, fields, sender)
			if fields.channel then minetest.get_meta(pos):set_string("channel", fields.channel) end
		end,
		light_source = name~= "off" and default.LIGHT_MAX-2 or 0,
		digiline = {
			receptor = {},
			effector = {
				action = function(pos, node, channel, msg)
					local channel_set = minetest.get_meta(pos):get_string("channel")
					if channel==channel_set then
						for _,color in ipairs(rgblightstone.colors) do
							if msg==color then minetest.swap_node(pos, {name = "rgblightstone:lightstone_"..color}) end
						end
					end
				end
			}
		}
	})
end
for _,i in ipairs(rgblightstone.colors) do rgblightstone.add(i) end
if minetest.get_modpath("mesecons_luacontroller") and minetest.get_modpath("digilines") then
	minetest.register_craft({
		output = "rgblightstone:lightstone_off",
		recipe = {
			{"","mesecons_lightstone:lightstone_green_off",""},
			{"mesecons_lightstone:lightstone_red_off","mesecons_luacontroller:luacontroller0000","mesecons_lightstone:lightstone_blue_off"},
			{"","digilines:wire_std_00000000",""}
		}
	})
else
        minetest.register_craft({
                output = "rgblightstone:lightstone_off",
                recipe = {
                        {"","mesecons_lightstone:lightstone_green_off",""},
                        {"mesecons_lightstone:lightstone_red_off","group:mesecon_conductor_craftable","mesecons_lightstone:lightstone_blue_off"},
                        {"","group:mesecon_conductor_craftable",""}
                }
        })
end