forked from mtcontrib/homedecor_modpack
10cef3dda1
Just a minimal code reduction, but big reduction in code duplication. This could help if in the future, support for different "internationalization" mods will be added, or in case Minetest supports I18N/L10N internally in the engine.
287 lines
8.7 KiB
Lua
287 lines
8.7 KiB
Lua
|
|
-- This file supplies glowlights
|
|
|
|
local S = homedecor.gettext
|
|
|
|
local colors = {"yellow","white"}
|
|
|
|
for i in ipairs(colors) do
|
|
local color = colors[i]
|
|
|
|
minetest.register_abm({
|
|
nodenames = { "homedecor:glowlight_thin_"..color },
|
|
interval = 1,
|
|
chance = 1,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
minetest.add_node(pos, {name = "homedecor:glowlight_quarter_"..color, param2 = 20})
|
|
end,
|
|
})
|
|
|
|
minetest.register_abm({
|
|
nodenames = { "homedecor:glowlight_thick_"..color },
|
|
interval = 1,
|
|
chance = 1,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
minetest.add_node(pos, {name = "homedecor:glowlight_half_"..color, param2 = 20})
|
|
end,
|
|
})
|
|
|
|
minetest.register_abm({
|
|
nodenames = { "homedecor:glowlight_thin_"..color.."_wall" },
|
|
interval = 1,
|
|
chance = 1,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
local fdir = node.param2 or 0
|
|
nfdir = dirs2[fdir+1]
|
|
minetest.add_node(pos, {name = "homedecor:glowlight_quarter_"..color, param2 = nfdir})
|
|
end,
|
|
})
|
|
|
|
minetest.register_abm({
|
|
nodenames = { "homedecor:glowlight_thick_"..color.."_wall" },
|
|
interval = 1,
|
|
chance = 1,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
local fdir = node.param2 or 0
|
|
nfdir = dirs2[fdir+1]
|
|
minetest.add_node(pos, {name = "homedecor:glowlight_half_"..color, param2 = nfdir})
|
|
end,
|
|
})
|
|
|
|
minetest.register_abm({
|
|
nodenames = { "homedecor:glowlight_small_cube_"..color.."_ceiling" },
|
|
interval = 1,
|
|
chance = 1,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
minetest.add_node(pos, {name = "homedecor:glowlight_small_cube_"..color, param2 = 20})
|
|
end,
|
|
})
|
|
end
|
|
|
|
-- Yellow
|
|
|
|
minetest.register_node('homedecor:glowlight_half_yellow', {
|
|
description = S("Yellow Glowlight (thick)"),
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
'homedecor_glowlight_yellow_top.png',
|
|
'homedecor_glowlight_yellow_bottom.png',
|
|
'homedecor_glowlight_thick_yellow_sides.png',
|
|
'homedecor_glowlight_thick_yellow_sides.png',
|
|
'homedecor_glowlight_thick_yellow_sides.png',
|
|
'homedecor_glowlight_thick_yellow_sides.png'
|
|
},
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
|
},
|
|
|
|
sunlight_propagates = false,
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
walkable = true,
|
|
groups = { snappy = 3 },
|
|
light_source = LIGHT_MAX,
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
|
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
|
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
|
end
|
|
return itemstack
|
|
end
|
|
})
|
|
|
|
minetest.register_node('homedecor:glowlight_quarter_yellow', {
|
|
description = S("Yellow Glowlight (thin)"),
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
'homedecor_glowlight_yellow_top.png',
|
|
'homedecor_glowlight_yellow_bottom.png',
|
|
'homedecor_glowlight_thin_yellow_sides.png',
|
|
'homedecor_glowlight_thin_yellow_sides.png',
|
|
'homedecor_glowlight_thin_yellow_sides.png',
|
|
'homedecor_glowlight_thin_yellow_sides.png'
|
|
},
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
|
},
|
|
|
|
sunlight_propagates = false,
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
walkable = true,
|
|
groups = { snappy = 3 },
|
|
light_source = LIGHT_MAX-1,
|
|
sounds = default.node_sound_wood_defaults(),
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
|
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
|
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
|
end
|
|
return itemstack
|
|
end
|
|
})
|
|
|
|
|
|
|
|
-- White
|
|
|
|
minetest.register_node('homedecor:glowlight_half_white', {
|
|
description = S("White Glowlight (thick)"),
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
'homedecor_glowlight_white_top.png',
|
|
'homedecor_glowlight_white_bottom.png',
|
|
'homedecor_glowlight_thick_white_sides.png',
|
|
'homedecor_glowlight_thick_white_sides.png',
|
|
'homedecor_glowlight_thick_white_sides.png',
|
|
'homedecor_glowlight_thick_white_sides.png'
|
|
},
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
|
},
|
|
|
|
sunlight_propagates = false,
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
walkable = true,
|
|
groups = { snappy = 3 },
|
|
light_source = LIGHT_MAX,
|
|
sounds = default.node_sound_wood_defaults(),
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
|
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
|
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
|
end
|
|
return itemstack
|
|
end
|
|
})
|
|
|
|
minetest.register_node('homedecor:glowlight_quarter_white', {
|
|
description = S("White Glowlight (thin)"),
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
'homedecor_glowlight_white_top.png',
|
|
'homedecor_glowlight_white_bottom.png',
|
|
'homedecor_glowlight_thin_white_sides.png',
|
|
'homedecor_glowlight_thin_white_sides.png',
|
|
'homedecor_glowlight_thin_white_sides.png',
|
|
'homedecor_glowlight_thin_white_sides.png'
|
|
},
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
|
},
|
|
|
|
sunlight_propagates = false,
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
walkable = true,
|
|
groups = { snappy = 3 },
|
|
light_source = LIGHT_MAX-1,
|
|
sounds = default.node_sound_wood_defaults(),
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
|
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
|
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
|
end
|
|
return itemstack
|
|
end
|
|
})
|
|
|
|
-- Glowlight "cubes"
|
|
|
|
minetest.register_node('homedecor:glowlight_small_cube_yellow', {
|
|
description = S("Yellow Glowlight (small cube)"),
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
'homedecor_glowlight_cube_yellow_tb.png',
|
|
'homedecor_glowlight_cube_yellow_tb.png',
|
|
'homedecor_glowlight_cube_yellow_sides.png',
|
|
'homedecor_glowlight_cube_yellow_sides.png',
|
|
'homedecor_glowlight_cube_yellow_sides.png',
|
|
'homedecor_glowlight_cube_yellow_sides.png'
|
|
},
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
|
},
|
|
|
|
sunlight_propagates = false,
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
walkable = true,
|
|
groups = { snappy = 3 },
|
|
light_source = LIGHT_MAX-1,
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
|
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
|
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
|
end
|
|
return itemstack
|
|
end
|
|
})
|
|
|
|
minetest.register_node('homedecor:glowlight_small_cube_white', {
|
|
description = S("White Glowlight (small cube)"),
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
'homedecor_glowlight_cube_white_tb.png',
|
|
'homedecor_glowlight_cube_white_tb.png',
|
|
'homedecor_glowlight_cube_white_sides.png',
|
|
'homedecor_glowlight_cube_white_sides.png',
|
|
'homedecor_glowlight_cube_white_sides.png',
|
|
'homedecor_glowlight_cube_white_sides.png'
|
|
},
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
|
},
|
|
|
|
sunlight_propagates = false,
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
walkable = true,
|
|
groups = { snappy = 3 },
|
|
light_source = LIGHT_MAX-1,
|
|
sounds = default.node_sound_wood_defaults(),
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if not homedecor:node_is_owned(pointed_thing.under, placer)
|
|
and not homedecor:node_is_owned(pointed_thing.above, placer) then
|
|
lib_6d:rotate_and_place(itemstack, placer, pointed_thing, homedecor.expect_infinite_stacks)
|
|
end
|
|
return itemstack
|
|
end
|
|
})
|
|
|