commit 0c3ebb99bd20b03d3497bdfff9e0bd330a5053b7 Author: Auke Kok Date: Wed Jan 13 09:47:32 2016 -0800 Initial checkin. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fa08c5d --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ + +Lightning mod for minetest + + +Copyright (C) 2016 - Auke Kok + +"lightning" is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 +of the license, or (at your option) any later version. + +Textures: CC-BY-SA-4.0 by sofar + lightning_1.png + +Sounds: + thunder.1.ogg - CC-BY-SA - hantorio - http://www.freesound.org/people/hantorio/sounds/121945/ + thunder.2.ogg - CC-BY-SA - juskiddink - http://www.freesound.org/people/juskiddink/sounds/101948/ + thunder.3.ogg - CC-BY-SA - IllusiaProductions - http://www.freesound.org/people/IllusiaProductions/sounds/249950/ diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..98fdb36 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +A mod that adds thunder and lightning effects. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..520b11b --- /dev/null +++ b/init.lua @@ -0,0 +1,100 @@ + +--[[ + +Copyright (C) 2016 - Auke Kok + +"lightning" is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 +of the license, or (at your option) any later version. + +--]] + +local lightning = {} + +lightning.interval_low = 17 +lightning.interval_high = 503 +lightning.range = 200 +lightning.size = 100 + +local rng = PcgRandom(32321123312123) + +lightning.strike = function() + minetest.after(rng:next(lightning.interval_low, lightning.interval_high), lightning.strike) + + local playerlist = minetest.get_connected_players() + local playercount = table.getn(playerlist) + + -- nobody on + if playercount == 0 then + return + end + + local r = rng:next(1, playercount) + local randomplayer = playerlist[r] + local pos = randomplayer:getpos() + + -- avoid striking underground + if pos.y < -20 then + return + end + + pos.x = math.floor(pos.x - (lightning.range / 2) + rng:next(1, lightning.range)) + pos.y = pos.y + (lightning.range / 2) + pos.z = math.floor(pos.z - (lightning.range / 2) + rng:next(1, lightning.range)) + + local b, pos2 = minetest.line_of_sight(pos, {x = pos.x, y = pos.y - lightning.range, z = pos.z}, 1) + -- nothing but air found + if b then + return + end + + minetest.add_particlespawner({ + amount = 1, + time = 0.2, + -- make it hit the top of a block exactly with the bottom + minpos = { x = pos2.x, y = pos2.y + (lightning.size / 2) + 1/2, z = pos2.z }, + maxpos = { x = pos2.x, y = pos2.y + (lightning.size / 2) + 1/2, z = pos2.z }, + -- the particle will be centered above the pos2 position but we + -- want it to hit the node on the ground + -- down really fast at the ground + minvel = {x = 0, y = 0, z = 0}, + maxvel = {x = 0, y = 0, z = 0}, + minacc = {x = 0, y = 0, z = 0}, + maxacc = {x = 0, y = 0, z = 0}, + minexptime = 0.2, + maxexptime = 0.2, + minsize = lightning.size * 10, + maxsize = lightning.size * 10, + collisiondetection = true, + vertical = true, + -- to make it appear hitting the node that will get set on fire, make sure + -- to make the texture lightning bolt hit exactly in the middle of the + -- texture (e.g. 127/128 on a 256x wide texture) + texture = "lightning_lightning_" .. rng:next(1,3) .. ".png", + }) + + minetest.sound_play({ pos = pos, name = "lightning_thunder", gain = 10, max_hear_distance = 500 }) + + -- set the air node above it on fire + pos2.y = pos2.y + 1/2 + if minetest.get_node(pos2).name == "air" then + minetest.set_node(pos2, {name = "fire:basic_flame"}) + end + + -- perform block modifications + pos2.y = pos2.y - 1 + local n = minetest.get_node(pos2) + if n.name == "default:tree" or n.name == "default:jungletree" or n.name == "default:pine_tree" or + n.name == "default:acacia_tree" or n.name == "default:acacia_tree" then + minetest.set_node(pos2, { name = "default:coalblock"}) + elseif n.name == "default:sand" or n.name == "default:desert_sand" then + minetest.set_node(pos2, { name = "default:glass"}) + elseif string.find(n.name, "default:dirt") then + minetest.set_node(pos2, { name = "default:gravel"}) + elseif string.find(n.name, "default:soil") then + minetest.set_node(pos2, { name = "default:gravel"}) + end +end + +minetest.after(rng:next(lightning.interval_low, lightning.interval_high), lightning.strike) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..948a407 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = lightning diff --git a/sounds/lightning_thunder.1.ogg b/sounds/lightning_thunder.1.ogg new file mode 100644 index 0000000..18e0119 Binary files /dev/null and b/sounds/lightning_thunder.1.ogg differ diff --git a/sounds/lightning_thunder.2.ogg b/sounds/lightning_thunder.2.ogg new file mode 100644 index 0000000..c9e1b0d Binary files /dev/null and b/sounds/lightning_thunder.2.ogg differ diff --git a/sounds/lightning_thunder.3.ogg b/sounds/lightning_thunder.3.ogg new file mode 100644 index 0000000..3690d20 Binary files /dev/null and b/sounds/lightning_thunder.3.ogg differ diff --git a/textures/lightning_lightning_1.png b/textures/lightning_lightning_1.png new file mode 100644 index 0000000..37af59e Binary files /dev/null and b/textures/lightning_lightning_1.png differ diff --git a/textures/lightning_lightning_2.png b/textures/lightning_lightning_2.png new file mode 100644 index 0000000..7bab36b Binary files /dev/null and b/textures/lightning_lightning_2.png differ diff --git a/textures/lightning_lightning_3.png b/textures/lightning_lightning_3.png new file mode 100644 index 0000000..f090529 Binary files /dev/null and b/textures/lightning_lightning_3.png differ