diff --git a/mods/day_night/init.lua b/mods/day_night/init.lua index a232e77..42943ca 100644 --- a/mods/day_night/init.lua +++ b/mods/day_night/init.lua @@ -26,7 +26,7 @@ minetest.register_globalstep(function(dtime) if store_tod == 0 and old_time == 1 then minetest.sound_play("day_night_power_down", { - name = "day_night_power_down.ogg", + name = "day_night_power_down", gain = 1.0, pitch = 1.0, }) diff --git a/mods/light_api/init.lua b/mods/light_api/init.lua new file mode 100644 index 0000000..3daa9b0 --- /dev/null +++ b/mods/light_api/init.lua @@ -0,0 +1,87 @@ +light = {} + +function light.toggle_light(pos, node, play_sound) + local store_tod = day_night.get_storetime() + local is_off = false + if node.name:sub(-4) == "_off" then + is_off = true + end + + if is_off and store_tod == 1 then + minetest.swap_node(pos, {name = node.name:sub(0,-5)}) + + if play_sound then + minetest.sound_play("light_api_toggle", { + name = "light_api_toggle", + pos = pos, + max_hear_distance = 150, + gain = 1.0, + pitch = 1.0, + }) + end + + elseif not is_off and store_tod == 0 then + minetest.swap_node(pos, {name = node.name.."_off"}) + + if play_sound then + minetest.sound_play("light_api_toggle", { + name = "light_api_toggle", + pos = pos, + max_hear_distance = 150, + gain = 1.0, + pitch = 1.0, + }) + end + end +end + + +local light_default = { + description = "Default Description For Lights", + mesh = "error.obj", + tiles = {"unknown_node.png^[colorize:#ff0000:255"}, + collision_box = nil, + selection_box = nil, + light_source = minetest.LIGHT_MAX, +} + +function light.register_light(name, def) + local def = { + description = (def.description or light_default.description), + paramtype = "light", + drawtype = "mesh", + mesh = (def.mesh or light_default.mesh), + tiles = (def.tiles or light_default.tiles), + collision_box = (def.collision_box or light_default.collision_box), + selection_box = (def.selection_box or light_default.selection_box), + light_source = (def.light_source or light_default.light_source), + groups = {static = 1, light = 1}, + } + + minetest.register_node(":" .. name, def) + + local def_off = def + def_off.light_source = 0 + + minetest.register_node(":" .. name .. "_off", def_off) +end + +minetest.register_abm({ + nodenames = {"group:light"}, + interval = 1.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + light.toggle_light(pos, node, true) + end +}) + +minetest.register_lbm({ + label = "Light Updater LBM", + name = "light_api:light_toggle", + nodenames = {"group:light"}, + run_at_every_load = true, + + action = function(pos, node) + light.toggle_light(pos, node, false) + end, +}) diff --git a/mods/light_api/sounds/light_api_toggle.ogg b/mods/light_api/sounds/light_api_toggle.ogg new file mode 100644 index 0000000..ef9914b Binary files /dev/null and b/mods/light_api/sounds/light_api_toggle.ogg differ diff --git a/mods/warehouse/mod.conf b/mods/warehouse/mod.conf index f1dbbdf..fb73464 100644 --- a/mods/warehouse/mod.conf +++ b/mods/warehouse/mod.conf @@ -1,2 +1,2 @@ name = warehouse -depends = mapgen +depends = mapgen,light_api diff --git a/mods/warehouse/nodes.lua b/mods/warehouse/nodes.lua index a3e22fb..b3f0ec9 100644 --- a/mods/warehouse/nodes.lua +++ b/mods/warehouse/nodes.lua @@ -16,15 +16,11 @@ minetest.register_node("warehouse:rack", { sunlight_propagates = true, }) -minetest.register_node("warehouse:light", { +light.register_light("warehouse:light", { description = "Lights That Light The Warehouse", - drawtype = "mesh", mesh = "warehouse_light.obj", tiles = {name = "warehouse_light.png"}, - paramtype = "light", light_source = minetest.LIGHT_MAX, - is_ground_content = true, - groups = {static = 1}, }) minetest.register_node("warehouse:rack_filler", {