From b6fc8885593505eada1d8fa7e76ae82e9ab2ebd5 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 12 Mar 2021 00:10:50 +0100 Subject: [PATCH 1/6] Add API for mcl_jukebox --- mods/ITEMS/mcl_jukebox/init.lua | 63 +++++++++++++++------------------ 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/mods/ITEMS/mcl_jukebox/init.lua b/mods/ITEMS/mcl_jukebox/init.lua index db9f2531..b9f762a5 100644 --- a/mods/ITEMS/mcl_jukebox/init.lua +++ b/mods/ITEMS/mcl_jukebox/init.lua @@ -1,5 +1,8 @@ local S = minetest.get_translator("mcl_jukebox") +mcl_jukebox = {} +mcl_jukebox.registered_records = {} + -- Player name-indexed table containing the currently heard track local active_tracks = {} @@ -10,47 +13,30 @@ local active_huds = {} -- Used to make sure that minetest.after only applies to the latest HUD change event local hud_sequence_numbers = {} --- List of music -local recorddata = { - -- { title, author, identifier } - { "The Evil Sister (Jordach's Mix)", "SoundHelix", "13" } , - { "The Energetic Rat (Jordach's Mix)", "SoundHelix", "wait" }, - { "Eastern Feeling", "Jordach", "blocks"}, - { "Minetest", "Jordach", "far" }, - { "Credit Roll (Jordach's HD Mix)", "Junichi Masuda", "chirp" }, - { "Winter Feeling", "Tom Peter", "strad" }, - { "Synthgroove (Jordach's Mix)", "HeroOfTheWinds", "mellohi" }, - { "The Clueless Frog (Jordach's Mix)", "SoundHelix", "mall" }, -} -local records = #recorddata - -for r=1, records do - local doc = false - local entryname, longdesc, usagehelp - if r == 1 then - doc = true - entryname = S("Music Disc") - longdesc = S("A music disc holds a single music track which can be used in a jukebox to play music.") - usagehelp = S("Place a music disc into an empty jukebox to play the music. Use the jukebox again to retrieve the music disc. The music can only be heard by you, not by other players.") - end - minetest.register_craftitem("mcl_jukebox:record_"..r, { +function mcl_jukebox.register_record(title, author, identifier, image, sound) + mcl_jukebox.registered_records["mcl_jukebox:record_"..identifier] = {title, author, identifier, image, sound} + local entryname = S("Music Disc") + local longdesc = S("A music disc holds a single music track which can be used in a jukebox to play music.") + local usagehelp = S("Place a music disc into an empty jukebox to play the music. Use the jukebox again to retrieve the music disc. The music can only be heard by you, not by other players.") + minetest.register_craftitem(":mcl_jukebox:record_"..identifier, { description = core.colorize("#55FFFF", S("Music Disc")) .. "\n" .. - core.colorize("#989898", S("@1—@2", recorddata[r][2], recorddata[r][1])), - _doc_items_create_entry = doc, + core.colorize("#989898", S("@1—@2", author, title)), + _doc_items_create_entry = true, _doc_items_entry_name = entryname, _doc_items_longdesc = longdesc, _doc_items_usagehelp = usagehelp, - inventory_image = "mcl_jukebox_record_"..recorddata[r][3]..".png", + --inventory_image = "mcl_jukebox_record_"..recorddata[r][3]..".png", + inventory_image = image, stack_max = 1, - groups = { music_record = r }, + groups = { music_record = 1 }, }) end -local function now_playing(player, track_id) +local function now_playing(player, name) local playername = player:get_player_name() local hud = active_huds[playername] - local text = S("Now playing: @1—@2", recorddata[track_id][2], recorddata[track_id][1]) + local text = S("Now playing: @1—@2", mcl_jukebox.registered_records[name][2], mcl_jukebox.registered_records[name][1]) if not hud_sequence_numbers[playername] then hud_sequence_numbers[playername] = 1 @@ -106,18 +92,18 @@ minetest.register_craft({ }) local play_record = function(pos, itemstack, player) - local record_id = minetest.get_item_group(itemstack:get_name(), "music_record") - if record_id ~= 0 then + local name = itemstack:get_name() + if mcl_jukebox.registered_records[name] then local cname = player:get_player_name() if active_tracks[cname] ~= nil then minetest.sound_stop(active_tracks[cname]) active_tracks[cname] = nil end - active_tracks[cname] = minetest.sound_play("mcl_jukebox_track_"..record_id, { + active_tracks[cname] = minetest.sound_play(mcl_jukebox.registered_records[name][5], { to_player = cname, gain = 1, }) - now_playing(player, record_id) + now_playing(player, name) return true end return false @@ -239,3 +225,12 @@ minetest.register_craft({ recipe = "mcl_jukebox:jukebox", burntime = 15, }) + +mcl_jukebox.register_record("The Evil Sister (Jordach's Mix)", "SoundHelix", "13", "mcl_jukebox_record_13.png", "mcl_jukebox_track_1") +mcl_jukebox.register_record("The Energetic Rat (Jordach's Mix)", "SoundHelix", "wait", "mcl_jukebox_record_wait.png", "mcl_jukebox_track_2") +mcl_jukebox.register_record("Eastern Feeling", "Jordach", "blocks", "mcl_jukebox_record_blocks.png", "mcl_jukebox_track_3") +mcl_jukebox.register_record("Minetest", "Jordach", "far", "mcl_jukebox_record_far.png", "mcl_jukebox_track_4") +mcl_jukebox.register_record("Credit Roll (Jordach's HD Mix)", "Junichi Masuda", "chirp", "mcl_jukebox_record_chirp.png", "mcl_jukebox_track_5") +mcl_jukebox.register_record("Winter Feeling", "Tom Peter", "strad", "mcl_jukebox_record_strad.png", "mcl_jukebox_track_6") +mcl_jukebox.register_record("Synthgroove (Jordach's Mix)", "HeroOfTheWinds", "mellohi", "mcl_jukebox_record_mellohi.png", "mcl_jukebox_track_7") +mcl_jukebox.register_record("The Clueless Frog (Jordach's Mix)", "SoundHelix", "mall", "mcl_jukebox_record_mall.png", "mcl_jukebox_track_8") \ No newline at end of file From 20b7b6ff994892822d421d7b9c0c6753ea972dc4 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 12 Mar 2021 00:24:34 +0100 Subject: [PATCH 2/6] Add API documentation for mcl_jukeboxe --- mods/ITEMS/mcl_jukebox/API.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 mods/ITEMS/mcl_jukebox/API.md diff --git a/mods/ITEMS/mcl_jukebox/API.md b/mods/ITEMS/mcl_jukebox/API.md new file mode 100644 index 00000000..85900ede --- /dev/null +++ b/mods/ITEMS/mcl_jukebox/API.md @@ -0,0 +1,18 @@ +# mcl_jukebox + +## mcl_jukebox.register_record(title, author, identifier, image, sound) + +* title: title of the track +* author: author of the track +* identifier: short string used in the item registration +* image: the texture of the track +* sound: sound file of the track + +## mcl_jukebox.registered_records + +Table indexed by item name containing: +* title: title of the track +* author: author of the track +* identifier: short string used in the item registration +* image: the texture of the track +* sound: sound file of the track \ No newline at end of file From e858ea623388934e319c1485ab4f810e1147f03d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 12 Mar 2021 15:36:24 +0100 Subject: [PATCH 3/6] Add backward compatibility for mcl_jukeboxes --- mods/ITEMS/mcl_jukebox/init.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_jukebox/init.lua b/mods/ITEMS/mcl_jukebox/init.lua index b9f762a5..c5bd3d26 100644 --- a/mods/ITEMS/mcl_jukebox/init.lua +++ b/mods/ITEMS/mcl_jukebox/init.lua @@ -233,4 +233,14 @@ mcl_jukebox.register_record("Minetest", "Jordach", "far", "mcl_jukebox_record_fa mcl_jukebox.register_record("Credit Roll (Jordach's HD Mix)", "Junichi Masuda", "chirp", "mcl_jukebox_record_chirp.png", "mcl_jukebox_track_5") mcl_jukebox.register_record("Winter Feeling", "Tom Peter", "strad", "mcl_jukebox_record_strad.png", "mcl_jukebox_track_6") mcl_jukebox.register_record("Synthgroove (Jordach's Mix)", "HeroOfTheWinds", "mellohi", "mcl_jukebox_record_mellohi.png", "mcl_jukebox_track_7") -mcl_jukebox.register_record("The Clueless Frog (Jordach's Mix)", "SoundHelix", "mall", "mcl_jukebox_record_mall.png", "mcl_jukebox_track_8") \ No newline at end of file +mcl_jukebox.register_record("The Clueless Frog (Jordach's Mix)", "SoundHelix", "mall", "mcl_jukebox_record_mall.png", "mcl_jukebox_track_8") + +--add backward compatibility +minetest.register_alias("mcl_jukebox:record_1", "mcl_jukebox:record_13") +minetest.register_alias("mcl_jukebox:record_2", "mcl_jukebox:record_wait") +minetest.register_alias("mcl_jukebox:record_3", "mcl_jukebox:record_blocks") +minetest.register_alias("mcl_jukebox:record_4", "mcl_jukebox:record_far") +minetest.register_alias("mcl_jukebox:record_5", "mcl_jukebox:record_chirp") +minetest.register_alias("mcl_jukebox:record_6", "mcl_jukebox:record_strad") +minetest.register_alias("mcl_jukebox:record_7", "mcl_jukebox:record_mellohi") +minetest.register_alias("mcl_jukebox:record_8", "mcl_jukebox:record_mall") \ No newline at end of file From 5f0710a486459ebd620001c6e74899a629eb03ba Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Tue, 15 Jun 2021 17:33:43 +0200 Subject: [PATCH 4/6] Make jukebox accept and play old music records With the introduction of the mcl_jukebox API, all music record items were given new names. Old music record items were aliased, but never worked with the jukebox. Apparently no one tested existing records. By explicitly looking up the item name in minetest.registered_aliases, the jukebox accepts old records, plays them, and gives out new records. --- mods/ITEMS/mcl_jukebox/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_jukebox/init.lua b/mods/ITEMS/mcl_jukebox/init.lua index c5bd3d26..cc5e97ee 100644 --- a/mods/ITEMS/mcl_jukebox/init.lua +++ b/mods/ITEMS/mcl_jukebox/init.lua @@ -92,7 +92,9 @@ minetest.register_craft({ }) local play_record = function(pos, itemstack, player) - local name = itemstack:get_name() + local item_name = itemstack:get_name() + -- ensure the jukebox uses the new record names for old records + local name = minetest.registered_aliases[item_name] or item_name if mcl_jukebox.registered_records[name] then local cname = player:get_player_name() if active_tracks[cname] ~= nil then From 7ccdbc5905aac78be6c323a45e73ebbdb933fee1 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Tue, 15 Jun 2021 23:22:37 +0200 Subject: [PATCH 5/6] Document that music_record group, if it exists, is always 1 --- GROUPS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GROUPS.md b/GROUPS.md index f94b0497..860dcfb1 100644 --- a/GROUPS.md +++ b/GROUPS.md @@ -149,7 +149,7 @@ These groups are used mostly for informational purposes * `trapdoor=2`: Open trapdoor * `glass=1`: Glass (full cubes only) * `rail=1`: Rail -* `music_record`: Music Disc (rating is track ID) +* `music_record=1`: Music Disc * `tnt=1`: Block is TNT * `boat=1`: Boat * `minecart=1`: Minecart From 79766bff23facb9e5c4caa81597cbd1b6477d648 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 15 Jun 2021 01:13:24 +0200 Subject: [PATCH 6/6] Fix server crash when players dig unknown nodes Digging unknown nodes crashes the Clamity Minetest server, which runs modified Minetest: https://github.com/ClamityAnarchy/minetest Crashes did occur with commit d5434bf008 of that Minetest version. This commit makes unknown nodes explicitly not harvestable. --- mods/CORE/_mcl_autogroup/init.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index c8475d0b..d714db7d 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -207,6 +207,10 @@ end function mcl_autogroup.can_harvest(nodename, toolname) local ndef = minetest.registered_nodes[nodename] + if not ndef then + return false + end + if minetest.get_item_group(nodename, "dig_immediate") >= 2 then return true end