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
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.10-SNAPSHOT'
id 'net.fabricmc.fabric-loom-remap' version "${loom_version}"
id 'maven-publish'
}

Expand All @@ -13,8 +13,6 @@ base {
allprojects {
apply plugin: "java"
apply plugin: "maven-publish"

archivesBaseName = rootProject.archives_base_name
}

repositories {
Expand All @@ -33,7 +31,7 @@ repositories {
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

Expand Down Expand Up @@ -64,7 +62,6 @@ java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
Expand Down
13 changes: 8 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# IntelliJ IDEA is not yet fully compatible with configuration cache, see: https://github.com/FabricMC/fabric-loom/issues/1349
org.gradle.configuration-cache=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.5
yarn_mappings=1.21.5+build.1
loader_version=0.16.10
minecraft_version=1.21.11
loader_version=0.18.2
loom_version=1.14-SNAPSHOT

# Mod Properties
# need versioning system
Expand All @@ -15,5 +18,5 @@ maven_group = com.tanishisherewith
archives_base_name = dynamichud

# Dependencies
fabric_version=0.119.5+1.21.5
yacl_version=3.6.6+1.21.5-fabric
fabric_version=0.139.4+1.21.11
yacl_version=3.8.2+1.21.11-fabric
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
43 changes: 36 additions & 7 deletions src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
package com.tanishisherewith.dynamichud;

import com.mojang.blaze3d.platform.InputConstants;
import com.tanishisherewith.dynamichud.config.GlobalConfig;
import com.tanishisherewith.dynamichud.helpers.MouseColorQuery;
import com.tanishisherewith.dynamichud.integration.IntegrationManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
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.rendering.v1.HudLayerRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements;
import net.fabricmc.fabric.impl.client.rendering.hud.HudElementRegistryImpl;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.rendertype.RenderType;
import net.minecraft.client.renderer.rendertype.RenderTypes;
import net.minecraft.resources.Identifier;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Environment(EnvType.CLIENT)
public class DynamicHUD implements ClientModInitializer {
public static MinecraftClient MC = MinecraftClient.getInstance();
public static Minecraft MC = Minecraft.getInstance();
public static final Logger logger = LoggerFactory.getLogger("DynamicHud");
public static String MOD_ID = "dynamichud";

static KeyMapping EDITOR_SCREEN_KEYBIND = KeyBindingHelper.registerKeyBinding(new KeyMapping(
"DynamicHud Editor Screen",
InputConstants.Type.KEYSYM,
GLFW.GLFW_KEY_RIGHT_SHIFT,
KeyMapping.Category.register(Identifier.fromNamespaceAndPath("dynamichud", "editor_screen"))
));

public static void printInfo(String msg) {
logger.info(msg);
}
Expand All @@ -28,17 +44,30 @@ public static void printWarn(String msg) {
logger.warn(msg);
}


@Override
public void onInitializeClient() {
printInfo("Initialising DynamicHUD");

//YACL load
GlobalConfig.HANDLER.load();

IntegrationManager.integrate();
ClientLifecycleEvents.CLIENT_STARTED.register((minecraft)-> IntegrationManager.integrate());


//In game screen render.
HudLayerRegistrationCallback.EVENT.register(new HudRender());
/*
* Using the fabric event {@link HudElementRegistry} to render widgets in the game HUD.
* Mouse positions are passed in the negatives even though theoretically it's in the centre of the screen.
*/
HudElementRegistryImpl.attachElementAfter(VanillaHudElements.MISC_OVERLAYS,
Identifier.fromNamespaceAndPath("dynamichud","hudrender_callback"),
(graphics, tickCounter) -> {
for (WidgetRenderer widgetRenderer : IntegrationManager.getWidgetRenderers()) {
widgetRenderer.renderWidgets(graphics, -120, -120);
}
});

ClientTickEvents.END_CLIENT_TICK.register(mc-> MouseColorQuery.processIfPending());
}
}
30 changes: 0 additions & 30 deletions src/main/java/com/tanishisherewith/dynamichud/HudRender.java

This file was deleted.

22 changes: 16 additions & 6 deletions src/main/java/com/tanishisherewith/dynamichud/IntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.tanishisherewith.dynamichud;

import com.mojang.blaze3d.platform.InputConstants;
import com.tanishisherewith.dynamichud.integration.DynamicHudConfigurator;
import com.tanishisherewith.dynamichud.integration.DynamicHudIntegration;
import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.utils.DynamicValueRegistry;
import com.tanishisherewith.dynamichud.widget.Widget;
import com.tanishisherewith.dynamichud.widgets.GraphWidget;
import com.tanishisherewith.dynamichud.widgets.TextWidget;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.text.Text;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import org.lwjgl.glfw.GLFW;

import java.awt.*;

Expand All @@ -23,13 +28,13 @@ public class IntegrationTest implements DynamicHudIntegration {
public void init() {
//Global registry
// We recommend using the syntax "modid:key_name" for easier debugging and to prevent data conflicts in global registries.
DynamicValueRegistry.registerGlobal("dynamichud:FPS", () -> "FPS: " + DynamicHUD.MC.getCurrentFps());
DynamicValueRegistry.registerGlobal("dynamichud:FPS", () -> "FPS: " + DynamicHUD.MC.getFps());

//Local registry
registry = new DynamicValueRegistry(DynamicHUD.MOD_ID);
registry.registerLocal("Hello", () -> "Hello " + DynamicHUD.MC.getSession().getUsername() + "!");
registry.registerLocal("Hello", () -> "Hello " + DynamicHUD.MC.getGameProfile().name() + "!");
registry.registerLocal("DynamicHUD", () -> "DynamicHUD");
registry.registerLocal("FPS", () -> DynamicHUD.MC.getCurrentFps());
registry.registerLocal("FPS", () -> DynamicHUD.MC.getFps());

FPSWidget = new TextWidget.Builder()
.setX(250)
Expand Down Expand Up @@ -99,7 +104,7 @@ public DynamicHudConfigurator configure(DynamicHudConfigurator configurator) {
//renderer.shouldRenderInGameHud(true);
renderer.addScreen(TitleScreen.class);
})
.withMoveableScreen(config -> new AbstractMoveableScreen(Text.literal("Editor Screen"), config.getRenderer()) {});
.withMoveableScreen(config -> new AbstractMoveableScreen(Component.literal("Editor Screen"), config.getRenderer()) {});

return configurator;
}
Expand All @@ -108,4 +113,9 @@ public DynamicHudConfigurator configure(DynamicHudConfigurator configurator) {
public void registerCustomWidgets() {
//WidgetManager.addWidgetData(MyWidget.DATA);
}

@Override
public KeyMapping getKeyBind() {
return DynamicHUD.EDITOR_SCREEN_KEYBIND;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;

import java.awt.*;

public final class GlobalConfig {
public static final ConfigClassHandler<GlobalConfig> HANDLER = ConfigClassHandler.createBuilder(GlobalConfig.class)
.id(Identifier.of("dynamichud", "dynamichud_config"))
.id(Identifier.fromNamespaceAndPath("dynamichud", "dynamichud_config"))
.serializer(config -> GsonConfigSerializerBuilder.create(config)
.setPath(FabricLoader.getInstance().getConfigDir().resolve("dynamichud.json5"))
.setJson5(true)
Expand Down Expand Up @@ -60,69 +60,69 @@ public static GlobalConfig get() {

public Screen createYACLGUI() {
return YetAnotherConfigLib.createBuilder()
.title(Text.literal("DynamicHUD config screen."))
.title(Component.literal("DynamicHUD config screen."))
.category(ConfigCategory.createBuilder()
.name(Text.literal("General"))
.tooltip(Text.literal("Set the general settings for all widgets."))
.name(Component.literal("General"))
.tooltip(Component.literal("Set the general settings for all widgets."))
.group(OptionGroup.createBuilder()
.name(Text.literal("Global"))
.description(OptionDescription.of(Text.literal("Global settings for all widgets.")))
.name(Component.literal("Global"))
.description(OptionDescription.of(Component.literal("Global settings for all widgets.")))
.option(Option.<Float>createBuilder()
.name(Text.literal("Scale"))
.description(OptionDescription.of(Text.literal("Set scale for all widgets.")))
.name(Component.literal("Scale"))
.description(OptionDescription.of(Component.literal("Set scale for all widgets.")))
.binding(1.0f, () -> this.scale, newVal -> this.scale = newVal)
.controller(floatOption -> FloatSliderControllerBuilder.create(floatOption).range(0.1f, 2.5f).step(0.1f))
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.literal("Render in debug screen"))
.description(OptionDescription.of(Text.literal("Renders widgets even when the debug screen is on")))
.name(Component.literal("Render in debug screen"))
.description(OptionDescription.of(Component.literal("Renders widgets even when the debug screen is on")))
.binding(true, () -> this.renderInDebugScreen, newVal -> this.renderInDebugScreen = newVal)
.controller(booleanOption -> BooleanControllerBuilder.create(booleanOption).yesNoFormatter())
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.literal("Show Color picker preview"))
.description(OptionDescription.of(Text.literal("Shows the preview below your mouse pointer on selecting color from the screen. Note: You may drop some frames with the preview on.")))
.name(Component.literal("Show Color picker preview"))
.description(OptionDescription.of(Component.literal("Shows the preview below your mouse pointer on selecting color from the screen. Note: You may drop some frames with the preview on.")))
.binding(true, () -> this.showColorPickerPreview, newVal -> this.showColorPickerPreview = newVal)
.controller(booleanOption -> BooleanControllerBuilder.create(booleanOption).yesNoFormatter())
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.literal("Show widget descriptions/tooltips"))
.description(OptionDescription.of(Text.literal("Shows the description of widgets as tooltips.")))
.name(Component.literal("Show widget descriptions/tooltips"))
.description(OptionDescription.of(Component.literal("Shows the description of widgets as tooltips.")))
.binding(true, () -> this.displayDescriptions, newVal -> this.displayDescriptions = newVal)
.controller(booleanOption -> BooleanControllerBuilder.create(booleanOption).yesNoFormatter())
.build())
.option(Option.<Integer>createBuilder()
.name(Text.literal("Snap Size"))
.description(OptionDescription.of(Text.literal("Grid size for snapping widgets")))
.name(Component.literal("Snap Size"))
.description(OptionDescription.of(Component.literal("Grid size for snapping widgets")))
.binding(100, () -> this.snapSize, newVal -> this.snapSize = newVal)
.controller(integerOption -> IntegerFieldControllerBuilder.create(integerOption).range(10, 500))
.build())
.build())
.option(Option.<Color>createBuilder()
.name(Text.literal("Widget HUD Active Background Color"))
.description(OptionDescription.of(Text.literal("Color of the background of the widget when it will be rendered")))
.name(Component.literal("Widget HUD Active Background Color"))
.description(OptionDescription.of(Component.literal("Color of the background of the widget when it will be rendered")))
.binding(new Color(0, 0, 0, 128), () -> this.hudActiveColor, newVal -> this.hudActiveColor = newVal)
.controller(ColorControllerBuilder::create)
.build())
.option(Option.<Color>createBuilder()
.name(Text.literal("Widget HUD Inactive Background Color"))
.description(OptionDescription.of(Text.literal("Color of the background of the widget when it will NOT be rendered")))
.name(Component.literal("Widget HUD Inactive Background Color"))
.description(OptionDescription.of(Component.literal("Color of the background of the widget when it will NOT be rendered")))
.binding(new Color(255, 0, 0, 128), () -> this.hudInactiveColor, newVal -> this.hudInactiveColor = newVal)
.controller(ColorControllerBuilder::create)
.build())
.option(Option.<com.tanishisherewith.dynamichud.utils.contextmenu.options.Option.Complexity>createBuilder()
.name(Text.literal("Settings Complexity"))
.description(OptionDescription.of(Text.literal("The level of options to display. Options equal to or below this level will be displayed")))
.name(Component.literal("Settings Complexity"))
.description(OptionDescription.of(Component.literal("The level of options to display. Options equal to or below this level will be displayed")))
.binding(com.tanishisherewith.dynamichud.utils.contextmenu.options.Option.Complexity.Simple, () -> this.complexity, newVal -> this.complexity = newVal)
.controller((option) -> EnumControllerBuilder.create(option)
.enumClass(com.tanishisherewith.dynamichud.utils.contextmenu.options.Option.Complexity.class)
.formatValue(value -> Text.of(value.name()))
.formatValue(value -> Component.literal(value.name()))
)
.build())
.build())
.save(HANDLER::save)
.build()
.generateScreen(MinecraftClient.getInstance().currentScreen);
.generateScreen(Minecraft.getInstance().screen);
}

public float getScale() {
Expand Down
Loading