forked from VoxeLibre/VoxeLibre
Merge pull request 'Add lightning rods' (#2772) from lightning_rod into master
Reviewed-on: MineClone2/MineClone2#2772 Reviewed-by: PrairieWind <prairie.astronomer1@gmail.com>
This commit is contained in:
commit
05232e99cd
|
@ -107,29 +107,7 @@ local function choose_pos(pos)
|
|||
return pos, pos2
|
||||
end
|
||||
|
||||
-- * pos: optional, if not given a random pos will be chosen
|
||||
-- * returns: bool - success if a strike happened
|
||||
function lightning.strike(pos)
|
||||
if lightning.auto then
|
||||
after(rng:next(lightning.interval_low, lightning.interval_high), lightning.strike)
|
||||
end
|
||||
|
||||
local pos2
|
||||
pos, pos2 = choose_pos(pos)
|
||||
|
||||
if not pos then
|
||||
return false
|
||||
end
|
||||
if lightning.on_strike_functions then
|
||||
for _, func in pairs(lightning.on_strike_functions) do
|
||||
-- allow on_strike callbacks to destroy entities by re-obtaining objects for each callback
|
||||
local objects = get_objects_inside_radius(pos2, 3.5)
|
||||
func(pos, pos2, objects)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
lightning.register_on_strike(function(pos, pos2, objects)
|
||||
function lightning.strike_func(pos, pos2, objects)
|
||||
local particle_pos = vector.offset(pos2, 0, (lightning.size / 2) + 0.5, 0)
|
||||
local particle_size = lightning.size * 10
|
||||
local time = 0.2
|
||||
|
@ -230,7 +208,38 @@ lightning.register_on_strike(function(pos, pos2, objects)
|
|||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- * pos: optional, if not given a random pos will be chosen
|
||||
-- * returns: bool - success if a strike happened
|
||||
function lightning.strike(pos)
|
||||
if lightning.auto then
|
||||
after(rng:next(lightning.interval_low, lightning.interval_high), lightning.strike)
|
||||
end
|
||||
|
||||
local pos2
|
||||
pos, pos2 = choose_pos(pos)
|
||||
|
||||
if not pos then
|
||||
return false
|
||||
end
|
||||
local do_strike = true
|
||||
if lightning.on_strike_functions then
|
||||
for _, func in pairs(lightning.on_strike_functions) do
|
||||
-- allow on_strike callbacks to destroy entities by re-obtaining objects for each callback
|
||||
local objects = get_objects_inside_radius(pos2, 3.5)
|
||||
local p,stop = func(pos, pos2, objects)
|
||||
if p then
|
||||
pos = p
|
||||
pos2 = choose_pos(p)
|
||||
end
|
||||
do_strike = do_strike and not stop
|
||||
end
|
||||
end
|
||||
if do_strike then
|
||||
lightning.strike_func(pos,pos2,get_objects_inside_radius(pos2, 3.5))
|
||||
end
|
||||
end
|
||||
|
||||
-- if other mods disable auto lightning during initialization, don't trigger the first lightning.
|
||||
after(5, function(dtime)
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
local S = minetest.get_translator("mobs_mc")
|
||||
|
||||
local cbox = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{ 0/16, -8/16, 0/16, 2/16, 4/16, 2/16 },
|
||||
{ 0/16, 4/16, 0/16, 3/16, 8/16, 3/16 },
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node("mcl_lightning_rods:rod", {
|
||||
description = S("Lightning Rod"),
|
||||
_doc_items_longdesc = S("A block that attracts lightning"),
|
||||
--inventory_image = "mcl_lightning_rods_rod_inv.png",
|
||||
tiles = {
|
||||
"mcl_lightning_rods_rod.png",
|
||||
"mcl_lightning_rods_rod.png",
|
||||
"mcl_lightning_rods_rod.png",
|
||||
"mcl_lightning_rods_rod.png",
|
||||
"mcl_lightning_rods_rod.png",
|
||||
"mcl_lightning_rods_rod.png",
|
||||
},
|
||||
drawtype = "nodebox",
|
||||
is_ground_content = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {pickaxey=2,attracts_lightning=1},
|
||||
sounds = mcl_sounds.node_sound_metal_defaults(),
|
||||
node_box = cbox,
|
||||
selection_box = cbox,
|
||||
collision_box = cbox,
|
||||
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
|
||||
local dir = {
|
||||
x = p1.x - placer_pos.x,
|
||||
y = p1.y - placer_pos.y,
|
||||
z = p1.z - placer_pos.z
|
||||
}
|
||||
param2 = minetest.dir_to_facedir(dir)
|
||||
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,
|
||||
|
||||
sounds = mcl_sounds.node_sound_glass_defaults(),
|
||||
_mcl_blast_resistance = 0,
|
||||
})
|
||||
|
||||
lightning.register_on_strike(function(pos,pos2,objects)
|
||||
local lr = minetest.find_node_near(pos,128,{"group:attracts_lightning"},true)
|
||||
return lr,nil
|
||||
end)
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mcl_lightning_rods:rod",
|
||||
recipe = {
|
||||
{"", "mcl_copper:copper_ingot",""},
|
||||
{"", "mcl_copper:copper_ingot",""},
|
||||
{"", "mcl_copper:copper_ingot",""},
|
||||
}
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
name = mcl_lightning_rods
|
||||
author = cora
|
||||
depends = mcl_sounds, lightning
|
Binary file not shown.
After Width: | Height: | Size: 236 B |
Loading…
Reference in New Issue