From cacd0da4314759fd41cd3318afca4a9c99bba78d Mon Sep 17 00:00:00 2001 From: Gabriel Pérez-Cerezo Date: Tue, 4 Oct 2016 10:54:48 +0200 Subject: Now honors protections --- trackplacer.lua | 67 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/trackplacer.lua b/trackplacer.lua index 1dbdffa..ca1ebc7 100644 --- a/trackplacer.lua +++ b/trackplacer.lua @@ -1,7 +1,7 @@ --trackplacer.lua --holds code for the track-placing system. the default 'track' item will be a craftitem that places rails as needed. this will neither place or change switches nor place vertical rails. -local print=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_all(table.concat({t, ...}, " ")) end +local print=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_player(table.concat({t, ...}, " ")) end --all new trackplacer code local tp={ @@ -176,6 +176,9 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname) if pointed_thing.type=="node" then local pos=pointed_thing.above local upos=pointed_thing.under + if minetest.is_protected(pos,placer) and minetest.is_protected(upos,placer) then + return itemstack + end if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to and minetest.registered_nodes[minetest.get_node(upos).name] and minetest.registered_nodes[minetest.get_node(upos).name].walkable then tp.placetrack(pos, nnprefix) @@ -198,40 +201,46 @@ minetest.register_craftitem("advtrains:trackworker",{ wield_image = "advtrains_trackworker.png", stack_max = 1, on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type=="node" then - local pos=pointed_thing.under - local node=minetest.get_node(pos) - - --if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end - if advtrains.is_train_at_pos(pos) then return end - - local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") - --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation) - if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then - print("[advtrains]railtype not workable by trackworker") - return - end - local modext=tp.tracks[nnprefix].twrotate[suffix] + if pointed_thing.type=="node" then + local pos=pointed_thing.under + if minetest.is_protected(pos, placer) then + return + end + local node=minetest.get_node(pos) + + --if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end + if advtrains.is_train_at_pos(pos) then return end + + local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") + --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation) + if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then + print("[advtrains]railtype not workable by trackworker") + return + end + local modext=tp.tracks[nnprefix].twrotate[suffix] - if rotation==modext[#modext] then --increase param2 - minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[1], param2=(node.param2+1)%4}) - return - else - local modpos - for k,v in pairs(modext) do if v==rotation then modpos=k end end - if not modpos then - print("[advtrains]rail not workable by trackworker") - return - end - minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2}) - end - advtrains.invalidate_all_paths() - end + if rotation==modext[#modext] then --increase param2 + minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[1], param2=(node.param2+1)%4}) + return + else + local modpos + for k,v in pairs(modext) do if v==rotation then modpos=k end end + if not modpos then + print("[advtrains]rail not workable by trackworker") + return + end + minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2}) + end + advtrains.invalidate_all_paths() + end end, on_use=function(itemstack, user, pointed_thing) if pointed_thing.type=="node" then local pos=pointed_thing.under local node=minetest.get_node(pos) + if minetest.is_protected(pos, user) then + return + end --if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end if advtrains.is_train_at_pos(pos) then return end -- cgit v1.2.3 From 307b4048ac620f6e3368976b1575f2ac800edc70 Mon Sep 17 00:00:00 2001 From: Gabriel Pérez-Cerezo Date: Wed, 5 Oct 2016 15:27:16 +0200 Subject: Fixed crash problem --- trainhud.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/trainhud.lua b/trainhud.lua index 601b28f..81b9e94 100644 --- a/trainhud.lua +++ b/trainhud.lua @@ -8,6 +8,9 @@ end) function advtrains.set_trainhud(name, text) local hud = advtrains.hud[name] local player=minetest.get_player_by_name(name) + if not player then + return + end if not hud then hud = {} advtrains.hud[name] = hud @@ -53,4 +56,4 @@ function advtrains.hud_train_format(train, flip) elseif vel>0 then return firstLine.."\n"..secondLine.."\nPress up to accelerate, down to decelerate, sneak to stop." end -end \ No newline at end of file +end -- cgit v1.2.3 From c0c9bd5a609e016d0b9607bf1d7a2ddce80df754 Mon Sep 17 00:00:00 2001 From: Gabriel Pérez-Cerezo Date: Wed, 5 Oct 2016 17:39:53 +0200 Subject: Fixed bug (unable to send message to player) --- trackplacer.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/trackplacer.lua b/trackplacer.lua index ca1ebc7..f5d3ad3 100644 --- a/trackplacer.lua +++ b/trackplacer.lua @@ -1,7 +1,11 @@ --trackplacer.lua --holds code for the track-placing system. the default 'track' item will be a craftitem that places rails as needed. this will neither place or change switches nor place vertical rails. -local print=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_player(table.concat({t, ...}, " ")) end +local print=function(player, t, ...) minetest.log("action", table.concat({t, ...}, " ")) + if player then + minetest.chat_send_player(player,table.concat({t, ...}, " ")) + end +end --all new trackplacer code local tp={ @@ -214,7 +218,7 @@ minetest.register_craftitem("advtrains:trackworker",{ local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation) if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then - print("[advtrains]railtype not workable by trackworker") + print(placer, "[advtrains]railtype not workable by trackworker") return end local modext=tp.tracks[nnprefix].twrotate[suffix] @@ -226,7 +230,7 @@ minetest.register_craftitem("advtrains:trackworker",{ local modpos for k,v in pairs(modext) do if v==rotation then modpos=k end end if not modpos then - print("[advtrains]rail not workable by trackworker") + print(placer,"[advtrains]rail not workable by trackworker") return end minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2}) @@ -247,7 +251,7 @@ minetest.register_craftitem("advtrains:trackworker",{ local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twcycle[suffix] then - print("[advtrains]railtype not workable by trackworker") + print(user,"[advtrains]railtype not workable by trackworker") return end local nextsuffix=tp.tracks[nnprefix].twcycle[suffix] -- cgit v1.2.3 From 08f957f1895f18a8bc017c9a99c5d5ef139694fc Mon Sep 17 00:00:00 2001 From: Gabriel Pérez-Cerezo Date: Wed, 5 Oct 2016 21:56:21 +0200 Subject: Fixed Bug introduced by bugfix --- trackplacer.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/trackplacer.lua b/trackplacer.lua index f5d3ad3..e1033a4 100644 --- a/trackplacer.lua +++ b/trackplacer.lua @@ -205,9 +205,13 @@ minetest.register_craftitem("advtrains:trackworker",{ wield_image = "advtrains_trackworker.png", stack_max = 1, on_place = function(itemstack, placer, pointed_thing) + local name = placer:get_player_name() + if not name then + return + end if pointed_thing.type=="node" then local pos=pointed_thing.under - if minetest.is_protected(pos, placer) then + if minetest.is_protected(pos, name) then return end local node=minetest.get_node(pos) @@ -218,7 +222,7 @@ minetest.register_craftitem("advtrains:trackworker",{ local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation) if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then - print(placer, "[advtrains]railtype not workable by trackworker") + print(name, "[advtrains]railtype not workable by trackworker") return end local modext=tp.tracks[nnprefix].twrotate[suffix] @@ -239,10 +243,14 @@ minetest.register_craftitem("advtrains:trackworker",{ end end, on_use=function(itemstack, user, pointed_thing) + local name = user:get_player_name() + if not name then + return + end if pointed_thing.type=="node" then local pos=pointed_thing.under local node=minetest.get_node(pos) - if minetest.is_protected(pos, user) then + if minetest.is_protected(pos, name) then return end @@ -251,7 +259,7 @@ minetest.register_craftitem("advtrains:trackworker",{ local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twcycle[suffix] then - print(user,"[advtrains]railtype not workable by trackworker") + print(name,"[advtrains]railtype not workable by trackworker") return end local nextsuffix=tp.tracks[nnprefix].twcycle[suffix] @@ -259,7 +267,7 @@ minetest.register_craftitem("advtrains:trackworker",{ --invalidate trains advtrains.invalidate_all_paths() else - print(dump(tp.tracks)) + print(name, dump(tp.tracks)) end end, }) -- cgit v1.2.3 From c936b824d6453cf942e30e423c0de28b7018f782 Mon Sep 17 00:00:00 2001 From: Gabriel Pérez-Cerezo Date: Sat, 8 Oct 2016 14:33:21 +0200 Subject: Fixed bug with protections --- trackplacer.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trackplacer.lua b/trackplacer.lua index e1033a4..8ff9a63 100644 --- a/trackplacer.lua +++ b/trackplacer.lua @@ -177,10 +177,14 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname) wield_image = imgprefix.."_placer.png", groups={}, on_place = function(itemstack, placer, pointed_thing) + local name = placer:get_player_name() + if not name then + return itemstack + end if pointed_thing.type=="node" then local pos=pointed_thing.above local upos=pointed_thing.under - if minetest.is_protected(pos,placer) and minetest.is_protected(upos,placer) then + if minetest.is_protected(pos,name) and minetest.is_protected(upos,name) then return itemstack end if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to -- cgit v1.2.3