aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains/tracks.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/advtrains/tracks.lua')
-rw-r--r--advtrains/advtrains/tracks.lua32
1 files changed, 14 insertions, 18 deletions
diff --git a/advtrains/advtrains/tracks.lua b/advtrains/advtrains/tracks.lua
index 671c861..1108a06 100644
--- a/advtrains/advtrains/tracks.lua
+++ b/advtrains/advtrains/tracks.lua
@@ -235,10 +235,7 @@ advtrains.trackpresets = ap
function advtrains.register_tracks(tracktype, def, preset)
local function make_switchfunc(suffix_target, mesecon_state)
local switchfunc=function(pos, node)
- if advtrains.is_train_at_pos(pos) then return end
- minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
- advtrains.invalidate_all_paths()
- advtrains.reset_trackdb_position(pos)
+ advtrains.ndb.swap_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
end
return switchfunc, {effector = {
["action_"..mesecon_state] = switchfunc,
@@ -258,10 +255,12 @@ function advtrains.register_tracks(tracktype, def, preset)
rely1=conns.rely1 or 0,
rely2=conns.rely2 or 0,
railheight=conns.railheight or 0,
+
on_rightclick=switchfunc,
groups = {
attached_node=1,
["advtrains_track_"..tracktype]=1,
+ save_in_nodedb=1,
dig_immediate=2,
not_in_creative_inventory=(not in_creative_inv and 1 or nil),
not_blocking_trains=1,
@@ -299,13 +298,10 @@ function advtrains.register_tracks(tracktype, def, preset)
end,
after_dig_node=function(pos)
advtrains.invalidate_all_paths()
- advtrains.reset_trackdb_position(pos)
+ advtrains.ndb.update(pos)
end,
after_place_node=function(pos)
- advtrains.reset_trackdb_position(pos)
- end,
- on_place_rail=function(pos)
- advtrains.reset_trackdb_position(pos)
+ advtrains.ndb.update(pos)
end,
}, def.common or {})
--make trackplacer base def
@@ -398,10 +394,10 @@ advtrains.detector.clean_step_before = false
--The entry already being contained in advtrains.detector.on_node_restore will not trigger an on_train_enter event on the node. (when path is reset, this is saved).
function advtrains.detector.enter_node(pos, train_id)
local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
- atprint("enterNode "..pts.." "..sid(train_id))
+ --atprint("enterNode "..pts.." "..sid(train_id))
if advtrains.detector.on_node[pts] then
if advtrains.trains[advtrains.detector.on_node[pts]] then
- atprint(""..pts.." already occupied")
+ --atprint(""..pts.." already occupied")
return false
else
advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
@@ -417,9 +413,9 @@ function advtrains.detector.enter_node(pos, train_id)
end
function advtrains.detector.leave_node(pos, train_id)
local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
- atprint("leaveNode "..pts.." "..sid(train_id))
+ --atprint("leaveNode "..pts.." "..sid(train_id))
if not advtrains.detector.on_node[pts] then
- atprint(""..pts.." leave: nothing here")
+ --atprint(""..pts.." leave: nothing here")
return false
end
if advtrains.detector.on_node[pts]==train_id then
@@ -427,7 +423,7 @@ function advtrains.detector.leave_node(pos, train_id)
advtrains.detector.on_node[pts]=nil
else
if advtrains.trains[advtrains.detector.on_node[pts]] then
- atprint(""..pts.." occupied by another train")
+ --atprint(""..pts.." occupied by another train")
return false
else
advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
@@ -438,7 +434,7 @@ function advtrains.detector.leave_node(pos, train_id)
end
--called immediately before invalidating paths
function advtrains.detector.setup_restore()
- atprint("setup_restore")
+ --atprint("setup_restore")
-- don't execute if it already has been called. For some reason it gets called twice...
if advtrains.detector.clean_step_before then
return
@@ -452,7 +448,7 @@ function advtrains.detector.setup_restore()
end
--called one step after invalidating paths, when all trains have restored their path and called enter_node for their contents.
function advtrains.detector.finalize_restore()
- atprint("finalize_restore")
+ --atprint("finalize_restore")
for pts, train_id in pairs(advtrains.detector.on_node_restore) do
--atprint("called leave callback "..pts.." "..train_id)
advtrains.detector.call_leave_callback(minetest.string_to_pos(pts), train_id)
@@ -461,7 +457,7 @@ function advtrains.detector.finalize_restore()
advtrains.detector.clean_step_before = false
end
function advtrains.detector.call_enter_callback(pos, train_id)
- atprint("instructed to call enter calback")
+ --atprint("instructed to call enter calback")
local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
local mregnode=minetest.registered_nodes[node.name]
@@ -473,7 +469,7 @@ function advtrains.detector.call_enter_callback(pos, train_id)
advtrains.atc.trigger_controller_train_enter(pos, train_id)
end
function advtrains.detector.call_leave_callback(pos, train_id)
- atprint("instructed to call leave calback")
+ --atprint("instructed to call leave calback")
local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
local mregnode=minetest.registered_nodes[node.name]