techage/tools/end_wrench.lua

245 lines
8.6 KiB
Lua
Raw Normal View History

2019-04-28 22:34:21 +03:00
--[[
2019-08-24 00:35:37 +03:00
TechAge
=======
2019-04-28 22:34:21 +03:00
2023-09-16 22:03:46 +03:00
Copyright (C) 2017-2023 Joachim Stolberg
2019-04-28 22:34:21 +03:00
2020-10-19 20:09:17 +03:00
AGPL v3
2019-04-28 22:34:21 +03:00
See LICENSE.txt for more information
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
2019-04-28 22:34:21 +03:00
2020-02-18 00:46:29 +03:00
local Cable1 = techage.ElectricCable
local Cable2 = techage.TA4_Cable
local Pipe2 = techage.LiquidPipe
2021-12-30 17:05:20 +03:00
local menu = techage.menu
2019-08-24 11:54:20 +03:00
2022-01-10 23:39:36 +03:00
local N = techage.get_node_lvm
local CTL = function(pos) return (minetest.registered_nodes[N(pos).name] or {}).control end
2020-02-18 00:46:29 +03:00
local function network_check(start_pos, Cable, player_name)
2021-06-09 23:09:59 +03:00
-- local ndef = techage.networks.net_def(start_pos, Cable.tube_type)
-- local outdir = nil
-- local num = 0
-- if ndef and ndef.ntype ~= "junc" then
-- outdir = M(start_pos):get_int("outdir")
-- end
-- networks.connection_walk(start_pos, outdir, Cable, function(pos, indir, node)
-- local distance = vector.distance(start_pos, pos)
-- num = num + 1
-- if distance < 50 and num < 100 then
-- local state = techage.power.power_available(pos, Cable) and "power" or "no power"
-- techage.mark_position(player_name, pos, state, "#ff0000", 6)
-- end
-- end)
2022-01-03 23:40:31 +03:00
end
2019-04-28 22:34:21 +03:00
local function read_state(itemstack, user, pointed_thing)
local pos = pointed_thing.under
if pos and user then
local time = math.floor(minetest.get_timeofday() * 24 * 6)
local hours = math.floor(time / 6)
local mins = (time % 6) * 10
if mins < 10 then mins = "00" end
2022-01-03 23:40:31 +03:00
2020-10-11 18:57:15 +03:00
local number = techage.get_node_number(pos)
local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
2022-01-03 23:40:31 +03:00
2020-10-11 18:57:15 +03:00
if node.name == "default:water_source" then
local player_name = user:get_player_name()
techage.valid_place_for_windturbine(pos, player_name, 0)
return itemstack
end
2022-01-03 23:40:31 +03:00
minetest.chat_send_player(user:get_player_name(), S("Time")..": "..hours..":"..mins.." ")
2019-08-21 22:52:11 +03:00
local data = minetest.get_biome_data(pos)
if data then
local name = minetest.get_biome_name(data.biome)
minetest.chat_send_player(user:get_player_name(), S("Biome")..": "..name..", "..S("Position temperature")..": "..math.floor(data.heat).." ")
2019-08-21 22:52:11 +03:00
end
2022-01-03 23:40:31 +03:00
2019-04-28 22:34:21 +03:00
if number then
if ndef and ndef.description then
local info = techage.send_single("0", number, "info", nil)
if info and info ~= "" and info ~= "unsupported" then
info = tostring(info)
2021-06-09 23:09:59 +03:00
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..":\n"..info.." ")
end
local state = techage.send_single("0", number, "state", nil)
if state and state ~= "" and state ~= "unsupported" then
2019-09-28 20:40:49 +03:00
state = dump(state)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": state = "..state.." ")
end
2022-06-07 20:14:43 +03:00
local state = techage.send_single("0", number, "count", nil)
if state and state ~= "" and state ~= "unsupported" then
state = dump(state)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": count = "..state.." ")
end
local fuel = techage.send_single("0", number, "fuel", nil)
if fuel and fuel ~= "" and fuel ~= "unsupported" then
2019-09-28 20:40:49 +03:00
fuel = dump(fuel)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": fuel = "..fuel.." ")
end
2020-11-27 15:46:48 +03:00
local output = techage.send_single("0", number, "output", nil)
if output and output ~= "" and output ~= "unsupported" then
output = dump(output)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": output = "..output.." ")
end
local load, abs = techage.send_single("0", number, "load", nil)
if load and load ~= "" and load ~= "unsupported" then
load, abs = dump(load), abs and dump(abs) or "--"
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % / "..abs.." units ")
end
local delivered = techage.send_single("0", number, "delivered", nil)
if delivered and delivered ~= "" and delivered ~= "unsupported" then
delivered = dump(delivered)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": delivered = "..delivered.." ku ")
end
local consumption = techage.send_single("0", number, "consumption", nil)
if consumption and consumption ~= "" and consumption ~= "unsupported" then
consumption = dump(consumption)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": consumption = "..consumption.." kud ")
end
local flowrate = techage.send_single("0", number, "flowrate", nil)
if flowrate and flowrate ~= "" and flowrate ~= "unsupported" then
flowrate = dump(flowrate)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": flowrate = "..flowrate.." ")
end
local owner = M(pos):get_string("owner") or ""
if owner ~= "" then
minetest.chat_send_player(user:get_player_name(), S("Node owner")..": "..owner.." ")
end
2022-09-10 21:42:31 +03:00
if ndef and ndef.networks and ndef.networks.pipe2 and ndef.networks.pipe2.ntype == "pump" then
local tbl = networks.liquid.get_liquids(pos, Pipe2)
if #tbl > 0 then
local names = table.concat(tbl, ", ")
minetest.chat_send_player(user:get_player_name(), S("Pump connected to tank(s) with: @1", names))
else
minetest.chat_send_player(user:get_player_name(), S("Pump connected to no/empty tank(s)."))
end
end
minetest.chat_send_player(user:get_player_name(), S("Position")..": "..minetest.pos_to_string(pos).." ")
itemstack:add_wear(65636/200)
return itemstack
2019-04-28 22:34:21 +03:00
end
elseif ndef and ndef.description then
2020-02-18 00:46:29 +03:00
if ndef.techage_info then
2019-10-08 22:13:28 +03:00
local info = ndef.techage_info(pos) or ""
minetest.chat_send_player(user:get_player_name(), ndef.description..":\n"..info)
end
local owner = M(pos):get_string("owner") or ""
if owner ~= "" then
minetest.chat_send_player(user:get_player_name(), S("Node owner")..": "..owner.." ")
end
minetest.chat_send_player(user:get_player_name(), S("Position")..": "..minetest.pos_to_string(pos).." ")
itemstack:add_wear(65636/200)
return itemstack
2019-04-28 22:34:21 +03:00
end
end
end
2021-06-09 23:09:59 +03:00
local context = {}
local function settings_menu(pos, playername)
2021-09-24 23:19:36 +03:00
if minetest.is_protected(pos, playername) then
return
end
-- Check node settings in addition
local access = M(pos):get_string("access")
local owner = M(pos):get_string("owner")
if access == "private" and playername ~= owner then
return
end
2022-01-03 23:40:31 +03:00
2021-06-09 23:09:59 +03:00
local number = techage.get_node_number(pos)
local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
local form_def
2022-01-03 23:40:31 +03:00
if ndef then
if ndef.ta3_formspec or ndef.ta4_formspec then
form_def = ndef.ta3_formspec or ndef.ta4_formspec
elseif ndef.ta5_formspec then
local player = minetest.get_player_by_name(playername)
if techage.get_expoints(player) >= ndef.ta5_formspec.ex_points then
form_def = ndef.ta5_formspec.menu
end
end
end
2022-01-03 23:40:31 +03:00
2021-06-09 23:09:59 +03:00
context[playername] = pos
if form_def then
2022-01-03 23:40:31 +03:00
minetest.show_formspec(playername, "techage:ta_formspec",
2021-09-19 21:02:24 +03:00
menu.generate_formspec(pos, ndef, form_def, playername))
2021-06-09 23:09:59 +03:00
end
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "techage:ta_formspec" then
return false
end
2022-01-03 23:40:31 +03:00
2021-06-09 23:09:59 +03:00
local playername = player:get_player_name()
local pos = context[playername]
if pos then
--context[playername] = nil
local number = techage.get_node_number(pos)
local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
2021-12-29 14:36:42 +03:00
local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec or ndef.ta5_formspec.menu)
2022-01-03 23:40:31 +03:00
2021-06-09 23:09:59 +03:00
if form_def then
2021-09-24 23:19:36 +03:00
if menu.eval_input(pos, form_def, fields, playername) then
2021-06-09 23:09:59 +03:00
--context[playername] = pos
minetest.after(0.2, function()
2022-01-03 23:40:31 +03:00
minetest.show_formspec(playername, "techage:ta_formspec",
2021-09-19 21:02:24 +03:00
menu.generate_formspec(pos, ndef, form_def, playername))
2021-06-09 23:09:59 +03:00
end)
2021-09-25 22:40:05 +03:00
if ndef.ta_after_formspec then
ndef.ta_after_formspec(pos, fields, playername)
end
2021-06-09 23:09:59 +03:00
end
end
end
return true
end)
local function on_place(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.under
local playername = placer:get_player_name()
if placer:get_player_control().sneak then
settings_menu(pos, playername)
end
end
end
minetest.register_tool("techage:end_wrench", {
description = S("TechAge Info Tool (use = read status info)"),
2019-05-11 02:21:03 +03:00
inventory_image = "techage_end_wrench.png",
wield_image = "techage_end_wrench.png",
2019-04-28 22:34:21 +03:00
groups = {cracky=1, book=1},
on_use = read_state,
2021-06-09 23:09:59 +03:00
on_place = on_place,
2019-04-28 22:34:21 +03:00
node_placement_prediction = "",
2020-10-11 18:57:15 +03:00
liquids_pointable = true,
stack_max = 1,
2019-04-28 22:34:21 +03:00
})
minetest.register_craft({
output = "techage:end_wrench",
2019-04-28 22:34:21 +03:00
recipe = {
{"", "", "default:steel_ingot"},
{"", "techage:iron_ingot", ""},
2019-04-28 22:34:21 +03:00
{"default:steel_ingot", "", ""},
},
})