Skip to content

Commit

Permalink
Fix background music looping when it shouldn't
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Jan 29, 2024
1 parent 25727a0 commit d4c998e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Expand Up @@ -30,22 +30,22 @@
p_194488_.setSelfPosition(vec3);
p_194488_.setRelative(flag);
});
+ final SoundInstance soundinstance = p_120313_;
+ final SoundInstance soundinstance = p_120313_;
if (!flag2) {
this.soundBuffers.getCompleteBuffer(sound.getPath()).thenAccept((p_194501_) -> {
channelaccess$channelhandle.execute((p_194495_) -> {
p_194495_.attachStaticBuffer(p_194501_);
p_194495_.play();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.PlaySoundSourceEvent(this, soundinstance, p_194495_));
+ net.minecraftforge.client.event.ForgeEventFactoryClient.onPlaySoundSource(this, soundinstance, p_194495_);
});
});
} else {
- this.soundBuffers.getStream(sound.getPath(), flag1).thenAccept((p_194504_) -> {
+ soundinstance.getStream(this.soundBuffers, sound, flag2).thenAccept((p_194504_) -> {
+ soundinstance.getStream(this.soundBuffers, sound, flag1).thenAccept((p_194504_) -> {
channelaccess$channelhandle.execute((p_194498_) -> {
p_194498_.attachBufferStream(p_194504_);
p_194498_.play();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.PlayStreamingSourceEvent(this, soundinstance, p_194498_));
+ net.minecraftforge.client.event.ForgeEventFactoryClient.onPlayStreamingSource(this, soundinstance, p_194498_);
});
});
}
Expand Up @@ -9,13 +9,19 @@

import org.jetbrains.annotations.Nullable;

import com.mojang.blaze3d.audio.Channel;

import net.minecraft.client.MouseHandler;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider.Context;
import net.minecraft.client.resources.PlayerSkin.Model;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.SoundEngine;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.client.event.sound.PlaySoundSourceEvent;
import net.minecraftforge.client.event.sound.PlayStreamingSourceEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.ModLoader;
Expand Down Expand Up @@ -91,4 +97,12 @@ public static void onScreenMouseDragPost(Screen guiScreen, double mouseX, double
public static void onScreenClose(Screen screen) {
post(new ScreenEvent.Closing(screen));
}

public static void onPlaySoundSource(SoundEngine engine, SoundInstance sound, Channel channel) {
post(new PlaySoundSourceEvent(engine, sound, channel));
}

public static void onPlayStreamingSource(SoundEngine engine, SoundInstance sound, Channel channel) {
post(new PlayStreamingSourceEvent(engine, sound, channel));
}
}
Expand Up @@ -18,7 +18,6 @@

import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
Expand Down

0 comments on commit d4c998e

Please sign in to comment.