opus/sys/apis/sound.lua

19 lines
337 B
Lua
Raw Normal View History

2018-11-27 01:53:28 +00:00
local peripheral = _G.peripheral
2018-12-04 06:33:58 +00:00
local Sound = {
_volume = 1,
}
2018-11-27 01:53:28 +00:00
function Sound.play(sound, vol)
2018-11-29 20:12:25 +00:00
local speaker = peripheral.find('speaker')
2018-11-27 01:53:28 +00:00
if speaker then
2018-12-04 06:33:58 +00:00
speaker.playSound('minecraft:' .. sound, vol or Sound._volume)
2018-11-27 01:53:28 +00:00
end
end
2018-12-04 06:33:58 +00:00
function Sound.setVolume(volume)
Sound._volume = math.max(0, math.min(volume, 1))
end
2018-11-27 01:53:28 +00:00
return Sound