2020-05-31 23:31:18 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Signs Bot
|
|
|
|
=========
|
|
|
|
|
2021-05-14 19:50:16 +03:00
|
|
|
Copyright (C) 2019-2021 Joachim Stolberg
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
GPL v3
|
|
|
|
See LICENSE.txt for more information
|
2022-09-24 12:01:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
Sensor/Actuator Connection Tool
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2021-05-14 19:50:16 +03:00
|
|
|
-- Load support for I18n.
|
|
|
|
local S = signs_bot.S
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
local lib = signs_bot.lib
|
|
|
|
|
|
|
|
local function get_current_data(pointed_thing)
|
|
|
|
local pos = pointed_thing.under
|
|
|
|
local ntype = signs_bot.get_node_type(pos)
|
|
|
|
return pos, ntype
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_stored_data(placer)
|
2021-05-14 19:50:16 +03:00
|
|
|
local meta = placer:get_meta()
|
|
|
|
local spos = meta:get_string("signs_bot_spos")
|
|
|
|
local name = meta:get_string("signs_bot_name")
|
2020-05-31 23:31:18 +03:00
|
|
|
if spos ~= "" then
|
|
|
|
return minetest.string_to_pos(spos), name
|
|
|
|
end
|
|
|
|
end
|
2022-09-24 12:01:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
local function store_data(placer, pos, name)
|
2021-05-14 19:50:16 +03:00
|
|
|
local meta = placer:get_meta()
|
2020-05-31 23:31:18 +03:00
|
|
|
if pos then
|
|
|
|
local spos = minetest.pos_to_string(pos)
|
2021-05-14 19:50:16 +03:00
|
|
|
meta:set_string("signs_bot_spos", spos)
|
|
|
|
meta:set_string("signs_bot_name", name)
|
2020-05-31 23:31:18 +03:00
|
|
|
else
|
2021-05-14 19:50:16 +03:00
|
|
|
meta:set_string("signs_bot_spos", nil)
|
|
|
|
meta:set_string("signs_bot_name", nil)
|
2020-05-31 23:31:18 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Write actuator_pos data to sensor_pos
|
|
|
|
local function pairing(actuator_pos, sensor_pos)
|
|
|
|
local signal = signs_bot.get_signal(actuator_pos)
|
|
|
|
if signal then
|
|
|
|
signs_bot.store_signal(sensor_pos, actuator_pos, signal)
|
2021-02-07 16:37:07 +03:00
|
|
|
local node = tubelib2.get_node_lvm(sensor_pos)
|
2020-05-31 23:31:18 +03:00
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
|
|
|
if ndef and ndef.update_infotext then
|
|
|
|
ndef.update_infotext(sensor_pos, actuator_pos, signal)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function use_tool(itemstack, placer, pointed_thing)
|
|
|
|
if pointed_thing.type == "node" then
|
|
|
|
local pos1,ntype1 = get_stored_data(placer)
|
|
|
|
local pos2,ntype2 = get_current_data(pointed_thing)
|
2022-09-24 12:01:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
if ntype1 == "actuator" and (ntype2 == "sensor" or ntype2 == "repeater") then
|
|
|
|
pairing(pos1, pos2)
|
|
|
|
store_data(placer, nil, nil)
|
|
|
|
minetest.sound_play('signs_bot_pong', {to_player = placer:get_player_name()})
|
|
|
|
elseif (ntype1 == "actuator" or ntype1 == "repeater") and ntype2 == "sensor" then
|
|
|
|
pairing(pos1, pos2)
|
|
|
|
store_data(placer, nil, nil)
|
|
|
|
minetest.sound_play('signs_bot_pong', {to_player = placer:get_player_name()})
|
|
|
|
elseif ntype2 == "actuator" and (ntype1 == "sensor" or ntype1 == "repeater") then
|
|
|
|
pairing(pos2, pos1)
|
|
|
|
store_data(placer, nil, nil)
|
|
|
|
minetest.sound_play('signs_bot_pong', {to_player = placer:get_player_name()})
|
|
|
|
elseif (ntype2 == "actuator" or ntype2 == "repeater") and ntype1 == "sensor" then
|
|
|
|
pairing(pos2, pos1)
|
|
|
|
store_data(placer, nil, nil)
|
|
|
|
minetest.sound_play('signs_bot_pong', {to_player = placer:get_player_name()})
|
|
|
|
elseif ntype2 == "actuator" or ntype2 == "sensor" or ntype2 == "repeater" then
|
|
|
|
store_data(placer, pos2, ntype2)
|
|
|
|
minetest.sound_play('signs_bot_ping', {to_player = placer:get_player_name()})
|
|
|
|
else
|
|
|
|
store_data(placer, nil, nil)
|
|
|
|
minetest.sound_play('signs_bot_error', {to_player = placer:get_player_name()})
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2022-09-24 12:01:30 +03:00
|
|
|
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
minetest.register_node("signs_bot:connector", {
|
2021-05-14 19:50:16 +03:00
|
|
|
description = S("Sensor Connection Tool"),
|
2020-05-31 23:31:18 +03:00
|
|
|
inventory_image = "signs_bot_tool.png",
|
|
|
|
wield_image = "signs_bot_tool.png",
|
|
|
|
groups = {cracky=1, book=1},
|
|
|
|
on_use = use_tool,
|
|
|
|
on_place = use_tool,
|
|
|
|
node_placement_prediction = "",
|
|
|
|
stack_max = 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "signs_bot:connector",
|
|
|
|
recipe = {
|
|
|
|
{"dye:yellow", "default:mese_crystal", "dye:yellow"},
|
|
|
|
{"", "default:stick", ""},
|
|
|
|
{"", "default:stick", ""}
|
|
|
|
}
|
|
|
|
})
|