Builtin/../item: Enable tool breaking sounds
authorAuke Kok <sofar@foo-projects.org>
Sat, 23 Jan 2016 05:52:50 +0000 (21:52 -0800)
committerparamat <mat.gregory@virginmedia.com>
Fri, 18 Nov 2016 06:15:08 +0000 (06:15 +0000)
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.

builtin/game/item.lua
doc/lua_api.txt

index ec996292f3510d88080f9c90a28592f34811c7ff..a2fdbc1f4600f90e6b6aaea0372a74b1f68fab19 100644 (file)
@@ -474,6 +474,9 @@ function core.node_dig(pos, node, digger)
                -- Wear out tool
                if not core.setting_getbool("creative_mode") then
                        wielded:add_wear(dp.wear)
+                       if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
+                               core.sound_play(wdef.sound.breaks, {pos = pos, gain = 1.0})
+                       end
                end
        end
        digger:set_wielded_item(wielded)
index 2164bfc5ea9575c2239449732d27a12845554a0e..84080502f0052e99a9e771923e4408c5ecb51206 100644 (file)
@@ -3606,6 +3606,7 @@ Definition tables
           actual result to client in a short moment.
         ]]
         sound = {
+            breaks = "default_tool_break", -- tools only
             place = --[[<SimpleSoundSpec>]],
         },