From 8b8a554ff7ec66d4c4dfb577f05734ae653a4135 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 16 Feb 2017 00:10:19 +0000 Subject: [PATCH] Add support for sfinv --- 3d_armor/README.txt | 3 +-- 3d_armor/armor.lua | 30 ++++++++++++++++++++++++------ 3d_armor/depends.txt | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/3d_armor/README.txt b/3d_armor/README.txt index 224f81c..3ec204d 100644 --- a/3d_armor/README.txt +++ b/3d_armor/README.txt @@ -3,7 +3,7 @@ Depends: default -Recommends: inventory_plus or unified_inventory (use only one) +Recommends: sfinv, inventory_plus or unified_inventory (use only one to avoid conflicts) Adds craftable armor that is visible to other players. Each armor item worn contributes to a player's armor group level making them less vulnerable to weapons. @@ -21,4 +21,3 @@ Armor can be configured by adding a file called armor.conf in 3d_armor mod and/o see armor.conf.example for all available options. Note: worldpath config settings override any settings made in the mod's directory. - diff --git a/3d_armor/armor.lua b/3d_armor/armor.lua index 20bc37c..554a335 100644 --- a/3d_armor/armor.lua +++ b/3d_armor/armor.lua @@ -93,7 +93,7 @@ if minetest.get_modpath("inventory_plus") then inventory_plus.get_formspec = function(player, page) end end -elseif minetest.get_modpath("unified_inventory") then +elseif minetest.get_modpath("unified_inventory") and not unified_inventory.sfinv_compat_layer then inv_mod = "unified_inventory" unified_inventory.register_button("armor", { type = "image", @@ -120,6 +120,17 @@ elseif minetest.get_modpath("inventory_enhanced") then inv_mod = "inventory_enhanced" elseif minetest.get_modpath("smart_inventory") then inv_mod = "smart_inventory" +elseif minetest.get_modpath("sfinv") then + inv_mod = "sfinv" + armor.formspec = "image[2,0.5;2,4;armor_preview]" + + sfinv.register_page("3d_armor:armor", { + title = "Armor", + get = function(self, player, context) + return sfinv.make_formspec(player, context, + armor:get_armor_formspec(player:get_player_name()), true) + end + }) end if minetest.get_modpath("skins") then @@ -248,7 +259,7 @@ end armor.update_armor = function(self, player) -- Legacy support: Called when armor levels are changed - -- Other mods can hook on to this function, see hud mod for example + -- Other mods can hook on to this function, see hud mod for example end armor.get_player_skin = function(self, name) @@ -297,9 +308,16 @@ armor.update_inventory = function(self, player) if state then state:get("update_hook"):submit() end - return - end - if inv_mod == "unified_inventory" then + elseif inv_mod == "sfinv" then + if sfinv.set_page then + sfinv.set_page(player, "3d_armor:armor") + else + -- Backwards compat + sfinv.set_player_inventory_formspec(player, { + page = "3d_armor:armor" + }) + end + elseif inv_mod == "unified_inventory" then if unified_inventory.current_page[name] == "armor" then unified_inventory.set_inventory_formspec(player, "armor") end @@ -428,7 +446,7 @@ minetest.register_on_joinplayer(function(player) for i=1, 6 do local stack = player_inv:get_stack("armor", i) armor_inv:set_stack("armor", i, stack) - end + end armor.def[name] = { state = 0, count = 0, diff --git a/3d_armor/depends.txt b/3d_armor/depends.txt index 3acf737..1f1a7a3 100644 --- a/3d_armor/depends.txt +++ b/3d_armor/depends.txt @@ -1,6 +1,7 @@ default inventory_plus? unified_inventory? +sfinv? fire? ethereal? bakedclay?