2019-10-11 08:34:50 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2021-07-09 08:18:55 -04:00
|
|
|
local minetest, nodecore, pairs, vector
|
|
|
|
= minetest, nodecore, pairs, vector
|
2019-10-11 08:34:50 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2020-06-18 22:35:47 -04:00
|
|
|
local modname = minetest.get_current_modname()
|
2020-06-19 09:38:03 -04:00
|
|
|
|
2020-06-18 22:35:47 -04:00
|
|
|
local dntname = modname .. ":ablation"
|
|
|
|
|
2021-07-10 18:31:18 -04:00
|
|
|
local hash = minetest.hash_node_position
|
|
|
|
local cooldowns = {}
|
|
|
|
|
2020-06-19 09:38:03 -04:00
|
|
|
local function ablation(pos, node)
|
2021-07-10 18:31:18 -04:00
|
|
|
local key = hash(pos)
|
|
|
|
local cooldown = cooldowns[key] or 0
|
2021-07-05 12:10:47 -04:00
|
|
|
if cooldown > nodecore.gametime then return end
|
2021-07-10 18:31:18 -04:00
|
|
|
cooldowns[key] = nodecore.gametime + 2
|
2021-07-05 12:10:47 -04:00
|
|
|
|
2020-06-18 22:35:47 -04:00
|
|
|
local face = nodecore.facedirs[node.param2]
|
|
|
|
local out = vector.add(face.k, pos)
|
|
|
|
local tn = minetest.get_node(out)
|
|
|
|
if nodecore.operate_door(out, tn, face.k) then
|
2021-04-03 19:21:09 -04:00
|
|
|
local ppos = vector.add(vector.multiply(face.k, 0.5), pos)
|
|
|
|
local vel = vector.multiply(face.f, 0.5)
|
|
|
|
local dvel = {
|
|
|
|
x = vel.x ~= 0 and 0.5 or 2,
|
|
|
|
y = vel.y ~= 0 and 0.5 or 2,
|
|
|
|
z = vel.z ~= 0 and 0.5 or 2,
|
|
|
|
}
|
|
|
|
minetest.add_particlespawner({
|
|
|
|
time = 0.05,
|
|
|
|
amount = 30,
|
|
|
|
minpos = ppos,
|
|
|
|
maxpos = ppos,
|
|
|
|
minvel = vector.add(vel, vector.multiply(dvel, -1)),
|
|
|
|
maxvel = vector.add(vel, dvel),
|
2021-12-13 22:18:06 -05:00
|
|
|
texture = "nc_doors_ablation_particle.png",
|
2021-04-03 19:21:09 -04:00
|
|
|
minsize = 0.25,
|
|
|
|
maxsize = 1,
|
|
|
|
minexptime = 0.25,
|
|
|
|
maxexptime = 0.5
|
|
|
|
})
|
2020-06-18 22:35:47 -04:00
|
|
|
nodecore.witness(pos, "door ablation")
|
2020-06-19 09:38:03 -04:00
|
|
|
return nodecore.dnt_set(pos, dntname, 2)
|
2020-06-18 22:35:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nodecore.register_dnt({
|
|
|
|
name = dntname,
|
2022-01-09 13:07:16 -05:00
|
|
|
nodenames = {"group:optic_lens_emit"},
|
2020-06-19 09:38:03 -04:00
|
|
|
time = 2,
|
2020-06-18 22:35:47 -04:00
|
|
|
action = ablation
|
|
|
|
})
|
|
|
|
|
2021-07-10 11:09:44 -04:00
|
|
|
minetest.register_abm({
|
2020-06-17 07:09:20 -04:00
|
|
|
label = "door ablation",
|
2019-12-03 20:21:09 -05:00
|
|
|
interval = 2,
|
2019-10-11 08:34:50 -04:00
|
|
|
chance = 1,
|
2022-01-09 13:07:16 -05:00
|
|
|
nodenames = {"group:optic_lens_emit"},
|
2020-06-18 22:35:47 -04:00
|
|
|
neighbors = {"group:door"},
|
|
|
|
action = function(pos)
|
2020-06-19 09:38:03 -04:00
|
|
|
return nodecore.dnt_set(pos, dntname, 2)
|
2019-10-11 08:34:50 -04:00
|
|
|
end
|
|
|
|
})
|
2020-06-19 00:30:17 -04:00
|
|
|
|
2020-06-19 09:38:03 -04:00
|
|
|
local function doortrigger(doorpos)
|
|
|
|
for _, dir in pairs(nodecore.dirs()) do
|
|
|
|
local lenspos = vector.add(doorpos, dir)
|
|
|
|
local lensnode = minetest.get_node(lenspos)
|
2022-01-09 13:11:59 -05:00
|
|
|
if minetest.get_item_group(lensnode.name, "optic_lens_emit") > 0 then
|
2020-06-19 09:38:03 -04:00
|
|
|
local face = nodecore.facedirs[lensnode.param2]
|
|
|
|
local out = vector.add(face.k, lenspos)
|
|
|
|
if vector.equals(doorpos, out) then
|
|
|
|
return ablation(lenspos, minetest.get_node(lenspos))
|
2020-06-19 00:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-09 08:18:55 -04:00
|
|
|
nodecore.register_on_register_item({
|
|
|
|
retroactive = true,
|
|
|
|
func = function(_, def)
|
|
|
|
if def.groups and def.groups.door and def.groups.door > 0 then
|
|
|
|
def.optic_check = doortrigger
|
|
|
|
def.groups.optic_check = 1
|
2020-06-19 00:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
2021-07-09 08:18:55 -04:00
|
|
|
})
|