aboutsummaryrefslogtreecommitdiff
path: root/advtrains/p_mesecon_iface.lua
blob: 33fcecdab5e0af462388bdd9704e04b0009b24fd (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
name=serialize_lib
title=Lua Serialization Library
description=A library to efficiently write and read Lua tables to/from a file, with support for atomic operations
author=orwell96
47 48 49 50 51 52 53 54 55 56 57 58
-- p_mesecon_iface.lua
-- Mesecons interface by overriding the switch

if minetest.get_modpath("mesecons_switch") == nil then return end

minetest.override_item("mesecons_switch:mesecon_switch_off", {
	groups = {
		dig_immediate=2,
		save_in_at_nodedb=1,
	},
	on_rightclick = function (pos, node)
		advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2})
		mesecon.receptor_on(pos)
		minetest.sound_play("mesecons_switch", {pos=pos})
	end,
	advtrains = {
		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})
				if advtrains.is_node_loaded(pos) then
					mesecon.receptor_on(pos)
				end
			end
		end,
		on_updated_from_nodedb = function(pos, node)
			mesecon.receptor_off(pos)
		end,
	},
})

minetest.override_item("mesecons_switch:mesecon_switch_on", {
	groups = {
		dig_immediate=2,
		save_in_at_nodedb=1,
		not_in_creative_inventory=1,
	},
	on_rightclick = function (pos, node)
		advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2})
		mesecon.receptor_off(pos)
		minetest.sound_play("mesecons_switch", {pos=pos})
	end,
	advtrains = {
		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})
				if advtrains.is_node_loaded(pos) then
					mesecon.receptor_off(pos)
				end
			end
		end,
		fallback_state = "off",
		on_updated_from_nodedb = function(pos, node)
			mesecon.receptor_on(pos)
		end,
	},
})