2018-08-13 23:21:22 +02:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Tubelib Addons 1
|
|
|
|
================
|
|
|
|
|
|
|
|
Copyright (C) 2017-2018 Joachim Stolberg
|
|
|
|
|
|
|
|
LGPLv2.1+
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
detector.lua:
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
|
|
|
|
local function switch_on(pos)
|
2019-04-23 21:46:08 +02:00
|
|
|
if tubelib.data_not_corrupted(pos) then
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
node.name = "tubelib_addons1:detector_active"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
minetest.get_node_timer(pos):start(1)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local own_num = meta:get_string("own_num")
|
|
|
|
local numbers = meta:get_string("numbers")
|
|
|
|
local placer_name = meta:get_string("placer_name")
|
|
|
|
tubelib.send_message(numbers, placer_name, nil, "on", own_num)
|
|
|
|
end
|
2018-08-13 23:21:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function switch_off(pos)
|
2019-04-23 21:46:08 +02:00
|
|
|
if tubelib.data_not_corrupted(pos) then
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
node.name = "tubelib_addons1:detector"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local own_num = meta:get_string("own_num")
|
|
|
|
local numbers = meta:get_string("numbers")
|
|
|
|
local placer_name = meta:get_string("placer_name")
|
|
|
|
tubelib.send_message(numbers, placer_name, nil, "off", own_num)
|
|
|
|
end
|
2018-08-13 23:21:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("tubelib_addons1:detector", {
|
|
|
|
description = "Tubelib Detector",
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
'tubelib_front.png',
|
|
|
|
'tubelib_front.png',
|
|
|
|
'tubelib_outp.png',
|
|
|
|
'tubelib_inp.png',
|
|
|
|
'tubelib_addons1_detector.png^[transformFX',
|
|
|
|
"tubelib_addons1_detector.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local own_num = tubelib.add_node(pos, "tubelib_addons1:detector")
|
|
|
|
meta:set_string("own_num", own_num)
|
|
|
|
meta:set_string("formspec", "size[7.5,3]"..
|
|
|
|
"field[0.5,1;7,1;numbers;Insert destination node number(s);]" ..
|
|
|
|
"button_exit[2,2;3,1;exit;Save]")
|
|
|
|
meta:set_string("placer_name", placer:get_player_name())
|
|
|
|
meta:set_string("infotext", "Tubelib Detector, unconfigured")
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_receive_fields = function(pos, formname, fields, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if tubelib.check_numbers(fields.numbers) then
|
|
|
|
meta:set_string("numbers", fields.numbers)
|
|
|
|
local own_num = meta:get_string("own_num")
|
|
|
|
meta:set_string("infotext", "Tubelib Detector, connected")
|
|
|
|
meta:set_string("formspec", "size[7.5,3]"..
|
|
|
|
"field[0.5,1;7,1;numbers;Insert destination node number(s);"..fields.numbers.."]" ..
|
|
|
|
"button_exit[2,2;3,1;exit;Save]")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2019-01-06 15:03:22 +01:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
|
|
|
|
2018-08-13 23:21:22 +02:00
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("tubelib_addons1:detector_active", {
|
|
|
|
description = "Tubelib Detector",
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
'tubelib_front.png',
|
|
|
|
'tubelib_front.png',
|
|
|
|
'tubelib_outp.png',
|
|
|
|
'tubelib_inp.png',
|
|
|
|
'tubelib_addons1_detector_active.png^[transformFX',
|
|
|
|
"tubelib_addons1_detector_active.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
on_timer = switch_off,
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
|
2019-01-06 15:03:22 +01:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
|
|
|
|
2018-08-13 23:21:22 +02:00
|
|
|
paramtype = "light",
|
|
|
|
light_source = 2,
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
drop = "tubelib_addons1:detector",
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "tubelib_addons1:detector",
|
|
|
|
recipe = {
|
|
|
|
{"", "group:wood", ""},
|
2018-12-31 14:59:02 +01:00
|
|
|
{"tubelib:tubeS", "tubelib:wlanchip", "tubelib:tubeS"},
|
2018-08-13 23:21:22 +02:00
|
|
|
{"", "group:wood", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
tubelib.register_node("tubelib_addons1:detector", {"tubelib_addons1:detector_active"}, {
|
|
|
|
on_push_item = function(pos, side, item)
|
2019-09-14 20:39:12 +02:00
|
|
|
if side ~= "L" then return false end
|
2018-08-13 23:21:22 +02:00
|
|
|
local player_name = minetest.get_meta(pos):get_string("player_name")
|
|
|
|
if tubelib.push_items(pos, "R", item, player_name) then
|
|
|
|
switch_on(pos)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end,
|
|
|
|
is_pusher = true, -- is a pulling/pushing node
|
|
|
|
})
|
|
|
|
|