Switch to an internal sound API

Avoid mangling official Minetest API
functions that mods may want to
use directly.
This commit is contained in:
Aaron Suen 2020-04-05 21:22:51 -04:00
parent 4a41aae4a8
commit 35292eb259
18 changed files with 33 additions and 33 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
})

View File

@ -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

View File

@ -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",

View File

@ -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

View File

@ -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)

View File

@ -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