2020-05-31 23:31:18 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Hyperloop Mod
|
|
|
|
=============
|
|
|
|
|
|
|
|
Copyright (C) 2017-2019 Joachim Stolberg
|
|
|
|
|
|
|
|
LGPLv2.1+
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
2024-08-25 20:49:57 +03:00
|
|
|
--local P = minetest.string_to_pos
|
|
|
|
--local M = minetest.get_meta
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
-- Load support for intllib.
|
|
|
|
local S = hyperloop.S
|
|
|
|
|
|
|
|
local Shaft = hyperloop.Shaft
|
|
|
|
local Tube = hyperloop.Tube
|
|
|
|
|
|
|
|
|
|
|
|
local function chat_message(dir, cnt, peer_pos, peer_dir)
|
|
|
|
local sdir = tubelib2.dir_to_string(dir)
|
|
|
|
if Shaft:is_secondary_node(peer_pos, peer_dir) then
|
|
|
|
local npos, node = Shaft:get_node(peer_pos, peer_dir)
|
|
|
|
return "[Hyperloop] To the "..sdir..": "..cnt.." tube nodes to "..node.name.." at "..SP(npos)
|
|
|
|
else
|
|
|
|
return "[Hyperloop] To the "..sdir..": "..cnt.." tube nodes to "..SP(peer_pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function repair_tubes(itemstack, placer, pointed_thing)
|
|
|
|
if pointed_thing.type == "node" then
|
|
|
|
local pos = pointed_thing.under
|
2024-08-25 20:49:57 +03:00
|
|
|
local dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1, cnt2 =
|
2020-05-31 23:31:18 +03:00
|
|
|
Shaft:tool_repair_tube(pos, placer, pointed_thing)
|
|
|
|
if fpos1 and fpos2 then
|
2021-02-07 16:37:07 +03:00
|
|
|
if cnt1 + cnt2 >= Shaft.max_tube_length then
|
2024-08-25 20:49:57 +03:00
|
|
|
minetest.chat_send_player(placer:get_player_name(), string.char(0x1b) ..
|
2021-02-07 16:37:07 +03:00
|
|
|
"(c@#ff0000)" .. S("[Hyperloop] Error: Tube is too long!"))
|
|
|
|
end
|
2020-05-31 23:31:18 +03:00
|
|
|
minetest.chat_send_player(placer:get_player_name(), chat_message(dir1, cnt1, fpos1, fdir1))
|
|
|
|
minetest.chat_send_player(placer:get_player_name(), chat_message(dir2, cnt2, fpos2, fdir2))
|
|
|
|
minetest.sound_play({
|
|
|
|
name="hyperloop_crowbar"},{
|
|
|
|
pos = pos,
|
|
|
|
gain=2,
|
|
|
|
max_hear_distance=5,
|
|
|
|
loop=false})
|
|
|
|
else
|
2024-08-25 20:49:57 +03:00
|
|
|
dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1, cnt2 =
|
2020-05-31 23:31:18 +03:00
|
|
|
Tube:tool_repair_tube(pos, placer, pointed_thing)
|
|
|
|
if fpos1 and fpos2 then
|
2021-02-07 16:37:07 +03:00
|
|
|
if cnt1 + cnt2 >= Shaft.max_tube_length then
|
2024-08-25 20:49:57 +03:00
|
|
|
minetest.chat_send_player(placer:get_player_name(), string.char(0x1b) ..
|
2021-02-07 16:37:07 +03:00
|
|
|
"(c@#ff0000)" .. S("[Hyperloop] Error: Tube is too long!"))
|
|
|
|
end
|
2020-05-31 23:31:18 +03:00
|
|
|
minetest.chat_send_player(placer:get_player_name(), chat_message(dir1, cnt1, fpos1, fdir1))
|
|
|
|
minetest.chat_send_player(placer:get_player_name(), chat_message(dir2, cnt2, fpos2, fdir2))
|
|
|
|
minetest.sound_play({
|
|
|
|
name="hyperloop_crowbar"},{
|
|
|
|
pos = pos,
|
|
|
|
gain=2,
|
|
|
|
max_hear_distance=5,
|
|
|
|
loop=false})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2024-08-25 20:49:57 +03:00
|
|
|
minetest.chat_send_player(placer:get_player_name(),
|
2020-05-31 23:31:18 +03:00
|
|
|
S("[Crowbar Help]\n")..
|
|
|
|
S(" left: remove node\n")..
|
|
|
|
S(" right: repair tube/shaft line\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function add_to_inventory(placer, item_name)
|
|
|
|
local inv = placer:get_inventory()
|
|
|
|
local item = ItemStack(item_name)
|
|
|
|
if inv and item and inv:room_for_item("main", item) then
|
|
|
|
inv:add_item("main", item)
|
|
|
|
end
|
2024-08-25 20:49:57 +03:00
|
|
|
end
|
2020-05-31 23:31:18 +03:00
|
|
|
|
|
|
|
local function remove_tube(itemstack, placer, pointed_thing)
|
|
|
|
if minetest.check_player_privs(placer:get_player_name(), "hyperloop") then
|
|
|
|
if pointed_thing.type == "node" then
|
|
|
|
local pos = pointed_thing.under
|
|
|
|
if Shaft:tool_remove_tube(pos, "default_break_glass") then
|
|
|
|
add_to_inventory(placer, "hyperloop:shaft")
|
|
|
|
elseif Tube:tool_remove_tube(pos, "default_break_glass") then
|
|
|
|
add_to_inventory(placer, "hyperloop:tubeS")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(placer:get_player_name(), S("You don't have the necessary privs!"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Tool for tube workers to crack a protected tube line
|
|
|
|
minetest.register_node("hyperloop:tube_crowbar", {
|
|
|
|
description = S("Hyperloop Tube Crowbar"),
|
|
|
|
inventory_image = "hyperloop_tubecrowbar.png",
|
|
|
|
wield_image = "hyperloop_tubecrowbar.png",
|
2022-07-11 21:24:44 +03:00
|
|
|
use_texture_alpha = hyperloop.CLIP,
|
2020-05-31 23:31:18 +03:00
|
|
|
groups = {cracky=1, book=1},
|
|
|
|
on_use = remove_tube,
|
|
|
|
on_place = repair_tubes,
|
|
|
|
on_secondary_use = repair_tubes,
|
|
|
|
node_placement_prediction = "",
|
|
|
|
stack_max = 1,
|
|
|
|
})
|
|
|
|
|
2024-08-25 20:49:57 +03:00
|
|
|
minetest.register_privilege("hyperloop",
|
|
|
|
{description = S("Rights to remove tube nodes by means of the crowbar"),
|
2020-05-31 23:31:18 +03:00
|
|
|
give_to_singleplayer = false})
|
|
|
|
|
|
|
|
|
|
|
|
if(minetest.get_modpath("worldedit")) ~= nil then
|
|
|
|
minetest.register_chatcommand("hyperloop_repair_tubes", {
|
|
|
|
description = S("Repair via WorldEdit placed Hyperloop tubes by reusing WorldEdit pos1/pos2"),
|
|
|
|
privs = {worldedit=true},
|
|
|
|
func = function(name, param)
|
|
|
|
local pos1 = worldedit.pos1[name]
|
|
|
|
local pos2 = worldedit.pos2[name]
|
|
|
|
Tube:replace_tube_line(pos1, pos2)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|