Skip to content

Commit 4a0a672

Browse files
sofarparamat
authored andcommitted
Builtin/../item: Enable tool breaking sounds
If a tool wears out and is destroyed, it's itemstack count goes to 0, and we can optionally play a breaking sound. This patch implements playing a breaking sound when this occurs. Sounds need to be added to the tool itemdef registration as the sound name string in the .sound.breaks member.
1 parent afc48c8 commit 4a0a672

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

builtin/game/item.lua

+3
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@ function core.node_dig(pos, node, digger)
474474
-- Wear out tool
475475
if not core.setting_getbool("creative_mode") then
476476
wielded:add_wear(dp.wear)
477+
if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
478+
core.sound_play(wdef.sound.breaks, {pos = pos, gain = 1.0})
479+
end
477480
end
478481
end
479482
digger:set_wielded_item(wielded)

doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3606,6 +3606,7 @@ Definition tables
36063606
actual result to client in a short moment.
36073607
]]
36083608
sound = {
3609+
breaks = "default_tool_break", -- tools only
36093610
place = --[[<SimpleSoundSpec>]],
36103611
},
36113612

0 commit comments

Comments
 (0)