2012-08-18 15:46:26 +02:00
|
|
|
rcvboxes = {
|
2012-09-01 20:37:32 +02:00
|
|
|
{ -3/16, -3/16 , -8/16 , 3/16, 3/16, -13/32 }, -- the smaller bump
|
|
|
|
{ -5/32, -5/32 , -13/32 , 5/32, 5/32, -12/32 }, -- the receiver itself
|
|
|
|
{ -3/32, -.5-1/32, -.5 , 3/32, 0 , -.5002+3/32 }, -- the vertical wire bit
|
|
|
|
{ -3/32, -17/32 , -7/16+0.002 , 3/32, -13/32, 16/32+0.001 } -- the horizontal wire
|
2012-08-18 15:46:26 +02:00
|
|
|
}
|
|
|
|
|
2012-08-17 16:28:59 +02:00
|
|
|
minetest.register_node("mesecons_receiver:receiver_on", {
|
2012-08-18 15:46:26 +02:00
|
|
|
drawtype = "nodebox",
|
|
|
|
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
|
|
|
},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2012-08-28 20:17:18 +02:00
|
|
|
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = rcvboxes
|
|
|
|
},
|
2012-08-17 16:28:59 +02:00
|
|
|
groups = {dig_immediate = 3, mesecon = 3, not_in_creative_inventory = 1},
|
|
|
|
drop = "mesecons:wire_00000000_off",
|
2012-08-18 15:46:26 +02:00
|
|
|
|
2012-08-17 16:28:59 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("mesecons_receiver:receiver_off", {
|
2012-08-18 15:46:26 +02:00
|
|
|
drawtype = "nodebox",
|
2012-08-17 16:28:59 +02:00
|
|
|
description = "You hacker you",
|
2012-08-18 15:46:26 +02:00
|
|
|
tiles = {
|
2012-09-01 20:37:32 +02:00
|
|
|
"receiver_top_off.png",
|
|
|
|
"receiver_bottom_off.png",
|
2012-08-28 20:17:18 +02:00
|
|
|
"receiver_lr_off.png",
|
|
|
|
"receiver_lr_off.png",
|
|
|
|
"receiver_fb_off.png",
|
|
|
|
"receiver_fb_off.png",
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2012-08-28 20:17:18 +02:00
|
|
|
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
|
2012-08-18 15:46:26 +02:00
|
|
|
},
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = rcvboxes
|
|
|
|
},
|
2012-08-17 16:28:59 +02:00
|
|
|
groups = {dig_immediate = 3, mesecon = 3},
|
|
|
|
drop = "mesecons:wire_00000000_off",
|
|
|
|
})
|
|
|
|
|
|
|
|
mesecon:add_rules("receiver_pos", {{x = 2, y = 0, z = 0}})
|
|
|
|
|
|
|
|
mesecon:add_rules("receiver_pos_all", {
|
|
|
|
{x = 2, y = 0, z = 0},
|
|
|
|
{x =-2, y = 0, z = 0},
|
|
|
|
{x = 0, y = 0, z = 2},
|
|
|
|
{x = 0, y = 0, z =-2}})
|
|
|
|
|
|
|
|
mesecon:add_rules("mesecon_receiver", {
|
|
|
|
{x = 1, y = 0, z = 0},
|
|
|
|
{x = -2, y = 0, z = 0},})
|
|
|
|
|
|
|
|
mesecon:add_rules("mesecon_receiver_all", {
|
|
|
|
{x = 1, y = 0, z = 0},
|
|
|
|
{x =-2, y = 0, z = 0},
|
|
|
|
{x =-1, y = 0, z = 0},
|
|
|
|
{x = 2, y = 0, z = 0},
|
|
|
|
{x = 0, y = 0, z = 1},
|
|
|
|
{x = 0, y = 0, z =-2},
|
|
|
|
{x = 1, y = 0, z =-1},
|
|
|
|
{x =-2, y = 0, z = 2},})
|
|
|
|
|
|
|
|
function receiver_get_rules(param2)
|
|
|
|
local rules = mesecon:get_rules("mesecon_receiver")
|
|
|
|
if param2 == 2 then
|
|
|
|
rules = mesecon:rotate_rules_left(rules)
|
|
|
|
elseif param2 == 3 then
|
|
|
|
rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
|
|
|
elseif param2 == 0 then
|
|
|
|
rules = mesecon:rotate_rules_right(rules)
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
mesecon:register_conductor("mesecons_receiver:receiver_on", "mesecons_receiver:receiver_off", mesecon:get_rules("mesecon_receiver_all"), receiver_get_rules)
|
|
|
|
|
2012-08-17 23:48:09 +02:00
|
|
|
function mesecon:receiver_get_pos_from_rcpt(pos, param2)
|
2012-08-17 16:28:59 +02:00
|
|
|
local rules = mesecon:get_rules("receiver_pos")
|
2012-08-17 23:48:09 +02:00
|
|
|
if param2 == nil then param2 = minetest.env:get_node(pos).param2 end
|
|
|
|
if param2 == 2 then
|
2012-08-17 16:28:59 +02:00
|
|
|
rules = mesecon:rotate_rules_left(rules)
|
2012-08-17 23:48:09 +02:00
|
|
|
elseif param2 == 3 then
|
2012-08-17 16:28:59 +02:00
|
|
|
rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
2012-08-17 23:48:09 +02:00
|
|
|
elseif param2 == 0 then
|
2012-08-17 16:28:59 +02:00
|
|
|
rules = mesecon:rotate_rules_right(rules)
|
|
|
|
end
|
|
|
|
np = {
|
|
|
|
x = pos.x + rules[1].x,
|
|
|
|
y = pos.y + rules[1].y,
|
|
|
|
z = pos.z + rules[1].z}
|
|
|
|
return np
|
|
|
|
end
|
|
|
|
|
|
|
|
function mesecon:receiver_place(rcpt_pos)
|
|
|
|
local node = minetest.env:get_node(rcpt_pos)
|
2012-08-17 23:48:09 +02:00
|
|
|
local pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
|
|
|
|
local nn = minetest.env:get_node(pos)
|
2012-08-17 16:28:59 +02:00
|
|
|
|
|
|
|
if string.find(nn.name, "mesecons:wire_") ~= nil then
|
|
|
|
minetest.env:dig_node(pos)
|
2012-08-19 10:38:44 +02:00
|
|
|
if mesecon:is_power_on(rcpt_pos) then
|
|
|
|
minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2})
|
|
|
|
mesecon:receptor_on(pos, receiver_get_rules(node.param2))
|
|
|
|
else
|
|
|
|
minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2})
|
|
|
|
end
|
2012-08-17 16:28:59 +02:00
|
|
|
mesecon:update_autoconnect(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-17 23:48:09 +02:00
|
|
|
function mesecon:receiver_remove(rcpt_pos, dugnode)
|
|
|
|
local pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos, dugnode.param2)
|
|
|
|
local nn = minetest.env:get_node(pos)
|
|
|
|
if string.find(nn.name, "mesecons_receiver:receiver_") ~=nil then
|
2012-08-17 16:28:59 +02:00
|
|
|
minetest.env:dig_node(pos)
|
|
|
|
minetest.env:place_node(pos, {name = "mesecons:wire_00000000_off"})
|
|
|
|
mesecon:update_autoconnect(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_placenode(function (pos, node)
|
|
|
|
if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then
|
|
|
|
mesecon:receiver_place(pos)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_dignode(function(pos, node)
|
|
|
|
if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then
|
2012-08-17 23:48:09 +02:00
|
|
|
mesecon:receiver_remove(pos, node)
|
2012-08-17 16:28:59 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_placenode(function (pos, node)
|
|
|
|
if string.find(node.name, "mesecons:wire_") ~=nil then
|
|
|
|
rules = mesecon:get_rules("receiver_pos_all")
|
|
|
|
local i = 1
|
|
|
|
while rules[i] ~= nil do
|
|
|
|
np = {
|
|
|
|
x = pos.x + rules[i].x,
|
|
|
|
y = pos.y + rules[i].y,
|
|
|
|
z = pos.z + rules[i].z}
|
|
|
|
if minetest.get_item_group(minetest.env:get_node(np).name, "mesecon_needs_receiver") == 1 then
|
|
|
|
mesecon:receiver_place(np)
|
|
|
|
end
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|