From 99c9c18ed86072966d79758f1398f5c426f96337 Mon Sep 17 00:00:00 2001 From: Duane Date: Fri, 24 Jun 2016 11:07:24 -0500 Subject: [PATCH] Add an option for non-violent explosions. --- abms.lua | 49 ++++++++++++++++++++++++++++++++---------------- init.lua | 1 + settingtypes.txt | 3 +++ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/abms.lua b/abms.lua index ddbc716..07e1600 100644 --- a/abms.lua +++ b/abms.lua @@ -2,8 +2,6 @@ -- Abms ------------------------------------------------------------------- --- see also, fungal_tree.lua - -- player surface damage and hunger local dps_delay = 3 @@ -26,11 +24,21 @@ for i = 1, 4 do fungal_tree_leaves[#fungal_tree_leaves+1] = "fun_caves:fungal_tree_leaves_"..i end -local leaves = {} +local is_fungal_leaf = {} for _, leaf in ipairs(fungal_tree_leaves) do - leaves[leaf] = true + is_fungal_leaf[leaf] = true end +local fungal_nodes = {} +for _, leaf in pairs(fungal_tree_leaves) do + fungal_nodes[#fungal_nodes+1] = {name = leaf} +end +fungal_nodes[#fungal_nodes+1] = {name = 'fun_caves:fungal_tree_fruit'} + +local fungi_to_explode = {} -- see below +local exploding_fungi = fun_caves.exploding_fungi + + -- hot spike parameters local spike_air = {} spike_air['default:lava_source'] = true @@ -323,11 +331,6 @@ minetest.register_abm({ }) -- fungal spread -local fungal_nodes = {} -for _, leaf in pairs(fungal_tree_leaves) do - fungal_nodes[#fungal_nodes+1] = {name = leaf} -end -fungal_nodes[#fungal_nodes+1] = {name = 'fun_caves:fungal_tree_fruit'} minetest.register_abm({ nodenames = fungal_tree_leaves, neighbors = {"air", "group:liquid"}, @@ -352,7 +355,7 @@ minetest.register_abm({ if grow_node and grow_node.name == "air" and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then minetest.set_node(grow_pos, node) return - elseif grow_node and leaves[grow_node.name] and grow_node.name ~= node.name then + elseif grow_node and is_fungal_leaf[grow_node.name] and grow_node.name ~= node.name then minetest.remove_node(grow_pos) return end @@ -578,6 +581,15 @@ minetest.after(0, function() on_blast = def.on_blast, } end + + -- This also has to be done after content ids are established. + for i = 1, 4 do + fungi_to_explode[minetest.get_content_id("fun_caves:fungal_tree_leaves_"..i)] = true + end + fungi_to_explode[minetest.get_content_id('fun_caves:fungal_tree_fruit')] = true + fungi_to_explode[minetest.get_content_id('fun_caves:giant_mushroom_cap')] = true + fungi_to_explode[minetest.get_content_id('fun_caves:giant_mushroom_stem')] = true + fungi_to_explode[minetest.get_content_id('fun_caves:huge_mushroom_cap')] = true end) local function add_effects(pos, radius) @@ -613,7 +625,9 @@ local function destroy(pos, cid) return end - minetest.remove_node(pos) + if exploding_fungi or fungi_to_explode[cid] then + minetest.remove_node(pos) + end end local function explode(pos, radius) @@ -625,7 +639,6 @@ local function explode(pos, radius) local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) local data = vm:get_data() - local drops = {} local p = {} local c_air = minetest.get_content_id("air") @@ -647,7 +660,7 @@ local function explode(pos, radius) end vi = vi + 1 end - end + end end end @@ -697,12 +710,16 @@ fun_caves.soft_boom = function(pos) return end - minetest.sound_play("tnt_explode", {pos=pos, gain=1.5, max_hear_distance=2*64}) + if exploding_fungi then + minetest.sound_play("tnt_explode", {pos=pos, gain=1.5, max_hear_distance=2*64}) + end local radius = 5 minetest.remove_node(pos) explode(pos, radius) - entity_physics(pos, radius) - add_effects(pos, radius) + if exploding_fungi then + entity_physics(pos, radius) + add_effects(pos, radius) + end end --local function burn(pos) diff --git a/init.lua b/init.lua index ebe37d4..7455003 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ fun_caves.path = minetest.get_modpath(minetest.get_current_modname()) fun_caves.world = minetest.get_worldpath() fun_caves.elixir_armor = minetest.setting_getbool('fun_caves_use_armor_elixirs') fun_caves.expire_elixir_on_death = minetest.setting_getbool('fun_caves_expire_elixir_on_death') +fun_caves.exploding_fungi = minetest.setting_getbool('fun_caves_exploding_fungi') fun_caves.DEBUG = false -- for maintenance only diff --git a/settingtypes.txt b/settingtypes.txt index d6f14aa..7c8261e 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -3,3 +3,6 @@ fun_caves_use_armor_elixirs (Use Armor Elixirs) bool true # If set, you will lose the effects of elixirs when you die. fun_caves_expire_elixir_on_death (Elixirs Expire On Death) bool true + +# Unset this to remove exploding fungi from the underworld. +fun_caves_exploding_fungi (Exploding Fungi) bool true