Files
src
build.gradle
Config.java
diazsongs-mod-source (2).zip
gradle.properties
LrcParser.java
manifest.kod
README.md
README.txt
settings.gradle
SongPlayer.java
Code
22 1,216
src/main/java/com/diaz/songs/DiazSongsClient.java
package com.diaz.songs;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
import java.util.List;
public class DiazSongsClient implements ClientModInitializer {
private static final KeyBinding.Category CAT = KeyBinding.Category.create(Identifier.of("diazsongs", "main"));
private static KeyBinding next, prev, pause, hud, volUp, volDown, dashboard;
static boolean showHud = true;
static boolean showLyrics = true;
static float lyricScale = 2.0f;
static int lyricColor = 0xFFE8D5FF;
static boolean showFps = true;
static boolean showClock = true;
static int lyricPosition = 0;
@Override
public void onInitializeClient() {
DiazSongPlayer.INSTANCE.scan();
next = reg("key.diazsongs.next", GLFW.GLFW_KEY_RIGHT_BRACKET);
prev = reg("key.diazsongs.prev", GLFW.GLFW_KEY_LEFT_BRACKET);
pause = reg("key.diazsongs.pause", GLFW.GLFW_KEY_BACKSLASH);
hud = reg("key.diazsongs.hud", GLFW.GLFW_KEY_APOSTROPHE);
volUp = reg("key.diazsongs.volup", GLFW.GLFW_KEY_EQUAL);
volDown = reg("key.diazsongs.voldown", GLFW.GLFW_KEY_MINUS);
dashboard = reg("key.diazsongs.dashboard", GLFW.GLFW_KEY_RIGHT_SHIFT);
ClientTickEvents.END_CLIENT_TICK.register(c -> {
DiazSongPlayer p = DiazSongPlayer.INSTANCE;
while (next.wasPressed()) p.next();
while (prev.wasPressed()) p.prev();
while (pause.wasPressed()) p.togglePause();
while (hud.wasPressed()) showHud = !showHud;
while (volUp.wasPressed()) p.changeVolume(0.05f);
while (volDown.wasPressed()) p.changeVolume(-0.05f);
while (dashboard.wasPressed()) {
if (c.currentScreen == null) c.setScreen(new DiazSongsDashboard());
}
p.tick();
});
ClientLifecycleEvents.CLIENT_STOPPING.register(c -> DiazSongPlayer.INSTANCE.stop());
HudElementRegistry.addLast(Identifier.of("diazsongs", "now_playing"), DiazSongsClient::renderHud);
}
private static KeyBinding reg(String id, int key) {
return KeyBindingHelper.registerKeyBinding(new KeyBinding(id, InputUtil.Type.KEYSYM, key, CAT));
}
private static String fmt(long ms) {
long s = ms / 1000;
return String.format("%d:%02d", s / 60, s % 60);
}
private static void renderHud(DrawContext ctx, net.minecraft.client.render.RenderTickCounter tick) {
MinecraftClient mc = MinecraftClient.getInstance();
if (!showHud || mc.options.hudHidden || mc.player == null) return;
DiazSongPlayer p = DiazSongPlayer.INSTANCE;
TextRenderer tr = mc.textRenderer;
int sw = ctx.getScaledWindowWidth();
int cornerY = 5;
if (showFps) {
ctx.drawTextWithShadow(tr, "FPS: " + mc.getCurrentFps(), 5, cornerY, 0xFFFFFFFF);
cornerY += 10;
}
if (showClock) {
ctx.drawTextWithShadow(tr, java.time.LocalTime.now().format(java.time.format.DateTimeFormatter.ofPattern("HH:mm")), 5, cornerY, 0xFFFFFFFF);
}
// --- Now-playing pill (top center) ---
String title = !p.error().isEmpty() ? p.error() : (p.isPaused() ? "\u23F8 " : "\u266B ") + p.title();
int w = Math.max(120, tr.getWidth(title) + 20);
int x = (sw - w) / 2, y = 4, h = 22;
ctx.fill(x, y, x + w, y + h, 0xB0140A24);
ctx.fill(x, y, x + w, y + 1, 0xFFB46CFF);
ctx.drawCenteredTextWithShadow(tr, title, sw / 2, y + 4, 0xFFFFFFFF);
if (p.hasSongs() && p.lengthMs() > 0) {
float prog = Math.min(1f, p.positionMs() / (float) p.lengthMs());
ctx.fill(x + 4, y + h - 5, x + w - 4, y + h - 3, 0x60FFFFFF);
ctx.fill(x + 4, y + h - 5, x + 4 + (int) ((w - 8) * prog), y + h - 3, 0xFFB46CFF);
String time = fmt(p.positionMs()) + " / " + fmt(p.lengthMs());
ctx.drawTextWithShadow(tr, time, x + w + 4, y + 4, 0xFFCCCCCC);
}
// --- Lyrics (big, centered, upper screen) ---
List<DiazLyricsParser.Line> lyr = p.lyrics();
if (showLyrics && !lyr.isEmpty() && !p.isPaused()) {
String line = DiazLyricsParser.currentLine(lyr, p.positionMs());
if (!line.isEmpty()) {
var m = ctx.getMatrices();
m.pushMatrix();
float scale = lyricScale;
float position = lyricPosition == 0 ? 0.28f : lyricPosition == 1 ? 0.5f : 0.75f;
m.translate(sw / 2f, ctx.getScaledWindowHeight() * position);
m.scale(scale, scale);
ctx.drawCenteredTextWithShadow(tr, line, 0, 0, lyricColor);
m.popMatrix();
}
}
}
}









