2022-10-23 00:38:56 +02:00
|
|
|
local S = minetest.get_translator("mcl_lightning_rods")
|
2022-10-13 23:29:37 +02:00
|
|
|
|
2022-10-23 00:38:56 +02:00
|
|
|
---@type nodebox
|
2022-10-13 23:29:37 +02:00
|
|
|
local cbox = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
2022-10-23 00:38:56 +02:00
|
|
|
{ -0.0625, -0.5, -0.0625, 0.0625, 0.25, 0.0625 },
|
|
|
|
{ -0.125, 0.25, -0.125, 0.125, 0.5, 0.125 },
|
|
|
|
},
|
2022-10-13 23:29:37 +02:00
|
|
|
}
|
|
|
|
|
2022-11-08 22:40:36 +01:00
|
|
|
---@type node_definition
|
|
|
|
local rod_def = {
|
2022-10-13 23:29:37 +02:00
|
|
|
description = S("Lightning Rod"),
|
|
|
|
_doc_items_longdesc = S("A block that attracts lightning"),
|
2022-11-28 00:14:17 +01:00
|
|
|
tiles = { "mcl_lightning_rods_rod.png" },
|
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "mcl_lightning_rods_rod.obj",
|
2022-10-13 23:29:37 +02:00
|
|
|
is_ground_content = false,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2022-10-23 00:38:56 +02:00
|
|
|
use_texture_alpha = "opaque",
|
|
|
|
groups = { pickaxey = 2, attracts_lightning = 1 },
|
2022-10-13 23:29:37 +02:00
|
|
|
sounds = mcl_sounds.node_sound_metal_defaults(),
|
|
|
|
selection_box = cbox,
|
|
|
|
collision_box = cbox,
|
2022-10-23 00:38:56 +02:00
|
|
|
node_placement_prediction = "",
|
2022-11-08 22:40:36 +01:00
|
|
|
mesecons = {
|
|
|
|
receptor = {
|
|
|
|
state = mesecon.state.off,
|
|
|
|
rules = mesecon.rules.alldirs,
|
|
|
|
},
|
|
|
|
},
|
2022-10-13 23:29:37 +02:00
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
local p0 = pointed_thing.under
|
|
|
|
local p1 = pointed_thing.above
|
|
|
|
local param2 = 0
|
|
|
|
|
|
|
|
local placer_pos = placer:get_pos()
|
|
|
|
if placer_pos then
|
2022-10-23 00:38:56 +02:00
|
|
|
param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos))
|
2022-10-13 23:29:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if p0.y - 1 == p1.y then
|
|
|
|
param2 = 20
|
|
|
|
elseif p0.x - 1 == p1.x then
|
|
|
|
param2 = 16
|
|
|
|
elseif p0.x + 1 == p1.x then
|
|
|
|
param2 = 12
|
|
|
|
elseif p0.z - 1 == p1.z then
|
|
|
|
param2 = 8
|
|
|
|
elseif p0.z + 1 == p1.z then
|
|
|
|
param2 = 4
|
|
|
|
end
|
|
|
|
|
|
|
|
return minetest.item_place(itemstack, placer, pointed_thing, param2)
|
|
|
|
end,
|
|
|
|
|
|
|
|
_mcl_blast_resistance = 0,
|
2022-11-08 22:40:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
minetest.register_node("mcl_lightning_rods:rod", rod_def)
|
|
|
|
|
|
|
|
local rod_def_a = table.copy(rod_def)
|
|
|
|
|
2022-11-28 00:14:17 +01:00
|
|
|
rod_def_a.tiles = { "mcl_lightning_rods_rod.png^[brighten" }
|
2022-11-08 22:40:36 +01:00
|
|
|
|
|
|
|
rod_def_a.groups.not_in_creative_inventory = 1
|
|
|
|
|
|
|
|
rod_def_a.mesecons = {
|
|
|
|
receptor = {
|
|
|
|
state = mesecon.state.on,
|
|
|
|
rules = mesecon.rules.alldirs,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
rod_def_a.on_timer = function(pos, elapsed)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
|
|
|
|
if node.name == "mcl_lightning_rods:rod_powered" then --has not been dug
|
2023-05-10 23:05:11 +02:00
|
|
|
minetest.set_node(pos, { name = "mcl_lightning_rods:rod", param2 = node.param2 })
|
2022-11-08 22:40:36 +01:00
|
|
|
mesecon.receptor_off(pos, mesecon.rules.alldirs)
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("mcl_lightning_rods:rod_powered", rod_def_a)
|
|
|
|
|
2022-10-13 23:29:37 +02:00
|
|
|
|
2022-10-23 00:38:56 +02:00
|
|
|
lightning.register_on_strike(function(pos, pos2, objects)
|
|
|
|
local lr = minetest.find_node_near(pos, 128, { "group:attracts_lightning" }, true)
|
2022-11-08 22:40:36 +01:00
|
|
|
|
|
|
|
if lr then
|
|
|
|
local node = minetest.get_node(lr)
|
|
|
|
|
|
|
|
if node.name == "mcl_lightning_rods:rod" then
|
2023-05-10 23:05:11 +02:00
|
|
|
minetest.set_node(lr, { name = "mcl_lightning_rods:rod_powered", param2 = node.param2 })
|
2022-11-08 22:40:36 +01:00
|
|
|
mesecon.receptor_on(lr, mesecon.rules.alldirs)
|
2022-11-09 20:20:08 +01:00
|
|
|
minetest.get_node_timer(lr):start(0.4)
|
2022-11-08 22:40:36 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-23 00:38:56 +02:00
|
|
|
return lr, nil
|
2022-10-13 23:29:37 +02:00
|
|
|
end)
|
2022-10-14 04:39:51 +02:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "mcl_lightning_rods:rod",
|
|
|
|
recipe = {
|
2022-10-23 00:38:56 +02:00
|
|
|
{ "", "mcl_copper:copper_ingot", "" },
|
|
|
|
{ "", "mcl_copper:copper_ingot", "" },
|
|
|
|
{ "", "mcl_copper:copper_ingot", "" },
|
|
|
|
},
|
2022-10-14 04:39:51 +02:00
|
|
|
})
|