Voxel Manipulator function added to read unloaded nodes

master
Joachim Stolberg 2017-10-06 22:32:19 +02:00
parent d382f9ae91
commit 2190dd9199
4 changed files with 20 additions and 15 deletions

2
api.md
View File

@ -11,7 +11,7 @@ Tubelib supports:
Tubes represent connections between two nodes, so that it is irrelevant Tubes represent connections between two nodes, so that it is irrelevant
if the receiving node is nearby or far away, connected via tubes. if the receiving node is nearby or far away, connected via tubes.
The length of the tube is limited to 50 nodes. The length of the tube is limited to 100 nodes.
For StackItem exchange we have to distinguish the following roles: For StackItem exchange we have to distinguish the following roles:
- client: An active node calling push/pull functions - client: An active node calling push/pull functions

View File

@ -48,6 +48,7 @@ local string_split = string.split
local minetest_is_protected = minetest.is_protected local minetest_is_protected = minetest.is_protected
local tubelib_NodeDef = tubelib.NodeDef local tubelib_NodeDef = tubelib.NodeDef
local get_neighbor_pos = tubelib.get_neighbor_pos local get_neighbor_pos = tubelib.get_neighbor_pos
local read_node_with_vm = tubelib.read_node_with_vm
-- Translate from facedir to contact side of the other node -- Translate from facedir to contact side of the other node
-- (left for one is right for the other node) -- (left for one is right for the other node)
@ -73,7 +74,7 @@ end
-- Determine the contact side of the node at the given pos -- Determine the contact side of the node at the given pos
-- param facedir: facedir to the node -- param facedir: facedir to the node
local function get_node_side(npos, facedir) local function get_node_side(npos, facedir)
local node = minetest.get_node(npos) local node = minetest.get_node_or_nil(npos) or read_node_with_vm(npos)
if facedir < 4 then if facedir < 4 then
facedir = (facedir - node.param2 + 4) % 4 facedir = (facedir - node.param2 + 4) % 4
end end

View File

@ -9,6 +9,7 @@ But Tubelib provides the following basic blocks:
### Tubes ### Tubes
Tubes allow the item exchange between two blocks. Tube forks are not possible. You have to use chests or other inventory blocks as hubs to build more complex structures. The maximum length of one tube line is 48 blocks. Tubes allow the item exchange between two blocks. Tube forks are not possible. You have to use chests or other inventory blocks as hubs to build more complex structures. The maximum length of one tube line is 48 blocks.
Tubes for itself are passive. For item exchange you have to use pulling/pushing blocks in addition. Tubes for itself are passive. For item exchange you have to use pulling/pushing blocks in addition.
The maximum tube length is limited to 100 nodes.
### Pusher ### Pusher
The Pusher is able to pull one item out of one inventory block and pushing it into another inventory block directly or by means of tubes. The Pusher is able to pull one item out of one inventory block and pushing it into another inventory block directly or by means of tubes.

View File

@ -98,7 +98,7 @@ local function dir_to_facedir(my_pos, other_pos)
end end
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- API function -- API functions
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Determine neighbor position and own facedir to the node. -- Determine neighbor position and own facedir to the node.
@ -118,6 +118,21 @@ function tubelib.get_neighbor_pos(pos, side)
return npos, facedir return npos, facedir
end end
-- use Voxel Manipulator to read the node
function tubelib.read_node_with_vm(pos)
local vm = VoxelManip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
local data = vm:get_data()
local param2_data = vm:get_param2_data()
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
return {
name=minetest.get_name_from_content_id(data[area:index(pos.x, pos.y, pos.z)]),
param2 = param2_data[area:index(pos.x, pos.y, pos.z)]
}
end
local read_node_with_vm = tubelib.read_node_with_vm
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Tube placement -- Tube placement
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -210,18 +225,6 @@ local function nodetype_to_pos(mpos, opos, node)
end end
end end
-- use Voxel Manipulator to read the node
local function read_node_with_vm(pos)
local vm = VoxelManip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
local data = vm:get_data()
local param2_data = vm:get_param2_data()
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
return {
name=minetest.get_name_from_content_id(data[area:index(pos.x, pos.y, pos.z)]),
param2 = param2_data[area:index(pos.x, pos.y, pos.z)]
}
end
-- Walk to the other end of the tube line, starting at 'pos1'. -- Walk to the other end of the tube line, starting at 'pos1'.
-- Returns: cnt - number of tube nodes -- Returns: cnt - number of tube nodes