Files
Client/src/main/java/de/fullrisk/citrusDev/UI/Module_FPS.java
T
2026-07-11 12:30:16 +02:00

80 lines
2.6 KiB
Java

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;
public class Module_FPS {
private static LabelComponent fpsLabel;
public static FlowLayout fpsContainer;
static boolean toggle = true;
private static boolean shown = false;
private static final Config CONFIG = Config.get();
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();
}
public static void setFpsPadding(int padding) {
CONFIG.fpsP = padding;
CONFIG.save();
if (fpsContainer == null) return;
fpsContainer.padding(Insets.of(padding));
}
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));
}
return fpsContainer;
});
}
public static void tick() {
if (fpsContainer == null) return;
if (toggle && !shown) {
fpsContainer.surface(GLASS_PANEL);
fpsContainer.padding(Insets.of(Config.get().fpsP));
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"));
}
}