From 9f4dc1412b3acb852537f895ed1d56ae32e4c962 Mon Sep 17 00:00:00 2001
From: red-001 <red-001@openmailbox.org>
Date: Wed, 27 Jan 2016 16:33:32 +0000
Subject: [PATCH] Fix TNT mod calculate blast intensity.

Currently the TNT mod uses a dummy vaule of 1 for this.
---
 mods/tnt/init.lua | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua
index 9295ed70..366a34a1 100644
--- a/mods/tnt/init.lua
+++ b/mods/tnt/init.lua
@@ -84,13 +84,15 @@ end
 
 local fire_node = {name="fire:basic_flame"}
 
-local function destroy(drops, pos, cid, ignore_protection, ignore_on_blast)
-	if not ignore_protection and minetest.is_protected(pos, "") then
-		return
+local function destroy(drops, npos, cid, c_air, c_fire, on_blast_queue, ignore_protection, ignore_on_blast)
+	if not ignore_protection and minetest.is_protected(npos, "") then
+		return cid
 	end
 	local def = cid_data[cid]
 	if not ignore_on_blast and def and def.on_blast then
-		local node_drops = def.on_blast(vector.new(pos), 1)
+		local dist = vector.distance(bpos, npos)
+		local intensity = 1 / (dist * dist)
+		local node_drops = def.on_blast(vector.new(npos), intensity)
 		if node_drops then
 			for _, item in ipairs(node_drops) do
 				add_drop(drops, item)
@@ -99,9 +101,9 @@ local function destroy(drops, pos, cid, ignore_protection, ignore_on_blast)
 		return
 	end
 	if def and def.flammable then
-		minetest.set_node(pos, fire_node)
+		minetest.set_node(npos, fire_node)
 	else
-		minetest.remove_node(pos)
+		minetest.remove_node(npos)
 		if def then
 			local node_drops = minetest.get_node_drops(def.name, "")
 			for _, item in ipairs(node_drops) do
@@ -233,7 +235,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast)
 			p.y = pos.y + y
 			p.z = pos.z + z
 			if cid ~= c_air then
-				destroy(drops, p, cid, ignore_protection, ignore_on_blast)
+				destroy(drops, p, cid, pos, ignore_protection, ignore_on_blast)
 			end
 		end
 		vi = vi + 1
-- 
GitLab