Skip to content

Commit

Permalink
Restore menu music overrides.
Browse files Browse the repository at this point in the history
- Fix menu music overrides (probably)
* Super sketchy work-around hopefully resolves #36
  • Loading branch information
gniftygnome committed Feb 26, 2024
1 parent 975fc31 commit d5bf485
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.resource.ReloadableResourceManagerImpl;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.sound.MusicSound;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -23,17 +23,17 @@

@Environment(EnvType.CLIENT)
@Mixin(MinecraftClient.class)
public class MinecraftClientMixin implements MinecraftClientAccess {
public abstract class MinecraftClientMixin implements MinecraftClientAccess {
@Unique
private PanoramaResourceReloader panoramaResourceReloader;

@Shadow
@Final
private ReloadableResourceManagerImpl resourceManager;

@Nullable
@Shadow
public ClientPlayerEntity player;
@Nullable
private IntegratedServer server;

@Inject(
method = "<init>",
Expand All @@ -51,7 +51,7 @@ public class MinecraftClientMixin implements MinecraftClientAccess {

@Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true)
private void vistas$getMusicType(CallbackInfoReturnable<MusicSound> ci) {
if (this.player == null) {
if (this.server == null) {
ci.setReturnValue(VistasTitle.CURRENT.getValue().getMusicSound());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.client.sound.MusicType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.sound.MusicSound;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;

import java.util.List;
Expand All @@ -19,16 +18,16 @@ public class Panorama {
public static final Codec<MusicSound> OPTIONAL_MUSIC_SOUND_CODEC = RecordCodecBuilder.create(
(instance) ->
instance.group(
SoundEvent.CODEC.optionalFieldOf("sound")
.forGetter((sound) -> Optional.of(sound.getSound().value())),
Identifier.CODEC.fieldOf("sound")
.forGetter((sound) -> sound.getSound().getKey().orElseThrow().getValue()),
Codec.INT.optionalFieldOf("min_delay")
.forGetter((sound) -> Optional.of(sound.getMinDelay())),
Codec.INT.optionalFieldOf("max_delay")
.forGetter((sound) -> Optional.of(sound.getMaxDelay())),
Codec.BOOL.optionalFieldOf("replace_current_music")
.forGetter((sound) -> Optional.of(sound.shouldReplaceCurrentMusic()))
)
.apply(instance, (sound, min, max, replace)-> new MusicSound(sound.map(Registries.SOUND_EVENT::getEntry).orElse(SoundEvents.MUSIC_MENU), min.orElse(20), max.orElse(600), replace.orElse(true))));
.apply(instance, (sound, min, max, replace) -> new MusicSound(RegistryEntry.of(SoundEvent.of(sound)), min.orElse(20), max.orElse(600), replace.orElse(true))));

public static final Codec<Panorama> CODEC = RecordCodecBuilder.create(
(instance) ->
Expand Down

0 comments on commit d5bf485

Please sign in to comment.