diff --git a/README.md b/README.md index 1ce60ea..37b23aa 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,6 @@ Textures: CC0 - 2019-05-01 v1.3 * API function 'compatible_node' added - 2019-05-09 v1.4 * Attribute 'tube_type' added - 2019-07-12 v1.5 * internal handling of secondary nodes changed +- 2019-10-25 v1.6 * callback 'tubelib2_on_update2' added + + diff --git a/internal1.lua b/internal1.lua index c77d2f2..7af35e8 100644 --- a/internal1.lua +++ b/internal1.lua @@ -96,8 +96,11 @@ end function Tube:update_secondary_node(pos1, dir1, pos2, dir2) local node,_ = self:get_secondary_node(pos1) if node then - if (minetest.registered_nodes[node.name] or {}).tubelib2_on_update then - minetest.registered_nodes[node.name].tubelib2_on_update(node, pos1, dir1, pos2, Turn180Deg[dir2]) + local ndef = minetest.registered_nodes[node.name] or {} + if ndef.tubelib2_on_update2 then + ndef.tubelib2_on_update2(pos1, dir1, self, node) + elseif ndef.tubelib2_on_update then + ndef.tubelib2_on_update(node, pos1, dir1, pos2, Turn180Deg[dir2]) elseif self.clbk_update_secondary_node then self.clbk_update_secondary_node(node, pos1, dir1, pos2, Turn180Deg[dir2]) end diff --git a/storage.lua b/storage.lua index 463cedc..bde34a2 100644 --- a/storage.lua +++ b/storage.lua @@ -70,6 +70,17 @@ local function unlock(pos) return block, node_key end +local function keys_to_pos(block_key, node_key) + local f = math.floor + block_key = tonumber(block_key) or 0 + node_key = tonumber(node_key) or 0 + local x = ((f(block_key % 0x1000) * 0x10) - 32768) + (node_key % 0x10) + block_key, node_key = f(block_key / 0x1000), f(node_key / 0x10) + local y = ((f(block_key % 0x1000) * 0x10) - 32768) + (node_key % 0x10) + block_key, node_key = f(block_key / 0x1000), f(node_key / 0x10) + local z = ((f(block_key % 0x1000) * 0x10) - 32768) + (node_key % 0x10) + return {x = x, y = y, z = z} +end ------------------------------------------------------------------------------- -- API functions for a node related and high efficient storage table @@ -99,3 +110,18 @@ function tubelib2.get_mem_data(pos, key, default) return tubelib2.get_mem(pos)[key] or default end +function tubelib2.walk_over_all(clbk) + local data = storage:to_table() + for block_key,sblock in pairs(data.fields) do + local block = minetest.deserialize(sblock) + for node_key,mem in pairs(block) do + if mem then + if node_key ~= "used" and node_key ~= "best_before" then + local pos = keys_to_pos(block_key, node_key) + local node = techage.get_node_lvm(pos) + clbk(pos, node, mem) + end + end + end + end +end diff --git a/tube_api.lua b/tube_api.lua index 1737e1d..18d9cd7 100644 --- a/tube_api.lua +++ b/tube_api.lua @@ -13,7 +13,7 @@ ]]-- -- Version for compatibility checks, see readme.md/history -tubelib2.version = 1.4 +tubelib2.version = 1.6 -- for lazy programmers local S = function(pos) if pos then return minetest.pos_to_string(pos) end end