Try to fix stack node sounds.
Use same node_sound hook as punch hook, to limit sound rate.
This commit is contained in:
parent
209e0491a4
commit
27770dfdb7
@ -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
|
||||
|
@ -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
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user