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.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.4 - Add support for fern saplings from plantlife mod (thanks nixnoxus)
Lucky Blocks: 6

View file

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

View file

@ -689,4 +689,4 @@ minetest.override_item("default:dirt", {
dofile(path .. "/mods.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, {
{name = "bonemeal:mulch", max = 20},
{name = "bonemeal:bonemeal", max = 15},
{name = "bonemeal:fertiliser", max = 10},
}},
{name = "bonemeal:fertiliser", max = 10}
}}
})
end

View file

@ -1,4 +1,4 @@
name = bonemeal
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.

View file

@ -3,9 +3,8 @@
if minetest.get_modpath("animalmaterials") then
minetest.register_craft({
type = "shapeless",
output = "bonemeal:bonemeal 2",
recipe = {"animalmaterials:bone"}
recipe = {{"animalmaterials:bone"}}
})
end
@ -115,13 +114,11 @@ if minetest.get_modpath("moretrees") then
{"moretrees:apple_tree_sapling", moretrees.spawn_apple_tree_object, "soil"},
{"moretrees:oak_sapling", moretrees.spawn_oak_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:palm_sapling", moretrees.spawn_palm_object, "soil"},
{"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, "sand"},
--{"moretrees:spruce_sapling", moretrees.spawn_spruce_object, "soil"},
{"moretrees:spruce_sapling", moretrees.grow_spruce, "soil"},
{"moretrees:cedar_sapling", moretrees.spawn_cedar_object, "soil"},
{"moretrees:poplar_sapling", moretrees.spawn_poplar_object, "soil"},
@ -155,6 +152,29 @@ if minetest.get_modpath("caverealms") then
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
local bonemeal_dyes = {

View file

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

View file

@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20211212",
version = "20220116",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -1002,19 +1002,19 @@ end
-- 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
return true
end
if self.lava_damage > 0
if mob_object.lava_damage > 0
and minetest.get_item_group(nodename, "lava") ~= 0 then
return true
end
if self.fire_damage > 0
if mob_object.fire_damage > 0
and minetest.get_item_group(nodename, "fire") ~= 0 then
return true
end
@ -1026,6 +1026,10 @@ local is_node_dangerous = function(self, nodename)
return false
end
local function is_node_dangerous(mob_object, nodename)
return mobs:is_node_dangerous(mob_object, nodename)
end
-- is mob facing a 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.
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"
------------------------------------

View file

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

View file

@ -162,6 +162,14 @@ minetest.register_node("ferns:tree_fern_leave_big", {
},
drop = "",
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"},
inventory_image = "ferns_sapling_tree_fern_giant.png",
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(),
selection_box = {
type = "fixed",

View file

@ -158,7 +158,7 @@ minetest.register_node("ferns:sapling_tree_fern", {
tiles = {"ferns_sapling_tree_fern.png"},
inventory_image = "ferns_sapling_tree_fern.png",
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(),
selection_box = {
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
Copyright (C) 2017-2021 Joachim Stolberg
Copyright (C) 2017-2022 Joachim Stolberg
Code: Licensed under the GNU LGPL version 2.1 or later.
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
Textures: CC0
@ -89,5 +89,6 @@ Textures: CC0
- 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-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
internal1.lua
First level functions behind the API
]]--
@ -133,7 +133,7 @@ end
--------------------------------------------------------------------------------------
-- 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)
meta:set_string("tele_pos", S(peer_pos))
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
self.clbk_after_place_tube(self:get_tube_data(pos, dir1, dir2, num_tubes))
end
if num_tubes >= 1 then
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
self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num+1))
end
end
if num_tubes >= 2 then
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
@ -198,25 +198,25 @@ function Tube:update_after_place_tube(pos, placer, pointed_thing)
end
end
return true, dir1, dir2, num_tubes
end
end
function Tube:update_after_dig_tube(pos, param2)
local dir1, dir2 = self:decode_param2(pos, param2)
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
self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num))
else
dir1 = nil
end
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
self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num))
else
dir2 = nil
end
return dir1, dir2
end
@ -229,7 +229,7 @@ function Tube:replace_nodes(pos1, pos2, dir1, dir2)
pos = get_pos(pos, dir1)
end
self.clbk_after_place_tube(self:get_tube_data(pos2, dir1, dir2, 1))
end
end
function Tube:switch_nodes(pos, dir, state)
pos = get_pos(pos, dir)

View file

@ -93,7 +93,7 @@ function Tube:get_node_lvm(pos)
end
-- 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 Tube:get_primary_node_param2(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -104,7 +104,7 @@ function Tube:get_primary_node_param2(pos, dir)
end
-- 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 Tube:is_primary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -113,7 +113,7 @@ function Tube:is_primary_node(pos, dir)
end
-- 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 Tube:get_secondary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -124,7 +124,7 @@ function Tube:get_secondary_node(pos, dir)
end
-- 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 Tube:get_special_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -135,7 +135,7 @@ function Tube:get_special_node(pos, dir)
end
-- 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 Tube:is_secondary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0])
@ -144,7 +144,7 @@ function Tube:is_secondary_node(pos, dir)
end
-- 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 Tube:is_special_node(pos, dir)
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)
local param2, tube_type = self:encode_param2(dir1, dir2, num_tubes)
return pos, param2, tube_type, num_tubes, state
end
end
-- Return pos for a primary_node and true if num_conn < 2, else false
function Tube:friendly_primary_node(pos, dir)
@ -238,12 +238,12 @@ function Tube:vector_to_dir(v)
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).
function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
local tbl = {}
local allowed = table.copy(self.valid_dirs)
-- If the node at players "prefered position" is a tube,
-- then the other side of the new tube shall point to the player.
if preferred_pos then
@ -282,7 +282,7 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
elseif #tbl >= 2 then
return tbl[1], tbl[2], 2
end
-- Check for secondary nodes (chests and so on)
for dir = 1,6 do
if allowed[dir] then
@ -301,8 +301,8 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
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 tbl[1] == Turn180Deg[fdir] and allowed[fdir] then
tbl[2] = fdir
@ -310,7 +310,7 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
tbl[2] = Turn180Deg[fdir]
end
end
-- dir1, dir2 still unknown?
if fdir then
if #tbl == 0 and allowed[Turn180Deg[fdir]] then
@ -324,14 +324,14 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
end
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)
return tbl[1], tbl[2], math.min(2, num_tubes)
end
end
-- 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)
function Tube:add_tube_dir(pos, dir)
local param2, npos = self:get_primary_node_param2(pos, dir)
@ -359,7 +359,7 @@ function Tube:add_tube_dir(pos, dir)
end
-- 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)
function Tube:del_tube_dir(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
-- Pairing helper function
function Tube:store_teleport_data(pos, peer_pos)
function Tube:store_teleport_data(pos, peer_pos)
local meta = M(pos)
meta:set_string("tele_pos", S(peer_pos))
meta:set_string("channel", nil)
@ -409,7 +409,7 @@ function Tube:dbg_out()
end
end
end
-- 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
function Tube:walk_tube_line(pos, dir)
@ -429,4 +429,4 @@ function Tube:walk_tube_line(pos, dir)
end
end
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))
MemStore[k] = nil -- remove from memory
end
end
end
-- run every 10 minutes
minetest.after(600, update_mod_storage)
end
@ -37,7 +37,7 @@ end
minetest.register_on_shutdown(function()
for k,v in pairs(MemStore) do
storage:set_string(k, minetest.serialize(v))
end
end
end)
minetest.after(600, update_mod_storage)
@ -52,14 +52,14 @@ local function empty_block(block)
end
return empty
end
minetest.after(1, function()
local tbl = storage:to_table()
for k,v in pairs(tbl.fields) do
if empty_block(v) then
storage:set_string(k, "")
end
end
end
end)
--
@ -81,7 +81,7 @@ local function new_node(block, node_key)
end
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)
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)

View file

@ -13,7 +13,7 @@
]]--
-- Version for compatibility checks, see readme.md/history
tubelib2.version = 2.1
tubelib2.version = 2.2
-- for lazy programmers
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
-- 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)
if dir < 5 then
dir = (((dir - 1) - (param2 % 4)) % 4) + 1
local SideToDir = {B={}, R={}, F={}, L={}, D={}, U={}}
for param2 = 0,23 do
for dir = 1,6 do
local side = DirToSide[dir][param2]
SideToDir[side][param2] = dir
end
return DirToSide[dir]
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)
local dir = SideToDir[side]
if dir < 5 then
dir = (((dir - 1) + (param2 % 4)) % 4) + 1
end
return dir
return SideToDir[side][param2]
end
@ -92,7 +100,7 @@ local function update1(self, pos, dir)
local fpos,fdir = self:walk_tube_line(pos, dir)
self:infotext(get_pos(pos, dir), fpos)
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.
if fpos and fdir then
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)
M(get_pos(pos1, dir1)):set_string("infotext", I("Maximum length reached!"))
M(get_pos(pos1, dir2)):set_string("infotext", I("Maximum length reached!"))
return false
return false
end
self:infotext(fpos1, fpos2)
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.
local spos1, sdir1 = get_pos(fpos1,fdir1), Turn180Deg[fdir1]
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)
self:infotext(fpos1, fpos2)
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.
if fpos1 and fpos2 and fdir1 and fdir2 then
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
tmp, npos = self:get_special_node(pos, dir)
else
tmp, npos = self:get_secondary_node(pos, dir)
tmp, npos = self:get_secondary_node(pos, dir)
end
if npos then
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
tmp, npos = self:get_special_node(pos, dir)
else
tmp, npos = self:get_secondary_node(pos, dir)
tmp, npos = self:get_secondary_node(pos, dir)
end
if npos then
self:del_from_cache(npos, Turn180Deg[dir])
@ -196,18 +204,18 @@ end
function Tube:new(attr)
local o = {
dirs_to_check = attr.dirs_to_check or {1,2,3,4,5,6},
max_tube_length = attr.max_tube_length or 1000,
primary_node_names = Tbl(attr.primary_node_names or {}),
max_tube_length = attr.max_tube_length or 1000,
primary_node_names = Tbl(attr.primary_node_names or {}),
secondary_node_names = Tbl(attr.secondary_node_names or {}),
valid_node_contact_sides = {},
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,
tube_type = attr.tube_type or "unknown",
pairingList = {}, -- teleporting nodes
connCache = {}, -- connection cache {pos1 = {dir1 = {pos2 = pos2, dir2 = dir2},...}
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)
setmetatable(o, self)
@ -234,7 +242,7 @@ local function invert_booleans(tab)
end
return inversion
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 function complete_valid_sides(valid_sides, existing_defaults)
local valid_sides_complete = {}
@ -368,13 +376,13 @@ end
function Tube:after_dig_tube(pos, oldnode)
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
-- s..secondary, f..far, n..near, x..node to be removed
-- update tubes
if oldnode and oldnode.param2 then
local dir1, dir2 = self:update_after_dig_tube(pos, oldnode.param2)
if dir1 then update1(self, pos, dir1) end
if dir2 then update1(self, pos, dir2) end
-- Update secondary nodes, if right beside
dir1, dir2 = self:decode_param2(pos, oldnode.param2)
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
local item = self.connCache[key][dir]
return item.pos2, Turn180Deg[item.dir2]
end
end
local fpos,fdir = self:walk_tube_line(pos, dir)
local spos = get_pos(fpos,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,
-- 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 Tube:compatible_node(pos, dir)
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
function Tube:replace_tube_line(pos1, pos2)
if pos1 and pos2 and not vector.equals(pos1, pos2) then
local check = (((pos1.x == pos2.x) and 1) or 0) +
(((pos1.y == pos2.y) and 1) or 0) +
local check = (((pos1.x == pos2.x) and 1) or 0) +
(((pos1.y == pos2.y) and 1) or 0) +
(((pos1.z == pos2.z) and 1) or 0)
if check == 2 then
local v = vector.direction(pos1, pos2)
local dir1 = self:vector_to_dir(v)
local dir2 = Turn180Deg[dir1]
self:replace_nodes(pos1, pos2, dir1, dir2)
update3(self, pos1, dir1, dir2)
end
@ -532,4 +540,4 @@ function Tube:get_tube_line(pos, dir)
end
end, self, 0
end
end
end

View file

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