2013-11-20 20:27:10 +01:00
|
|
|
-- This version of the travelnet box allows to move up or down only.
|
|
|
|
-- The network name is determined automaticly from the position (x/z coordinates).
|
2022-01-07 16:37:46 +01:00
|
|
|
-- Author: Sokomine
|
2020-11-19 19:57:19 +01:00
|
|
|
local S = minetest.get_translator("travelnet")
|
2013-06-13 05:49:41 +02:00
|
|
|
|
2021-07-03 18:41:00 +01:00
|
|
|
function travelnet.show_nearest_elevator(pos, owner_name, param2)
|
2021-07-02 05:58:54 +01:00
|
|
|
if not pos or not pos.x or not pos.z or not owner_name then
|
|
|
|
return
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
|
|
|
|
2021-07-02 05:58:54 +01:00
|
|
|
if not travelnet.targets[owner_name] then
|
|
|
|
minetest.chat_send_player(owner_name,
|
|
|
|
S("Congratulations! This is your first elevator. " ..
|
|
|
|
"You can build an elevator network by placing further elevators somewhere above " ..
|
|
|
|
"or below this one. Just make sure that the x and z coordinate are the same."))
|
|
|
|
return
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
|
|
|
|
2021-07-03 18:41:00 +01:00
|
|
|
local network_name = travelnet.elevator_network(pos)
|
2017-12-17 17:56:36 +01:00
|
|
|
-- will this be an elevator that will be added to an existing network?
|
2021-07-02 05:58:54 +01:00
|
|
|
if travelnet.targets[owner_name][network_name]
|
|
|
|
-- does the network have any members at all?
|
|
|
|
and next(travelnet.targets[owner_name][network_name], nil)
|
|
|
|
then
|
|
|
|
minetest.chat_send_player(owner_name,
|
2022-08-26 02:17:34 +02:00
|
|
|
S("This elevator will automatically connect to the " ..
|
2021-07-02 05:58:54 +01:00
|
|
|
"other elevators you have placed at different heights. Just enter a station name " ..
|
|
|
|
"and click on \"store\" to set it up. Or just punch it to set the height as station " ..
|
|
|
|
"name."))
|
|
|
|
return
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
|
|
|
|
2021-07-03 18:41:00 +01:00
|
|
|
local nearest_name, nearest_dist = travelnet.find_nearest_elevator_network(pos, owner_name)
|
2017-12-17 17:56:36 +01:00
|
|
|
|
2021-07-03 18:41:00 +01:00
|
|
|
if not nearest_name then
|
2021-07-02 05:58:54 +01:00
|
|
|
minetest.chat_send_player(owner_name,
|
|
|
|
S("This is your first elevator. It differs from " ..
|
|
|
|
"travelnet networks by only allowing movement in vertical direction (up or down). " ..
|
2022-08-26 02:17:34 +02:00
|
|
|
"All further elevators which you will place at the same x,z coordinates at different " ..
|
2021-07-02 05:58:54 +01:00
|
|
|
"heights will be able to connect to this elevator."))
|
2021-07-03 18:41:00 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local direction_strings = {
|
|
|
|
S("m to the right"),
|
|
|
|
S("m behind this elevator and"),
|
|
|
|
S("m to the left"),
|
|
|
|
S("m in front of this elevator and")
|
|
|
|
}
|
|
|
|
local direction_indexes = { x=param2+1, z=((param2+1) % 4)+1 }
|
|
|
|
|
|
|
|
-- Should X or Z be displayed first?
|
|
|
|
local direction_order = ({ [0]={"z","x"}, [1]={"x","z"} })[param2 % 2]
|
|
|
|
|
|
|
|
local text = S("Your nearest elevator network is located") .. " "
|
|
|
|
|
|
|
|
for index, direction in ipairs(direction_order) do
|
|
|
|
local nearest_dist_direction = nearest_dist[direction]
|
|
|
|
local direction_index = direction_indexes[direction]
|
|
|
|
if nearest_dist_direction < 0 then
|
|
|
|
direction_index = ((direction_indexes[direction]+1) % 4)+1
|
|
|
|
end
|
|
|
|
text = text .. tostring(math.abs(nearest_dist_direction)) .. " " .. direction_strings[direction_index]
|
|
|
|
if index == 1 then text = text .. " " end
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
2021-07-03 18:41:00 +01:00
|
|
|
|
|
|
|
minetest.chat_send_player(owner_name, text .. S(", located at x") ..
|
|
|
|
("=%f, z=%f. "):format(pos.x + nearest_dist.x, pos.z + nearest_dist.z) ..
|
|
|
|
S("This elevator here will start a new shaft/network."))
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2022-02-10 16:38:07 +00:00
|
|
|
local function on_interact(pos, _, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local legacy_formspec = meta:get_string("formspec")
|
|
|
|
if not travelnet.is_falsey_string(legacy_formspec) then
|
|
|
|
meta:set_string("formspec", "")
|
|
|
|
end
|
|
|
|
|
2022-02-12 19:56:37 +00:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
travelnet.show_current_formspec(pos, meta, player_name)
|
2022-02-10 16:38:07 +00:00
|
|
|
end
|
|
|
|
|
2013-06-13 05:49:41 +02:00
|
|
|
minetest.register_node("travelnet:elevator", {
|
2017-12-25 02:08:06 +01:00
|
|
|
description = S("Elevator"),
|
2015-07-30 18:44:46 -04:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "travelnet_elevator.obj",
|
|
|
|
sunlight_propagates = true,
|
2021-07-02 05:58:54 +01:00
|
|
|
paramtype = "light",
|
2015-07-30 18:44:46 -04:00
|
|
|
paramtype2 = "facedir",
|
2021-07-02 05:58:54 +01:00
|
|
|
wield_scale = { x=0.6, y=0.6, z=0.6 },
|
2015-07-30 18:44:46 -04:00
|
|
|
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 }
|
|
|
|
},
|
|
|
|
|
|
|
|
collision_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
|
|
|
|
{ 0.48, -0.5,-0.5, 0.5, 0.5, 0.5},
|
2019-06-30 22:26:20 +01:00
|
|
|
{-0.5 , -0.5, 0.48, 0.48, 0.5, 0.5},
|
2015-07-30 18:44:46 -04:00
|
|
|
{-0.5, -0.5,-0.5 ,-0.48, 0.5, 0.5},
|
|
|
|
|
|
|
|
--groundplate to stand on
|
2019-06-30 22:26:20 +01:00
|
|
|
{ -0.5,-0.5,-0.5,0.5,-0.48, 0.5},
|
2015-07-30 18:44:46 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-02-26 20:36:14 +01:00
|
|
|
tiles = travelnet.tiles_elevator,
|
|
|
|
|
|
|
|
inventory_image = travelnet.elevator_inventory_image,
|
2021-01-08 15:11:19 +01:00
|
|
|
groups = {
|
|
|
|
elevator = 1
|
|
|
|
},
|
2013-06-13 05:49:41 +02:00
|
|
|
|
2021-01-15 08:26:42 +01:00
|
|
|
light_source = 10,
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
2021-07-02 05:58:54 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("infotext", S("Elevator (unconfigured)"))
|
|
|
|
meta:set_string("station_name", "")
|
|
|
|
meta:set_string("station_network","")
|
|
|
|
meta:set_string("owner", placer:get_player_name())
|
2021-07-03 18:41:00 +01:00
|
|
|
|
|
|
|
minetest.set_node(vector.add(pos, { x=0, y=1, z=0 }), { name="travelnet:hidden_top" })
|
2021-07-02 05:58:54 +01:00
|
|
|
travelnet.show_nearest_elevator(pos, placer:get_player_name(), minetest.dir_to_facedir(placer:get_look_dir()))
|
2021-01-15 08:26:42 +01:00
|
|
|
end,
|
|
|
|
|
2022-02-10 16:38:07 +00:00
|
|
|
on_rightclick = on_interact,
|
|
|
|
on_punch = on_interact,
|
2021-01-15 08:26:42 +01:00
|
|
|
|
2021-07-02 05:58:54 +01:00
|
|
|
can_dig = function(pos, player)
|
|
|
|
return travelnet.can_dig(pos, player, "elevator")
|
2021-01-15 08:26:42 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2021-07-02 05:58:54 +01:00
|
|
|
travelnet.remove_box(pos, oldnode, oldmetadata, digger)
|
2021-01-15 08:26:42 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
-- TNT and overenthusiastic DMs do not destroy elevators either
|
|
|
|
on_blast = function()
|
|
|
|
end,
|
|
|
|
|
|
|
|
-- taken from VanessaEs homedecor fridge
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
2021-07-03 18:41:00 +01:00
|
|
|
local node = minetest.get_node(vector.add(pointed_thing.above, { x=0, y=1, z=0 }))
|
2021-01-15 08:26:42 +01:00
|
|
|
local def = minetest.registered_nodes[node.name]
|
|
|
|
-- leftover top nodes can be removed by placing a new elevator underneath
|
|
|
|
if (not def or not def.buildable_to) and node.name ~= "travelnet:hidden_top" then
|
|
|
|
minetest.chat_send_player(
|
|
|
|
placer:get_player_name(),
|
2021-07-02 05:58:54 +01:00
|
|
|
S("Not enough vertical space to place the travelnet box!")
|
2021-01-15 08:26:42 +01:00
|
|
|
)
|
2021-07-02 05:58:54 +01:00
|
|
|
return
|
2021-01-15 08:26:42 +01:00
|
|
|
end
|
2021-07-02 05:58:54 +01:00
|
|
|
return minetest.item_place(itemstack, placer, pointed_thing)
|
2021-01-15 08:26:42 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_destruct = function(pos)
|
2021-07-03 18:41:00 +01:00
|
|
|
minetest.remove_node(vector.add(pos, { x=0, y=1, z=0 }))
|
2021-01-15 08:26:42 +01:00
|
|
|
end
|
2013-06-13 05:49:41 +02:00
|
|
|
})
|
|
|
|
|
2021-01-15 08:26:42 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "travelnet:elevator",
|
|
|
|
recipe = travelnet.elevator_recipe,
|
|
|
|
})
|