120 lines
3.0 KiB
Lua
Raw Normal View History

-- LUALOCALS < ---------------------------------------------------------
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
return modname .. ":lens_glow"
2019-03-07 00:35:27 -05:00
end
local fore = vector.add(pos, face.f)
local on
if face.f.y == 1 then
local ll = minetest.get_node_light(fore)
if ll then
local lt = 15
if node and node.name == modname .. ":lens_on" then lt = 14 end
on = ll >= lt and face.f.y == 1
end
end
2019-03-07 00:35:27 -05:00
if not on then
local nnode = minetest.get_node(fore)
local def = minetest.registered_items[nnode.name] or {}
on = def.light_source and def.light_source > 4
2019-03-07 00:35:27 -05:00
end
if on then
return modname .. ":lens_on", {face.k}
2019-03-07 00:35:27 -05:00
end
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"
local pact = modname .. "_port_active.png"
local pout = modname .. "_port_output.png"
local pinp = modname .. "_port_input.png"
2019-03-07 19:26:53 -05:00
2019-03-07 00:35:27 -05:00
local basedef = {
description = "Lens",
drawtype = "mesh",
mesh = "nc_optics_lens.obj",
selection_box = nodecore.fixedbox(
2019-12-04 19:35:35 -05:00
{-7/16, -7/16, -3/8, 7/16, 7/16, 3/8}
),
2019-11-30 17:44:28 -05:00
tiles = {
txr,
txr .. "^" .. pout,
txr .. "^" .. pinp
2019-11-30 17:44:28 -05:00
},
2019-03-07 00:35:27 -05:00
groups = {
silica = 1,
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,
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)
2019-03-14 20:13:37 -04:00
end),
sounds = nodecore.sounds("nc_optics_glassy")
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",
tiles = {
2019-11-30 19:50:19 -05:00
txr .. "^(" .. pact .. "^[opacity:96)",
txr .. "^" .. pact .. "^" .. pout,
txr .. "^" .. pinp .. "^" .. pout
},
2019-03-07 19:26:53 -05:00
light_source = 2
})
reg("_glow", {
description = "Shining Lens",
light_source = 12,
tiles = {
txr .. "^" .. modname .. "_shine_side.png",
txr .. "^" .. modname .. "_shine_end.png^" .. pinp,
txr .. "^" .. modname .. "_shine_end.png^" .. pact,
},
2019-03-07 19:26:53 -05:00
})
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 {}
local flam = tdef and tdef.groups and tdef.groups.flammable
if flam then
return nodecore.fire_check_ignite(out, tn)
2019-03-08 23:30:12 -05:00
end
if tdef.groups and tdef.groups.is_stack_only then
local stack = nodecore.stack_get(out)
return nodecore.fire_check_ignite(out, {
name = stack:get_name(),
count = stack:get_count()
})
end
2019-03-08 23:30:12 -05:00
end
})