88 lines
2.1 KiB
Lua
Raw Normal View History

-- LUALOCALS < ---------------------------------------------------------
2019-03-07 00:35:27 -05:00
local minetest, nodecore, vector
= minetest, nodecore, vector
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
2019-03-07 00:35:27 -05:00
local function lens_check(pos, node, check)
local face = nodecore.facedirs[node.param2]
if check(face.k) then
nodecore.node_change(pos, node, modname .. ":lens_glow")
2019-03-07 00:35:27 -05:00
return
end
local fore = vector.add(pos, face.f)
local ll = minetest.get_node_light(fore)
local on = ll >= 15 and face.f.y == 1
if not on then
local node = minetest.get_node(fore)
local def = minetest.registered_items[node.name]
on = def and def.light_source and def.light_source > 4
end
if on then
nodecore.node_change(pos, node, modname .. ":lens_on")
2019-03-07 00:35:27 -05:00
return {face.k}
end
nodecore.node_change(pos, node, modname .. ":lens")
2019-03-07 00:35:27 -05:00
end
2019-03-07 19:26:53 -05:00
local txr = modname .. "_glass_frost.png"
2019-03-07 00:35:27 -05:00
local basedef = {
description = "Lens",
drawtype = "nodebox",
node_box = nodecore.fixedbox(
{-0.5, -0.5, -3/8, 0.25, -0.25, 1/8},
{-0.25, 0.25, -3/8, 0.5, 0.5, 1/8},
{-0.5, -0.25, -3/8, -0.25, 0.5, 1/8},
{0.25, -0.5, -3/8, 0.5, 0.25, 1/8},
{-0.25, -0.25, -1/8, 0.25, 0.25, 0.25}
),
tiles = {
2019-03-07 19:26:53 -05:00
txr,
txr,
txr,
txr,
txr .. "^" .. modname .. "_lens_out.png",
txr .. "^" .. modname .. "_lens_in.png",
2019-03-07 00:35:27 -05:00
},
groups = {
optic_check = 1,
2019-03-07 19:26:53 -05:00
cracky = 3
2019-03-07 00:35:27 -05:00
},
drop = modname .. ":lens",
on_construct = nodecore.optic_check,
on_destruct = nodecore.optic_check,
2019-03-07 01:40:26 -05:00
on_spin = nodecore.optic_check,
optic_check = lens_check,
2019-03-07 00:35:27 -05:00
paramtype = "light",
paramtype2 = "facedir",
on_rightclick = nodecore.node_spin_filtered(function(a, b)
return vector.equals(a.f, b.f)
end)
2019-03-07 00:35:27 -05:00
}
local function reg(suff, def)
minetest.register_node(modname .. ":lens" .. suff,
nodecore.underride(def, basedef))
end
reg("", {})
2019-03-07 19:26:53 -05:00
reg("_on", {
description = "Active Lens",
light_source = 2
})
reg("_glow", {
description = "Shining Lens",
light_source = 12,
tiles = {
txr,
txr,
txr,
txr,
txr .. "^" .. modname .. "_lens_in.png",
txr .. "^" .. modname .. "_lens_out.png",
},
})