From 2a979ef1fe76ac6e358e37bb4e11893e3a8b0112 Mon Sep 17 00:00:00 2001 From: Hector Franqui Date: Sun, 17 Sep 2017 12:11:31 -0400 Subject: [PATCH] Actions: Add sounds to dig/place actions. --- actions/actions.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/actions/actions.lua b/actions/actions.lua index 00b548b..bca2d0e 100644 --- a/actions/actions.lua +++ b/actions/actions.lua @@ -111,6 +111,7 @@ npc.actions.take_from_inventory = "take_from_inventory" npc.actions.take_from_inventory_forced = "take_from_inventory_forced" npc.actions.force_place = "force_place" +-------------- -- Executor -- -------------- -- Function references aren't reliable in Minetest entities. Objects get serialized @@ -211,6 +212,7 @@ function npc.actions.dig(self, args) local pos = args.pos local add_to_inventory = args.add_to_inventory local bypass_protection = args.bypass_protection + local play_sound = args.play_sound or true local node = minetest.get_node_or_nil(pos) if node then -- Set mine animation @@ -219,6 +221,17 @@ function npc.actions.dig(self, args) y = npc.ANIMATION_MINE_END}, self.animation.speed_normal, 0) + -- Play dig sound + if play_sound == true then + minetest.sound_play( + minetest.registered_nodes[node.name].sounds.dug, + { + max_hear_distance = 10, + object = self.object + } + ) + end + -- Check if protection not enforced if not bypass_protection then -- Try to dig node @@ -276,6 +289,7 @@ function npc.actions.place(self, args) local node = args.node local source = args.source local bypass_protection = args.bypass_protection + local play_sound = args.play_sound or true local node_at_pos = minetest.get_node_or_nil(pos) -- Check if position is empty or has a node that can be built to if node_at_pos and @@ -304,6 +318,16 @@ function npc.actions.place(self, args) self.animation.speed_normal, 0) -- Place node minetest.set_node(pos, {name=node}) + -- Play place sound + if play_sound == true then + minetest.sound_play( + minetest.registered_nodes[node].sounds.place, + { + max_hear_distance = 10, + object = self.object + } + ) + end end end end