2016-12-26 06:50:09 +01:00
|
|
|
local rcvboxes = {
|
2015-10-04 13:30:34 +02:00
|
|
|
{ -3/16, -3/16, -8/16 , 3/16, 3/16 , -13/32 }, -- the smaller bump
|
2014-12-06 17:24:34 +01:00
|
|
|
{ -1/32, -1/32, -3/2 , 1/32, 1/32 , -1/2 }, -- the wire through the block
|
|
|
|
{ -2/32, -1/2 , -.5 , 2/32, 0 , -.5002+3/32 }, -- the vertical wire bit
|
|
|
|
{ -2/32, -1/2 , -7/16+0.002 , 2/32, -14/32, 16/32+0.001 } -- the horizontal wire
|
2012-08-18 15:46:26 +02:00
|
|
|
}
|
|
|
|
|
2016-12-26 06:50:09 +01:00
|
|
|
local down_rcvboxes = {
|
|
|
|
{-6/16, -8/16, -6/16, 6/16, -7/16, 6/16}, -- Top plate
|
|
|
|
{-2/16, -6/16, -2/16, 2/16, -7/16, 2/16}, -- Bump
|
|
|
|
{-1/16, -8/16, -1/16, 1/16, -24/16, 1/16}, -- Wire through the block
|
|
|
|
{-1/16, -8/16, 6/16, 1/16, -7/16, 8/16}, -- Plate extension (North)
|
|
|
|
{-1/16, -8/16, -6/16, 1/16, -7/16, -8/16}, -- Plate extension (South)
|
|
|
|
{-8/16, -8/16, 1/16, -6/16, -7/16, -1/16}, -- Plate extension (West)
|
|
|
|
{6/16, -8/16, 1/16, 8/16, -7/16, -1/16}, -- Plate extension (East)
|
|
|
|
}
|
|
|
|
|
|
|
|
local up_rcvboxes = {
|
|
|
|
{-6/16, -8/16, -6/16, 6/16, -7/16, 6/16}, -- Top plate
|
|
|
|
{-2/16, -6/16, -2/16, 2/16, -7/16, 2/16}, -- Bump
|
|
|
|
{-1/16, -6/16, -1/16, 1/16, 24/16, 1/16}, -- Wire through the block
|
|
|
|
{-1/16, -8/16, 6/16, 1/16, -7/16, 8/16}, -- Plate extension (North)
|
|
|
|
{-1/16, -8/16, -6/16, 1/16, -7/16, -8/16}, -- Plate extension (South)
|
|
|
|
{-8/16, -8/16, 1/16, -6/16, -7/16, -1/16}, -- Plate extension (West)
|
|
|
|
{6/16, -8/16, 1/16, 8/16, -7/16, -1/16}, -- Plate extension (East)
|
|
|
|
}
|
|
|
|
|
2012-12-09 00:42:30 +01:00
|
|
|
local receiver_get_rules = function (node)
|
|
|
|
local rules = { {x = 1, y = 0, z = 0},
|
|
|
|
{x = -2, y = 0, z = 0}}
|
|
|
|
if node.param2 == 2 then
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
2012-12-09 00:42:30 +01:00
|
|
|
elseif node.param2 == 3 then
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules))
|
2012-12-09 00:42:30 +01:00
|
|
|
elseif node.param2 == 0 then
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_right(rules)
|
2012-12-09 00:42:30 +01:00
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
2016-12-26 06:50:09 +01:00
|
|
|
mesecon.register_node("mesecons_receiver:receiver", {
|
2012-08-18 15:46:26 +02:00
|
|
|
drawtype = "nodebox",
|
2016-12-26 06:50:09 +01:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2016-12-26 06:50:09 +01:00
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
on_rotate = false,
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
|
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = rcvboxes
|
|
|
|
},
|
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
|
|
|
drop = "mesecons:wire_00000000_off",
|
2018-01-28 20:56:42 +01:00
|
|
|
sounds = default.node_sound_defaults(),
|
2016-12-26 06:50:09 +01:00
|
|
|
}, {
|
|
|
|
tiles = {
|
|
|
|
"receiver_top_off.png",
|
|
|
|
"receiver_bottom_off.png",
|
|
|
|
"receiver_lr_off.png",
|
|
|
|
"receiver_lr_off.png",
|
|
|
|
"receiver_fb_off.png",
|
|
|
|
"receiver_fb_off.png",
|
|
|
|
},
|
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
rules = receiver_get_rules,
|
|
|
|
onstate = "mesecons_receiver:receiver_on"
|
|
|
|
}}
|
|
|
|
}, {
|
2012-08-18 15:46:26 +02:00
|
|
|
tiles = {
|
2012-09-01 20:37:32 +02:00
|
|
|
"receiver_top_on.png",
|
|
|
|
"receiver_bottom_on.png",
|
2012-08-28 20:17:18 +02:00
|
|
|
"receiver_lr_on.png",
|
|
|
|
"receiver_lr_on.png",
|
|
|
|
"receiver_fb_on.png",
|
|
|
|
"receiver_fb_on.png",
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
2016-12-26 06:50:09 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.on,
|
|
|
|
rules = receiver_get_rules,
|
|
|
|
offstate = "mesecons_receiver:receiver_off"
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
mesecon.register_node("mesecons_receiver:receiver_up", {
|
|
|
|
drawtype = "nodebox",
|
2012-08-18 15:46:26 +02:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-09-07 15:59:49 +02:00
|
|
|
sunlight_propagates = true,
|
2012-12-09 13:28:32 +01:00
|
|
|
walkable = false,
|
2016-12-26 06:50:09 +01:00
|
|
|
on_rotate = false,
|
2012-08-18 15:46:26 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2016-12-26 06:50:09 +01:00
|
|
|
fixed = up_rcvboxes
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
2016-12-26 06:50:09 +01:00
|
|
|
fixed = up_rcvboxes
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
2012-12-09 00:42:30 +01:00
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
2012-08-17 16:28:59 +02:00
|
|
|
drop = "mesecons:wire_00000000_off",
|
2018-01-28 20:56:42 +01:00
|
|
|
sounds = default.node_sound_defaults(),
|
2016-12-26 06:50:09 +01:00
|
|
|
}, {
|
|
|
|
tiles = {"mesecons_wire_off.png"},
|
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
rules = {{x=1, y=0, z=0},
|
|
|
|
{x=-1, y=0, z=0},
|
|
|
|
{x=0, y=0, z=1},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{x=0, y=1, z=0},
|
|
|
|
{x=0, y=2, z=0}},
|
|
|
|
onstate = "mesecons_receiver:receiver_up_on"
|
|
|
|
}}
|
|
|
|
}, {
|
|
|
|
tiles = {"mesecons_wire_on.png"},
|
2012-12-09 00:42:30 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.on,
|
2016-12-26 06:50:09 +01:00
|
|
|
rules = {{x=1, y=0, z=0},
|
|
|
|
{x=-1, y=0, z=0},
|
|
|
|
{x=0, y=0, z=1},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{x=0, y=1, z=0},
|
|
|
|
{x=0, y=2, z=0}},
|
|
|
|
offstate = "mesecons_receiver:receiver_up_off"
|
2012-12-09 00:42:30 +01:00
|
|
|
}}
|
2012-08-17 16:28:59 +02:00
|
|
|
})
|
|
|
|
|
2016-12-26 06:50:09 +01:00
|
|
|
mesecon.register_node("mesecons_receiver:receiver_down", {
|
2012-08-18 15:46:26 +02:00
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-09-07 15:59:49 +02:00
|
|
|
sunlight_propagates = true,
|
2012-12-09 13:28:32 +01:00
|
|
|
walkable = false,
|
2016-12-26 06:50:09 +01:00
|
|
|
on_rotate = false,
|
2012-08-18 15:46:26 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2016-12-26 06:50:09 +01:00
|
|
|
fixed = down_rcvboxes
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
2016-12-26 06:50:09 +01:00
|
|
|
fixed = down_rcvboxes
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
2012-12-09 00:42:30 +01:00
|
|
|
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
2012-08-17 16:28:59 +02:00
|
|
|
drop = "mesecons:wire_00000000_off",
|
2018-01-28 20:56:42 +01:00
|
|
|
sounds = default.node_sound_defaults(),
|
2016-12-26 06:50:09 +01:00
|
|
|
}, {
|
|
|
|
tiles = {"mesecons_wire_off.png"},
|
2012-12-09 00:42:30 +01:00
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.off,
|
2016-12-26 06:50:09 +01:00
|
|
|
rules = {{x=1,y=0, z=0},
|
|
|
|
{x=-1,y=0, z=0},
|
|
|
|
{x=0, y=0, z=1},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{x=0, y=-2,z=0}},
|
|
|
|
onstate = "mesecons_receiver:receiver_down_on"
|
|
|
|
}}
|
|
|
|
}, {
|
|
|
|
tiles = {"mesecons_wire_on.png"},
|
|
|
|
mesecons = {conductor = {
|
|
|
|
state = mesecon.state.on,
|
|
|
|
rules = {{x=1,y=0, z=0},
|
|
|
|
{x=-1,y=0, z=0},
|
|
|
|
{x=0, y=0, z=1},
|
|
|
|
{x=0, y=0, z=-1},
|
|
|
|
{x=0, y=-2,z=0}},
|
|
|
|
offstate = "mesecons_receiver:receiver_down_off"
|
2012-12-09 00:42:30 +01:00
|
|
|
}}
|
2012-08-17 16:28:59 +02:00
|
|
|
})
|
|
|
|
|
2014-11-22 15:42:22 +01:00
|
|
|
function mesecon.receiver_get_pos_from_rcpt(pos, param2)
|
2014-11-22 11:37:47 +01:00
|
|
|
local rules = {{x = 2, y = 0, z = 0}}
|
2013-12-01 04:13:00 +01:00
|
|
|
if param2 == nil then param2 = minetest.get_node(pos).param2 end
|
2016-12-26 06:50:09 +01:00
|
|
|
local rcvtype = "mesecons_receiver:receiver_off"
|
|
|
|
local dir = minetest.facedir_to_dir(param2)
|
|
|
|
|
|
|
|
if dir.x == 1 then
|
|
|
|
-- No action needed
|
|
|
|
elseif dir.z == -1 then
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
2016-12-26 06:50:09 +01:00
|
|
|
elseif dir.x == -1 then
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules))
|
2016-12-26 06:50:09 +01:00
|
|
|
elseif dir.z == 1 then
|
2014-11-22 15:42:22 +01:00
|
|
|
rules = mesecon.rotate_rules_right(rules)
|
2016-12-26 06:50:09 +01:00
|
|
|
elseif dir.y == -1 then
|
|
|
|
rules = mesecon.rotate_rules_up(rules)
|
|
|
|
rcvtype = "mesecons_receiver:receiver_up_off"
|
|
|
|
elseif dir.y == 1 then
|
|
|
|
rules = mesecon.rotate_rules_down(rules)
|
|
|
|
rcvtype = "mesecons_receiver:receiver_down_off"
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
2014-11-22 16:00:49 +01:00
|
|
|
local np = { x = pos.x + rules[1].x,
|
|
|
|
y = pos.y + rules[1].y,
|
|
|
|
z = pos.z + rules[1].z}
|
2016-12-26 06:50:09 +01:00
|
|
|
return np, rcvtype
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
|
|
|
|
2014-11-22 15:42:22 +01:00
|
|
|
function mesecon.receiver_place(rcpt_pos)
|
2013-12-01 04:13:00 +01:00
|
|
|
local node = minetest.get_node(rcpt_pos)
|
2016-12-26 06:50:09 +01:00
|
|
|
local pos, rcvtype = mesecon.receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
|
2013-12-01 04:13:00 +01:00
|
|
|
local nn = minetest.get_node(pos)
|
2016-12-26 06:50:09 +01:00
|
|
|
local param2 = minetest.dir_to_facedir(minetest.facedir_to_dir(node.param2))
|
2012-08-17 16:28:59 +02:00
|
|
|
|
|
|
|
if string.find(nn.name, "mesecons:wire_") ~= nil then
|
2016-12-26 06:50:09 +01:00
|
|
|
minetest.set_node(pos, {name = rcvtype, param2 = param2})
|
2016-08-23 07:20:46 +02:00
|
|
|
mesecon.on_placenode(pos, nn)
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-22 15:42:22 +01:00
|
|
|
function mesecon.receiver_remove(rcpt_pos, dugnode)
|
|
|
|
local pos = mesecon.receiver_get_pos_from_rcpt(rcpt_pos, dugnode.param2)
|
2013-12-01 04:13:00 +01:00
|
|
|
local nn = minetest.get_node(pos)
|
2018-07-21 09:42:24 +02:00
|
|
|
if string.find(nn.name, "mesecons_receiver:receiver_") ~= nil then
|
2013-02-08 20:18:42 +01:00
|
|
|
local node = {name = "mesecons:wire_00000000_off"}
|
2016-02-14 21:00:37 +01:00
|
|
|
minetest.set_node(pos, node)
|
2013-02-08 20:18:42 +01:00
|
|
|
mesecon.on_placenode(pos, node)
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_placenode(function (pos, node)
|
|
|
|
if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.receiver_place(pos)
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_dignode(function(pos, node)
|
|
|
|
if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.receiver_remove(pos, node)
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_placenode(function (pos, node)
|
2016-12-26 06:50:09 +01:00
|
|
|
if string.find(node.name, "mesecons:wire_") ~= nil then
|
|
|
|
local rules = { {x = 2, y = 0, z = 0},
|
|
|
|
{x =-2, y = 0, z = 0},
|
|
|
|
{x = 0, y = 0, z = 2},
|
|
|
|
{x = 0, y = 0, z =-2},
|
|
|
|
{x = 0, y = 2, z = 0},
|
|
|
|
{x = 0, y = -2, z = 0}}
|
2012-08-17 16:28:59 +02:00
|
|
|
local i = 1
|
|
|
|
while rules[i] ~= nil do
|
2014-11-22 16:00:49 +01:00
|
|
|
local np = { x = pos.x + rules[i].x,
|
|
|
|
y = pos.y + rules[i].y,
|
|
|
|
z = pos.z + rules[i].z}
|
2013-12-01 04:13:00 +01:00
|
|
|
if minetest.get_item_group(minetest.get_node(np).name, "mesecon_needs_receiver") == 1 then
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.receiver_place(np)
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2016-12-26 06:50:09 +01:00
|
|
|
|
|
|
|
function mesecon.buttonlike_onrotate(pos, node)
|
|
|
|
minetest.after(0, mesecon.receiver_remove, pos, node)
|
|
|
|
minetest.after(0, mesecon.receiver_place, pos)
|
|
|
|
end
|