Play sound when hit if "sounds" mod available

This commit is contained in:
Jordan Irwin 2021-07-19 18:05:01 -07:00
parent ab748fdecb
commit 776bd77a61
5 changed files with 22 additions and 2 deletions

@ -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/)

@ -1,5 +1,4 @@
TODO:
- add sound when hit
- add version using mobs_redo API
- add version using cmer API

@ -1,4 +1,8 @@
v1.1
----
- added sound when hit
v1.0
----
- forked & renamed from Rui's original "creeper" mod

@ -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})

@ -4,4 +4,4 @@ description = An explosive nuisance.
version = 1.0
author = Rui
depends = default, tnt
optional_depends = nether
optional_depends = nether, sounds