mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-11-28 10:23:45 +01:00
v1.6 callback 'tubelib2_on_update2' added
This commit is contained in:
parent
e3e30e7b27
commit
57abcec464
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
26
storage.lua
26
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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user