Подпишитесь на наш Telegram-канал, чтобы всегда быть в курсе важных обновлений! Перейти

Часть функционала MediaPlayerRenderer upgrade

Забаненный
Забаненный
Статус
Оффлайн
Регистрация
5 Сен 2025
Сообщения
143
Реакции
5
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Выберите загрузчик игры
  1. Vanilla
  2. Forge
  3. Fabric
  4. NeoForge
  5. OptiFine
  6. ForgeOptiFine
1761337788995.png

1761337799182.png

короче в ориг коде пиксели жесткие были и цвета баганные,сейчас для вас всё пофиксил.
методы сами делайте. рендер утилку и градиент не дам!!!


пр тык то:
Expand Collapse Copy
package dev.zovchik.ui.display.impl;

import com.mojang.blaze3d.matrix.MatrixStack;
import dev.redstones.mediaplayerinfo.IMediaSession;
import dev.redstones.mediaplayerinfo.MediaPlayerInfo;
import dev.zovchik.Zovchik;
import dev.zovchik.events.EventDisplay;
import dev.zovchik.modules.api.ModuleManager;
import dev.zovchik.modules.impl.render.HUD;
import dev.zovchik.modules.impl.render.Theme;
import dev.zovchik.ui.display.ElementRenderer;
import dev.zovchik.utils.Round;
import dev.zovchik.utils.drag.Dragging;
import dev.zovchik.utils.math.Vector4i;
import dev.zovchik.utils.render.GaussianBlur;
import dev.zovchik.utils.render.color.ColorUtils;
import dev.zovchik.utils.render.font.Fonts;
import dev.zovchik.utils.render.gl.Scissor;
import dev.zovchik.utils.render.rect.RenderUtility;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.NativeImage;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector4f;

import java.awt.image.BufferedImage;
import java.util.List;

@FieldDefaults(level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
@SuppressWarnings("all")
public class MediaPlayerRenderer implements ElementRenderer {
    final Dragging dragging;
    private final MediaPlayerInfo mediaPlayerInfo = MediaPlayerInfo.Instance;
    private String currentTrackTitle = "";
    private String previousTrackTitle = "";
    private String artist = "";
    private ResourceLocation trackIcon = new ResourceLocation("Zovchik/images/logo.png");
    private DynamicTexture dynamicTexture = null;
    private long posit;
    private long durat;
    boolean session1;
    String getFormattedTime;

    private long lastUpdate = System.currentTimeMillis();
    private static final long UPDATE_INTERVAL = 1000;
    private float textX = 0;
    private final Vector4f ROUNDING_VECTOR = new Vector4f(5, 5, 5, 5);

    @Override
    public void render(EventDisplay eventRender2D) {
        MatrixStack ms = eventRender2D.getMatrixStack();
        float x = dragging.getX();
        float y = dragging.getY();
        float width = 110;
        float height = 30;
        float lineW = width - 10 - 25;

        ModuleManager moduleRegistry = Zovchik.getInstance().getModuleManager();
        HUD interFace = moduleRegistry.getHud();
        float fontSize = interFace.fontsize.get();

        if (System.currentTimeMillis() - lastUpdate >= UPDATE_INTERVAL) {
            lastUpdate = System.currentTimeMillis();
            updateTrackTitle();
        }

        drawStyledRect(x, y, width, height, 3.5f);
        RenderUtility.Rounded.roundedOutline(ms, x, y, width, height, 1.1F, ColorUtils.rgba(55,55,55,255), ColorUtils.rgba(45,45,45,255), ColorUtils.rgba(45,45,45,255), ColorUtils.rgba(55,55,55,255), Round.of(4));

        String displayText = session1 ? "Ожидаю" : currentTrackTitle;

        Scissor.push();
        Scissor.setFromComponentCoordinates(x + 10 + 20, y, lineW, height);
        Fonts.intersemibold.drawGradient(ms, displayText.substring(0, Math.min(displayText.length(), 20)).replace("Ë", "E").replace("ë", "ё"),
                x + 10 + 20, y + 5, Theme.getColor(5), Theme.getColorTwo(5), fontSize);
        Fonts.intersemibold.drawGradient(ms, session1 ? "" : artist, x + 10 + 20, y + 5 + fontSize + 2, Theme.getColor(5), Theme.getColorTwo(5), fontSize - 1, 0.1f);
        Scissor.unset();
        Scissor.pop();

        RenderUtility.drawRoundedRect(x + 10 + 20, y + height - 7.5f, lineW, 4, 1, ColorUtils.rgba(60, 60, 60, 255));
        RenderUtility.drawRoundedRect(x + 10 + 20, y + height - 7.5f, lineW * gettimepos(), 4, 1, Theme.getColor(5));

        RenderUtility.drawImage(trackIcon, x + 2.5f, y + 2.5f, height - 5, height - 5, -1);

        dragging.setWidth(width);
        dragging.setHeight(height);
    }

    private void drawStyledRect(float x, float y, float width, float height, float radius) {
        ModuleManager moduleManager = Zovchik.getInstance().getModuleManager();
        HUD blurblat = moduleManager.getHud();

        int solidDark = ColorUtils.rgba(10, 10, 10, 255);
        int baseAccent = ColorUtils.rgba(10, 11, 11, 255);
        int edgeAccent = ColorUtils.setAlpha(baseAccent, 80);

        if (blurblat.blur.get()) {
            GaussianBlur.startBlur();
            RenderUtility.drawRoundedRect(x, y, width, height, 4, solidDark);
            RenderUtility.drawRoundedRect(x, y, width, height, 4, edgeAccent);
            GaussianBlur.endBlur(4, 2);
        } else {
            RenderUtility.drawRoundedRect(x, y, width, height, 4, solidDark);
            RenderUtility.drawRoundedRect(x, y, width, height, 4, edgeAccent);
        }
    }

    public float gettimepos() {
        return !session1 ? (float) posit / (float) durat : 0.0F;
    }

    private void updateTrackTitle() {
        new Thread(() -> {
            try {
                List<IMediaSession> sessions = mediaPlayerInfo.getMediaSessions();
                session1 = sessions.isEmpty();

                if (!sessions.isEmpty()) {
                    IMediaSession currentSession = sessions.get(0);
                    String newTrackTitle = currentSession.getMedia().getTitle();
                    String newArtist = currentSession.getMedia().getArtist();
                    BufferedImage oblozka = currentSession.getMedia().getArtwork();
                    long position = currentSession.getMedia().getPosition();
                    long duration = currentSession.getMedia().getDuration();

                    synchronized (this) {
                        if (!newTrackTitle.equals(previousTrackTitle)) {
                            currentTrackTitle = newTrackTitle;
                            previousTrackTitle = newTrackTitle;
                            artist = newArtist;

                            if (oblozka != null) {
                                trackIcon = createTextureFromBufferedImage(oblozka);
                            } else {
                                trackIcon = new ResourceLocation("Zovchik/images/hud/music.jpg");
                            }
                        }
                        posit = position;
                        durat = duration;
                        long currentMinutes = (posit / 1000) / 60;
                        long currentSeconds = (posit / 1000) % 60;
                        long totalMinutes = (durat / 1000) / 60;
                        long totalSeconds = (durat / 1000) % 60;
                        getFormattedTime = String.format("%02d:%02d / %02d:%02d", currentMinutes, currentSeconds, totalMinutes, totalSeconds);
                    }
                } else {
                    synchronized (this) {
                        previousTrackTitle = null;
                        currentTrackTitle = "null";
                        artist = "";
                        posit = 0;
                        durat = 0;
                        trackIcon = new ResourceLocation("Zovchik/images/hud/music.jpg");
                    }
                }
            } finally {
                //прости но нет
            }

        }).start();
    }

    private ResourceLocation createTextureFromBufferedImage(BufferedImage image) {
        if (image == null || image.getWidth() <= 0 || image.getHeight() <= 0) {
            return new ResourceLocation("Zovchik/images/hud/music.jpg");
        }

        try {
            int size = 64;
            java.awt.Image scaled = image.getScaledInstance(size, size, java.awt.Image.SCALE_SMOOTH);
            BufferedImage resized = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
            resized.getGraphics().drawImage(scaled, 0, 0, null);

            NativeImage nativeImage = new NativeImage(size, size, false);

            for (int x = 0; x < size; x++) {
                for (int y = 0; y < size; y++) {
                    int argb = resized.getRGB(x, y);
                    int abgr = (argb & 0xFF00FF00) |
                            ((argb >> 16) & 0xFF) |
                            ((argb << 16) & 0xFF0000);
                    nativeImage.setPixelRGBA(x, y, abgr);
                }
            }
            
            if (dynamicTexture != null) {
                dynamicTexture.close();
            }

            dynamicTexture = new DynamicTexture(nativeImage);
            String textureId = "track_icon_" + System.nanoTime();
            ResourceLocation resourceLocation = new ResourceLocation("zovchik", textureId);
            Minecraft.getInstance().getTextureManager().loadTexture(resourceLocation, dynamicTexture);
            return resourceLocation;

        } catch (Exception e) {
            e.printStackTrace();
            if (dynamicTexture != null) {
                dynamicTexture.close();
                dynamicTexture = null;
            }
            return new ResourceLocation("Zovchik/images/hud/music.jpg");
        }
    }

    public void close() {
        if (dynamicTexture != null) {
            dynamicTexture.close();
            dynamicTexture = null;
        }
    }
}
 
Назад
Сверху Снизу