From 99bc8cf2d3bcc5964b2e2602d18d15403cd32c73 Mon Sep 17 00:00:00 2001 From: stujones11 Date: Sat, 15 Apr 2017 20:37:32 +0100 Subject: [PATCH] Reverse order of stack and index in callbacks for consistency --- 3d_armor/README.txt | 16 ++++++++-------- 3d_armor/api.lua | 18 +++++++++--------- 3d_armor/init.lua | 4 ++-- shields/init.lua | 40 ++++++++++++++++++++-------------------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/3d_armor/README.txt b/3d_armor/README.txt index aa3deae..b93ef37 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, index) + on_destroy = function(player, index, stack) 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, index) -on_unequip = func(player, stack, index) -on_destroy = func(player, stack, index) -on_damage = func(player, stack, index) +on_equip = func(player, index, stack) +on_unequip = func(player, index, stack) +on_destroy = func(player, index, stack) +on_damage = func(player, index, stack) 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, index)) -armor:register_on_unequip(func(player, stack, index)) -armor:register_on_destroy(func(player, stack, index)) +armor:register_on_equip(func(player, index, stack)) +armor:register_on_unequip(func(player, index, stack)) +armor:register_on_destroy(func(player, index, stack)) Global Callback Example: diff --git a/3d_armor/api.lua b/3d_armor/api.lua index 0ddd78c..c9c825b 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, index) +armor.run_callbacks = function(self, callback, player, index, stack) if stack then local def = stack:get_definition() or {} if type(def[callback]) == "function" then - def[callback](player, stack, index) + def[callback](player, index, stack) end end local callbacks = self.registered_callbacks[callback] if callbacks then for _, func in pairs(callbacks) do - func(player, stack, index) + func(player, index, stack) 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, index) + armor:run_callbacks("on_equip", player, index, stack) 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, index) + armor:run_callbacks("on_unequip", player, index, stack) end, on_move = function(inv, from_list, from_index, to_list, to_index, count, player) local plaver_inv = player:get_inventory() @@ -222,7 +222,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, i) + self:run_callbacks("on_equip", player, i, stack) end self.def[name] = { init_time = minetest.get_gametime(), @@ -448,10 +448,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, i) + self:run_callbacks("on_damage", player, i, stack) if stack:get_count() == 0 then - self:run_callbacks("on_unequip", player, old_stack, i) - self:run_callbacks("on_destroy", player, old_stack, i) + 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 diff --git a/3d_armor/init.lua b/3d_armor/init.lua index d694318..52673dc 100644 --- a/3d_armor/init.lua +++ b/3d_armor/init.lua @@ -63,7 +63,7 @@ armor.formspec = armor.formspec.. if armor.config.fire_protect then armor.formspec = armor.formspec.."label[5,2;"..S("Fire")..": armor_fire]" end -armor:register_on_destroy(function(player, stack) +armor:register_on_destroy(function(player, index, stack) local name = player:get_player_name() local def = stack:get_definition() if name and def and def.description then @@ -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, i) + armor:run_callbacks("on_unequip", player, i, stack) end end armor:set_player_armor(player) diff --git a/shields/init.lua b/shields/init.lua index 5ce4385..90636da 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_wood_footstep") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_wood_footstep") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_glass_footstep") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_dig_metal") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_glass_footstep") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) 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, index) + on_damage = function(player, index, stack) play_sound_effect(player, "default_glass_footstep") end, - on_destroy = function(player, stack, index) + on_destroy = function(player, index, stack) play_sound_effect(player, "default_break_glass") end, })