2017-01-31 06:34:41 +01:00
|
|
|
|
2019-04-21 17:25:21 +02:00
|
|
|
local S = homedecor.gettext
|
2017-01-31 06:34:41 +01:00
|
|
|
|
2019-05-26 07:33:22 +02:00
|
|
|
function homedecor.toggle_switch(pos, node, clicker, itemstack, pointed_thing)
|
2019-05-31 14:00:09 +02:00
|
|
|
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)
|
2019-05-26 07:33:22 +02:00
|
|
|
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
|
|
|
|
|
2015-01-24 00:34:02 +01:00
|
|
|
homedecor.register("power_outlet", {
|
2017-01-31 06:34:41 +01:00
|
|
|
description = S("Power Outlet"),
|
2014-06-26 05:08:20 +02:00
|
|
|
tiles = {
|
|
|
|
"homedecor_outlet_edges.png",
|
|
|
|
"homedecor_outlet_edges.png",
|
|
|
|
"homedecor_outlet_edges.png",
|
|
|
|
"homedecor_outlet_edges.png",
|
|
|
|
"homedecor_outlet_back.png",
|
2014-11-03 12:46:45 +01:00
|
|
|
"homedecor_outlet_edges.png"
|
2014-06-26 05:08:20 +02:00
|
|
|
},
|
2014-08-02 02:45:41 +02:00
|
|
|
inventory_image = "homedecor_outlet_inv.png",
|
2014-06-26 05:08:20 +02:00
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
2014-08-02 06:12:23 +02:00
|
|
|
{ -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},
|
2014-06-26 05:08:20 +02:00
|
|
|
}
|
|
|
|
},
|
2014-08-02 02:45:41 +02:00
|
|
|
groups = {cracky=3,dig_immediate=2},
|
2015-04-29 14:14:36 +02:00
|
|
|
walkable = false
|
2014-06-26 05:08:20 +02:00
|
|
|
})
|
|
|
|
|
2019-05-26 07:33:22 +02:00
|
|
|
for _, onoff in ipairs ({"on", "off"}) do
|
2014-06-26 05:08:20 +02:00
|
|
|
|
2019-05-26 07:33:22 +02:00
|
|
|
local model = {
|
2019-05-26 08:17:21 +02:00
|
|
|
{ -0.125, -0.1875, 0.4375, 0.125, 0.125, 0.5 },
|
|
|
|
{ -0.03125, 0, 0.40625, 0.03125, 0.0625, 0.5 },
|
2019-05-26 07:33:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if onoff == "on" then
|
|
|
|
model = {
|
2019-05-26 08:17:21 +02:00
|
|
|
{ -0.125, -0.1875, 0.4375, 0.125, 0.125, 0.5 },
|
|
|
|
{ -0.03125, -0.125, 0.40625, 0.03125, -0.0625, 0.5 },
|
2014-06-26 05:08:20 +02:00
|
|
|
}
|
2019-05-26 07:33:22 +02:00
|
|
|
end
|
2014-06-26 05:08:20 +02:00
|
|
|
|
2019-05-26 07:33:22 +02:00
|
|
|
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 = {
|
2019-05-26 08:17:21 +02:00
|
|
|
{ -0.1875, -0.25, 0.375, 0.1875, 0.1875, 0.5 },
|
2019-05-26 07:33:22 +02:00
|
|
|
}
|
|
|
|
},
|
2019-05-26 07:49:56 +02:00
|
|
|
groups = {cracky=3, dig_immediate=2, mesecon_needs_receiver=1, not_in_creative_inventory = (onoff == "on") and 1 or nil},
|
2019-05-26 07:33:22 +02:00
|
|
|
walkable = false,
|
|
|
|
drop = {
|
|
|
|
items = {
|
|
|
|
{items = {"homedecor:light_switch_off"}, inherit_color = true },
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mesecons = switch_receptor,
|
|
|
|
on_rightclick = on_rc
|
|
|
|
})
|
|
|
|
end
|
2015-01-23 22:48:40 +01:00
|
|
|
|
2015-01-24 00:34:02 +01:00
|
|
|
homedecor.register("doorbell", {
|
2015-01-23 22:48:40 +01:00
|
|
|
tiles = { "homedecor_doorbell.png" },
|
|
|
|
inventory_image = "homedecor_doorbell_inv.png",
|
2017-01-31 06:34:41 +01:00
|
|
|
description = S("Doorbell"),
|
2015-01-23 22:48:40 +01:00
|
|
|
groups = {snappy=3},
|
2015-04-29 14:14:36 +02:00
|
|
|
walkable = false,
|
2015-01-23 22:48:40 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
},
|
2017-02-21 00:30:59 +01:00
|
|
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
2015-01-23 22:48:40 +01:00
|
|
|
minetest.sound_play("homedecor_doorbell", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1.0,
|
|
|
|
max_hear_distance = 15
|
|
|
|
})
|
|
|
|
end
|
|
|
|
})
|
2019-04-20 21:49:36 +02:00
|
|
|
|
|
|
|
-- 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( {
|
2019-05-26 07:49:56 +02:00
|
|
|
output = "homedecor:light_switch_off",
|
2019-04-20 21:49:36 +02:00
|
|
|
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" }
|
|
|
|
},
|
|
|
|
})
|
2019-05-26 07:33:22 +02:00
|
|
|
|
|
|
|
-- aliases
|
|
|
|
|
|
|
|
minetest.register_alias("homedecor:light_switch", "homedecor:light_switch_on")
|