1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-23 07:10:19 +01:00

Flint & steel sounds: Fix bugs caused by nil position

Usage and tool break sounds were played at 'pointed_thing.above' which
can be nil if not pointing at anything or at an entity. This caused
sounds to be played to all players on a server non-positionally.

Fallback to player pos for sounds if 'pointed_thing.above' is nil.

Replace 'pt' variable with 'pointed_thing' in 'register_tool'.
This commit is contained in:
paramat 2017-03-10 18:43:44 +00:00
parent c52ad140ae
commit ad118ea98d

View File

@ -80,27 +80,27 @@ minetest.register_tool("fire:flint_and_steel", {
sound = {breaks = "default_tool_breaks"}, sound = {breaks = "default_tool_breaks"},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
local pt = pointed_thing local sound_pos = pointed_thing.above or user:get_pos()
minetest.sound_play( minetest.sound_play(
"fire_flint_and_steel", "fire_flint_and_steel",
{pos = pt.above, gain = 0.5, max_hear_distance = 8} {pos = sound_pos, gain = 0.5, max_hear_distance = 8}
) )
if pt.type == "node" then if pointed_thing.type == "node" then
local node_under = minetest.get_node(pt.under).name local node_under = minetest.get_node(pointed_thing.under).name
local nodedef = minetest.registered_nodes[node_under] local nodedef = minetest.registered_nodes[node_under]
if not nodedef then if not nodedef then
return return
end end
local player_name = user:get_player_name() local player_name = user:get_player_name()
if minetest.is_protected(pt.under, player_name) then if minetest.is_protected(pointed_thing.under, player_name) then
minetest.chat_send_player(player_name, "This area is protected") minetest.chat_send_player(player_name, "This area is protected")
return return
end end
if nodedef.on_ignite then if nodedef.on_ignite then
nodedef.on_ignite(pt.under, user) nodedef.on_ignite(pointed_thing.under, user)
elseif minetest.get_item_group(node_under, "flammable") >= 1 elseif minetest.get_item_group(node_under, "flammable") >= 1
and minetest.get_node(pt.above).name == "air" then and minetest.get_node(pointed_thing.above).name == "air" then
minetest.set_node(pt.above, {name = "fire:basic_flame"}) minetest.set_node(pointed_thing.above, {name = "fire:basic_flame"})
end end
end end
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
@ -109,7 +109,7 @@ minetest.register_tool("fire:flint_and_steel", {
itemstack:add_wear(1000) itemstack:add_wear(1000)
-- Tool break sound -- Tool break sound
if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then
minetest.sound_play(wdef.sound.breaks, {pos = pt.above, gain = 0.5}) minetest.sound_play(wdef.sound.breaks, {pos = sound_pos, gain = 0.5})
end end
return itemstack return itemstack
end end