diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-04-29 19:44:43 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-04-29 19:44:43 +0200 |
commit | 0c7144bcc49449eba9f6ab8f2c1d8efa72b0307a (patch) | |
tree | eb66e11bc2a6fb1937d85e2006a7f20d39e40e0b /advtrains/advtrains/nodedb.lua | |
parent | 331db7ba5f4e4b308c1f8efa93c2b40c5139766d (diff) | |
parent | f42b01c74bdc7e91d3def03125a0e24e6a3bb0d4 (diff) | |
download | advtrains-0c7144bcc49449eba9f6ab8f2c1d8efa72b0307a.tar.gz advtrains-0c7144bcc49449eba9f6ab8f2c1d8efa72b0307a.tar.bz2 advtrains-0c7144bcc49449eba9f6ab8f2c1d8efa72b0307a.zip |
Merge nocrash branch into master and merging it with the unified functions so that restoring works how it should
Also fix minor bugs and an occasional crash with couples
Diffstat (limited to 'advtrains/advtrains/nodedb.lua')
-rw-r--r-- | advtrains/advtrains/nodedb.lua | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/advtrains/advtrains/nodedb.lua b/advtrains/advtrains/nodedb.lua index ddd1a67..55adea8 100644 --- a/advtrains/advtrains/nodedb.lua +++ b/advtrains/advtrains/nodedb.lua @@ -203,37 +203,41 @@ minetest.register_abm({ nodenames = {"group:save_in_nodedb"}, run_at_every_load = true, action = function(pos, node) - local cid=ndbget(pos.x, pos.y, pos.z) - if cid then - --if in database, detect changes and apply. - local nodeid = ndb_nodeids[u14b(cid)] - local param2 = l2b(cid) - if not nodeid then - --something went wrong - atprint("nodedb: lbm nid not found", pos, "with nid", u14b(cid), "param2", param2, "cid is", cid) - ndb.update(pos, node) - else - if (nodeid~=node.name or param2~=node.param2) then - atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid) - minetest.swap_node(pos, {name=nodeid, param2 = param2}) - local ndef=minetest.registered_nodes[nodeid] - if ndef and ndef.on_updated_from_nodedb then - ndef.on_updated_from_nodedb(pos, node) + return advtrains.pcall(function() + local cid=ndbget(pos.x, pos.y, pos.z) + if cid then + --if in database, detect changes and apply. + local nodeid = ndb_nodeids[u14b(cid)] + local param2 = l2b(cid) + if not nodeid then + --something went wrong + atprint("nodedb: lbm nid not found", pos, "with nid", u14b(cid), "param2", param2, "cid is", cid) + ndb.update(pos, node) + else + if (nodeid~=node.name or param2~=node.param2) then + atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid) + minetest.swap_node(pos, {name=nodeid, param2 = param2}) + local ndef=minetest.registered_nodes[nodeid] + if ndef and ndef.on_updated_from_nodedb then + ndef.on_updated_from_nodedb(pos, node) + end end end + else + --if not in database, take it. + atprint("nodedb: ", pos, "not in database") + ndb.update(pos, node) end - else - --if not in database, take it. - atprint("nodedb: ", pos, "not in database") - ndb.update(pos, node) - end + end) end, interval=10, chance=1, }) minetest.register_on_dignode(function(pos, oldnode, digger) - ndb.clear(pos) + return advtrains.pcall(function() + ndb.clear(pos) + end) end) function ndb.get_nodes() |