Raul

Make me a Minecraft mod for version fabric 1.21.11 that allows you to customise the totem popping sound right in the game options( it adds a button with a small menu in options)

Kodari AI
KodariNov 9 at 4:57 pm 4
TotemSoundCustomizer
A Fabric mod for Minecraft 1.21.1 that adds a customizable totem pop sound option directly in the game's Options menu. It introduces a new "Totem Sound" button in the Options screen, opening a small sub-menu where players can select from multiple pre-defined sound effects or upload their own custom sound file. The mod replaces the default totem activation sound globally, with changes taking effect immediately without requiring a restart. It also includes a preview feature to test sounds before applying, and stores the player's preference in the game's configuration file for persistence across sessions.

Plan:

  1. Add a client-only sound choice setting with persistent config.

  2. Add a button to the game’s Options screen and an owo-ui picker.

  3. Replace the totem-use sound at playback while preserving its position, category, volume, and pitch.

Added a client-side Fabric 1.21.11 mod with a Totem Sound button in Options. Choose the vanilla sound, Amethyst Chime, Note Block Pling, Experience Orb, Level Up, or Beacon Activation; your choice is saved in config/totem_sound_options.properties. The picker uses owo-ui, included via manifest.kod.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
10 307
src/client/java/com/kodari/totemsoundoptions/client/TotemSoundScreen.java
package com.kodari.totemsoundoptions.client;

import com.kodari.totemsoundoptions.config.TotemSoundConfig;
import io.wispforest.owo.ui.base.BaseOwoScreen;
import io.wispforest.owo.ui.component.ButtonComponent;
import io.wispforest.owo.ui.component.UIComponents;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.UIContainers;
import io.wispforest.owo.ui.core.HorizontalAlignment;
import io.wispforest.owo.ui.core.Insets;
import io.wispforest.owo.ui.core.OwoUIAdapter;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.core.Surface;
import io.wispforest.owo.ui.core.VerticalAlignment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

public final class TotemSoundScreen extends BaseOwoScreen<FlowLayout> {
    private final Screen parent;

    public TotemSoundScreen(Screen parent) {
        super(Text.literal("Totem Pop Sound"));
        this.parent = parent;
    }

    @Override
    protected OwoUIAdapter<FlowLayout> createAdapter() {
        return OwoUIAdapter.create(this, UIContainers::verticalFlow);
    }

    @Override
    protected void build(FlowLayout root) {
        root.surface(Surface.VANILLA_TRANSLUCENT);
        root.alignment(HorizontalAlignment.CENTER, VerticalAlignment.CENTER);

        FlowLayout panel = UIContainers.verticalFlow(Sizing.fixed(240), Sizing.content());
        panel.padding(Insets.of(8));
        panel.gap(5);
        panel.surface(Surface.DARK_PANEL);
        panel.child(UIComponents.label(Text.literal("Choose a sound for a totem save")));

        String selectedSound = TotemSoundConfig.selectedSound();
        for (TotemSoundConfig.SoundChoice choice : TotemSoundConfig.CHOICES) {
            String marker = choice.id().equals(selectedSound) ? " [Selected]" : "";
            ButtonComponent button = UIComponents.button(Text.literal(choice.label() + marker), clicked -> {
                TotemSoundConfig.select(choice.id());
                MinecraftClient.getInstance().setScreen(this.parent);
            });
            button.horizontalSizing(Sizing.fill(100));
            panel.child(button);
        }

        ButtonComponent backButton = UIComponents.button(Text.literal("Back"), clicked -> MinecraftClient.getInstance().setScreen(this.parent));
        backButton.horizontalSizing(Sizing.fill(100));
        panel.child(backButton);
        root.child(panel);
    }
}