Начинающий
- Статус
- Оффлайн
- Регистрация
- 7 Мар 2025
- Сообщения
- 94
- Реакции
- 2
- Выберите загрузчик игры
- Vanilla
можно сказать даже не скид просто такой же дизайн мне понравился он вроде не большой и удобный ну мне понравился короче делал с нуля гпт насрал 500 строк
SS -
Code -
SS -
Code -
сарделька:
package dev.sk3d.display.hud;
import dev.sk3d.utils.display.render.post.KawaseBlur;
import dev.sk3d.utils.interactions.interact.PlayerInteractionHelper;
import dev.sk3d.utils.math.Timer;
import dev.sk3d.utils.theme.ThemeManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.redstones.mediaplayerinfo.IMediaSession;
import dev.redstones.mediaplayerinfo.MediaInfo;
import dev.redstones.mediaplayerinfo.MediaPlayerInfo;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import dev.sk3d.utils.client.managers.api.draggable.AbstractDraggable;
import dev.sk3d.features.impl.render.Hud;
import dev.sk3d.common.animation.Animation;
import dev.sk3d.common.animation.Direction;
import dev.sk3d.common.animation.implement.Decelerate;
import dev.sk3d.common.animation.implement.EaseOut;
import dev.sk3d.utils.display.render.font.FontRenderer;
import dev.sk3d.utils.display.render.font.Fonts;
import dev.sk3d.utils.display.render.shape.ShapeProperties;
import dev.sk3d.utils.display.render.geometry.Render2D;
import java.awt.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MusicInfo extends AbstractDraggable {
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private MediaInfo mediaInfo = new MediaInfo("Название Трека", "Артист", new byte[0], 43, 150, false);
private final Identifier artwork = Identifier.of("hawen", "textures/music_artwork.png");
private final Timer lastMedia = new Timer();
public IMediaSession session;
private boolean artworkRegistered = false;
private final Animation exit = new Decelerate().setMs(200).setValue(0);
private final Animation fadeAnimation = new Decelerate().setMs(300).setValue(1);
private final Animation progressAnimation = new Decelerate().setMs(200).setValue(0);
public MusicInfo() {
super("Music Info", 10, 250, 90, 130, true);
this.scaleAnimation = new EaseOut().setValue(1).setMs(100);
exit.setValue(0);
}
@Override
public boolean visible() {
return Hud.getInstance().interfaceSettings.isSelected("Music Info") &&
Hud.getInstance().state;
}
@Override
public void tick() {
if (PlayerInteractionHelper.nullCheck()) {
return;
}
if (mc.player.age % 5 == 0) {
executorService.execute(() -> {
try {
java.util.Collection<IMediaSession> sessions = MediaPlayerInfo.Instance.getMediaSessions();
if (sessions == null || sessions.isEmpty()) {
return;
}
IMediaSession currentSession = sessions.stream()
.filter(s -> s != null && s.getMedia() != null)
.max(Comparator.comparing(s -> {
try {
return s.getMedia().getPlaying();
} catch (Exception e) {
return false;
}
}))
.orElse(null);
if (currentSession != null) {
try {
MediaInfo info = currentSession.getMedia();
if (info == null) {
return;
}
if (!info.getTitle().isEmpty() || !info.getArtist().isEmpty() || info.getPlaying()) {
boolean needsUpdate = mediaInfo.getTitle().equals("Название Трека") ||
!Arrays.equals(mediaInfo.getArtworkPng(), info.getArtworkPng());
if (needsUpdate && info.getArtworkPng() != null && info.getArtworkPng().length > 0) {
try {
mc.execute(() -> {
try {
net.minecraft.client.texture.NativeImageBackedTexture texture =
new net.minecraft.client.texture.NativeImageBackedTexture(
net.minecraft.client.texture.NativeImage.read(
new java.io.ByteArrayInputStream(info.getArtworkPng())
)
);
mc.getTextureManager().registerTexture(artwork, texture);
artworkRegistered = true;
} catch (Exception e) {
artworkRegistered = false;
}
});
} catch (Exception e) {
artworkRegistered = false;
}
}
mediaInfo = info;
session = currentSession;
lastMedia.reset();
if (info.getPlaying()) {
mc.execute(() -> {
exit.setDirection(Direction.FORWARDS);
exit.setValue(1.0);
});
}
}
} catch (Exception e) {
}
}
} catch (Exception e) {
}
});
}
boolean hasActiveMedia = !lastMedia.finished(5000);
boolean inChat = PlayerInteractionHelper.isChat(mc.currentScreen);
boolean isPlaying = false;
try {
if (mediaInfo != null && mediaInfo.getPlaying()) {
isPlaying = true;
}
} catch (Exception e) {
}
boolean shouldShow = hasActiveMedia || inChat || isPlaying;
if (shouldShow) {
exit.setDirection(Direction.FORWARDS);
} else {
exit.setDirection(Direction.BACKWARDS);
}
}
@Override
public void drawDraggable(DrawContext context) {
try {
boolean inChat = PlayerInteractionHelper.isChat(mc.currentScreen);
float exitValue = exit.getOutput().floatValue();
boolean hasMusic = !lastMedia.finished(5000);
if (!inChat && exitValue <= 0.01f && !hasMusic) return;
if (inChat) exitValue = 1.0f;
if (mediaInfo == null) {
mediaInfo = new MediaInfo("Название Трека", "Артист", new byte[0], 43, 150, false);
}
MatrixStack matrix = context.getMatrices();
FontRenderer titleFont = Fonts.getSize(14, Fonts.Type.BOLD);
FontRenderer artistFont = Fonts.getSize(12, Fonts.Type.BOLD);
FontRenderer iconFont = Fonts.getSize(16, Fonts.Type.HAWEN);
FontRenderer musicIconFont = Fonts.getSize(20, Fonts.Type.HAWEN);
float totalWidth = 90f;
float totalHeight = 130f;
float padding = 5f;
float borderRadius = 4f;
float posX = getX();
float posY = getY();
matrix.push();
float scaleX = posX + totalWidth / 2;
float scaleY = posY + totalHeight / 2;
matrix.translate(scaleX, scaleY, 0);
matrix.scale(exitValue, exitValue, 1);
matrix.translate(-scaleX, -scaleY, 0);
rectangle.render(ShapeProperties.create(matrix, posX, posY, totalWidth, totalHeight)
.round(borderRadius)
.color(ThemeManager.BackgroundGui.getColor())
.build());
float coverSize = totalWidth - padding * 2;
float coverX = posX + padding;
float coverY = posY + padding;
if (artworkRegistered && mediaInfo.getArtworkPng() != null && mediaInfo.getArtworkPng().length > 0) {
try {
float coverRadius = 4f;
rectangle.render(ShapeProperties.create(matrix, coverX, coverY, coverSize, coverSize)
.round(coverRadius)
.color(new Color(255, 255, 255, 255).getRGB())
.build());
context.enableScissor((int)coverX, (int)coverY, (int)(coverX + coverSize), (int)(coverY + coverSize));
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShaderTexture(0, artwork);
com.mojang.blaze3d.platform.GlStateManager._texParameter(
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_2D,
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_MIN_FILTER,
com.mojang.blaze3d.platform.GlConst.GL_LINEAR
);
com.mojang.blaze3d.platform.GlStateManager._texParameter(
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_2D,
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_MAG_FILTER,
com.mojang.blaze3d.platform.GlConst.GL_LINEAR
);
context.drawTexture(net.minecraft.client.render.RenderLayer::getGuiTextured,
artwork,
(int)coverX,
(int)coverY,
0, 0,
(int)coverSize,
(int)coverSize,
(int)coverSize,
(int)coverSize);
com.mojang.blaze3d.platform.GlStateManager._texParameter(
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_2D,
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_MIN_FILTER,
com.mojang.blaze3d.platform.GlConst.GL_NEAREST
);
com.mojang.blaze3d.platform.GlStateManager._texParameter(
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_2D,
com.mojang.blaze3d.platform.GlConst.GL_TEXTURE_MAG_FILTER,
com.mojang.blaze3d.platform.GlConst.GL_NEAREST
);
RenderSystem.disableBlend();
context.disableScissor();
} catch (Exception e) {
artworkRegistered = false;
}
}
float controlPanelHeight = 20f;
float controlPanelY = coverY + coverSize + padding;
rectangle.render(ShapeProperties.create(matrix, posX + padding, controlPanelY,
totalWidth - padding * 2, controlPanelHeight)
.round(3f)
.color(ThemeManager.BackgroundSettings.getColor())
.build());
float buttonSize = 16f;
float buttonSpacing = 8f;
float totalButtonsWidth = buttonSize * 3 + buttonSpacing * 2;
float buttonsStartX = posX + (totalWidth - totalButtonsWidth) / 2;
float buttonY = controlPanelY + (controlPanelHeight - buttonSize) / 2 + 8f;
FontRenderer buttonFont = Fonts.getSize(16, Fonts.Type.Untitled1);
float prevX = buttonsStartX;
String prevIcon = "E";
buttonFont.drawString(matrix, prevIcon,
prevX + (buttonSize - buttonFont.getStringWidth(prevIcon)) / 2,
buttonY + (buttonSize - buttonFont.getStringHeight(prevIcon)) / 2,
ThemeManager.primaryColor.getColor());
float playX = prevX + buttonSize + buttonSpacing;
String playPauseIcon = mediaInfo.getPlaying() ? "C" : "D";
buttonFont.drawString(matrix, playPauseIcon,
playX + (buttonSize - buttonFont.getStringWidth(playPauseIcon)) / 2,
buttonY + (buttonSize - buttonFont.getStringHeight(playPauseIcon)) / 2,
ThemeManager.primaryColor.getColor());
float nextX = playX + buttonSize + buttonSpacing;
String nextIcon = "B";
buttonFont.drawString(matrix, nextIcon,
nextX + (buttonSize - buttonFont.getStringWidth(nextIcon)) / 2,
buttonY + (buttonSize - buttonFont.getStringHeight(nextIcon)) / 2,
ThemeManager.primaryColor.getColor());
float progressPanelHeight = 10f;
float progressPanelY = controlPanelY + controlPanelHeight + padding;
rectangle.render(ShapeProperties.create(matrix, posX + padding, progressPanelY,
totalWidth - padding * 2, progressPanelHeight)
.round(3f)
.color(ThemeManager.BackgroundSettings.getColor())
.build());
float progressHeight = 3f;
float progressPadding = 6f;
float progressY = progressPanelY + (progressPanelHeight - progressHeight) / 2;
float progressWidth = totalWidth - padding * 2 - progressPadding * 2;
float progressX = posX + padding + progressPadding;
float progress = mediaInfo.getDuration() > 0 ? (float) mediaInfo.getPosition() / mediaInfo.getDuration() : 0f;
progressAnimation.setValue(progress);
float animatedProgress = progressAnimation.getOutput().floatValue();
rectangle.render(ShapeProperties.create(matrix, progressX, progressY, progressWidth, progressHeight)
.round(1.5f)
.color(ThemeManager.BackgroundSettings.getColor())
.build());
if (animatedProgress > 0) {
rectangle.render(ShapeProperties.create(matrix, progressX, progressY,
progressWidth * Math.min(1f, animatedProgress), progressHeight)
.round(1.5f)
.color(ThemeManager.primaryColor.getColor())
.build());
}
matrix.pop();
setWidth((int) totalWidth);
setHeight((int) totalHeight);
} catch (Exception e) {
e.printStackTrace();
}
}
private void renderScrollingText(MatrixStack matrix, FontRenderer font, String text,
float x, float y, int color, float maxWidth, DrawContext context) {
float textW = font.getStringWidth(text);
float scroll = 0f;
if (textW > maxWidth) {
float scrollMax = textW - maxWidth;
if (scrollMax < 0) scrollMax = 0;
float pauseDuration = 1000f;
float scrollDuration = 4000f;
float totalCycle = pauseDuration + scrollDuration + pauseDuration + scrollDuration;
long now = System.currentTimeMillis();
float timeInCycle = now % (long) totalCycle;
if (timeInCycle < pauseDuration) {
scroll = 0f;
} else if (timeInCycle < pauseDuration + scrollDuration) {
float t = (timeInCycle - pauseDuration) / scrollDuration;
scroll = t * scrollMax;
} else if (timeInCycle < pauseDuration + scrollDuration + pauseDuration) {
scroll = scrollMax;
} else {
float t = (timeInCycle - pauseDuration - scrollDuration - pauseDuration) / scrollDuration;
scroll = scrollMax * (1f - t);
}
}
context.enableScissor((int) Math.ceil(x - 1), (int) Math.ceil(y - 1),
(int) Math.ceil((x - 1) + maxWidth + 2), (int) Math.ceil((y - 1) + font.getStringHeight(text) + 5));
font.drawString(matrix, text, x - scroll, y, color);
context.disableScissor();
}
private java.util.List<String> wrapText(FontRenderer font, String text, float maxWidth) {
java.util.List<String> lines = new java.util.ArrayList<>();
String[] words = text.split(" ");
StringBuilder currentLine = new StringBuilder();
for (String word : words) {
String testLine = currentLine.length() == 0 ? word : currentLine + " " + word;
if (font.getStringWidth(testLine) <= maxWidth) {
currentLine = new StringBuilder(testLine);
} else {
if (currentLine.length() > 0) {
lines.add(currentLine.toString());
currentLine = new StringBuilder(word);
} else {
lines.add(word);
}
}
}
if (currentLine.length() > 0) {
lines.add(currentLine.toString());
}
return lines;
}
private String trimStringToWidth(FontRenderer font, String text, float maxWidth) {
if (font.getStringWidth(text) <= maxWidth) {
return text;
}
String trimmed = text;
while (font.getStringWidth(trimmed + "...") > maxWidth && trimmed.length() > 0) {
trimmed = trimmed.substring(0, trimmed.length() - 1);
}
return trimmed + "...";
}
private String formatTime(long ms) {
long seconds = ms / 1000;
long minutes = seconds / 60;
seconds = seconds % 60;
return String.format("%d:%02d", minutes, seconds);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (button == 0) {
float posX = getX();
float posY = getY();
float totalWidth = 90f;
float padding = 5f;
float coverSize = totalWidth - padding * 2;
float coverY = posY + padding;
float controlPanelHeight = 20f;
float controlPanelY = coverY + coverSize + padding;
float buttonSize = 16f;
float buttonSpacing = 8f;
float totalButtonsWidth = buttonSize * 3 + buttonSpacing * 2;
float buttonsStartX = posX + (totalWidth - totalButtonsWidth) / 2;
float buttonY = controlPanelY + (controlPanelHeight - buttonSize) / 2 + 8f;
float prevX = buttonsStartX;
if (mouseX >= prevX && mouseX <= prevX + buttonSize &&
mouseY >= buttonY && mouseY <= buttonY + buttonSize) {
if (session != null) {
try {
session.previous();
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
float playX = prevX + buttonSize + buttonSpacing;
if (mouseX >= playX && mouseX <= playX + buttonSize &&
mouseY >= buttonY && mouseY <= buttonY + buttonSize) {
if (session != null) {
try {
if (mediaInfo.getPlaying()) {
session.pause();
} else {
session.play();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
float nextX = playX + buttonSize + buttonSpacing;
if (mouseX >= nextX && mouseX <= nextX + buttonSize &&
mouseY >= buttonY && mouseY <= buttonY + buttonSize) {
if (session != null) {
try {
session.next();
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
FontRenderer HAWENFont = Fonts.getSize(15, Fonts.Type.HAWEN);
float pX = getX() + getWidth() - HAWENFont.getStringWidth("p") - 5;
float pY = getY() + 6.5f;
float pWidth = HAWENFont.getStringWidth("p");
float pHeight = HAWENFont.getStringHeight("p");
if (mouseX >= pX && mouseX <= pX + pWidth && mouseY >= pY && mouseY <= pY + pHeight) {
java.util.List<String> selected = new java.util.ArrayList<>(Hud.getInstance().interfaceSettings.getSelected());
selected.remove("Music Info");
Hud.getInstance().interfaceSettings.setSelected(selected);
return true;
}
}
return super.mouseClicked(mouseX, mouseY, button);
}
}