added coords

This commit is contained in:
2026-07-11 14:58:57 +02:00
parent 476925c31b
commit a2d8780238
6 changed files with 191 additions and 9 deletions
@@ -16,11 +16,18 @@ public class Config {
public int fpsSize = 16; public int fpsSize = 16;
public int fpsX = 1; public int fpsX = 1;
public int fpsY = 1; public int fpsY = 1;
public boolean fpsEnabled = true;
public String lastModule = "FPS"; public String lastModule = "FPS";
public int keyX = 1; public int keyX = 1;
public int keyY = 1; public int keyY = 1;
public int keySize = 16; public int keySize = 16;
public boolean keyEnabled = true;
public int coordsX = 1;
public int coordsY = 1;
public int coordsP = 4;
public boolean coordsEnabled = true;
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static final Path PATH = FabricLoader.getInstance() private static final Path PATH = FabricLoader.getInstance()
@@ -0,0 +1,121 @@
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.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.world.phys.Vec3;
import de.fullrisk.citrusDev.Config;
public class Module_Coords {
private static LabelComponent x;
private static LabelComponent y;
private static LabelComponent z;
public static FlowLayout coordinates;
private static final Config CONFIG = Config.get();
// Loaded from Config instead of hardcoded, so the toggle survives a restart.
static boolean toggle = CONFIG.coordsEnabled;
private static boolean shown = false;
public static boolean isEnabled() {
return toggle;
}
public static void setEnabled(boolean value) {
toggle = value;
CONFIG.coordsEnabled = value;
CONFIG.save();
}
private static final Surface GLASS_PANEL = Surface.blur(5f, 15f)
.and(Surface.flat(0x40FFFFFF));
public static void setPosition(int x, int y) {
if (coordinates != null) {
coordinates.positioning(Positioning.relative(x, y));
}
CONFIG.coordsX = x;
CONFIG.coordsY = y;
CONFIG.save();
}
public static void setCoordsPadding(int padding) {
CONFIG.coordsP = padding;
CONFIG.save();
if (coordinates == null) return;
coordinates.padding(Insets.of(padding));
}
public static void register() {
Hud.add(Identifier.fromNamespaceAndPath("citrus-dev", "coords_display"), () -> {
if (coordinates == null) {
x = UIComponents.label(Component.literal(""));
y = UIComponents.label(Component.literal(""));
z = UIComponents.label(Component.literal(""));
coordinates = UIContainers.verticalFlow(Sizing.content(), Sizing.content());
coordinates.gap(2);
coordinates.verticalAlignment(VerticalAlignment.CENTER);
coordinates.horizontalAlignment(HorizontalAlignment.CENTER);
coordinates.padding(Insets.of(0));
coordinates.positioning(Positioning.relative(CONFIG.coordsX, CONFIG.coordsY));
}
return coordinates;
});
}
public static Vec3 getPlayerPosition() {
LocalPlayer player = Minecraft.getInstance().player;
return player != null ? player.position() : null;
}
public static double getX() {
LocalPlayer player = Minecraft.getInstance().player;
return player != null ? player.getX() : 0.0;
}
public static double getY() {
LocalPlayer player = Minecraft.getInstance().player;
return player != null ? player.getY() : 0.0;
}
public static double getZ() {
LocalPlayer player = Minecraft.getInstance().player;
return player != null ? player.getZ() : 0.0;
}
public static void tick() {
if (coordinates == null) return;
if (toggle && !shown) {
coordinates.surface(GLASS_PANEL);
coordinates.padding(Insets.of(CONFIG.coordsP));
coordinates.child(x);
coordinates.child(y);
coordinates.child(z);
shown = true;
} else if (!toggle && shown) {
coordinates.clearChildren();
coordinates.surface(Surface.flat(0));
coordinates.padding(Insets.of(0));
shown = false;
}
if (!toggle) return;
x.text(Component.literal("X: " + String.format("%.1f", Module_Coords.getX())));
y.text(Component.literal("Y: " + String.format("%.1f", Module_Coords.getY())));
z.text(Component.literal("Z: " + String.format("%.1f", Module_Coords.getZ())));
}
}
@@ -15,11 +15,23 @@ public class Module_FPS {
private static LabelComponent fpsLabel; private static LabelComponent fpsLabel;
public static FlowLayout fpsContainer; public static FlowLayout fpsContainer;
static boolean toggle = true;
private static boolean shown = false;
private static final Config CONFIG = Config.get(); private static final Config CONFIG = Config.get();
// Loaded from Config instead of hardcoded, so the toggle survives a restart.
static boolean toggle = CONFIG.fpsEnabled;
private static boolean shown = false;
public static boolean isEnabled() {
return toggle;
}
public static void setEnabled(boolean value) {
toggle = value;
CONFIG.fpsEnabled = value;
CONFIG.save();
}
private static final Surface GLASS_PANEL = Surface.blur(5f, 15f) private static final Surface GLASS_PANEL = Surface.blur(5f, 15f)
.and(Surface.flat(0x40FFFFFF)); .and(Surface.flat(0x40FFFFFF));
@@ -25,18 +25,22 @@ public class Module_KeyStrokes {
private static FlowLayout wBox, aBox, sBox, dBox; private static FlowLayout wBox, aBox, sBox, dBox;
private static ScalableLabel wLabel, aLabel, sLabel, dLabel; // was LabelComponent private static ScalableLabel wLabel, aLabel, sLabel, dLabel; // was LabelComponent
static boolean toggle = true; private static final Config CONFIG = Config.get();
// Loaded from Config instead of hardcoded, so the toggle survives a restart.
static boolean toggle = CONFIG.keyEnabled;
private static boolean shown = false; private static boolean shown = false;
public static boolean isEnabled() { public static boolean isEnabled() {
return toggle; return toggle;
} }
public static void setEnabled(boolean value) { public static void setEnabled(boolean value) {
toggle = value; toggle = value;
CONFIG.keyEnabled = value;
CONFIG.save();
} }
private static final Config CONFIG = Config.get();
private static final Surface GLASS_PANEL = Surface.blur(5f, 15f) private static final Surface GLASS_PANEL = Surface.blur(5f, 15f)
.and(Surface.flat(0x40FFFFFF)); .and(Surface.flat(0x40FFFFFF));
@@ -291,6 +291,28 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
"Module Enabled", "Keystrokes is now active", "Module Enabled", "Keystrokes is now active",
"Module Disabled", "KeyStrokes is now inactive" "Module Disabled", "KeyStrokes is now inactive"
); );
FlowLayout coordinatesRow = ModuleRow.build(
GLASS_PANEL, DISABLED, FLAT,
Identifier.fromNamespaceAndPath("citrus-dev", "textures/icons/block_culling_file.png"),
18, 12,
MC_FIVE,
"Coordinates",
"Shows your Position",
new ModuleRow.ToggleState() {
public boolean get() { return Module_Coords.toggle; }
public void set(boolean value) { Module_Coords.toggle = value; }
},
Identifier.fromNamespaceAndPath("citrus-dev", "textures/icons/settings.png"),
() -> {
Config.get().lastModule = "Coords";
Config.get().save();
openModuleSettings("Coords", CoordsSettings());
},
"Module Enabled", "Keystrokes is now active",
"Module Disabled", "KeyStrokes is now inactive"
);
content.child(coordinatesRow);
content.child(keyStrokesRow); content.child(keyStrokesRow);
content.child(fpsRow); content.child(fpsRow);
@@ -421,6 +443,23 @@ public class MyScreen extends BaseOwoScreen<FlowLayout> {
); );
} }
private List<SettingRow> CoordsSettings() {
List<SettingsControls.ButtonState> positionStates = List.of(
new SettingsControls.ButtonState("L-TOP", () -> Module_Coords.setPosition(1, 1)),
new SettingsControls.ButtonState("R-TOP", () -> Module_Coords.setPosition(99, 1)),
new SettingsControls.ButtonState("R-BOTTOM", () -> Module_Coords.setPosition(99, 99)),
new SettingsControls.ButtonState("L-BOTTOM", () -> Module_Coords.setPosition(1, 99))
);
int currentIndex = positionIndex(Config.get().fpsX, Config.get().fpsY);
return List.of(
new SettingRow("Position", SettingsControls.makeCyclingButton(GLASS_PANEL, positionStates, currentIndex))
);
}
private int positionIndex(int x, int y) { private int positionIndex(int x, int y) {
boolean right = x > 50; boolean right = x > 50;
boolean bottom = y > 50; boolean bottom = y > 50;
@@ -2,10 +2,7 @@ package de.fullrisk.citrusDev.client;
import de.fullrisk.citrusDev.Config; import de.fullrisk.citrusDev.Config;
import de.fullrisk.citrusDev.UI.Module_FPS; import de.fullrisk.citrusDev.UI.*;
import de.fullrisk.citrusDev.UI.Module_KeyStrokes;
import de.fullrisk.citrusDev.UI.MyScreen;
import de.fullrisk.citrusDev.UI.OverviewScreen;
import io.wispforest.owo.ui.hud.Hud; import io.wispforest.owo.ui.hud.Hud;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@@ -22,6 +19,7 @@ public class CitrusDevClient implements ClientModInitializer {
public void onInitializeClient() { public void onInitializeClient() {
Module_FPS.register(); Module_FPS.register();
Module_KeyStrokes.register(); Module_KeyStrokes.register();
Module_Coords.register();
KeyMapping.Category category = KeyMapping.Category.register( KeyMapping.Category category = KeyMapping.Category.register(
Identifier.fromNamespaceAndPath("citrus-dev", "general")); Identifier.fromNamespaceAndPath("citrus-dev", "general"));
@@ -39,6 +37,7 @@ public class CitrusDevClient implements ClientModInitializer {
Module_FPS.tick(); Module_FPS.tick();
Module_KeyStrokes.tick(); Module_KeyStrokes.tick();
Module_Coords.tick();
while (openScreenKey.consumeClick()) { while (openScreenKey.consumeClick()) {
if (client.player != null && client.player.isShiftKeyDown()) { if (client.player != null && client.player.isShiftKeyDown()) {