From d948b64af46cf14097377155baa0e72f97094f75 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 18 May 2018 17:18:25 +0200 Subject: [PATCH] Do not damage on join --- gui_unified_inventory.lua | 7 ++----- init.lua | 16 ++++++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/gui_unified_inventory.lua b/gui_unified_inventory.lua index 1978915..995480e 100644 --- a/gui_unified_inventory.lua +++ b/gui_unified_inventory.lua @@ -1,7 +1,3 @@ -if unified_inventory.sfinv_compat_layer then - return -end - unified_inventory.register_button("ugpacks", { type = "image", image = "heart.png", @@ -13,7 +9,8 @@ unified_inventory.register_page("ugpacks", { local y = perplayer_formspec.formspec_y return { formspec = ( - "label[3,0;Upgrade Packs]" .. + "listcolors[#EEE;#EEE;#111]" .. + "label[3," .. (y + 0.2) .. ";Upgrade Packs]" .. "list[current_player;ugpacks;3," .. (y + 1) .. ";2,2;]" .. "listring[current_player;main]" .. "listring[current_player;ugpacks]" diff --git a/init.lua b/init.lua index 09660c9..b405ee4 100644 --- a/init.lua +++ b/init.lua @@ -5,7 +5,8 @@ upgrade_packs.breath_items = {} local modpath = minetest.get_modpath("upgrade_packs") dofile(modpath .. "/api.lua") -if minetest.get_modpath("unified_inventory") then +if minetest.get_modpath("unified_inventory") + and not unified_inventory.sfinv_compat_layer then dofile(modpath .. "/gui_unified_inventory.lua") elseif minetest.get_modpath("sfinv") then dofile(modpath .. "/gui_sfinv.lua") @@ -46,7 +47,8 @@ minetest.after(0, function() upgrade_packs.breath_items = breath_items end) -minetest.register_on_joinplayer(function(player) +-- Hacky: Set the hp_max and breath_max value first +table.insert(minetest.registered_on_joinplayers, 1, function(player) local inv = player:get_inventory() inv:set_size("ugpacks", 4) upgrade_packs.update_player(player) @@ -62,14 +64,16 @@ end) minetest.register_on_player_hpchange(function(player, hp_change, reason) if hp_change >= 0 then - return + return hp_change end if reason == "drown" then - upgrade_packs.add_wear(player, "breath", 200) + upgrade_packs.add_wear(player, "breath", 400) else - upgrade_packs.add_wear(player, "health", hp_change * -10) + upgrade_packs.add_wear(player, "health", hp_change * -25) end -end, false) + + return hp_change +end, true) minetest.register_allow_player_inventory_action(function(player, action, inv, data) if data.to_list ~= "ugpacks" then