summaryrefslogtreecommitdiff
path: root/light.lua
blob: aeca08de336c3c8dd5a4913a3b8de129b154b169 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
for i=0,14,1 do
	local mult = 255 - ((14-i)*12)
	minetest.register_node("digistuff:light_"..i, {
		drop = "digistuff:light_0",
		description = "Digilines Dimmable Light"..(i > 0 and " (on state - you hacker you!)" or ""),
		tiles = {"digistuff_light.png"},
		paramtype = "light",
		paramtype2 = "facedir",
		drawtype = "nodebox",
		node_box = {
			type = "fixed",
			fixed = {
					{-0.25,0.4,-0.25,0.25,0.5,0.25},
				}
		},
		groups = i > 0 and {cracky = 1, not_in_creative_inventory = 1} or {cracky = 1},
		is_ground_content = false,
		light_source = i,
		color = {r = mult,g = mult,b = mult},
		sounds = default and default.node_sound_glass_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)
			local name = sender:get_player_name()
			if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
				minetest.record_protection_violation(pos,name)
				return
			end
			local meta = minetest.get_meta(pos)
			if fields.channel then meta:set_string("channel",fields.channel) end
		end,
		digiline = {
			receptor = {},
			wire = {
				rules = {
					{x = 1,y = 0,z = 0},
					{x = -1,y = 0,z = 0},
					{x = 0,y = 0,z = 1},
					{x = 0,y = 0,z = -1},
					{x = 0,y = 1,z = 0},
					{x = 0,y = -1,z = 0},
					{x = 2,y = 0,z = 0},
					{x = -2,y = 0,z = 0},
					{x = 0,y = 0,z = 2},
					{x = 0,y = 0,z = -2},
					{x = 0,y = 2,z = 0},
					{x = 0,y = -2,z = 0},
				}
			},
			effector = {
				action = function(pos,node,channel,msg)
						local meta = minetest.get_meta(pos)
						if meta:get_string("channel") ~= channel then return end
						local value = tonumber(msg)
						if (not value) or value > 14 or value < 0 then return end
						node.name = "digistuff:light_"..math.floor(value)
						minetest.swap_node(pos,node)
					end
			},
		},
	})
end

minetest.register_craft({
	output = "digistuff:light_0",
	recipe = {
		{"digilines:wire_std_00000000","mesecons_lamp:lamp_off",},
	}
})