2019-01-28 21:52:08 +01:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Tubelib Addons 2
|
|
|
|
================
|
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2019-01-28 21:52:08 +01:00
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
AGPL v3
|
2019-01-28 21:52:08 +01:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
logic_not.lua:
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2020-11-03 20:19:38 +01:00
|
|
|
-- Load support for I18n
|
|
|
|
local S = tubelib_addons2.S
|
|
|
|
|
2019-01-28 21:52:08 +01:00
|
|
|
local function formspec(meta)
|
|
|
|
local numbers = meta:get_string("numbers")
|
|
|
|
return "size[7,5]"..
|
2020-11-03 20:19:38 +01:00
|
|
|
"field[0.5,2;6,1;number;"..S("Destination node numbers")..";"..numbers.."]" ..
|
|
|
|
"button_exit[1,3;2,1;exit;"..S("Save").."]"
|
2019-01-28 21:52:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("tubelib_addons2:logic_not", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("Tubelib Logic Not"),
|
2019-01-28 21:52:08 +01:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
'tubelib_front.png',
|
|
|
|
'tubelib_front.png',
|
|
|
|
'tubelib_front.png^tubelib_addon2_logic_not.png',
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local own_number = tubelib.add_node(pos, "tubelib_addons2:logic_not")
|
|
|
|
meta:set_string("own_number", own_number)
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("Tubelib Logic Not").." "..own_number..S(": not connected"))
|
2019-01-28 21:52:08 +01:00
|
|
|
meta:set_string("owner", placer:get_player_name())
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_receive_fields = function(pos, formname, fields, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
if owner ~= player:get_player_name() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if tubelib.check_numbers(fields.number) then
|
|
|
|
meta:set_string("numbers", fields.number)
|
|
|
|
local own_number = meta:get_string("own_number")
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("Tubelib Logic Not").." "..own_number..S(": connected with").." "..fields.number)
|
2019-01-28 21:52:08 +01:00
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos)
|
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "tubelib_addons2:logic_not",
|
|
|
|
recipe = {
|
|
|
|
{"", "tubelib:wlanchip", ""},
|
|
|
|
{"group:wood", "", "group:wood"},
|
|
|
|
{"", "tubelib:wlanchip", ""},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
tubelib.register_node("tubelib_addons2:logic_not", {}, {
|
|
|
|
on_recv_message = function(pos, topic, payload)
|
2019-04-23 21:46:08 +02:00
|
|
|
if tubelib.data_not_corrupted(pos) then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
local numbers = meta:get_string("numbers")
|
|
|
|
local own_number = meta:get_string("own_number")
|
|
|
|
if topic == "set_numbers" then
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("Tubelib Logic Not").." "..own_number..S(": connected with").." "..payload)
|
2019-04-23 21:46:08 +02:00
|
|
|
meta:set_string("numbers", payload)
|
|
|
|
meta:set_string("formspec", formspec(meta))
|
|
|
|
return true
|
|
|
|
elseif topic == "on" then
|
|
|
|
return tubelib.send_message(numbers, owner, nil, "off", payload)
|
|
|
|
elseif topic == "off" then
|
|
|
|
return tubelib.send_message(numbers, owner, nil, "on", payload)
|
|
|
|
end
|
2019-01-28 21:52:08 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|