From 065815eec1ba161c1fcfa9d89e355870a6041e4a Mon Sep 17 00:00:00 2001 From: stujones11 Date: Sat, 15 Apr 2017 17:54:39 +0100 Subject: [PATCH] Include stack index it armor item callbacks --- 3d_armor/README.txt | 16 ++++++++-------- 3d_armor/api.lua | 18 +++++++++--------- 3d_armor/init.lua | 2 +- shields/init.lua | 40 ++++++++++++++++++++-------------------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/3d_armor/README.txt b/3d_armor/README.txt index 6ec80b4..aa3deae 100644 --- a/3d_armor/README.txt +++ b/3d_armor/README.txt @@ -107,7 +107,7 @@ armor:register_armor("mod_name:speed_boots", { armor_groups = {fleshy=10, radiation=10}, damage_groups = {cracky=3, snappy=3, choppy=3, crumbly=3, level=1}, reciprocate_damage = true, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) local pos = player:getpos() if pos then minetest.sound_play({ @@ -140,10 +140,10 @@ Reciprocal tool damage will be done only by the first armor inventory item Item Callbacks: -on_equip = func(player, stack) -on_unequip = func(player, stack) -on_destroy = func(player, stack) -on_damage = func(player, stack) +on_equip = func(player, stack, index) +on_unequip = func(player, stack, index) +on_destroy = func(player, stack, index) +on_damage = func(player, stack, index) on_punch = func(player, hitter, time_from_last_punch, tool_capabilities) Notes: @@ -157,9 +157,9 @@ When armor is destroyed `stack` will contain a copy of the previous stack. Global Callbacks: armor:register_on_update(func(player)) -armor:register_on_equip(func(player, stack)) -armor:register_on_unequip(func(player, stack)) -armor:register_on_destroy(func(player, stack)) +armor:register_on_equip(func(player, stack, index)) +armor:register_on_unequip(func(player, stack, index)) +armor:register_on_destroy(func(player, stack, index)) Global Callback Example: diff --git a/3d_armor/api.lua b/3d_armor/api.lua index 1db7207..4fd1900 100644 --- a/3d_armor/api.lua +++ b/3d_armor/api.lua @@ -140,17 +140,17 @@ armor.register_on_destroy = function(self, func) end end -armor.run_callbacks = function(self, callback, player, stack) +armor.run_callbacks = function(self, callback, player, stack, index) if stack then local def = stack:get_definition() or {} if type(def[callback]) == "function" then - def[callback](player, stack) + def[callback](player, stack, index) end end local callbacks = self.registered_callbacks[callback] if callbacks then for _, func in pairs(callbacks) do - func(player, stack) + func(player, stack, index) end end end @@ -180,12 +180,12 @@ armor.init_player_armor = function(self, player) on_put = function(inv, listname, index, stack, player) player:get_inventory():set_stack(listname, index, stack) armor:set_player_armor(player) - armor:run_callbacks("on_equip", player, stack) + armor:run_callbacks("on_equip", player, stack, index) end, on_take = function(inv, listname, index, stack, player) player:get_inventory():set_stack(listname, index, nil) armor:set_player_armor(player) - armor:run_callbacks("on_unequip", player, stack) + armor:run_callbacks("on_unequip", player, stack, index) end, on_move = function(inv, from_list, from_index, to_list, to_index, count, player) local plaver_inv = player:get_inventory() @@ -220,7 +220,7 @@ armor.init_player_armor = function(self, player) for i=1, 6 do local stack = player_inv:get_stack("armor", i) armor_inv:set_stack("armor", i, stack) - self:run_callbacks("on_equip", player, stack) + self:run_callbacks("on_equip", player, stack, i) end self.def[name] = { init_time = minetest.get_gametime(), @@ -446,10 +446,10 @@ armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabili local old_stack = ItemStack(stack) stack:add_wear(use) self:set_inventory_stack(player, i, stack) - self:run_callbacks("on_damage", player, stack) + self:run_callbacks("on_damage", player, stack, i) if stack:get_count() == 0 then - self:run_callbacks("on_unequip", player, old_stack) - self:run_callbacks("on_destroy", player, old_stack) + self:run_callbacks("on_unequip", player, old_stack, i) + self:run_callbacks("on_destroy", player, old_stack, i) self:set_player_armor(player) end end diff --git a/3d_armor/init.lua b/3d_armor/init.lua index a86b650..d694318 100644 --- a/3d_armor/init.lua +++ b/3d_armor/init.lua @@ -164,7 +164,7 @@ if armor.config.drop == true or armor.config.destroy == true then if stack:get_count() > 0 then table.insert(drop, stack) armor:set_inventory_stack(player, i, nil) - armor:run_callbacks("on_unequip", player, stack) + armor:run_callbacks("on_unequip", player, stack, i) end end armor:set_player_armor(player) diff --git a/shields/init.lua b/shields/init.lua index a32c238..5ce4385 100644 --- a/shields/init.lua +++ b/shields/init.lua @@ -50,10 +50,10 @@ if armor.materials.wood then armor_groups = {fleshy=5}, damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_wood_footstep") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_wood_footstep") end, }) @@ -64,10 +64,10 @@ if armor.materials.wood then armor_groups = {fleshy=8}, damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=2}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_dug_metal") end, }) @@ -89,10 +89,10 @@ if armor.materials.cactus then armor_groups = {fleshy=5}, damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_wood_footstep") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_wood_footstep") end, }) @@ -103,10 +103,10 @@ if armor.materials.cactus then armor_groups = {fleshy=8}, damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=2}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_dug_metal") end, }) @@ -129,10 +129,10 @@ if armor.materials.steel then armor_groups = {fleshy=10}, damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_dug_metal") end, }) @@ -147,10 +147,10 @@ if armor.materials.bronze then armor_groups = {fleshy=10}, damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_dug_metal") end, }) @@ -164,10 +164,10 @@ if armor.materials.diamond then armor_groups = {fleshy=15}, damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_glass_footstep") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_break_glass") end, }) @@ -182,10 +182,10 @@ if armor.materials.gold then armor_groups = {fleshy=10}, damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_dug_metal") end, }) @@ -199,10 +199,10 @@ if armor.materials.mithril then armor_groups = {fleshy=15}, damage_groups = {cracky=2, snappy=1, level=3}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_glass_footstep") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_break_glass") end, }) @@ -216,10 +216,10 @@ if armor.materials.crystal then armor_groups = {fleshy=15}, damage_groups = {cracky=2, snappy=1, level=3}, reciprocate_damage = true, - on_damage = function(player, stack) + on_damage = function(player, stack, index) play_sound_effect(player, "default_glass_footstep") end, - on_destroy = function(player, stack) + on_destroy = function(player, stack, index) play_sound_effect(player, "default_break_glass") end, })