From 11f566fc1fc5ebb9faad3454784e24451c5993d2 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sat, 26 May 2018 22:14:09 -0600 Subject: [PATCH] import radiant_damage code to handle different height snareweed nodes --- config.lua | 2 ++ depends.txt | 3 +-- features/snareweed.lua | 35 +++++++++++++++++++++++------------ settingtypes.txt | 1 + 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/config.lua b/config.lua index 79b5544..83f6bee 100644 --- a/config.lua +++ b/config.lua @@ -65,6 +65,8 @@ end setting("float", "glow_worm_delay_multiplier", 10.0, "glow worm growth delay multiplier") setting("bool", "light_kills_fungus", true, "Light kills fungus") +setting("bool", "snareweed_damage", true, "Snareweed causes damage to players") + --Caverns setting("float", "vertical_cavern_scale", 256, "Vertical cavern dimension scale") diff --git a/depends.txt b/depends.txt index e03b9dd..c333993 100644 --- a/depends.txt +++ b/depends.txt @@ -8,5 +8,4 @@ wool? magma_conduits? intllib? doc? -simplecrafting_lib? -radiant_damage? \ No newline at end of file +simplecrafting_lib? \ No newline at end of file diff --git a/features/snareweed.lua b/features/snareweed.lua index a1f7ee3..799ba84 100644 --- a/features/snareweed.lua +++ b/features/snareweed.lua @@ -17,18 +17,29 @@ minetest.register_node("dfcaverns:snareweed", { sounds = default.node_sound_dirt_defaults(), }) -if minetest.get_modpath("radiant_damage") then - radiant_damage.register_radiant_damage({ - damage_name = "snareweed", -- a string used in logs to identify the type of damage dealt - interval = 1, -- number of seconds between each damage check - range = 5, -- range of the damage. Can be omitted if inverse_square_falloff is true, in that case it defaults to the range at which 1 point of damage is done. - inverse_square_falloff = false, -- if true, damage falls off with the inverse square of the distance. If false, damage is constant within the range. - damage = 2, -- number of damage points dealt each interval - nodenames = {"dfcaverns:snareweed"}, -- nodes that cause this damage. Same format as the nodenames parameter for minetest.find_nodes_in_area - occlusion = false, -- if true, damaging effect only passes through air. Other nodes will cast "shadows". - above_only = true, -- if true, damage only propagates directly upward. - cumulative = false, -- if true, all nodes within range do damage. If false, only the nearest one does damage. - }) +if dfcaverns.config.snareweed_damage then + local timer = 0 + + minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer >= 1 then + timer = timer - 1 + for _, player in pairs(minetest.get_connected_players()) do + local player_pos = player:getpos() -- node player's feet are in this location. + local rounded_pos = vector.round(player_pos) + nearby_nodes = minetest.find_nodes_in_area(vector.add(rounded_pos, {x=0, y= -8, z=0}), rounded_pos, {"dfcaverns:snareweed"}) + for _, node_pos in ipairs(nearby_nodes) do + local node = minetest.get_node(node_pos) + local distance = player_pos.y - node_pos.y + if distance <= node.param2/16 then + minetest.log("action", player:get_player_name() .. " takes 2 damage from snareweed") + player:set_hp(player:get_hp() - 2) + break + end + end + end + end + end) end diff --git a/settingtypes.txt b/settingtypes.txt index 2390f0b..46968c9 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -22,6 +22,7 @@ dfcaverns_sweet_pod_delay_multiplier (sweet_pod growth delay multiplier) float 2 #To disable glow worm growth, set this to 0. dfcaverns_glow_worm_delay_multiplier (glow worm growth delay multiplier) float 10 dfcaverns_light_kills_fungus (Light kills fungus) bool true +dfcaverns_snareweed_damage (Snareweed causes damage to player) bool true [Cavern dimensions] #Note that this doesn't guarantee caverns of this setting's size. This setting