mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-08-19 21:14:22 +02:00
v0.3 further improvements
This commit is contained in:
parent
d3ec70e7e0
commit
92f6d8ce55
@ -63,4 +63,4 @@ default
|
|||||||
## History
|
## History
|
||||||
- 2018-10-20 v0.1 * Tested against hyperloop elevator.
|
- 2018-10-20 v0.1 * Tested against hyperloop elevator.
|
||||||
- 2018-10-27 v0.2 * Tested against and enhanced for the hyperloop mod.
|
- 2018-10-27 v0.2 * Tested against and enhanced for the hyperloop mod.
|
||||||
|
- 2018-10-27 v0.3 * Further improvements.
|
||||||
|
13
convert.lua
13
convert.lua
@ -33,8 +33,9 @@ function Tube:convert_tube_line(pos, dir)
|
|||||||
local npos, node = self:get_next_node(pos, dir)
|
local npos, node = self:get_next_node(pos, dir)
|
||||||
local dir1, dir2, num = self.convert_tube_clbk(npos, node.name, node.param2)
|
local dir1, dir2, num = self.convert_tube_clbk(npos, node.name, node.param2)
|
||||||
if dir1 then
|
if dir1 then
|
||||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, dir1, dir2 or tubelib2.Turn180Deg[dir1], num))
|
dir2 = dir2 or tubelib2.Turn180Deg[dir1]
|
||||||
|
self.clbk_after_place_tube(
|
||||||
|
self:tube_data_to_table(npos, dir1, dir2, num), {convert = true})
|
||||||
if tubelib2.Turn180Deg[dir] == dir1 then
|
if tubelib2.Turn180Deg[dir] == dir1 then
|
||||||
return npos, dir2
|
return npos, dir2
|
||||||
else
|
else
|
||||||
@ -53,3 +54,11 @@ function Tube:convert_tube_line(pos, dir)
|
|||||||
end
|
end
|
||||||
return pos, dir, cnt
|
return pos, dir, cnt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Tube:set_pairing(pos, peer_pos)
|
||||||
|
local tube_dir1 = self:store_teleport_data(pos, peer_pos)
|
||||||
|
local tube_dir2 = self:store_teleport_data(peer_pos, pos)
|
||||||
|
|
||||||
|
self:delete_tube_meta_data(pos, tube_dir1)
|
||||||
|
self:delete_tube_meta_data(peer_pos, tube_dir2)
|
||||||
|
end
|
||||||
|
3
init.lua
3
init.lua
@ -2,5 +2,6 @@ tubelib2 = {}
|
|||||||
|
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/tube_api.lua")
|
dofile(minetest.get_modpath("tubelib2") .. "/tube_api.lua")
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/internal.lua")
|
dofile(minetest.get_modpath("tubelib2") .. "/internal.lua")
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/tube_test.lua")
|
|
||||||
dofile(minetest.get_modpath("tubelib2") .. "/convert.lua")
|
dofile(minetest.get_modpath("tubelib2") .. "/convert.lua")
|
||||||
|
-- Only for testing/demo purposes
|
||||||
|
--dofile(minetest.get_modpath("tubelib2") .. "/tube_test.lua")
|
||||||
|
66
tube_api.lua
66
tube_api.lua
@ -13,7 +13,7 @@
|
|||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- Version for compatibility checks, see readme.md/history
|
-- Version for compatibility checks, see readme.md/history
|
||||||
tubelib2.version = 0.2
|
tubelib2.version = 0.3
|
||||||
|
|
||||||
-- for lazy programmers
|
-- for lazy programmers
|
||||||
local M = minetest.get_meta
|
local M = minetest.get_meta
|
||||||
@ -32,6 +32,32 @@ local function Tbl(list)
|
|||||||
return tbl
|
return tbl
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function after_place_node(self, 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
|
||||||
|
|
||||||
|
local function after_dig_node(self, 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
|
||||||
|
|
||||||
--
|
--
|
||||||
-- API Functions
|
-- API Functions
|
||||||
--
|
--
|
||||||
@ -129,6 +155,11 @@ end
|
|||||||
|
|
||||||
-- To be called after a secondary node is placed.
|
-- To be called after a secondary node is placed.
|
||||||
function Tube:after_place_node(pos, dir1, dir2)
|
function Tube:after_place_node(pos, dir1, dir2)
|
||||||
|
if not dir1 and not dir2 then
|
||||||
|
after_place_node(self, pos)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
self:delete_tube_meta_data(pos, dir1, dir2)
|
self:delete_tube_meta_data(pos, dir1, dir2)
|
||||||
|
|
||||||
if dir1 then
|
if dir1 then
|
||||||
@ -146,19 +177,6 @@ function Tube:after_place_node(pos, dir1, dir2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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.
|
-- To be called after a tube/primary node is placed.
|
||||||
function Tube:after_place_tube(pos, placer, pointed_thing)
|
function Tube:after_place_tube(pos, placer, pointed_thing)
|
||||||
@ -191,6 +209,11 @@ end
|
|||||||
|
|
||||||
-- To be called after a secondary node is removed.
|
-- To be called after a secondary node is removed.
|
||||||
function Tube:after_dig_node(pos, dir1, dir2)
|
function Tube:after_dig_node(pos, dir1, dir2)
|
||||||
|
if not dir1 and not dir2 then
|
||||||
|
after_dig_node(self, pos)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
self:delete_tube_meta_data(pos, dir1, dir2)
|
self:delete_tube_meta_data(pos, dir1, dir2)
|
||||||
|
|
||||||
local npos, d1, d2, num = self:del_tube_dir(pos, dir1)
|
local npos, d1, d2, num = self:del_tube_dir(pos, dir1)
|
||||||
@ -204,21 +227,6 @@ function Tube:after_dig_node(pos, dir1, dir2)
|
|||||||
end
|
end
|
||||||
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.
|
-- To be called after a tube node is removed.
|
||||||
function Tube:after_dig_tube(pos, oldnode, oldmetadata)
|
function Tube:after_dig_tube(pos, oldnode, oldmetadata)
|
||||||
local dir1, dir2, num_tubes = self:decode_param2(oldnode.param2)
|
local dir1, dir2, num_tubes = self:decode_param2(oldnode.param2)
|
||||||
|
@ -30,13 +30,16 @@ local Tube = tubelib2.Tube:new({
|
|||||||
primary_node_names = {"tubelib2:tubeS", "tubelib2:tubeA"},
|
primary_node_names = {"tubelib2:tubeS", "tubelib2:tubeA"},
|
||||||
secondary_node_names = {"default:chest", "default:chest_open",
|
secondary_node_names = {"default:chest", "default:chest_open",
|
||||||
"tubelib2:source", "tubelib2:teleporter"},
|
"tubelib2:source", "tubelib2:teleporter"},
|
||||||
after_place_tube = function(pos, param2, tube_type, num_tubes)
|
after_place_tube = function(pos, param2, tube_type, num_tubes, tbl)
|
||||||
minetest.set_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2})
|
minetest.set_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2})
|
||||||
|
|
||||||
|
if not tbl.convert then
|
||||||
minetest.sound_play({
|
minetest.sound_play({
|
||||||
name="default_place_node_glass"},{
|
name="default_place_node_glass"},{
|
||||||
gain=1,
|
gain=1,
|
||||||
max_hear_distance=5,
|
max_hear_distance=5,
|
||||||
loop=false})
|
loop=false})
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user