2017-05-16 19:47:12 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Music player mod
|
|
|
|
-- By Kaadmy, for Pixture
|
|
|
|
--
|
2019-08-28 17:31:41 +02:00
|
|
|
local S = minetest.get_translator("music")
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
music = {}
|
|
|
|
|
2017-06-27 21:13:30 +02:00
|
|
|
music.default_track = minetest.settings:get("music_track") or "music_catsong"
|
|
|
|
music.track_length = tonumber(minetest.settings:get("music_track_length")) or 30.0
|
|
|
|
music.volume = tonumber(minetest.settings:get("music_volume")) or 1.0
|
2015-09-29 20:46:57 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
-- Array of music players
|
|
|
|
|
|
|
|
music.players = {}
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-06-27 21:13:30 +02:00
|
|
|
if minetest.settings:get_bool("music_enable") then
|
2015-09-01 17:15:24 +02:00
|
|
|
function music.stop(pos)
|
2017-05-12 04:29:55 +02:00
|
|
|
local dp = minetest.hash_node_position(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2019-08-28 17:31:41 +02:00
|
|
|
meta:set_string("infotext", S("Music Player (off)"))
|
2015-09-01 17:15:24 +02:00
|
|
|
meta:set_int("music_player_enabled", 0)
|
|
|
|
|
|
|
|
if music.players[dp] ~= nil then
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.sound_stop(music.players[dp]["handle"])
|
2015-09-01 17:15:24 +02:00
|
|
|
music.players[dp] = nil
|
|
|
|
end
|
|
|
|
end
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
function music.start(pos)
|
2017-05-12 04:29:55 +02:00
|
|
|
local dp = minetest.hash_node_position(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2019-08-28 17:31:41 +02:00
|
|
|
meta:set_string("infotext", S("Music Player (on)"))
|
2015-09-01 17:15:24 +02:00
|
|
|
meta:set_int("music_player_enabled", 1)
|
|
|
|
|
|
|
|
if music.players[dp] == nil then
|
|
|
|
music.players[dp] = {
|
2017-05-12 04:29:55 +02:00
|
|
|
["handle"] = minetest.sound_play(
|
2015-09-29 20:46:57 +02:00
|
|
|
music.default_track,
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
pos = pos,
|
2017-05-11 23:21:03 +02:00
|
|
|
gain = music.volume,
|
2017-05-10 19:19:28 +02:00
|
|
|
}),
|
2015-09-01 17:15:24 +02:00
|
|
|
["timer"] = 0,
|
|
|
|
["pos"] = pos,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
music.players[dp]["timer"] = 0
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.sound_stop(music.players[dp]["handle"])
|
|
|
|
music.players[dp]["handle"] = minetest.sound_play(
|
2015-09-29 20:46:57 +02:00
|
|
|
music.default_track,
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
pos = pos,
|
2017-05-11 23:21:03 +02:00
|
|
|
gain = music.volume,
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function music.update(pos)
|
2017-05-12 04:29:55 +02:00
|
|
|
local dp = minetest.hash_node_position(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
if music.players[dp] ~= nil then
|
2017-05-12 04:29:55 +02:00
|
|
|
local node = minetest.get_node(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
if node.name ~= "music:player" then
|
|
|
|
music.stop(pos)
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-05-12 01:05:36 +02:00
|
|
|
if music.players[dp]["timer"] > music.track_length then
|
2015-09-01 17:15:24 +02:00
|
|
|
music.start(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function music.toggle(pos)
|
2017-05-12 04:29:55 +02:00
|
|
|
local dp = minetest.hash_node_position(pos)
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if music.players[dp] == nil then
|
|
|
|
music.start(pos)
|
|
|
|
else
|
|
|
|
music.stop(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_node(
|
2015-09-01 17:15:24 +02:00
|
|
|
"music:player",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Music Player"),
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
tiles = {"music_top.png", "music_bottom.png", "music_side.png"},
|
|
|
|
|
|
|
|
inventory_image = "music_inventory.png",
|
|
|
|
wield_image = "music_inventory.png",
|
|
|
|
|
2019-08-29 14:52:32 +02:00
|
|
|
is_ground_content = false,
|
2019-09-06 15:51:59 +02:00
|
|
|
floodable = true,
|
2015-09-01 17:15:24 +02:00
|
|
|
paramtype = "light",
|
|
|
|
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-4/16, -0.5, -4/16, 4/16, -0.5 + (4/16), 4/16}
|
|
|
|
},
|
|
|
|
|
2019-08-29 14:58:02 +02:00
|
|
|
sounds = default.node_sound_defaults(),
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
on_construct = function(pos)
|
2017-05-10 19:19:28 +02:00
|
|
|
music.start(pos)
|
|
|
|
end,
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
after_destruct = function(pos)
|
2017-05-10 19:19:28 +02:00
|
|
|
music.stop(pos)
|
|
|
|
end,
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
on_rightclick = function(pos)
|
2017-05-10 19:19:28 +02:00
|
|
|
music.toggle(pos)
|
|
|
|
end,
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-09-04 14:58:05 +02:00
|
|
|
groups = {oddly_breakable_by_hand = 3, attached_node = 1}
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-08-29 14:42:50 +02:00
|
|
|
local function step(dtime)
|
2015-09-01 17:15:24 +02:00
|
|
|
for dp, _ in pairs(music.players) do
|
|
|
|
music.players[dp]["timer"] = music.players[dp]["timer"] + dtime
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
music.update(music.players[dp]["pos"])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_globalstep(step)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_abm(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2019-06-23 22:37:51 +02:00
|
|
|
label = "Music Player",
|
2015-09-01 17:15:24 +02:00
|
|
|
nodenames = {"music:player"},
|
|
|
|
chance = 1,
|
|
|
|
interval = 1,
|
|
|
|
action = function(pos, node)
|
2017-05-12 04:29:55 +02:00
|
|
|
if music.players[minetest.hash_node_position(pos)] == nil then
|
|
|
|
local meta = minetest.get_meta(pos)
|
2017-05-10 19:19:28 +02:00
|
|
|
if meta:get_int("music_player_enabled") == 1 then
|
|
|
|
music.start(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
else
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_node(
|
2015-09-01 17:15:24 +02:00
|
|
|
"music:player",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Music Player"),
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
tiles = {"music_top.png", "music_bottom.png", "music_side.png"},
|
|
|
|
|
|
|
|
inventory_image = "music_inventory.png",
|
|
|
|
wield_image = "music_inventory.png",
|
|
|
|
|
2019-08-29 14:52:32 +02:00
|
|
|
is_ground_content = false,
|
2019-09-06 15:51:59 +02:00
|
|
|
floodable = true,
|
2015-09-01 17:15:24 +02:00
|
|
|
paramtype = "light",
|
|
|
|
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {-4/16, -0.5, -4/16, 4/16, -0.5 + (4/16), 4/16}
|
|
|
|
},
|
|
|
|
|
2019-08-29 14:58:02 +02:00
|
|
|
sounds = default.node_sound_defaults(),
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
on_construct = function(pos)
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-08-28 17:31:41 +02:00
|
|
|
meta:set_string("infotext", S("Music Player (disabled by server)"))
|
2017-05-10 19:19:28 +02:00
|
|
|
end,
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-09-04 14:58:05 +02:00
|
|
|
groups = {oddly_breakable_by_hand = 3, attached_node = 1}
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
crafting.register_craft(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
output = "music:player",
|
2017-05-16 19:47:12 +02:00
|
|
|
items = {
|
|
|
|
"group:planks 5",
|
|
|
|
"default:ingot_steel",
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Achievements
|
|
|
|
|
|
|
|
achievements.register_achievement(
|
|
|
|
"musician",
|
|
|
|
{
|
2019-09-06 00:31:13 +02:00
|
|
|
title = S("Sound Engineer"),
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Craft a music player."),
|
2017-05-10 19:19:28 +02:00
|
|
|
times = 1,
|
|
|
|
craftitem = "music:player",
|
|
|
|
})
|
|
|
|
|
|
|
|
default.log("mod:music", "loaded")
|