Skip to content

Commit

Permalink
fix: play menu music after second reload
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv256 committed Nov 27, 2024
1 parent 00d0b8b commit 5942ab0
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import gay.sylv.legacy_landscape.client.LegacyResourceFaker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.sounds.MusicManager;
import net.minecraft.sounds.Musics;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -15,19 +18,31 @@ public abstract class Mixin_Minecraft {
@Shadow
public abstract CompletableFuture<Void> reloadResourcePacks();

@Shadow
public abstract MusicManager getMusicManager();

@Unique
private boolean legacy_landscape$secondGameLoadFinished = false;

@Inject(
method = "onResourceLoadFinished",
at = @At("TAIL")
at = @At("HEAD")
)
private void onFinishLoad(Minecraft.GameLoadCookie gameLoadCookie, CallbackInfo ci) {
this.getMusicManager().stopPlaying();
LegacyResourceFaker.loadLegacyResources();
if (legacy_landscape$secondGameLoadFinished) {
legacy_landscape$secondGameLoadFinished = false;
this.getMusicManager().startPlaying(Musics.MENU);
}
}

@Inject(
method = "onGameLoadFinished",
at = @At("TAIL")
)
private void onGameLoadFinished(Minecraft.GameLoadCookie gameLoadCookie, CallbackInfo ci) {
legacy_landscape$secondGameLoadFinished = true;
this.reloadResourcePacks();
}
}

0 comments on commit 5942ab0

Please sign in to comment.