mirror of
https://github.com/minetest-mods/3d_armor.git
synced 2024-12-28 03:30:38 +01:00
Depreciate update_inventory and use on_update callback
This commit is contained in:
parent
5517be8ff2
commit
1570efb7ac
@ -288,40 +288,8 @@ armor.get_armor_formspec = function(self, name, listring)
|
|||||||
end
|
end
|
||||||
|
|
||||||
armor.update_inventory = function(self, player)
|
armor.update_inventory = function(self, player)
|
||||||
local name = armor:get_valid_player(player, "[set_player_armor]")
|
-- DEPRECIATED: Legacy inventory support
|
||||||
if not name or self.inv_mod == "inventory_enhanced" then
|
self:run_callbacks("on_update", player)
|
||||||
return
|
|
||||||
end
|
|
||||||
if self.inv_mod == "smart_inventory" then
|
|
||||||
local state = smart_inventory.get_page_state("player", name)
|
|
||||||
if state then
|
|
||||||
state:get("update_hook"):submit()
|
|
||||||
end
|
|
||||||
elseif self.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 self.inv_mod == "unified_inventory" then
|
|
||||||
if unified_inventory.current_page[name] == "armor" then
|
|
||||||
unified_inventory.set_inventory_formspec(player, "armor")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if self.inv_mod == "inventory_plus" then
|
|
||||||
local formspec = armor:get_armor_formspec(name, true)
|
|
||||||
local page = player:get_inventory_formspec()
|
|
||||||
if page:find("detached:"..name.."_armor") then
|
|
||||||
inventory_plus.set_inventory_formspec(player, formspec)
|
|
||||||
end
|
|
||||||
elseif not core.setting_getbool("creative_mode") then
|
|
||||||
local formspec = armor:get_armor_formspec(name)
|
|
||||||
player:set_inventory_formspec(formspec)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
armor.get_valid_player = function(self, player, msg)
|
armor.get_valid_player = function(self, player, msg)
|
||||||
|
@ -73,12 +73,26 @@ end
|
|||||||
if minetest.get_modpath("inventory_plus") then
|
if minetest.get_modpath("inventory_plus") then
|
||||||
armor.inv_mod = "inventory_plus"
|
armor.inv_mod = "inventory_plus"
|
||||||
armor.formspec = "size[8,8.5]button[6,0;2,0.5;main;Back]"..armor_formpage
|
armor.formspec = "size[8,8.5]button[6,0;2,0.5;main;Back]"..armor_formpage
|
||||||
|
armor:register_on_update(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local formspec = armor:get_armor_formspec(name, true)
|
||||||
|
local page = player:get_inventory_formspec()
|
||||||
|
if page:find("detached:"..name.."_armor") then
|
||||||
|
inventory_plus.set_inventory_formspec(player, formspec)
|
||||||
|
end
|
||||||
|
end)
|
||||||
if minetest.get_modpath("crafting") then
|
if minetest.get_modpath("crafting") then
|
||||||
inventory_plus.get_formspec = function(player, page)
|
inventory_plus.get_formspec = function(player, page)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif minetest.get_modpath("unified_inventory") and not unified_inventory.sfinv_compat_layer then
|
elseif minetest.get_modpath("unified_inventory") and not unified_inventory.sfinv_compat_layer then
|
||||||
armor.inv_mod = "unified_inventory"
|
armor.inv_mod = "unified_inventory"
|
||||||
|
armor:register_on_update(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if unified_inventory.current_page[name] == "armor" then
|
||||||
|
unified_inventory.set_inventory_formspec(player, "armor")
|
||||||
|
end
|
||||||
|
end)
|
||||||
unified_inventory.register_button("armor", {
|
unified_inventory.register_button("armor", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "inventory_plus_armor.png",
|
image = "inventory_plus_armor.png",
|
||||||
@ -110,9 +124,26 @@ elseif minetest.get_modpath("inventory_enhanced") then
|
|||||||
armor.inv_mod = "inventory_enhanced"
|
armor.inv_mod = "inventory_enhanced"
|
||||||
elseif minetest.get_modpath("smart_inventory") then
|
elseif minetest.get_modpath("smart_inventory") then
|
||||||
armor.inv_mod = "smart_inventory"
|
armor.inv_mod = "smart_inventory"
|
||||||
|
armor:register_on_update(function(player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local state = smart_inventory.get_page_state("player", name)
|
||||||
|
if state then
|
||||||
|
state:get("update_hook"):submit()
|
||||||
|
end
|
||||||
|
end)
|
||||||
elseif minetest.get_modpath("sfinv") then
|
elseif minetest.get_modpath("sfinv") then
|
||||||
armor.inv_mod = "sfinv"
|
armor.inv_mod = "sfinv"
|
||||||
armor.formspec = armor_formpage
|
armor.formspec = armor_formpage
|
||||||
|
armor:register_on_update(function(player)
|
||||||
|
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
|
||||||
|
end)
|
||||||
sfinv.register_page("3d_armor:armor", {
|
sfinv.register_page("3d_armor:armor", {
|
||||||
title = "Armor",
|
title = "Armor",
|
||||||
get = function(self, player, context)
|
get = function(self, player, context)
|
||||||
@ -163,7 +194,7 @@ default.player_register_model("3d_armor_character.b3d", {
|
|||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
|
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
|
||||||
if not name or armor.inv_mod == "inventory_enhanced" then
|
if not name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if armor.inv_mod == "inventory_plus" and fields.armor then
|
if armor.inv_mod == "inventory_plus" and fields.armor then
|
||||||
@ -190,13 +221,11 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
on_put = function(inv, listname, index, stack, player)
|
on_put = function(inv, listname, index, stack, player)
|
||||||
player:get_inventory():set_stack(listname, index, stack)
|
player:get_inventory():set_stack(listname, index, stack)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
armor:update_inventory(player)
|
|
||||||
armor:run_callbacks("on_equip", player, stack)
|
armor:run_callbacks("on_equip", player, stack)
|
||||||
end,
|
end,
|
||||||
on_take = function(inv, listname, index, stack, player)
|
on_take = function(inv, listname, index, stack, player)
|
||||||
player:get_inventory():set_stack(listname, index, nil)
|
player:get_inventory():set_stack(listname, index, nil)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
armor:update_inventory(player)
|
|
||||||
armor:run_callbacks("on_unequip", player, stack)
|
armor:run_callbacks("on_unequip", player, stack)
|
||||||
end,
|
end,
|
||||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||||
@ -205,7 +234,6 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
player_inv:set_stack(to_list, to_index, stack)
|
player_inv:set_stack(to_list, to_index, stack)
|
||||||
player_inv:set_stack(from_list, from_index, nil)
|
player_inv:set_stack(from_list, from_index, nil)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
armor:update_inventory(player)
|
|
||||||
end,
|
end,
|
||||||
allow_put = function(inv, listname, index, stack, player)
|
allow_put = function(inv, listname, index, stack, player)
|
||||||
local def = stack:get_definition() or {}
|
local def = stack:get_definition() or {}
|
||||||
@ -290,9 +318,6 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
for i=1, armor.config.init_times do
|
for i=1, armor.config.init_times do
|
||||||
minetest.after(armor.config.init_delay * i, function(player)
|
minetest.after(armor.config.init_delay * i, function(player)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
if not armor.inv_mod then
|
|
||||||
armor:update_inventory(player)
|
|
||||||
end
|
|
||||||
end, player)
|
end, player)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -317,10 +342,8 @@ if armor.config.drop == true or armor.config.destroy == true then
|
|||||||
if armor.inv_mod == "unified_inventory" then
|
if armor.inv_mod == "unified_inventory" then
|
||||||
unified_inventory.set_inventory_formspec(player, "craft")
|
unified_inventory.set_inventory_formspec(player, "craft")
|
||||||
elseif armor.inv_mod == "inventory_plus" then
|
elseif armor.inv_mod == "inventory_plus" then
|
||||||
local formspec = inventory_plus.get_formspec(player,"main")
|
local formspec = inventory_plus.get_formspec(player, "main")
|
||||||
inventory_plus.set_inventory_formspec(player, formspec)
|
inventory_plus.set_inventory_formspec(player, formspec)
|
||||||
else
|
|
||||||
armor:update_inventory(player)
|
|
||||||
end
|
end
|
||||||
if armor.config.destroy == false then
|
if armor.config.destroy == false then
|
||||||
minetest.after(armor.config.bones_delay, function()
|
minetest.after(armor.config.bones_delay, function()
|
||||||
@ -378,7 +401,6 @@ minetest.register_on_player_hpchange(function(player, hp_change)
|
|||||||
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
||||||
end
|
end
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
armor:update_inventory(player)
|
|
||||||
armor:run_callbacks("on_unequip", player, stack)
|
armor:run_callbacks("on_unequip", player, stack)
|
||||||
armor:run_callbacks("on_destroy", player, stack)
|
armor:run_callbacks("on_destroy", player, stack)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user