summaryrefslogtreecommitdiff
path: root/extranodes/extramesecons.lua
blob: 05581c59a7b4173139856092a7e6301bd5605193 (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
local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end

if minetest.get_modpath("mesecons") then

	mesecon.register_node("extranodes:mesecon_switch_protected", {
		paramtype2="facedir",
		description="Switch (protected)",
		is_ground_content = false,
		sounds = default.node_sound_stone_defaults(),
		after_place_node = function(pos, placer, itemstack, pointed_thing)
			local meta = minetest.get_meta(pos)
			meta:set_string("owner", placer:get_player_name() or "")
		end,
		on_rightclick = function (pos, node, player)
			local meta = minetest.get_meta(pos)
			local owner = meta:get_string("owner")
			local pname = player:get_player_name();
			if owner ~= pname then
				minetest.chat_send_player(pname, "This switch can only be used by " .. owner)
				return
			end
			if(mesecon.flipstate(pos, node) == "on") then
				mesecon.receptor_on(pos)
			else
				mesecon.receptor_off(pos)
			end
			minetest.sound_play("mesecons_switch", {pos=pos})
		end
	},{
		groups = {dig_immediate=2},
		tiles = {	"mesecons_switch_side.png", 
	                  "mesecons_switch_side.png",
				"mesecons_switch_side.png^default_key.png^[transformR180",
				"mesecons_switch_side.png^default_key.png^[transformR180FX",
				"mesecons_switch_side.png", 
				"mesecons_switch_off.png^mesecons_switch_locked_frame.png"},
		mesecons = {receptor = { state = mesecon.state.off }}
	},{
		groups = {dig_immediate=2, not_in_creative_inventory=1},
		tiles = {	"mesecons_switch_side.png", 
	                  "mesecons_switch_side.png",
				"mesecons_switch_side.png^default_key.png^[transformR180", 
				"mesecons_switch_side.png^default_key.png^[transformR180FX",
				"mesecons_switch_side.png",
				"mesecons_switch_on.png^mesecons_switch_locked_frame.png"},
		mesecons = {receptor = { state = mesecon.state.on }}
	})

	minetest.register_craft({
		output = "extranodes:mesecon_switch_protected_off 2",
		recipe = {
			{"default:steel_ingot", "default:cobble", "default:steel_ingot"},
			{"group:mesecon_conductor_craftable","default:skeleton_key", "group:mesecon_conductor_craftable"},
		}
	})
	
	minetest.register_craft({
		output = "extranodes:mesecon_switch_protected_off",
		type = "shapeless",
		recipe = {"default:skeleton_key", "mesecons_switch:mesecon_switch_off"}
	})

end