From 2c322977a6413c8df218f5a6bf8d710f44de0da3 Mon Sep 17 00:00:00 2001 From: bzoss Date: Fri, 12 Jun 2020 19:11:06 -0400 Subject: [PATCH] Add invisibility potion - includes splash and plus --- mods/ITEMS/mcl_brewing/init.lua | 2 +- mods/ITEMS/mcl_potions/init.lua | 63 ++++++++++++++++++++++++- mods/ITEMS/mcl_potions/invisibility.lua | 28 +++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 mods/ITEMS/mcl_potions/invisibility.lua diff --git a/mods/ITEMS/mcl_brewing/init.lua b/mods/ITEMS/mcl_brewing/init.lua index 4e93d87925..73ddb9840d 100755 --- a/mods/ITEMS/mcl_brewing/init.lua +++ b/mods/ITEMS/mcl_brewing/init.lua @@ -134,7 +134,7 @@ local function brewing_stand_timer(pos, elapsed) -- return 1 -- end -- end - brew_output = brewable(inv) + local brew_output = brewable(inv) if fuel ~= 0 and brew_output then fuel_timer = fuel_timer + elapsed diff --git a/mods/ITEMS/mcl_potions/init.lua b/mods/ITEMS/mcl_potions/init.lua index c5273bcd27..54c7bcf55e 100644 --- a/mods/ITEMS/mcl_potions/init.lua +++ b/mods/ITEMS/mcl_potions/init.lua @@ -1,4 +1,8 @@ local S = minetest.get_translator("mcl_potions") +mcl_potions = {} + +local modpath = minetest.get_modpath("mcl_potions") +dofile(modpath .. "/invisibility.lua") local brewhelp = S("Put this item in an item frame for decoration. It's useless otherwise.") @@ -770,6 +774,53 @@ minetest.register_craftitem("mcl_potions:regeneration_plus", { end }) +local invisiblility_func = function(player, duration) + invisible(player, true) + minetest.after(duration, function() mcl_potions.invisible(player, false) end ) +end + +minetest.register_craftitem("mcl_potions:invisibility", { + description = S("Invisibility Potion"), + _doc_items_longdesc = brewhelp, + wield_image = potion_image("#B0B0B0"), + inventory_image = potion_image("#B0B0B0"), + groups = { brewitem = 1, food = 0 }, + stack_max = 1, + + on_place = function(itemstack, user, pointed_thing) + invisiblility_func(user, 180) + _use_potion() + return itemstack + end, + + on_secondary_use = function(itemstack, user, pointed_thing) + invisiblility_func(user, 180) + _use_potion() + return itemstack + end +}) + +minetest.register_craftitem("mcl_potions:invisibility_plus", { + description = S("Invisibility Potion +"), + _doc_items_longdesc = brewhelp, + wield_image = potion_image("#A0A0A0"), + inventory_image = potion_image("#A0A0A0"), + groups = { brewitem = 1, food = 0 }, + stack_max = 1, + + on_place = function(itemstack, user, pointed_thing) + invisiblility_func(user, 480) + _use_potion() + return itemstack + end, + + on_secondary_use = function(itemstack, user, pointed_thing) + invisiblility_func(user, 480) + _use_potion() + return itemstack + end +}) + -- Look into reducing attack on punch minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) if puncher:get_attribute("weakness") then @@ -908,6 +959,15 @@ register_splash("regeneration_2", "Splash Regeneration II", "#B52CC2", { register_splash("regeneration_plus", "Splash Regeneration +", "#C53DD3", { potion_fun = function(player) regeneration_func(player, 0.85, 180) end }) + +register_splash("invisibility", "Splash Invisibility", "#B0B0B0", { + potion_fun = function(player) invisiblility_func(player, 135) end +}) + +register_splash("invisibility", "Splash Invisibility", "#A0A0A0", { + potion_fun = function(player) invisiblility_func(player, 300) end +}) + -- duration effects of redstone are a factor of 8/3 -- duration effects of glowstone are a time factor of 1/2 and effect of 14/12 -- splash potion effects are reduced by a factor of 3/4 @@ -958,7 +1018,8 @@ local inversion_table = { ["mcl_potions:swiftness_plus"] = "mlc_potions:slowness_plus", ["mcl_potions:leaping"] = "mcl_potions:slowness", ["mcl_potions:leaping_2"] = "mcl_potions:slowness_plus", - ["mcl_potions:leaping_plus"] = "mlc_potions:slowness_plus", + ["mcl_potions:leaping_plus"] = "mcl_potions:slowness_plus", + ["mcl_potions:night_vision"] = "mcl_potions:invisibility", } diff --git a/mods/ITEMS/mcl_potions/invisibility.lua b/mods/ITEMS/mcl_potions/invisibility.lua new file mode 100644 index 0000000000..f7311c2172 --- /dev/null +++ b/mods/ITEMS/mcl_potions/invisibility.lua @@ -0,0 +1,28 @@ +-- invisibility function +invisibility = {} + +-- reset player invisibility if they go offline +minetest.register_on_leaveplayer(function(player) + + local name = player:get_player_name() + if invisibility[name] then + invisibility[name] = nil + end + +end) + +invisible = function(player, toggle) + + if not player then return false end + + invisibility[player:get_player_name()] = toggle + + if toggle then -- hide player + player:set_properties({visual_size = {x = 0, y = 0}}) + player:set_nametag_attributes({color = {a = 0}}) + else -- show player + player:set_properties({visual_size = {x = 1, y = 1}}) + player:set_nametag_attributes({color = {a = 255}}) + end + +end