v0.2 Tested against and enhanced for the hyperloop mod.

This commit is contained in:
Joachim Stolberg 2018-10-27 17:53:07 +02:00
parent 6bb5e76d0d
commit d3ec70e7e0
5 changed files with 106 additions and 32 deletions

@ -12,6 +12,43 @@ Browse on: ![GitHub](https://github.com/joe7575/tubelib2)
Download: ![GitHub](https://github.com/joe7575/tubelib2/archive/master.zip)
## Description
Tubelib2 distinguished two kinds of nodes:
- primary nodes are tube like nodes (pipes, cables, ...)
- secondary nodes are all kind of nodes, which can be connected by means of primary nodes
Tubelib2 specific 6D directions (1 = North, 2 = East, 3 = South, 4 = West, 5 = Down, 6 = Up)
All 6D dirs are the view from the node to the outer side
Tubes are based on two node types, "angled" and "straight" tubes.
+-------+
/ /| +-------+
+-------+ | / /|
| | | / / |
| | | +-------+ |
| | | | | |
| | | | |/ |
| | + +-------+| +
| |/ | |/
+-------+ +------+
All other nodes are build by means of axis/rotation variants based on param2
(paramtype2 == "facedir").
The 3 free MSB bits of param2 of tube nodes are used to store the number of connections (0..2).
The data of the peer head tube are stored as meta data: "peer_pos" and "peer_dir"
Tubelib2 provides no update mechanism for connected "secondary" nodes.
That means, all secondary nodes have to check their surrounding for any changes,
based on player interaction and/or on LBM basis.
## Dependencies
default
@ -23,3 +60,7 @@ Textures: CC0
## Dependencies
default
## History
- 2018-10-20 v0.1 * Tested against hyperloop elevator.
- 2018-10-27 v0.2 * Tested against and enhanced for the hyperloop mod.

@ -33,7 +33,7 @@ function Tube:convert_tube_line(pos, dir)
local npos, node = self:get_next_node(pos, dir)
local dir1, dir2, num = self.convert_tube_clbk(npos, node.name, node.param2)
if dir1 then
self.clbk_after_place_tube(self:tube_data_to_table(npos, dir1, dir2, num))
self.clbk_after_place_tube(self:tube_data_to_table(npos, dir1, dir2 or tubelib2.Turn180Deg[dir1], num))
if tubelib2.Turn180Deg[dir] == dir1 then
return npos, dir2

@ -18,31 +18,6 @@ local P = minetest.string_to_pos
local M = minetest.get_meta
--
-- Tubelib2 specific 6D directions (1 = North, 2 = East, 3 = South, 4 = West, 5 = Down, 6 = Up)
--
-- All 6D dirs are the view from the node to the outer side
-- Tubes are based on two node types, "angled" and "straight" tubes.
--
-- +-------+
-- / /| +-------+
-- +-------+ | / /|
-- | | | / / |
-- | | | +-------+ |
-- | | | | | |
-- | | | | |/ |
-- | | + +-------+| +
-- | |/ | |/
-- +-------+ +------+
--
-- All other nodes are build by means of axis/rotation variants based on param2
-- (paramtype2 == "facedir").
--
-- The 3 free MSB bits of param2 of tube nodes are used to store the number of connections (0..2).
--
-- The data of the peer head tube are stored as meta data: "peer_pos" and "peer_dir"
local Turn180Deg = {[0]=0,3,4,1,2,6,5}
tubelib2.Turn180Deg = Turn180Deg
@ -506,7 +481,7 @@ function Tube:get_peer_tube_head(node_tbl)
-- repair tube line
local pos2, dir2, cnt = self:find_peer_tube_head(node_tbl)
if pos2 then
self:add_meta_data(node_tbl.pos, pos2, Turn180Deg[node_tbl.dir], dir2, cnt)
self:add_meta_data(node_tbl.pos, pos2, Turn180Deg[node_tbl.dir], dir2, cnt+1)
return pos2, dir2
end
end

@ -12,11 +12,17 @@
]]--
-- Version for compatibility checks, see readme.md/history
tubelib2.version = 0.2
-- for lazy programmers
local S = minetest.pos_to_string
local P = minetest.string_to_pos
local M = minetest.get_meta
local Dir2Str = {"north", "east", "south", "west", "down", "up"}
function tubelib2.dir_to_string(dir)
return Dir2Str[dir]
end
local function Tbl(list)
local tbl = {}
@ -77,6 +83,18 @@ function Tube:secondary_node(pos, dir)
end
end
-- Used to determine the node side to the tube connection.
-- Function returns the first found dir value
-- to a primary node.
function Tube:get_primary_dir(pos)
-- Check all valid positions
for dir = 1,6 do
if self:primary_node(pos, dir) then
return dir
end
end
end
-- From source node to destination node via tubes.
-- pos is the source node position, dir the output dir
-- The returned pos is the destination position, dir
@ -90,6 +108,12 @@ function Tube:get_connected_node_pos(pos, dir)
return vector.add(pos, tubelib2.Dir6dToVector[dir or 0]), dir
end
function Tube:beside(pos1, pos2)
local pos = vector.subtract(pos1, pos2)
local res = pos.x + pos.y + pos.z
return res == 1 or res == -1
end
-- From tube head to tube head.
-- pos is the tube head position, dir is the direction into the head node.
-- The returned pos is the peer head position, dir
@ -103,7 +127,7 @@ function Tube:get_tube_end_pos(pos, dir)
end
-- To be called after a tube node is placed.
-- To be called after a secondary node is placed.
function Tube:after_place_node(pos, dir1, dir2)
self:delete_tube_meta_data(pos, dir1, dir2)
@ -122,7 +146,21 @@ function Tube:after_place_node(pos, dir1, dir2)
end
end
-- To be called after a tube node is placed.
-- To be called after a crossing node is placed.
function Tube:after_place_crossing_node(pos)
-- Check all valid positions
for dir = 1,6 do
if self.allowed_6d_dirs[dir] then
self:delete_tube_meta_data(pos, dir)
local npos, d1, d2, num = self:add_tube_dir(pos, dir)
if npos then
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
end
end
end
end
-- To be called after a tube/primary node is placed.
function Tube:after_place_tube(pos, placer, pointed_thing)
local preferred_pos, fdir = self:get_player_data(placer, pointed_thing)
local dir1, dir2, num_tubes = self:determine_tube_dirs(pos, preferred_pos, fdir)
@ -166,6 +204,21 @@ function Tube:after_dig_node(pos, dir1, dir2)
end
end
-- To be called after a crossing node is removed.
function Tube:after_dig_crossing_node(pos)
-- Check all valid positions
for dir = 1,6 do
if self.allowed_6d_dirs[dir] then
self:delete_tube_meta_data(pos, dir)
local npos, d1, d2, num = self:del_tube_dir(pos, dir)
if npos then
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
end
end
end
end
-- To be called after a tube node is removed.
function Tube:after_dig_tube(pos, oldnode, oldmetadata)
local dir1, dir2, num_tubes = self:decode_param2(oldnode.param2)
@ -259,7 +312,7 @@ end
function Tube:stop_pairing(pos, oldmetadata, sFormspec)
-- unpair peer node
if oldmetadata and oldmetadata.fields and oldmetadata.fields.tele_pos then
local tele_pos = P(oldmetadata.fields.tele_pos)
local tele_pos = minetest.string_to_pos(oldmetadata.fields.tele_pos)
local peer_meta = M(tele_pos)
if peer_meta then
self:delete_tube_meta_data(tele_pos, peer_meta:get_int("tube_dir"))

@ -32,6 +32,11 @@ local Tube = tubelib2.Tube:new({
"tubelib2:source", "tubelib2:teleporter"},
after_place_tube = function(pos, param2, tube_type, num_tubes)
minetest.set_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2})
minetest.sound_play({
name="default_place_node_glass"},{
gain=1,
max_hear_distance=5,
loop=false})
end,
})