mirror of
https://codeberg.org/tenplus1/ambience.git
synced 2025-05-05 02:50:16 +02:00
change minetest. to core.
This commit is contained in:
parent
adecc1b95c
commit
9c4a1f1e28
48
init.lua
48
init.lua
@ -8,7 +8,7 @@ ambience = {}
|
|||||||
local SOUNDVOLUME = 1.0
|
local SOUNDVOLUME = 1.0
|
||||||
local MUSICVOLUME = 0.6
|
local MUSICVOLUME = 0.6
|
||||||
local MUSICINTERVAL = 60 * 20
|
local MUSICINTERVAL = 60 * 20
|
||||||
local play_music = minetest.settings:get_bool("ambience_music") ~= false
|
local play_music = core.settings:get_bool("ambience_music") ~= false
|
||||||
local radius = 6
|
local radius = 6
|
||||||
local playing = {} -- user settings, timers and current set playing
|
local playing = {} -- user settings, timers and current set playing
|
||||||
local sound_sets = {} -- all the sounds and their settings
|
local sound_sets = {} -- all the sounds and their settings
|
||||||
@ -17,7 +17,7 @@ local set_nodes = {} -- all the nodes needed for sets
|
|||||||
|
|
||||||
-- translation
|
-- translation
|
||||||
|
|
||||||
local S = minetest.get_translator("ambience")
|
local S = core.get_translator("ambience")
|
||||||
|
|
||||||
-- add set to list
|
-- add set to list
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ function ambience.group_total(ntab, ngrp)
|
|||||||
|
|
||||||
for _,n in pairs(ntab) do
|
for _,n in pairs(ntab) do
|
||||||
|
|
||||||
def = minetest.registered_nodes[_]
|
def = core.registered_nodes[_]
|
||||||
grp = def and def.groups and def.groups[ngrp]
|
grp = def and def.groups and def.groups[ngrp]
|
||||||
|
|
||||||
if grp and grp > 0 then
|
if grp and grp > 0 then
|
||||||
@ -103,7 +103,7 @@ end
|
|||||||
|
|
||||||
-- setup table when player joins
|
-- setup table when player joins
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
core.register_on_joinplayer(function(player)
|
||||||
|
|
||||||
if player then
|
if player then
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ end)
|
|||||||
|
|
||||||
-- remove table when player leaves
|
-- remove table when player leaves
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
core.register_on_leaveplayer(function(player)
|
||||||
|
|
||||||
if player then playing[player:get_player_name()] = nil end
|
if player then playing[player:get_player_name()] = nil end
|
||||||
end)
|
end)
|
||||||
@ -140,7 +140,7 @@ local function get_ambience(player, tod, name)
|
|||||||
-- play music on interval check
|
-- play music on interval check
|
||||||
if playing[name].music > MUSICINTERVAL and playing[name].music_handler == nil then
|
if playing[name].music > MUSICINTERVAL and playing[name].music_handler == nil then
|
||||||
|
|
||||||
playing[name].music_handler = minetest.sound_play("ambience_music", {
|
playing[name].music_handler = core.sound_play("ambience_music", {
|
||||||
to_player = name,
|
to_player = name,
|
||||||
gain = playing[name].mvol
|
gain = playing[name].mvol
|
||||||
})
|
})
|
||||||
@ -157,16 +157,16 @@ local function get_ambience(player, tod, name)
|
|||||||
|
|
||||||
pos.y = pos.y + eyeh -- head level
|
pos.y = pos.y + eyeh -- head level
|
||||||
|
|
||||||
local nod_head = minetest.get_node(pos).name
|
local nod_head = core.get_node(pos).name
|
||||||
|
|
||||||
pos.y = (pos.y - eyeh) + 0.2 -- foot level
|
pos.y = (pos.y - eyeh) + 0.2 -- foot level
|
||||||
|
|
||||||
local nod_feet = minetest.get_node(pos).name
|
local nod_feet = core.get_node(pos).name
|
||||||
|
|
||||||
pos.y = pos.y - 0.2 -- reset pos
|
pos.y = pos.y - 0.2 -- reset pos
|
||||||
|
|
||||||
-- get all set nodes around player
|
-- get all set nodes around player
|
||||||
local ps, cn = minetest.find_nodes_in_area(
|
local ps, cn = core.find_nodes_in_area(
|
||||||
{x = pos.x - radius, y = pos.y - radius, z = pos.z - radius},
|
{x = pos.x - radius, y = pos.y - radius, z = pos.z - radius},
|
||||||
{x = pos.x + radius, y = pos.y + radius, z = pos.z + radius}, set_nodes)
|
{x = pos.x + radius, y = pos.y + radius, z = pos.z + radius}, set_nodes)
|
||||||
|
|
||||||
@ -178,8 +178,8 @@ local function get_ambience(player, tod, name)
|
|||||||
if set and set.sound_check then
|
if set and set.sound_check then
|
||||||
|
|
||||||
-- get biome data
|
-- get biome data
|
||||||
local bdata = minetest.get_biome_data(pos)
|
local bdata = core.get_biome_data(pos)
|
||||||
local biome = bdata and minetest.get_biome_name(bdata.biome) or ""
|
local biome = bdata and core.get_biome_name(bdata.biome) or ""
|
||||||
|
|
||||||
-- pass settings to set function for condition check
|
-- pass settings to set function for condition check
|
||||||
local set_name, gain = set.sound_check({
|
local set_name, gain = set.sound_check({
|
||||||
@ -206,9 +206,9 @@ end
|
|||||||
local timer = 0
|
local timer = 0
|
||||||
local random = math.random
|
local random = math.random
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
core.register_globalstep(function(dtime)
|
||||||
|
|
||||||
local players = minetest.get_connected_players()
|
local players = core.get_connected_players()
|
||||||
local pname
|
local pname
|
||||||
|
|
||||||
-- reduce sound timer for each player and stop/reset when needed
|
-- reduce sound timer for each player and stop/reset when needed
|
||||||
@ -223,7 +223,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
if playing[pname].timer <= 0 then
|
if playing[pname].timer <= 0 then
|
||||||
|
|
||||||
if playing[pname].handler then
|
if playing[pname].handler then
|
||||||
minetest.sound_stop(playing[pname].handler)
|
core.sound_stop(playing[pname].handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
playing[pname].set = nil
|
playing[pname].set = nil
|
||||||
@ -237,7 +237,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
timer = timer + dtime ; if timer < 1 then return end ; timer = 0
|
timer = timer + dtime ; if timer < 1 then return end ; timer = 0
|
||||||
|
|
||||||
local number, chance, ambience, handler, ok
|
local number, chance, ambience, handler, ok
|
||||||
local tod = minetest.get_timeofday()
|
local tod = core.get_timeofday()
|
||||||
|
|
||||||
-- loop through players
|
-- loop through players
|
||||||
for _, player in pairs(players) do
|
for _, player in pairs(players) do
|
||||||
@ -257,7 +257,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
|
|
||||||
--print ("-- change stop", set_name, playing[pname].handler)
|
--print ("-- change stop", set_name, playing[pname].handler)
|
||||||
|
|
||||||
minetest.sound_stop(playing[pname].handler)
|
core.sound_stop(playing[pname].handler)
|
||||||
|
|
||||||
playing[pname].set = nil
|
playing[pname].set = nil
|
||||||
playing[pname].gain = nil
|
playing[pname].gain = nil
|
||||||
@ -278,7 +278,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
ambience = sound_sets[set_name].sounds[number] -- grab sound information
|
ambience = sound_sets[set_name].sounds[number] -- grab sound information
|
||||||
|
|
||||||
-- play sound
|
-- play sound
|
||||||
handler = minetest.sound_play(ambience.name, {
|
handler = core.sound_play(ambience.name, {
|
||||||
to_player = pname,
|
to_player = pname,
|
||||||
gain = ((ambience.gain or 0.3) + (MORE_GAIN or 0)) * playing[pname].svol,
|
gain = ((ambience.gain or 0.3) + (MORE_GAIN or 0)) * playing[pname].svol,
|
||||||
pitch = ambience.pitch or 1.0
|
pitch = ambience.pitch or 1.0
|
||||||
@ -301,7 +301,7 @@ end)
|
|||||||
|
|
||||||
-- sound volume command
|
-- sound volume command
|
||||||
|
|
||||||
minetest.register_chatcommand("svol", {
|
core.register_chatcommand("svol", {
|
||||||
params = S("<svol>"),
|
params = S("<svol>"),
|
||||||
description = S("set sound volume (0.1 to 1.0)"),
|
description = S("set sound volume (0.1 to 1.0)"),
|
||||||
privs = {},
|
privs = {},
|
||||||
@ -313,7 +313,7 @@ minetest.register_chatcommand("svol", {
|
|||||||
if svol < 0.1 then svol = 0.1 end
|
if svol < 0.1 then svol = 0.1 end
|
||||||
if svol > 1.0 then svol = 1.0 end
|
if svol > 1.0 then svol = 1.0 end
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
|
|
||||||
meta:set_string("ambience.svol", svol)
|
meta:set_string("ambience.svol", svol)
|
||||||
@ -326,7 +326,7 @@ minetest.register_chatcommand("svol", {
|
|||||||
|
|
||||||
-- music volume command (0 stops music)
|
-- music volume command (0 stops music)
|
||||||
|
|
||||||
minetest.register_chatcommand("mvol", {
|
core.register_chatcommand("mvol", {
|
||||||
params = S("<mvol>"),
|
params = S("<mvol>"),
|
||||||
description = S("set music volume (0.1 to 1.0, 0 to stop music)"),
|
description = S("set music volume (0.1 to 1.0, 0 to stop music)"),
|
||||||
privs = {},
|
privs = {},
|
||||||
@ -338,17 +338,17 @@ minetest.register_chatcommand("mvol", {
|
|||||||
-- stop music currently playing by setting volume to 0
|
-- stop music currently playing by setting volume to 0
|
||||||
if mvol == 0 and playing[name].music_handler then
|
if mvol == 0 and playing[name].music_handler then
|
||||||
|
|
||||||
minetest.sound_stop(playing[name].music_handler)
|
core.sound_stop(playing[name].music_handler)
|
||||||
|
|
||||||
playing[name].music_handler = nil
|
playing[name].music_handler = nil
|
||||||
|
|
||||||
minetest.chat_send_player(name, S("Music stopped!"))
|
core.chat_send_player(name, S("Music stopped!"))
|
||||||
end
|
end
|
||||||
|
|
||||||
if mvol < 0 then mvol = 0 end
|
if mvol < 0 then mvol = 0 end
|
||||||
if mvol > 1.0 then mvol = 1.0 end
|
if mvol > 1.0 then mvol = 1.0 end
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = core.get_player_by_name(name)
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
|
|
||||||
meta:set_string("ambience.mvol", mvol)
|
meta:set_string("ambience.mvol", mvol)
|
||||||
@ -361,7 +361,7 @@ minetest.register_chatcommand("mvol", {
|
|||||||
|
|
||||||
-- load default sound sets
|
-- load default sound sets
|
||||||
|
|
||||||
dofile(minetest.get_modpath("ambience") .. "/soundsets.lua")
|
dofile(core.get_modpath("ambience") .. "/soundsets.lua")
|
||||||
|
|
||||||
|
|
||||||
print("[MOD] Ambience Lite loaded")
|
print("[MOD] Ambience Lite loaded")
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
-- mod support
|
-- mod support
|
||||||
|
|
||||||
local mod_def = minetest.get_modpath("default")
|
local mod_def = core.get_modpath("default")
|
||||||
local mod_mcl = minetest.get_modpath("mcl_core")
|
local mod_mcl = core.get_modpath("mcl_core")
|
||||||
|
|
||||||
-- Underwater sounds play when player head is submerged
|
-- Underwater sounds play when player head is submerged
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ ambience.add_set("underwater", {
|
|||||||
|
|
||||||
sound_check = function(def)
|
sound_check = function(def)
|
||||||
|
|
||||||
local nodef = minetest.registered_nodes[def.head_node]
|
local nodef = core.registered_nodes[def.head_node]
|
||||||
|
|
||||||
if nodef and nodef.groups and nodef.groups.water then
|
if nodef and nodef.groups and nodef.groups.water then
|
||||||
return "underwater"
|
return "underwater"
|
||||||
@ -33,20 +33,20 @@ ambience.add_set("underwater", {
|
|||||||
|
|
||||||
-- Splashing sound plays when player walks inside water nodes (if enabled)
|
-- Splashing sound plays when player walks inside water nodes (if enabled)
|
||||||
|
|
||||||
if minetest.settings:get_bool("ambience_water_move") ~= false then
|
if core.settings:get_bool("ambience_water_move") ~= false then
|
||||||
|
|
||||||
-- override default water sounds
|
-- override default water sounds
|
||||||
|
|
||||||
if mod_def then
|
if mod_def then
|
||||||
minetest.override_item("default:water_source", { sounds = {} })
|
core.override_item("default:water_source", { sounds = {} })
|
||||||
minetest.override_item("default:water_flowing", { sounds = {} })
|
core.override_item("default:water_flowing", { sounds = {} })
|
||||||
minetest.override_item("default:river_water_source", { sounds = {} })
|
core.override_item("default:river_water_source", { sounds = {} })
|
||||||
minetest.override_item("default:river_water_flowing", { sounds = {} })
|
core.override_item("default:river_water_flowing", { sounds = {} })
|
||||||
elseif mod_mcl then
|
elseif mod_mcl then
|
||||||
minetest.override_item("mcl_core:water_source", { sounds = {} })
|
core.override_item("mcl_core:water_source", { sounds = {} })
|
||||||
minetest.override_item("mcl_core:water_flowing", { sounds = {} })
|
core.override_item("mcl_core:water_flowing", { sounds = {} })
|
||||||
minetest.override_item("mclx_core:river_water_source", { sounds = {} })
|
core.override_item("mclx_core:river_water_source", { sounds = {} })
|
||||||
minetest.override_item("mclx_core:river_water_flowing", { sounds = {} })
|
core.override_item("mclx_core:river_water_flowing", { sounds = {} })
|
||||||
end
|
end
|
||||||
|
|
||||||
ambience.add_set("splash", {
|
ambience.add_set("splash", {
|
||||||
@ -59,7 +59,7 @@ if minetest.settings:get_bool("ambience_water_move") ~= false then
|
|||||||
|
|
||||||
sound_check = function(def)
|
sound_check = function(def)
|
||||||
|
|
||||||
local nodef = minetest.registered_nodes[def.feet_node]
|
local nodef = core.registered_nodes[def.feet_node]
|
||||||
|
|
||||||
if nodef and nodef.groups and nodef.groups.water then
|
if nodef and nodef.groups and nodef.groups.water then
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ if minetest.settings:get_bool("ambience_water_move") ~= false then
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- check for env_sounds mod, if not found enable water flowing and lava sounds
|
-- check for env_sounds mod, if not found enable water flowing and lava sounds
|
||||||
if not minetest.get_modpath("env_sounds") then
|
if not core.get_modpath("env_sounds") then
|
||||||
|
|
||||||
-- Water sound plays when near flowing water
|
-- Water sound plays when near flowing water
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user