mirror of
https://github.com/minetest-mods/3d_armor.git
synced 2024-11-23 04:53:43 +01:00
More armor callback fixes
This commit is contained in:
parent
a5ddc3e60a
commit
1f11a28ad4
@ -387,7 +387,6 @@ armor.damage = function(self, player, index, stack, use)
|
|||||||
self:run_callbacks("on_damage", player, index, stack)
|
self:run_callbacks("on_damage", player, index, stack)
|
||||||
self:set_inventory_stack(player, index, stack)
|
self:set_inventory_stack(player, index, stack)
|
||||||
if stack:get_count() == 0 then
|
if stack:get_count() == 0 then
|
||||||
self:run_callbacks("on_unequip", player, index, old_stack)
|
|
||||||
self:run_callbacks("on_destroy", player, index, old_stack)
|
self:run_callbacks("on_destroy", player, index, old_stack)
|
||||||
self:set_player_armor(player)
|
self:set_player_armor(player)
|
||||||
end
|
end
|
||||||
@ -482,11 +481,14 @@ armor.save_armor_inventory = function(self, player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Workaround for detached inventory swap exploit
|
-- Workaround for detached inventory swap exploit
|
||||||
local armor_list = {}
|
local armor_prev = {}
|
||||||
local armor_list_string = player:get_attribute("3d_armor_inventory")
|
local armor_list_string = player:get_attribute("3d_armor_inventory")
|
||||||
if armor_list_string then
|
if armor_list_string then
|
||||||
for i, item in pairs(minetest.deserialize(armor_list_string)) do
|
local armor_list = self:deserialize_inventory_list(armor_list_string)
|
||||||
armor_list[item] = item ~= "" and i or nil
|
for i, stack in ipairs(armor_list) do
|
||||||
|
if stack:get_count() > 0 then
|
||||||
|
armor_prev[stack:get_name()] = i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local elements = {}
|
local elements = {}
|
||||||
@ -497,8 +499,8 @@ armor.save_armor_inventory = function(self, player)
|
|||||||
local item = stack:get_name()
|
local item = stack:get_name()
|
||||||
local element = self:get_element(item)
|
local element = self:get_element(item)
|
||||||
if element and not elements[element] then
|
if element and not elements[element] then
|
||||||
if armor_list[item] then
|
if armor_prev[item] then
|
||||||
armor_list[item] = nil
|
armor_prev[item] = nil
|
||||||
else
|
else
|
||||||
-- Item was not in previous inventory
|
-- Item was not in previous inventory
|
||||||
armor:run_callbacks("on_equip", player, i, stack)
|
armor:run_callbacks("on_equip", player, i, stack)
|
||||||
@ -512,7 +514,7 @@ armor.save_armor_inventory = function(self, player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for item, i in pairs(armor_list) do
|
for item, i in pairs(armor_prev) do
|
||||||
local stack = ItemStack(item)
|
local stack = ItemStack(item)
|
||||||
-- Previous item is not in current inventory
|
-- Previous item is not in current inventory
|
||||||
armor:run_callbacks("on_unequip", player, i, stack)
|
armor:run_callbacks("on_unequip", player, i, stack)
|
||||||
@ -527,11 +529,10 @@ end
|
|||||||
|
|
||||||
armor.set_inventory_stack = function(self, player, i, stack)
|
armor.set_inventory_stack = function(self, player, i, stack)
|
||||||
local name, inv = self:get_valid_player(player, "[set_inventory_stack]")
|
local name, inv = self:get_valid_player(player, "[set_inventory_stack]")
|
||||||
if not name then
|
if inv then
|
||||||
return
|
|
||||||
end
|
|
||||||
inv:set_stack("armor", i, stack)
|
inv:set_stack("armor", i, stack)
|
||||||
self:save_armor_inventory(player)
|
self:save_armor_inventory(player)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
armor.get_valid_player = function(self, player, msg)
|
armor.get_valid_player = function(self, player, msg)
|
||||||
|
@ -268,10 +268,10 @@ if armor.config.drop == true or armor.config.destroy == true then
|
|||||||
local stack = armor_inv:get_stack("armor", i)
|
local stack = armor_inv:get_stack("armor", i)
|
||||||
if stack:get_count() > 0 then
|
if stack:get_count() > 0 then
|
||||||
table.insert(drop, stack)
|
table.insert(drop, stack)
|
||||||
armor:set_inventory_stack(player, i, nil)
|
armor_inv:set_stack("armor", i, nil)
|
||||||
armor:run_callbacks("on_unequip", player, i, stack)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
armor:save_armor_inventory(player)
|
||||||
armor:set_player_armor(player)
|
armor:set_player_armor(player)
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
if pos and armor.config.destroy == false then
|
if pos and armor.config.destroy == false then
|
||||||
|
Loading…
Reference in New Issue
Block a user