From d9e78e8ad902129429e3dc6c74084a4841dd7863 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 18 Jun 2020 17:59:36 -0400 Subject: [PATCH] Add water breathing. --- mods/ITEMS/mcl_potions/functions.lua | 10 +++++++ mods/ITEMS/mcl_potions/init.lua | 6 ++-- mods/ITEMS/mcl_potions/potions.lua | 43 ++++++++++++++++++++++++++++ mods/ITEMS/mcl_potions/splash.lua | 10 ++++++- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 56833faf7f..d66e49d58e 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -81,3 +81,13 @@ function mcl_potions.invisiblility_func(player, duration) mcl_potions.invisible(player, true) minetest.after(duration, function() mcl_potions.invisible(player, false) end ) end + +function mcl_potions.water_breathing_func(player, duration) + if minetest.is_player(player) then + + for i=1,math.floor(duration) do + minetest.after(i, function() player:set_breath(10) end ) + end + end + +end diff --git a/mods/ITEMS/mcl_potions/init.lua b/mods/ITEMS/mcl_potions/init.lua index 2e31316c65..46d4eb464f 100644 --- a/mods/ITEMS/mcl_potions/init.lua +++ b/mods/ITEMS/mcl_potions/init.lua @@ -303,7 +303,7 @@ local awkward_table = { ["mcl_fishing:pufferfish_raw"] = "mcl_potions:water_breathing", --add craft ["mcl_mobitems:ghast_tear"] = "mcl_potions:regeneration", --add craft ["mcl_mobitems:spider_eye"] = "mcl_potions:poison", --add craft - ["mcl_mobitems:rabbit_foot"] = "mcl_potions:leaping", --add craft + ["mcl_mobitems:rabbit_foot"] = "mcl_potions:leaping", } local output_table = { @@ -316,11 +316,11 @@ local output_table = { local enhancement_table = {} local extension_table = {} local potions = {"awkward", "mundane", "thick"} -for i, potion in ipairs({"healing","harming","swiftness","leaping","poison","regeneration","invisibility","weakness"}) do +for i, potion in ipairs({"healing","harming","swiftness","leaping","poison","regeneration","invisibility","weakness","water_breathing"}) do table.insert(potions, potion) - if potion ~= "invisibility" and potion ~= "night_vision" and potion ~= "weakness" then + if potion ~= "invisibility" and potion ~= "night_vision" and potion ~= "weakness" and potion ~= "water_breathing" then enhancement_table["mcl_potions:"..potion] = "mcl_potions:"..potion.."_2" enhancement_table["mcl_potions:"..potion.."_splash"] = "mcl_potions:"..potion.."_2_splash" table.insert(potions, potion.."_2") diff --git a/mods/ITEMS/mcl_potions/potions.lua b/mods/ITEMS/mcl_potions/potions.lua index bdae4326cb..b39a185919 100644 --- a/mods/ITEMS/mcl_potions/potions.lua +++ b/mods/ITEMS/mcl_potions/potions.lua @@ -548,3 +548,46 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) print("Weakness Active") end end) + + +minetest.register_craftitem("mcl_potions:water_breathing", { + description = S("Water Breathing Potion"), + _doc_items_longdesc = brewhelp, + wield_image = potion_image("#0000AA"), + inventory_image = potion_image("#0000AA"), + groups = { brewitem = 1, food = 0 }, + stack_max = 1, + + on_place = function(itemstack, user, pointed_thing) + mcl_potions.water_breathing_func(user, 180) + mcl_potions._use_potion(itemstack) + return itemstack + end, + + on_secondary_use = function(itemstack, user, pointed_thing) + mcl_potions.water_breathing_func(user, 180) + mcl_potions._use_potion(itemstack) + return itemstack + end +}) + +minetest.register_craftitem("mcl_potions:water_breathing_plus", { + description = S("Water Breathing Potion +"), + _doc_items_longdesc = brewhelp, + wield_image = potion_image("#0000CC"), + inventory_image = potion_image("#0000CC"), + groups = { brewitem = 1, food = 0 }, + stack_max = 1, + + on_place = function(itemstack, user, pointed_thing) + mcl_potions.water_breathing_func(user, 480) + mcl_potions._use_potion(itemstack) + return itemstack + end, + + on_secondary_use = function(itemstack, user, pointed_thing) + mcl_potions.water_breathing_func(user, 480) + mcl_potions._use_potion(itemstack) + return itemstack + end +}) diff --git a/mods/ITEMS/mcl_potions/splash.lua b/mods/ITEMS/mcl_potions/splash.lua index 4543386f93..ce39e795eb 100644 --- a/mods/ITEMS/mcl_potions/splash.lua +++ b/mods/ITEMS/mcl_potions/splash.lua @@ -171,7 +171,7 @@ register_splash("invisibility", "Splash Invisibility", "#B0B0B0", { }) register_splash("invisibility_plus", "Splash Invisibility +", "#A0A0A0", { - potion_fun = function(player, redx) mcl_potions.invisiblility_func(player, 300*redx) end + potion_fun = function(player, redx) mcl_potions.invisiblility_func(player, 360*redx) end }) register_splash("weakness", "Splash Weakness", "#6600AA", { @@ -181,3 +181,11 @@ register_splash("weakness", "Splash Weakness", "#6600AA", { register_splash("weakness_plus", "Splash Weakness +", "#7700BB", { potion_fun = function(player, redx) mcl_potions.weakness_func(player, 1.4, 180*redx) end }) + +register_splash("water_breathing", "Splash Water Breathing", "#0000AA", { + potion_fun = function(player, redx) mcl_potions.water_breathing_func(player, 135*redx) end +}) + +register_splash("water_breathing_plus", "Splash Water Breathing +", "#0000CC", { + potion_fun = function(player, redx) mcl_potions.water_breathing_func(player, 360*redx) end +})