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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
local S = homedecor.gettext
function homedecor.toggle_switch(pos, node, clicker, itemstack, pointed_thing)
if not clicker then return false end
local playername = clicker:get_player_name()
if minetest.is_protected(pos, playername) then
minetest.record_protection_violation(pos, playername)
return false
end
local sep = string.find(node.name, "_o", -5)
local onoff = string.sub(node.name, sep + 1)
local newname = string.sub(node.name, 1, sep - 1)..((onoff == "off") and "_on" or "_off")
minetest.swap_node(pos, {name = newname, param2 = node.param2})
return true
end
local on_rc
local switch_receptor
if minetest.get_modpath("mesecons") then
on_rc = function(pos, node, clicker, itemstack, pointed_thing)
local t = homedecor.toggle_switch(pos, node, clicker, itemstack, pointed_thing)
if not t then return end
if string.find(node.name, "_on", -5) then
mesecon.receptor_off(pos, mesecon.rules.buttonlike_get(node))
else
mesecon.receptor_on(pos, mesecon.rules.buttonlike_get(node))
end
end
switch_receptor = {
receptor = {
state = mesecon.state[onoff],
rules = mesecon.rules.buttonlike_get
}
}
end
homedecor.register("power_outlet", {
description = S("Power Outlet"),
tiles = {
"homedecor_outlet_edges.png",
"homedecor_outlet_edges.png",
"homedecor_outlet_edges.png",
"homedecor_outlet_edges.png",
"homedecor_outlet_back.png",
"homedecor_outlet_edges.png"
},
inventory_image = "homedecor_outlet_inv.png",
node_box = {
type = "fixed",
fixed = {
{ -0.125, -0.3125, 0.4375, 0.125, 0, 0.5},
}
},
selection_box = {
type = "fixed",
fixed = {
{ -0.1875, -0.375, 0.375, 0.1875, 0.0625, 0.5},
}
},
groups = {cracky=3,dig_immediate=2},
walkable = false
})
for _, onoff in ipairs ({"on", "off"}) do
local model = {
{ -0.125, -0.1875, 0.4375, 0.125, 0.125, 0.5 },
{ -0.03125, 0, 0.40625, 0.03125, 0.0625, 0.5 },
}
if onoff == "on" then
model = {
{ -0.125, -0.1875, 0.4375, 0.125, 0.125, 0.5 },
{ -0.03125, -0.125, 0.40625, 0.03125, -0.0625, 0.5 },
}
end
homedecor.register("light_switch_"..onoff, {
description = S("Light switch"),
tiles = {
"homedecor_light_switch_edges.png",
"homedecor_light_switch_edges.png",
"homedecor_light_switch_edges.png",
"homedecor_light_switch_edges.png",
"homedecor_light_switch_back.png",
"homedecor_light_switch_front_"..onoff..".png"
},
inventory_image = "homedecor_light_switch_inv.png",
node_box = {
type = "fixed",
fixed = model
},
selection_box = {
type = "fixed",
fixed = {
{ -0.1875, -0.25, 0.375, 0.1875, 0.1875, 0.5 },
}
},
groups = {cracky=3, dig_immediate=2, mesecon_needs_receiver=1, not_in_creative_inventory = (onoff == "on") and 1 or nil},
walkable = false,
drop = {
items = {
{items = {"homedecor:light_switch_off"}, inherit_color = true },
}
},
mesecons = switch_receptor,
on_rightclick = on_rc
})
end
homedecor.register("doorbell", {
tiles = { "homedecor_doorbell.png" },
inventory_image = "homedecor_doorbell_inv.png",
description = S("Doorbell"),
groups = {snappy=3},
walkable = false,
node_box = {
type = "fixed",
fixed = {
{-0.0625, 0, 0.46875, 0.0625, 0.1875, 0.5}, -- NodeBox1
{-0.03125, 0.0625, 0.45, 0.03125, 0.125, 0.4675}, -- NodeBox2
}
},
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
minetest.sound_play("homedecor_doorbell", {
pos = pos,
gain = 1.0,
max_hear_distance = 15
})
end
})
-- crafting
minetest.register_craft( {
output = "homedecor:power_outlet",
recipe = {
{"basic_materials:plastic_sheet", "basic_materials:copper_strip"},
{"basic_materials:plastic_sheet", ""},
{"basic_materials:plastic_sheet", "basic_materials:copper_strip"}
},
})
minetest.register_craft( {
output = "homedecor:light_switch_off",
recipe = {
{"", "basic_materials:plastic_sheet", "basic_materials:copper_strip"},
{"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:copper_strip"},
{"", "basic_materials:plastic_sheet", "basic_materials:copper_strip"}
},
})
minetest.register_craft( {
output = "homedecor:doorbell",
recipe = {
{ "homedecor:light_switch", "basic_materials:energy_crystal_simple", "homedecor:speaker_driver" }
},
})
-- aliases
minetest.register_alias("homedecor:light_switch", "homedecor:light_switch_on")
|