Начинающий
			
			
				
					
				
			
		- Статус
 - Оффлайн
 
- Регистрация
 - 14 Июн 2024
 
- Сообщения
 - 55
 
- Реакции
 - 2
 
Ну крутой красивый Плеер музыки
Основу брал с этой темы (noad)
ss:
Я на базе шедевро евавара но перенести любой думаю сможет
Инструкция:
1. Добавляем сам плеер с оригинальной темы: тема(noad)
2. Добавляем шрифты
---- Регать в Fonts.java (im/expensive/utils/render/font) вот так:
---- test1488 = new Font("nurik.png", "nurik.json");
3. Меняем MusicPlayerUI(не функцию) на это:
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
				
			Основу брал с этой темы (noad)
ss:
	Пожалуйста, авторизуйтесь для просмотра ссылки.
Я на базе шедевро евавара но перенести любой думаю сможет
Инструкция:
1. Добавляем сам плеер с оригинальной темы: тема(noad)
2. Добавляем шрифты
	Пожалуйста, авторизуйтесь для просмотра ссылки.
---- Регать в Fonts.java (im/expensive/utils/render/font) вот так:
---- test1488 = new Font("nurik.png", "nurik.json");
3. Меняем MusicPlayerUI(не функцию) на это:
			
				MusicPlayerUI:
			
		
		
		package eva.ware.ui.musicplayer;
import com.mojang.blaze3d.matrix.MatrixStack;
import eva.ware.utils.client.IMinecraft;
import eva.ware.utils.math.MathUtility;
import eva.ware.utils.render.color.ColorUtility;
import eva.ware.utils.render.engine2d.RenderUtility;
import eva.ware.utils.render.font.Fonts;
import eva.ware.utils.render.other.Scissor;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraft.util.text.ITextComponent;
import javax.sound.sampled.*;
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("saves/files/music");
    private String message = "Папка с музыкой пуста =(";
    final ResourceLocation folder = new ResourceLocation("eva/images/musicplayer/folder.png");
    final ResourceLocation play = new ResourceLocation("eva/images/musicplayer/play.png");
    final ResourceLocation pause = new ResourceLocation("eva/images/musicplayer/pause.png");
    final ResourceLocation repeat = new ResourceLocation("eva/images/musicplayer/repeat.png");
    final ResourceLocation yes = new ResourceLocation("eva/images/musicplayer/yes.png");
    private int selectedMusicIndex = -1;
    private boolean isPlaying = false;
    private boolean isRepeat = false;
    private Clip clip;
    private float volume = 0.3f;
    private MatrixStack matrixStack;
    private int scrollOffset = 0;
    private int maxVisibleItems = 10;
    private float itemHeight = 25f;
    float iconSizeX = 10;
    float iconSizeY = 10;
    private enum Category {
        LOCAL
    }
    private Category currentCategory = Category.LOCAL;
    public MusicPlayerUI(ITextComponent titleIn) {
        super(titleIn);
    }
    [USER=1367676]@override[/USER]
    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 (!musicDirectory.exists()) {
                    musicDirectory.mkdir();
                }
                if (musicFiles.isEmpty()) {
                    message = "Папка с музыкой пуста =(\n";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            message = "Произошла ошибка при загрузке треков.";
            musicFiles.clear();
        }
    }
    [USER=1367676]@override[/USER]
    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 = 200;
        float height;
        if (selectedMusicIndex != -1) {
            height = 340;
        } else {
            height = 230;
        }
        float x = windowWidth / 2f - width / 2f;
        float y = windowHeight / 2f - height / 2f;
        RenderUtility.drawRoundedRect(x, y, width, height, new Vector4f(7, 7, 7, 7), ColorUtility.rgba(17, 17, 17, 215));
        RenderUtility.drawRoundedRect(x + width - 65 + 1 - 125, y + 8, 150, 20, 5, ColorUtility.rgba(30, 30, 30, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, "Музыкальный плеер", x + width / 2f - 15, y + 11.5f, ColorUtility.rgb(255, 255, 255), 11);
        float openFolderX = x + width - 65 + 1;
        float openFolderY = y + 8;//10;
        float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);
        RenderUtility.drawRoundedRect(openFolderX + 35, openFolderY, 20, 20, 5, ColorUtility.rgba(30, 30, 30, 255));
        RenderUtility.drawImage(folder, openFolderX + 40, openFolderY + 5, 10f, 10f, ColorUtility.rgb(255, 255, 255));
        if (musicFiles.isEmpty()) {
            String message2 = "чтобы добавить музыку, поместите её в папку";
            String message3 = "assets/skins/0/music в формате .wav";
            Fonts.montserrat.drawCenteredText(matrixStack, message, x + width / 2f, y + height / 2f - 30, ColorUtility.rgb(255, 0, 0), 12);
            Fonts.montserrat.drawCenteredText(matrixStack, message2, x + width / 2f, y + height / 2f - 17.5f, ColorUtility.rgb(255, 0, 0), 12);
            Fonts.montserrat.drawCenteredText(matrixStack, message3, x + width / 2f, y + height / 2f - 5, ColorUtility.rgb(255, 0, 0), 12);
        } else {
            Scissor.push();
            Scissor.setFromComponentCoordinates(x, y + 30, width + 300, height - 10);
            float listX = x + 20;
            float listY = y + 40;
            RenderUtility.drawRoundedRect(listX - 10, listY - 5, width - 20, 185, 5, ColorUtility.rgba(30, 30, 30, 255));
            int visibleItems = 7;
            int maxScroll = Math.max(0, musicFiles.size() - visibleItems);
            int scrollOffset1 = Math.max(0, Math.min(scrollOffset, maxScroll));
            int startIndex = Math.max(0, scrollOffset1);
            int endIndex = Math.min(musicFiles.size(), startIndex + visibleItems);
            float visibleHeight = 175;
            for (int i = startIndex; i < endIndex; i++) {
                float itemY = listY + (i - startIndex) * itemHeight;
                if (itemY >= listY && itemY + itemHeight <= listY + visibleHeight) {
                    boolean hovered = MathUtility.isHovered(mouseX, mouseY, listX, itemY, width - 40, itemHeight);
                    if (hovered) {
                        RenderUtility.drawRoundedRect(listX, itemY, width - 40, itemHeight, 3, ColorUtility.rgba(20, 20, 20, 255));
                    }
                    String songName = trimSongName(musicFiles.get(i).getName().replaceAll("\\.wav", ""), width - 80);
                    Fonts.montserrat.drawText(matrixStack, songName, listX + 5, itemY + 5, ColorUtility.rgb(255, 255, 255), 10);
                    if (selectedMusicIndex == i) {
                        RenderUtility.drawImage(yes, listX + width - 65, itemY + 1, 20, 20, ColorUtility.rgb(0, 255, 0));
                    }
                }
            }
            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 ? ColorUtility.rgba(60, 60, 60, 255) : ColorUtility.rgba(30, 30, 30, 255);
        RenderUtility.drawRoundedRect(x, y, Fonts.montserrat.getWidth(label, 10) + 22.5f, 20, 5, buttonColor);
        Fonts.montserrat.drawCenteredText(matrixStack, label, x + 45, y + 5, ColorUtility.rgb(255, 255, 255), 10);
    }
    private String trimSongName(String name, float maxWidth) {
        float textWidth = Fonts.montserrat.getWidth(name, 10);
        if (textWidth > maxWidth) {
            while (textWidth > maxWidth && name.length() > 3) {
                name = name.substring(0, name.length() - 1);
                textWidth = Fonts.montserrat.getWidth(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 - 45;
        if (selectedMusicIndex != -1) {
            RenderUtility.drawRoundedRect(x + 10, panelY + 30, width - 20, panelHeight - 30, 10, ColorUtility.rgba(30, 30, 30, 255));
            RenderUtility.drawRoundedRect(x + 10, panelY + 107, width - 20, 32, 10, ColorUtility.rgba(30, 30, 30, 255));
            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, ColorUtility.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 + 35;
        RenderUtility.drawRoundedRect(prevButtonX, prevButtonY, buttonSize, buttonSize, 5, ColorUtility.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, "<", prevButtonX + buttonSize / 2f, prevButtonY + 5, ColorUtility.rgb(255, 255, 255), 10);
        float playPauseButtonX = x + width / 2f - buttonSize / 2f;
        float playPauseButtonY = y + height / 2f - buttonSize / 2f + 35;
        RenderUtility.drawRoundedRect(playPauseButtonX, playPauseButtonY, buttonSize, buttonSize, 5, ColorUtility.rgba(60, 60, 60, 255));
        RenderUtility.drawImage(isPlaying ? pause : play, playPauseButtonX + buttonSize / 2f - 5, playPauseButtonY + 5, 10, 10, ColorUtility.rgb(255, 255, 255));
        float nextButtonX = x + width / 2f + buttonSpacing + 5;
        float nextButtonY = y + height / 2f - buttonSize / 2f + 35;
        RenderUtility.drawRoundedRect(nextButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtility.rgba(60, 60, 60, 255));
        Fonts.montserrat.drawCenteredText(matrixStack, ">", nextButtonX + buttonSize / 2f, nextButtonY + 5, ColorUtility.rgb(255, 255, 255), 10);
        float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;
        float repeatButtonY = nextButtonY;
        int repeatButtonColor = isRepeat ? ColorUtility.rgba(0, 0, 255, 255) : ColorUtility.rgba(60, 60, 60, 255);
        RenderUtility.drawRoundedRect(repeatButtonX, repeatButtonY, buttonSize, buttonSize, 5, repeatButtonColor);
        RenderUtility.drawImage(repeat, repeatButtonX + buttonSize / 2f - 5, repeatButtonY + 5, 10, 10, ColorUtility.rgb(255, 255, 255));
        float closeButtonX = x + width / 2f - buttonSize / 2f - 60;
        RenderUtility.drawRoundedRect(closeButtonX, nextButtonY, buttonSize, buttonSize, 5, ColorUtility.rgba(60, 60, 60, 255));
        Fonts.test1488.drawCenteredText(matrixStack, "U", closeButtonX + buttonSize / 2f - 1, repeatButtonY + 6f, ColorUtility.rgb(255, 255, 255), 10);
        //VOLUME
        Fonts.montserrat.drawText(matrixStack, "VOLUME", x + 60, y + 110, ColorUtility.rgb(255, 255, 255), 11);
        float volumeSliderX = x + 10;
        float volumeSliderY = y + height / 2f - 4 + 77;
        float volumeSliderWidth = width - 20 ;
        RenderUtility.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth, 10, 5, ColorUtility.rgba(60, 60, 60, 255));
        RenderUtility.drawRoundedRect(volumeSliderX, volumeSliderY, volumeSliderWidth * volume, 10, 5, ColorUtility.rgba(0, 255, 0, 255));
        //TIME
        float timeSliderX = x + 10;
        float timeSliderY = y + height - 37;
        float timeSliderWidth = width - 20;
        long currentMicroseconds = clip.getMicrosecondPosition();
        long totalMicroseconds = clip.getMicrosecondLength();
        String currentTime = formatTime(currentMicroseconds);
        String totalTime = formatTime(totalMicroseconds);
        Fonts.montserrat.drawText(matrixStack, currentTime, timeSliderX, timeSliderY - 12, ColorUtility.rgb(255, 255, 255), 9);
        Fonts.montserrat.drawText(matrixStack, totalTime, timeSliderX + timeSliderWidth - Fonts.montserrat.getWidth(totalTime, 10), timeSliderY - 12, ColorUtility.rgb(255, 255, 255), 9);
        RenderUtility.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth, 5, 2.5f, ColorUtility.rgba(60, 60, 60, 255));
        RenderUtility.drawRoundedRect(timeSliderX, timeSliderY, timeSliderWidth * getCurrentPlaybackPosition(), 5, 2.5f, ColorUtility.rgba(0, 255, 0, 255));
    }
    private String formatTime(long microseconds) {
        int seconds = (int) (microseconds / 1_000_000) % 60;
        int minutes = (int) (microseconds / 60_000_000);
        return String.format("%02d:%02d", minutes, seconds);
    }
    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 "";
    }
    [USER=1367676]@override[/USER]
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        if (button == 0) {
            float windowWidth = mc.getMainWindow().getScaledWidth();
            float windowHeight = mc.getMainWindow().getScaledHeight();
            float width = 200;
            float height;
            if (selectedMusicIndex != -1) {
                height = 340;
            } else {
                height = 230;
            }
            float x = windowWidth / 2f - width / 2f;
            float y = windowHeight / 2f - height / 2f;
            float panelHeight = 100;
            float panelY = y + height - panelHeight - 45;
            float buttonSize = 20;
            float buttonSpacing = 10;
            float prevButtonX = x + width / 2f - buttonSize - buttonSpacing - 5;
            float prevButtonY = panelY + panelHeight / 2f - buttonSize / 2f + 35;
            if (MathUtility.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 + 35;
            if (MathUtility.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 + 35;
            if (MathUtility.isHovered((float) mouseX, (float) mouseY, nextButtonX, nextButtonY, buttonSize, buttonSize)) {
                selectNextMusic();
                return true;
            }
            float repeatButtonX = nextButtonX + buttonSize + buttonSpacing + 5;
            float repeatButtonY = nextButtonY;
            if (MathUtility.isHovered((float) mouseX, (float) mouseY, repeatButtonX, repeatButtonY, buttonSize, buttonSize)) {
                isRepeat = !isRepeat;
                return true;
            }
            float volumeSliderX = x + 20;
            float volumeSliderY = panelY + panelHeight / 2f - 5 + 77;
            float volumeSliderWidth = width - 40;
            if (MathUtility.isHovered((float) mouseX, (float) mouseY, volumeSliderX, volumeSliderY, volumeSliderWidth, 10)) {
                volume = (float) ((mouseX - volumeSliderX) / volumeSliderWidth);
                setVolume(volume);
                return true;
            }
            float timeSliderX = x + 20;
            float timeSliderY = panelY + panelHeight - 37;
            float timeSliderWidth = width - 40;
            if (MathUtility.isHovered((float) mouseX, (float) mouseY, timeSliderX, timeSliderY, timeSliderWidth, 5)) {
                seek((float) ((mouseX - timeSliderX) / timeSliderWidth));
                return true;
            }
            float openFolderX = x + width - 30          + 1.5f;
            float openFolderY = y + 8;//10;
            float folderTextWidth = Fonts.montserrat.getWidth("Папка", 10);
            if (MathUtility.isHovered((float) mouseX, (float) mouseY, openFolderX, openFolderY, 20, 20)) {
                openMusicFolder();
                return true;
            }
            float listY = y + 40;
            float listHeight = 165;
            float listX = x + 20;
            int startIndex = scrollOffset;
            int endIndex = Math.min(startIndex + maxVisibleItems, musicFiles.size());
            for (int i = startIndex; i < endIndex; i++) {
                float itemY = listY + (i - startIndex) * itemHeight;
                if (itemY >= listY && itemY <= listY + listHeight) {
                    if (MathUtility.isHovered((float) mouseX, (float) mouseY, listX, itemY, width - 40, itemHeight)) {
                        selectedMusicIndex = i;
                        playSelectedMusic();
                        return true;
                    }
                }
            }
            float closeButtonX = x + width / 2f - buttonSize / 2f - 60;
            if (MathUtility.isHovered((float) mouseX, (float) mouseY, closeButtonX, prevButtonY, buttonSize, buttonSize)) {
                clip.stop();
                clip.close();
                clip = null;
                selectedMusicIndex = -1;
                return true;
            }
            for (int i = startIndex; i < endIndex; i++) {
                if (MathUtility.isHovered((float) mouseX, (float) mouseY, x + 20, listY + (i - startIndex) * itemHeight, width - 40, itemHeight) && scrollOffset > 0) {
                    selectedMusicIndex = i;
                    playSelectedMusic();
                    return true;
                }
            }
        }
        return super.mouseClicked(mouseX, mouseY, button);
    }
    [USER=1367676]@override[/USER]
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        int maxOffset = Math.max(0, musicFiles.size() - maxVisibleItems);
        scrollOffset = Math.max(0, Math.min(scrollOffset - (int) delta, maxOffset));
        return super.mouseScrolled(mouseX, mouseY, delta);
    }
    public void handleMouseWheel(int delta) {
        int maxOffset = Math.max(0, musicFiles.size() - maxVisibleItems);
        scrollOffset = Math.max(0, Math.min(scrollOffset - delta * 3, maxOffset));
    }
    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 {
            Runtime.getRuntime().exec("explorer " + musicDirectory.getAbsolutePath());
        } 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();
        }
    }
    [USER=1367676]@override[/USER]
    public boolean isPauseScreen() {
        return false;
    }
}