Files
Client/src/main/java/de/fullrisk/citrusDev/UI/Module_FPS.java
T

73 lines
2.4 KiB
Java
Raw Normal View History

2026-07-06 18:52:02 +02:00
package de.fullrisk.citrusDev.UI;
import io.wispforest.owo.ui.component.LabelComponent;
import io.wispforest.owo.ui.component.UIComponents;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.UIContainers;
import io.wispforest.owo.ui.core.*;
import io.wispforest.owo.ui.hud.Hud;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import de.fullrisk.citrusDev.Config;
2026-07-06 18:52:02 +02:00
public class Module_FPS {
private static LabelComponent fpsLabel;
public static FlowLayout fpsContainer;
2026-07-06 18:52:02 +02:00
static boolean toggle = true;
2026-07-07 21:46:26 +02:00
private static boolean shown = false;
2026-07-06 18:52:02 +02:00
private static final Config CONFIG = Config.get();
2026-07-06 18:52:02 +02:00
private static final Surface GLASS_PANEL = Surface.blur(5f, 15f)
.and(Surface.flat(0x40FFFFFF));
public static void setPosition(int x, int y) {
if (fpsContainer != null) {
fpsContainer.positioning(Positioning.relative(x, y));
}
CONFIG.fpsX = x;
CONFIG.fpsY = y;
CONFIG.save();
}
2026-07-06 18:52:02 +02:00
public static void register() {
Hud.add(Identifier.fromNamespaceAndPath("citrus-dev", "fps_display"), () -> {
if (fpsContainer == null) {
fpsLabel = UIComponents.label(Component.literal(""));
fpsContainer = UIContainers.horizontalFlow(Sizing.content(), Sizing.content());
fpsContainer.gap(4);
fpsContainer.verticalAlignment(VerticalAlignment.CENTER);
fpsContainer.horizontalAlignment(HorizontalAlignment.CENTER);
fpsContainer.padding(Insets.of(0));
fpsContainer.positioning(Positioning.relative(CONFIG.fpsX, CONFIG.fpsY));
2026-07-06 18:52:02 +02:00
}
return fpsContainer;
});
}
public static void tick() {
if (fpsContainer == null) return;
if (toggle && !shown) {
fpsContainer.surface(GLASS_PANEL);
fpsContainer.padding(Insets.of(6));
fpsContainer.child(fpsLabel);
shown = true;
} else if (!toggle && shown) {
fpsContainer.clearChildren();
fpsContainer.surface(Surface.flat(0));
fpsContainer.padding(Insets.of(0));
shown = false;
}
if (!toggle) return;
Minecraft client = Minecraft.getInstance();
fpsLabel.text(Component.literal(client.getFps() + " FPS"));
}
}