mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 18:41:09 +01:00
Merge pull request 'Expanding music choices and adding in Jester's first 4 tracks' (#3464) from music_enable_multiple_track_choice into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/3464
This commit is contained in:
commit
22e7200ea0
6 changed files with 87 additions and 34 deletions
|
@ -204,3 +204,4 @@
|
||||||
* The workaholics who spent way too much time writing for the Minecraft Wiki. It's an invaluable resource for creating this game
|
* The workaholics who spent way too much time writing for the Minecraft Wiki. It's an invaluable resource for creating this game
|
||||||
* Notch and Jeb for being the major forces behind Minecraft
|
* Notch and Jeb for being the major forces behind Minecraft
|
||||||
* Dark Reaven Music (https://soundcloud.com/dark-reaven-music) for the main menu theme (Calmed Cube), which is licensed under https://creativecommons.org/licenses/by-sa/3.0/
|
* Dark Reaven Music (https://soundcloud.com/dark-reaven-music) for the main menu theme (Calmed Cube), which is licensed under https://creativecommons.org/licenses/by-sa/3.0/
|
||||||
|
* Jester for helping to finely tune MineClone2 (https://www.youtube.com/@Jester-8-bit). Songs: Hailing Forest, Gift, 0dd BL0ck, Flock of One (License CC BY-SA 4.0)
|
|
@ -6,95 +6,147 @@ local music_enabled = minetest.settings:get_bool("mcl_game_music", true)
|
||||||
local pianowtune = "diminixed-pianowtune01"
|
local pianowtune = "diminixed-pianowtune01"
|
||||||
local end_tune = "diminixed-ambientwip"
|
local end_tune = "diminixed-ambientwip"
|
||||||
local nether_tune = "horizonchris96-traitor"
|
local nether_tune = "horizonchris96-traitor"
|
||||||
|
local odd_block = "Jester-0dd-BL0ck"
|
||||||
|
local flock_of_one = "Jester-Flock-of-One"
|
||||||
|
local gift = "Jester-Gift"
|
||||||
|
local hailing_forest = "Jester-Hailing_Forest"
|
||||||
|
|
||||||
local dimension_to_base_track = {
|
local dimension_to_base_track = {
|
||||||
["overworld"] = pianowtune,
|
["overworld"] = {pianowtune, flock_of_one, gift, hailing_forest},
|
||||||
["nether"] = nether_tune,
|
["nether"] = {nether_tune},
|
||||||
["end"] = end_tune,
|
["end"] = {end_tune},
|
||||||
|
["mining"] = {odd_block},
|
||||||
}
|
}
|
||||||
|
|
||||||
local listeners = {}
|
local listeners = {}
|
||||||
|
|
||||||
local weather_state
|
local weather_state
|
||||||
|
|
||||||
|
local function pick_track(dimension, underground)
|
||||||
|
local track_key
|
||||||
|
|
||||||
|
if dimension == "overworld" and underground then
|
||||||
|
track_key = "mining"
|
||||||
|
else
|
||||||
|
-- Pick random dimension song
|
||||||
|
track_key = dimension
|
||||||
|
end
|
||||||
|
|
||||||
|
local dimension_tracks = dimension_to_base_track[track_key]
|
||||||
|
|
||||||
|
if dimension_tracks and #dimension_tracks >= 1 then
|
||||||
|
local index = 1
|
||||||
|
if #dimension_tracks > 1 then
|
||||||
|
index = math.random(1, #dimension_tracks)
|
||||||
|
end
|
||||||
|
local chosen_track = dimension_tracks[index]
|
||||||
|
--minetest.log("chosen_track: " .. chosen_track)
|
||||||
|
minetest.log("action", "[mcl_music] Playing track: " .. chosen_track .. ", for context: " .. track_key)
|
||||||
|
return chosen_track
|
||||||
|
else
|
||||||
|
--?
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function stop_music_for_listener_name(listener_name)
|
local function stop_music_for_listener_name(listener_name)
|
||||||
if not listener_name then return end
|
if not listener_name then return end
|
||||||
local listener = listeners[listener_name]
|
local listener = listeners[listener_name]
|
||||||
if not listener then return end
|
if not listener then return end
|
||||||
local handle = listener.handle
|
local handle = listener.handle
|
||||||
if not handle then return end
|
if not handle then return end
|
||||||
|
|
||||||
minetest.sound_stop(handle)
|
minetest.sound_stop(handle)
|
||||||
listeners[listener_name].handle = nil
|
listeners[listener_name].handle = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop()
|
local function stop_music_for_all()
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
stop_music_for_listener_name(player_name)
|
stop_music_for_listener_name(player_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function play_song(track, player_name, hp, dimension, day_count, underground)
|
||||||
|
local spec = {
|
||||||
|
name = track,
|
||||||
|
gain = 0.3,
|
||||||
|
pitch = 1.0,
|
||||||
|
}
|
||||||
|
local parameters = {
|
||||||
|
to_player = player_name,
|
||||||
|
gain = 1.0,
|
||||||
|
fade = 0.0,
|
||||||
|
pitch = 1.0,
|
||||||
|
}
|
||||||
|
local handle = minetest.sound_play(spec, parameters, false)
|
||||||
|
listeners[player_name] = {
|
||||||
|
handle = handle,
|
||||||
|
hp = hp,
|
||||||
|
dimension = dimension,
|
||||||
|
day_count = day_count,
|
||||||
|
underground = underground,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
local function play()
|
local function play()
|
||||||
local new_weather_state = mcl_weather.get_weather()
|
local new_weather_state = mcl_weather.get_weather()
|
||||||
local was_good_weather = weather_state == "none" or weather_state == "clear"
|
local was_good_weather = weather_state == "none" or weather_state == "clear"
|
||||||
weather_state = new_weather_state
|
weather_state = new_weather_state
|
||||||
local is_good_weather = weather_state == "none" or weather_state == "clear"
|
local is_good_weather = weather_state == "none" or weather_state == "clear"
|
||||||
local is_weather_changed = weather_state ~= new_weather_state
|
local is_weather_changed = weather_state ~= new_weather_state
|
||||||
|
|
||||||
local time = minetest.get_timeofday()
|
local time = minetest.get_timeofday()
|
||||||
if time < 0.25 or time >= 0.75 then
|
if time < 0.25 or time >= 0.75 then
|
||||||
stop()
|
stop_music_for_all()
|
||||||
minetest.after(10, play)
|
minetest.after(10, play)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local day_count = minetest.get_day_count()
|
local day_count = minetest.get_day_count()
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local hp = player:get_hp()
|
local hp = player:get_hp()
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
|
||||||
local dimension = mcl_worlds.pos_to_dimension(pos)
|
local dimension = mcl_worlds.pos_to_dimension(pos)
|
||||||
|
|
||||||
|
local underground = dimension == "overworld" and pos and pos.y < 0
|
||||||
|
|
||||||
local listener = listeners[player_name]
|
local listener = listeners[player_name]
|
||||||
local old_hp = listener and listener.hp
|
local handle = listener and listener.handle
|
||||||
local old_dimension = listener and listener.dimension
|
|
||||||
|
local old_hp = listener and listener.hp
|
||||||
|
local old_dimension = listener and listener.dimension
|
||||||
|
local old_underground = listener and listener.underground
|
||||||
|
|
||||||
local is_dimension_changed = old_dimension and (old_dimension ~= dimension) or false
|
local is_dimension_changed = old_dimension and (old_dimension ~= dimension) or false
|
||||||
local is_hp_changed = old_hp and (math.abs(old_hp - hp) > 0.00001) or false
|
local is_hp_changed = old_hp and (math.abs(old_hp - hp) > 0.00001) or false
|
||||||
local handle = listener and listener.handle
|
local underground_changed = old_underground and underground ~= old_underground
|
||||||
|
|
||||||
local track = dimension_to_base_track[dimension]
|
|
||||||
|
|
||||||
if is_hp_changed
|
--minetest.log("handle: " .. dump (handle))
|
||||||
or is_dimension_changed
|
if is_hp_changed or is_dimension_changed or underground_changed
|
||||||
or (dimension == "overworld" and (is_weather_changed or not is_good_weather))
|
or (dimension == "overworld" and (is_weather_changed or not is_good_weather)) then
|
||||||
or not track
|
minetest.log("action", "[mcl_music] Stopping music")
|
||||||
then
|
|
||||||
stop_music_for_listener_name(player_name)
|
stop_music_for_listener_name(player_name)
|
||||||
if not listeners[player_name] then
|
if not listeners[player_name] then
|
||||||
listeners[player_name] = {}
|
listeners[player_name] = {}
|
||||||
end
|
end
|
||||||
listeners[player_name].hp = hp
|
listeners[player_name].hp = hp
|
||||||
listeners[player_name].dimension = dimension
|
listeners[player_name].dimension = dimension
|
||||||
|
listeners[player_name].underground = underground
|
||||||
elseif not handle and (not listener or (listener.day_count ~= day_count)) then
|
elseif not handle and (not listener or (listener.day_count ~= day_count)) then
|
||||||
local spec = {
|
local track = pick_track(dimension, underground)
|
||||||
name = track,
|
if track then
|
||||||
gain = 0.3,
|
play_song(track, player_name, hp, dimension, day_count, underground)
|
||||||
pitch = 1.0,
|
else
|
||||||
}
|
--minetest.log("no track found. weird")
|
||||||
local parameters = {
|
end
|
||||||
to_player = player_name,
|
else
|
||||||
gain = 1.0,
|
--minetest.log("else")
|
||||||
fade = 0.0,
|
|
||||||
pitch = 1.0,
|
|
||||||
}
|
|
||||||
handle = minetest.sound_play(spec, parameters, false)
|
|
||||||
listeners[player_name] = {
|
|
||||||
spec = spec,
|
|
||||||
parameters = parameters,
|
|
||||||
handle = handle,
|
|
||||||
hp = hp,
|
|
||||||
dimension = dimension,
|
|
||||||
day_count = day_count,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
BIN
mods/PLAYER/mcl_music/sounds/Jester-0dd-BL0ck.ogg
Normal file
BIN
mods/PLAYER/mcl_music/sounds/Jester-0dd-BL0ck.ogg
Normal file
Binary file not shown.
BIN
mods/PLAYER/mcl_music/sounds/Jester-Flock-of-One.ogg
Normal file
BIN
mods/PLAYER/mcl_music/sounds/Jester-Flock-of-One.ogg
Normal file
Binary file not shown.
BIN
mods/PLAYER/mcl_music/sounds/Jester-Gift.ogg
Normal file
BIN
mods/PLAYER/mcl_music/sounds/Jester-Gift.ogg
Normal file
Binary file not shown.
BIN
mods/PLAYER/mcl_music/sounds/Jester-Hailing_Forest.ogg
Normal file
BIN
mods/PLAYER/mcl_music/sounds/Jester-Hailing_Forest.ogg
Normal file
Binary file not shown.
Loading…
Reference in a new issue