}
})
+local music_handles = {}
+
local music_player_formspec =
"invsize[8,9;]"..
"label[0,0;"..S("Music Player").."]"..
"button[6,4;1,2;stop;Stop]"..
"label[4,0;Current track --]"
+local function play_track(pos, track)
+ return minetest.sound_play("technic_track"..track,
+ {pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,})
+end
+
minetest.register_node("technic:music_player", {
description = S("Music Player"),
tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png",
end,
on_receive_fields = function(pos, formanme, fields, sender)
local meta = minetest.get_meta(pos)
- local music_handle = meta:get_int("music_handle")
+ local pos_hash = minetest.hash_node_position(pos)
+ local music_handle = music_handles[pos_hash]
local current_track = meta:get_int("current_track")
if fields.track1 then current_track = 1 end
if fields.track2 then current_track = 2 end
if music_handle then
minetest.sound_stop(music_handle)
end
+ music_handle = play_track(pos, current_track)
meta:set_int("active", 1)
end
if fields.stop then
minetest.sound_stop(music_handle)
end
end
- meta:set_int("music_handle", music_handle)
+ music_handles[pos_hash] = music_handle
end,
})
local machine_node = "technic:music_player"
local demand = 150
- local music_handle = meta:get_int("music_handle")
local current_track = meta:get_int("current_track")
+ local pos_hash = minetest.hash_node_position(pos)
+ local music_handle = music_handles[pos_hash]
-- Setup meta data if it does not exist.
if not eu_input then
if meta:get_int("active") == 0 then
meta:set_string("infotext", S("%s Idle"):format(machine_name))
meta:set_int("LV_EU_demand", 0)
- if music_handle then
- minetest.sound_stop(music_handle)
- end
return
end
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
if music_handle then
minetest.sound_stop(music_handle)
+ music_handle = nil
end
elseif eu_input >= demand then
meta:set_string("infotext", S("%s Active"):format(machine_name))
- music_handle = minetest.sound_play("technic_track"..current_track,
- {pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,})
- meta:set_int("music_handle", music_handle)
+ if not music_handle then
+ music_handle = play_track(pos, current_track)
+ end
end
+ music_handles[pos_hash] = music_handle
meta:set_int("LV_EU_demand", demand)
end
})