Add node breaker sounds (#219)

Also, disallow node breakers to dig unknown nodes
and a bit whitespace fix
This commit is contained in:
HybridDog 2018-08-01 16:41:55 +02:00 committed by SmallJoker
parent 8186f003be
commit 6492b8ec76

@ -331,12 +331,25 @@ if pipeworks.enable_node_breaker then
virtplayer:set_wielded_item(wieldstack) virtplayer:set_wielded_item(wieldstack)
else else
local under_node = minetest.get_node(pointed_thing.under) local under_node = minetest.get_node(pointed_thing.under)
local on_dig = (minetest.registered_nodes[under_node.name] or {on_dig=minetest.node_dig}).on_dig local def = minetest.registered_nodes[under_node.name]
-- check that the current tool is capable of destroying the target node. if not def then
-- do not dig an unknown node
return
end
-- check that the current tool is capable of destroying the
-- target node.
-- if we can't, don't dig, and leave the wield stack unchanged. -- if we can't, don't dig, and leave the wield stack unchanged.
-- note that wieldstack:get_tool_capabilities() returns hand properties if the item has none of it's own. -- note that wieldstack:get_tool_capabilities() returns hand
if can_tool_dig_node(under_node.name, wieldstack:get_tool_capabilities(), wieldstack:get_name()) then -- properties if the item has none of it's own.
on_dig(pointed_thing.under, under_node, virtplayer) if can_tool_dig_node(under_node.name,
wieldstack:get_tool_capabilities(),
wieldstack:get_name()) then
def.on_dig(pointed_thing.under, under_node, virtplayer)
local sound = def.sounds and def.sounds.dug
if sound then
minetest.sound_play(sound.name,
{pos=pointed_thing.under, gain=sound.gain})
end
wieldstack = virtplayer:get_wielded_item() wieldstack = virtplayer:get_wielded_item()
else else
--pipeworks.logger(dname.."couldn't dig node!") --pipeworks.logger(dname.."couldn't dig node!")