Try to fix stack node sounds.

Use same node_sound hook as punch hook, to limit sound rate.
This commit is contained in:
Aaron Suen 2019-03-16 17:10:20 -04:00
parent 209e0491a4
commit 27770dfdb7
2 changed files with 5 additions and 7 deletions

View File

@ -4,6 +4,7 @@ local minetest, nodecore, pairs
-- LUALOCALS > ---------------------------------------------------------
function nodecore.node_sound(pos, kind)
if nodecore.stack_sounds(pos, kind) then return end
local node = minetest.get_node(pos)
local def = minetest.registered_items[node.name] or {}
if (not def.sounds) or (not def.sounds[kind]) then return end
@ -16,15 +17,16 @@ end
local lasthit = {}
minetest.register_on_punchnode(function(pos, node, puncher, pointed)
local def = minetest.registered_items[node.name] or {}
if not def.groups or not def.sounds then return end
if not puncher then return end
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
local def = minetest.registered_items[node.name] or {}
local wield = puncher:get_wielded_item()
if not nodecore.toolspeed(wield, def.groups) then
if (not def.groups) or (not nodecore.toolspeed(wield, def.groups))
or not(def.sounds) then
nodecore.node_sound(pos, "dig")
lasthit[pname] = now
end

View File

@ -47,10 +47,6 @@ minetest.register_node(modname .. ":stack", {
return nodecore.stack_sounds(pos, "place")
end)
return nodecore.visinv_on_construct(pos, ...)
end,
on_punch = function(pos, ...)
nodecore.stack_sounds(pos, "dig")
minetest.node_punch(pos, ...)
end
})