[mp_advtrains] Update to Git commit da884af patch 26f8bf4:

Commit: https://github.com/orwell96/advtrains/tree/da884af
Patch: https://github.com/AntumDeluge/mtmp-advtrains/tree/26f8bf4
This commit is contained in:
AntumDeluge 2017-05-12 23:29:46 -07:00
parent 8396d206bd
commit 08abfd8621
8 changed files with 77 additions and 37 deletions

View File

@ -127,7 +127,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
* shields * shields
* technic_armor * technic_armor
* wieldview * wieldview
* [advtrains][] ([LGPL][lic.lgpl2.1] / [CC BY-NC-SA][lic.ccbyncsa3.0]) -- version: [28717b4 Git][ver.advtrains] *2017-05-03* * [advtrains][] ([LGPL][lic.lgpl2.1] / [CC BY-NC-SA][lic.ccbyncsa3.0]) -- version: [da884af Git][ver.advtrains] *2017-05-12* ([patched][patch.advtrains])
* [animalmaterials][animals_modpack] (part of animals_modpack) ([CC0][lic.cc0] / [CC BY-SA][lic.ccbysa3.0]) -- version: [0.1.3 (d952d27 Git)][ver.animalmaterials] *2014-09-10* * [animalmaterials][animals_modpack] (part of animals_modpack) ([CC0][lic.cc0] / [CC BY-SA][lic.ccbysa3.0]) -- version: [0.1.3 (d952d27 Git)][ver.animalmaterials] *2014-09-10*
* mp_animalmaterials/ * mp_animalmaterials/
* animal_resources * animal_resources
@ -393,7 +393,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[ver.3d_armor]: https://github.com/stujones11/minetest-3d_armor/tree/793c748 [ver.3d_armor]: https://github.com/stujones11/minetest-3d_armor/tree/793c748
[ver.adv_spawning]: https://github.com/sapier/adv_spawning/tree/ec41aa9 [ver.adv_spawning]: https://github.com/sapier/adv_spawning/tree/ec41aa9
[ver.advtrains]: https://github.com/orwell96/advtrains/tree/28717b4 [ver.advtrains]: https://github.com/orwell96/advtrains/tree/da884af
[ver.airtanks]: https://github.com/minetest-mods/airtanks/tree/fc01ffb [ver.airtanks]: https://github.com/minetest-mods/airtanks/tree/fc01ffb
[ver.animalmaterials]: https://github.com/sapier/animalmaterials/tree/d952d27 [ver.animalmaterials]: https://github.com/sapier/animalmaterials/tree/d952d27
[ver.animals_modpack]: https://github.com/sapier/animals_modpack/tree/b9d0172 [ver.animals_modpack]: https://github.com/sapier/animals_modpack/tree/b9d0172
@ -474,6 +474,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[ver.worldedge]: https://github.com/minetest-mods/worldedge/tree/e15fa99 [ver.worldedge]: https://github.com/minetest-mods/worldedge/tree/e15fa99
[patch.adv_spawning]: https://github.com/AntumDeluge/mtmod-adv_spawning/tree/572688b [patch.adv_spawning]: https://github.com/AntumDeluge/mtmod-adv_spawning/tree/572688b
[patch.advtrains]: https://github.com/AntumDeluge/mtmp-advtrains/tree/26f8bf4
[patch.animals_modpack]: https://github.com/AntumDeluge/mtmp-animals_modpack/tree/e84e1e6 [patch.animals_modpack]: https://github.com/AntumDeluge/mtmp-animals_modpack/tree/e84e1e6
[patch.bags]: https://github.com/AntumDeluge/mtmod-bags/tree/4363284 [patch.bags]: https://github.com/AntumDeluge/mtmod-bags/tree/4363284
[patch.bedrock2]: https://github.com/AntumDeluge/mtmod-bedrock2/tree/0375ac1 [patch.bedrock2]: https://github.com/AntumDeluge/mtmod-bedrock2/tree/0375ac1

View File

@ -14,9 +14,11 @@ local no_action=false
function advtrains.pcall(fun) function advtrains.pcall(fun)
if no_action then return end if no_action then return end
local succ, err, return1, return2, return3, return4=pcall(fun) local succ, return1, return2, return3, return4=xpcall(fun, function(err)
atwarn("Lua Error occured: ", err)
atwarn(debug.traceback())
end)
if not succ then if not succ then
atwarn("Lua Error occured: ", err)
atwarn("Restoring saved state in 1 second...") atwarn("Restoring saved state in 1 second...")
no_action=true no_action=true
--read last save state and continue, as if server was restarted --read last save state and continue, as if server was restarted
@ -25,9 +27,13 @@ function advtrains.pcall(fun)
le.object:remove() le.object:remove()
end end
end end
minetest.after(1, advtrains.load) minetest.after(1, function()
advtrains.load()
atwarn("Reload successful!")
advtrains.ndb.restore_all()
end)
else else
return err, return1, return2, return3, return4 return return1, return2, return3, return4
end end
end end
@ -65,7 +71,7 @@ function advtrains.print_concat_table(a)
return str return str
end end
atprint=function() end atprint=function() end
if minetest.setting_getbool("advtrains_debug") then if minetest.settings:get_bool("advtrains_debug") then
atprint=function(t, ...) atprint=function(t, ...)
local context=advtrains.atprint_context_tid local context=advtrains.atprint_context_tid
if not context then context="" end if not context then context="" end

View File

@ -197,13 +197,16 @@ function advtrains.get_rail_info_at(pos, drives_on)
return true, conn1, conn2, rely1, rely2, railheight return true, conn1, conn2, rely1, rely2, railheight
end end
ndb.run_lbm = function(pos, nodep)
minetest.register_abm({
name = "advtrains:nodedb_on_load_update",
nodenames = {"group:save_in_nodedb"},
run_at_every_load = true,
action = function(pos, node)
return advtrains.pcall(function() return advtrains.pcall(function()
local node=nodep
if not node then
node=minetest.get_node_or_nil(pos)
if not node then
--this is defintely not loaded
return nil
end
end
local cid=ndbget(pos.x, pos.y, pos.z) local cid=ndbget(pos.x, pos.y, pos.z)
if cid then if cid then
--if in database, detect changes and apply. --if in database, detect changes and apply.
@ -215,11 +218,17 @@ minetest.register_abm({
ndb.update(pos, node) ndb.update(pos, node)
else else
if (nodeid~=node.name or param2~=node.param2) then if (nodeid~=node.name or param2~=node.param2) then
atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid) local ori_ndef=minetest.registered_nodes[node.name]
minetest.swap_node(pos, {name=nodeid, param2 = param2}) if ori_ndef and ori_ndef.groups.save_in_nodedb then --check if this node has been worldedited, and don't replace then
local ndef=minetest.registered_nodes[nodeid] atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid)
if ndef and ndef.on_updated_from_nodedb then minetest.swap_node(pos, {name=nodeid, param2 = param2})
ndef.on_updated_from_nodedb(pos, node) local ndef=minetest.registered_nodes[nodeid]
if ndef and ndef.on_updated_from_nodedb then
ndef.on_updated_from_nodedb(pos, node)
end
return true
else
ndb.clear(pos)
end end
end end
end end
@ -228,11 +237,35 @@ minetest.register_abm({
atprint("nodedb: ", pos, "not in database") atprint("nodedb: ", pos, "not in database")
ndb.update(pos, node) ndb.update(pos, node)
end end
return false
end) end)
end, end
minetest.register_abm({
name = "advtrains:nodedb_on_load_update",
nodenames = {"group:save_in_nodedb"},
run_at_every_load = true,
action = ndb.run_lbm,
interval=10, interval=10,
chance=1, chance=1,
}) })
--used when restoring stuff after a crash
ndb.restore_all = function()
atwarn("Updating the map from the nodedb, this may take a while")
local cnt=0
for y, ny in pairs(ndb_nodes) do
for x, nx in pairs(ny) do
for z, _ in pairs(nx) do
if ndb.run_lbm({x=x, y=y, z=z}) then
cnt=cnt+1
end
end
end
end
atwarn("Updated",cnt,"nodes")
end
minetest.register_on_dignode(function(pos, oldnode, digger) minetest.register_on_dignode(function(pos, oldnode, digger)
return advtrains.pcall(function() return advtrains.pcall(function()

View File

@ -202,7 +202,7 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname)
if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to 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 and minetest.registered_nodes[minetest.get_node(upos).name] and minetest.registered_nodes[minetest.get_node(upos).name].walkable then
tp.placetrack(pos, nnprefix, placer, itemstack, pointed_thing) tp.placetrack(pos, nnprefix, placer, itemstack, pointed_thing)
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
end end

View File

@ -534,12 +534,12 @@ function sl.create_slopeplacer_on_place(def, preset)
if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to or advtrains.is_protected(pos, player:get_player_name()) then if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to or advtrains.is_protected(pos, player:get_player_name()) then
--do slopes of this distance exist? --do slopes of this distance exist?
if lookup[step] then if lookup[step] then
if minetest.setting_getbool("creative_mode") or istack:get_count()>=step then if minetest.settings:get_bool("creative_mode") or istack:get_count()>=step then
--start placing --start placing
local placenodes=lookup[step] local placenodes=lookup[step]
while step>0 do while step>0 do
minetest.set_node(pos, {name=def.nodename_prefix.."_"..placenodes[step], param2=param2}) minetest.set_node(pos, {name=def.nodename_prefix.."_"..placenodes[step], param2=param2})
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
istack:take_item() istack:take_item()
end end
step=step-1 step=step-1

View File

@ -338,12 +338,12 @@ function advtrains.train_step_a(id, train, dtime)
train.savedpos_off_track_index_offset=train.index-train.max_index_on_track train.savedpos_off_track_index_offset=train.index-train.max_index_on_track
train.last_pos=train.path[train.max_index_on_track] train.last_pos=train.path[train.max_index_on_track]
train.last_pos_prev=train.path[train.max_index_on_track-1] train.last_pos_prev=train.path[train.max_index_on_track-1]
atprint("train is off-track (front), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev)) atprint("train is off-track (front), last positions kept at", train.last_pos, "/", train.last_pos_prev)
elseif train.min_index_on_track+1>train.index then --whoops, train went even more far. same behavior elseif train.min_index_on_track+1>train.index then --whoops, train went even more far. same behavior
train.savedpos_off_track_index_offset=train.index-train.min_index_on_track train.savedpos_off_track_index_offset=train.index-train.min_index_on_track
train.last_pos=train.path[train.min_index_on_track+1] train.last_pos=train.path[train.min_index_on_track+1]
train.last_pos_prev=train.path[train.min_index_on_track] train.last_pos_prev=train.path[train.min_index_on_track]
atprint("train is off-track (back), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev)) atprint("train is off-track (back), last positions kept at", train.last_pos, "/", train.last_pos_prev)
else --regular case else --regular case
train.savedpos_off_track_index_offset=nil train.savedpos_off_track_index_offset=nil
train.last_pos=train.path[math.floor(train.index+0.5)] train.last_pos=train.path[math.floor(train.index+0.5)]
@ -445,7 +445,7 @@ function advtrains.train_step_a(id, train, dtime)
--check for any trainpart entities if they have been unloaded. do this only if train is near a player, to not spawn entities into unloaded areas --check for any trainpart entities if they have been unloaded. do this only if train is near a player, to not spawn entities into unloaded areas
train.check_trainpartload=(train.check_trainpartload or 0)-dtime train.check_trainpartload=(train.check_trainpartload or 0)-dtime
local node_range=(math.max((minetest.setting_get("active_block_range") or 0),1)*16) local node_range=(math.max((minetest.settings:get("active_block_range") or 0),1)*16)
if train.check_trainpartload<=0 then if train.check_trainpartload<=0 then
local ori_pos=train_pos --see 3a. local ori_pos=train_pos --see 3a.
--atprint("[train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos))) --atprint("[train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos)))
@ -482,7 +482,7 @@ function advtrains.pathpredict(id, train, regular)
local maxn=train.path_extent_max or 0 local maxn=train.path_extent_max or 0
while maxn < gen_front do--pregenerate while maxn < gen_front do--pregenerate
atprint("maxn conway for ",maxn,minetest.pos_to_string(train.path[maxn]),maxn-1,minetest.pos_to_string(train.path[maxn-1])) atprint("maxn conway for ",maxn,train.path[maxn],maxn-1,train.path[maxn-1])
local conway=advtrains.conway(train.path[maxn], train.path[maxn-1], train.drives_on) local conway=advtrains.conway(train.path[maxn], train.path[maxn-1], train.drives_on)
if conway then if conway then
train.path[maxn+1]=conway train.path[maxn+1]=conway
@ -490,7 +490,7 @@ function advtrains.pathpredict(id, train, regular)
else else
--do as if nothing has happened and preceed with path --do as if nothing has happened and preceed with path
--but do not update max_index_on_track --but do not update max_index_on_track
atprint("over-generating path max to index "..(maxn+1).." (position "..minetest.pos_to_string(train.path[maxn]).." )") atprint("over-generating path max to index ",(maxn+1)," (position ",train.path[maxn]," )")
train.path[maxn+1]=vector.add(train.path[maxn], vector.subtract(train.path[maxn], train.path[maxn-1])) train.path[maxn+1]=vector.add(train.path[maxn], vector.subtract(train.path[maxn], train.path[maxn-1]))
end end
train.path_dist[maxn]=vector.distance(train.path[maxn+1], train.path[maxn]) train.path_dist[maxn]=vector.distance(train.path[maxn+1], train.path[maxn])
@ -500,7 +500,7 @@ function advtrains.pathpredict(id, train, regular)
local minn=train.path_extent_min or -1 local minn=train.path_extent_min or -1
while minn > gen_back do while minn > gen_back do
atprint("minn conway for ",minn,minetest.pos_to_string(train.path[minn]),minn+1,minetest.pos_to_string(train.path[minn+1])) atprint("minn conway for ",minn,train.path[minn],minn+1,train.path[minn+1])
local conway=advtrains.conway(train.path[minn], train.path[minn+1], train.drives_on) local conway=advtrains.conway(train.path[minn], train.path[minn+1], train.drives_on)
if conway then if conway then
train.path[minn-1]=conway train.path[minn-1]=conway
@ -508,7 +508,7 @@ function advtrains.pathpredict(id, train, regular)
else else
--do as if nothing has happened and preceed with path --do as if nothing has happened and preceed with path
--but do not update min_index_on_track --but do not update min_index_on_track
atprint("over-generating path min to index "..(minn-1).." (position "..minetest.pos_to_string(train.path[minn]).." )") atprint("over-generating path min to index ",(minn-1)," (position ",train.path[minn]," )")
train.path[minn-1]=vector.add(train.path[minn], vector.subtract(train.path[minn], train.path[minn+1])) train.path[minn-1]=vector.add(train.path[minn], vector.subtract(train.path[minn], train.path[minn+1]))
end end
train.path_dist[minn-1]=vector.distance(train.path[minn], train.path[minn-1]) train.path_dist[minn-1]=vector.distance(train.path[minn], train.path[minn-1])
@ -552,7 +552,7 @@ function advtrains.train_step_b(id, train, dtime)
advtrains.collide_and_spawn_couple(id, testpos, advtrains.detector.on_node[testpts], train.movedir==-1) advtrains.collide_and_spawn_couple(id, testpos, advtrains.detector.on_node[testpts], train.movedir==-1)
end end
--- 8b damage players --- --- 8b damage players ---
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
local player=advtrains.playersbypts[testpts] local player=advtrains.playersbypts[testpts]
if player and train.velocity>3 then if player and train.velocity>3 then
--instantly kill player --instantly kill player
@ -696,7 +696,7 @@ function advtrains.split_train_at_wagon(wagon)
end end
local node_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on) local node_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on)
if not node_ok then if not node_ok then
atprint("split_train: pos_for_new_train "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail") atprint("split_train: pos_for_new_train ",advtrains.round_vector_floor_y(pos_for_new_train_prev)," not loaded or is not a rail")
return false return false
end end
@ -707,7 +707,7 @@ function advtrains.split_train_at_wagon(wagon)
local prevnode_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on) local prevnode_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on)
if not prevnode_ok then if not prevnode_ok then
atprint("split_train: pos_for_new_train_prev "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail") atprint("split_train: pos_for_new_train_prev ", advtrains.round_vector_floor_y(pos_for_new_train_prev), " not loaded or is not a rail")
return false return false
end end
@ -756,7 +756,7 @@ function advtrains.trains_facing(train1, train2)
end end
function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos) function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos)
atprint("COLLISION: "..sid(id1).." and "..sid(id2).." at "..minetest.pos_to_string(pos)..", t1_is_backpos="..(t1_is_backpos and "true" or "false")) atprint("COLLISION: "..sid(id1).." and "..sid(id2).." at ",pos,", t1_is_backpos="..(t1_is_backpos and "true" or "false"))
--TODO: --TODO:
local train1=advtrains.trains[id1] local train1=advtrains.trains[id1]
@ -784,7 +784,7 @@ function advtrains.collide_and_spawn_couple(id1, pos, id2, t1_is_backpos)
local frontpos2=train2.path[math.floor(train2.detector_old_index)] local frontpos2=train2.path[math.floor(train2.detector_old_index)]
local backpos2=train2.path[math.floor(train2.detector_old_end_index)] local backpos2=train2.path[math.floor(train2.detector_old_end_index)]
local t2_is_backpos local t2_is_backpos
atprint("End positions: "..minetest.pos_to_string(frontpos2)..minetest.pos_to_string(backpos2)) atprint("End positions: ",frontpos2,backpos2)
t2_is_backpos = vector.distance(backpos2, pos) < vector.distance(frontpos2, pos) t2_is_backpos = vector.distance(backpos2, pos) < vector.distance(frontpos2, pos)

View File

@ -159,7 +159,7 @@ function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direct
return return
end end
if minetest.setting_getbool("creative_mode") then if minetest.settings:get_bool("creative_mode") then
if not self:destroy() then return end if not self:destroy() then return end
local inv = puncher:get_inventory() local inv = puncher:get_inventory()
@ -882,7 +882,7 @@ function advtrains.register_wagon(sysname, prototype, desc, inv_img)
local wagon_uid=le:init_new_instance(id, {}) local wagon_uid=le:init_new_instance(id, {})
advtrains.add_wagon_to_train(le, id) advtrains.add_wagon_to_train(le, id)
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack

View File

@ -9,7 +9,7 @@ Manual:
If manual.pdf is not present (which is the case when you downloaded the zip file), see https://github.com/orwell96/advtrains/blob/master/manual.pdf If manual.pdf is not present (which is the case when you downloaded the zip file), see https://github.com/orwell96/advtrains/blob/master/manual.pdf
License of code: LGPL 2.1 License of code: LGPL 2.1
License of media: CC-BY-NC-SA 3.0 License of media: CC-BY-SA 3.0
Contributions: Contributions: