From edab0be8f5986a7967645dc9be51042afb9452c3 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 18 Feb 2020 14:51:15 +0100 Subject: [PATCH] Play armor (un-)equip sounds on armor stand --- .../minetest-3d_armor/3d_armor/armor.lua | 38 +++++++++---------- .../minetest-3d_armor/3d_armor_stand/init.lua | 2 + 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/mods/ITEMS/minetest-3d_armor/3d_armor/armor.lua b/mods/ITEMS/minetest-3d_armor/3d_armor/armor.lua index 8661f641b0..007bb2744c 100644 --- a/mods/ITEMS/minetest-3d_armor/3d_armor/armor.lua +++ b/mods/ITEMS/minetest-3d_armor/3d_armor/armor.lua @@ -221,6 +221,22 @@ armor.get_valid_player = function(self, player, msg) return name, player_inv, armor_inv, pos end +armor.play_equip_sound = function(self, player, stack, unequip) + local def = stack:get_definition() + local estr = "equip" + if unequip then + estr = "unequip" + end + local snd = def.sounds and def.sounds["_mcl_armor_"..estr] + if not snd then + -- Fallback sound + snd = { name = "3d_armor_"..estr.."_iron" } + end + if snd then + minetest.sound_play(snd, {object=player, gain=0.5, max_hear_distance=8}) + end +end + -- Register Player Model mcl_player.player_register_model("3d_armor_character.b3d", { @@ -265,22 +281,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end end) -local function play_equip_sound(player, stack, unequip) - local def = stack:get_definition() - local estr = "equip" - if unequip then - estr = "unequip" - end - local snd = def.sounds and def.sounds["_mcl_armor_"..estr] - if not snd then - -- Fallback sound - snd = { name = "3d_armor_"..estr.."_iron" } - end - if snd then - minetest.sound_play(snd, {object=player, gain=0.5, max_hear_distance=8}) - end -end - minetest.register_on_joinplayer(function(player) mcl_player.player_set_model(player, "3d_armor_character.b3d") local name = player:get_player_name() @@ -290,13 +290,13 @@ minetest.register_on_joinplayer(function(player) player:get_inventory():set_stack(listname, index, stack) armor:set_player_armor(player) armor:update_inventory(player) - play_equip_sound(player, stack) + armor:play_equip_sound(player, stack) end, on_take = function(inv, listname, index, stack, player) player:get_inventory():set_stack(listname, index, nil) armor:set_player_armor(player) armor:update_inventory(player) - play_equip_sound(player, stack, true) + armor:play_equip_sound(player, stack, true) end, on_move = function(inv, from_list, from_index, to_list, to_index, count, player) local plaver_inv = player:get_inventory() @@ -305,7 +305,7 @@ minetest.register_on_joinplayer(function(player) player_inv:set_stack(from_list, from_index, nil) armor:set_player_armor(player) armor:update_inventory(player) - play_equip_sound(player, stack) + armor:play_equip_sound(player, stack) end, allow_put = function(inv, listname, index, stack, player) local iname = stack:get_name() diff --git a/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua b/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua index f17f73cbf8..e2d0f12251 100644 --- a/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua +++ b/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua @@ -146,6 +146,7 @@ minetest.register_node("3d_armor_stand:armor_stand", { single_item:set_count(1) if inv:is_empty(list) then inv:add_item(list, single_item) + armor:play_equip_sound(clicker, single_item) update_entity(pos) itemstack:take_item() return itemstack @@ -170,6 +171,7 @@ minetest.register_node("3d_armor_stand:armor_stand", { taken = true end if taken then + armor:play_equip_sound(clicker, stand_armor, true) stand_armor:take_item() inv:set_stack("armor_" .. elements[e], 1, stand_armor) end