mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-03-29 06:46:58 +00:00
Clamp speaker volume again
Looks like this was removed in b048b6666d652dafc4614b086782f956de58d377.
This commit is contained in:
parent
aa203802c6
commit
230c7ee904
@ -8,7 +8,6 @@ package dan200.computercraft.shared.peripheral.speaker;
|
|||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.api.lua.LuaTable;
|
import dan200.computercraft.api.lua.LuaTable;
|
||||||
import dan200.computercraft.shared.util.PauseAwareTimer;
|
import dan200.computercraft.shared.util.PauseAwareTimer;
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -16,6 +15,7 @@ import java.util.Optional;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral.SAMPLE_RATE;
|
import static dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral.SAMPLE_RATE;
|
||||||
|
import static dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral.clampVolume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal state of the DFPWM decoder and the state of playback.
|
* Internal state of the DFPWM decoder and the state of playback.
|
||||||
@ -82,7 +82,7 @@ class DfpwmState {
|
|||||||
buffer.flip();
|
buffer.flip();
|
||||||
|
|
||||||
pendingAudio = buffer;
|
pendingAudio = buffer;
|
||||||
pendingVolume = Mth.clamp(volume.orElse((double) pendingVolume).floatValue(), 0.0f, 3.0f);
|
pendingVolume = (float) clampVolume(volume.orElse((double) pendingVolume));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -203,7 +204,7 @@ public abstract class SpeakerPeripheral implements IPeripheral {
|
|||||||
*/
|
*/
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public final boolean playNote(ILuaContext context, String instrumentA, Optional<Double> volumeA, Optional<Double> pitchA) throws LuaException {
|
public final boolean playNote(ILuaContext context, String instrumentA, Optional<Double> volumeA, Optional<Double> pitchA) throws LuaException {
|
||||||
var volume = (float) checkFinite(1, volumeA.orElse(1.0));
|
var volume = (float) clampVolume(checkFinite(1, volumeA.orElse(1.0)));
|
||||||
var pitch = (float) checkFinite(2, pitchA.orElse(1.0));
|
var pitch = (float) checkFinite(2, pitchA.orElse(1.0));
|
||||||
|
|
||||||
NoteBlockInstrument instrument = null;
|
NoteBlockInstrument instrument = null;
|
||||||
@ -248,7 +249,7 @@ public abstract class SpeakerPeripheral implements IPeripheral {
|
|||||||
*/
|
*/
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public final boolean playSound(ILuaContext context, String name, Optional<Double> volumeA, Optional<Double> pitchA) throws LuaException {
|
public final boolean playSound(ILuaContext context, String name, Optional<Double> volumeA, Optional<Double> pitchA) throws LuaException {
|
||||||
var volume = (float) checkFinite(1, volumeA.orElse(1.0));
|
var volume = (float) clampVolume(checkFinite(1, volumeA.orElse(1.0)));
|
||||||
var pitch = (float) checkFinite(2, pitchA.orElse(1.0));
|
var pitch = (float) checkFinite(2, pitchA.orElse(1.0));
|
||||||
|
|
||||||
ResourceLocation identifier;
|
ResourceLocation identifier;
|
||||||
@ -361,6 +362,10 @@ public abstract class SpeakerPeripheral implements IPeripheral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double clampVolume(double volume) {
|
||||||
|
return Mth.clamp(volume, 0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
private record PendingSound<T>(T sound, float volume, float pitch) {
|
private record PendingSound<T>(T sound, float volume, float pitch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user