From 35292eb2599f1d6b1562e60d55d76b1d7c4b511f Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Sun, 5 Apr 2020 21:22:51 -0400 Subject: [PATCH] Switch to an internal sound API Avoid mangling official Minetest API functions that mods may want to use directly. --- mods/nc_api/item_punch_sounds.lua | 2 +- mods/nc_api/item_tool_wears_to.lua | 6 +++--- mods/nc_api/util_misc.lua | 2 +- mods/nc_api/util_sound.lua | 8 ++++---- mods/nc_api_active/ambiance.lua | 2 +- mods/nc_api_craft/register_cook_abm.lua | 2 +- mods/nc_doors/operate.lua | 4 ++-- mods/nc_envsound/init.lua | 4 ++-- mods/nc_fire/api.lua | 8 ++++---- mods/nc_fire/firestarting.lua | 2 +- mods/nc_optics/cooking.lua | 2 +- mods/nc_player_hand/wieldsounds.lua | 2 +- mods/nc_sponge/abm.lua | 6 +++--- mods/nc_sponge/cultivate.lua | 2 +- mods/nc_stonework/tools.lua | 2 +- mods/nc_torch/abm.lua | 6 +++--- mods/nc_torch/node.lua | 2 +- mods/nc_torch/wield.lua | 4 ++-- 18 files changed, 33 insertions(+), 33 deletions(-) diff --git a/mods/nc_api/item_punch_sounds.lua b/mods/nc_api/item_punch_sounds.lua index 40e6c2c9..c11ab8eb 100644 --- a/mods/nc_api/item_punch_sounds.lua +++ b/mods/nc_api/item_punch_sounds.lua @@ -25,7 +25,7 @@ minetest.register_on_punchnode(function(pos, node, puncher) end if wield:get_wear() >= (65536 * 0.95) then - minetest.sound_play("nc_api_toolwear", + nodecore.sound_play("nc_api_toolwear", {object = puncher, gain = 0.5}) end end) diff --git a/mods/nc_api/item_tool_wears_to.lua b/mods/nc_api/item_tool_wears_to.lua index c99b002c..480fbf29 100644 --- a/mods/nc_api/item_tool_wears_to.lua +++ b/mods/nc_api/item_tool_wears_to.lua @@ -1,6 +1,6 @@ -- LUALOCALS < --------------------------------------------------------- -local ItemStack, minetest, nodecore - = ItemStack, minetest, nodecore +local ItemStack, nodecore + = ItemStack, nodecore -- LUALOCALS > --------------------------------------------------------- nodecore.register_on_register_item(function(_, def) @@ -9,7 +9,7 @@ nodecore.register_on_register_item(function(_, def) what:add_wear(dp.wear) if what:get_count() == 0 then if def.sound and def.sound.breaks then - minetest.sound_play(def.sound.breaks, + nodecore.sound_play(def.sound.breaks, {object = who, gain = 0.5}) end return ItemStack(def.tool_wears_to) diff --git a/mods/nc_api/util_misc.lua b/mods/nc_api/util_misc.lua index 26e2d3b0..3a1117ca 100644 --- a/mods/nc_api/util_misc.lua +++ b/mods/nc_api/util_misc.lua @@ -179,7 +179,7 @@ function nodecore.wear_wield(player, groups, qty) wielded:add_wear(dp.wear * (qty or 1)) if wielded:get_count() <= 0 and wdef.sound and wdef.sound.breaks then - minetest.sound_play(wdef.sound.breaks, + nodecore.sound_play(wdef.sound.breaks, {object = player, gain = 0.5}) end end diff --git a/mods/nc_api/util_sound.lua b/mods/nc_api/util_sound.lua index 383a8974..16aa9667 100644 --- a/mods/nc_api/util_sound.lua +++ b/mods/nc_api/util_sound.lua @@ -8,7 +8,7 @@ local math_exp, math_random, math_sin, math_sqrt -- LUALOCALS > --------------------------------------------------------- local oldplay = minetest.sound_play -function minetest.sound_play(name, spec, ephem, ...) +function nodecore.sound_play(name, spec, ephem, ...) if spec and type(spec) == "table" and spec.pitch == nil then spec.pitch = math_exp((math_random() - 0.5) * (spec.pitchvary or 0.05)) end @@ -31,7 +31,7 @@ function nodecore.stack_sounds(pos, kind, stack) local t = {} for k, v in pairs(def.sounds[kind]) do t[k] = v end t.pos = pos - return minetest.sound_play(t.name, t) + return nodecore.sound_play(t.name, t) end function nodecore.stack_sounds_delay(...) local t = {...} @@ -61,7 +61,7 @@ end function nodecore.sound_play_except(name, def, pname) if not pname then - return minetest.sound_play(name, def) + return nodecore.sound_play(name, def) end if type(pname) ~= "string" then pname = pname:get_player_name() @@ -71,7 +71,7 @@ function nodecore.sound_play_except(name, def, pname) if pn ~= pname and ((not def.pos) or (vector.distance(p:get_pos(), def.pos) <= 32)) then def.to_player = pn - minetest.sound_play(name, def) + nodecore.sound_play(name, def) end end end diff --git a/mods/nc_api_active/ambiance.lua b/mods/nc_api_active/ambiance.lua index cc9c876b..7ef39e1d 100644 --- a/mods/nc_api_active/ambiance.lua +++ b/mods/nc_api_active/ambiance.lua @@ -32,7 +32,7 @@ function nodecore.register_ambiance(def) opts.name = opts.name or def.sound_name opts.gain = opts.gain or def.sound_gain - minetest.sound_play(opts.name, opts) + nodecore.sound_play(opts.name, opts) time = time - rate end diff --git a/mods/nc_api_craft/register_cook_abm.lua b/mods/nc_api_craft/register_cook_abm.lua index 80efdca7..280580c2 100644 --- a/mods/nc_api_craft/register_cook_abm.lua +++ b/mods/nc_api_craft/register_cook_abm.lua @@ -22,7 +22,7 @@ end local function playcookfx(pos, cookfx, sound, smokeqty, smoketime) if not cookfx then return end if cookfx == true or cookfx and cookfx[sound] then - minetest.sound_play("nc_api_craft_" .. sound, + nodecore.sound_play("nc_api_craft_" .. sound, {gain = 1, pos = pos}) end if cookfx == true or cookfx and cookfx.smoke then diff --git a/mods/nc_doors/operate.lua b/mods/nc_doors/operate.lua index c0ccabf9..c8e0b9c6 100644 --- a/mods/nc_doors/operate.lua +++ b/mods/nc_doors/operate.lua @@ -214,7 +214,7 @@ function nodecore.operate_door(pos, node, dir) axis = hinge } if nodecore.craft_check(press.pos, minetest.get_node(press.pos), data) then - minetest.sound_play("nc_doors_operate", + nodecore.sound_play("nc_doors_operate", {pos = press.pos, gain = 0.5}) return true end @@ -248,7 +248,7 @@ function nodecore.operate_door(pos, node, dir) local k = "sfx" .. minetest.hash_node_position(p) if not squelch[k] then squelch[k] = 0 - minetest.sound_play("nc_doors_operate", + nodecore.sound_play("nc_doors_operate", {pos = v.pos, gain = 0.5}) end else diff --git a/mods/nc_envsound/init.lua b/mods/nc_envsound/init.lua index 6070569d..dbf69dd4 100644 --- a/mods/nc_envsound/init.lua +++ b/mods/nc_envsound/init.lua @@ -30,12 +30,12 @@ local function check(pos, done, srcs) if nodecore.is_full_sun(sp) then if sp.y <= 0 then return end - minetest.sound_play("nc_envsound_air", { + nodecore.sound_play("nc_envsound_air", { pos = sp, gain = nodecore.windiness(sp.y) / 100 }) elseif nodecore.get_node_light(sp) < 4 then - minetest.sound_play("nc_envsound_drip", { + nodecore.sound_play("nc_envsound_drip", { pos = sp, pitchvary = 0.4, gain = math_exp(math_random()) / 5 diff --git a/mods/nc_fire/api.lua b/mods/nc_fire/api.lua index 30a9a162..3b3419f4 100644 --- a/mods/nc_fire/api.lua +++ b/mods/nc_fire/api.lua @@ -93,8 +93,8 @@ function nodecore.fire_ignite(pos, node) minetest.set_node(pos, {name = modname .. ":fire"}) end - minetest.sound_play("nc_fire_ignite", {gain = 1, pos = pos}) - minetest.sound_play("nc_fire_flamy", {gain = 3, pos = pos}) + nodecore.sound_play("nc_fire_ignite", {gain = 1, pos = pos}) + nodecore.sound_play("nc_fire_flamy", {gain = 3, pos = pos}) nodecore.fallcheck(pos) return true end @@ -123,13 +123,13 @@ local function snuff(cons, coal, pos, node, ember) if ember > 0 then if coal then minetest.set_node(pos, {name = modname .. ":coal" .. ember}) - minetest.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) + nodecore.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) else minetest.set_node(pos, {name = modname .. ":ember" .. ember}) end else minetest.set_node(pos, {name = modname .. ":ash"}) - minetest.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) + nodecore.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) end nodecore.fallcheck(pos) return true diff --git a/mods/nc_fire/firestarting.lua b/mods/nc_fire/firestarting.lua index 9e8c25d7..648b3564 100644 --- a/mods/nc_fire/firestarting.lua +++ b/mods/nc_fire/firestarting.lua @@ -28,7 +28,7 @@ nodecore.register_craft({ local r = math_random(1, 4) if r > fs then nodecore.smokefx(pos, 1, 5 + fs - r) - minetest.sound_play("nc_api_toolbreak", {pos = pos, gain = 1}) + nodecore.sound_play("nc_api_toolbreak", {pos = pos, gain = 1}) return end diff --git a/mods/nc_optics/cooking.lua b/mods/nc_optics/cooking.lua index 256df358..4a67ac33 100644 --- a/mods/nc_optics/cooking.lua +++ b/mods/nc_optics/cooking.lua @@ -116,7 +116,7 @@ nodecore.register_limited_abm({ local gen = meta:get_int("glassgen") if gen >= 32 and math_random(1, 2) == 1 then minetest.set_node(pos, {name = modname .. ":glass_crude"}) - minetest.sound_play("nc_api_craft_hiss", {gain = 1, pos = pos}) + nodecore.sound_play("nc_api_craft_hiss", {gain = 1, pos = pos}) return nodecore.smokefx(pos, 0.2, 80) end local miny = pos.y diff --git a/mods/nc_player_hand/wieldsounds.lua b/mods/nc_player_hand/wieldsounds.lua index 0b3c9ee6..57cd4a7c 100644 --- a/mods/nc_player_hand/wieldsounds.lua +++ b/mods/nc_player_hand/wieldsounds.lua @@ -13,7 +13,7 @@ local function wieldsound(player, idx, gain) t.object = player t.gain = gain or 1 if player:get_player_control().sneak then t.gain = t.gain / 4 end - return function() minetest.sound_play(t.name, t) end + return function() nodecore.sound_play(t.name, t) end end end return function() end diff --git a/mods/nc_sponge/abm.lua b/mods/nc_sponge/abm.lua index e833d19b..2c65ba4c 100644 --- a/mods/nc_sponge/abm.lua +++ b/mods/nc_sponge/abm.lua @@ -58,7 +58,7 @@ nodecore.register_limited_abm({ action = function(pos) local above = {x = pos.x, y = pos.y + 1, z = pos.z} if nodecore.is_full_sun(above) and #findwater(pos) < 1 then - minetest.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = pos}) + nodecore.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = pos}) return minetest.set_node(pos, {name = modname .. ":sponge"}) end end @@ -74,7 +74,7 @@ nodecore.register_aism({ or data.slot ~= data.player:get_wield_index()) then return end if data.pos and nodecore.is_full_sun(data.pos) and #findwater(data.pos) < 1 then - minetest.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = data.pos}) + nodecore.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = data.pos}) local taken = stack:take_item(1) taken:set_name(modname .. ":sponge") if data.inv then taken = data.inv:add_item("main", taken) end @@ -92,7 +92,7 @@ nodecore.register_limited_abm({ nodenames = {modname .. ":sponge_wet"}, neighbors = {"group:igniter"}, action = function(pos) - minetest.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = pos}) + nodecore.sound_play("nc_api_craft_hiss", {gain = 0.02, pos = pos}) return minetest.set_node(pos, {name = modname .. ":sponge"}) end }) diff --git a/mods/nc_sponge/cultivate.lua b/mods/nc_sponge/cultivate.lua index ff4ca5a5..00676844 100644 --- a/mods/nc_sponge/cultivate.lua +++ b/mods/nc_sponge/cultivate.lua @@ -110,7 +110,7 @@ nodecore.register_aism({ itemnames = {living}, action = function(stack, data) if spongesurvive(data) then return end - minetest.sound_play("nc_terrain_swishy", {gain = 1, pos = data.pos}) + nodecore.sound_play("nc_terrain_swishy", {gain = 1, pos = data.pos}) stack:set_name(wet) return stack end diff --git a/mods/nc_stonework/tools.lua b/mods/nc_stonework/tools.lua index adfd5982..7f842219 100644 --- a/mods/nc_stonework/tools.lua +++ b/mods/nc_stonework/tools.lua @@ -25,7 +25,7 @@ nodecore.extend_item(chip, function(copy, orig) minetest.remove_node(pos) nodecore.item_eject(pos, v.to) stoned.pos = pos - minetest.sound_play(stoned.name, stoned) + nodecore.sound_play(stoned.name, stoned) itemstack:set_count(itemstack:get_count() - 1) if placer then nodecore.player_stat_add(1, placer, "craft", diff --git a/mods/nc_torch/abm.lua b/mods/nc_torch/abm.lua index 89706452..cd6e4f86 100644 --- a/mods/nc_torch/abm.lua +++ b/mods/nc_torch/abm.lua @@ -54,7 +54,7 @@ nodecore.register_limited_abm({ if nodecore.quenched(pos) or nodecore.gametime > expire then minetest.remove_node(pos) minetest.add_item(pos, {name = "nc_fire:lump_ash"}) - minetest.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) + nodecore.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) return end local nn = modname .. ":torch_lit_" .. torchlife(expire) @@ -71,7 +71,7 @@ nodecore.register_aism({ action = function(stack, data) local expire = stack:get_meta():get_float("expire") or 0 if expire < nodecore.gametime then - minetest.sound_play("nc_fire_snuff", {gain = 1, pos = data.pos}) + nodecore.sound_play("nc_fire_snuff", {gain = 1, pos = data.pos}) return "nc_fire:lump_ash" end @@ -84,7 +84,7 @@ nodecore.register_aism({ end if nodecore.quenched(pos, data.node and 1 or 0.3) then - minetest.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) + nodecore.sound_play("nc_fire_snuff", {gain = 1, pos = pos}) return "nc_fire:lump_ash" end if math_random() < 0.1 then nodecore.fire_check_ignite(pos) end diff --git a/mods/nc_torch/node.lua b/mods/nc_torch/node.lua index ec011254..8a2614aa 100644 --- a/mods/nc_torch/node.lua +++ b/mods/nc_torch/node.lua @@ -30,7 +30,7 @@ minetest.register_node(modname .. ":torch", { sounds = nodecore.sounds("nc_tree_sticky"), on_ignite = function(pos, node) minetest.set_node(pos, {name = modname .. ":torch_lit"}) - minetest.sound_play("nc_fire_ignite", {gain = 1, pos = pos}) + nodecore.sound_play("nc_fire_ignite", {gain = 1, pos = pos}) local expire = nodecore.gametime + nodecore.torch_life_base * (nodecore.boxmuller() * 0.1 + 1) minetest.get_meta(pos):set_float("expire", expire) diff --git a/mods/nc_torch/wield.lua b/mods/nc_torch/wield.lua index a3c34480..f5a3da2f 100644 --- a/mods/nc_torch/wield.lua +++ b/mods/nc_torch/wield.lua @@ -16,7 +16,7 @@ local function islit(stack) end local function snuffinv(player, inv, i) - minetest.sound_play("nc_fire_snuff", {object = player, gain = 0.5}) + nodecore.sound_play("nc_fire_snuff", {object = player, gain = 0.5}) inv:set_stack("main", i, "nc_fire:lump_ash") end @@ -47,7 +47,7 @@ minetest.register_globalstep(function() local t = ambtimers[name] or 0 if t <= now then ambtimers[name] = now + 1 - minetest.sound_play("nc_fire_flamy", + nodecore.sound_play("nc_fire_flamy", {object = player, gain = 0.1}) end else