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).
|
|
|
|
-- >utor: Sokomine
|
2017-12-25 02:08:06 +01:00
|
|
|
local S = travelnet.S;
|
2013-06-13 05:49:41 +02:00
|
|
|
|
2017-12-17 17:56:36 +01:00
|
|
|
travelnet.show_nearest_elevator = function( pos, owner_name, param2 )
|
|
|
|
if( not( pos ) or not(pos.x) or not(pos.z) or not( owner_name )) then
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
if( not( travelnet.targets[ owner_name ] )) then
|
2017-12-25 02:08:06 +01:00
|
|
|
minetest.chat_send_player( owner_name, S("Congratulations! This is your first elevator."..
|
2017-12-17 17:56:36 +01:00
|
|
|
"You can build an elevator network by placing further elevators somewhere above "..
|
2017-12-25 02:08:06 +01:00
|
|
|
"or below this one. Just make sure that the x and z coordinate are the same."));
|
2017-12-17 17:56:36 +01:00
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
local network_name = tostring( pos.x )..','..tostring( pos.z );
|
|
|
|
-- will this be an elevator that will be added to an existing network?
|
|
|
|
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
|
2017-12-25 02:08:06 +01:00
|
|
|
minetest.chat_send_player( owner_name, S("This elevator will automaticly connect to the "..
|
2017-12-17 17:56:36 +01:00
|
|
|
"other elevators you have placed at diffrent heights. Just enter a station name "..
|
|
|
|
"and click on \"store\" to set it up. Or just punch it to set the height as station "..
|
2017-12-25 02:08:06 +01:00
|
|
|
"name."));
|
2017-12-17 17:56:36 +01:00
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
local nearest_name = "";
|
|
|
|
local nearest_dist = 100000000;
|
|
|
|
local nearest_dist_x = 0;
|
|
|
|
local nearest_dist_z = 0;
|
|
|
|
for network_name, data in pairs( travelnet.targets[ owner_name ] ) do
|
|
|
|
local station_name = next( data, nil );
|
|
|
|
if( station_name and data[ station_name ][ "nr" ] and data[ station_name ].pos) then
|
|
|
|
local station_pos = data[ station_name ].pos;
|
|
|
|
local dist = math.ceil(math.sqrt(
|
|
|
|
( station_pos.x - pos.x ) * ( station_pos.x - pos.x )
|
|
|
|
+ ( station_pos.z - pos.z ) * ( station_pos.z - pos.z )));
|
|
|
|
-- find the nearest one; store network_name and (minimal) distance
|
|
|
|
if( dist < nearest_dist ) then
|
|
|
|
nearest_dist = dist;
|
|
|
|
nearest_dist_x = station_pos.x - pos.x;
|
|
|
|
nearest_dist_z = station_pos.z - pos.z;
|
|
|
|
nearest_name = network_name;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if( nearest_name ~= "" ) then
|
2017-12-25 02:08:06 +01:00
|
|
|
local text = S("Your nearest elevator network is located").." ";
|
2017-12-17 17:56:36 +01:00
|
|
|
-- in front of/behind
|
|
|
|
if( (param2==0 and nearest_dist_z>=0)or (param2==2 and nearest_dist_z<=0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_z )).." "..S("m behind this elevator and");
|
2017-12-17 17:56:36 +01:00
|
|
|
elseif((param2==1 and nearest_dist_x>=0)or (param2==3 and nearest_dist_x<=0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_x )).." "..S("m behind this elevator and");
|
2017-12-17 17:56:36 +01:00
|
|
|
elseif((param2==0 and nearest_dist_z< 0)or (param2==2 and nearest_dist_z> 0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_z )).." "..S("m in front of this elevator and");
|
2017-12-17 17:56:36 +01:00
|
|
|
elseif((param2==1 and nearest_dist_x< 0)or (param2==3 and nearest_dist_x> 0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_x )).." "..S("m in front of this elevator and");
|
|
|
|
else text = text..S(" ERROR");
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text.." ";
|
2017-12-17 17:56:36 +01:00
|
|
|
|
|
|
|
-- right/left
|
|
|
|
if( (param2==0 and nearest_dist_x< 0)or (param2==2 and nearest_dist_x> 0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_x )).." "..S("m to the left");
|
2017-12-17 17:56:36 +01:00
|
|
|
elseif((param2==1 and nearest_dist_z>=0)or (param2==3 and nearest_dist_z<=0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_z )).." "..S("m to the left");
|
2017-12-17 17:56:36 +01:00
|
|
|
elseif((param2==0 and nearest_dist_x>=0)or (param2==2 and nearest_dist_x<=0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_x )).." "..S("m to the right");
|
2017-12-17 17:56:36 +01:00
|
|
|
elseif((param2==1 and nearest_dist_z< 0)or (param2==3 and nearest_dist_z> 0)) then
|
2017-12-25 02:08:06 +01:00
|
|
|
text = text..tostring( math.abs(nearest_dist_z )).." "..S("m to the right");
|
|
|
|
else text = text..S(" ERROR");
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.chat_send_player( owner_name, text..
|
2017-12-25 02:08:06 +01:00
|
|
|
S(", located at x").."="..tostring( pos.x+nearest_dist_x)..
|
2017-12-17 17:56:36 +01:00
|
|
|
", z="..tostring( pos.z+nearest_dist_z)..
|
2017-12-25 02:08:06 +01:00
|
|
|
". "..S("This elevator here will start a new shaft/network."));
|
2017-12-17 17:56:36 +01:00
|
|
|
else
|
2017-12-25 02:08:06 +01:00
|
|
|
minetest.chat_send_player( owner_name, S("This is your first elevator. It differs from "..
|
2017-12-17 17:56:36 +01:00
|
|
|
"travelnet networks by only allowing movement in vertical direction (up or down). "..
|
|
|
|
"All further elevators which you will place at the same x,z coordinates at differnt "..
|
2017-12-25 02:08:06 +01:00
|
|
|
"heights will be able to connect to this elevator."));
|
2017-12-17 17:56:36 +01:00
|
|
|
end
|
|
|
|
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-31 00:44:46 +02:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "travelnet_elevator.obj",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = 'light',
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
wield_scale = {x=0.6, y=0.6, z=0.6},
|
|
|
|
|
|
|
|
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},
|
|
|
|
{-0.5 , -0.5, 0.48, 0.48, 0.5, 0.5},
|
|
|
|
{-0.5, -0.5,-0.5 ,-0.48, 0.5, 0.5},
|
|
|
|
|
|
|
|
--groundplate to stand on
|
|
|
|
{ -0.5,-0.5,-0.5,0.5,-0.48, 0.5},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-02-26 20:36:14 +01:00
|
|
|
tiles = travelnet.tiles_elevator,
|
|
|
|
|
|
|
|
inventory_image = travelnet.elevator_inventory_image,
|
|
|
|
groups = {cracky=1,choppy=1,snappy=1,
|
|
|
|
-- for MineClone2
|
|
|
|
handy=1, axey=1, pickaxey=1, building_block=1, material_wood=1},
|
2013-06-13 05:49:41 +02:00
|
|
|
|
|
|
|
light_source = 10,
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer, itemstack)
|
2014-11-30 18:50:48 +01:00
|
|
|
local meta = minetest.get_meta(pos);
|
2017-12-25 02:08:06 +01:00
|
|
|
meta:set_string("infotext", S("Elevator (unconfigured)"));
|
2013-06-13 05:49:41 +02:00
|
|
|
meta:set_string("station_name", "");
|
|
|
|
meta:set_string("station_network","");
|
|
|
|
meta:set_string("owner", placer:get_player_name() );
|
2016-08-30 02:14:19 +02:00
|
|
|
-- request initial data
|
2013-06-13 05:49:41 +02:00
|
|
|
meta:set_string("formspec",
|
|
|
|
"size[12,10]"..
|
2017-12-25 02:08:06 +01:00
|
|
|
"field[0.3,5.6;6,0.7;station_name;"..S("Name of this station:")..";]"..
|
2013-06-20 04:59:04 +02:00
|
|
|
-- "field[0.3,6.6;6,0.7;station_network;Assign to Network:;]"..
|
|
|
|
-- "field[0.3,7.6;6,0.7;owner_name;(optional) owned by:;]"..
|
2017-12-25 02:08:06 +01:00
|
|
|
"button_exit[6.3,6.2;1.7,0.7;station_set;"..S("Store").."]" );
|
2013-06-21 22:01:54 +02:00
|
|
|
|
|
|
|
local p = {x=pos.x, y=pos.y+1, z=pos.z}
|
|
|
|
local p2 = minetest.dir_to_facedir(placer:get_look_dir())
|
2014-11-30 18:50:48 +01:00
|
|
|
minetest.add_node(p, {name="travelnet:elevator_top", paramtype2="facedir", param2=p2})
|
2017-12-17 17:56:36 +01:00
|
|
|
travelnet.show_nearest_elevator( pos, placer:get_player_name(), p2 );
|
2013-06-13 05:49:41 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_receive_fields = travelnet.on_receive_fields,
|
|
|
|
on_punch = function(pos, node, puncher)
|
2017-12-18 20:05:26 +01:00
|
|
|
if( not( travelnet.check_if_trying_to_dig( puncher, node ))) then
|
|
|
|
travelnet.update_formspec(pos, puncher:get_player_name())
|
|
|
|
end
|
2013-06-13 05:49:41 +02:00
|
|
|
end,
|
|
|
|
|
2013-06-19 22:52:32 +02:00
|
|
|
can_dig = function( pos, player )
|
|
|
|
return travelnet.can_dig( pos, player, 'elevator' )
|
|
|
|
end,
|
|
|
|
|
2013-06-13 05:49:41 +02:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
travelnet.remove_box( pos, oldnode, oldmetadata, digger )
|
|
|
|
end,
|
|
|
|
|
2017-12-17 02:34:15 +01:00
|
|
|
-- TNT and overenthusiastic DMs do not destroy elevators either
|
|
|
|
on_blast = function(pos, intensity)
|
|
|
|
end,
|
|
|
|
|
2013-06-13 05:49:41 +02:00
|
|
|
-- taken from VanessaEs homedecor fridge
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
2013-06-21 22:01:54 +02:00
|
|
|
local pos = pointed_thing.above;
|
2014-11-30 18:50:48 +01:00
|
|
|
local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z});
|
2013-06-21 22:01:54 +02:00
|
|
|
-- leftover elevator_top nodes can be removed by placing a new elevator underneath
|
|
|
|
if( node ~= nil and node.name ~= "air" and node.name ~= 'travelnet:elevator_top') then
|
2017-12-25 02:08:06 +01:00
|
|
|
minetest.chat_send_player( placer:get_player_name(), S('Not enough vertical space to place the travelnet box!'))
|
2013-06-13 05:49:41 +02:00
|
|
|
return;
|
|
|
|
end
|
|
|
|
return minetest.item_place(itemstack, placer, pointed_thing);
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_destruct = function(pos)
|
|
|
|
local p = {x=pos.x, y=pos.y+1, z=pos.z}
|
2014-11-30 18:50:48 +01:00
|
|
|
minetest.remove_node(p)
|
2013-06-13 05:49:41 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2015-07-31 00:44:46 +02:00
|
|
|
minetest.register_alias("travelnet:elevator_top", "air")
|
2013-06-13 05:49:41 +02:00
|
|
|
|
2013-06-26 23:15:57 +02:00
|
|
|
--if( minetest.get_modpath("technic") ~= nil ) then
|
|
|
|
-- minetest.register_craft({
|
|
|
|
-- output = "travelnet:elevator",
|
|
|
|
-- recipe = {
|
|
|
|
-- {"default:steel_ingot", "technic:motor", "default:steel_ingot", },
|
|
|
|
-- {"default:steel_ingot", "technic:control_logic_unit", "default:steel_ingot", },
|
|
|
|
-- {"default:steel_ingot", "moreores:copper_ingot", "default:steel_ingot", }
|
|
|
|
-- }
|
|
|
|
-- })
|
|
|
|
--else
|
2013-06-13 05:49:41 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "travelnet:elevator",
|
2013-11-20 20:27:10 +01:00
|
|
|
recipe = travelnet.elevator_recipe,
|
2013-06-13 05:49:41 +02:00
|
|
|
})
|
2013-06-26 23:15:57 +02:00
|
|
|
--end
|
2013-06-13 05:49:41 +02:00
|
|
|
|