summaryrefslogtreecommitdiff
path: root/music_player.lua
diff options
context:
space:
mode:
authorMaciej Kasatkin <mk@realbadangel.pl>2012-09-01 11:27:35 +0200
committerMaciej Kasatkin <mk@realbadangel.pl>2012-09-01 11:27:35 +0200
commitcabcae11d379ed921941bdf8f858356754df6da6 (patch)
tree259b59d686d92658ce385fb4444c330fc7827e3a /music_player.lua
parent167434085cf62f133aaeaeadd7f9eb80d946189f (diff)
music player power usage fix
Diffstat (limited to 'music_player.lua')
-rw-r--r--music_player.lua14
1 files changed, 8 insertions, 6 deletions
diff --git a/music_player.lua b/music_player.lua
index 72adee1..5b5c650 100644
--- a/music_player.lua
+++ b/music_player.lua
@@ -1,4 +1,3 @@
-
minetest.register_alias("music_player", "technic:music_player")
minetest.register_craft({
output = 'technic:music_player',
@@ -33,6 +32,7 @@ minetest.register_node("technic:music_player", {
internal_EU_buffer=0,
internal_EU_buffer_size=5000,
music_player_on=0,
+ music_playing =0,
music_handle = 0,
music_player_current_track =1,
on_construct = function(pos)
@@ -63,11 +63,13 @@ minetest.register_node("technic:music_player", {
if fields.track9 then music_player_current_track=9 end
meta:set_float("music_player_current_track",music_player_current_track)
if fields.play and player_on==1 then
- minetest.sound_stop(music_handle)
+ if music_handle then minetest.sound_stop(music_handle) end
music_handle=minetest.sound_play("technic_track"..music_player_current_track, {pos = pos, gain = 1.0,loop = true, max_hear_distance = 72,})
+ meta:set_float("music_playing",1)
end
if fields.stop then
- minetest.sound_stop(music_handle)
+ meta:set_float("music_playing",0)
+ if music_handle then minetest.sound_stop(music_handle) end
end
meta:set_float("music_handle",music_handle)
end,
@@ -86,13 +88,13 @@ minetest.register_abm({
local play_cost=80
if charge>play_cost then
- charge=charge-play_cost;
+ if meta:get_float("music_playing")==1 then charge=charge-play_cost end
meta:set_float("internal_EU_buffer",charge)
meta:set_float("music_player_on",1)
else
- player_on=0
+ meta:set_float("music_playing",0)
meta:set_float("music_player_on",0)
- minetest.sound_stop(music_handle)
+ if music_handle then minetest.sound_stop(music_handle) end
end
local load = math.floor((charge/max_charge)*100)
meta:set_string("formspec",