mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-07 04:47: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<>();
|
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;
|
SpeakerSound sound = (SpeakerSound) soundInstance;
|
||||||
if( sound.stream == null ) return;
|
if( sound.stream == null ) return false;
|
||||||
|
|
||||||
channel.attachBufferStream( sound.stream );
|
channel.attachBufferStream( sound.stream );
|
||||||
channel.play();
|
channel.play();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SpeakerInstance getSound( UUID source )
|
public static SpeakerInstance getSound( UUID source )
|
||||||
|
@@ -19,18 +19,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
@Mixin( SoundEngine.class )
|
@Mixin( SoundEngine.class )
|
||||||
public class MixinSoundEngine
|
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.
|
// this code is only called from the render thread as far as I can tell.
|
||||||
@Unique
|
@Unique
|
||||||
private static SoundInstance onPlaySoundInstanceCapture;
|
private static SoundInstance onPlaySoundInstanceCapture;
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "lambda$play$8",
|
method = "lambda$play$8",
|
||||||
at = @At( "TAIL" )
|
at = @At( "HEAD" ),
|
||||||
|
cancellable = true
|
||||||
)
|
)
|
||||||
private static void onStreamingSourcePlay( AudioStream audioStream, Channel channel, CallbackInfo ci )
|
private static void onStreamingSourcePlay( AudioStream audioStream, Channel channel, CallbackInfo ci )
|
||||||
{
|
{
|
||||||
SpeakerManager.playStreaming( onPlaySoundInstanceCapture, channel );
|
if( SpeakerManager.playStreaming( onPlaySoundInstanceCapture, channel ) ) ci.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
|
Reference in New Issue
Block a user