From 20793b811875bf6cc51f68f64fb8b04ccd731a78 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Thu, 13 Jan 2022 17:07:33 -0800 Subject: [PATCH 1/4] remove explode_center --- game_api.txt | 15 +++++++-------- mods/tnt/init.lua | 22 +++++----------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/game_api.txt b/game_api.txt index a2e9c646..f082452b 100644 --- a/game_api.txt +++ b/game_api.txt @@ -167,11 +167,11 @@ Doors API The doors mod allows modders to register custom doors and trapdoors. -`doors.registered_doors[name] = Door definition` - * Table of registered doors, indexed by door name +`doors.registered_doors[name] = Door definition` + * Table of registered doors, indexed by door name -`doors.registered_trapdoors[name] = Trapdoor definition` - * Table of registered trap doors, indexed by trap door name +`doors.registered_trapdoors[name] = Trapdoor definition` + * Table of registered trap doors, indexed by trap door name `doors.register_door(name, def)` @@ -214,7 +214,7 @@ The doors mod allows modders to register custom doors and trapdoors. * `pos` Position of the door * `node` Node definition * `clicker` Player definition for the player that clicked on the door - + ### Door definition description = "Door description", @@ -257,7 +257,7 @@ The doors mod allows modders to register custom doors and trapdoors. gain_open = 0.3, -- optional, defaults to 0.3 gain_close = 0.3, -- optional, defaults to 0.3 protected = false, -- If true, only placer can open the door (locked for others) - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) , + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing), -- function containing the on_rightclick callback use_texture_alpha = "clip", @@ -543,8 +543,7 @@ TNT API ^ Create an explosion. * `position` The center of explosion. -* `definition` The TNT definion as passed to `tnt.register` with the following addition: - * `explode_center` false by default which removes TNT node on blast, when true will explode center node. +* `definition` The TNT definion as passed to `tnt.register`. `tnt.burn(position, [nodename])` diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index c59363a5..04017776 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -91,12 +91,7 @@ end local basic_flame_on_construct -- cached value local function destroy(drops, npos, cid, c_air, c_fire, - on_blast_queue, on_construct_queue, - ignore_protection, ignore_on_blast, owner) - if not ignore_protection and minetest.is_protected(npos, owner) then - return cid - end - + on_blast_queue, on_construct_queue, ignore_on_blast) local def = cid_data[cid] if not def then @@ -284,7 +279,7 @@ function tnt.burn(pos, nodename) end end -local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner, explode_center) +local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner) pos = vector.round(pos) -- scan for adjacent TNT nodes first, and enlarge the explosion local vm1 = VoxelManip() @@ -293,7 +288,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne local minp, maxp = vm1:read_from_map(p1, p2) local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) local data = vm1:get_data() - local count = 0 + local count = 1 local c_tnt local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning") local c_tnt_boom = minetest.get_content_id("tnt:boom") @@ -304,10 +299,6 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne else c_tnt = c_tnt_burning -- tnt is not registered if disabled end - -- make sure we still have explosion even when centre node isnt tnt related - if explode_center then - count = 1 - end for z = pos.z - 2, pos.z + 2 do for y = pos.y - 2, pos.y + 2 do @@ -352,7 +343,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne if (radius * radius) / (r * r) >= (pr:next(80, 125) / 100) then local cid = data[vi] local p = {x = pos.x + x, y = pos.y + y, z = pos.z + z} - if cid ~= c_air and cid ~= c_ignore then + if cid ~= c_air and cid ~= c_ignore and (ignore_protection or not minetest.is_protected(p, owner)) then data[vi] = destroy(drops, p, cid, c_air, c_fire, on_blast_queue, on_construct_queue, ignore_protection, ignore_on_blast, owner) @@ -409,14 +400,11 @@ function tnt.boom(pos, def) def.damage_radius = def.damage_radius or def.radius * 2 local meta = minetest.get_meta(pos) local owner = meta:get_string("owner") - if not def.explode_center and def.ignore_protection ~= true then - minetest.set_node(pos, {name = "tnt:boom"}) - end local sound = def.sound or "tnt_explode" minetest.sound_play(sound, {pos = pos, gain = 2.5, max_hear_distance = math.min(def.radius * 20, 128)}, true) local drops, radius = tnt_explode(pos, def.radius, def.ignore_protection, - def.ignore_on_blast, owner, def.explode_center) + def.ignore_on_blast, owner) -- append entity drops local damage_radius = (radius / math.max(1, def.radius)) * def.damage_radius entity_physics(pos, damage_radius, drops) From 4cd18a908be4349e4997f7873329c70e2c2df425 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Fri, 14 Jan 2022 08:37:06 -0800 Subject: [PATCH 2/4] don't double-count tnt @ the center --- mods/tnt/init.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 04017776..8b29db21 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -300,6 +300,13 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne c_tnt = c_tnt_burning -- tnt is not registered if disabled end + -- don't double-count tnt @ the center + local v = a:index(pos.x, pos.y, pos.z) + local c = data[v] + if (c == c_tnt or c == c_tnt_boom or c == c_tnt_burning) then + data[v] = c_air + end + for z = pos.z - 2, pos.z + 2 do for y = pos.y - 2, pos.y + 2 do local vi = a:index(pos.x - 2, y, z) From 7e597c92c22b5d2a1606088d433f8cd48041fed6 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Fri, 14 Jan 2022 12:00:07 -0800 Subject: [PATCH 3/4] fix explosion flash (tnt:boom node) --- mods/tnt/init.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 8b29db21..472e3928 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -301,10 +301,10 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne end -- don't double-count tnt @ the center - local v = a:index(pos.x, pos.y, pos.z) - local c = data[v] - if (c == c_tnt or c == c_tnt_boom or c == c_tnt_burning) then - data[v] = c_air + local vc = a:index(pos.x, pos.y, pos.z) + local ccid = data[vc] + if (ccid == c_tnt or ccid == c_tnt_boom or ccid == c_tnt_burning) then + data[vc] = c_air end for z = pos.z - 2, pos.z + 2 do @@ -361,11 +361,23 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne end end + -- make the center of the explosion flash, if it's safe + ccid = data[vc] + if ccid == c_air then + data[vc] = c_tnt_boom + end + vm:set_data(data) vm:write_to_map() vm:update_map() vm:update_liquids() + -- make the center of the explosion flash, if it's safe + -- have to set the timer *after* data is written to the map + if ccid == c_air then + minetest.get_node_timer(pos):start(0) + end + -- call check_single_for_falling for everything within 1.5x blast radius for y = -radius * 1.5, radius * 1.5 do for z = -radius * 1.5, radius * 1.5 do @@ -433,6 +445,13 @@ minetest.register_node("tnt:boom", { groups = {dig_immediate = 3, not_in_creative_inventory = 1}, -- unaffected by explosions on_blast = function() end, + on_timer = function(pos, elapsed) + if elapsed > 0 then + minetest.remove_node(pos) + else + return true + end + end, }) minetest.register_node("tnt:gunpowder", { From 943de3b22765c1d1dcee567c34b89fa88f42dfdd Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Fri, 29 Dec 2023 13:59:49 -0800 Subject: [PATCH 4/4] re-add explode_center and set the minimum number of counted nodes to 1 --- game_api.txt | 5 +++-- mods/tnt/init.lua | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/game_api.txt b/game_api.txt index f082452b..2fefb5ae 100644 --- a/game_api.txt +++ b/game_api.txt @@ -232,7 +232,7 @@ The doors mod allows modders to register custom doors and trapdoors. gain_open = 0.3, -- optional, defaults to 0.3 gain_close = 0.3, -- optional, defaults to 0.3 protected = false, -- If true, only placer can open the door (locked for others) - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing), + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing), -- optional function containing the on_rightclick callback, defaults to a doors.door_toggle-wrapper use_texture_alpha = "clip", @@ -543,7 +543,8 @@ TNT API ^ Create an explosion. * `position` The center of explosion. -* `definition` The TNT definion as passed to `tnt.register`. +* `definition` The TNT definion as passed to `tnt.register` with the following addition: + * `explode_center` false by default which removes TNT node on blast, when true will explode center node. `tnt.burn(position, [nodename])` diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 472e3928..8119b2c4 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -279,7 +279,7 @@ function tnt.burn(pos, nodename) end end -local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner) +local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner, explode_center) pos = vector.round(pos) -- scan for adjacent TNT nodes first, and enlarge the explosion local vm1 = VoxelManip() @@ -288,7 +288,6 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne local minp, maxp = vm1:read_from_map(p1, p2) local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) local data = vm1:get_data() - local count = 1 local c_tnt local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning") local c_tnt_boom = minetest.get_content_id("tnt:boom") @@ -300,11 +299,11 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne c_tnt = c_tnt_burning -- tnt is not registered if disabled end - -- don't double-count tnt @ the center - local vc = a:index(pos.x, pos.y, pos.z) - local ccid = data[vc] - if (ccid == c_tnt or ccid == c_tnt_boom or ccid == c_tnt_burning) then - data[vc] = c_air + local count + if explode_center then + count = 1 + else + count = 0 end for z = pos.z - 2, pos.z + 2 do @@ -320,6 +319,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne end end end + count = math.max(1, count) vm1:set_data(data) vm1:write_to_map() @@ -353,7 +353,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne if cid ~= c_air and cid ~= c_ignore and (ignore_protection or not minetest.is_protected(p, owner)) then data[vi] = destroy(drops, p, cid, c_air, c_fire, on_blast_queue, on_construct_queue, - ignore_protection, ignore_on_blast, owner) + ignore_on_blast) end end vi = vi + 1 @@ -362,7 +362,8 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne end -- make the center of the explosion flash, if it's safe - ccid = data[vc] + local vc = a:index(pos.x, pos.y, pos.z) + local ccid = data[vc] if ccid == c_air then data[vc] = c_tnt_boom end @@ -423,7 +424,7 @@ function tnt.boom(pos, def) minetest.sound_play(sound, {pos = pos, gain = 2.5, max_hear_distance = math.min(def.radius * 20, 128)}, true) local drops, radius = tnt_explode(pos, def.radius, def.ignore_protection, - def.ignore_on_blast, owner) + def.ignore_on_blast, owner, def.explode_center) -- append entity drops local damage_radius = (radius / math.max(1, def.radius)) * def.damage_radius entity_physics(pos, damage_radius, drops)