From d571d62863ca69a151f89175d9de3fe8397f9b79 Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Sun, 24 Jan 2021 17:47:28 -0600 Subject: [PATCH 1/8] Fix crash in 'mcl_spawn' in v6,flat,singlenode mapgens; and fix mobs despawning when attacking/following players. --- mods/ENTITIES/mcl_mobs/api.lua | 4 +++- mods/PLAYER/mcl_spawn/init.lua | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 895cad72..821dbc0e 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3604,7 +3604,9 @@ local mob_step = function(self, dtime) -- Despawning: when lifetimer expires, remove mob if remove_far and self.can_despawn == true - and ((not self.nametag) or (self.nametag == "")) then + and ((not self.nametag) or (self.nametag == "")) + and self.state ~= "attack" + and self.following == nil then self.lifetimer = self.lifetimer - dtime if self.despawn_immediately or self.lifetimer <= 0 then diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index eb6135bc..a3a461f7 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -425,7 +425,7 @@ end minetest.register_on_respawnplayer(mcl_spawn.spawn) function mcl_spawn.shadow_worker() - if #biome_ids < 1 then + if #biome_ids > 1 then for _, biome_name in pairs(biomes_white_list) do table.insert(biome_ids, minetest.get_biome_id(biome_name)) end From 41bd8031855741078b33a94b783becf3130bbe7d Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Mon, 25 Jan 2021 20:23:38 -0600 Subject: [PATCH 2/8] Add support for mcimported worlds by clearing out singlenode mapgen, and adding a toggleable fix for converted double_plants. --- mods/CORE/mcl_init/init.lua | 12 +++++++++- mods/ITEMS/mcl_flowers/init.lua | 31 ++++++++++++++++++++++++++ mods/MAPGEN/mcl_dungeons/init.lua | 2 ++ mods/MAPGEN/tsm_railcorridors/init.lua | 6 ++++- settingtypes.txt | 4 ++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/mods/CORE/mcl_init/init.lua b/mods/CORE/mcl_init/init.lua index a1346f50..ebbfd559 100644 --- a/mods/CORE/mcl_init/init.lua +++ b/mods/CORE/mcl_init/init.lua @@ -25,6 +25,7 @@ mcl_vars.inventory_header = "" local mg_name = minetest.get_mapgen_setting("mg_name") local minecraft_height_limit = 256 local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superflat_classic") == "true" +local singlenode = mg_name == "singlenode" -- Calculate mapgen_edge_min/mapgen_edge_max mcl_vars.chunksize = math.max(1, tonumber(minetest.get_mapgen_setting("chunksize")) or 5) @@ -45,7 +46,7 @@ local numcmax = math.max(math.floor((mapgen_limit_max - ccfmax) / chunk_size_in_ mcl_vars.mapgen_edge_min = central_chunk_min_pos - numcmin * chunk_size_in_nodes mcl_vars.mapgen_edge_max = central_chunk_max_pos + numcmax * chunk_size_in_nodes -if not superflat then +if not superflat and not singlenode then -- Normal mode --[[ Realm stacking (h is for height) - Overworld (h>=256) @@ -66,6 +67,14 @@ if not superflat then mcl_vars.mg_lava = true mcl_vars.mg_bedrock_is_rough = true +elseif singlenode then + mcl_vars.mg_overworld_min = -66 + mcl_vars.mg_overworld_max_official = mcl_vars.mg_overworld_min + minecraft_height_limit + mcl_vars.mg_bedrock_overworld_min = mcl_vars.mg_overworld_min + mcl_vars.mg_bedrock_overworld_max = mcl_vars.mg_bedrock_overworld_min + mcl_vars.mg_lava = false + mcl_vars.mg_lava_overworld_max = mcl_vars.mg_overworld_min + mcl_vars.mg_bedrock_is_rough = false else -- Classic superflat local ground = minetest.get_mapgen_setting("mgflat_ground_level") @@ -128,3 +137,4 @@ minetest.craftitemdef_default.stack_max = 64 -- Set random seed for all other mods (Remember to make sure no other mod calls this function) math.randomseed(os.time()) + diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 42deede2..af892bfa 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -448,3 +448,34 @@ minetest.register_node("mcl_flowers:waterlily", { -- Legacy support minetest.register_alias("mcl_core:tallgrass", "mcl_flowers:tallgrass") + +-- mcimport support: re-adds missing double_plant tops in mcimported worlds. +local mg_name = minetest.get_mapgen_setting("mg_name") +local mod_mcimport = minetest.get_modpath("mcimport") ~= nil +local fix_doubleplants = minetest.settings:get_bool("fix_doubleplants", true) + + + if mod_mcimport and mg_name == "singlenode" and fix_doubleplants == true then + local flowernames = { "peony", "rose_bush", "lilac", "sunflower", "double_fern", "double_grass" } + for c=1, 6 do + local flowername = flowernames[c] + end + + minetest.register_lbm({ + label = "Add double plant tops.", + name = "mcl_flowers:double_plant_topper", + run_at_every_load = true, + nodenames = { "mcl_flowers:peony", "mcl_flowers:rose_bush", "mcl_flowers:lilac", "mcl_flowers:sunflower", "mcl_flowers:double_fern", "mcl_flowers:double_grass" }, + action = function(pos, node) + for c=1, 6 do + local flowername = flowernames[c] + local bottom = pos + local top = { x = bottom.x, y = bottom.y + 1, z = bottom.z } + if node.name == "mcl_flowers:"..flowername then + minetest.set_node(top, {name = "mcl_flowers:"..flowername.."_top"}) + end + end + end, + }) + end + diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index e1218c0b..1ce1556b 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -8,6 +8,7 @@ if mcl_vars.mg_dungeons == false then return end +if mg_name ~= "singlenode" then -- Get loot for dungeon chests local get_loot = function() local loottable = { @@ -396,3 +397,4 @@ minetest.register_on_generated(function(minp, maxp) end end) +end diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 3cc0d75d..f2e02d99 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -15,7 +15,11 @@ end -- Probability for every newly generated mapchunk to get corridors local probability_railcaves_in_mapchunk = P(0.33333) setting = tonumber(minetest.settings:get("tsm_railcorridors_probability_railcaves_in_mapchunk")) -if setting then +-- Extra check to prevent mod griefing in singlenode, mcimported worlds. +local mg_name = minetest.get_mapgen_setting("mg_name") +if mg_name == "singlenode" then + probability_railcaves_in_mapchunk = P(0) +elseif setting then probability_railcaves_in_mapchunk = P(setting) end diff --git a/settingtypes.txt b/settingtypes.txt index 49274244..b7a75e52 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -126,3 +126,7 @@ mcl_superflat_classic (Classic superflat map generation) bool false # WARNING: This setting has quite poor performance and can slow down your # game by a lot. mcl_node_particles (Block particles detail level) enum none high,medium,low,none + + +# If enabled, will run an LBM to fix the top 1/2 of double plants in mcimported worlds; defaults to true. +fix_doubleplants (Mcimport double plant fixes) bool true From 5ecb56452e96f2e1257ca7daf6b7b5d6f8d6c5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 26 Jan 2021 14:13:21 +0100 Subject: [PATCH 3/8] Fix creeper explosions only doing 1/2 heart damage The solution was to move the creeper explosions to originate from the center of the creepers collisionbox and not its entity position. --- mods/CORE/mcl_util/init.lua | 11 ++++++++++- mods/ENTITIES/mcl_mobs/api.lua | 3 +-- mods/ENTITIES/mobs_mc/creeper.lua | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 7e851336..6c63c21a 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -395,4 +395,13 @@ function mcl_util.generate_on_place_plant_function(condition) end end - +-- adjust the y level of an object to the center of its collisionbox +-- used to get the origin position of entity explosions +function mcl_util.get_object_center(obj) + local collisionbox = obj:get_properties().collisionbox + local pos = obj:get_pos() + local ymin = collisionbox[2] + local ymax = collisionbox[5] + pos.y = pos.y + (ymax - ymin) / 2.0 + return pos +end diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 821dbc0e..33e049a8 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2258,7 +2258,6 @@ local dogswitch = function(self, dtime) return self.dogshoot_switch end - -- execute current state (stand, walk, run, attacks) -- returns true if mob has died local do_states = function(self, dtime) @@ -2550,7 +2549,7 @@ local do_states = function(self, dtime) if mod_explosions then if mobs_griefing and not minetest.is_protected(pos, "") then - mcl_explosions.explode(self.object:get_pos(), self.explosion_strength, { drop_chance = 1.0 }, self.object) + mcl_explosions.explode(mcl_util.get_object_center(self.object), self.explosion_strength, { drop_chance = 1.0 }, self.object) else minetest.sound_play(self.sounds.explode, { pos = pos, diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 2beffcf8..f1648525 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -71,7 +71,7 @@ mobs:register_mob("mobs_mc:creeper", { if self._forced_explosion_countdown_timer ~= nil then self._forced_explosion_countdown_timer = self._forced_explosion_countdown_timer - dtime if self._forced_explosion_countdown_timer <= 0 then - mobs:boom(self, self.object:get_pos(), self.explosion_strength) + mobs:boom(self, mcl_util.get_object_center(self.object), self.explosion_strength) self.object:remove() end end From c907df966980a17df9a8448447817b0b064c4f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 26 Jan 2021 15:35:41 +0100 Subject: [PATCH 4/8] Tiny code style cleanup in mcl_explosions --- mods/CORE/mcl_explosions/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index 862a2f9d..723ebd24 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -377,7 +377,6 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire, -- Log explosion minetest.log('action', 'Explosion at ' .. minetest.pos_to_string(pos) .. ' with strength ' .. strength .. ' and radius ' .. radius) - end -- Create an explosion with strength at pos. @@ -404,7 +403,7 @@ function mcl_explosions.explode(pos, strength, info, puncher) local shape = sphere_shapes[radius] local creative_enabled = minetest.is_creative_enabled("") - trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, info.fire == true, puncher, creative_enabled) + trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, info.fire, puncher, creative_enabled) if not (info and info.no_particle) then add_particles(pos, radius) From 4a07b0607f0752a7b6906cfbade9409ad6243cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 26 Jan 2021 16:02:56 +0100 Subject: [PATCH 5/8] Improve API of mcl_explosions.explode Replace the 'no_sound' and 'no_particle' options in the 'info' parameter with 'sound' and 'particles'. But also has backwards compatability for the old parameter names. --- mods/CORE/mcl_explosions/init.lua | 33 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index 723ebd24..24e8d778 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -384,16 +384,20 @@ end -- Parameters: -- pos - The position where the explosion originates from -- strength - The blast strength of the explosion (a TNT explosion uses 4) --- info - Table containing information about explosion. +-- info - Table containing information about explosion -- puncher - object that is reported as source of punches/damage (optional) -- -- Values in info: -- drop_chance - If specified becomes the drop chance of all nodes in the --- explosion (defaults to 1.0 / strength) --- no_sound - If true then the explosion will not play a sound --- no_particle - If true then the explosion will not create particles +-- explosion (default: 1.0 / strength) +-- sound - If true, the explosion will play a sound (default: true) +-- particles - If true, the explosion will create particles (default: true) -- fire - If true, 1/3 nodes become fire (default: false) function mcl_explosions.explode(pos, strength, info, puncher) + if info == nil then + info = {} + end + -- The maximum blast radius (in the air) local radius = math.ceil(1.3 * strength / (0.3 * 0.75) * 0.3) @@ -402,13 +406,26 @@ function mcl_explosions.explode(pos, strength, info, puncher) end local shape = sphere_shapes[radius] - local creative_enabled = minetest.is_creative_enabled("") - trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, info.fire, puncher, creative_enabled) + local drop_chance = info.drop_change ~= nil and info.drop_change or 1 / strength + local particles = info.particles ~= nil and info.particles or true + local sound = info.sound ~= nil and info.sound or true + local fire = info.fire ~= nil and info.fire or false - if not (info and info.no_particle) then + -- For backwards compatability + if info.no_particle then + particles = false + end + if info.no_sound then + sound = false + end + + local creative_enabled = minetest.is_creative_enabled("") + trace_explode(pos, strength, shape, radius, drop_chance, fire, puncher, creative_enabled) + + if particles then add_particles(pos, radius) end - if not (info and info.no_sound) then + if sound then minetest.sound_play("tnt_explode", { pos = pos, gain = 1.0, max_hear_distance = strength * 16 From e3d22844851889d9e0af614c37abad8340666d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 26 Jan 2021 16:31:17 +0100 Subject: [PATCH 6/8] Refactor some stuff in mcl_explosions --- mods/CORE/mcl_explosions/init.lua | 42 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index 24e8d778..b50185b5 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -135,14 +135,17 @@ end -- strength - The strength of each ray -- raydirs - The directions for each ray -- radius - The maximum distance each ray will go --- drop_chance - The chance that destroyed nodes will drop their items --- fire - If true, 1/3 of destroyed nodes become fire +-- info - Table containing information about explosion -- puncher - object that punches other objects (optional) -- +-- Values in info: +-- drop_chance - The chance that destroyed nodes will drop their items +-- fire - If true, 1/3 nodes become fire +-- -- Note that this function has been optimized, it contains code which has been -- inlined to avoid function calls and unnecessary table creation. This was -- measured to give a significant performance increase. -local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire, puncher, creative_enabled) +local function trace_explode(pos, strength, raydirs, radius, info, puncher) local vm = minetest.get_voxel_manip() local emin, emax = vm:read_from_map(vector.subtract(pos, radius), @@ -164,6 +167,9 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire, local data = vm:get_data() local destroy = {} + local drop_chance = info.drop_chance + local fire = info.fire + -- Trace rays for environment destruction for i = 1, #raydirs do local rpos_x = pos.x @@ -327,7 +333,7 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire, -- Remove destroyed blocks and drop items for hash, idx in pairs(destroy) do - local do_drop = not creative_enabled and math.random() <= drop_chance + local do_drop = math.random() <= drop_chance local on_blast = node_on_blast[data[idx]] local remove = true @@ -406,26 +412,26 @@ function mcl_explosions.explode(pos, strength, info, puncher) end local shape = sphere_shapes[radius] - local drop_chance = info.drop_change ~= nil and info.drop_change or 1 / strength - local particles = info.particles ~= nil and info.particles or true - local sound = info.sound ~= nil and info.sound or true - local fire = info.fire ~= nil and info.fire or false + -- Default values + if info.drop_chance == nil then info.drop_chance = 1 / strength end + if info.particles == nil then info.particles = true end + if info.sound == nil then info.sound = true end + if info.fire == nil then info.fire = false end -- For backwards compatability - if info.no_particle then - particles = false - end - if info.no_sound then - sound = false - end + if info.no_particle then info.particles = false end + if info.no_sound then info.sound = false end - local creative_enabled = minetest.is_creative_enabled("") - trace_explode(pos, strength, shape, radius, drop_chance, fire, puncher, creative_enabled) + -- Dont do drops in creative mode + if minetest.is_creative_enabled("") then + info.drop_chance = 0 + end + trace_explode(pos, strength, shape, radius, info, puncher) - if particles then + if info.particles then add_particles(pos, radius) end - if sound then + if info.sound then minetest.sound_play("tnt_explode", { pos = pos, gain = 1.0, max_hear_distance = strength * 16 From 34274486c797fe5198d0b575576d6c4443783561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 26 Jan 2021 16:33:45 +0100 Subject: [PATCH 7/8] Add griefing option to mcl_explosions.explode When set to false explosions will only affect entities and not destroy nodes. --- mods/CORE/mcl_explosions/init.lua | 57 +++++++++++++++++-------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index b50185b5..c18ac316 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -141,6 +141,7 @@ end -- Values in info: -- drop_chance - The chance that destroyed nodes will drop their items -- fire - If true, 1/3 nodes become fire +-- griefing - If true, the explosion will destroy nodes (default: true) -- -- Note that this function has been optimized, it contains code which has been -- inlined to avoid function calls and unnecessary table creation. This was @@ -171,38 +172,40 @@ local function trace_explode(pos, strength, raydirs, radius, info, puncher) local fire = info.fire -- Trace rays for environment destruction - for i = 1, #raydirs do - local rpos_x = pos.x - local rpos_y = pos.y - local rpos_z = pos.z - local rdir_x = raydirs[i].x - local rdir_y = raydirs[i].y - local rdir_z = raydirs[i].z - local rstr = (0.7 + math.random() * 0.6) * strength + if info.griefing then + for i = 1, #raydirs do + local rpos_x = pos.x + local rpos_y = pos.y + local rpos_z = pos.z + local rdir_x = raydirs[i].x + local rdir_y = raydirs[i].y + local rdir_z = raydirs[i].z + local rstr = (0.7 + math.random() * 0.6) * strength - for r = 0, math.ceil(radius * (1.0 / STEP_LENGTH)) do - local npos_x = math.floor(rpos_x + 0.5) - local npos_y = math.floor(rpos_y + 0.5) - local npos_z = math.floor(rpos_z + 0.5) - local idx = (npos_z - emin_z) * zstride + (npos_y - emin_y) * ystride + - npos_x - emin_x + 1 + for r = 0, math.ceil(radius * (1.0 / STEP_LENGTH)) do + local npos_x = math.floor(rpos_x + 0.5) + local npos_y = math.floor(rpos_y + 0.5) + local npos_z = math.floor(rpos_z + 0.5) + local idx = (npos_z - emin_z) * zstride + (npos_y - emin_y) * ystride + + npos_x - emin_x + 1 - local cid = data[idx] - local br = node_blastres[cid] - local hash = minetest.hash_node_position({x=npos_x, y=npos_y, z=npos_z}) + local cid = data[idx] + local br = node_blastres[cid] + local hash = minetest.hash_node_position({x=npos_x, y=npos_y, z=npos_z}) - rpos_x = rpos_x + STEP_LENGTH * rdir_x - rpos_y = rpos_y + STEP_LENGTH * rdir_y - rpos_z = rpos_z + STEP_LENGTH * rdir_z + rpos_x = rpos_x + STEP_LENGTH * rdir_x + rpos_y = rpos_y + STEP_LENGTH * rdir_y + rpos_z = rpos_z + STEP_LENGTH * rdir_z - rstr = rstr - 0.75 * STEP_LENGTH - (br + 0.3) * STEP_LENGTH + rstr = rstr - 0.75 * STEP_LENGTH - (br + 0.3) * STEP_LENGTH - if rstr <= 0 then - break - end + if rstr <= 0 then + break + end - if cid ~= minetest.CONTENT_AIR and not minetest.is_protected({x = npos_x, y = npos_y, z = npos_z}, "") then - destroy[hash] = idx + if cid ~= minetest.CONTENT_AIR and not minetest.is_protected({x = npos_x, y = npos_y, z = npos_z}, "") then + destroy[hash] = idx + end end end end @@ -399,6 +402,7 @@ end -- sound - If true, the explosion will play a sound (default: true) -- particles - If true, the explosion will create particles (default: true) -- fire - If true, 1/3 nodes become fire (default: false) +-- griefing - If true, the explosion will destroy nodes (default: true) function mcl_explosions.explode(pos, strength, info, puncher) if info == nil then info = {} @@ -417,6 +421,7 @@ function mcl_explosions.explode(pos, strength, info, puncher) if info.particles == nil then info.particles = true end if info.sound == nil then info.sound = true end if info.fire == nil then info.fire = false end + if info.griefing == nil then info.griefing = true end -- For backwards compatability if info.no_particle then info.particles = false end From 948438bd1ce0ffbf30284ac0bfddfa6c75ebcadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Tue, 26 Jan 2021 16:57:18 +0100 Subject: [PATCH 8/8] Add max_blast_resistance to mcl_explosions.explode If the option is specified, then the explosion will treat all non-indestructible nodes as having a blast resistance of no more than the value of the option. --- mods/CORE/mcl_explosions/init.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index c18ac316..b2348986 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -32,6 +32,10 @@ local STEP_LENGTH = 0.3 -- How many rays to compute entity exposure to explosion local N_EXPOSURE_RAYS = 16 +-- Nodes having a blast resistance of this value or higher are treated as +-- indestructible +local INDESTRUCT_BLASTRES = 1000000 + minetest.register_on_mods_loaded(function() -- Store blast resistance values by content ids to improve performance. for name, def in pairs(minetest.registered_nodes) do @@ -142,6 +146,9 @@ end -- drop_chance - The chance that destroyed nodes will drop their items -- fire - If true, 1/3 nodes become fire -- griefing - If true, the explosion will destroy nodes (default: true) +-- max_blast_resistance - The explosion will treat all non-indestructible nodes +-- as having a blast resistance of no more than this +-- value -- -- Note that this function has been optimized, it contains code which has been -- inlined to avoid function calls and unnecessary table creation. This was @@ -170,6 +177,7 @@ local function trace_explode(pos, strength, raydirs, radius, info, puncher) local drop_chance = info.drop_chance local fire = info.fire + local max_blast_resistance = info.max_blast_resistance -- Trace rays for environment destruction if info.griefing then @@ -191,6 +199,10 @@ local function trace_explode(pos, strength, raydirs, radius, info, puncher) local cid = data[idx] local br = node_blastres[cid] + if br < INDESTRUCT_BLASTRES and br > max_blast_resistance then + br = max_blast_resistance + end + local hash = minetest.hash_node_position({x=npos_x, y=npos_y, z=npos_z}) rpos_x = rpos_x + STEP_LENGTH * rdir_x @@ -399,6 +411,9 @@ end -- Values in info: -- drop_chance - If specified becomes the drop chance of all nodes in the -- explosion (default: 1.0 / strength) +-- max_blast_resistance - If specified the explosion will treat all +-- non-indestructible nodes as having a blast resistance +-- of no more than this value -- sound - If true, the explosion will play a sound (default: true) -- particles - If true, the explosion will create particles (default: true) -- fire - If true, 1/3 nodes become fire (default: false) @@ -422,8 +437,11 @@ function mcl_explosions.explode(pos, strength, info, puncher) if info.sound == nil then info.sound = true end if info.fire == nil then info.fire = false end if info.griefing == nil then info.griefing = true end + if info.max_blast_resistance == nil then + info.max_blast_resistance = INDESTRUCT_BLASTRES + end - -- For backwards compatability + -- For backwards compatibility if info.no_particle then info.particles = false end if info.no_sound then info.sound = false end @@ -431,6 +449,7 @@ function mcl_explosions.explode(pos, strength, info, puncher) if minetest.is_creative_enabled("") then info.drop_chance = 0 end + trace_explode(pos, strength, shape, radius, info, puncher) if info.particles then