diff --git a/sys/apis/sound.lua b/sys/apis/sound.lua index 28ca11c..b4dab46 100644 --- a/sys/apis/sound.lua +++ b/sys/apis/sound.lua @@ -1,12 +1,18 @@ local peripheral = _G.peripheral -local Sound = { } +local Sound = { + _volume = 1, +} function Sound.play(sound, vol) local speaker = peripheral.find('speaker') if speaker then - speaker.playSound('minecraft:' .. sound, vol or 1) + speaker.playSound('minecraft:' .. sound, vol or Sound._volume) end end +function Sound.setVolume(volume) + Sound._volume = math.max(0, math.min(volume, 1)) +end + return Sound