Исходник Spotify render exp 3.1

[Q
Код:
Expand Collapse Copy
package im.quantum.utils.media;

import de.labystudio.spotifyapi.SpotifyAPI;
import de.labystudio.spotifyapi.SpotifyAPIFactory;
import de.labystudio.spotifyapi.SpotifyListener;
import de.labystudio.spotifyapi.model.Track;
import lombok.Getter;

import java.time.Duration;
import quantumprotect.annotations.Native;

@Native
public class MediaUtil {
    private static final SpotifyAPI spotifyApi = SpotifyAPIFactory.create();
   
    @Getter
    private static Track currentSpotifyTrack;
   
    @Getter
    private static String currentYoutubeTitle;
   
    private static boolean isSpotifyPlaying;
    private static boolean isYoutubePlaying;
   
    @Getter
    private static int currentSpotifyPosition;
    @Getter
    private static int currentYoutubePosition;
    @Getter
    private static int currentYoutubeLength;
   
    @Getter
    private static MediaSource currentSource = MediaSource.NONE;
   
    public enum MediaSource {
        SPOTIFY,
        YOUTUBE,
        NONE
    }

    static {
        spotifyApi.registerListener(new SpotifyListener() {
            @Override
            public void onConnect() {
                currentSource = MediaSource.SPOTIFY;
            }

            @Override
            public void onTrackChanged(Track track) {
                currentSpotifyTrack = track;
                currentSource = MediaSource.SPOTIFY;
            }

            @Override
            public void onPositionChanged(int position) {
                if (!spotifyApi.hasTrack()) {
                    return;
                }
               
                currentSpotifyPosition = position;
            }

            @Override
            public void onPlayBackChanged(boolean playing) {
                isSpotifyPlaying = playing;
                if (playing) {
                    currentSource = MediaSource.SPOTIFY;
                } else if (currentSource == MediaSource.SPOTIFY) {
                    currentSource = isYoutubePlaying ? MediaSource.YOUTUBE : MediaSource.NONE;
                }
            }

            @Override
            public void onSync() {}

            @Override
            public void onDisconnect(Exception exception) {
                if (currentSource == MediaSource.SPOTIFY) {
                    currentSource = isYoutubePlaying ? MediaSource.YOUTUBE : MediaSource.NONE;
                }
            }
        });

        spotifyApi.initialize();
       
        // YouTube initialization would go here
        initializeYouTube();
    }
   
    private static void initializeYouTube() {
        // This would be implemented with a proper YouTube API
        // For now, providing a dummy implementation that can be replaced later
    }
   
    // YouTube integration methods
    public static void updateYouTubeStatus(String title, int position, int length, boolean playing) {
        currentYoutubeTitle = title;
        currentYoutubePosition = position;
        currentYoutubeLength = length;
        isYoutubePlaying = playing;
       
        if (playing && (currentSource == MediaSource.NONE || currentSource == MediaSource.YOUTUBE)) {
            currentSource = MediaSource.YOUTUBE;
        } else if (!playing && currentSource == MediaSource.YOUTUBE) {
            currentSource = isSpotifyPlaying ? MediaSource.SPOTIFY : MediaSource.NONE;
        }
    }
   
    // Player control actions
    public static void playPause() {
        if (currentSource == MediaSource.SPOTIFY) {
            // Toggle Spotify playback
            // spotifyApi.playPause(); - implement if API supports this
        } else if (currentSource == MediaSource.YOUTUBE) {
            // Toggle YouTube playback
            // Implement YouTube playback toggle
        }
    }
   
    public static void skip() {
        if (currentSource == MediaSource.SPOTIFY) {
            // Skip Spotify track
            // spotifyApi.next(); - implement if API supports this
        } else if (currentSource == MediaSource.YOUTUBE) {
            // Skip YouTube video
            // Implement YouTube skip
        }
    }
   
    public static void previous() {
        if (currentSource == MediaSource.SPOTIFY) {
            // Previous Spotify track
            // spotifyApi.previous(); - implement if API supports this
        } else if (currentSource == MediaSource.YOUTUBE) {
            // Previous YouTube video
            // Implement YouTube previous
        }
    }

    public static String getCurrentTrackInfo() {
        if (currentSource == MediaSource.SPOTIFY) {
            if (currentSpotifyTrack == null) return "Трек не найден";
            return currentSpotifyTrack.getArtist() + " - " + currentSpotifyTrack.getName();
        } else if (currentSource == MediaSource.YOUTUBE) {
            if (currentYoutubeTitle == null) return "Видео не найдено";
            return currentYoutubeTitle;
        }
        return "Медиа не найдено";
    }

    public static String getCurrentListeningTime() {
        if (currentSource == MediaSource.SPOTIFY) {
            return formatDuration(Duration.ofMillis(currentSpotifyPosition));
        } else if (currentSource == MediaSource.YOUTUBE) {
            return formatDuration(Duration.ofMillis(currentYoutubePosition));
        }
        return "00:00";
    }

    public static boolean isPlaying() {
        return currentSource == MediaSource.SPOTIFY ? isSpotifyPlaying :
               currentSource == MediaSource.YOUTUBE ? isYoutubePlaying : false;
    }

    public static String getCurrentTrackDuration() {
        if (currentSource == MediaSource.SPOTIFY) {
            if (currentSpotifyTrack == null) return "Длительность: неизвестно";
            return formatDuration(Duration.ofMillis(currentSpotifyTrack.getLength()));
        } else if (currentSource == MediaSource.YOUTUBE) {
            return formatDuration(Duration.ofMillis(currentYoutubeLength));
        }
        return "Длительность: неизвестно";
    }

    public static String formatDuration(Duration duration) {
        long seconds = duration.getSeconds();
        long minutes = seconds / 60;
        seconds %= 60;
        return String.format("%02d:%02d", minutes, seconds);
    }
}
Код:
Expand Collapse Copy
package im.quantum.ui.display.impl;

import com.mojang.blaze3d.matrix.MatrixStack;
import im.quantum.events.EventDisplay;
import im.quantum.functions.impl.Interface.HUD;
import im.quantum.ui.display.ElementRenderer;
import im.quantum.utils.animations.impl.DecelerateAnimation;
import im.quantum.utils.drag.Dragging;
import im.quantum.utils.render.DisplayUtils;
import im.quantum.utils.render.font.Fonts;
import im.quantum.utils.media.MediaUtil;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.minecraft.util.math.vector.Vector4f;
import ru.hogoshi.Animation;
import quantumprotect.annotations.Native;

@Native
@FieldDefaults(level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
public class MediaRenderer implements ElementRenderer {

    final Dragging dragging;

    float width;
    float height;
   
    // Animation for buttons
    Animation playPauseHoverAnimation = new DecelerateAnimation(250, false);
    Animation skipHoverAnimation = new DecelerateAnimation(250, false);
    Animation previousHoverAnimation = new DecelerateAnimation(250, false);
   
    boolean playPauseHover = false;
    boolean skipHover = false;
    boolean previousHover = false;

    @Override
    public void render(EventDisplay eventDisplay) {
        MatrixStack ms = eventDisplay.getMatrixStack();

        float posX = dragging.getX();
        float posY = dragging.getY();

        String duration = "Длительность: " + MediaUtil.getCurrentTrackDuration();
        String dNotFound = "Длительность: неизвестно";
        String notFound = "Медиа не найдено";
        float nameWidth = Fonts.sSB.getWidth(MediaUtil.getCurrentTrackInfo(), 8.5f);
        float nameNotFound = Fonts.sSB.getWidth(notFound, 8.5f);
        float nameHeight = Fonts.sSB.getHeight(8.5f);
        float padding = 5;

        float durationWidth = Fonts.sSB.getWidth(duration, 8.5f);
        float durationNotFound = Fonts.sSB.getWidth(dNotFound, 8.5f);
       
        // Calculate button sizes
        float buttonSize = nameHeight + 4;
        float buttonsWidth = buttonSize * 3 + padding * 2; // 3 buttons with padding between them

        // Update animations
        playPauseHoverAnimation.setValue(playPauseHover ? 1 : 0);
        skipHoverAnimation.setValue(skipHover ? 1 : 0);
        previousHoverAnimation.setValue(previousHover ? 1 : 0);

        // Calculate width and height based on content
        if (MediaUtil.isPlaying()) {
            width = padding * 2 + Math.max(Math.max(nameWidth, durationWidth), buttonsWidth);
            height = padding * 2 + nameHeight * 2 + padding + buttonSize + padding;
        } else {
            width = padding * 2 + Math.max(nameNotFound, durationNotFound);
            height = padding * 2 + nameHeight;
        }

        // Draw background
        DisplayUtils.newrect(posX, posY, width, height, new Vector4f(5, 5, 5, 5), 190);
        DisplayUtils.drawRoundedOutline(posX - 0.25f, posY, width, height, 5, 1, HUD.getColor(90, 1.5f));
       
        if (MediaUtil.isPlaying()) {
            // Draw track info
            Fonts.sSB.drawText(ms, MediaUtil.getCurrentTrackInfo(), posX + width/2 - nameWidth/2, posY + padding, -1, 8.5f);
            Fonts.sSB.drawText(ms, duration, posX + width/2 - durationWidth/2, posY + padding + nameHeight + padding, -1, 8.5f);
           
            // Draw control buttons
            float buttonsY = posY + padding + nameHeight * 2 + padding;
            float buttonsStartX = posX + width/2 - buttonsWidth/2;
           
            // Previous button
            float prevX = buttonsStartX;
            drawButton(ms, prevX, buttonsY, buttonSize, "◄", previousHoverAnimation.getValue());
           
            // Play/Pause button
            float playX = prevX + buttonSize + padding;
            drawButton(ms, playX, buttonsY, buttonSize, MediaUtil.isPlaying() ? "⏸" : "►", playPauseHoverAnimation.getValue());
           
            // Skip button
            float skipX = playX + buttonSize + padding;
            drawButton(ms, skipX, buttonsY, buttonSize, "►|", skipHoverAnimation.getValue());
           
            // Handle button hover states
            float mouseX = eventDisplay.getMouseX();
            float mouseY = eventDisplay.getMouseY();
           
            previousHover = isHovering(mouseX, mouseY, prevX, buttonsY, buttonSize, buttonSize);
            playPauseHover = isHovering(mouseX, mouseY, playX, buttonsY, buttonSize, buttonSize);
            skipHover = isHovering(mouseX, mouseY, skipX, buttonsY, buttonSize, buttonSize);
           
            // Handle button clicks
            if (eventDisplay.isLeftClicked()) {
                if (previousHover) {
                    MediaUtil.previous();
                } else if (playPauseHover) {
                    MediaUtil.playPause();
                } else if (skipHover) {
                    MediaUtil.skip();
                }
            }
           
        } else {
            Fonts.sSB.drawText(ms, notFound, posX + width/2 - nameNotFound/2, posY + padding, -1, 8.5f);
        }
       
        dragging.setWidth(width);
        dragging.setHeight(height);
    }
   
    private void drawButton(MatrixStack ms, float x, float y, float size, String symbol, float hoverProgress) {
        // Draw button background with hover effect
        int baseColor = 0x505050;
        int hoverColor = HUD.getColor(90, 1.5f);
       
        int blendedColor = blendColors(baseColor, hoverColor, hoverProgress);
       
        DisplayUtils.newrect(x, y, size, size, new Vector4f(3, 3, 3, 3), blendedColor);
       
        // Draw symbol
        float symbolWidth = Fonts.sSB.getWidth(symbol, 10f);
        float symbolHeight = Fonts.sSB.getHeight(10f);
        Fonts.sSB.drawText(ms, symbol, x + size/2 - symbolWidth/2, y + size/2 - symbolHeight/2, -1, 10f);
    }
   
    private boolean isHovering(float mouseX, float mouseY, float x, float y, float width, float height) {
        return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
    }
   
    private int blendColors(int color1, int color2, float blendFactor) {
        int r1 = (color1 >> 16) & 0xFF;
        int g1 = (color1 >> 8) & 0xFF;
        int b1 = color1 & 0xFF;
       
        int r2 = (color2 >> 16) & 0xFF;
        int g2 = (color2 >> 8) & 0xFF;
        int b2 = color2 & 0xFF;
       
        int r = (int) (r1 + (r2 - r1) * blendFactor);
        int g = (int) (g1 + (g2 - g1) * blendFactor);
        int b = (int) (b1 + (b2 - b1) * blendFactor);
       
        return (r << 16) | (g << 8) | b;
    }
}
Код:
Expand Collapse Copy
package im.quantum.ui.chat;

import com.mojang.blaze3d.matrix.MatrixStack;
import im.quantum.functions.impl.Interface.HUD;
import im.quantum.utils.animations.impl.DecelerateAnimation;
import im.quantum.utils.render.DisplayUtils;
import im.quantum.utils.render.font.Fonts;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.util.math.vector.Vector4f;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import ru.hogoshi.Animation;
import quantumprotect.annotations.Native;

@Native
public class ChatButtons {
   
    private static final Animation skipButtonHover = new DecelerateAnimation(250, false);
    private static final Animation playPauseButtonHover = new DecelerateAnimation(250, false);
   
    private static boolean skipHovered = false;
    private static boolean playPauseHovered = false;
   
    @SubscribeEvent
    public static void onGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) {
        if (!(event.getGui() instanceof ChatScreen)) return;
       
        ChatScreen chatScreen = (ChatScreen) event.getGui();
        MatrixStack ms = event.getMatrixStack();
        int mouseX = event.getMouseX();
        int mouseY = event.getMouseY();
       
        int width = Minecraft.getInstance().getMainWindow().getScaledWidth();
        int height = Minecraft.getInstance().getMainWindow().getScaledHeight();
       
        // Button dimensions
        int buttonWidth = 80;
        int buttonHeight = 20;
        int padding = 5;
       
        // Skip button
        int skipX = width - buttonWidth - padding;
        int skipY = height - 50; // Position above chat input
       
        // Play/Pause button
        int playPauseX = skipX - buttonWidth - padding;
        int playPauseY = skipY;
       
        // Update hover states
        skipHovered = isHovering(mouseX, mouseY, skipX, skipY, buttonWidth, buttonHeight);
        playPauseHovered = isHovering(mouseX, mouseY, playPauseX, playPauseY, buttonWidth, buttonHeight);
       
        skipButtonHover.setValue(skipHovered ? 1 : 0);
        playPauseButtonHover.setValue(playPauseHovered ? 1 : 0);
       
        // Draw buttons
        drawButton(ms, skipX, skipY, buttonWidth, buttonHeight, "Пропустить", skipButtonHover.getValue());
        drawButton(ms, playPauseX, playPauseY, buttonWidth, buttonHeight, "Запустить/Выключить", playPauseButtonHover.getValue());
    }
   
    @SubscribeEvent
    public static void onGuiMouseClicked(GuiScreenEvent.MouseClickedEvent.Pre event) {
        if (!(event.getGui() instanceof ChatScreen)) return;
       
        if (event.getButton() == 0) { // Left click
            if (skipHovered) {
                // Handle skip button click
                // Implement the action to skip
                event.setCanceled(true);
            } else if (playPauseHovered) {
                // Handle play/pause button click
                // Implement the action to play/pause
                event.setCanceled(true);
            }
        }
    }
   
    private static void drawButton(MatrixStack ms, int x, int y, int width, int height, String text, float hoverProgress) {
        // Draw button background with hover effect
        int baseColor = 0x50505050;
        int hoverColor = HUD.getColor(90, 1.5f);
       
        int blendedColor = blendColors(baseColor, hoverColor, hoverProgress);
       
        DisplayUtils.newrect(x, y, width, height, new Vector4f(3, 3, 3, 3), blendedColor);
       
        // Draw text
        float textWidth = Fonts.sSB.getWidth(text, 8.5f);
        float textHeight = Fonts.sSB.getHeight(8.5f);
        Fonts.sSB.drawText(ms, text, x + width/2 - textWidth/2, y + height/2 - textHeight/2, -1, 8.5f);
    }
   
    private static boolean isHovering(int mouseX, int mouseY, int x, int y, int width, int height) {
        return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
    }
   
    private static int blendColors(int color1, int color2, float blendFactor) {
        int a1 = (color1 >> 24) & 0xFF;
        int r1 = (color1 >> 16) & 0xFF;
        int g1 = (color1 >> 8) & 0xFF;
        int b1 = color1 & 0xFF;
       
        int a2 = (color2 >> 24) & 0xFF;
        int r2 = (color2 >> 16) & 0xFF;
        int g2 = (color2 >> 8) & 0xFF;
        int b2 = color2 & 0xFF;
       
        int a = (int) (a1 + (a2 - a1) * blendFactor);
        int r = (int) (r1 + (r2 - r1) * blendFactor);
        int g = (int) (g1 + (g2 - g1) * blendFactor);
        int b = (int) (b1 + (b2 - b1) * blendFactor);
       
        return (a << 24) | (r << 16) | (g << 8) | b;
    }
}
Код:
Expand Collapse Copy
package im.quantum.utils.media;

import lombok.Getter;
import quantumprotect.annotations.Native;

/**
* Integration with YouTube for tracking video playback
*/
@Native
public class YouTubeIntegration {

    @Getter
    private static boolean initialized = false;
   
    /**
     * Initialize the YouTube integration
     */
    public static void initialize() {
        if (initialized) return;
       
        try {
            // Initialize browser hooks or API connection
            // This implementation would connect to browser extension or use YouTube API
           
            initialized = true;
           
            // Start periodic polling for YouTube status if necessary
            startPolling();
        } catch (Exception e) {
            System.out.println("Error initializing YouTube integration: " + e.getMessage());
        }
    }
   
    /**
     * Start polling for YouTube status updates
     */
    private static void startPolling() {
        // Create a thread that periodically checks YouTube status
        Thread pollingThread = new Thread(() -> {
            while (initialized) {
                try {
                    // Get current YouTube state from browser/extension
                    String currentTitle = getCurrentVideoTitle();
                    int currentPosition = getCurrentVideoPosition();
                    int totalLength = getCurrentVideoLength();
                    boolean isPlaying = isVideoPlaying();
                   
                    // Update the MediaUtil with YouTube information
                    MediaUtil.updateYouTubeStatus(
                        currentTitle,
                        currentPosition,
                        totalLength,
                        isPlaying
                    );
                   
                    // Sleep for a short time before next update
                    Thread.sleep(1000);
                } catch (Exception e) {
                    // Silently handle errors during polling
                }
            }
        });
       
        pollingThread.setDaemon(true);
        pollingThread.start();
    }
   
    /**
     * Get the current YouTube video title
     */
    private static String getCurrentVideoTitle() {
        // This would be implemented with browser extension or YouTube API
        // For now, returning a dummy implementation
        return null; // Change to actual implementation
    }
   
    /**
     * Get the current position in the YouTube video (in milliseconds)
     */
    private static int getCurrentVideoPosition() {
        // This would be implemented with browser extension or YouTube API
        return 0; // Change to actual implementation
    }
   
    /**
     * Get the total length of the YouTube video (in milliseconds)
     */
    private static int getCurrentVideoLength() {
        // This would be implemented with browser extension or YouTube API
        return 0; // Change to actual implementation
    }
   
    /**
     * Check if a YouTube video is currently playing
     */
    private static boolean isVideoPlaying() {
        // This would be implemented with browser extension or YouTube API
        return false; // Change to actual implementation
    }
   
    /**
     * Play or pause the current YouTube video
     */
    public static void playPause() {
        // Implement YouTube play/pause functionality
    }
   
    /**
     * Skip to the next video in YouTube
     */
    public static void next() {
        // Implement YouTube next video functionality
    }
   
    /**
     * Go to the previous video in YouTube
     */
    public static void previous() {
        // Implement YouTube previous video functionality
    }
   
    /**
     * Shutdown the YouTube integration
     */
    public static void shutdown() {
        initialized = false;
    }
}

1. в твоем коде 0 функционала
2. говно код
3. работает только для спотифая

итог: говнище
Вот тебе функционал
[/QUOTE]
1-рендер статуса, куда дальше надо?
2-где говно код? укажи
3-прочитай назв темы
 
Вот тебе функционал
1-рендер статуса, куда дальше надо?
2-где говно код? укажи
3-прочитай назв темы
[/QUOTE]
ты дебил я челу ответил просто это не прорисовалось
Вот тебе функционал
1-рендер статуса, куда дальше надо?
2-где говно код? укажи
3-прочитай назв темы
[/QUOTE]
тема имба я просто доделал добавил кнопки ютуб и тд
Вот тебе функционал
1-рендер статуса, куда дальше надо?
2-где говно код? укажи
3-прочитай назв темы
[/QUOTE]
чел сделал хорошо а другой оскорбляй прежде чем писать выше бы посмотрел а потом уже бы говорил
 
1-рендер статуса, куда дальше надо?
2-где говно код? укажи
3-прочитай назв темы
ты дебил я челу ответил просто это не прорисовалось

1-рендер статуса, куда дальше надо?
2-где говно код? укажи
3-прочитай назв темы
[/QUOTE]
тема имба я просто доделал добавил кнопки ютуб и тд

1-рендер статуса, куда дальше надо?
2-где говно код? укажи
3-прочитай назв темы
[/QUOTE]
чел сделал хорошо а другой оскорбляй прежде чем писать выше бы посмотрел а потом уже бы говорил
[/QUOTE]
ой, сорри
 
тупой вопрос НЕ ап а вопрос я скачал библиотеку а ее надо забилдить и в libraries?
 
Назад
Сверху Снизу