Skip to content

Commit

Permalink
Add support for sfinv
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy authored and stujones11 committed Mar 8, 2017
1 parent 3df7802 commit 8b8a554
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
3 changes: 1 addition & 2 deletions 3d_armor/README.txt
Expand Up @@ -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.
Expand All @@ -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.

30 changes: 24 additions & 6 deletions 3d_armor/armor.lua
Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions 3d_armor/depends.txt
@@ -1,6 +1,7 @@
default
inventory_plus?
unified_inventory?
sfinv?
fire?
ethereal?
bakedclay?

0 comments on commit 8b8a554

Please sign in to comment.