2018-08-13 23:21:22 +02:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Tubelib Addons 1
|
|
|
|
================
|
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2018-08-13 23:21:22 +02:00
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
AGPL v3
|
2018-08-13 23:21:22 +02:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
detector.lua:
|
2019-09-13 00:53:29 +02:00
|
|
|
|
2018-08-13 23:21:22 +02:00
|
|
|
]]--
|
|
|
|
|
2020-11-03 20:19:38 +01:00
|
|
|
-- Load support for I18n
|
|
|
|
local S = tubelib_addons1.S
|
2018-08-13 23:21:22 +02:00
|
|
|
|
|
|
|
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", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("Tubelib Detector"),
|
2018-08-13 23:21:22 +02:00
|
|
|
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]"..
|
2020-11-03 20:19:38 +01:00
|
|
|
"field[0.5,1;7,1;numbers;"..S("Insert destination node number(s)")..";]" ..
|
|
|
|
"button_exit[2,2;3,1;exit;"..S("Save").."]")
|
2018-08-13 23:21:22 +02:00
|
|
|
meta:set_string("placer_name", placer:get_player_name())
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("Tubelib Detector, unconfigured"))
|
2018-08-13 23:21:22 +02:00
|
|
|
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")
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("Tubelib Detector, connected"))
|
2018-08-13 23:21:22 +02:00
|
|
|
meta:set_string("formspec", "size[7.5,3]"..
|
2020-11-03 20:19:38 +01:00
|
|
|
"field[0.5,1;7,1;numbers;"..S("Insert destination node number(s)")..";"..fields.numbers.."]" ..
|
|
|
|
"button_exit[2,2;3,1;exit;"..S("Save").."]")
|
2018-08-13 23:21:22 +02:00
|
|
|
end
|
|
|
|
end,
|
2019-09-13 00:53:29 +02:00
|
|
|
|
2019-01-06 15:03:22 +01:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
2019-09-13 00:53:29 +02:00
|
|
|
|
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", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("Tubelib Detector"),
|
2018-08-13 23:21:22 +02:00
|
|
|
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,
|
2019-09-13 00:53:29 +02:00
|
|
|
|
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"}, {
|
2021-01-23 18:41:09 +01:00
|
|
|
valid_sides = {"R","L"},
|
2018-08-13 23:21:22 +02:00
|
|
|
on_push_item = function(pos, side, item)
|
2019-09-13 00:53:29 +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
|
2019-09-13 00:53:29 +02:00
|
|
|
})
|
2018-08-13 23:21:22 +02:00
|
|
|
|