From 1f8488aba5c68e27dec7aeae46597ae8a1fee2b6 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 5 Aug 2020 18:33:53 +0200 Subject: [PATCH] Make throwable water bottles useful --- mods/ENTITIES/mobs_mc/blaze.lua | 2 +- mods/ENTITIES/mobs_mc/enderman.lua | 1 + mods/ENTITIES/mobs_mc/snowman.lua | 1 + mods/ITEMS/mcl_potions/functions.lua | 26 +++++++++++++++++++++ mods/ITEMS/mcl_potions/init.lua | 35 +++++++++++++++++++++++++--- mods/ITEMS/mcl_potions/lingering.lua | 19 +++++++++++---- mods/ITEMS/mcl_potions/splash.lua | 6 ++++- 7 files changed, 81 insertions(+), 9 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index 8231148e..cbba537d 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -22,7 +22,7 @@ mobs:register_mob("mobs_mc:blaze", { textures = { {"mobs_mc_blaze.png"}, }, - armor = { fleshy = 100, snowball_vulnerable = 100 }, + armor = { fleshy = 100, snowball_vulnerable = 100, water_vulnerable = 100 }, visual_size = {x=3, y=3}, sounds = { random = "mobs_mc_blaze_breath", diff --git a/mods/ENTITIES/mobs_mc/enderman.lua b/mods/ENTITIES/mobs_mc/enderman.lua index aab690e0..3ecff4e3 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -520,6 +520,7 @@ mobs:register_mob("mobs_mc:enderman", { end end end, + armor = { fleshy = 100, water_vulnerable = 100 }, water_damage = 8, view_range = 64, fear_height = 4, diff --git a/mods/ENTITIES/mobs_mc/snowman.lua b/mods/ENTITIES/mobs_mc/snowman.lua index b9686ba5..02c1178e 100644 --- a/mods/ENTITIES/mobs_mc/snowman.lua +++ b/mods/ENTITIES/mobs_mc/snowman.lua @@ -31,6 +31,7 @@ mobs:register_mob("mobs_mc:snowman", { fall_damage = 0, water_damage = 4, rain_damage = 4, + armor = { fleshy = 100, water_vulnerable = 100 }, attacks_monsters = true, collisionbox = {-0.35, -0.01, -0.35, 0.35, 1.89, 0.35}, visual = "mesh", diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 0df06d15..11e579a5 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -747,3 +747,29 @@ function mcl_potions.night_vision_func(player, null, duration) end end + +function mcl_potions._extinguish_nearby_fire(pos) + local epos = {x=pos.x, y=pos.y+0.5, z=pos.z} + local dnode = minetest.get_node({x=pos.x,y=pos.y-0.5,z=pos.z}) + if minetest.get_item_group(dnode.name, "fire") ~= 0 then + epos.y = pos.y - 0.5 + end + local dirs = { + {x=0,y=0,z=0}, + {x=0,y=0,z=-1}, + {x=0,y=0,z=1}, + {x=-1,y=0,z=0}, + {x=1,y=0,z=0}, + } + local exting = false + for d=1, #dirs do + local tpos = vector.add(epos, dirs[d]) + local node = minetest.get_node(tpos) + if minetest.get_item_group(node.name, "fire") ~= 0 then + minetest.sound_play("fire_extinguish_flame", {pos = tpos, gain = 0.25, max_hear_distance = 16}, true) + minetest.remove_node(tpos) + exting = true + end + end + return exting +end diff --git a/mods/ITEMS/mcl_potions/init.lua b/mods/ITEMS/mcl_potions/init.lua index eb23d66f..1fd99771 100644 --- a/mods/ITEMS/mcl_potions/init.lua +++ b/mods/ITEMS/mcl_potions/init.lua @@ -277,9 +277,38 @@ minetest.register_craftitem("mcl_potions:river_water", { }) --- TODO: Extinguish fire, damage mobs -mcl_potions.register_splash("water", S("Splash Water Bottle"), "#0022FF", {tt=S("No effect"), potion_fun=function() end}) -mcl_potions.register_lingering("water", S("Lingering Water Bottle"), "#0022FF", {tt=S("No effect"), potion_fun=function() end}) +-- Hurt mobs +local water_splash = function(obj, damage) + if not obj then + return + end + if not damage or (damage > 0 and damage < 1) then + damage = 1 + end + -- Damage mobs that are vulnerable to water + local lua = obj:get_luaentity() + if lua and lua._cmi_is_mob then + obj:punch(obj, 1.0, { + full_punch_interval = 1.0, + damage_groups = {water_vulnerable=damage}, + }, nil) + end +end + +mcl_potions.register_splash("water", S("Splash Water Bottle"), "#0022FF", { + tt=S("Extinguishes fire and hurts some mobs"), + longdesc=S("A throwable water bottle that will shatter on impact, where it extinguishes nearby fire and hurts mobs that are vulnerable to water."), + no_effect=true, + potion_fun=water_splash, + effect=1 +}) +mcl_potions.register_lingering("water", S("Lingering Water Bottle"), "#0022FF", { + tt=S("Extinguishes fire and hurts some mobs"), + longdesc=S("A throwable water bottle that will shatter on impact, where it extinguishes nearby fire and hurts mobs that are vulnerable to water."), + no_effect=true, + potion_fun=water_splash, + effect=1 +}) minetest.register_craftitem("mcl_potions:speckled_melon", { description = S("Glistering Melon"), diff --git a/mods/ITEMS/mcl_potions/lingering.lua b/mods/ITEMS/mcl_potions/lingering.lua index 318d51a6..beb838ba 100644 --- a/mods/ITEMS/mcl_potions/lingering.lua +++ b/mods/ITEMS/mcl_potions/lingering.lua @@ -10,9 +10,9 @@ end local lingering_effect_at = {} -local function add_lingering_effect(pos, color, def) +local function add_lingering_effect(pos, color, def, is_water) - lingering_effect_at[pos] = {color = color, timer = 30, def = def} + lingering_effect_at[pos] = {color = color, timer = 30, def = def, is_water = is_water} end @@ -46,6 +46,14 @@ minetest.register_globalstep(function(dtime) texture = "mcl_potions_sprite.png^[colorize:"..vals.color..":127", }) + -- Extingish fire if water bottle + if vals.is_water then + if mcl_potions._extinguish_nearby_fire(pos) then + vals.timer = vals.timer / 2 + end + end + + -- Affect players and mobs for _, obj in pairs(minetest.get_objects_inside_radius(pos, d)) do local entity = obj:get_luaentity() @@ -114,13 +122,13 @@ function mcl_potions.register_lingering(name, descr, color, def) visual_size = {x=w/2,y=w/2}, collisionbox = {0,0,0,0,0,0}, on_step = function(self, dtime) - local pos = self.object:getpos() + local pos = self.object:get_pos() local node = minetest.get_node(pos) local n = node.name local d = 4 if n ~= "air" and n ~= "mcl_portals:portal" and n ~= "mcl_portals:portal_end" or mcl_potions.is_obj_hit(self, pos) then minetest.sound_play("mcl_potions_breaking_glass", {pos = pos, max_hear_distance = 16, gain = 1}) - add_lingering_effect(pos, color, def) + add_lingering_effect(pos, color, def, name == "water") minetest.add_particlespawner({ amount = 40, time = 1, @@ -138,6 +146,9 @@ function mcl_potions.register_lingering(name, descr, color, def) vertical = false, texture = "mcl_potions_sprite.png^[colorize:"..color..":127", }) + if name == "water" then + mcl_potions._extinguish_nearby_fire(pos) + end self.object:remove() end end, diff --git a/mods/ITEMS/mcl_potions/splash.lua b/mods/ITEMS/mcl_potions/splash.lua index 779c75ac..008cfa97 100644 --- a/mods/ITEMS/mcl_potions/splash.lua +++ b/mods/ITEMS/mcl_potions/splash.lua @@ -56,7 +56,7 @@ function mcl_potions.register_splash(name, descr, color, def) visual_size = {x=w/2,y=w/2}, collisionbox = {0,0,0,0,0,0}, on_step = function(self, dtime) - local pos = self.object:getpos() + local pos = self.object:get_pos() local node = minetest.get_node(pos) local n = node.name local d = 2 @@ -80,6 +80,10 @@ function mcl_potions.register_splash(name, descr, color, def) vertical = false, texture = "mcl_potions_sprite.png^[colorize:"..color..":127", }) + + if name == "water" then + mcl_potions._extinguish_nearby_fire(pos) + end self.object:remove() for _,obj in pairs(minetest.get_objects_inside_radius(pos, 4)) do