aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-10-22 20:32:02 +0200
committerorwell96 <mono96.mml@gmail.com>2016-10-22 20:32:02 +0200
commita3d8c3ae16021881b0b39cfe473f16ae62f5f81e (patch)
tree3acc2f234e9b7746fba53fd1e26ae127e175d655
parent7f92ac4bd2874d4609a50c95554cf5b956a52803 (diff)
parentdef57bcab87d57285b194827e63e734004eb3bfb (diff)
downloadadvtrains-a3d8c3ae16021881b0b39cfe473f16ae62f5f81e.tar.gz
advtrains-a3d8c3ae16021881b0b39cfe473f16ae62f5f81e.tar.bz2
advtrains-a3d8c3ae16021881b0b39cfe473f16ae62f5f81e.zip
Merge branch 'master' of https://github.com/orwell96/advtrains
-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