2017-01-11 16:25:04 +01:00
local active_tracks = { }
2017-01-11 22:32:38 +01:00
local active_huds = { }
2017-01-11 16:25:04 +01:00
local recorddata = {
{ " 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 " } ,
2017-06-08 03:03:46 +02:00
{ " Winter Feeling " , " Tom Peter " , " strad " } ,
2017-01-11 16:25:04 +01:00
{ " Synthgroove (Jordach's Mix) " , " HeroOfTheWinds " , " mellohi " } ,
{ " The Clueless Frog (Jordach's Mix) " , " SoundHelix " , " mall " } ,
}
local records = # recorddata
for r = 1 , records do
2017-03-10 05:10:08 +01:00
local doc = false
2017-08-02 01:34:12 +02:00
local entryname , longdesc , usagehelp
2017-03-10 05:10:08 +01:00
if r == 1 then
doc = true
entryname = " Music Disc "
longdesc = " A music disc holds a single music track which can be used in a jukebox to play music. "
usagehelp = " Rightclick an empty jukebox with the music disc in your hand to play the music. Rightclick the jukebox again to retrieve the music disc. The music can only be heard by you, not by other players. "
end
2017-01-11 16:25:04 +01:00
minetest.register_craftitem ( " mcl_jukebox:record_ " .. r , {
description =
2017-01-12 00:24:52 +01:00
core.colorize ( " #55FFFF " , " Music Disc " ) .. " \n " ..
core.colorize ( " #989898 " , recorddata [ r ] [ 2 ] .. " — " .. recorddata [ r ] [ 1 ] ) ,
2017-03-10 05:10:08 +01:00
_doc_items_create_entry = doc ,
_doc_items_entry_name = entryname ,
_doc_items_longdesc = longdesc ,
_doc_items_usagehelp = usagehelp ,
2017-01-11 16:25:04 +01:00
inventory_image = " mcl_jukebox_record_ " .. recorddata [ r ] [ 3 ] .. " .png " ,
stack_max = 1 ,
groups = { music_record = r } ,
} )
end
2017-01-11 22:32:38 +01:00
local function now_playing ( player , track_id )
local hud = active_huds [ player : get_player_name ( ) ]
2017-01-11 23:09:21 +01:00
local text = " Now playing: " .. recorddata [ track_id ] [ 2 ] .. " — " .. recorddata [ track_id ] [ 1 ]
2017-01-11 22:32:38 +01:00
2017-01-20 03:28:53 +01:00
local id
2017-01-11 22:32:38 +01:00
if hud ~= nil then
2017-01-11 23:22:09 +01:00
player : hud_change ( active_huds [ player : get_player_name ( ) ] , " text " , text )
2017-01-11 22:32:38 +01:00
else
2017-01-20 03:28:53 +01:00
id = player : hud_add ( {
2017-01-11 22:32:38 +01:00
hud_elem_type = " text " ,
position = { x = 0.5 , y = 0.8 } ,
offset = { x = 0 , y = 0 } ,
size = { x = 100 , y = 100 } ,
2017-01-12 00:24:52 +01:00
number = 0x55FFFF ,
2017-01-11 22:32:38 +01:00
text = text ,
} )
active_huds [ player : get_player_name ( ) ] = id
end
minetest.after ( 5 , function ( tab )
local player = tab [ 1 ]
local id = tab [ 2 ]
if not player or not player : is_player ( ) or not active_huds [ player : get_player_name ( ) ] then
return
end
if id == active_huds [ player : get_player_name ( ) ] then
player : hud_remove ( active_huds [ player : get_player_name ( ) ] )
2017-01-11 23:22:09 +01:00
active_huds [ player : get_player_name ( ) ] = nil
2017-01-11 22:32:38 +01:00
end
end , { player , id } )
end
minetest.register_on_leaveplayer ( function ( player )
active_tracks [ player : get_player_name ( ) ] = nil
active_huds [ player : get_player_name ( ) ] = nil
end )
2017-01-11 16:25:04 +01:00
-- Jukebox crafting
minetest.register_craft ( {
output = ' mcl_jukebox:jukebox ' ,
recipe = {
{ ' group:wood ' , ' group:wood ' , ' group:wood ' } ,
2017-01-31 23:32:56 +01:00
{ ' group:wood ' , ' mcl_core:diamond ' , ' group:wood ' } ,
2017-01-11 16:25:04 +01:00
{ ' group:wood ' , ' group:wood ' , ' group:wood ' } ,
}
} )
2017-01-11 22:32:38 +01:00
2017-01-11 16:25:04 +01:00
-- Jukebox
minetest.register_node ( " mcl_jukebox:jukebox " , {
description = " Jukebox " ,
2017-03-10 05:10:08 +01:00
_doc_items_longdesc = " Jukeboxes play music when they're supplied with a music disc. " ,
_doc_items_usagehelp = " Place a music disc into an empty jukebox to insert the music disc and play music. If the jukebox already has a music disc, you will retrieve this music disc first. The music can only be heard by you, not by other players. " ,
2017-01-11 16:25:04 +01:00
tiles = { " mcl_jukebox_top.png " , " mcl_jukebox_side.png " , " mcl_jukebox_side.png " } ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2017-03-11 05:34:58 +01:00
groups = { handy = 1 , axey = 1 , deco_block = 1 , material_wood = 1 } ,
2017-03-11 16:36:05 +01:00
is_ground_content = false ,
2017-01-11 16:25:04 +01:00
on_construct = function ( pos )
local meta = minetest.get_meta ( pos )
local inv = meta : get_inventory ( )
inv : set_size ( " main " , 1 )
end ,
2017-01-11 22:40:00 +01:00
on_rightclick = function ( pos , node , clicker , itemstack , pointed_thing )
if not clicker then return end
local cname = clicker : get_player_name ( )
2017-01-11 16:25:04 +01:00
local meta = minetest.get_meta ( pos )
local inv = meta : get_inventory ( )
if not inv : is_empty ( " main " ) then
-- Jukebox contains a disc: Stop music and remove disc
2017-01-11 22:40:00 +01:00
if active_tracks [ cname ] ~= nil then
minetest.sound_stop ( active_tracks [ cname ] )
2017-01-11 16:25:04 +01:00
end
local lx = pos.x
local ly = pos.y + 1
local lz = pos.z
local record = inv : get_stack ( " main " , 1 )
minetest.add_item ( { x = lx , y = ly , z = lz } , record : get_name ( ) )
inv : set_stack ( " main " , 1 , " " )
2017-01-11 22:40:00 +01:00
if active_tracks [ cname ] ~= nil then
minetest.sound_stop ( active_tracks [ cname ] )
clicker : hud_remove ( active_huds [ cname ] )
active_tracks [ cname ] = nil
active_huds [ cname ] = nil
2017-01-11 16:25:04 +01:00
end
else
-- Jukebox is empty: Play track if player holds music record
2017-01-11 22:40:00 +01:00
local record_id = minetest.get_item_group ( itemstack : get_name ( ) , " music_record " )
2017-01-11 16:25:04 +01:00
if record_id ~= 0 then
2017-01-11 22:40:00 +01:00
if active_tracks [ cname ] ~= nil then
minetest.sound_stop ( active_tracks [ cname ] )
2017-01-11 23:22:09 +01:00
active_tracks [ cname ] = nil
2017-01-11 16:25:04 +01:00
end
2017-01-11 22:40:00 +01:00
active_tracks [ cname ] = minetest.sound_play ( " mcl_jukebox_track_ " .. record_id , {
to_player = cname ,
2017-01-11 16:25:04 +01:00
--max_hear_distance = 16,
gain = 1 ,
} )
2017-01-11 22:40:00 +01:00
now_playing ( clicker , record_id )
inv : set_stack ( " main " , 1 , itemstack : get_name ( ) )
itemstack : take_item ( )
return itemstack
2017-01-11 16:25:04 +01:00
end
end
end ,
after_dig_node = function ( pos , oldnode , oldmetadata , digger )
2017-01-11 22:52:34 +01:00
local name = digger : get_player_name ( )
2017-01-11 16:25:04 +01:00
local meta = minetest.get_meta ( pos )
local meta2 = meta
meta : from_table ( oldmetadata )
local inv = meta : get_inventory ( )
local stack = inv : get_stack ( " main " , 1 )
if not stack : is_empty ( ) then
local p = { x = pos.x + math.random ( 0 , 10 ) / 10 - 0.5 , y = pos.y , z = pos.z + math.random ( 0 , 10 ) / 10 - 0.5 }
minetest.add_item ( p , stack )
2017-01-11 22:54:31 +01:00
if active_tracks [ name ] ~= nil then
minetest.sound_stop ( active_tracks [ name ] )
digger : hud_remove ( active_huds [ name ] )
2017-01-11 23:22:09 +01:00
active_tracks [ name ] = nil
active_huds [ name ] = nil
2017-01-11 22:54:31 +01:00
end
2017-01-11 16:25:04 +01:00
end
meta : from_table ( meta2 : to_table ( ) )
end ,
2017-02-22 16:03:59 +01:00
_mcl_blast_resistance = 30 ,
2017-02-27 01:33:34 +01:00
_mcl_hardness = 2 ,
2017-01-11 16:25:04 +01:00
} )
2017-01-11 22:48:53 +01:00
minetest.register_craft ( {
type = " fuel " ,
recipe = " mcl_jukebox:jukebox " ,
burntime = 15 ,
} )