2019-03-04 23:49:16 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-03-08 23:30:12 -05:00
|
|
|
local math, minetest, nodecore, vector
|
|
|
|
= math, minetest, nodecore, vector
|
|
|
|
local math_random
|
|
|
|
= math.random
|
2019-03-04 23:49:16 -05:00
|
|
|
-- 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
|
2019-03-12 20:22:42 -04:00
|
|
|
return modname .. ":lens_glow"
|
2019-03-07 00:35:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
local fore = vector.add(pos, face.f)
|
|
|
|
local ll = minetest.get_node_light(fore)
|
2019-03-12 20:22:42 -04:00
|
|
|
local lt = 15
|
|
|
|
if node and node.name == modname .. ":lens_on" then lt = 14 end
|
|
|
|
local on = ll >= lt and face.f.y == 1
|
2019-03-07 00:35:27 -05:00
|
|
|
if not on then
|
|
|
|
local node = minetest.get_node(fore)
|
2019-03-13 23:51:59 -04:00
|
|
|
local def = minetest.registered_items[node.name] or {}
|
|
|
|
on = def.light_source and def.light_source > 4
|
2019-03-07 00:35:27 -05:00
|
|
|
end
|
|
|
|
if on then
|
2019-03-12 20:22:42 -04:00
|
|
|
return modname .. ":lens_on", {face.k}
|
2019-03-07 00:35:27 -05:00
|
|
|
end
|
2019-03-12 20:22:42 -04:00
|
|
|
return 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 = {
|
2019-03-09 19:40:02 -05:00
|
|
|
silica_lens = 1,
|
2019-03-07 00:35:27 -05:00
|
|
|
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,
|
2019-03-07 10:04:32 -05:00
|
|
|
optic_check = lens_check,
|
2019-03-07 00:35:27 -05:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2019-03-07 10:04:32 -05:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
})
|
2019-03-08 23:30:12 -05:00
|
|
|
|
|
|
|
nodecore.register_limited_abm({
|
|
|
|
label = "Lens Fire Starting",
|
|
|
|
interval = 2,
|
|
|
|
chance = 2,
|
|
|
|
nodenames = {modname .. ":lens_on"},
|
|
|
|
action = function(pos, node)
|
|
|
|
local face = nodecore.facedirs[node.param2]
|
|
|
|
local out = vector.add(face.k, pos)
|
|
|
|
local tn = minetest.get_node(out)
|
|
|
|
local tdef = minetest.registered_items[tn.name] or {}
|
2019-03-09 19:46:52 -05:00
|
|
|
local flam = tdef and (not tdef.sunlight_propagates)
|
|
|
|
and tdef.groups and tdef.groups.flammable
|
2019-03-08 23:30:12 -05:00
|
|
|
if flam and math_random(1, flam) == 1 then
|
|
|
|
nodecore.ignite(out, tn)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|