From 2190dd9199dcb19ece70900bad44b860a6f4632e Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Fri, 6 Oct 2017 22:32:19 +0200 Subject: [PATCH] Voxel Manipulator function added to read unloaded nodes --- api.md | 2 +- command.lua | 3 ++- manual.md | 1 + tubes.lua | 29 ++++++++++++++++------------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/api.md b/api.md index eacf01f..0172c33 100644 --- a/api.md +++ b/api.md @@ -11,7 +11,7 @@ Tubelib supports: Tubes represent connections between two nodes, so that it is irrelevant 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: - client: An active node calling push/pull functions diff --git a/command.lua b/command.lua index 45a459e..3a4d189 100644 --- a/command.lua +++ b/command.lua @@ -48,6 +48,7 @@ local string_split = string.split local minetest_is_protected = minetest.is_protected local tubelib_NodeDef = tubelib.NodeDef 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 -- (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 -- param facedir: facedir to the node 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 facedir = (facedir - node.param2 + 4) % 4 end diff --git a/manual.md b/manual.md index 57fd004..cd1ff08 100644 --- a/manual.md +++ b/manual.md @@ -9,6 +9,7 @@ But Tubelib provides the following basic blocks: ### 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 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 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. diff --git a/tubes.lua b/tubes.lua index a9a5223..4760b27 100644 --- a/tubes.lua +++ b/tubes.lua @@ -98,7 +98,7 @@ local function dir_to_facedir(my_pos, other_pos) end ------------------------------------------------------------------------------- --- API function +-- API functions ------------------------------------------------------------------------------- -- Determine neighbor position and own facedir to the node. @@ -118,6 +118,21 @@ function tubelib.get_neighbor_pos(pos, side) return npos, facedir 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 ------------------------------------------------------------------------------- @@ -210,18 +225,6 @@ local function nodetype_to_pos(mpos, opos, node) 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'. -- Returns: cnt - number of tube nodes