2013-07-17 15:34:35 -04:00
|
|
|
-- LV Music player.
|
|
|
|
-- The player can play music. But it is high ampage!
|
|
|
|
|
2013-10-30 13:45:32 -04:00
|
|
|
local S = technic.getter
|
|
|
|
|
2013-07-17 15:34:35 -04:00
|
|
|
minetest.register_alias("music_player", "technic:music_player")
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'technic:music_player',
|
|
|
|
recipe = {
|
2014-07-07 21:48:38 +01:00
|
|
|
{'technic:chromium_ingot', 'default:diamond', 'technic:chromium_ingot'},
|
|
|
|
{'default:diamond', 'technic:machine_casing', 'default:diamond'},
|
|
|
|
{'default:mossycobble', 'technic:lv_cable0', 'default:mossycobble'},
|
2013-07-17 15:34:35 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2013-12-16 18:57:01 -05:00
|
|
|
local music_handles = {}
|
|
|
|
|
|
|
|
local function play_track(pos, track)
|
2014-01-10 21:57:16 -06:00
|
|
|
return minetest.sound_play("technic_track"..tostring(track),
|
2013-12-16 18:57:01 -05:00
|
|
|
{pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,})
|
|
|
|
end
|
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
local run = function(pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local eu_input = meta:get_int("LV_EU_input")
|
|
|
|
local machine_name = S("%s Music Player"):format("LV")
|
|
|
|
local machine_node = "technic:music_player"
|
|
|
|
local demand = 150
|
|
|
|
|
|
|
|
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
|
|
|
|
meta:set_int("LV_EU_demand", demand)
|
|
|
|
meta:set_int("LV_EU_input", 0)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if meta:get_int("active") == 0 then
|
|
|
|
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
|
|
|
meta:set_int("LV_EU_demand", 0)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if eu_input < demand then
|
|
|
|
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))
|
|
|
|
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
|
|
|
|
|
2014-08-14 15:04:42 +01:00
|
|
|
local function stop_player(pos, node)
|
|
|
|
local pos_hash = minetest.hash_node_position(pos)
|
|
|
|
local music_handle = music_handles[pos_hash]
|
|
|
|
if music_handle then
|
|
|
|
minetest.sound_stop(music_handle)
|
|
|
|
music_handles[pos_hash] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-14 15:29:50 +01:00
|
|
|
local function set_display(meta)
|
|
|
|
meta:set_string("formspec",
|
|
|
|
"size[4,4.5]"..
|
|
|
|
"item_image[0,0;1,1;technic:music_player]"..
|
|
|
|
"label[1,0;"..S("%s Music Player"):format("LV").."]"..
|
|
|
|
"button[0,1;1,1;track1;1]"..
|
|
|
|
"button[1,1;1,1;track2;2]"..
|
|
|
|
"button[2,1;1,1;track3;3]"..
|
|
|
|
"button[0,2;1,1;track4;4]"..
|
|
|
|
"button[1,2;1,1;track5;5]"..
|
|
|
|
"button[2,2;1,1;track6;6]"..
|
|
|
|
"button[0,3;1,1;track7;7]"..
|
|
|
|
"button[1,3;1,1;track8;8]"..
|
|
|
|
"button[2,3;1,1;track9;9]"..
|
|
|
|
"button[3,1;1,1;stop;Stop]"..
|
|
|
|
"label[0,4;"..minetest.formspec_escape(
|
|
|
|
meta:get_int("active") == 0 and
|
|
|
|
S("Stopped") or
|
|
|
|
S("Current track %s"):format(meta:get_int("current_track"))).."]")
|
|
|
|
end
|
|
|
|
|
2013-07-17 15:34:35 -04:00
|
|
|
minetest.register_node("technic:music_player", {
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 16:58:52 +01:00
|
|
|
description = S("%s Music Player"):format("LV"),
|
2013-07-17 15:34:35 -04:00
|
|
|
tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png",
|
|
|
|
"technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png"},
|
2014-07-11 11:00:46 +02:00
|
|
|
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
|
2013-07-17 15:34:35 -04:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 16:58:52 +01:00
|
|
|
meta:set_string("infotext", S("%s Music Player"):format("LV"))
|
2014-08-14 15:29:50 +01:00
|
|
|
set_display(meta)
|
2013-07-17 15:34:35 -04:00
|
|
|
end,
|
|
|
|
on_receive_fields = function(pos, formanme, fields, sender)
|
2014-08-14 15:29:50 +01:00
|
|
|
local new_track = nil
|
|
|
|
if fields.stop then new_track = 0 end
|
|
|
|
if fields.track1 then new_track = 1 end
|
|
|
|
if fields.track2 then new_track = 2 end
|
|
|
|
if fields.track3 then new_track = 3 end
|
|
|
|
if fields.track4 then new_track = 4 end
|
|
|
|
if fields.track5 then new_track = 5 end
|
|
|
|
if fields.track6 then new_track = 6 end
|
|
|
|
if fields.track7 then new_track = 7 end
|
|
|
|
if fields.track8 then new_track = 8 end
|
|
|
|
if fields.track9 then new_track = 9 end
|
|
|
|
if new_track then
|
2014-08-14 15:04:42 +01:00
|
|
|
stop_player(pos)
|
2014-08-14 15:29:50 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_int("active", new_track == 0 and 0 or 1)
|
|
|
|
meta:set_int("current_track", new_track)
|
|
|
|
set_display(meta)
|
2013-07-17 15:34:35 -04:00
|
|
|
end
|
|
|
|
end,
|
2014-08-14 15:04:42 +01:00
|
|
|
on_destruct = stop_player,
|
2014-07-11 11:00:46 +02:00
|
|
|
technic_run = run,
|
2014-08-14 15:04:42 +01:00
|
|
|
technic_on_disable = stop_player,
|
2013-07-17 15:34:35 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
technic.register_machine("LV", "technic:music_player", technic.receiver)
|
|
|
|
|