Исходник MusicUI (+ гайд) | Exp 3.1

Новичок
Статус
Оффлайн
Регистрация
29 Июл 2024
Сообщения
1
Реакции[?]
0
Поинты[?]
0
Начинающий
Статус
Онлайн
Регистрация
6 Дек 2023
Сообщения
96
Реакции[?]
0
Поинты[?]
0
Начинающий
Статус
Оффлайн
Регистрация
24 Июл 2024
Сообщения
29
Реакции[?]
4
Поинты[?]
3K
Держите панельку с музыкой + гайд как его делать(шрифты и некоторые элементы чуть кривые и требуют доработки, но в общем выглядит неплохо)
SS =
Пожалуйста, авторизуйтесь для просмотра ссылки.

1: Создаете класс MusicPlayerUI в папке с функциями
2: Ставите этот код

Java:
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import im.expensive.functions.settings.impl.BindSetting;

@FunctionRegister(name = "MusicPlayerUI", type = Category.Misc)
public class MusicPlayerUI extends Function {

    public BindSetting setting = new BindSetting("Кнопка открытия", -1);

    public MusicPlayerUI() {
        addSettings(setting);
    }
}
3: Заходите в основной класс(Expensive или другой) и делаете как написано ниже
P.S. Некоторые строки кода для вас будут выглядеть не так как для меня, потому что я писал команды и др.
Шаг 1. Вставьте на 130 строке этот код
Java:
 private MusicPlayerUI musicPlayerUI;
Шаг 2. На 202 строке ставите этот код
Java:
musicPlayerUI = new MusicPlayerUI(new StringTextComponent(""));
Шаг 3. На 227 строке вставляете это

Java:
if (this.functionRegistry.getMusicPlayerUI().isState() && this.functionRegistry.getMusicPlayerUI().setting.get() == key) {
            Minecraft.getInstance().displayGuiScreen(musicPlayerUI);
        }
4: Создаете класс по пути im.expensive.ui.musicplayer с названием MusicPlayerUI

Java:
package im.expensive.ui.musicplayer;

import com.mojang.blaze3d.matrix.MatrixStack;
import im.expensive.utils.client.IMinecraft;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.Scissor;
import im.expensive.utils.render.font.Fonts;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.util.text.ITextComponent;

import javax.sound.sampled.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MusicPlayerUI extends Screen implements IMinecraft {

    private List<File> musicFiles = new ArrayList<>();
    private File musicDirectory = new File("wonderful/music");
    private String message = "Папка с музыкой пуста =(";

    private int selectedMusicIndex = -1;

    private boolean isPlaying = false;
    private boolean isRepeat = false;
    private Clip clip;
    private float volume = 0.3f;
    private MatrixStack matrixStack;

    private enum Category {
        LOCAL
    }

    private Category currentCategory = Category.LOCAL;

    public MusicPlayerUI(ITextComponent titleIn) {
        super(titleIn);
    }

    @Override
    protected void init() {
        super.init();
        loadMusicFiles();
    }

    private void loadMusicFiles() {
        musicFiles.clear();
        try {
            if (currentCategory == Category.LOCAL) {
                if (musicDirectory.exists() && musicDirectory.isDirectory()) {
                    File[] files = musicDirectory.listFiles((dir, name) -> name.endsWith(".wav"));
                    if (files != null) {
                        for (File file : files) {
                            musicFiles.add(file);
                        }
                    }
                }
                if (musicFiles.isEmpty()) {
                    message = "Папка с музыкой пуста =(\nЧтобы добавить музыку, поместите её в папку 'wonderful/music'";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            message = "Произошла ошибка при загрузке треков.";
            musicFiles.clear();
        }
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        renderBackground(matrixStack);

        int windowWidth = mc.getMainWindow().getScaledWidth();
        int windowHeight = mc.getMainWindow().getScaledHeight();

        float width = 400;
        float height = 400;
        float x = windowWidth / 2f - width / 2f;
        float y = windowHeight / 2f - height / 2f;

        DisplayUtils.drawShadow(x, y, width, height, 10, ColorUtils.rgba(17, 17, 17, 128));
        DisplayUtils.drawRoundedRect(x, y, width, height, new Vector4f(7, 7, 7, 7), ColorUtils.rgba(17, 17, 17, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "Музыкальный плеер", x + width / 2f, y + 10, ColorUtils.rgb(255, 255, 255), 12);

        drawCategoryButton(matrixStack, x + 20, y + 10, "Локальный", currentCategory == Category.LOCAL);

        float openFolderX = x + width - 30;
        float openFolderY = y + 10;
        DisplayUtils.drawRoundedRect(openFolderX, openFolderY, 20, 20, 5, ColorUtils.rgba(30, 30, 30, 255));
        Fonts.montserrat.drawText(matrixStack, "Folder", openFolderX + 5, openFolderY + 5, ColorUtils.rgb(255, 255, 255), 10);

        if (musicFiles.isEmpty()) {
            Fonts.montserrat.drawCenteredText(matrixStack, message, x + width / 2f, y + height / 2f - 30, ColorUtils.rgb(255, 0, 0), 12);
        } else {
            Scissor.push();
            Scissor.setFromComponentCoordinates(x, y + 40, width, height - 160);
            float listX = x + 20;
            float listY = y + 40;

            for (int i = 0; i < musicFiles.size(); i++) {
                File music = musicFiles.get(i);
                boolean hovered = MathUtil.isHovered(mouseX, mouseY, listX, listY + i * 25, width - 40, 25);

                if (hovered) {
                    DisplayUtils.drawRoundedRect(listX, listY + i * 25, width - 40, 25, 3, ColorUtils.rgba(30, 30, 30, 255));
                }

                String songName = trimSongName(music.getName().replaceAll("\\.wav", ""), width - 80);
                Fonts.montserrat.drawText(matrixStack, songName, listX + 5, listY + i * 25 + 5, ColorUtils.rgb(255, 255, 255), 10);

                if (selectedMusicIndex == i) {
                    Fonts.montserrat.drawText(matrixStack, "Select", listX + width - 60, listY + i * 25 + 5, ColorUtils.rgb(0, 255, 0), 10);
                }
            }

            Scissor.unset();
            Scissor.pop();

            renderPlayerPanel(matrixStack, x, y, width, height);
        }

        super.render(matrixStack, mouseX, mouseY, partialTicks);
    }

    private void drawCategoryButton(MatrixStack matrixStack, float x, float y, String label, boolean selected) {
        int buttonColor = selected ? ColorUtils.rgba(60, 60, 60, 255) : ColorUtils.rgba(30, 30, 30, 255);
        DisplayUtils.drawRoundedRect(x, y, 90, 20, 5, buttonColor);
        Fonts.montserrat.drawCenteredText(matrixStack, label, x + 45, y + 5, ColorUtils.rgb(255, 255, 255), 10);
    }

    private String trimSongName(String name, float maxWidth) {
        float textWidth = Fonts.montserrat.getStringWidth(name, 10);
        if (textWidth > maxWidth) {
            while (textWidth > maxWidth && name.length() > 3) {
                name = name.substring(0, name.length() - 1);
                textWidth = Fonts.montserrat.getStringWidth(name + "...", 10);
            }
            name += "...";
        }
        return name;
    }

    private void renderPlayerPanel(MatrixStack matrixStack, float x, float y, float width, float height) {
        float panelHeight = 100;
        float panelY = y + height - panelHeight - 10;

        DisplayUtils.drawRoundedRect(x + 10, panelY + 30, width - 20, panelHeight - 30, 10, ColorUtils.rgba(30, 30, 30, 255));

        if (selectedMusicIndex != -1) {
            renderPlayer(matrixStack, x + 10, panelY, width - 20, panelHeight);
        }
    }

    private void renderPlayer(MatrixStack matrixStack, float x, float y, float width, float height) {
        String songName = trimSongName(musicFiles.get(selectedMusicIndex).getName().replaceAll("\\.wav", ""), width - 80);
        Fonts.montserrat.drawText(matrixStack, songName, x + 10, y + 35, ColorUtils.rgb(255, 255, 255), 12);

        float buttonSize = 20;
        float buttonSpacing = 10;

        float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;
        float prevButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(prevButtonX, prevButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, "<<", prevButtonX + buttonSize / 2f, prevButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float playPauseButtonX = x + width / 2f - buttonSize / 2f;
        float playPauseButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(playPauseButtonX, playPauseButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, isPlaying ? "Pause" : "Play", playPauseButtonX + buttonSize / 2f, playPauseButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float nextButtonX = x + width / 2f + buttonSpacing + 5;
        float nextButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(nextButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, ">>", nextButtonX + buttonSize / 2f, nextButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;
        float repeatButtonY = nextButtonY;
        int repeatButtonColor = isRepeat ? ColorUtils.rgba(0, 0, 255, 255) : ColorUtils.rgba(60, 60, 60, 255);
        DisplayUtils.drawRoundedRect(repeatButtonX, repeatButtonY, buttonSize, buttonSize, 5, repeatButtonColor);
        Fonts.montserrat.drawCenteredText(matrixStack, "R", repeatButtonX + buttonSize / 2f, repeatButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 55;
        float volumeSliderY = y + height / 2f - 4 + 10;
        float volumeSliderWidth = width / 4f - 15;
        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth, 10, 5, ColorUtils.rgba(60, 60, 60, 255));
        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth * volume, 10, 5, ColorUtils.rgba(0, 255, 0, 255));

        float timeSliderX = x + 10;
        float timeSliderY = y + height - 20;
        float timeSliderWidth = width - 20;
        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth, 5, 2.5f, ColorUtils.rgba(60, 60, 60, 255));
        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth * getCurrentPlaybackPosition(), 5, 2.5f, ColorUtils.rgba(0, 255, 0, 255));
    }


    public float getCurrentPlaybackPosition() {
        if (clip != null) {
            return clip.getMicrosecondPosition() / (float) clip.getMicrosecondLength();
        }
        return 0;
    }

    public String getCurrentSongName() {
        if (selectedMusicIndex != -1 && selectedMusicIndex < musicFiles.size()) {
            return musicFiles.get(selectedMusicIndex).getName().replace(".wav", "");
        }
        return "";
    }



    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        if (button == 0) {
            float windowWidth = mc.getMainWindow().getScaledWidth();
            float windowHeight = mc.getMainWindow().getScaledHeight();

            float width = 400;
            float height = 400;
            float x = windowWidth / 2f - width / 2f;
            float y = windowHeight / 2f - height / 2f;

            float panelHeight = 100;
            float panelY = y + height - panelHeight - 10;

            float buttonSize = 20;
            float buttonSpacing = 10;

            float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;
            float prevButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, prevButtonX, prevButtonY, buttonSize, buttonSize)) {
                selectPreviousMusic();
                return true;
            }

            float playPauseButtonX = x + width / 2f - buttonSize / 2f;
            float playPauseButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, playPauseButtonX, playPauseButtonY, buttonSize, buttonSize)) {
                togglePlayPause();
                return true;
            }

            float nextButtonX = x + width / 2f + buttonSpacing + 5;
            float nextButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, nextButtonX, nextButtonY, buttonSize, buttonSize)) {
                selectNextMusic();
                return true;
            }

            float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;
            float repeatButtonY = nextButtonY;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, repeatButtonX, repeatButtonY, buttonSize, buttonSize)) {
                isRepeat = !isRepeat;
                return true;
            }

            float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 53;
            float volumeSliderY = panelY + panelHeight / 2f - 5 + 10;
            float volumeSliderWidth = width / 4f - 15;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, volumeSliderX, volumeSliderY, volumeSliderWidth, 10)) {
                volume = (float) ((mouseX - volumeSliderX) / volumeSliderWidth);
                setVolume(volume);
                return true;
            }

            float timeSliderX = x + 8;
            float timeSliderY = panelY + panelHeight - 20;
            float timeSliderWidth = width - 20;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, timeSliderX, timeSliderY, timeSliderWidth, 5)) {
                seek((float) ((mouseX - timeSliderX) / timeSliderWidth));
                return true;
            }

            float openFolderX = x + width - 30;
            float openFolderY = y + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX, openFolderY, buttonSize, buttonSize)) {
                openMusicFolder();
                return true;
            }

            float listY = y + 40;
            for (int i = 0; i < musicFiles.size(); i++) {
                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + i * 25, width - 40, 25)) {
                    selectedMusicIndex = i;
                    playSelectedMusic();
                    return true;
                }
            }
        }
    
        return super.mouseClicked(mouseX, mouseY, button);
    }


    private void selectPreviousMusic() {
        if (musicFiles.isEmpty()) return;

        if (selectedMusicIndex > 0) {
            selectedMusicIndex--;
        } else {
            selectedMusicIndex = musicFiles.size() - 1;
        }
        playSelectedMusic();
    }

    private void selectNextMusic() {
        if (musicFiles.isEmpty()) return;

        if (selectedMusicIndex < musicFiles.size() - 1) {
            selectedMusicIndex++;
        } else {
            selectedMusicIndex = 0;
        }
        playSelectedMusic();
    }

    private void togglePlayPause() {
        if (clip == null) return;

        if (isPlaying) {
            clip.stop();
            isPlaying = false;
        } else {
            clip.setFramePosition(clip.getFramePosition());
            clip.start();
            isPlaying = true;
        }
    }

    private void openMusicFolder() {
        try {
            Desktop.getDesktop().open(musicDirectory);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    private void setVolume(float volume) {
        if (clip != null && clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            float dB = (float) (Math.log(volume) / Math.log(10) * 20);
            gainControl.setValue(dB);
        }
    }

    private void seek(float position) {
        if (clip != null) {
            clip.setMicrosecondPosition((long) (clip.getMicrosecondLength() * position));
        }
    }
    public boolean isVisible() {
        return this.minecraft.currentScreen == this;
    }
    public boolean isPlaying() {
        return isPlaying;
    }



    private void playSelectedMusic() {
        if (selectedMusicIndex == -1 || musicFiles.isEmpty()) return;

        if (clip != null && clip.isOpen()) {
            clip.stop();
            clip.close();
        }

        File music = musicFiles.get(selectedMusicIndex);
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(music);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            isPlaying = true;

            clip.addLineListener(event -> {
                if (event.getType() == LineEvent.Type.STOP && isPlaying) {
                    if (clip.getMicrosecondPosition() >= clip.getMicrosecondLength()) {
                        if (isRepeat) {
                            clip.setFramePosition(0);
                            clip.start();
                        } else {
                            selectNextMusic();
                        }
                    }
                }
            });

            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isPauseScreen() {
        return false;
    }
}
Вот и все готово, осталось прописать в FunctionRegistry нашу функцию
Для этого вставляете код
Java:
private MusicPlayerUI musicPlayerUI;
и в методе init прописываете
Java:
musicPlayerUI = new MusicPlayerUI()
Если не ошибаюсь все готово, вы можете заменить текст на свои элементы шрифта или же пнгшки, тут уже на ваше усмотрение
Такого подобия дерьма я ещё не видел..
 
Забаненный
Статус
Оффлайн
Регистрация
10 Май 2023
Сообщения
829
Реакции[?]
9
Поинты[?]
3K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Начинающий
Статус
Оффлайн
Регистрация
18 Май 2023
Сообщения
23
Реакции[?]
0
Поинты[?]
0
Держите панельку с музыкой + гайд как его делать(шрифты и некоторые элементы чуть кривые и требуют доработки, но в общем выглядит неплохо)
SS =
Пожалуйста, авторизуйтесь для просмотра ссылки.

1: Создаете класс MusicPlayerUI в папке с функциями
2: Ставите этот код

Java:
package im.expensive.functions.impl.misc;

import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import im.expensive.functions.settings.impl.BindSetting;

@FunctionRegister(name = "MusicPlayerUI", type = Category.Misc)
public class MusicPlayerUI extends Function {

    public BindSetting setting = new BindSetting("Кнопка открытия", -1);

    public MusicPlayerUI() {
        addSettings(setting);
    }
}
3: Заходите в основной класс(Expensive или другой) и делаете как написано ниже
P.S. Некоторые строки кода для вас будут выглядеть не так как для меня, потому что я писал команды и др.
Шаг 1. Вставьте на 130 строке этот код
Java:
 private MusicPlayerUI musicPlayerUI;
Шаг 2. На 202 строке ставите этот код
Java:
musicPlayerUI = new MusicPlayerUI(new StringTextComponent(""));
Шаг 3. На 227 строке вставляете это

Java:
if (this.functionRegistry.getMusicPlayerUI().isState() && this.functionRegistry.getMusicPlayerUI().setting.get() == key) {
            Minecraft.getInstance().displayGuiScreen(musicPlayerUI);
        }
4: Создаете класс по пути im.expensive.ui.musicplayer с названием MusicPlayerUI

Java:
package im.expensive.ui.musicplayer;

import com.mojang.blaze3d.matrix.MatrixStack;
import im.expensive.utils.client.IMinecraft;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.Scissor;
import im.expensive.utils.render.font.Fonts;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.util.text.ITextComponent;

import javax.sound.sampled.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MusicPlayerUI extends Screen implements IMinecraft {

    private List<File> musicFiles = new ArrayList<>();
    private File musicDirectory = new File("wonderful/music");
    private String message = "Папка с музыкой пуста =(";

    private int selectedMusicIndex = -1;

    private boolean isPlaying = false;
    private boolean isRepeat = false;
    private Clip clip;
    private float volume = 0.3f;
    private MatrixStack matrixStack;

    private enum Category {
        LOCAL
    }

    private Category currentCategory = Category.LOCAL;

    public MusicPlayerUI(ITextComponent titleIn) {
        super(titleIn);
    }

    @Override
    protected void init() {
        super.init();
        loadMusicFiles();
    }

    private void loadMusicFiles() {
        musicFiles.clear();
        try {
            if (currentCategory == Category.LOCAL) {
                if (musicDirectory.exists() && musicDirectory.isDirectory()) {
                    File[] files = musicDirectory.listFiles((dir, name) -> name.endsWith(".wav"));
                    if (files != null) {
                        for (File file : files) {
                            musicFiles.add(file);
                        }
                    }
                }
                if (musicFiles.isEmpty()) {
                    message = "Папка с музыкой пуста =(\nЧтобы добавить музыку, поместите её в папку 'wonderful/music'";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            message = "Произошла ошибка при загрузке треков.";
            musicFiles.clear();
        }
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        renderBackground(matrixStack);

        int windowWidth = mc.getMainWindow().getScaledWidth();
        int windowHeight = mc.getMainWindow().getScaledHeight();

        float width = 400;
        float height = 400;
        float x = windowWidth / 2f - width / 2f;
        float y = windowHeight / 2f - height / 2f;

        DisplayUtils.drawShadow(x, y, width, height, 10, ColorUtils.rgba(17, 17, 17, 128));
        DisplayUtils.drawRoundedRect(x, y, width, height, new Vector4f(7, 7, 7, 7), ColorUtils.rgba(17, 17, 17, 255));

        Fonts.montserrat.drawCenteredText(matrixStack, "Музыкальный плеер", x + width / 2f, y + 10, ColorUtils.rgb(255, 255, 255), 12);

        drawCategoryButton(matrixStack, x + 20, y + 10, "Локальный", currentCategory == Category.LOCAL);

        float openFolderX = x + width - 30;
        float openFolderY = y + 10;
        DisplayUtils.drawRoundedRect(openFolderX, openFolderY, 20, 20, 5, ColorUtils.rgba(30, 30, 30, 255));
        Fonts.montserrat.drawText(matrixStack, "Folder", openFolderX + 5, openFolderY + 5, ColorUtils.rgb(255, 255, 255), 10);

        if (musicFiles.isEmpty()) {
            Fonts.montserrat.drawCenteredText(matrixStack, message, x + width / 2f, y + height / 2f - 30, ColorUtils.rgb(255, 0, 0), 12);
        } else {
            Scissor.push();
            Scissor.setFromComponentCoordinates(x, y + 40, width, height - 160);
            float listX = x + 20;
            float listY = y + 40;

            for (int i = 0; i < musicFiles.size(); i++) {
                File music = musicFiles.get(i);
                boolean hovered = MathUtil.isHovered(mouseX, mouseY, listX, listY + i * 25, width - 40, 25);

                if (hovered) {
                    DisplayUtils.drawRoundedRect(listX, listY + i * 25, width - 40, 25, 3, ColorUtils.rgba(30, 30, 30, 255));
                }

                String songName = trimSongName(music.getName().replaceAll("\\.wav", ""), width - 80);
                Fonts.montserrat.drawText(matrixStack, songName, listX + 5, listY + i * 25 + 5, ColorUtils.rgb(255, 255, 255), 10);

                if (selectedMusicIndex == i) {
                    Fonts.montserrat.drawText(matrixStack, "Select", listX + width - 60, listY + i * 25 + 5, ColorUtils.rgb(0, 255, 0), 10);
                }
            }

            Scissor.unset();
            Scissor.pop();

            renderPlayerPanel(matrixStack, x, y, width, height);
        }

        super.render(matrixStack, mouseX, mouseY, partialTicks);
    }

    private void drawCategoryButton(MatrixStack matrixStack, float x, float y, String label, boolean selected) {
        int buttonColor = selected ? ColorUtils.rgba(60, 60, 60, 255) : ColorUtils.rgba(30, 30, 30, 255);
        DisplayUtils.drawRoundedRect(x, y, 90, 20, 5, buttonColor);
        Fonts.montserrat.drawCenteredText(matrixStack, label, x + 45, y + 5, ColorUtils.rgb(255, 255, 255), 10);
    }

    private String trimSongName(String name, float maxWidth) {
        float textWidth = Fonts.montserrat.getStringWidth(name, 10);
        if (textWidth > maxWidth) {
            while (textWidth > maxWidth && name.length() > 3) {
                name = name.substring(0, name.length() - 1);
                textWidth = Fonts.montserrat.getStringWidth(name + "...", 10);
            }
            name += "...";
        }
        return name;
    }

    private void renderPlayerPanel(MatrixStack matrixStack, float x, float y, float width, float height) {
        float panelHeight = 100;
        float panelY = y + height - panelHeight - 10;

        DisplayUtils.drawRoundedRect(x + 10, panelY + 30, width - 20, panelHeight - 30, 10, ColorUtils.rgba(30, 30, 30, 255));

        if (selectedMusicIndex != -1) {
            renderPlayer(matrixStack, x + 10, panelY, width - 20, panelHeight);
        }
    }

    private void renderPlayer(MatrixStack matrixStack, float x, float y, float width, float height) {
        String songName = trimSongName(musicFiles.get(selectedMusicIndex).getName().replaceAll("\\.wav", ""), width - 80);
        Fonts.montserrat.drawText(matrixStack, songName, x + 10, y + 35, ColorUtils.rgb(255, 255, 255), 12);

        float buttonSize = 20;
        float buttonSpacing = 10;

        float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;
        float prevButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(prevButtonX, prevButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, "<<", prevButtonX + buttonSize / 2f, prevButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float playPauseButtonX = x + width / 2f - buttonSize / 2f;
        float playPauseButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(playPauseButtonX, playPauseButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, isPlaying ? "Pause" : "Play", playPauseButtonX + buttonSize / 2f, playPauseButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float nextButtonX = x + width / 2f + buttonSpacing + 5;
        float nextButtonY = y + height / 2f - buttonSize / 2f + 10;
        DisplayUtils.drawRoundedRect(nextButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtils.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, ">>", nextButtonX + buttonSize / 2f, nextButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;
        float repeatButtonY = nextButtonY;
        int repeatButtonColor = isRepeat ? ColorUtils.rgba(0, 0, 255, 255) : ColorUtils.rgba(60, 60, 60, 255);
        DisplayUtils.drawRoundedRect(repeatButtonX, repeatButtonY, buttonSize, buttonSize, 5, repeatButtonColor);
        Fonts.montserrat.drawCenteredText(matrixStack, "R", repeatButtonX + buttonSize / 2f, repeatButtonY + 5, ColorUtils.rgb(255, 255, 255), 10);

        float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 55;
        float volumeSliderY = y + height / 2f - 4 + 10;
        float volumeSliderWidth = width / 4f - 15;
        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth, 10, 5, ColorUtils.rgba(60, 60, 60, 255));
        DisplayUtils.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth * volume, 10, 5, ColorUtils.rgba(0, 255, 0, 255));

        float timeSliderX = x + 10;
        float timeSliderY = y + height - 20;
        float timeSliderWidth = width - 20;
        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth, 5, 2.5f, ColorUtils.rgba(60, 60, 60, 255));
        DisplayUtils.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth * getCurrentPlaybackPosition(), 5, 2.5f, ColorUtils.rgba(0, 255, 0, 255));
    }


    public float getCurrentPlaybackPosition() {
        if (clip != null) {
            return clip.getMicrosecondPosition() / (float) clip.getMicrosecondLength();
        }
        return 0;
    }

    public String getCurrentSongName() {
        if (selectedMusicIndex != -1 && selectedMusicIndex < musicFiles.size()) {
            return musicFiles.get(selectedMusicIndex).getName().replace(".wav", "");
        }
        return "";
    }



    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        if (button == 0) {
            float windowWidth = mc.getMainWindow().getScaledWidth();
            float windowHeight = mc.getMainWindow().getScaledHeight();

            float width = 400;
            float height = 400;
            float x = windowWidth / 2f - width / 2f;
            float y = windowHeight / 2f - height / 2f;

            float panelHeight = 100;
            float panelY = y + height - panelHeight - 10;

            float buttonSize = 20;
            float buttonSpacing = 10;

            float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;
            float prevButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, prevButtonX, prevButtonY, buttonSize, buttonSize)) {
                selectPreviousMusic();
                return true;
            }

            float playPauseButtonX = x + width / 2f - buttonSize / 2f;
            float playPauseButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, playPauseButtonX, playPauseButtonY, buttonSize, buttonSize)) {
                togglePlayPause();
                return true;
            }

            float nextButtonX = x + width / 2f + buttonSpacing + 5;
            float nextButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, nextButtonX, nextButtonY, buttonSize, buttonSize)) {
                selectNextMusic();
                return true;
            }

            float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;
            float repeatButtonY = nextButtonY;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, repeatButtonX, repeatButtonY, buttonSize, buttonSize)) {
                isRepeat = !isRepeat;
                return true;
            }

            float volumeSliderX = nextButtonX + buttonSize + buttonSpacing + 53;
            float volumeSliderY = panelY + panelHeight / 2f - 5 + 10;
            float volumeSliderWidth = width / 4f - 15;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, volumeSliderX, volumeSliderY, volumeSliderWidth, 10)) {
                volume = (float) ((mouseX - volumeSliderX) / volumeSliderWidth);
                setVolume(volume);
                return true;
            }

            float timeSliderX = x + 8;
            float timeSliderY = panelY + panelHeight - 20;
            float timeSliderWidth = width - 20;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, timeSliderX, timeSliderY, timeSliderWidth, 5)) {
                seek((float) ((mouseX - timeSliderX) / timeSliderWidth));
                return true;
            }

            float openFolderX = x + width - 30;
            float openFolderY = y + 10;
            if (MathUtil.isHovered((float) mouseX, (float) mouseY, openFolderX, openFolderY, buttonSize, buttonSize)) {
                openMusicFolder();
                return true;
            }

            float listY = y + 40;
            for (int i = 0; i < musicFiles.size(); i++) {
                if (MathUtil.isHovered((float) mouseX, (float) mouseY, x + 20, listY + i * 25, width - 40, 25)) {
                    selectedMusicIndex = i;
                    playSelectedMusic();
                    return true;
                }
            }
        }
    
        return super.mouseClicked(mouseX, mouseY, button);
    }


    private void selectPreviousMusic() {
        if (musicFiles.isEmpty()) return;

        if (selectedMusicIndex > 0) {
            selectedMusicIndex--;
        } else {
            selectedMusicIndex = musicFiles.size() - 1;
        }
        playSelectedMusic();
    }

    private void selectNextMusic() {
        if (musicFiles.isEmpty()) return;

        if (selectedMusicIndex < musicFiles.size() - 1) {
            selectedMusicIndex++;
        } else {
            selectedMusicIndex = 0;
        }
        playSelectedMusic();
    }

    private void togglePlayPause() {
        if (clip == null) return;

        if (isPlaying) {
            clip.stop();
            isPlaying = false;
        } else {
            clip.setFramePosition(clip.getFramePosition());
            clip.start();
            isPlaying = true;
        }
    }

    private void openMusicFolder() {
        try {
            Desktop.getDesktop().open(musicDirectory);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    private void setVolume(float volume) {
        if (clip != null && clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            float dB = (float) (Math.log(volume) / Math.log(10) * 20);
            gainControl.setValue(dB);
        }
    }

    private void seek(float position) {
        if (clip != null) {
            clip.setMicrosecondPosition((long) (clip.getMicrosecondLength() * position));
        }
    }
    public boolean isVisible() {
        return this.minecraft.currentScreen == this;
    }
    public boolean isPlaying() {
        return isPlaying;
    }



    private void playSelectedMusic() {
        if (selectedMusicIndex == -1 || musicFiles.isEmpty()) return;

        if (clip != null && clip.isOpen()) {
            clip.stop();
            clip.close();
        }

        File music = musicFiles.get(selectedMusicIndex);
        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(music);
            clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            setVolume(volume);
            isPlaying = true;

            clip.addLineListener(event -> {
                if (event.getType() == LineEvent.Type.STOP && isPlaying) {
                    if (clip.getMicrosecondPosition() >= clip.getMicrosecondLength()) {
                        if (isRepeat) {
                            clip.setFramePosition(0);
                            clip.start();
                        } else {
                            selectNextMusic();
                        }
                    }
                }
            });

            clip.start();
        } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isPauseScreen() {
        return false;
    }
}
Вот и все готово, осталось прописать в FunctionRegistry нашу функцию
Для этого вставляете код
Java:
private MusicPlayerUI musicPlayerUI;
и в методе init прописываете
Java:
musicPlayerUI = new MusicPlayerUI()
Если не ошибаюсь все готово, вы можете заменить текст на свои элементы шрифта или же пнгшки, тут уже на ваше усмотрение
ураа более менее что-то годное хотя есть и спотифай и вк музыка и яндекс музыка
xd тут половина рендера с автобая взята
а кодер фрихи рокстар клиента типо откуда взял?
 
Начинающий
Статус
Оффлайн
Регистрация
25 Фев 2024
Сообщения
398
Реакции[?]
0
Поинты[?]
0
Начинающий
Статус
Онлайн
Регистрация
6 Дек 2023
Сообщения
96
Реакции[?]
0
Поинты[?]
0
Сверху Снизу