Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/joe7575/tubelib2 into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxionary committed Nov 23, 2019
2 parents 9d81417 + 57abcec commit ef5170a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


7 changes: 5 additions & 2 deletions internal1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion tube_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
]]--

-- Version for compatibility checks, see readme.md/history
tubelib2.version = 1.5
tubelib2.version = 1.6

-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
Expand Down

0 comments on commit ef5170a

Please sign in to comment.