aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-10-15 12:07:55 +0200
committerGitHub <noreply@github.com>2016-10-15 12:07:55 +0200
commitdef57bcab87d57285b194827e63e734004eb3bfb (patch)
treeceb92bbb4b16767d898b11c8837a4e41c369f905
parent8cae3cf9ee035757d5004389d12634f1a34f90bc (diff)
parentc936b824d6453cf942e30e423c0de28b7018f782 (diff)
downloadadvtrains-def57bcab87d57285b194827e63e734004eb3bfb.tar.gz
advtrains-def57bcab87d57285b194827e63e734004eb3bfb.tar.bz2
advtrains-def57bcab87d57285b194827e63e734004eb3bfb.zip
Merge pull request #5 from gpcf/master
Now honors protections
-rw-r--r--trackplacer.lua87
-rw-r--r--trainhud.lua5
2 files changed, 60 insertions, 32 deletions
diff --git a/trackplacer.lua b/trackplacer.lua
index 1dbdffa..8ff9a63 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_all(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={
@@ -173,9 +177,16 @@ 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,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
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,47 +209,61 @@ 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]
+ 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, name) 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(name, "[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(placer,"[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)
+ 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, name) 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
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(name,"[advtrains]railtype not workable by trackworker")
return
end
local nextsuffix=tp.tracks[nnprefix].twcycle[suffix]
@@ -246,7 +271,7 @@ minetest.register_craftitem("advtrains:trackworker",{
--invalidate trains
advtrains.invalidate_all_paths()
else
- print(dump(tp.tracks))
+ print(name, dump(tp.tracks))
end
end,
})
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