This commit is contained in:
root 2022-01-16 20:12:39 +01:00
parent b999fa4dc5
commit 4f66b7fd4b
24 changed files with 171 additions and 112 deletions

View file

@ -33,5 +33,6 @@ Changelog:
- 1.1 - Added {can_bonemeal=1} group for special nodes - 1.1 - Added {can_bonemeal=1} group for special nodes
- 1.2 - Added support for minetest 5.0 cactus seedling, blueberry bush sapling and emergent jungle tree saplings, additional flowers and pine bush sapling. - 1.2 - Added support for minetest 5.0 cactus seedling, blueberry bush sapling and emergent jungle tree saplings, additional flowers and pine bush sapling.
- 1.3 - Ability to craft dye from mulch, bonemeal and fertiliser (thanks orbea) - 1.3 - Ability to craft dye from mulch, bonemeal and fertiliser (thanks orbea)
- 1.4 - Add support for fern saplings from plantlife mod (thanks nixnoxus)
Lucky Blocks: 6 Lucky Blocks: 6

View file

@ -7,3 +7,5 @@ technic_worldgen?
lucky_block? lucky_block?
flowers? flowers?
dye? dye?
ferns?
dryplants?

View file

@ -689,4 +689,4 @@ minetest.override_item("default:dirt", {
dofile(path .. "/mods.lua") dofile(path .. "/mods.lua")
dofile(path .. "/lucky_block.lua") dofile(path .. "/lucky_block.lua")
print (S("[MOD] bonemeal loaded")) print ("[MOD] bonemeal loaded")

View file

@ -22,8 +22,7 @@ if minetest.get_modpath("lucky_block") then
{"nod", "default:chest", 0, { {"nod", "default:chest", 0, {
{name = "bonemeal:mulch", max = 20}, {name = "bonemeal:mulch", max = 20},
{name = "bonemeal:bonemeal", max = 15}, {name = "bonemeal:bonemeal", max = 15},
{name = "bonemeal:fertiliser", max = 10}, {name = "bonemeal:fertiliser", max = 10}
}}, }}
}) })
end end

View file

@ -1,4 +1,4 @@
name = bonemeal name = bonemeal
depends = default depends = default
optional_depends = intllib, lucky_block, farming, ethereal, moretrees, technic_worldgen, flowers, dye optional_depends = intllib, lucky_block, farming, ethereal, moretrees, technic_worldgen, flowers, dye, ferns, dryplants
description = Adds bone and bonemeal giving the ability to quickly grow plants and saplings. description = Adds bone and bonemeal giving the ability to quickly grow plants and saplings.

View file

@ -3,9 +3,8 @@
if minetest.get_modpath("animalmaterials") then if minetest.get_modpath("animalmaterials") then
minetest.register_craft({ minetest.register_craft({
type = "shapeless",
output = "bonemeal:bonemeal 2", output = "bonemeal:bonemeal 2",
recipe = {"animalmaterials:bone"} recipe = {{"animalmaterials:bone"}}
}) })
end end
@ -115,13 +114,11 @@ if minetest.get_modpath("moretrees") then
{"moretrees:apple_tree_sapling", moretrees.spawn_apple_tree_object, "soil"}, {"moretrees:apple_tree_sapling", moretrees.spawn_apple_tree_object, "soil"},
{"moretrees:oak_sapling", moretrees.spawn_oak_object, "soil"}, {"moretrees:oak_sapling", moretrees.spawn_oak_object, "soil"},
{"moretrees:sequoia_sapling", moretrees.spawn_sequoia_object, "soil"}, {"moretrees:sequoia_sapling", moretrees.spawn_sequoia_object, "soil"},
--{"moretrees:birch_sapling", moretrees.spawn_birch_object, "soil"},
{"moretrees:birch_sapling", moretrees.grow_birch, "soil"}, {"moretrees:birch_sapling", moretrees.grow_birch, "soil"},
{"moretrees:palm_sapling", moretrees.spawn_palm_object, "soil"}, {"moretrees:palm_sapling", moretrees.spawn_palm_object, "soil"},
{"moretrees:palm_sapling", moretrees.spawn_palm_object, "sand"}, {"moretrees:palm_sapling", moretrees.spawn_palm_object, "sand"},
{"moretrees:date_palm_sapling", moretrees.spawn_date_palm_object, "soil"}, {"moretrees:date_palm_sapling", moretrees.spawn_date_palm_object, "soil"},
{"moretrees:date_palm_sapling", moretrees.spawn_date_palm_object, "sand"}, {"moretrees:date_palm_sapling", moretrees.spawn_date_palm_object, "sand"},
--{"moretrees:spruce_sapling", moretrees.spawn_spruce_object, "soil"},
{"moretrees:spruce_sapling", moretrees.grow_spruce, "soil"}, {"moretrees:spruce_sapling", moretrees.grow_spruce, "soil"},
{"moretrees:cedar_sapling", moretrees.spawn_cedar_object, "soil"}, {"moretrees:cedar_sapling", moretrees.spawn_cedar_object, "soil"},
{"moretrees:poplar_sapling", moretrees.spawn_poplar_object, "soil"}, {"moretrees:poplar_sapling", moretrees.spawn_poplar_object, "soil"},
@ -155,6 +152,29 @@ if minetest.get_modpath("caverealms") then
end end
local function y_func(grow_func)
return function(pos)
grow_func({x = pos.x, y = pos.y - 1, z = pos.z})
end
end
if minetest.get_modpath("ferns") then
bonemeal:add_sapling({
{"ferns:sapling_giant_tree_fern", y_func(abstract_ferns.grow_giant_tree_fern), "soil"},
{"ferns:sapling_giant_tree_fern", y_func(abstract_ferns.grow_giant_tree_fern), "sand"},
{"ferns:sapling_tree_fern", y_func(abstract_ferns.grow_tree_fern), "soil"}
})
end
if minetest.get_modpath("dryplants") then
bonemeal:add_sapling({
{"dryplants:reedmace_sapling", y_func(abstract_dryplants.grow_reedmace), "soil"}
})
end
if minetest.get_modpath("dye") then if minetest.get_modpath("dye") then
local bonemeal_dyes = { local bonemeal_dyes = {

View file

@ -508,7 +508,7 @@ function doors.register(name, def)
def.paramtype = "light" def.paramtype = "light"
def.paramtype2 = "facedir" def.paramtype2 = "facedir"
def.sunlight_propagates = true def.sunlight_propagates = true
def.use_texture_alpha = "clip" def.use_texture_alpha = def.use_texture_alpha or "clip"
def.walkable = true def.walkable = true
def.is_ground_content = false def.is_ground_content = false
def.buildable_to = false def.buildable_to = false
@ -719,7 +719,7 @@ function doors.register_trapdoor(name, def)
def.drawtype = "nodebox" def.drawtype = "nodebox"
def.paramtype = "light" def.paramtype = "light"
def.paramtype2 = "facedir" def.paramtype2 = "facedir"
def.use_texture_alpha = "clip" def.use_texture_alpha = def.use_texture_alpha or "clip"
def.is_ground_content = false def.is_ground_content = false
if def.protected then if def.protected then

View file

@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20211212", version = "20220116",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {} invis = minetest.global_exists("invisibility") and invisibility or {}
} }
@ -1002,19 +1002,19 @@ end
-- Returns true is node can deal damage to self -- Returns true is node can deal damage to self
local is_node_dangerous = function(self, nodename) function mobs:is_node_dangerous(mob_object, nodename)
if self.water_damage > 0 if mob_object.water_damage > 0
and minetest.get_item_group(nodename, "water") ~= 0 then and minetest.get_item_group(nodename, "water") ~= 0 then
return true return true
end end
if self.lava_damage > 0 if mob_object.lava_damage > 0
and minetest.get_item_group(nodename, "lava") ~= 0 then and minetest.get_item_group(nodename, "lava") ~= 0 then
return true return true
end end
if self.fire_damage > 0 if mob_object.fire_damage > 0
and minetest.get_item_group(nodename, "fire") ~= 0 then and minetest.get_item_group(nodename, "fire") ~= 0 then
return true return true
end end
@ -1026,6 +1026,10 @@ local is_node_dangerous = function(self, nodename)
return false return false
end end
local function is_node_dangerous(mob_object, nodename)
return mobs:is_node_dangerous(mob_object, nodename)
end
-- is mob facing a cliff -- is mob facing a cliff
function mob_class:is_at_cliff() function mob_class:is_at_cliff()

View file

@ -691,6 +691,12 @@ space to spawn mob [name], if so then a new position is returned for use,
otherwise nil is returned. otherwise nil is returned.
mobs:is_node_dangerous(self, nodename)
This function returns true if the node name given is harmful to the mob (self), it is
mainly used when a mob is near a node it has to avoid.
External Settings for "minetest.conf" External Settings for "minetest.conf"
------------------------------------ ------------------------------------

View file

@ -264,7 +264,8 @@ minetest.register_node("dryplants:reedmace_sapling", {
groups = { groups = {
snappy=3, snappy=3,
flammable=2, flammable=2,
attached_node=1 attached_node=1,
sapling=1,
}, },
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {

View file

@ -162,6 +162,14 @@ minetest.register_node("ferns:tree_fern_leave_big", {
}, },
drop = "", drop = "",
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
after_destruct = function(pos,oldnode)
for _, d in pairs({{x=-1,z=0},{x=1,z=0},{x=0,z=-1},{x=0,z=1}}) do
local node = minetest.get_node({x=pos.x+d.x,y=pos.y+1,z=pos.z+d.z})
if node.name == "ferns:tree_fern_leave_big" then
minetest.dig_node({x=pos.x+d.x,y=pos.y+1,z=pos.z+d.z})
end
end
end,
}) })
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
@ -271,7 +279,7 @@ minetest.register_node("ferns:sapling_giant_tree_fern", {
tiles = {"ferns_sapling_tree_fern_giant.png"}, tiles = {"ferns_sapling_tree_fern_giant.png"},
inventory_image = "ferns_sapling_tree_fern_giant.png", inventory_image = "ferns_sapling_tree_fern_giant.png",
walkable = false, walkable = false,
groups = {snappy=3,flammable=2,flora=1,attached_node=1}, groups = {snappy=3,flammable=2,flora=1,attached_node=1,sapling=1},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",

View file

@ -158,7 +158,7 @@ minetest.register_node("ferns:sapling_tree_fern", {
tiles = {"ferns_sapling_tree_fern.png"}, tiles = {"ferns_sapling_tree_fern.png"},
inventory_image = "ferns_sapling_tree_fern.png", inventory_image = "ferns_sapling_tree_fern.png",
walkable = false, walkable = false,
groups = {snappy=3,flammable=2,flora=1,attached_node=1}, groups = {snappy=3,flammable=2,flora=1,attached_node=1,sapling=1},
sounds = default.node_sound_leaves_defaults(), sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",

View file

@ -0,0 +1,3 @@
SatchelmanSam
Philipbenr
CC BY-SA 3.0

View file

@ -0,0 +1,3 @@
olli
olli
CC BY-SA 3.0

View file

@ -0,0 +1,3 @@
bab-cora
cora
CC 0 (1.0)

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -55,7 +55,7 @@ optional: intllib
## License ## License
Copyright (C) 2017-2021 Joachim Stolberg Copyright (C) 2017-2022 Joachim Stolberg
Code: Licensed under the GNU LGPL version 2.1 or later. Code: Licensed under the GNU LGPL version 2.1 or later.
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
Textures: CC0 Textures: CC0
@ -89,5 +89,6 @@ Textures: CC0
- 2020-05-31 v1.9 * Generator function 'get_tube_line' added, storage improvements - 2020-05-31 v1.9 * Generator function 'get_tube_line' added, storage improvements
- 2021-01-23 v2.0 * Add functions for easy & fast 'valid side' checking (PR #8) - 2021-01-23 v2.0 * Add functions for easy & fast 'valid side' checking (PR #8)
- 2021-05-24 v2.1 * Add API functions 'register_on_tube_update2' - 2021-05-24 v2.1 * Add API functions 'register_on_tube_update2'
- 2022-01-05 v2.2 * Extend the 'node.param2' support for all 24 possible values

View file

@ -9,7 +9,7 @@
See LICENSE.txt for more information See LICENSE.txt for more information
internal1.lua internal1.lua
First level functions behind the API First level functions behind the API
]]-- ]]--
@ -133,7 +133,7 @@ end
-------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------
-- Pairing helper function. NOT USED (see internal2.lua)!!! -- Pairing helper function. NOT USED (see internal2.lua)!!!
function Tube:store_teleport_data(pos, peer_pos) function Tube:store_teleport_data(pos, peer_pos)
local meta = M(pos) local meta = M(pos)
meta:set_string("tele_pos", S(peer_pos)) meta:set_string("tele_pos", S(peer_pos))
meta:set_string("channel", nil) meta:set_string("channel", nil)
@ -183,14 +183,14 @@ function Tube:update_after_place_tube(pos, placer, pointed_thing)
if self.valid_dirs[dir1] and self.valid_dirs[dir2] and tValidNum[num_tubes] then if self.valid_dirs[dir1] and self.valid_dirs[dir2] and tValidNum[num_tubes] then
self.clbk_after_place_tube(self:get_tube_data(pos, dir1, dir2, num_tubes)) self.clbk_after_place_tube(self:get_tube_data(pos, dir1, dir2, num_tubes))
end end
if num_tubes >= 1 then if num_tubes >= 1 then
local npos, d1, d2, num = self:add_tube_dir(pos, dir1) local npos, d1, d2, num = self:add_tube_dir(pos, dir1)
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and num < 2 then if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and num < 2 then
self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num+1)) self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num+1))
end end
end end
if num_tubes >= 2 then if num_tubes >= 2 then
local npos, d1, d2, num = self:add_tube_dir(pos, dir2) local npos, d1, d2, num = self:add_tube_dir(pos, dir2)
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and num < 2 then if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and num < 2 then
@ -198,25 +198,25 @@ function Tube:update_after_place_tube(pos, placer, pointed_thing)
end end
end end
return true, dir1, dir2, num_tubes return true, dir1, dir2, num_tubes
end end
function Tube:update_after_dig_tube(pos, param2) function Tube:update_after_dig_tube(pos, param2)
local dir1, dir2 = self:decode_param2(pos, param2) local dir1, dir2 = self:decode_param2(pos, param2)
local npos, d1, d2, num = self:del_tube_dir(pos, dir1) local npos, d1, d2, num = self:del_tube_dir(pos, dir1)
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num] then if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num] then
self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num)) self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num))
else else
dir1 = nil dir1 = nil
end end
npos, d1, d2, num = self:del_tube_dir(pos, dir2) npos, d1, d2, num = self:del_tube_dir(pos, dir2)
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num] then if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num] then
self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num)) self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num))
else else
dir2 = nil dir2 = nil
end end
return dir1, dir2 return dir1, dir2
end end
@ -229,7 +229,7 @@ function Tube:replace_nodes(pos1, pos2, dir1, dir2)
pos = get_pos(pos, dir1) pos = get_pos(pos, dir1)
end end
self.clbk_after_place_tube(self:get_tube_data(pos2, dir1, dir2, 1)) self.clbk_after_place_tube(self:get_tube_data(pos2, dir1, dir2, 1))
end end
function Tube:switch_nodes(pos, dir, state) function Tube:switch_nodes(pos, dir, state)
pos = get_pos(pos, dir) pos = get_pos(pos, dir)

View file

@ -93,7 +93,7 @@ function Tube:get_node_lvm(pos)
end end
-- Read param2 from a primary node at the given position. -- Read param2 from a primary node at the given position.
-- If dir == nil then node_pos = pos -- If dir == nil then node_pos = pos
-- Function returns param2, new_pos or nil -- Function returns param2, new_pos or nil
function Tube:get_primary_node_param2(pos, dir) function Tube:get_primary_node_param2(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -104,7 +104,7 @@ function Tube:get_primary_node_param2(pos, dir)
end end
-- Check if node at given position is a tube node -- Check if node at given position is a tube node
-- If dir == nil then node_pos = pos -- If dir == nil then node_pos = pos
-- Function returns true/false -- Function returns true/false
function Tube:is_primary_node(pos, dir) function Tube:is_primary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -113,7 +113,7 @@ function Tube:is_primary_node(pos, dir)
end end
-- Get secondary node at given position -- Get secondary node at given position
-- If dir == nil then node_pos = pos -- If dir == nil then node_pos = pos
-- Function returns node and new_pos or nil -- Function returns node and new_pos or nil
function Tube:get_secondary_node(pos, dir) function Tube:get_secondary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -124,7 +124,7 @@ function Tube:get_secondary_node(pos, dir)
end end
-- Get special registered nodes at given position -- Get special registered nodes at given position
-- If dir == nil then node_pos = pos -- If dir == nil then node_pos = pos
-- Function returns node and new_pos or nil -- Function returns node and new_pos or nil
function Tube:get_special_node(pos, dir) function Tube:get_special_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -135,7 +135,7 @@ function Tube:get_special_node(pos, dir)
end end
-- Check if node at given position is a secondary node -- Check if node at given position is a secondary node
-- If dir == nil then node_pos = pos -- If dir == nil then node_pos = pos
-- Function returns true/false -- Function returns true/false
function Tube:is_secondary_node(pos, dir) function Tube:is_secondary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -144,7 +144,7 @@ function Tube:is_secondary_node(pos, dir)
end end
-- Check if node at given position is a special node -- Check if node at given position is a special node
-- If dir == nil then node_pos = pos -- If dir == nil then node_pos = pos
-- Function returns true/false -- Function returns true/false
function Tube:is_special_node(pos, dir) function Tube:is_special_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -216,7 +216,7 @@ end
function Tube:get_tube_data(pos, dir1, dir2, num_tubes, state) function Tube:get_tube_data(pos, dir1, dir2, num_tubes, state)
local param2, tube_type = self:encode_param2(dir1, dir2, num_tubes) local param2, tube_type = self:encode_param2(dir1, dir2, num_tubes)
return pos, param2, tube_type, num_tubes, state return pos, param2, tube_type, num_tubes, state
end end
-- Return pos for a primary_node and true if num_conn < 2, else false -- Return pos for a primary_node and true if num_conn < 2, else false
function Tube:friendly_primary_node(pos, dir) function Tube:friendly_primary_node(pos, dir)
@ -238,12 +238,12 @@ function Tube:vector_to_dir(v)
end end
end end
-- Check all 6 possible positions for known nodes considering preferred_pos -- Check all 6 possible positions for known nodes considering preferred_pos
-- and the players fdir and return dir1, dir2 and the number of tubes to connect to (0..2). -- and the players fdir and return dir1, dir2 and the number of tubes to connect to (0..2).
function Tube:determine_tube_dirs(pos, preferred_pos, fdir) function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
local tbl = {} local tbl = {}
local allowed = table.copy(self.valid_dirs) local allowed = table.copy(self.valid_dirs)
-- If the node at players "prefered position" is a tube, -- If the node at players "prefered position" is a tube,
-- then the other side of the new tube shall point to the player. -- then the other side of the new tube shall point to the player.
if preferred_pos then if preferred_pos then
@ -282,7 +282,7 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
elseif #tbl >= 2 then elseif #tbl >= 2 then
return tbl[1], tbl[2], 2 return tbl[1], tbl[2], 2
end end
-- Check for secondary nodes (chests and so on) -- Check for secondary nodes (chests and so on)
for dir = 1,6 do for dir = 1,6 do
if allowed[dir] then if allowed[dir] then
@ -301,8 +301,8 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
end end
end end
end end
-- player pointed to an unknown node to force the tube orientation? -- player pointed to an unknown node to force the tube orientation?
if preferred_pos and fdir then if preferred_pos and fdir then
if tbl[1] == Turn180Deg[fdir] and allowed[fdir] then if tbl[1] == Turn180Deg[fdir] and allowed[fdir] then
tbl[2] = fdir tbl[2] = fdir
@ -310,7 +310,7 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
tbl[2] = Turn180Deg[fdir] tbl[2] = Turn180Deg[fdir]
end end
end end
-- dir1, dir2 still unknown? -- dir1, dir2 still unknown?
if fdir then if fdir then
if #tbl == 0 and allowed[Turn180Deg[fdir]] then if #tbl == 0 and allowed[Turn180Deg[fdir]] then
@ -324,14 +324,14 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
end end
if #tbl >= 2 and tbl[1] ~= tbl[2] then if #tbl >= 2 and tbl[1] ~= tbl[2] then
local num_tubes = (self:connected(pos, tbl[1]) and 1 or 0) + local num_tubes = (self:connected(pos, tbl[1]) and 1 or 0) +
(self:connected(pos, tbl[2]) and 1 or 0) (self:connected(pos, tbl[2]) and 1 or 0)
return tbl[1], tbl[2], math.min(2, num_tubes) return tbl[1], tbl[2], math.min(2, num_tubes)
end end
end end
-- Determine a tube side without connection, increment the number of connections -- Determine a tube side without connection, increment the number of connections
-- and return the new data to be able to update the node: -- and return the new data to be able to update the node:
-- new_pos, dir1, dir2, num_connections (1, 2) -- new_pos, dir1, dir2, num_connections (1, 2)
function Tube:add_tube_dir(pos, dir) function Tube:add_tube_dir(pos, dir)
local param2, npos = self:get_primary_node_param2(pos, dir) local param2, npos = self:get_primary_node_param2(pos, dir)
@ -359,7 +359,7 @@ function Tube:add_tube_dir(pos, dir)
end end
-- Decrement the number of tube connections -- Decrement the number of tube connections
-- and return the new data to be able to update the node: -- and return the new data to be able to update the node:
-- new_pos, dir1, dir2, num_connections (0, 1) -- new_pos, dir1, dir2, num_connections (0, 1)
function Tube:del_tube_dir(pos, dir) function Tube:del_tube_dir(pos, dir)
local param2, npos = self:get_primary_node_param2(pos, dir) local param2, npos = self:get_primary_node_param2(pos, dir)
@ -372,9 +372,9 @@ function Tube:del_tube_dir(pos, dir)
end end
end end
end end
-- Pairing helper function -- Pairing helper function
function Tube:store_teleport_data(pos, peer_pos) function Tube:store_teleport_data(pos, peer_pos)
local meta = M(pos) local meta = M(pos)
meta:set_string("tele_pos", S(peer_pos)) meta:set_string("tele_pos", S(peer_pos))
meta:set_string("channel", nil) meta:set_string("channel", nil)
@ -409,7 +409,7 @@ function Tube:dbg_out()
end end
end end
end end
-- Walk to the end of the tube line and return pos and outdir of both head tube nodes. -- Walk to the end of the tube line and return pos and outdir of both head tube nodes.
-- If no tube is available, return nil -- If no tube is available, return nil
function Tube:walk_tube_line(pos, dir) function Tube:walk_tube_line(pos, dir)
@ -429,4 +429,4 @@ function Tube:walk_tube_line(pos, dir)
end end
end end
return table.copy(pos), dir, 0 return table.copy(pos), dir, 0
end end

View file

@ -29,7 +29,7 @@ local function update_mod_storage()
storage:set_string(k, minetest.serialize(v)) storage:set_string(k, minetest.serialize(v))
MemStore[k] = nil -- remove from memory MemStore[k] = nil -- remove from memory
end end
end end
-- run every 10 minutes -- run every 10 minutes
minetest.after(600, update_mod_storage) minetest.after(600, update_mod_storage)
end end
@ -37,7 +37,7 @@ end
minetest.register_on_shutdown(function() minetest.register_on_shutdown(function()
for k,v in pairs(MemStore) do for k,v in pairs(MemStore) do
storage:set_string(k, minetest.serialize(v)) storage:set_string(k, minetest.serialize(v))
end end
end) end)
minetest.after(600, update_mod_storage) minetest.after(600, update_mod_storage)
@ -52,14 +52,14 @@ local function empty_block(block)
end end
return empty return empty
end end
minetest.after(1, function() minetest.after(1, function()
local tbl = storage:to_table() local tbl = storage:to_table()
for k,v in pairs(tbl.fields) do for k,v in pairs(tbl.fields) do
if empty_block(v) then if empty_block(v) then
storage:set_string(k, "") storage:set_string(k, "")
end end
end end
end) end)
-- --
@ -81,7 +81,7 @@ local function new_node(block, node_key)
end end
local function unlock(pos) local function unlock(pos)
local block_key = math.floor((pos.z+32768)/16)*4096*4096 + local block_key = math.floor((pos.z+32768)/16)*4096*4096 +
math.floor((pos.y+32768)/16)*4096 + math.floor((pos.x+32768)/16) math.floor((pos.y+32768)/16)*4096 + math.floor((pos.x+32768)/16)
local node_key = (pos.z%16)*16*16 + (pos.y%16)*16 + (pos.x%16) local node_key = (pos.z%16)*16*16 + (pos.y%16)*16 + (pos.x%16)
local block = MemStore[block_key] or new_block(block_key) local block = MemStore[block_key] or new_block(block_key)

View file

@ -13,7 +13,7 @@
]]-- ]]--
-- Version for compatibility checks, see readme.md/history -- Version for compatibility checks, see readme.md/history
tubelib2.version = 2.1 tubelib2.version = 2.2
-- for lazy programmers -- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
@ -31,23 +31,31 @@ function tubelib2.dir_to_string(dir)
end end
-- Relative directions, dependant on orientation (param2) -- Relative directions, dependant on orientation (param2)
local DirToSide = {"B", "R", "F", "L", "D", "U"} local DirToSide = {
-- param2 (0 to 23)
{[0]="B","L","F","R", "U","U","U","U", "D","D","D","D", "B","L","F","R", "B","L","F","R", "B","L","F","R",}, -- dir = 1
{[0]="R","B","L","F", "R","B","L","F", "R","B","L","F", "U","U","U","U", "D","D","D","D", "L","F","R","B",}, -- dir = 2
{[0]="F","R","B","L", "D","D","D","D", "U","U","U","U", "F","R","B","L", "F","R","B","L", "F","R","B","L",}, -- dir = 3
{[0]="L","F","R","B", "L","F","R","B", "L","F","R","B", "D","D","D","D", "U","U","U","U", "R","B","L","F",}, -- dir = 4
{[0]="D","D","D","D", "B","L","F","R", "F","R","B","L", "R","B","L","F", "L","F","R","B", "U","U","U","U",}, -- dir = 5
{[0]="U","U","U","U", "F","R","B","L", "B","L","F","R", "L","F","R","B", "R","B","L","F", "D","D","D","D",}, -- dir = 6
}
function tubelib2.dir_to_side(dir, param2) local SideToDir = {B={}, R={}, F={}, L={}, D={}, U={}}
if dir < 5 then
dir = (((dir - 1) - (param2 % 4)) % 4) + 1 for param2 = 0,23 do
for dir = 1,6 do
local side = DirToSide[dir][param2]
SideToDir[side][param2] = dir
end end
return DirToSide[dir]
end end
local SideToDir = {B=1, R=2, F=3, L=4, D=5, U=6} function tubelib2.dir_to_side(dir, param2)
return DirToSide[dir][param2]
end
function tubelib2.side_to_dir(side, param2) function tubelib2.side_to_dir(side, param2)
local dir = SideToDir[side] return SideToDir[side][param2]
if dir < 5 then
dir = (((dir - 1) + (param2 % 4)) % 4) + 1
end
return dir
end end
@ -92,7 +100,7 @@ local function update1(self, pos, dir)
local fpos,fdir = self:walk_tube_line(pos, dir) local fpos,fdir = self:walk_tube_line(pos, dir)
self:infotext(get_pos(pos, dir), fpos) self:infotext(get_pos(pos, dir), fpos)
self:infotext(fpos, get_pos(pos, dir)) self:infotext(fpos, get_pos(pos, dir))
-- Translate pos/dir pointing to the secondary node into -- Translate pos/dir pointing to the secondary node into
-- spos/sdir of the secondary node pointing to the tube. -- spos/sdir of the secondary node pointing to the tube.
if fpos and fdir then if fpos and fdir then
local spos, sdir = get_pos(fpos,fdir), Turn180Deg[fdir] local spos, sdir = get_pos(fpos,fdir), Turn180Deg[fdir]
@ -113,11 +121,11 @@ local function update2(self, pos1, dir1, pos2, dir2)
self:update_after_dig_tube(pos1, param2) self:update_after_dig_tube(pos1, param2)
M(get_pos(pos1, dir1)):set_string("infotext", I("Maximum length reached!")) M(get_pos(pos1, dir1)):set_string("infotext", I("Maximum length reached!"))
M(get_pos(pos1, dir2)):set_string("infotext", I("Maximum length reached!")) M(get_pos(pos1, dir2)):set_string("infotext", I("Maximum length reached!"))
return false return false
end end
self:infotext(fpos1, fpos2) self:infotext(fpos1, fpos2)
self:infotext(fpos2, fpos1) self:infotext(fpos2, fpos1)
-- Translate fpos/fdir pointing to the secondary node into -- Translate fpos/fdir pointing to the secondary node into
-- spos/sdir of the secondary node pointing to the tube. -- spos/sdir of the secondary node pointing to the tube.
local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1] local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1]
local spos2, sdir2 = get_pos(fpos2,fdir2), Turn180Deg[fdir2] local spos2, sdir2 = get_pos(fpos2,fdir2), Turn180Deg[fdir2]
@ -136,7 +144,7 @@ local function update3(self, pos, dir1, dir2)
local fpos2,fdir2,cnt2 = self:walk_tube_line(pos, dir2) local fpos2,fdir2,cnt2 = self:walk_tube_line(pos, dir2)
self:infotext(fpos1, fpos2) self:infotext(fpos1, fpos2)
self:infotext(fpos2, fpos1) self:infotext(fpos2, fpos1)
-- Translate fpos/fdir pointing to the secondary node into -- Translate fpos/fdir pointing to the secondary node into
-- spos/sdir of the secondary node pointing to the tube. -- spos/sdir of the secondary node pointing to the tube.
if fpos1 and fpos2 and fdir1 and fdir2 then if fpos1 and fpos2 and fdir1 and fdir2 then
local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1] local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1]
@ -161,7 +169,7 @@ local function update_secondary_nodes_after_node_placed(self, pos, dirs)
if self.force_to_use_tubes then if self.force_to_use_tubes then
tmp, npos = self:get_special_node(pos, dir) tmp, npos = self:get_special_node(pos, dir)
else else
tmp, npos = self:get_secondary_node(pos, dir) tmp, npos = self:get_secondary_node(pos, dir)
end end
if npos then if npos then
self:update_secondary_node(npos, Turn180Deg[dir], pos, dir) self:update_secondary_node(npos, Turn180Deg[dir], pos, dir)
@ -178,7 +186,7 @@ local function update_secondary_nodes_after_node_dug(self, pos, dirs)
if self.force_to_use_tubes then if self.force_to_use_tubes then
tmp, npos = self:get_special_node(pos, dir) tmp, npos = self:get_special_node(pos, dir)
else else
tmp, npos = self:get_secondary_node(pos, dir) tmp, npos = self:get_secondary_node(pos, dir)
end end
if npos then if npos then
self:del_from_cache(npos, Turn180Deg[dir]) self:del_from_cache(npos, Turn180Deg[dir])
@ -196,18 +204,18 @@ end
function Tube:new(attr) function Tube:new(attr)
local o = { local o = {
dirs_to_check = attr.dirs_to_check or {1,2,3,4,5,6}, dirs_to_check = attr.dirs_to_check or {1,2,3,4,5,6},
max_tube_length = attr.max_tube_length or 1000, max_tube_length = attr.max_tube_length or 1000,
primary_node_names = Tbl(attr.primary_node_names or {}), primary_node_names = Tbl(attr.primary_node_names or {}),
secondary_node_names = Tbl(attr.secondary_node_names or {}), secondary_node_names = Tbl(attr.secondary_node_names or {}),
valid_node_contact_sides = {}, valid_node_contact_sides = {},
show_infotext = attr.show_infotext or false, show_infotext = attr.show_infotext or false,
force_to_use_tubes = attr.force_to_use_tubes or false, force_to_use_tubes = attr.force_to_use_tubes or false,
clbk_after_place_tube = attr.after_place_tube, clbk_after_place_tube = attr.after_place_tube,
tube_type = attr.tube_type or "unknown", tube_type = attr.tube_type or "unknown",
pairingList = {}, -- teleporting nodes pairingList = {}, -- teleporting nodes
connCache = {}, -- connection cache {pos1 = {dir1 = {pos2 = pos2, dir2 = dir2},...} connCache = {}, -- connection cache {pos1 = {dir1 = {pos2 = pos2, dir2 = dir2},...}
special_node_names = {}, -- use add_special_node_names() to register nodes special_node_names = {}, -- use add_special_node_names() to register nodes
debug_info = attr.debug_info, -- debug_info(pos, text) debug_info = attr.debug_info, -- debug_info(pos, text)
} }
o.valid_dirs = Tbl(o.dirs_to_check) o.valid_dirs = Tbl(o.dirs_to_check)
setmetatable(o, self) setmetatable(o, self)
@ -234,7 +242,7 @@ local function invert_booleans(tab)
end end
return inversion return inversion
end end
local valid_sides_default_true = Tbl(DirToSide) local valid_sides_default_true = Tbl({"B", "R", "F", "L", "D", "U"})
local valid_sides_default_false = invert_booleans(valid_sides_default_true) local valid_sides_default_false = invert_booleans(valid_sides_default_true)
local function complete_valid_sides(valid_sides, existing_defaults) local function complete_valid_sides(valid_sides, existing_defaults)
local valid_sides_complete = {} local valid_sides_complete = {}
@ -368,13 +376,13 @@ end
function Tube:after_dig_tube(pos, oldnode) function Tube:after_dig_tube(pos, oldnode)
-- [s1][f1]----[n1] x [n2]-----[f2][s2] -- [s1][f1]----[n1] x [n2]-----[f2][s2]
-- s..secondary, f..far, n..near, x..node to be removed -- s..secondary, f..far, n..near, x..node to be removed
-- update tubes -- update tubes
if oldnode and oldnode.param2 then if oldnode and oldnode.param2 then
local dir1, dir2 = self:update_after_dig_tube(pos, oldnode.param2) local dir1, dir2 = self:update_after_dig_tube(pos, oldnode.param2)
if dir1 then update1(self, pos, dir1) end if dir1 then update1(self, pos, dir1) end
if dir2 then update1(self, pos, dir2) end if dir2 then update1(self, pos, dir2) end
-- Update secondary nodes, if right beside -- Update secondary nodes, if right beside
dir1, dir2 = self:decode_param2(pos, oldnode.param2) dir1, dir2 = self:decode_param2(pos, oldnode.param2)
local npos1,ndir1 = get_pos(pos, dir1),Turn180Deg[dir1] local npos1,ndir1 = get_pos(pos, dir1),Turn180Deg[dir1]
@ -395,7 +403,7 @@ function Tube:get_connected_node_pos(pos, dir)
if self.connCache[key] and self.connCache[key][dir] then if self.connCache[key] and self.connCache[key][dir] then
local item = self.connCache[key][dir] local item = self.connCache[key][dir]
return item.pos2, Turn180Deg[item.dir2] return item.pos2, Turn180Deg[item.dir2]
end end
local fpos,fdir = self:walk_tube_line(pos, dir) local fpos,fdir = self:walk_tube_line(pos, dir)
local spos = get_pos(fpos,fdir) local spos = get_pos(fpos,fdir)
self:add_to_cache(pos, dir, spos, Turn180Deg[fdir]) self:add_to_cache(pos, dir, spos, Turn180Deg[fdir])
@ -405,7 +413,7 @@ end
-- Check if node at given position is a tubelib2 compatible node, -- Check if node at given position is a tubelib2 compatible node,
-- able to receive and/or deliver items. -- able to receive and/or deliver items.
-- If dir == nil then node_pos = pos -- If dir == nil then node_pos = pos
-- Function returns the result (true/false), new pos, and the node -- Function returns the result (true/false), new pos, and the node
function Tube:compatible_node(pos, dir) function Tube:compatible_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -497,14 +505,14 @@ end
-- Used by chat commands, when tubes are placed e.g. via WorldEdit -- Used by chat commands, when tubes are placed e.g. via WorldEdit
function Tube:replace_tube_line(pos1, pos2) function Tube:replace_tube_line(pos1, pos2)
if pos1 and pos2 and not vector.equals(pos1, pos2) then if pos1 and pos2 and not vector.equals(pos1, pos2) then
local check = (((pos1.x == pos2.x) and 1) or 0) + local check = (((pos1.x == pos2.x) and 1) or 0) +
(((pos1.y == pos2.y) and 1) or 0) + (((pos1.y == pos2.y) and 1) or 0) +
(((pos1.z == pos2.z) and 1) or 0) (((pos1.z == pos2.z) and 1) or 0)
if check == 2 then if check == 2 then
local v = vector.direction(pos1, pos2) local v = vector.direction(pos1, pos2)
local dir1 = self:vector_to_dir(v) local dir1 = self:vector_to_dir(v)
local dir2 = Turn180Deg[dir1] local dir2 = Turn180Deg[dir1]
self:replace_nodes(pos1, pos2, dir1, dir2) self:replace_nodes(pos1, pos2, dir1, dir2)
update3(self, pos1, dir1, dir2) update3(self, pos1, dir1, dir2)
end end
@ -532,4 +540,4 @@ function Tube:get_tube_line(pos, dir)
end end
end, self, 0 end, self, 0
end end
end end

View file

@ -9,7 +9,7 @@
See LICENSE.txt for more information See LICENSE.txt for more information
tube_test.lua tube_test.lua
THIS FILE IS ONLY FOR TESTING PURPOSES THIS FILE IS ONLY FOR TESTING PURPOSES
]]-- ]]--
@ -62,10 +62,10 @@ local Tube = tubelib2.Tube:new({
-- dirs_to_check = {1,2,3,4}, -- horizontal only -- dirs_to_check = {1,2,3,4}, -- horizontal only
-- dirs_to_check = {5,6}, -- vertical only -- dirs_to_check = {5,6}, -- vertical only
dirs_to_check = {1,2,3,4,5,6}, dirs_to_check = {1,2,3,4,5,6},
max_tube_length = 10, max_tube_length = 10,
show_infotext = true, show_infotext = true,
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:junction", "tubelib2:teleporter"}, "tubelib2:source", "tubelib2:junction", "tubelib2:teleporter"},
after_place_tube = function(pos, param2, tube_type, num_tubes, tbl) after_place_tube = function(pos, param2, tube_type, num_tubes, tbl)
minetest.swap_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2}) minetest.swap_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2})
@ -102,7 +102,7 @@ minetest.register_node("tubelib2:tubeS", {
"tubelib2_hole.png", "tubelib2_hole.png",
"tubelib2_hole.png", "tubelib2_hole.png",
}, },
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
--local t = minetest.get_us_time() --local t = minetest.get_us_time()
if not Tube:after_place_tube(pos, placer, pointed_thing) then if not Tube:after_place_tube(pos, placer, pointed_thing) then
@ -112,11 +112,11 @@ minetest.register_node("tubelib2:tubeS", {
--print("place time", minetest.get_us_time() - t) --print("place time", minetest.get_us_time() - t)
return false return false
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Tube:after_dig_tube(pos, oldnode, oldmetadata) Tube:after_dig_tube(pos, oldnode, oldmetadata)
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
@ -143,11 +143,11 @@ minetest.register_node("tubelib2:tubeA", {
"tubelib2_tube.png", "tubelib2_tube.png",
"tubelib2_hole.png", "tubelib2_hole.png",
}, },
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Tube:after_dig_tube(pos, oldnode, oldmetadata) Tube:after_dig_tube(pos, oldnode, oldmetadata)
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
@ -174,7 +174,7 @@ local function push_item(pos)
--print("on_timer: dest_pos="..S(dest_pos).." dest_dir="..dest_dir) --print("on_timer: dest_pos="..S(dest_pos).." dest_dir="..dest_dir)
local inv = minetest.get_inventory({type="node", pos=dest_pos}) local inv = minetest.get_inventory({type="node", pos=dest_pos})
local stack = ItemStack("default:dirt") local stack = ItemStack("default:dirt")
if on_push_item then if on_push_item then
return on_push_item(dest_pos, dest_dir, stack) return on_push_item(dest_pos, dest_dir, stack)
elseif inv then elseif inv then
@ -204,7 +204,7 @@ minetest.register_node("tubelib2:source", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local tube_dir = ((minetest.dir_to_facedir(placer:get_look_dir()) + 2) % 4) + 1 local tube_dir = ((minetest.dir_to_facedir(placer:get_look_dir()) + 2) % 4) + 1
M(pos):set_int("tube_dir", tube_dir) M(pos):set_int("tube_dir", tube_dir)
Tube:after_place_node(pos, {tube_dir}) Tube:after_place_node(pos, {tube_dir})
minetest.get_node_timer(pos):start(2) minetest.get_node_timer(pos):start(2)
end, end,
@ -212,14 +212,14 @@ minetest.register_node("tubelib2:source", {
local tube_dir = tonumber(oldmetadata.fields.tube_dir or 0) local tube_dir = tonumber(oldmetadata.fields.tube_dir or 0)
Tube:after_dig_node(pos, {tube_dir}) Tube:after_dig_node(pos, {tube_dir})
end, end,
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
if not push_item(pos) then if not push_item(pos) then
print("push_item error") print("push_item error")
end end
return true return true
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
on_rotate = screwdriver.disallow, -- important! on_rotate = screwdriver.disallow, -- important!
paramtype = "light", paramtype = "light",
@ -245,7 +245,7 @@ minetest.register_node("tubelib2:junction", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Tube:after_dig_node(pos) Tube:after_dig_node(pos)
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
on_rotate = screwdriver.disallow, -- important! on_rotate = screwdriver.disallow, -- important!
paramtype = "light", paramtype = "light",
@ -264,7 +264,7 @@ local sFormspec = "size[7.5,3]"..
"field[0.5,1;7,1;channel;Enter channel string;]" .. "field[0.5,1;7,1;channel;Enter channel string;]" ..
"button_exit[2,2;3,1;exit;Save]" "button_exit[2,2;3,1;exit;Save]"
local function store_connection(pos, peer_pos) local function store_connection(pos, peer_pos)
local meta = M(pos) local meta = M(pos)
meta:set_string("peer_pos", P2S(peer_pos)) meta:set_string("peer_pos", P2S(peer_pos))
meta:set_string("channel", "") meta:set_string("channel", "")
@ -332,7 +332,7 @@ minetest.register_node("tubelib2:teleporter", {
pairing(pos, fields.channel) pairing(pos, fields.channel)
end end
end, end,
on_push_item = function(pos, dir, item) on_push_item = function(pos, dir, item)
local tube_dir = M(pos):get_int("tube_dir") local tube_dir = M(pos):get_int("tube_dir")
if dir == tubelib2.Turn180Deg[tube_dir] then if dir == tubelib2.Turn180Deg[tube_dir] then
@ -343,13 +343,13 @@ minetest.register_node("tubelib2:teleporter", {
end end
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
stop_pairing(pos, oldmetadata) stop_pairing(pos, oldmetadata)
local tube_dir = tonumber(oldmetadata.fields.tube_dir or 0) local tube_dir = tonumber(oldmetadata.fields.tube_dir or 0)
Tube:after_dig_node(pos, {tube_dir}) Tube:after_dig_node(pos, {tube_dir})
end, end,
paramtype2 = "facedir", -- important! paramtype2 = "facedir", -- important!
on_rotate = screwdriver.disallow, -- important! on_rotate = screwdriver.disallow, -- important!
paramtype = "light", paramtype = "light",
@ -363,7 +363,7 @@ minetest.register_node("tubelib2:teleporter", {
-- Tool -- Tool
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
local function read_param2(pos, player) local function read_param2(pos, player)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local dir1, dir2, num_tubes = Tube:decode_param2(pos, node.param2) local dir1, dir2, num_tubes = Tube:decode_param2(pos, node.param2)
minetest.chat_send_player(player:get_player_name(), "[Tubelib2] pos="..P2S(pos)..", dir1="..dir1..", dir2="..dir2..", num_tubes="..num_tubes) minetest.chat_send_player(player:get_player_name(), "[Tubelib2] pos="..P2S(pos)..", dir1="..dir1..", dir2="..dir2..", num_tubes="..num_tubes)
end end
@ -378,7 +378,7 @@ local function remove_tube(itemstack, placer, pointed_thing)
end end
else else
local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1 local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
minetest.chat_send_player(placer:get_player_name(), minetest.chat_send_player(placer:get_player_name(),
"[Tool Help] dir="..dir.."\n".. "[Tool Help] dir="..dir.."\n"..
" left: remove node\n".. " left: remove node\n"..
" right: repair tube line\n") " right: repair tube line\n")
@ -399,7 +399,7 @@ end
-- end -- end
-- else -- else
-- local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1 -- local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
-- minetest.chat_send_player(placer:get_player_name(), -- minetest.chat_send_player(placer:get_player_name(),
-- "[Tool Help] dir="..dir.."\n".. -- "[Tool Help] dir="..dir.."\n"..
-- " left: remove node\n".. -- " left: remove node\n"..
-- " right: repair tube line\n") -- " right: repair tube line\n")
@ -411,22 +411,22 @@ local function repair_tube(itemstack, placer, pointed_thing)
local pos = pointed_thing.under local pos = pointed_thing.under
local _, _, fpos1, fpos2, _, _, cnt1, cnt2 = Tube:tool_repair_tube(pos) local _, _, fpos1, fpos2, _, _, cnt1, cnt2 = Tube:tool_repair_tube(pos)
local length = cnt1 + cnt2 local length = cnt1 + cnt2
local s = "Tube from " .. P2S(fpos1) .. " to " .. P2S(fpos2) .. ". Lenght = " .. length local s = "Tube from " .. P2S(fpos1) .. " to " .. P2S(fpos2) .. ". Lenght = " .. length
minetest.chat_send_player(placer:get_player_name(), s) minetest.chat_send_player(placer:get_player_name(), s)
if length > Tube.max_tube_length then if length > Tube.max_tube_length then
local s = string.char(0x1b) .. "(c@#ff0000)" .. "Tube length error!" local s = string.char(0x1b) .. "(c@#ff0000)" .. "Tube length error!"
minetest.chat_send_player(placer:get_player_name(), s) minetest.chat_send_player(placer:get_player_name(), s)
end end
minetest.sound_play("carts_cart_new", { minetest.sound_play("carts_cart_new", {
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 5}) max_hear_distance = 5})
else else
local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1 local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
minetest.chat_send_player(placer:get_player_name(), minetest.chat_send_player(placer:get_player_name(),
"[Tool Help] dir="..dir.."\n".. "[Tool Help] dir="..dir.."\n"..
" left: remove node\n".. " left: remove node\n"..
" right: repair tube line\n") " right: repair tube line\n")