aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains_luaautomation/p_mesecon_iface.lua
blob: d7e105240649d52a9f64229996ed8ad3142f7b1e (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
-- p_mesecon_iface.lua
-- Mesecons interface by overriding the switch

if not mesecon then return end

minetest.override_item("mesecons_switch:mesecon_switch_off", {
	groups = {
		dig_immediate=2,
		save_in_nodedb=1,
	},
	on_rightclick = function (pos, node)
		if(mesecon.flipstate(pos, node) == "on") then
			mesecon.receptor_on(pos)
		else
			mesecon.receptor_off(pos)
		end
		minetest.sound_play("mesecons_switch", {pos=pos})
		advtrains.ndb.update(pos, node)
	end,
	on_updated_from_nodedb = function(pos, node)
		mesecon.receptor_off(pos)
	end,
	luaautomation = {
		getstate = "off",
		setstate = function(pos, node, newstate)
			if newstate=="on" then
				advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2})
				mesecon.receptor_on(pos)
			end
		end,
	},
})

minetest.override_item("mesecons_switch:mesecon_switch_on", {
	groups = {
		dig_immediate=2,
		save_in_nodedb=1,
	},
	on_rightclick = function (pos, node)
		if(mesecon.flipstate(pos, node) == "on") then
			mesecon.receptor_on(pos)
		else
			mesecon.receptor_off(pos)
		end
		minetest.sound_play("mesecons_switch", {pos=pos})
		advtrains.ndb.update(pos, node)
	end,
	on_updated_from_nodedb = function(pos, node)
		mesecon.receptor_on(pos)
	end,
	luaautomation = {
		getstate = "on",
		setstate = function(pos, node, newstate)
			if newstate=="off" then
				advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2})
				mesecon.receptor_off(pos)
			end
		end,
	},
})