From 776bd77a6184cde1796779ae3befc5b444d721ed Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 19 Jul 2021 18:05:01 -0700 Subject: [PATCH] Play sound when hit if "sounds" mod available --- README.md | 5 +++++ TODO.txt | 1 - changelog.txt | 4 ++++ entity.lua | 12 ++++++++++++ mod.conf | 2 +- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff8e38a..d8b26ea 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ An explosive nuisance for [Minetest](http://minetest.net/). Settings documented in [reference][]. +### Requirements: + +- Depends: default, tnt +- Optional depends: nether, sounds + ### Links: - [![ContentDB](https://img.shields.io/static/v1?label=ContentDB&message=sneeker&color=%23375a7f&logo=minetest)](https://content.minetest.net/packages/AntumDeluge/sneeker/) diff --git a/TODO.txt b/TODO.txt index dbb2a4e..4cd1739 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,4 @@ TODO: -- add sound when hit - add version using mobs_redo API - add version using cmer API diff --git a/changelog.txt b/changelog.txt index 98424ee..9dd2ddb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ +v1.1 +---- +- added sound when hit + v1.0 ---- - forked & renamed from Rui's original "creeper" mod diff --git a/entity.lua b/entity.lua index ae474ae..8bbc91e 100644 --- a/entity.lua +++ b/entity.lua @@ -1,4 +1,12 @@ +local sounds_enabled = core.get_modpath("sounds") ~= nil +local hit_sound + +if sounds_enabled then + hit_sound = "sounds_entity_hit" +end + + local function jump(self, pos, direction) local velocity = self.object:get_velocity() if core.registered_nodes[core.get_node(pos).name].climbable then @@ -348,6 +356,10 @@ def.on_step = function(self, dtime) end def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir) + if hit_sound then + core.sound_play(hit_sound, {object=self.object}, parameters, true) + end + if self.knockback == false then local knockback_level = self.knockback_level self.object:set_velocity({x=dir.x*knockback_level, y=3, z=dir.z*knockback_level}) diff --git a/mod.conf b/mod.conf index 65653c0..708f340 100644 --- a/mod.conf +++ b/mod.conf @@ -4,4 +4,4 @@ description = An explosive nuisance. version = 1.0 author = Rui depends = default, tnt -optional_depends = nether +optional_depends = nether, sounds