mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 04:21:07 +01:00
Play armor (un-)equip sounds on armor stand
This commit is contained in:
parent
ef077fed72
commit
edab0be8f5
2 changed files with 21 additions and 19 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue