Add light_api, Toggle Lights At Night

master
benrob0329 2019-06-20 21:03:53 -04:00
parent f67a10971e
commit f6c19dc083
5 changed files with 90 additions and 7 deletions

View File

@ -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,
})

87
mods/light_api/init.lua Normal file
View File

@ -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,
})

Binary file not shown.

View File

@ -1,2 +1,2 @@
name = warehouse
depends = mapgen
depends = mapgen,light_api

View File

@ -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", {