diff --git a/3d_armor/README.txt b/3d_armor/README.txt index b93ef37..8f67c4f 100644 --- a/3d_armor/README.txt +++ b/3d_armor/README.txt @@ -138,6 +138,25 @@ damage groups need to be defined in the tool/weapon used against the player. Reciprocal tool damage will be done only by the first armor inventory item with `reciprocate_damage = true` +Armor Functions: + +armor:set_player_armor(player) + +Primarily an internal function but can be called externally to apply any +changes that might not otherwise get handled. + +armor:punch(player, hitter, time_from_last_punch, tool_capabilities) + +Used to apply damage to all equipped armor based on the damage groups of +each individual item.`hitter`, `time_from_last_punch` and `tool_capabilities` +are optional but should be valid if included. + +armor:damage(player, index, stack, use) + +Adds wear to a single armor itemstack, triggers `on_damage` callbacks and +updates the necessary inventories. Also handles item destruction callbacks +and so should NOT be called from `on_unequip` to avoid an infinite loop. + Item Callbacks: on_equip = func(player, index, stack) diff --git a/3d_armor/api.lua b/3d_armor/api.lua index 5889945..d99c7b0 100644 --- a/3d_armor/api.lua +++ b/3d_armor/api.lua @@ -445,15 +445,7 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili damage = minetest.get_item_group(name, "flammable") > 0 end if damage == true then - local old_stack = ItemStack(stack) - stack:add_wear(use) - self:set_inventory_stack(player, i, stack) - self:run_callbacks("on_damage", player, i, stack) - if stack:get_count() == 0 then - self:run_callbacks("on_unequip", player, i, old_stack) - self:run_callbacks("on_destroy", player, i, old_stack) - self:set_player_armor(player) - end + self:damage(player, i, stack, use) end state = state + stack:get_wear() count = count + 1 @@ -463,6 +455,18 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili self.def[name].count = count end +armor.damage = function(self, player, index, stack, use) + local old_stack = ItemStack(stack) + stack:add_wear(use) + self:run_callbacks("on_damage", player, i, stack) + self:set_inventory_stack(player, index, stack) + 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:set_player_armor(player) + end +end + armor.get_player_skin = function(self, name) local skin = nil if self.skin_mod == "skins" or self.skin_mod == "simple_skins" then