switch to the minetest-conventional def-table style of registering tubes to clean up their registrations

fallback for the old call is provided
This commit is contained in:
Tim 2015-01-31 16:10:25 +01:00
parent 810ae99008
commit e60f86a588
6 changed files with 197 additions and 174 deletions

View File

@ -10,20 +10,20 @@ minetest.register_craft( {
}) })
if pipeworks.enable_accelerator_tube then if pipeworks.enable_accelerator_tube then
local accelerator_noctr_textures = { "pipeworks_accelerator_tube_noctr.png" } pipeworks.register_tube("pipeworks:accelerator_tube", {
local accelerator_plain_textures = { "pipeworks_accelerator_tube_plain.png" } description = "Accelerating Pneumatic Tube Segment",
local accelerator_end_textures = { "pipeworks_accelerator_tube_end.png" } inventory_image = "pipeworks_accelerator_tube_inv.png",
local accelerator_short_texture = "pipeworks_accelerator_tube_short.png" plain = { "pipeworks_accelerator_tube_plain.png" },
local accelerator_inv_texture = "pipeworks_accelerator_tube_inv.png" noctr = { "pipeworks_accelerator_tube_noctr.png" },
ends = { "pipeworks_accelerator_tube_end.png" },
pipeworks.register_tube("pipeworks:accelerator_tube", "Accelerating Pneumatic Tube Segment", accelerator_plain_textures, short = "pipeworks_accelerator_tube_short.png",
accelerator_noctr_textures, accelerator_end_textures, accelerator_short_texture, accelerator_inv_texture, node_def = {
{tube = {can_go = function(pos, node, velocity, stack) tube = {can_go = function(pos, node, velocity, stack)
velocity.speed = velocity.speed+1 velocity.speed = velocity.speed+1
return pipeworks.notvel(pipeworks.meseadjlist, velocity) return pipeworks.notvel(pipeworks.meseadjlist, velocity)
end} end}
},
}) })
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:accelerator_tube_1 2", output = "pipeworks:accelerator_tube_1 2",
recipe = { recipe = {
@ -32,23 +32,20 @@ if pipeworks.enable_accelerator_tube then
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" } { "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
}, },
}) })
end end
if pipeworks.enable_crossing_tube then if pipeworks.enable_crossing_tube then
local crossing_noctr_textures = { "pipeworks_crossing_tube_noctr.png" } pipeworks.register_tube("pipeworks:crossing_tube", {
local crossing_plain_textures = { "pipeworks_crossing_tube_plain.png" } description = "Crossing Pneumatic Tube Segment",
local crossing_end_textures = { "pipeworks_crossing_tube_end.png" } inventory_image = "pipeworks_crossing_tube_inv.png",
local crossing_short_texture = "pipeworks_crossing_tube_short.png" plain = { "pipeworks_crossing_tube_plain.png" },
local crossing_inv_texture = "pipeworks_crossing_tube_inv.png" noctr = { "pipeworks_crossing_tube_noctr.png" },
ends = { "pipeworks_crossing_tube_end.png" },
pipeworks.register_tube("pipeworks:crossing_tube", "Crossing Pneumatic Tube Segment", crossing_plain_textures, short = "pipeworks_crossing_tube_short.png",
crossing_noctr_textures, crossing_end_textures, crossing_short_texture, crossing_inv_texture, node_def = {
{tube = {can_go = function(pos, node, velocity, stack) tube = {can_go = function(pos, node, velocity, stack) return {velocity} end }
return {velocity} },
end}
}) })
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:crossing_tube_1 5", output = "pipeworks:crossing_tube_1 5",
recipe = { recipe = {

View File

@ -1,10 +1,11 @@
if pipeworks.enable_detector_tube then if pipeworks.enable_detector_tube then
local detector_plain_textures = { "pipeworks_detector_tube_plain.png" }
local detector_inv_texture = "pipeworks_detector_tube_inv.png"
local detector_tube_step = 2 * tonumber(minetest.setting_get("dedicated_server_step")) local detector_tube_step = 2 * tonumber(minetest.setting_get("dedicated_server_step"))
pipeworks.register_tube("pipeworks:detector_tube_on", "Detecting Pneumatic Tube Segment on (you hacker you)", pipeworks.register_tube("pipeworks:detector_tube_on", {
detector_plain_textures, nil, nil, nil, detector_inv_texture, description = "Detecting Pneumatic Tube Segment on (you hacker you)",
{tube = {can_go = function(pos, node, velocity, stack) inventory_image = "pipeworks_detector_tube_inv.png",
plain = { "pipeworks_detector_tube_plain.png" },
node_def = {
tube = {can_go = function(pos, node, velocity, stack)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name local name = minetest.get_node(pos).name
local nitems = meta:get_int("nitems")+1 local nitems = meta:get_int("nitems")+1
@ -15,8 +16,7 @@ if pipeworks.enable_detector_tube then
end}, end},
groups = {mesecon = 2, not_in_creative_inventory = 1}, groups = {mesecon = 2, not_in_creative_inventory = 1},
drop = "pipeworks:detector_tube_off_1", drop = "pipeworks:detector_tube_off_1",
mesecons = {receptor = {state = "on", mesecons = {receptor = {state = "on", rules = pipeworks.mesecons_rules}},
rules = pipeworks.mesecons_rules}},
item_exit = function(pos) item_exit = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local nitems = meta:get_int("nitems")-1 local nitems = meta:get_int("nitems")-1
@ -36,11 +36,15 @@ if pipeworks.enable_detector_tube then
local name = minetest.get_node(pos).name local name = minetest.get_node(pos).name
local saved_pos = vector.new(pos) local saved_pos = vector.new(pos)
minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos) minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos)
end end,
},
}) })
pipeworks.register_tube("pipeworks:detector_tube_off", "Detecting Pneumatic Tube Segment", pipeworks.register_tube("pipeworks:detector_tube_off", {
detector_plain_textures, nil, nil, nil, detector_inv_texture, description = "Detecting Pneumatic Tube Segment",
{tube = {can_go = function(pos, node, velocity, stack) inventory_image = "pipeworks_detector_tube_inv.png",
plain = { "pipeworks_detector_tube_plain.png" },
node_def = {
tube = {can_go = function(pos, node, velocity, stack)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local name = node.name local name = node.name
local fdir = node.param2 local fdir = node.param2
@ -49,8 +53,8 @@ if pipeworks.enable_detector_tube then
return pipeworks.notvel(pipeworks.meseadjlist, velocity) return pipeworks.notvel(pipeworks.meseadjlist, velocity)
end}, end},
groups = {mesecon = 2}, groups = {mesecon = 2},
mesecons = {receptor = {state = "off", mesecons = {receptor = {state = "off", rules = pipeworks.mesecons_rules }},
rules = pipeworks.mesecons_rules}} },
}) })
minetest.register_craft( { minetest.register_craft( {
@ -64,31 +68,34 @@ if pipeworks.enable_detector_tube then
end end
if pipeworks.enable_conductor_tube then if pipeworks.enable_conductor_tube then
local conductor_plain_textures = { "pipeworks_conductor_tube_plain.png" } pipeworks.register_tube("pipeworks:conductor_tube_off", {
local conductor_noctr_textures = { "pipeworks_conductor_tube_noctr.png" } description = "Conducting Pneumatic Tube Segment",
local conductor_end_textures = { "pipeworks_conductor_tube_end.png" } inventory_image = "pipeworks_conductor_tube_inv.png",
local conductor_short_texture = "pipeworks_conductor_tube_short.png" short = "pipeworks_conductor_tube_short.png",
local conductor_inv_texture = "pipeworks_conductor_tube_inv.png" plain = { "pipeworks_conductor_tube_plain.png" },
noctr = { "pipeworks_conductor_tube_noctr.png" },
local conductor_on_plain_textures = { "pipeworks_conductor_tube_on_plain.png" } ends = { "pipeworks_conductor_tube_end.png" },
local conductor_on_noctr_textures = { "pipeworks_conductor_tube_on_noctr.png" } node_def = {
local conductor_on_end_textures = { "pipeworks_conductor_tube_on_end.png" } groups = {mesecon = 2},
pipeworks.register_tube("pipeworks:conductor_tube_off", "Conducting Pneumatic Tube Segment", conductor_plain_textures, conductor_noctr_textures,
conductor_end_textures, conductor_short_texture, conductor_inv_texture,
{groups = {mesecon = 2},
mesecons = {conductor = {state = "off", mesecons = {conductor = {state = "off",
rules = pipeworks.mesecons_rules, rules = pipeworks.mesecons_rules,
onstate = "pipeworks:conductor_tube_on_#id"}} onstate = "pipeworks:conductor_tube_on_#id"}}
},
}) })
pipeworks.register_tube("pipeworks:conductor_tube_on", {
pipeworks.register_tube("pipeworks:conductor_tube_on", "Conducting Pneumatic Tube Segment on (you hacker you)", conductor_on_plain_textures, conductor_on_noctr_textures, description = "Conducting Pneumatic Tube Segment on (you hacker you)",
conductor_on_end_textures, conductor_short_texture, conductor_inv_texture, inventory_image = "pipeworks_conductor_tube_inv.png",
{groups = {mesecon = 2, not_in_creative_inventory = 1}, short = "pipeworks_conductor_tube_short.png",
plain_textures = { "pipeworks_conductor_tube_on_plain.png" },
noctr = { "pipeworks_conductor_tube_on_noctr.png" },
ends = { "pipeworks_conductor_tube_on_end.png" },
node_def = {
groups = {mesecon = 2, not_in_creative_inventory = 1},
drop = "pipeworks:conductor_tube_off_1", drop = "pipeworks:conductor_tube_off_1",
mesecons = {conductor = {state = "on", mesecons = {conductor = {state = "on",
rules = pipeworks.mesecons_rules, rules = pipeworks.mesecons_rules,
offstate = "pipeworks:conductor_tube_off_#id"}} offstate = "pipeworks:conductor_tube_off_#id"}}
},
}) })
minetest.register_craft( { minetest.register_craft( {

View File

@ -1,11 +1,4 @@
if pipeworks.enable_mese_tube then if pipeworks.enable_mese_tube then
local mese_noctr_textures = {"pipeworks_mese_tube_noctr_1.png", "pipeworks_mese_tube_noctr_2.png", "pipeworks_mese_tube_noctr_3.png",
"pipeworks_mese_tube_noctr_4.png", "pipeworks_mese_tube_noctr_5.png", "pipeworks_mese_tube_noctr_6.png"}
local mese_plain_textures = {"pipeworks_mese_tube_plain_1.png", "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_3.png",
"pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_5.png", "pipeworks_mese_tube_plain_6.png"}
local mese_end_textures = { "pipeworks_mese_tube_end.png" }
local mese_short_texture = "pipeworks_mese_tube_short.png"
local mese_inv_texture = "pipeworks_mese_tube_inv.png"
local function update_formspec(pos) local function update_formspec(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local old_formspec = meta:get_string("formspec") local old_formspec = meta:get_string("formspec")
@ -40,9 +33,19 @@ if pipeworks.enable_mese_tube then
buttons_formspec.. buttons_formspec..
"list[current_player;main;0,7;8,4;]") "list[current_player;main;0,7;8,4;]")
end end
pipeworks.register_tube("pipeworks:mese_tube", "Sorting Pneumatic Tube Segment", mese_plain_textures, mese_noctr_textures,
mese_end_textures, mese_short_texture, mese_inv_texture, pipeworks.register_tube("pipeworks:mese_tube", {
{tube = {can_go = function(pos, node, velocity, stack) description = "Sorting Pneumatic Tube Segment",
inventory_image = "pipeworks_mese_tube_inv.png",
noctr = {"pipeworks_mese_tube_noctr_1.png", "pipeworks_mese_tube_noctr_2.png", "pipeworks_mese_tube_noctr_3.png",
"pipeworks_mese_tube_noctr_4.png", "pipeworks_mese_tube_noctr_5.png", "pipeworks_mese_tube_noctr_6.png"},
plain = {"pipeworks_mese_tube_plain_1.png", "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_3.png",
"pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_5.png", "pipeworks_mese_tube_plain_6.png"},
ends = { "pipeworks_mese_tube_end.png" },
short = "pipeworks_mese_tube_short.png",
no_facedir = true, -- Must use old tubes, since the textures are rotated with 6d ones
node_def = {
tube = {can_go = function(pos, node, velocity, stack)
local tbl, tbln = {}, 0 local tbl, tbln = {}, 0
local found, foundn = {}, 0 local found, foundn = {}, 0
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -108,7 +111,8 @@ if pipeworks.enable_mese_tube then
inv:set_stack(from_list, from_index, ItemStack("")) inv:set_stack(from_list, from_index, ItemStack(""))
return 0 return 0
end, end,
}, true) -- Must use old tubes, since the textures are rotated with 6d ones },
})
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:mese_tube_1 2", output = "pipeworks:mese_tube_1 2",

View File

@ -105,12 +105,6 @@ local function get_receivers(pos, channel)
return receivers return receivers
end end
local teleport_noctr_textures={ "pipeworks_teleport_tube_noctr.png" }
local teleport_plain_textures={ "pipeworks_teleport_tube_plain.png" }
local teleport_end_textures={ "pipeworks_teleport_tube_end.png" }
local teleport_short_texture="pipeworks_teleport_tube_short.png"
local teleport_inv_texture="pipeworks_teleport_tube_inv.png"
local function update_meta(meta, can_receive) local function update_meta(meta, can_receive)
meta:set_int("can_receive", can_receive and 1 or 0) meta:set_int("can_receive", can_receive and 1 or 0)
local cr_state = can_receive and "on" or "off" local cr_state = can_receive and "on" or "off"
@ -126,8 +120,14 @@ local function update_meta(meta, can_receive)
default.gui_bg_img) default.gui_bg_img)
end end
pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Segment",teleport_plain_textures, pipeworks.register_tube("pipeworks:teleport_tube", {
teleport_noctr_textures,teleport_end_textures,teleport_short_texture,teleport_inv_texture, { description = "Teleporting Pneumatic Tube Segment",
inventory_image = "pipeworks_teleport_tube_inv.png",
noctr = { "pipeworks_teleport_tube_noctr.png" },
plain = { "pipeworks_teleport_tube_plain.png" },
ends = { "pipeworks_teleport_tube_end.png" },
short = "pipeworks_teleport_tube_short.png",
node_def = {
is_teleport_tube = true, is_teleport_tube = true,
tube = { tube = {
can_go = function(pos,node,velocity,stack) can_go = function(pos,node,velocity,stack)
@ -217,8 +217,8 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Se
on_destruct = function(pos) on_destruct = function(pos)
remove_tube(pos) remove_tube(pos)
end end
},
}) })
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:teleport_tube_1 2", output = "pipeworks:teleport_tube_1 2",
recipe = { recipe = {

View File

@ -147,7 +147,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
minetest.register_node(rname, nodedef) minetest.register_node(rname, nodedef)
end end
pipeworks.register_tube = function(name, desc, plain, noctrs, ends, short, inv, special, old_registration) local register_all_tubes = function(name, desc, plain, noctrs, ends, short, inv, special, old_registration)
if old_registration then if old_registration then
for xm = 0, 1 do for xm = 0, 1 do
for xp = 0, 1 do for xp = 0, 1 do
@ -228,6 +228,20 @@ pipeworks.register_tube = function(name, desc, plain, noctrs, ends, short, inv,
end end
end end
pipeworks.register_tube = function(name, def, ...)
if type(def) == "table" then
register_all_tubes(name, def.description,
def.plain, def.noctr, def.ends, def.short,
def.inventory_image, def.node_def, def.no_facedir)
else
-- we assert to be the old function with the second parameter being the description
-- function(name, desc, plain, noctrs, ends, short, inv, special, old_registration)
assert(type(def) == "string", "invalid arguments to pipeworks.register_tube")
register_all_tubes(name, def, ...)
end
end
if REGISTER_COMPATIBILITY then if REGISTER_COMPATIBILITY then
minetest.register_abm({ minetest.register_abm({
nodenames = {"group:tube_to_update"}, nodenames = {"group:tube_to_update"},

View File

@ -1,13 +1,13 @@
if pipeworks.enable_sand_tube then if pipeworks.enable_sand_tube then
local sand_noctr_textures = { "pipeworks_sand_tube_noctr.png" } pipeworks.register_tube("pipeworks:sand_tube", {
local sand_plain_textures = { "pipeworks_sand_tube_plain.png" } description = "Vacuuming Pneumatic Tube Segment",
local sand_end_textures = { "pipeworks_sand_tube_end.png" } inventory_image = "pipeworks_sand_tube_inv.png",
local sand_short_texture = "pipeworks_sand_tube_short.png" short = "pipeworks_sand_tube_short.png",
local sand_inv_texture = "pipeworks_sand_tube_inv.png" noctr = { "pipeworks_sand_tube_noctr.png" },
plain = { "pipeworks_sand_tube_plain.png" },
pipeworks.register_tube("pipeworks:sand_tube", "Vacuuming Pneumatic Tube Segment", sand_plain_textures, sand_noctr_textures, sand_end_textures, ends = { "pipeworks_sand_tube_end.png" },
sand_short_texture, sand_inv_texture, node_def = { groups = {vacuum_tube = 1}},
{groups = {vacuum_tube = 1}}) })
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:sand_tube_1 2", output = "pipeworks:sand_tube_1 2",
@ -36,15 +36,15 @@ if pipeworks.enable_sand_tube then
end end
if pipeworks.enable_mese_sand_tube then if pipeworks.enable_mese_sand_tube then
local mese_sand_noctr_textures = { "pipeworks_mese_sand_tube_noctr.png" } pipeworks.register_tube("pipeworks:mese_sand_tube", {
local mese_sand_plain_textures = { "pipeworks_mese_sand_tube_plain.png" } description = "Adjustable Vacuuming Pneumatic Tube Segment",
local mese_sand_end_textures = { "pipeworks_mese_sand_tube_end.png" } inventory_image = "pipeworks_mese_sand_tube_inv.png",
local mese_sand_short_texture = "pipeworks_mese_sand_tube_short.png" short = "pipeworks_mese_sand_tube_short.png",
local mese_sand_inv_texture = "pipeworks_mese_sand_tube_inv.png" noctr = { "pipeworks_mese_sand_tube_noctr.png" },
plain = { "pipeworks_mese_sand_tube_plain.png" },
pipeworks.register_tube("pipeworks:mese_sand_tube", "Adjustable Vacuuming Pneumatic Tube Segment", mese_sand_plain_textures, mese_sand_noctr_textures, ends = { "pipeworks_mese_sand_tube_end.png" },
mese_sand_end_textures, mese_sand_short_texture,mese_sand_inv_texture, node_def = {
{groups = {vacuum_tube = 1}, groups = {vacuum_tube = 1},
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("dist", 0) meta:set_int("dist", 0)
@ -63,6 +63,7 @@ if pipeworks.enable_mese_sand_tube then
meta:set_string("infotext", ("Adjustable Vacuuming Pneumatic Tube Segment (%dm)"):format(dist)) meta:set_string("infotext", ("Adjustable Vacuuming Pneumatic Tube Segment (%dm)"):format(dist))
end end
end, end,
},
}) })
minetest.register_craft( { minetest.register_craft( {