v0.4 - on_update function for secondary nodes introduced

This commit is contained in:
Joachim Stolberg 2018-11-11 21:46:33 +01:00
parent 8bc08daf83
commit ec298259b6
3 changed files with 12 additions and 3 deletions

@ -183,6 +183,11 @@ function Tube:decode_param2(pos, param2)
end end
-- No connection to both sides
function Tube:first_placed_node(pos, param2)
return math.floor(param2 / 32) == 0
end
-- Return node next to pos in direction 'dir' -- Return node next to pos in direction 'dir'
function Tube:get_node(pos, dir) function Tube:get_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0]) local npos = vector.add(pos, Dir6dToVector[dir or 0])

@ -79,6 +79,7 @@ function Tube:after_place_node(pos, dirs)
end end
-- To be called after a tube/primary node is placed. -- To be called after a tube/primary node is placed.
-- Returns false, if placing is not allowed
function Tube:after_place_tube(pos, placer, pointed_thing) function Tube:after_place_tube(pos, placer, pointed_thing)
-- [s1][f1]----[n1] x [n2]-----[f2][s2] -- [s1][f1]----[n1] x [n2]-----[f2][s2]
-- s..secondary, f..far, n..near, x..node to be placed -- s..secondary, f..far, n..near, x..node to be placed

@ -23,15 +23,16 @@ local M = minetest.get_meta
local Tube = tubelib2.Tube:new({ local Tube = tubelib2.Tube:new({
-- North, East, South, West, Down, Up -- North, East, South, West, Down, Up
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},
max_tube_length = 1000, max_tube_length = 1000,
show_infotext = false, show_infotext = false,
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.set_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2}) minetest.swap_node(pos, {name = "tubelib2:tube"..tube_type, param2 = param2})
end, end,
}) })
@ -47,10 +48,12 @@ minetest.register_node("tubelib2:tubeS", {
}, },
after_place_node = function(pos, placer, itemstack, pointed_thing) 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 if not Tube:after_place_tube(pos, placer, pointed_thing) then
minetest.remove_node(pos) minetest.remove_node(pos)
return true return true
end end
print("place time", minetest.get_us_time() - t)
return false return false
end, end,
@ -102,7 +105,7 @@ minetest.register_node("tubelib2:tubeA", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
is_ground_content = false, is_ground_content = false,
groups = {crumbly = 3, cracky = 3, snappy = 3}, --not_in_creative_inventory=1}, groups = {crumbly = 3, cracky = 3, snappy = 3, not_in_creative_inventory=1},
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
drop = "tubelib2:tubeS", drop = "tubelib2:tubeS",
}) })