added buttons for removing/digging stations

This commit is contained in:
Sokomine 2019-02-26 22:44:33 +01:00
parent af49bccd79
commit 5b338f0d5c
5 changed files with 57 additions and 11 deletions

@ -117,9 +117,7 @@ minetest.register_node("travelnet:elevator", {
tiles = travelnet.tiles_elevator, tiles = travelnet.tiles_elevator,
inventory_image = travelnet.elevator_inventory_image, inventory_image = travelnet.elevator_inventory_image,
groups = {cracky=1,choppy=1,snappy=1, groups = {}, --cracky=1,choppy=1,snappy=1,
-- for MineClone2
handy=1, axey=1, pickaxey=1, building_block=1, material_wood=1},
light_source = 10, light_source = 10,
@ -145,9 +143,7 @@ minetest.register_node("travelnet:elevator", {
on_receive_fields = travelnet.on_receive_fields, on_receive_fields = travelnet.on_receive_fields,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
if( not( travelnet.check_if_trying_to_dig( puncher, node ))) then
travelnet.update_formspec(pos, puncher:get_player_name()) travelnet.update_formspec(pos, puncher:get_player_name())
end
end, end,
can_dig = function( pos, player ) can_dig = function( pos, player )

@ -224,6 +224,7 @@ travelnet.reset_formspec = function( meta )
meta:set_string("formspec", meta:set_string("formspec",
"size[10,6.0]".. "size[10,6.0]"..
"label[2.0,0.0;--> "..S("Configure this travelnet station").." <--]".. "label[2.0,0.0;--> "..S("Configure this travelnet station").." <--]"..
"button_exit[8.0,0.0;2.2,0.7;station_dig;"..S("Remove station").."]"..
"field[0.3,1.2;9,0.9;station_name;"..S("Name of this station")..":;".. "field[0.3,1.2;9,0.9;station_name;"..S("Name of this station")..":;"..
minetest.formspec_escape(station_name or "").."]".. minetest.formspec_escape(station_name or "").."]"..
"label[0.3,1.5;"..S("How do you call this place here? Example: \"my first house\", \"mine\", \"shop\"...").."]".. "label[0.3,1.5;"..S("How do you call this place here? Example: \"my first house\", \"mine\", \"shop\"...").."]"..
@ -461,6 +462,7 @@ travelnet.update_formspec = function( pos, puncher_name, fields )
formspec = formspec.. formspec = formspec..
"label[8.0,1.6;"..S("Position in list:").."]".. "label[8.0,1.6;"..S("Position in list:").."]"..
"button_exit[11.3,0.0;1.0,0.5;station_exit;"..S("Exit").."]".. "button_exit[11.3,0.0;1.0,0.5;station_exit;"..S("Exit").."]"..
"button_exit[10.0,0.5;2.2,0.7;station_dig;"..S("Remove station").."]"..
"button[9.6,1.6;1.4,0.5;move_up;"..S("move up").."]".. "button[9.6,1.6;1.4,0.5;move_up;"..S("move up").."]"..
"button[10.9,1.6;1.4,0.5;move_down;"..S("move down").."]"; "button[10.9,1.6;1.4,0.5;move_down;"..S("move down").."]";
@ -655,6 +657,50 @@ travelnet.on_receive_fields = function(pos, formname, fields, player)
return; return;
end end
-- the player wants to remove the station
if( fields.station_dig ) then
local owner = meta:get_string( "owner" );
local node = minetest.get_node(pos)
local description = "station"
if( node and node.name and node.name == "travelnet:travelnet") then
description = "travelnet box"
elseif( node and node.name and node.name == "travelnet:elevator") then
description = "elevator"
else
minetest.chat_send_player(name, "Error: Unkown node.");
return
end
-- players with travelnet_remove priv can dig the station
if( not(minetest.check_player_privs(name, {travelnet_remove=true}))
-- the function travelnet.allow_dig(..) may allow additional digging
and not(travelnet.allow_dig( name, owner, network_name ))
-- the owner can remove the station
and owner ~= name
-- stations without owner can be removed by anybody
and owner ~= "") then
minetest.chat_send_player(name, S("This %s belongs to %s. You can't remove it."):format(description, tostring( meta:get_string('owner'))));
return
end
local pinv = player:get_inventory()
if(not(pinv:room_for_item("main", node.name))) then
minetest.chat_send_player(name, S("You do not have enough room in your inventory."));
return
end
-- give the player the box
pinv:add_item("main", node.name)
-- remove the box from the data structure
travelnet.remove_box( pos, nil, meta:to_table(), player );
-- remove the node as such
minetest.remove_node(pos)
return;
end
-- if the box has not been configured yet -- if the box has not been configured yet
if( meta:get_string("station_network")=="" ) then if( meta:get_string("station_network")=="" ) then
@ -847,7 +893,12 @@ end
travelnet.can_dig = function( pos, player, description ) travelnet.can_dig = function( pos, player, description )
-- forbid digging of the travelnet
return false;
end
-- obsolete function
travelnet.can_dig_old = function( pos, player, description )
if( not( player )) then if( not( player )) then
return false; return false;
end end

@ -24,6 +24,8 @@ Owned by: = Besitzer:
Unless you know what you are doing, leave this empty. = Wenn du nicht weißt, wozu dieses Feld dient, laß es leer. Unless you know what you are doing, leave this empty. = Wenn du nicht weißt, wozu dieses Feld dient, laß es leer.
Help = Hilfe Help = Hilfe
Save = Speichern Save = Speichern
Remove station = Station entfernen
You do not have enough room in your inventory. = Du hast nicht genug Platz in deinem Inventar.
Update failed! Resetting this box on the travelnet. = Aktualisierung gescheitert. Konfiguration der Reisenetz-Box wird zurückgesetzt. Update failed! Resetting this box on the travelnet. = Aktualisierung gescheitert. Konfiguration der Reisenetz-Box wird zurückgesetzt.
Station '%s' = Station '%s' Station '%s' = Station '%s'
has been reattached to the network '%s'. = wurde dem Netzwerk '%s' wieder hinzugefügt. has been reattached to the network '%s'. = wurde dem Netzwerk '%s' wieder hinzugefügt.

@ -24,6 +24,8 @@ Owned by: =
Unless you know what you are doing, leave this empty. = Unless you know what you are doing, leave this empty. =
Help = Help =
Save = Save =
Remove station =
You do not have enough room in your inventory. =
Update failed! Resetting this box on the travelnet. = Update failed! Resetting this box on the travelnet. =
Station '%s' = Station '%s' =
has been reattached to the network '%s'. = has been reattached to the network '%s'. =

@ -43,10 +43,7 @@ minetest.register_node("travelnet:travelnet", {
inventory_image = travelnet.travelnet_inventory_image, inventory_image = travelnet.travelnet_inventory_image,
groups = {cracky=1,choppy=1,snappy=1, groups = {}, --cracky=1,choppy=1,snappy=1},
-- for MineClone2
handy=1, axey=1, pickaxey=1, building_block=1, material_wood=1},
light_source = 10, light_source = 10,
@ -58,9 +55,7 @@ minetest.register_node("travelnet:travelnet", {
on_receive_fields = travelnet.on_receive_fields, on_receive_fields = travelnet.on_receive_fields,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
if( not( travelnet.check_if_trying_to_dig( puncher, node ))) then
travelnet.update_formspec(pos, puncher:get_player_name(), nil) travelnet.update_formspec(pos, puncher:get_player_name(), nil)
end
end, end,
can_dig = function( pos, player ) can_dig = function( pos, player )