From 2dcf60dec6304abc910dea82c6f9a5904bbf365b Mon Sep 17 00:00:00 2001 From: orwell96 Date: Fri, 12 Mar 2021 17:30:50 +0100 Subject: Track can-dig check: also notify user when digging is not allowed --- advtrains/locale/advtrains.de.tr | 1 + advtrains/tracks.lua | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/advtrains/locale/advtrains.de.tr b/advtrains/locale/advtrains.de.tr index f0d797f..cd43eed 100644 --- a/advtrains/locale/advtrains.de.tr +++ b/advtrains/locale/advtrains.de.tr @@ -66,6 +66,7 @@ Subway Passenger Wagon=U-Bahn-Waggon The wagon's inventory is not empty!=Das Inventar dieses Waggons ist nicht leer! This track can not be changed!=Diese Schiene kann nicht geƤndert werden! This track can not be rotated!=Diese Schiene kann nicht gedreht werden! +This track can not be removed!=Diese Schiene kann nicht entfernt werden! Position is occupied by a train.=Ein Zug steht an dieser Position. There's a Track Circuit Break here.=Hier ist eine Gleisabschnittsgrenze (TCB). There's a Signal Influence Point here.=Hier ist ein Signal-Beeinflussungspunkt. diff --git a/advtrains/tracks.lua b/advtrains/tracks.lua index ba59720..e034e85 100644 --- a/advtrains/tracks.lua +++ b/advtrains/tracks.lua @@ -442,6 +442,15 @@ Depending on the number of connections: - conn3 <> conn4 ]] +-- Notify the user if digging the rail is not allowed +local function can_dig_callback(pos, player) + local ok, reason = advtrains.can_dig_or_modify_track(pos) + if not ok and player then + minetest.chat_send_player(player:get_player_name(), attrans("This track can not be removed!") .. " " .. reason) + end + return ok +end + function advtrains.register_tracks(tracktype, def, preset) advtrains.trackplacer.register_tracktype(def.nodename_prefix, preset.tpdefault) if preset.regtp then @@ -478,7 +487,7 @@ function advtrains.register_tracks(tracktype, def, preset) not_blocking_trains=1, }, - can_dig = advtrains.can_dig_or_modify_track, + can_dig = can_dig_callback, after_dig_node=function(pos) advtrains.ndb.update(pos) end, -- cgit v1.2.3