Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/assets/hud-editor-dragged.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/assets/hud-editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@

A simple HUD with essential information easily accessible for Minecraft Fabric.

Requires [Cloth Config](https://modrinth.com/mod/cloth-config), [Mod Menu](https://modrinth.com/mod/modmenu), and [Fabric API](https://modrinth.com/mod/fabric-api).
Requires [Cloth Config](https://modrinth.com/mod/cloth-config) and
[Fabric API](https://modrinth.com/mod/fabric-api).

![Picture of HUD](https://cdn.modrinth.com/data/cached_images/4dd33c9ed510e100af5cc442eb93092624856ba5.png)

## Features
## HUD Editor

- **FPS**: Displays the current frames per second.
- **Ping**: Displays the player's ping to the server.
- **Momentum**: Displays the player's current momentum.
- **Coordinates**: Displays the player's current coordinates.
- **Biome**: Displays the current biome the player is in.
- **Facing**: Displays the direction the player is facing.
- **Time**: Displays the current real world time.
Use **Right Shift** in game (rebindable in Minecraft controls) or open BetterHUD settings with **Mod Menu** to edit BetterHUD.

## Configuration (requires Mod Menu)
## Configuration (requires Cloth Config)
![General Settings](https://cdn.modrinth.com/data/cached_images/9c3ed350ef0c2206a7439d1e1c15b708aa22a332.png)
![Mod Settings](https://cdn.modrinth.com/data/cached_images/f89e15c258a5a24cfda8fe9398406a7ce16edbcc.png)
## Installation
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ dependencies {
processResources {
def dependsExtra = ''',
"fabric-api": "*",
"modmenu": "*",
"cloth-config2": "*"'''

def expansion = [
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ dev.kikugie.stonecutter.hard_mode=true
loom_version=1.17-SNAPSHOT

# Mod Properties (shared)
mod_version=2.1.1
mod_version=3.0.0
maven_group=dsns.betterhud
archives_base_name=betterhud
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
// Keep the two files in sync when changing the test.

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

import net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest;
import net.fabricmc.fabric.api.client.gametest.v1.TestInput;
import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext;
import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screens.worldselection.WorldCreationUiState;
import org.lwjgl.glfw.GLFW;

@SuppressWarnings("UnstableApiUsage")
public class BetterHudClientGameTest implements FabricClientGameTest {
Expand All @@ -28,7 +33,73 @@ public void runTest(ClientGameTestContext context) {

context.waitTicks(40);
assertScreenshotSaved(context.takeScreenshot("betterhud-survival-world"));

exerciseHudEditor(context);
}
}

private static void exerciseHudEditor(ClientGameTestContext context) {
TestInput input = context.getInput();

input.pressKey(GLFW.GLFW_KEY_RIGHT_SHIFT);
context.waitTicks(5);
assertScreenshotSaved(context.takeScreenshot("betterhud-hud-editor"));

double guiScale = context.computeOnClient(client -> (double) client.getWindow().getGuiScale());

input.setCursorPos(12.0 * guiScale, 8.0 * guiScale);
input.holdMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
for (int i = 0; i < 10; i++) {
input.moveCursor(8.0 * guiScale, 5.0 * guiScale);
context.waitTick();
}
input.releaseMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
assertScreenshotSaved(context.takeScreenshot("betterhud-hud-editor-dragged"));

input.pressKey(GLFW.GLFW_KEY_ESCAPE);
context.waitTicks(2);

Properties config = loadConfig();
if (!"custom".equals(config.getProperty("FPS.Position"))) {
throw new AssertionError(
"Dragging in the HUD editor did not give the FPS element a custom position: " + config);
}
double customX = Double.parseDouble(config.getProperty("FPS.Custom X"));
double customY = Double.parseDouble(config.getProperty("FPS.Custom Y"));
if (customX <= 1 || customY <= 1) {
throw new AssertionError(
"Dragging in the HUD editor did not move the FPS element: x=" + customX + "% y=" + customY + "%");
}

input.pressKey(GLFW.GLFW_KEY_RIGHT_SHIFT);
context.waitTicks(5);
input.setCursorPos(92.0 * guiScale, 58.0 * guiScale);
input.holdMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
for (int i = 0; i < 10; i++) {
input.moveCursor(-8.0 * guiScale, -5.0 * guiScale);
context.waitTick();
}
input.releaseMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
context.waitTicks(2);
input.pressKey(GLFW.GLFW_KEY_ESCAPE);
context.waitTicks(2);

config = loadConfig();
if (!"top-left".equals(config.getProperty("FPS.Position"))) {
throw new AssertionError(
"Dragging into the corner did not dock the FPS element back: " + config);
}
}

private static Properties loadConfig() {
Path config = FabricLoader.getInstance().getConfigDir().resolve("betterhud.properties");
Properties properties = new Properties();
try (InputStream in = Files.newInputStream(config)) {
properties.load(in);
} catch (IOException e) {
throw new UncheckedIOException("Could not read " + config, e);
}
return properties;
}

private static void assertScreenshotSaved(Path screenshot) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package dsns.betterhud.gametest;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

import net.fabricmc.fabric.api.client.gametest.v1.FabricClientGameTest;
import net.fabricmc.fabric.api.client.gametest.v1.TestInput;
import net.fabricmc.fabric.api.client.gametest.v1.context.ClientGameTestContext;
import net.fabricmc.fabric.api.client.gametest.v1.context.TestSingleplayerContext;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screens.worldselection.WorldCreationUiState;
import org.lwjgl.glfw.GLFW;

@SuppressWarnings("UnstableApiUsage")
public class BetterHudClientGameTest implements FabricClientGameTest {
Expand All @@ -23,7 +28,73 @@ public void runTest(ClientGameTestContext context) {

context.waitTicks(40);
assertScreenshotSaved(context.takeScreenshot("betterhud-survival-world"));

exerciseHudEditor(context);
}
}

private static void exerciseHudEditor(ClientGameTestContext context) {
TestInput input = context.getInput();

input.pressKey(GLFW.GLFW_KEY_RIGHT_SHIFT);
context.waitTicks(5);
assertScreenshotSaved(context.takeScreenshot("betterhud-hud-editor"));

double guiScale = context.computeOnClient(client -> (double) client.getWindow().getGuiScale());

input.setCursorPos(12.0 * guiScale, 8.0 * guiScale);
input.holdMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
for (int i = 0; i < 10; i++) {
input.moveCursor(8.0 * guiScale, 5.0 * guiScale);
context.waitTick();
}
input.releaseMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
assertScreenshotSaved(context.takeScreenshot("betterhud-hud-editor-dragged"));

input.pressKey(GLFW.GLFW_KEY_ESCAPE);
context.waitTicks(2);

Properties config = loadConfig();
if (!"custom".equals(config.getProperty("FPS.Position"))) {
throw new AssertionError(
"Dragging in the HUD editor did not give the FPS element a custom position: " + config);
}
double customX = Double.parseDouble(config.getProperty("FPS.Custom X"));
double customY = Double.parseDouble(config.getProperty("FPS.Custom Y"));
if (customX <= 1 || customY <= 1) {
throw new AssertionError(
"Dragging in the HUD editor did not move the FPS element: x=" + customX + "% y=" + customY + "%");
}

input.pressKey(GLFW.GLFW_KEY_RIGHT_SHIFT);
context.waitTicks(5);
input.setCursorPos(92.0 * guiScale, 58.0 * guiScale);
input.holdMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
for (int i = 0; i < 10; i++) {
input.moveCursor(-8.0 * guiScale, -5.0 * guiScale);
context.waitTick();
}
input.releaseMouse(GLFW.GLFW_MOUSE_BUTTON_LEFT);
context.waitTicks(2);
input.pressKey(GLFW.GLFW_KEY_ESCAPE);
context.waitTicks(2);

config = loadConfig();
if (!"top-left".equals(config.getProperty("FPS.Position"))) {
throw new AssertionError(
"Dragging into the corner did not dock the FPS element back: " + config);
}
}

private static Properties loadConfig() {
Path config = FabricLoader.getInstance().getConfigDir().resolve("betterhud.properties");
Properties properties = new Properties();
try (InputStream in = Files.newInputStream(config)) {
properties.load(in);
} catch (IOException e) {
throw new UncheckedIOException("Could not read " + config, e);
}
return properties;
}

private static void assertScreenshotSaved(Path screenshot) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/dsns/betterhud/BetterHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
//? if >=26 {
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
//?} else {
/*import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;*/
//?}
//? if >=1.21.6 {
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
//?} else {
/*import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
*///?}
import net.minecraft.client.KeyMapping;
//? if >=26 {
import net.minecraft.resources.Identifier;
//?} else if >=1.21.6 {
/*import net.minecraft.resources.ResourceLocation;*/
//?}
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,10 +44,34 @@ public class BetterHUD implements ClientModInitializer {
)
);

public static KeyMapping openEditorKey;

@Override
public void onInitializeClient() {
Config.configure();

//? if >=26 {
openEditorKey = KeyMappingHelper.registerKeyMapping(
//?} else {
/*openEditorKey = KeyBindingHelper.registerKeyBinding(*/
//?}
new KeyMapping(
"key.betterhud.open_editor",
GLFW.GLFW_KEY_RIGHT_SHIFT,
//? if >=26 {
KeyMapping.Category.register(
Identifier.fromNamespaceAndPath("betterhud", "main")
)
//?} else if >=1.21.9 {
/*KeyMapping.Category.register(
ResourceLocation.fromNamespaceAndPath("betterhud", "main")
)*/
//?} else {
/*"key.categories.betterhud"*/
//?}
)
);

BetterHUDGUI betterHUDGUI = new BetterHUDGUI();

//? if >=26 {
Expand Down
Loading
Loading