mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-01 01:57:55 +00:00
Make SoundEngine#play mixin cancellable.
No reason to call channel.play() twice.
This commit is contained in:
@@ -20,14 +20,16 @@ public class SpeakerManager
|
||||
{
|
||||
private static final Map<UUID, SpeakerInstance> sounds = new ConcurrentHashMap<>();
|
||||
|
||||
public static void playStreaming( SoundInstance soundInstance, Channel channel )
|
||||
// A return value of true cancels the event
|
||||
public static boolean playStreaming( SoundInstance soundInstance, Channel channel )
|
||||
{
|
||||
if( !(soundInstance instanceof SpeakerSound) ) return;
|
||||
if( !(soundInstance instanceof SpeakerSound) ) return false;
|
||||
SpeakerSound sound = (SpeakerSound) soundInstance;
|
||||
if( sound.stream == null ) return;
|
||||
if( sound.stream == null ) return false;
|
||||
|
||||
channel.attachBufferStream( sound.stream );
|
||||
channel.play();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static SpeakerInstance getSound( UUID source )
|
||||
|
@@ -19,18 +19,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin( SoundEngine.class )
|
||||
public class MixinSoundEngine
|
||||
{
|
||||
// Used to capture the SoundInstance argument passed to SoundEngine#Play. Not a thread-safe way to do it but
|
||||
// Used to capture the SoundInstance argument passed to SoundEngine#play. Not a thread-safe way to do it but
|
||||
// this code is only called from the render thread as far as I can tell.
|
||||
@Unique
|
||||
private static SoundInstance onPlaySoundInstanceCapture;
|
||||
|
||||
@Inject(
|
||||
method = "lambda$play$8",
|
||||
at = @At( "TAIL" )
|
||||
at = @At( "HEAD" ),
|
||||
cancellable = true
|
||||
)
|
||||
private static void onStreamingSourcePlay( AudioStream audioStream, Channel channel, CallbackInfo ci )
|
||||
{
|
||||
SpeakerManager.playStreaming( onPlaySoundInstanceCapture, channel );
|
||||
if( SpeakerManager.playStreaming( onPlaySoundInstanceCapture, channel ) ) ci.cancel();
|
||||
}
|
||||
|
||||
@Inject(
|
||||
|
Reference in New Issue
Block a user