mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-26 03:07:32 +01:00
Add lightning rod
This commit is contained in:
parent
7b1d5501c1
commit
e80e44612c
@ -228,9 +228,11 @@ function lightning.strike(pos)
|
|||||||
for _, func in pairs(lightning.on_strike_functions) do
|
for _, func in pairs(lightning.on_strike_functions) do
|
||||||
-- allow on_strike callbacks to destroy entities by re-obtaining objects for each callback
|
-- allow on_strike callbacks to destroy entities by re-obtaining objects for each callback
|
||||||
local objects = get_objects_inside_radius(pos2, 3.5)
|
local objects = get_objects_inside_radius(pos2, 3.5)
|
||||||
local p,p2,stop = func(pos, pos2, objects)
|
local p,stop = func(pos, pos2, objects)
|
||||||
if p then pos = p end
|
if p then
|
||||||
if p2 then pos2 = p2 end
|
pos = p
|
||||||
|
pos2 = choose_pos(p)
|
||||||
|
end
|
||||||
do_strike = do_strike and not stop
|
do_strike = do_strike and not stop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
73
mods/ITEMS/mcl_lightning_rods/init.lua
Normal file
73
mods/ITEMS/mcl_lightning_rods/init.lua
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
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)
|
3
mods/ITEMS/mcl_lightning_rods/mod.conf
Normal file
3
mods/ITEMS/mcl_lightning_rods/mod.conf
Normal file
@ -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
Block a user