nodecore-cd2025/mods/nc_api/item_punch_sounds.lua

41 lines
1.2 KiB
Lua
Raw Normal View History

2019-03-14 21:48:29 -04:00
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore
= minetest, nodecore
2019-03-14 21:48:29 -04:00
-- LUALOCALS > ---------------------------------------------------------
2019-03-14 22:04:44 -04:00
local lasthit = {}
minetest.register_on_punchnode(function(pos, node, puncher)
2019-03-14 21:48:29 -04:00
if not puncher then return end
2019-03-14 22:04:44 -04:00
local pname = puncher:get_player_name()
local now = minetest.get_us_time() / 1000000
local last = lasthit[pname] or 0
if now - last < 0.25 then return end
lasthit[pname] = now
local def = minetest.registered_items[node.name] or {}
2019-03-14 21:48:29 -04:00
local wield = puncher:get_wielded_item()
if (not def.sounds) or (not def.groups)
or (not nodecore.toolspeed(wield, def.groups)) then
2019-03-14 21:48:29 -04:00
nodecore.node_sound(pos, "dig")
else
2019-04-06 21:28:11 -04:00
nodecore.node_sound(pos, "dig",
{except = puncher})
2019-03-14 21:48:29 -04:00
end
if wield:get_wear() >= (65536 * 0.95) then
minetest.sound_play("nc_api_toolwear",
{pos = pos, gain = 0.5})
end
2019-03-14 21:48:29 -04:00
end)
minetest.register_on_dignode(function(pos, node, digger)
2019-04-06 21:28:11 -04:00
return nodecore.node_sound(pos, "dug",
{node = node, except = digger})
end)
minetest.register_on_placenode(function(pos, node, placer)
2019-04-06 21:28:11 -04:00
return nodecore.node_sound(pos, "place",
{node = node, except = placer})
end)