Reverse order of stack and index in callbacks for consistency

This commit is contained in:
stujones11 2017-04-15 20:37:32 +01:00
parent a2ec13e28d
commit 99bc8cf2d3
4 changed files with 39 additions and 39 deletions

@ -107,7 +107,7 @@ armor:register_armor("mod_name:speed_boots", {
armor_groups = {fleshy=10, radiation=10}, armor_groups = {fleshy=10, radiation=10},
damage_groups = {cracky=3, snappy=3, choppy=3, crumbly=3, level=1}, damage_groups = {cracky=3, snappy=3, choppy=3, crumbly=3, level=1},
reciprocate_damage = true, reciprocate_damage = true,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
local pos = player:getpos() local pos = player:getpos()
if pos then if pos then
minetest.sound_play({ minetest.sound_play({
@ -140,10 +140,10 @@ Reciprocal tool damage will be done only by the first armor inventory item
Item Callbacks: Item Callbacks:
on_equip = func(player, stack, index) on_equip = func(player, index, stack)
on_unequip = func(player, stack, index) on_unequip = func(player, index, stack)
on_destroy = func(player, stack, index) on_destroy = func(player, index, stack)
on_damage = func(player, stack, index) on_damage = func(player, index, stack)
on_punch = func(player, hitter, time_from_last_punch, tool_capabilities) on_punch = func(player, hitter, time_from_last_punch, tool_capabilities)
Notes: Notes:
@ -157,9 +157,9 @@ When armor is destroyed `stack` will contain a copy of the previous stack.
Global Callbacks: Global Callbacks:
armor:register_on_update(func(player)) armor:register_on_update(func(player))
armor:register_on_equip(func(player, stack, index)) armor:register_on_equip(func(player, index, stack))
armor:register_on_unequip(func(player, stack, index)) armor:register_on_unequip(func(player, index, stack))
armor:register_on_destroy(func(player, stack, index)) armor:register_on_destroy(func(player, index, stack))
Global Callback Example: Global Callback Example:

@ -140,17 +140,17 @@ armor.register_on_destroy = function(self, func)
end end
end end
armor.run_callbacks = function(self, callback, player, stack, index) armor.run_callbacks = function(self, callback, player, index, stack)
if stack then if stack then
local def = stack:get_definition() or {} local def = stack:get_definition() or {}
if type(def[callback]) == "function" then if type(def[callback]) == "function" then
def[callback](player, stack, index) def[callback](player, index, stack)
end end
end end
local callbacks = self.registered_callbacks[callback] local callbacks = self.registered_callbacks[callback]
if callbacks then if callbacks then
for _, func in pairs(callbacks) do for _, func in pairs(callbacks) do
func(player, stack, index) func(player, index, stack)
end end
end end
end end
@ -180,12 +180,12 @@ armor.init_player_armor = function(self, player)
on_put = function(inv, listname, index, stack, player) on_put = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, stack) player:get_inventory():set_stack(listname, index, stack)
armor:set_player_armor(player) armor:set_player_armor(player)
armor:run_callbacks("on_equip", player, stack, index) armor:run_callbacks("on_equip", player, index, stack)
end, end,
on_take = function(inv, listname, index, stack, player) on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, nil) player:get_inventory():set_stack(listname, index, nil)
armor:set_player_armor(player) armor:set_player_armor(player)
armor:run_callbacks("on_unequip", player, stack, index) armor:run_callbacks("on_unequip", player, index, stack)
end, end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, player) on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
local plaver_inv = player:get_inventory() local plaver_inv = player:get_inventory()
@ -222,7 +222,7 @@ armor.init_player_armor = function(self, player)
for i=1, 6 do for i=1, 6 do
local stack = player_inv:get_stack("armor", i) local stack = player_inv:get_stack("armor", i)
armor_inv:set_stack("armor", i, stack) armor_inv:set_stack("armor", i, stack)
self:run_callbacks("on_equip", player, stack, i) self:run_callbacks("on_equip", player, i, stack)
end end
self.def[name] = { self.def[name] = {
init_time = minetest.get_gametime(), 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) local old_stack = ItemStack(stack)
stack:add_wear(use) stack:add_wear(use)
self:set_inventory_stack(player, i, stack) 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 if stack:get_count() == 0 then
self:run_callbacks("on_unequip", player, old_stack, i) self:run_callbacks("on_unequip", player, i, old_stack)
self:run_callbacks("on_destroy", player, old_stack, i) self:run_callbacks("on_destroy", player, i, old_stack)
self:set_player_armor(player) self:set_player_armor(player)
end end
end end

@ -63,7 +63,7 @@ armor.formspec = armor.formspec..
if armor.config.fire_protect then if armor.config.fire_protect then
armor.formspec = armor.formspec.."label[5,2;"..S("Fire")..": armor_fire]" armor.formspec = armor.formspec.."label[5,2;"..S("Fire")..": armor_fire]"
end end
armor:register_on_destroy(function(player, stack) armor:register_on_destroy(function(player, index, stack)
local name = player:get_player_name() local name = player:get_player_name()
local def = stack:get_definition() local def = stack:get_definition()
if name and def and def.description then 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 if stack:get_count() > 0 then
table.insert(drop, stack) table.insert(drop, stack)
armor:set_inventory_stack(player, i, nil) 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
end end
armor:set_player_armor(player) armor:set_player_armor(player)

@ -50,10 +50,10 @@ if armor.materials.wood then
armor_groups = {fleshy=5}, armor_groups = {fleshy=5},
damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_wood_footstep") play_sound_effect(player, "default_wood_footstep")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_wood_footstep") play_sound_effect(player, "default_wood_footstep")
end, end,
}) })
@ -64,10 +64,10 @@ if armor.materials.wood then
armor_groups = {fleshy=8}, armor_groups = {fleshy=8},
damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=2}, damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=2},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_dig_metal") play_sound_effect(player, "default_dig_metal")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_dug_metal") play_sound_effect(player, "default_dug_metal")
end, end,
}) })
@ -89,10 +89,10 @@ if armor.materials.cactus then
armor_groups = {fleshy=5}, armor_groups = {fleshy=5},
damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1}, damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_wood_footstep") play_sound_effect(player, "default_wood_footstep")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_wood_footstep") play_sound_effect(player, "default_wood_footstep")
end, end,
}) })
@ -103,10 +103,10 @@ if armor.materials.cactus then
armor_groups = {fleshy=8}, armor_groups = {fleshy=8},
damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=2}, damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=2},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_dig_metal") play_sound_effect(player, "default_dig_metal")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_dug_metal") play_sound_effect(player, "default_dug_metal")
end, end,
}) })
@ -129,10 +129,10 @@ if armor.materials.steel then
armor_groups = {fleshy=10}, armor_groups = {fleshy=10},
damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_dig_metal") play_sound_effect(player, "default_dig_metal")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_dug_metal") play_sound_effect(player, "default_dug_metal")
end, end,
}) })
@ -147,10 +147,10 @@ if armor.materials.bronze then
armor_groups = {fleshy=10}, armor_groups = {fleshy=10},
damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_dig_metal") play_sound_effect(player, "default_dig_metal")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_dug_metal") play_sound_effect(player, "default_dug_metal")
end, end,
}) })
@ -164,10 +164,10 @@ if armor.materials.diamond then
armor_groups = {fleshy=15}, armor_groups = {fleshy=15},
damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, damage_groups = {cracky=2, snappy=1, choppy=1, level=3},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_glass_footstep") play_sound_effect(player, "default_glass_footstep")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_break_glass") play_sound_effect(player, "default_break_glass")
end, end,
}) })
@ -182,10 +182,10 @@ if armor.materials.gold then
armor_groups = {fleshy=10}, armor_groups = {fleshy=10},
damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_dig_metal") play_sound_effect(player, "default_dig_metal")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_dug_metal") play_sound_effect(player, "default_dug_metal")
end, end,
}) })
@ -199,10 +199,10 @@ if armor.materials.mithril then
armor_groups = {fleshy=15}, armor_groups = {fleshy=15},
damage_groups = {cracky=2, snappy=1, level=3}, damage_groups = {cracky=2, snappy=1, level=3},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_glass_footstep") play_sound_effect(player, "default_glass_footstep")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_break_glass") play_sound_effect(player, "default_break_glass")
end, end,
}) })
@ -216,10 +216,10 @@ if armor.materials.crystal then
armor_groups = {fleshy=15}, armor_groups = {fleshy=15},
damage_groups = {cracky=2, snappy=1, level=3}, damage_groups = {cracky=2, snappy=1, level=3},
reciprocate_damage = true, reciprocate_damage = true,
on_damage = function(player, stack, index) on_damage = function(player, index, stack)
play_sound_effect(player, "default_glass_footstep") play_sound_effect(player, "default_glass_footstep")
end, end,
on_destroy = function(player, stack, index) on_destroy = function(player, index, stack)
play_sound_effect(player, "default_break_glass") play_sound_effect(player, "default_break_glass")
end, end,
}) })