2019-03-04 23:49:16 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-03-31 20:54:38 -04:00
|
|
|
local minetest, nodecore, vector
|
|
|
|
= minetest, nodecore, vector
|
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]
|
|
|
|
|
2019-12-04 00:17:07 -05:00
|
|
|
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)
|
2019-11-23 08:52:12 -05:00
|
|
|
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
|
2019-08-31 09:26:53 -04:00
|
|
|
local nnode = minetest.get_node(fore)
|
|
|
|
local def = minetest.registered_items[nnode.name] or {}
|
2019-03-13 23:51:59 -04:00
|
|
|
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-11-23 08:52:12 -05:00
|
|
|
|
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-11-30 18:44:51 -05:00
|
|
|
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",
|
2019-11-30 16:40:07 -05:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "nc_optics_lens.obj",
|
2019-03-30 21:23:02 -04:00
|
|
|
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-02 23:32:26 -04:00
|
|
|
),
|
2019-11-30 17:44:28 -05:00
|
|
|
tiles = {
|
|
|
|
txr,
|
2019-11-30 18:44:51 -05:00
|
|
|
txr .. "^" .. pout,
|
|
|
|
txr .. "^" .. pinp
|
2019-11-30 17:44:28 -05:00
|
|
|
},
|
2019-03-07 00:35:27 -05:00
|
|
|
groups = {
|
2019-04-01 19:15:01 -04:00
|
|
|
silica = 1,
|
2019-12-18 07:41:01 -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)
|
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",
|
2019-11-30 18:44:51 -05:00
|
|
|
tiles = {
|
2019-11-30 19:50:19 -05:00
|
|
|
txr .. "^(" .. pact .. "^[opacity:96)",
|
2019-11-30 18:44:51 -05:00
|
|
|
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 = {
|
2019-11-30 19:37:43 -05:00
|
|
|
txr .. "^" .. modname .. "_shine_side.png",
|
|
|
|
txr .. "^" .. modname .. "_shine_end.png^" .. pinp,
|
|
|
|
txr .. "^" .. modname .. "_shine_end.png^" .. pact,
|
2019-08-27 19:14:51 -04:00
|
|
|
},
|
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 {}
|
2019-11-28 11:03:45 -05:00
|
|
|
local flam = tdef and tdef.groups and tdef.groups.flammable
|
2019-03-31 20:54:38 -04:00
|
|
|
if flam then
|
|
|
|
return nodecore.fire_check_ignite(out, tn)
|
2019-03-08 23:30:12 -05:00
|
|
|
end
|
2019-11-28 11:18:03 -05:00
|
|
|
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
|
|
|
|
})
|