mirror of
https://github.com/minetest-mods/3d_armor.git
synced 2024-08-20 21:14:09 +02:00
Add damage method and update README.txt
This commit is contained in:
parent
df429ee487
commit
4dd7e41749
@ -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
|
Reciprocal tool damage will be done only by the first armor inventory item
|
||||||
with `reciprocate_damage = true`
|
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:
|
Item Callbacks:
|
||||||
|
|
||||||
on_equip = func(player, index, stack)
|
on_equip = func(player, index, stack)
|
||||||
|
@ -445,15 +445,7 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili
|
|||||||
damage = minetest.get_item_group(name, "flammable") > 0
|
damage = minetest.get_item_group(name, "flammable") > 0
|
||||||
end
|
end
|
||||||
if damage == true then
|
if damage == true then
|
||||||
local old_stack = ItemStack(stack)
|
self:damage(player, i, stack, use)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
state = state + stack:get_wear()
|
state = state + stack:get_wear()
|
||||||
count = count + 1
|
count = count + 1
|
||||||
@ -463,6 +455,18 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili
|
|||||||
self.def[name].count = count
|
self.def[name].count = count
|
||||||
end
|
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)
|
armor.get_player_skin = function(self, name)
|
||||||
local skin = nil
|
local skin = nil
|
||||||
if self.skin_mod == "skins" or self.skin_mod == "simple_skins" then
|
if self.skin_mod == "skins" or self.skin_mod == "simple_skins" then
|
||||||
|
Loading…
Reference in New Issue
Block a user