From 44536dd75dfc350fc7868b5c47d9d397343c1302 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 20 Jun 2020 21:30:26 -0400 Subject: [PATCH] put some rudementary night vision together --- mods/ITEMS/mcl_potions/functions.lua | 44 ++++++++++++++++++++++++++-- mods/ITEMS/mcl_potions/potions.lua | 16 +++++----- mods/ITEMS/mcl_potions/splash.lua | 4 +-- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 26b57262dd..1c32b52333 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -6,8 +6,9 @@ local is_weak = {} local is_water_breathing = {} local is_leaping = {} local is_swift = {} +local is_cat = {} + -local timer = 0 minetest.register_globalstep(function(dtime) -- Check for invisible players @@ -155,6 +156,28 @@ minetest.register_globalstep(function(dtime) end + -- Check for Night Vision equipped players + for player, vals in pairs(is_cat) do + + if is_cat[player] and player:get_properties() then + + player = player or player:get_luaentity() + + is_cat[player].timer = is_cat[player].timer + dtime + + if player:get_pos() then mcl_potions._add_spawner(player, "#1010AA") end + player:override_day_night_ratio(0.45) + + if is_cat[player].timer >= is_cat[player].dur then + is_cat[player] = nil + end + + elseif not player:get_properties() then + is_cat[player] = nil + end + + end + end ) -- reset player is_invisible/poison if they go offline @@ -194,6 +217,10 @@ minetest.register_on_leaveplayer(function(player) is_swift[player] = nil end + if is_cat[player] then + is_cat[player] = nil + end + end) function mcl_potions.make_invisible(player, toggle) @@ -425,5 +452,18 @@ end function mcl_potions.night_vision_func(player, duration) - player:override_day_night_ratio(0.45) + + if not is_cat[player] then + + is_cat[player] = {dur = duration, timer = 0} + + else + + local victim = is_cat[player] + + victim.dur = math.max(duration, victim.dur - victim.timer) + victim.timer = 0 + + end + end diff --git a/mods/ITEMS/mcl_potions/potions.lua b/mods/ITEMS/mcl_potions/potions.lua index 57a2c6014d..26036e146b 100644 --- a/mods/ITEMS/mcl_potions/potions.lua +++ b/mods/ITEMS/mcl_potions/potions.lua @@ -152,20 +152,20 @@ minetest.register_craftitem("mcl_potions:harming_2", { minetest.register_craftitem("mcl_potions:night_vision", { description = S("Night Vision Potion"), _doc_items_longdesc = brewhelp, - wield_image = potion_image("#009999"), - inventory_image = potion_image("#009999"), + wield_image = potion_image("#1010AA"), + inventory_image = potion_image("#1010AA"), groups = { brewitem = 1, food=0}, stack_max = 1, on_place = function(itemstack, user, pointed_thing) mcl_potions.night_vision_func(user, 180) - mcl_potions._use_potion(itemstack, user, "#009999") + mcl_potions._use_potion(itemstack, user, "#1010AA") return itemstack end, on_secondary_use = function(itemstack, user, pointed_thing) mcl_potions.night_vision_func(user, 180) - mcl_potions._use_potion(itemstack, user, "#009999") + mcl_potions._use_potion(itemstack, user, "#1010AA") return itemstack end, }) @@ -173,20 +173,20 @@ minetest.register_craftitem("mcl_potions:night_vision", { minetest.register_craftitem("mcl_potions:night_vision_plus", { description = S("Night Vision Potion +"), _doc_items_longdesc = brewhelp, - wield_image = potion_image("#000A0A"), - inventory_image = potion_image("#000A0A"), + wield_image = potion_image("#2020BA"), + inventory_image = potion_image("#2020BA"), groups = { brewitem = 1, food=0}, stack_max = 1, on_place = function(itemstack, user, pointed_thing) mcl_potions.night_vision_func(user, 480) - mcl_potions._use_potion(itemstack, user, "#000A0A") + mcl_potions._use_potion(itemstack, user, "#2020BA") return itemstack end, on_secondary_use = function(itemstack, user, pointed_thing) mcl_potions.night_vision_func(user, 480) - mcl_potions._use_potion(itemstack, user, "#000A0A") + mcl_potions._use_potion(itemstack, user, "#2020BA") return itemstack end, }) diff --git a/mods/ITEMS/mcl_potions/splash.lua b/mods/ITEMS/mcl_potions/splash.lua index 0f60342df2..108514387c 100644 --- a/mods/ITEMS/mcl_potions/splash.lua +++ b/mods/ITEMS/mcl_potions/splash.lua @@ -197,10 +197,10 @@ register_splash("water_breathing_plus", "Splash Fire Resistance +", "#E0B050", { potion_fun = function(player, redx) mcl_potions.fire_resistance_func(player, 360*redx) end }) -register_splash("night_vision", "Splash Night Vision", "#009999", { +register_splash("night_vision", "Splash Night Vision", "#1010AA", { potion_fun = function(player, redx) mcl_potions.night_vision_func(player, 135*redx) end }) -register_splash("night_vision_plus", "Splash Night Vision +", "#000A0A", { +register_splash("night_vision_plus", "Splash Night Vision +", "#2020BA", { potion_fun = function(player, redx) mcl_potions.night_vision_func(player, 360*redx) end })