Play armor (un-)equip sounds on armor stand

This commit is contained in:
Wuzzy 2020-02-18 14:51:15 +01:00
parent ef077fed72
commit edab0be8f5
2 changed files with 21 additions and 19 deletions

View file

@ -221,6 +221,22 @@ armor.get_valid_player = function(self, player, msg)
return name, player_inv, armor_inv, pos return name, player_inv, armor_inv, pos
end 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 -- Register Player Model
mcl_player.player_register_model("3d_armor_character.b3d", { 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
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) minetest.register_on_joinplayer(function(player)
mcl_player.player_set_model(player, "3d_armor_character.b3d") mcl_player.player_set_model(player, "3d_armor_character.b3d")
local name = player:get_player_name() local name = player:get_player_name()
@ -290,13 +290,13 @@ minetest.register_on_joinplayer(function(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:update_inventory(player) armor:update_inventory(player)
play_equip_sound(player, stack) armor:play_equip_sound(player, 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:update_inventory(player) armor:update_inventory(player)
play_equip_sound(player, stack, true) armor:play_equip_sound(player, stack, true)
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()
@ -305,7 +305,7 @@ minetest.register_on_joinplayer(function(player)
player_inv:set_stack(from_list, from_index, nil) player_inv:set_stack(from_list, from_index, nil)
armor:set_player_armor(player) armor:set_player_armor(player)
armor:update_inventory(player) armor:update_inventory(player)
play_equip_sound(player, stack) armor:play_equip_sound(player, stack)
end, end,
allow_put = function(inv, listname, index, stack, player) allow_put = function(inv, listname, index, stack, player)
local iname = stack:get_name() local iname = stack:get_name()

View file

@ -146,6 +146,7 @@ minetest.register_node("3d_armor_stand:armor_stand", {
single_item:set_count(1) single_item:set_count(1)
if inv:is_empty(list) then if inv:is_empty(list) then
inv:add_item(list, single_item) inv:add_item(list, single_item)
armor:play_equip_sound(clicker, single_item)
update_entity(pos) update_entity(pos)
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
@ -170,6 +171,7 @@ minetest.register_node("3d_armor_stand:armor_stand", {
taken = true taken = true
end end
if taken then if taken then
armor:play_equip_sound(clicker, stand_armor, true)
stand_armor:take_item() stand_armor:take_item()
inv:set_stack("armor_" .. elements[e], 1, stand_armor) inv:set_stack("armor_" .. elements[e], 1, stand_armor)
end end