diff --git a/build.gradle b/build.gradle
index b6f4027..8d9cd23 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
plugins {
- id 'fabric-loom' version '1.10-SNAPSHOT'
+ id 'net.fabricmc.fabric-loom-remap' version "${loom_version}"
id 'maven-publish'
}
@@ -13,8 +13,6 @@ base {
allprojects {
apply plugin: "java"
apply plugin: "maven-publish"
-
- archivesBaseName = rootProject.archives_base_name
}
repositories {
@@ -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}"
@@ -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.
diff --git a/gradle.properties b/gradle.properties
index d78b830..1c7c0d3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -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
@@ -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
\ No newline at end of file
+fabric_version=0.139.4+1.21.11
+yacl_version=3.8.2+1.21.11-fabric
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 9bf7bd3..d205b54 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -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
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java
index 7021a07..53dc955 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java
@@ -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);
}
@@ -28,6 +44,7 @@ public static void printWarn(String msg) {
logger.warn(msg);
}
+
@Override
public void onInitializeClient() {
printInfo("Initialising DynamicHUD");
@@ -35,10 +52,22 @@ public void onInitializeClient() {
//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());
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/HudRender.java b/src/main/java/com/tanishisherewith/dynamichud/HudRender.java
deleted file mode 100644
index f7abd75..0000000
--- a/src/main/java/com/tanishisherewith/dynamichud/HudRender.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.tanishisherewith.dynamichud;
-
-import com.tanishisherewith.dynamichud.integration.IntegrationManager;
-import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
-import net.fabricmc.fabric.api.client.rendering.v1.HudLayerRegistrationCallback;
-import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
-import net.fabricmc.fabric.api.client.rendering.v1.IdentifiedLayer;
-import net.fabricmc.fabric.api.client.rendering.v1.LayeredDrawerWrapper;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.render.RenderTickCounter;
-import net.minecraft.util.Identifier;
-
-/**
- * Using the fabric event {@link HudLayerRegistrationCallback} 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.
- */
-public class HudRender implements HudLayerRegistrationCallback {
- @Override
- public void register(LayeredDrawerWrapper layeredDrawer) {
- layeredDrawer.attachLayerAfter(
- IdentifiedLayer.MISC_OVERLAYS,
- IdentifiedLayer.of(Identifier.of("dynamichud","hudrender_callback"),
- (context, tickCounter) -> {
- for (WidgetRenderer widgetRenderer : IntegrationManager.getWidgetRenderers()) {
- widgetRenderer.renderWidgets(context, -120, -120);
- }
- })
- );
- }
-}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/IntegrationTest.java b/src/main/java/com/tanishisherewith/dynamichud/IntegrationTest.java
index e6c010c..1dd92c6 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/IntegrationTest.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/IntegrationTest.java
@@ -1,5 +1,6 @@
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;
@@ -7,8 +8,12 @@
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.*;
@@ -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)
@@ -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;
}
@@ -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;
+ }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java
index e832380..b1dcd44 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java
@@ -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 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)
@@ -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.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.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.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.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.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.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.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.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() {
diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/ColorHelper.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/ColorHelper.java
index 3e39197..1e59066 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/helpers/ColorHelper.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/ColorHelper.java
@@ -1,16 +1,8 @@
package com.tanishisherewith.dynamichud.helpers;
-import com.mojang.blaze3d.systems.RenderSystem;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gl.Framebuffer;
-import net.minecraft.client.util.Window;
-import net.minecraft.util.math.MathHelper;
-import org.lwjgl.BufferUtils;
-import org.lwjgl.opengl.GL11;
-import org.lwjgl.opengl.GL30;
+import net.minecraft.util.Mth;
import java.awt.*;
-import java.nio.ByteBuffer;
/**
* This class provides helper methods for working with colors.
@@ -113,9 +105,9 @@ public static float[] getRainbowColor() {
float pi = (float) Math.PI;
float[] rainbow = new float[3];
- rainbow[0] = 0.5F + 0.5F * MathHelper.sin(x * pi);
- rainbow[1] = 0.5F + 0.5F * MathHelper.sin((x + 4F / 3F) * pi);
- rainbow[2] = 0.5F + 0.5F * MathHelper.sin((x + 8F / 3F) * pi);
+ rainbow[0] = 0.5F + 0.5F * Mth.sin(x * pi);
+ rainbow[1] = 0.5F + 0.5F * Mth.sin((x + 4F / 3F) * pi);
+ rainbow[2] = 0.5F + 0.5F * Mth.sin((x + 8F / 3F) * pi);
return rainbow;
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java
index 0d26f32..e089219 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/DrawHelper.java
@@ -1,25 +1,26 @@
package com.tanishisherewith.dynamichud.helpers;
-import com.mojang.blaze3d.systems.ProjectionType;
import com.mojang.blaze3d.systems.RenderSystem;
import com.tanishisherewith.dynamichud.DynamicHUD;
-import com.tanishisherewith.dynamichud.internal.IRenderLayer;
+import com.tanishisherewith.dynamichud.renderstates.GeometryRenderState;
+import com.tanishisherewith.dynamichud.renderstates.QuadColorRectRenderState;
+import com.tanishisherewith.dynamichud.renderstates.RoundedRectRenderState;
import com.tanishisherewith.dynamichud.utils.CustomRenderLayers;
import com.tanishisherewith.dynamichud.widget.WidgetBox;
-import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.render.*;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.client.util.math.Vector2f;
-import net.minecraft.text.Text;
+import net.minecraft.client.gui.Font;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.navigation.ScreenPosition;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import net.minecraft.client.renderer.RenderPipelines;
+import net.minecraft.network.chat.Component;
+import net.minecraft.util.ARGB;
import net.minecraft.util.Util;
-import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.NotNull;
-import org.joml.Matrix4f;
+import org.joml.Matrix3x2fStack;
import org.joml.Vector4f;
-import org.lwjgl.opengl.GL40C;
import java.awt.*;
+import java.util.Arrays;
import java.util.Objects;
import static com.tanishisherewith.dynamichud.helpers.TextureHelper.mc;
@@ -40,59 +41,42 @@ public class DrawHelper {
* @param endColor end color of the gradient
* @param direction Draws the gradient in the given direction
*/
- public static void drawGradient(DrawContext drawContext, float x, float y, float width, float height, int startColor, int endColor, Direction direction) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugQuads());
-
- switch (direction) {
- case LEFT_RIGHT:
- consumer.vertex(matrix4f, x, y + height, 0.0F).color(startColor);
- consumer.vertex(matrix4f, x + width, y + height, 0.0F).color(endColor);
- consumer.vertex(matrix4f, x + width, y, 0.0F).color(endColor);
- consumer.vertex(matrix4f, x, y, 0.0F).color(startColor);
- break;
- case TOP_BOTTOM:
- consumer.vertex(matrix4f, x, y + height, 0.0F).color(endColor);
- consumer.vertex(matrix4f, x + width, y + height, 0.0F).color(endColor);
- consumer.vertex(matrix4f, x + width, y, 0.0F).color(startColor);
- consumer.vertex(matrix4f, x, y, 0.0F).color(startColor);
- break;
- case RIGHT_LEFT:
- consumer.vertex(matrix4f, x, y + height, 0.0F).color(endColor);
- consumer.vertex(matrix4f, x + width, y + height, 0.0F).color(startColor);
- consumer.vertex(matrix4f, x + width, y, 0.0F).color(startColor);
- consumer.vertex(matrix4f, x, y, 0.0F).color(endColor);
- break;
- case BOTTOM_TOP:
- consumer.vertex(matrix4f, x, y + height, 0.0F).color(startColor);
- consumer.vertex(matrix4f, x + width, y + height, 0.0F).color(startColor);
- consumer.vertex(matrix4f, x + width, y, 0.0F).color(endColor);
- consumer.vertex(matrix4f, x, y, 0.0F).color(endColor);
- break;
- }
- });
- }
-
- public static void enableScissor(int x, int y, int width, int height) {
- enableScissor(x, y, width, height, mc.getWindow().getScaleFactor());
- }
-
- public static void enableScissor(WidgetBox box) {
- enableScissor((int) box.x, (int) box.y, (int) box.getWidth(), (int) box.getHeight(), mc.getWindow().getScaleFactor());
- }
-
- public static void enableScissor(int x, int y, int width, int height, double scaleFactor) {
+ public static void drawGradient(GuiGraphics g, float x, float y, float width, float height, int startColor, int endColor, Direction direction) {
+ int[] c = switch(direction) {
+ case TOP_BOTTOM -> new int[]{startColor, startColor, endColor, endColor};
+ case LEFT_RIGHT -> new int[]{startColor, endColor, endColor, startColor};
+ case RIGHT_LEFT -> new int[]{endColor, startColor, startColor, endColor};
+ case BOTTOM_TOP -> new int[]{endColor, endColor, startColor, startColor};
+ };
+
+ g.guiRenderState.submitGuiElement(
+ new QuadColorRectRenderState(RenderPipelines.GUI,g.pose(),x,y,width,height,c,
+ new ScreenRectangle((int) x, (int) y,(int)width,(int) height),
+ g.scissorStack.peek())
+ );
+ }
+
+ public static void enableScissor(int x, int y, int width, int height, GuiGraphics graphics) {
+ enableScissor(x, y, width, height, mc.getWindow().getGuiScale(),graphics);
+ }
+
+ public static void enableScissor(WidgetBox box,GuiGraphics graphics) {
+ enableScissor((int) box.x, (int) box.y, (int) box.getWidth(), (int) box.getHeight(), mc.getWindow().getGuiScale(),graphics);
+ }
+
+ public static void enableScissor(int x, int y, int width, int height, double scaleFactor, GuiGraphics graphics) {
int scissorX = (int) (x * scaleFactor);
- int scissorY = (int) (DynamicHUD.MC.getWindow().getHeight() - ((y + height) * scaleFactor));
+ int scissorY = (int) (y * scaleFactor);
int scissorWidth = (int) (width * scaleFactor);
int scissorHeight = (int) (height * scaleFactor);
- RenderSystem.enableScissor(scissorX, scissorY, scissorWidth, scissorHeight);
+ ScreenRectangle rect = new ScreenRectangle(x, y, width, height);
+ graphics.scissorStack.push(rect);
}
- public static void disableScissor() {
- RenderSystem.disableScissor();
+
+ public static void disableScissor(GuiGraphics graphics) {
+ graphics.disableScissor();
}
/**
@@ -104,16 +88,8 @@ public static void disableScissor() {
* @param height Height of the rectangle
* @param color Color of the rectangle
*/
- public static void drawRectangle(DrawContext drawContext, float x, float y, float width, float height, int color) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugQuads());
-
- consumer.vertex(matrix4f, x, y + height, 0.0F).color(color);
- consumer.vertex(matrix4f, x + width, y + height, 0.0F).color(color);
- consumer.vertex(matrix4f, x + width, y, 0.0F).color(color);
- consumer.vertex(matrix4f, x, y, 0.0F).color(color);
- });
+ public static void drawRectangle(GuiGraphics graphics, float x, float y, float width, float height, int color) {
+ drawGradient(graphics,x,y,width,height,color,color,Direction.LEFT_RIGHT);
}
/* ==== Drawing Rectangles ==== */
@@ -127,11 +103,11 @@ public static void drawRectangle(DrawContext drawContext, float x, float y, floa
* @param height Height of the rectangle
* @param color Color of the rectangle
*/
- public static void drawOutlineBox(DrawContext drawContext, float x, float y, float width, float height, float thickness, int color) {
- drawRectangle(drawContext, x, y, width, thickness, color);
- drawRectangle(drawContext, x, y + height - thickness, width, thickness, color);
- drawRectangle(drawContext, x, y + thickness, thickness, height - thickness * 2, color);
- drawRectangle(drawContext, x + width - thickness, y + thickness, thickness, height - thickness * 2, color);
+ public static void drawOutlineBox(GuiGraphics graphics, float x, float y, float width, float height, float thickness, int color) {
+ drawRectangle(graphics, x, y, width, thickness, color);
+ drawRectangle(graphics, x, y + height - thickness, width, thickness, color);
+ drawRectangle(graphics, x, y + thickness, thickness, height - thickness * 2, color);
+ drawRectangle(graphics, x + width - thickness, y + thickness, thickness, height - thickness * 2, color);
}
/**
@@ -147,12 +123,12 @@ public static void drawOutlineBox(DrawContext drawContext, float x, float y, flo
* @param shadowOffsetX X position Offset of the shadow from the main rectangle X pos
* @param shadowOffsetY Y position Offset of the shadow from the main rectangle Y pos
*/
- public static void drawRectangleWithShadowBadWay(DrawContext drawContext, float x, float y, float width, float height, int color, int shadowOpacity, float shadowOffsetX, float shadowOffsetY) {
+ public static void drawRectangleWithShadowBadWay(GuiGraphics graphics, float x, float y, float width, float height, int color, int shadowOpacity, float shadowOffsetX, float shadowOffsetY) {
// First, render the shadow
- drawRectangle(drawContext, x + shadowOffsetX, y + shadowOffsetY, width, height, ColorHelper.getColor(0, 0, 0, shadowOpacity));
+ drawRectangle(graphics, x + shadowOffsetX, y + shadowOffsetY, width, height, ColorHelper.getColor(0, 0, 0, shadowOpacity));
// Then, render the rectangle
- drawRectangle(drawContext, x, y, width, height, color);
+ drawRectangle(graphics, x, y, width, height, color);
}
/**
@@ -166,12 +142,12 @@ public static void drawRectangleWithShadowBadWay(DrawContext drawContext, float
* @param color Color of the rounded.fsh rectangle
* @param thickness thickness of the outline
*/
- public static void drawOutlineRoundedBox(DrawContext drawContext, float x, float y, float width, float height, float radius, float thickness, int color) {
+ public static void drawOutlineRoundedBox(GuiGraphics graphics, float x, float y, float width, float height, float radius, float thickness, int color) {
Color c = new Color(color, true);
- drawOutlineRoundedBox(drawContext,x,y,width,height,new Vector4f(radius),thickness,c,c,c,c);
+ drawOutlineRoundedBox(graphics,x,y,width,height,new Vector4f(radius),thickness,c,c,c,c);
}
- public static void drawOutlineRoundedBox(DrawContext drawContext, float x, float y, float width, float height, Vector4f radii, float thickness, Color tl, Color tr, Color br, Color bl) {
+ public static void drawOutlineRoundedBox(GuiGraphics graphics, float x, float y, float width, float height, Vector4f radii, float thickness, Color tl, Color tr, Color br, Color bl) {
if (width <= 0 || height <= 0) return;
float maxRadius = Math.min(width, height) / 2;
radii.set(Math.min(radii.x, maxRadius), // top-left
@@ -179,43 +155,42 @@ public static void drawOutlineRoundedBox(DrawContext drawContext, float x, float
Math.min(radii.z, maxRadius), // bottom-right
Math.min(radii.w, maxRadius) // bottom-left
);
- drawContext.draw(vcp -> {
- VertexConsumer dvc = vcp.getBuffer(CustomRenderLayers.ROUNDED_RECT_OUTLINE.apply(new CustomRenderLayers.OutlineParameters(radii, thickness ,new float[]{width, height})));
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
+ int[] intColors = {tl.getRGB(),tr.getRGB(),br.getRGB(),bl.getRGB()};
- dvc.vertex(matrix4f, x, y + height, 0).texture(0, 0).color(bl.getRGB());
- dvc.vertex(matrix4f, x + width, y + height, 0).texture(width, 0).color(br.getRGB());
- dvc.vertex(matrix4f, x + width, y, 0).texture(width, height).color(tr.getRGB());
- dvc.vertex(matrix4f, x, y, 0).texture(0, height).color(tl.getRGB());
- });
+ graphics.guiRenderState.submitGuiElement(new RoundedRectRenderState(
+ CustomRenderLayers.ROUNDED_RECT_OUTLINE,
+ graphics.pose(),
+ x, y, width, height, thickness, intColors, radii, graphics.scissorStack.peek(),
+ new ScreenRectangle(new ScreenPosition((int) x, (int) y), (int) width, (int) height)
+ ));
}
/**
- * Draw chroma text (text with a nice rainbow effect)
+ * Draw chroma Component (Component with a nice rainbow effect)
*
- * @param drawContext A drawContext object
- * @param text The text to display
- * @param x X pos of text
- * @param y Y pos of text
+ * @param graphics A graphics object
+ * @param Component The Component to display
+ * @param x X pos of Component
+ * @param y Y pos of Component
* @param speed Speed of rainbow
* @param saturation Saturation of the rainbow colors
* @param brightness Brightness of the rainbow colors
* @param spread How much the color difference should be between each character (ideally between 0.001 to 0.2)
- * @param shadow Whether to render the text as shadow.
+ * @param shadow Whether to render the Component as shadow.
*/
- public static void drawChromaText(@NotNull DrawContext drawContext, String text, int x, int y, float speed, float saturation, float brightness, float spread, boolean shadow) {
+ public static void drawChromaText(@NotNull GuiGraphics graphics, String Component, int x, int y, float speed, float saturation, float brightness, float spread, boolean shadow) {
long time = System.currentTimeMillis();
- int length = text.length();
+ int length = Component.length();
for (int i = 0; i < length; i++) {
float hue = (time % (int) (5000 / speed)) / (5000f / speed) + (i * spread); // Adjust the hue based on time and character position
- hue = MathHelper.floorMod(hue, 1.0f); // hue should stay within the range [0, 1]
+ hue = floorMod(hue, 1.0f); // hue should stay within the range [0, 1]
// Convert the hue to an RGB color
int color = Color.HSBtoRGB(hue, saturation, brightness);
// Draw the character with the calculated color
- drawContext.drawText(mc.textRenderer, String.valueOf(text.charAt(i)), x + mc.textRenderer.getWidth(text.substring(0, i)), y, color, shadow);
+ graphics.drawString(mc.font, String.valueOf(Component.charAt(i)), x + mc.font.width(Component.substring(0, i)), y, color, shadow);
}
}
@@ -231,20 +206,30 @@ public static void drawChromaText(@NotNull DrawContext drawContext, String text,
* @param radius radius of the circle outline
* @param color color of the circle outline
*/
- public static void drawOutlineCircle(DrawContext drawContext, float xCenter, float yCenter, float radius, float lineWidth, int color) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugLineStrip(lineWidth));
-
- for (int i = 0; i <= 360; i++) {
- double x = xCenter + Math.sin(Math.toRadians(i)) * radius;
- double y = yCenter + Math.cos(Math.toRadians(i)) * radius;
- double x2 = xCenter + Math.sin(Math.toRadians(i)) * (radius + lineWidth);
- double y2 = yCenter + Math.cos(Math.toRadians(i)) * (radius + lineWidth);
- consumer.vertex(matrix4f, (float) x, (float) y, 0).color(color);
- consumer.vertex(matrix4f, (float) x2, (float) y2, 0).color(color);
- }
- });
+ public static void drawOutlineCircle(GuiGraphics graphics, float xCenter, float yCenter, float radius, float lineWidth, int color) {
+ int segments = 72; // 5-degree steps
+ float[] verts = new float[(segments + 1) * 4];
+ int[] colors = new int[(segments + 1) * 2];
+ Arrays.fill(colors, color);
+
+ for (int i = 0; i <= segments; i++) {
+ float rad = (float) Math.toRadians(i * 5);
+ float sin = (float) Math.sin(rad);
+ float cos = (float) Math.cos(rad);
+
+
+ int base = i * 4;
+ verts[base] = xCenter + sin * radius;
+ verts[base + 1] = yCenter + cos * radius;
+ verts[base + 2] = xCenter + sin * (radius + lineWidth);
+ verts[base + 3] = yCenter + cos * (radius + lineWidth);
+ }
+
+ graphics.guiRenderState.submitGuiElement(new GeometryRenderState(
+ CustomRenderLayers.TRIANGLE_STRIP,
+ graphics.pose(),
+ verts, colors, graphics.scissorStack.peek()
+ ));
}
/**
@@ -255,19 +240,28 @@ public static void drawOutlineCircle(DrawContext drawContext, float xCenter, flo
* @param radius radius of the circle outline
* @param color color of the circle outline
*/
- public static void drawFilledCircle(DrawContext drawContext, float xCenter, float yCenter, float radius, int color) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugTriangleFan());
-
- consumer.vertex(matrix4f, xCenter, yCenter, 0).color(color);
+ public static void drawFilledCircle(GuiGraphics graphics, float xCenter, float yCenter, float radius, int color) {
+ int segments = 72; // 5-degree steps for smoothness
+ float[] verts = new float[(segments + 2) * 2];
+ int[] colors = new int[segments + 2];
+
+ // Center point
+ verts[0] = xCenter; verts[1] = yCenter;
+ colors[0] = color;
+
+ for (int i = 0; i <= segments; i++) {
+ float rad = (float) Math.toRadians(i * 5);
+ int idx = (i + 1) * 2;
+ verts[idx] = xCenter + (float) Math.sin(rad) * radius;
+ verts[idx + 1] = yCenter + (float) Math.cos(rad) * radius;
+ colors[i + 1] = color;
+ }
- for (int i = 0; i <= 360; i++) {
- double x = xCenter + Math.sin(Math.toRadians(i)) * radius;
- double y = yCenter + Math.cos(Math.toRadians(i)) * radius;
- consumer.vertex(matrix4f, (float) x, (float) y, 0).color(color);
- }
- });
+ graphics.guiRenderState.submitGuiElement(new GeometryRenderState(
+ CustomRenderLayers.TRIANGLE_FAN_CUSTOM_BLEND,
+ graphics.pose(),
+ verts, colors, graphics.scissorStack.peek()
+ ));
}
/**
@@ -281,42 +275,14 @@ public static void drawFilledCircle(DrawContext drawContext, float xCenter, floa
* @param shadowOffsetY X position of the circle shadow offset from main circle
* @param shadowOpacity Opacity of the circle shadow offset from main circle
*/
- public static void drawCircleWithShadow(DrawContext drawContext, float xCenter, float yCenter, float radius, int color, int shadowOpacity, float shadowOffsetX, float shadowOffsetY) {
+ public static void drawCircleWithShadow(GuiGraphics graphics, float xCenter, float yCenter, float radius, int color, int shadowOpacity, float shadowOffsetX, float shadowOffsetY) {
// First, render the shadow
- drawFilledCircle(drawContext, xCenter + shadowOffsetX, yCenter + shadowOffsetY, radius, ColorHelper.getColor(0, 0, 0, shadowOpacity));
+ drawFilledCircle(graphics, xCenter + shadowOffsetX, yCenter + shadowOffsetY, radius, ColorHelper.getColor(0, 0, 0, shadowOpacity));
// Then, render the circle
- drawFilledCircle(drawContext, xCenter, yCenter, radius, color);
+ drawFilledCircle(graphics, xCenter, yCenter, radius, color);
}
- /**
- * Not Tested
- *
- * @param x
- * @param y
- * @param radius
- * @param startAngle
- * @param endAngle
- * @param color
- */
- @Deprecated
- public static void drawFilledArc(DrawContext drawContext, float x, float y, float radius, float startAngle, float endAngle, int color) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugLineStrip(1.0f));
-
- for (float angle = startAngle; angle <= endAngle; angle += 1.0F) {
- float x1 = x + MathHelper.cos(angle * 0.017453292F) * radius;
- float y1 = y + MathHelper.sin(angle * 0.017453292F) * radius;
- float x2 = x + MathHelper.cos((angle + 1.0F) * 0.017453292F) * radius;
- float y2 = y + MathHelper.sin((angle + 1.0F) * 0.017453292F) * radius;
-
- consumer.vertex(matrix4f, x, y, 0).color(color);
- consumer.vertex(matrix4f, x1, y1, 0).color(color);
- consumer.vertex(matrix4f, x2, y2, 0).color(color);
- }
- });
- }
/* ==== Drawing Quadrants, Arcs, and Triangles ==== */
/**
@@ -329,37 +295,29 @@ public static void drawFilledArc(DrawContext drawContext, float x, float y, floa
* @param endColor end color of the gradient
* @param quadrant Integer value of the quadrant of the circle. 1 == Top Right, 2 == Top Left, 3 == Bottom Right, 4 == Bottom Left
*/
- public static void drawFilledGradientQuadrant(DrawContext drawContext, float xCenter, float yCenter, float radius, int startColor, int endColor, int quadrant) {
- float startRed = (float) (startColor >> 16 & 255) / 255.0F;
- float startGreen = (float) (startColor >> 8 & 255) / 255.0F;
- float startBlue = (float) (startColor & 255) / 255.0F;
- float startAlpha = (float) (startColor >> 24 & 255) / 255.0F;
-
- float endRed = (float) (endColor >> 16 & 255) / 255.0F;
- float endGreen = (float) (endColor >> 8 & 255) / 255.0F;
- float endBlue = (float) (endColor & 255) / 255.0F;
- float endAlpha = (float) (endColor >> 24 & 255) / 255.0F;
-
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugTriangleFan());
-
- consumer.vertex(matrix4f, xCenter, yCenter, 0).color(startColor);
-
- for (int i = quadrant * 90; i <= quadrant * 90 + 90; i++) {
- double x = xCenter + Math.sin(Math.toRadians(i)) * radius;
- double y = yCenter + Math.cos(Math.toRadians(i)) * radius;
-
- // Interpolate the color based on the angle
- float t = (float) (i - quadrant * 90) / 90.0f;
- float red = startRed * (1 - t) + endRed * t;
- float green = startGreen * (1 - t) + endGreen * t;
- float blue = startBlue * (1 - t) + endBlue * t;
- float alpha = startAlpha * (1 - t) + endAlpha * t;
+ public static void drawFilledGradientQuadrant(GuiGraphics graphics, float xCenter, float yCenter, float radius, int startColor, int endColor, int quadrant) {
+ int segments = 18; // 90 degrees / 5
+ float[] verts = new float[(segments + 2) * 2];
+ int[] colors = new int[segments + 2];
+
+ verts[0] = xCenter; verts[1] = yCenter;
+ colors[0] = startColor;
+
+ for (int i = 0; i <= segments; i++) {
+ float angle = (quadrant * 90) + (i * 5);
+ float rad = (float) Math.toRadians(angle);
+
+ int idx = (i + 1) * 2;
+ verts[idx] = xCenter + (float) Math.sin(rad) * radius;
+ verts[idx + 1] = yCenter + (float) Math.cos(rad) * radius;
+ colors[i + 1] = ARGB.linearLerp((float) i / segments, startColor, endColor);
+ }
- consumer.vertex(matrix4f, (float) x, (float) y, 0).color(red,green,blue,alpha);
- }
- });
+ graphics.guiRenderState.submitGuiElement(new GeometryRenderState(
+ CustomRenderLayers.TRIANGLE_FAN_CUSTOM_BLEND,
+ graphics.pose(),
+ verts, colors, graphics.scissorStack.peek()
+ ));
}
/**
@@ -372,23 +330,37 @@ public static void drawFilledGradientQuadrant(DrawContext drawContext, float xCe
* @param endAngle end Angle of the arc
* @param thickness Thickness of the arc (width of the arc)
*/
- public static void drawArc(DrawContext drawContext, float xCenter, float yCenter, float radius, float thickness, int color, int startAngle, int endAngle) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugTriangleFan());
-
- for (int i = startAngle; i <= endAngle; i++) {
- double innerX = xCenter + Math.sin(Math.toRadians(i)) * (radius - thickness);
- double innerY = yCenter + Math.cos(Math.toRadians(i)) * (radius - thickness);
- double outerX = xCenter + Math.sin(Math.toRadians(i)) * radius;
- double outerY = yCenter + Math.cos(Math.toRadians(i)) * radius;
+ public static void drawArc(GuiGraphics graphics, float xCenter, float yCenter, float radius, float thickness, int color, int startAngle, int endAngle) {
+ int segments = Math.max(1, (endAngle - startAngle) / 5);
+ float[] verts = new float[(segments + 1) * 4];
+ int[] colors = new int[(segments + 1) * 2];
+ Arrays.fill(colors, color);
+
+ for (int i = 0; i <= segments; i++) {
+ int currentAngle = startAngle + (i * 5);
+ if (currentAngle > endAngle) currentAngle = endAngle;
+
+ float rad = (float) Math.toRadians(currentAngle);
+ float sin = (float) Math.sin(rad);
+ float cos = (float) Math.cos(rad);
+
+ int base = i * 4;
+ // Inner Vertex
+ verts[base] = xCenter + sin * (radius - thickness);
+ verts[base + 1] = yCenter + cos * (radius - thickness);
+ // Outer Vertex
+ verts[base + 2] = xCenter + sin * radius;
+ verts[base + 3] = yCenter + cos * radius;
+ }
- consumer.vertex(matrix4f, (float) innerX, (float) innerY, 0).color(color);
- consumer.vertex(matrix4f, (float) outerX, (float) outerY, 0).color(color);
- }
- });
+ graphics.guiRenderState.submitGuiElement(new GeometryRenderState(
+ CustomRenderLayers.TRIANGLE_FAN_CUSTOM_BLEND,
+ graphics.pose(),
+ verts, colors, graphics.scissorStack.peek()
+ ));
}
+
/**
* Draws a filled quadrant
*
@@ -398,44 +370,32 @@ public static void drawArc(DrawContext drawContext, float xCenter, float yCenter
* @param color color of the quadrant
* @param quadrant Integer value of the quadrant of the circle. 1 == Top Right, 2 == Top Left, 3 == Bottom Right, 4 == Bottom Left
*/
- public static void drawFilledQuadrant(DrawContext drawContext, float xCenter, float yCenter, float radius, int color, int quadrant) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getDebugTriangleFan());
-
- consumer.vertex(matrix4f, xCenter, yCenter, 0).color(color);
-
- for (int i = quadrant * 90; i <= quadrant * 90 + 90; i++) {
- double x = xCenter + Math.sin(Math.toRadians(i)) * radius;
- double y = yCenter + Math.cos(Math.toRadians(i)) * radius;
- consumer.vertex(matrix4f, (float) x, (float) y, 0).color(color);
- }
- });
+ public static void drawFilledQuadrant(GuiGraphics graphics, float xCenter, float yCenter, float radius, int color, int quadrant) {
+ drawFilledGradientQuadrant(graphics, xCenter, yCenter, radius, color, color, quadrant);
}
/**
* Draws a Triangle with the given coordinates
- *
- * @param x1
- * @param y1
- * @param x2
- * @param y2
- * @param x3
- * @param y3
- * @param color
*/
- public static void drawOutlineTriangle(DrawContext drawContext, int x1, int y1, int x2, int y2, int x3, int y3, int color) {
- drawContext.draw(vcp -> {
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(RenderLayer.getLines());
-
- consumer.vertex(matrix4f, x1, y1, 0).color(color);
- consumer.vertex(matrix4f, x2, y2, 0).color(color);
- consumer.vertex(matrix4f, x3, y3, 0).color(color);
- consumer.vertex(matrix4f, x1, y1, 0).color(color);
- });
+ public static void drawOutlineTriangle(GuiGraphics graphics, int x1, int y1, int x2, int y2, int x3, int y3, int color) {
+ // 3 lines require 6 vertices (1-2, 2-3, 3-1) to form a closed loop
+ float[] vertices = {
+ (float)x1, (float)y1, (float)x2, (float)y2, // Line 1
+ (float)x2, (float)y2, (float)x3, (float)y3, // Line 2
+ (float)x3, (float)y3, (float)x1, (float)y1 // Line 3
+ };
+
+ int[] colors = new int[6];
+ java.util.Arrays.fill(colors, color);
+
+ graphics.guiRenderState.submitGuiElement(new GeometryRenderState(
+ CustomRenderLayers.COLOR_LINE,
+ graphics.pose(),
+ vertices,
+ colors,
+ graphics.scissorStack.peek()
+ ));
}
-
/**
* Draws a outline quadrant
*
@@ -445,7 +405,7 @@ public static void drawOutlineTriangle(DrawContext drawContext, int x1, int y1,
* @param color color of the quadrant
* @param quadrant Integer value of the quadrant of the circle. 1 == Top Right, 2 == Top Left, 3 == Bottom Right, 4 == Bottom Left
*/
- public static void drawOutlineQuadrant(DrawContext drawContext, float xCenter, float yCenter, float radius, int quadrant, int color) {
+ public static void drawOutlineQuadrant(GuiGraphics graphics, float xCenter, float yCenter, float radius, int quadrant, int color) {
int startAngle = 0;
int endAngle = 0;
@@ -462,7 +422,7 @@ public static void drawOutlineQuadrant(DrawContext drawContext, float xCenter, f
endAngle = 90;
}
- drawArc(drawContext, xCenter, yCenter, radius, 1f, color, startAngle, endAngle);
+ drawArc(graphics, xCenter, yCenter, radius, 1f, color, startAngle, endAngle);
}
/**
@@ -475,8 +435,8 @@ public static void drawOutlineQuadrant(DrawContext drawContext, float xCenter, f
* @param radius Radius of the quadrants / the rounded.fsh rectangle
* @param color Color of the rounded.fsh rectangle
*/
- public static void drawRoundedRectangle(DrawContext drawContext, float x, float y, float width, float height, float radius, int color) {
- drawRoundedRectangle(drawContext, x, y, true, true, true, true, width, height, radius, color);
+ public static void drawRoundedRectangle(GuiGraphics graphics, float x, float y, float width, float height, float radius, int color) {
+ drawRoundedRectangle(graphics, x, y, true, true, true, true, width, height, radius, color);
}
/* ==== Drawing Rounded Rectangles ==== */
@@ -495,17 +455,17 @@ public static void drawRoundedRectangle(DrawContext drawContext, float x, float
* @param radius Radius of the quadrants / the rounded.fsh rectangle
* @param color Color of the rounded.fsh rectangle
*/
- public static void drawRoundedRectangle(DrawContext drawContext, float x, float y, boolean TL, boolean TR, boolean BL, boolean BR, float width, float height, float radius, int color) {
+ public static void drawRoundedRectangle(GuiGraphics graphics, float x, float y, boolean TL, boolean TR, boolean BL, boolean BR, float width, float height, float radius, int color) {
Vector4f radii = new Vector4f(TR ? radius : 0.0f, BR ? radius : 0.0f, TL ? radius : 0.0f, BL ? radius : 0.0f);
// Turns out Color class takes rgb by default not rgba
Color c = new Color(color, true);
- drawRoundedRectangle(drawContext,x,y,width, height, radii, c,c,c,c);
+ drawRoundedRectangle(graphics,x,y,width, height, radii, c,c,c,c);
}
/**
* Draws a rounded rectangle with customizable corner radii, corner colors, and selective corner rounding.
- * @param drawContext DrawContext for rendering
+ * @param graphics GuiGraphics for rendering
* @param x X position
* @param y Y position
*
@@ -514,7 +474,7 @@ public static void drawRoundedRectangle(DrawContext drawContext, float x, float
* @param height Height of the rectangle
* @param radii Vector4f specifying radii for top-left, top-right, bottom-right, bottom-left corners
*/
- public static void drawRoundedRectangle(DrawContext drawContext, float x, float y, float width, float height,
+ public static void drawRoundedRectangle(GuiGraphics graphics, float x, float y, float width, float height,
Vector4f radii, Color tl, Color tr, Color br, Color bl) {
if (width <= 0 || height <= 0) return;
float maxRadius = Math.min(width, height) / 2;
@@ -523,17 +483,17 @@ public static void drawRoundedRectangle(DrawContext drawContext, float x, float
Math.min(radii.z, maxRadius), // bottom-right
Math.min(radii.w, maxRadius) // bottom-left
);
- drawContext.draw(vcp -> {
- VertexConsumer dvc = vcp.getBuffer(CustomRenderLayers.ROUNDED_RECT.apply(new CustomRenderLayers.RoundedParameters(radii, new float[]{width, height})));
- Matrix4f matrix4f = drawContext.getMatrices().peek().getPositionMatrix();
+ int[] intColors = {tl.getRGB(),tr.getRGB(),br.getRGB(),bl.getRGB()};
- dvc.vertex(matrix4f, x, y + height, 0).texture(0, 0).color(bl.getRGB());
- dvc.vertex(matrix4f, x + width, y + height, 0).texture(width, 0).color(br.getRGB());
- dvc.vertex(matrix4f, x + width, y, 0).texture(width, height).color(tr.getRGB());
- dvc.vertex(matrix4f, x, y, 0).texture(0, height).color(tl.getRGB());
- });
+ graphics.guiRenderState.submitGuiElement(new RoundedRectRenderState(
+ CustomRenderLayers.ROUNDED_RECT,
+ graphics.pose(),
+ x, y, width, height, 0f, intColors, radii, graphics.scissorStack.peek(),
+ new ScreenRectangle(new ScreenPosition((int) x, (int) y), (int) width, (int) height)
+ ));
}
+
/**
* Draws an outline rounded.fsh gradient rectangle
*
@@ -547,15 +507,8 @@ public static void drawRoundedRectangle(DrawContext drawContext, float x, float
* @param height Height of rounded.fsh gradient rectangle
* @param radius Radius of the quadrants / the rounded.fsh gradient rectangle
*/
- public static void drawOutlineGradientRoundedBox(DrawContext drawContext, float x, float y, float width, float height, float radius, float thickness, Color tl, Color tr, Color br, Color bl) {
- drawOutlineRoundedBox(drawContext,x,y,width,height,new Vector4f(radius),thickness,tl, tr, br,bl);
- }
-
- public static void drawCutRectangle(DrawContext drawContext, int x1, int y1, int x2, int y2, int z, int color, int cornerRadius) {
- // Draw the rectangles
- drawContext.fill(x1 + cornerRadius, y1, x2 - cornerRadius, y1 + cornerRadius, z, color);
- drawContext.fill(x1 + cornerRadius, y2 - cornerRadius, x2 - cornerRadius, y2, z, color);
- drawContext.fill(x1, y1 + cornerRadius, x2, y2 - cornerRadius, z, color);
+ public static void drawOutlineGradientRoundedBox(GuiGraphics graphics, float x, float y, float width, float height, float radius, float thickness, Color tl, Color tr, Color br, Color bl) {
+ drawOutlineRoundedBox(graphics,x,y,width,height,new Vector4f(radius),thickness,tl, tr, br,bl);
}
/**
@@ -571,12 +524,12 @@ public static void drawCutRectangle(DrawContext drawContext, int x1, int y1, int
* @param shadowOffsetX X offset of the shadow
* @param shadowOffsetY Y offset of the shadow
*/
- public static void drawRoundedRectangleWithShadowBadWay(DrawContext drawContext, float x, float y, float width, float height, float radius, int color, int shadowOpacity, float shadowOffsetX, float shadowOffsetY) {
+ public static void drawRoundedRectangleWithShadowBadWay(GuiGraphics graphics, float x, float y, float width, float height, float radius, int color, int shadowOpacity, float shadowOffsetX, float shadowOffsetY) {
// First, render the shadow
- drawRoundedRectangle(drawContext, x + shadowOffsetX, y + shadowOffsetY, width, height, radius, ColorHelper.getColor(0, 0, 0, shadowOpacity));
+ drawRoundedRectangle(graphics, x + shadowOffsetX, y + shadowOffsetY, width, height, radius, ColorHelper.getColor(0, 0, 0, shadowOpacity));
// Then, render the rounded.fsh rectangle
- drawRoundedRectangle(drawContext, x, y, width, height, radius, color);
+ drawRoundedRectangle(graphics, x, y, width, height, radius, color);
}
/**
@@ -592,8 +545,8 @@ public static void drawRoundedRectangleWithShadowBadWay(DrawContext drawContext,
* @param height Height of rounded.fsh gradient rectangle
* @param radius Radius of the quadrants / the rounded.fsh gradient rectangle
*/
- public static void drawRoundedGradientRectangle(DrawContext drawContext, Color tl, Color tr, Color br, Color bl, float x, float y, float width, float height, float radius) {
- drawRoundedGradientRectangle(drawContext, tl,tr,br,bl, x, y, width, height, radius, true, true, true, true);
+ public static void drawRoundedGradientRectangle(GuiGraphics graphics, Color tl, Color tr, Color br, Color bl, float x, float y, float width, float height, float radius) {
+ drawRoundedGradientRectangle(graphics, tl,tr,br,bl, x, y, width, height, radius, true, true, true, true);
}
/**
@@ -609,19 +562,19 @@ public static void drawRoundedGradientRectangle(DrawContext drawContext, Color t
* @param height Height of rounded.fsh gradient rectangle
* @param radius Radius of the quadrants / the rounded.fsh gradient rectangle
*/
- public static void drawRoundedGradientRectangle(DrawContext drawContext, Color tl, Color tr, Color br, Color bl, float x, float y, float width, float height, float radius, boolean TL, boolean TR, boolean BL, boolean BR) {
- drawRoundedRectangle(drawContext, x, y, width, height,
+ public static void drawRoundedGradientRectangle(GuiGraphics graphics, Color tl, Color tr, Color br, Color bl, float x, float y, float width, float height, float radius, boolean TL, boolean TR, boolean BL, boolean BR) {
+ drawRoundedRectangle(graphics, x, y, width, height,
new Vector4f(TR ? radius : 0.0f, BR ? radius : 0.0f, TL ? radius : 0.0f, BL ? radius : 0.0f),
tl,tr,br,bl);
}
/* ==== Drawing Lines ==== */
- public static void drawVerticalLine(DrawContext drawContext, float x, float y1, float height, float thickness, int color) {
- drawRectangle(drawContext, x, y1, thickness, height, color);
+ public static void drawVerticalLine(GuiGraphics graphics, float x, float y1, float height, float thickness, int color) {
+ drawRectangle(graphics, x, y1, thickness, height, color);
}
- public static void drawHorizontalLine(DrawContext drawContext, float x1, float width, float y, float thickness, int color) {
- drawRectangle(drawContext, x1, y, width, thickness, color);
+ public static void drawHorizontalLine(GuiGraphics graphics, float x1, float width, float y, float thickness, int color) {
+ drawRectangle(graphics, x1, y, width, thickness, color);
}
/**
@@ -633,23 +586,23 @@ public static void drawHorizontalLine(DrawContext drawContext, float x1, float w
* @param y2 The y position of the bottom right corner of the box
* @param color The color to draw the box with
*/
- public static void drawOutlinedBox(DrawContext drawContext, int x1, int y1, int x2, int y2, int color) {
- drawContext.fill(x1, y1, x2, y1 + 1, color);
- drawContext.fill(x1, y2 - 1, x2, y2, color);
- drawContext.fill(x1, y1 + 1, x1 + 1, y2 - 1, color);
- drawContext.fill(x2 - 1, y1 + 1, x2, y2 - 1, color);
+ public static void drawOutlinedBox(GuiGraphics graphics, int x1, int y1, int x2, int y2, int color) {
+ graphics.fill(x1, y1, x2, y1 + 1, color);
+ graphics.fill(x1, y2 - 1, x2, y2, color);
+ graphics.fill(x1, y1 + 1, x1 + 1, y2 - 1, color);
+ graphics.fill(x2 - 1, y1 + 1, x2, y2 - 1, color);
}
public static void unscaledProjection() {
- RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, mc.getWindow().getFramebufferWidth(), mc.getWindow().getFramebufferHeight(), 0, 1000, 21000), ProjectionType.ORTHOGRAPHIC);
+ //RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, mc.getWindow().getWidth(), mc.getWindow().getHeight(), 0, 1000, 21000), ProjectionType.ORTHOGRAPHIC);
}
public static void scaledProjection() {
- RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, (float) (mc.getWindow().getFramebufferWidth() / mc.getWindow().getScaleFactor()), (float) (mc.getWindow().getFramebufferHeight() / mc.getWindow().getScaleFactor()), 0, 1000, 21000), ProjectionType.ORTHOGRAPHIC);
+ //RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, (float) (mc.getWindow().getWidth() / mc.getWindow().getGuiScale()), (float) (mc.getWindow().getFramebufferHeight() / mc.getWindow().getScaleFactor()), 0, 1000, 21000), ProjectionType.ORTHOGRAPHIC);
}
public static void customScaledProjection(float scale) {
- RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, mc.getWindow().getFramebufferWidth() / scale, mc.getWindow().getFramebufferHeight() / scale, 0, 1000, 21000), ProjectionType.ORTHOGRAPHIC);
+ //RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0, mc.getWindow().getWidth() / scale, mc.getWindow().getHeight() / scale, 0, 1000, 21000), ProjectionType.ORTHOGRAPHIC);
}
/**
@@ -659,16 +612,16 @@ public static void customScaledProjection(float scale) {
* @param y Y position of widget
* @param scale Scale the matrices
*/
- public static void scaleAndPosition(MatrixStack matrices, float x, float y, float scale) {
- matrices.push(); // Save the current transformation state
+ public static void scaleAndPosition(Matrix3x2fStack matrices, float x, float y, float scale) {
+ matrices.pushMatrix(); // Save the current transformation state
// Translate the origin back to the desired position
- matrices.translate(x, y, 0);
+ matrices.translate(x, y);
// Scale the matrix
- matrices.scale(scale, scale, 1.0F);
+ matrices.scale(scale, scale);
- matrices.translate(-x, -y, 0);
+ matrices.translate(-x, -y);
}
/**
@@ -680,48 +633,52 @@ public static void scaleAndPosition(MatrixStack matrices, float x, float y, floa
* @param width width of widget
* @param scale Scale the matrices
*/
- public static void scaleAndPosition(MatrixStack matrices, float x, float y, float width, float height, float scale) {
- matrices.push(); // Save the current transformation state
+ public static void scaleAndPosition(Matrix3x2fStack matrices, float x, float y, float width, float height, float scale) {
+ matrices.pushMatrix(); // Save the current transformation state
// Translate the origin back to the desired position
- matrices.translate(x + width / 2.0f, y + height / 2.0f, 0);
+ matrices.translate(x + width / 2.0f, y + height / 2.0f);
// Scale the matrix
- matrices.scale(scale, scale, 1.0F);
+ matrices.scale(scale, scale);
- matrices.translate(-(x + width / 2.0f), -(y + height / 2.0f), 0);
+ matrices.translate(-(x + width / 2.0f), -(y + height / 2.0f));
}
- public static void stopScaling(MatrixStack matrices) {
- matrices.pop(); // Restore the previous transformation state
+ public static void stopScaling(Matrix3x2fStack matrices) {
+ matrices.popMatrix(); // Restore the previous transformation state
}
/**
* From minecraft
*/
- public static void drawScrollableText(DrawContext context, TextRenderer textRenderer, Text text, int centerX, int startX, int startY, int endX, int endY, int color) {
- int i = textRenderer.getWidth(text);
+ public static void drawScrollableText(GuiGraphics graphics, Font font, Component Component, int centerX, int startX, int startY, int endX, int endY, int color) {
+ int i = font.width(Component);
int var10000 = startY + endY;
- Objects.requireNonNull(textRenderer);
+ Objects.requireNonNull(font);
int j = (var10000 - 9) / 2 + 1;
int k = endX - startX;
int l;
if (i > k) {
l = i - k;
- double d = (double) Util.getMeasuringTimeMs() / 1000.0;
+ double d = (double) Util.getMillis() / 1000.0;
double e = Math.max((double) l * 0.5, 3.0);
double f = Math.sin(1.5707963267948966 * Math.cos(6.283185307179586 * d / e)) / 2.0 + 0.5;
- double g = MathHelper.lerp(f, 0.0, l);
- context.enableScissor(startX, startY, endX, endY);
- context.drawTextWithShadow(textRenderer, text, startX - (int) g, j, color);
- context.disableScissor();
+ double g = org.joml.Math.lerp(f, 0.0, l);
+ graphics.enableScissor(startX, startY, endX, endY);
+ graphics.drawString(font, Component, startX - (int) g, j, color,true);
+ graphics.disableScissor();
} else {
- l = MathHelper.clamp(centerX, startX + i / 2, endX - i / 2);
- context.drawCenteredTextWithShadow(textRenderer, text, l, j, color);
+ l = Math.clamp(centerX, startX + i / 2, endX - i / 2);
+ graphics.drawCenteredString(font, Component, l, j, color);
}
}
+ public static float floorMod(float x, float y) {
+ return x - y * (float) Math.floor(x / y);
+ }
+
public enum Direction {
/* LEFT_RIGHT means from left to right. Same for others */
LEFT_RIGHT, TOP_BOTTOM, RIGHT_LEFT, BOTTOM_TOP
diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/MouseColorQuery.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/MouseColorQuery.java
index 095bbf9..644b8ad 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/helpers/MouseColorQuery.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/MouseColorQuery.java
@@ -1,9 +1,9 @@
package com.tanishisherewith.dynamichud.helpers;
+import com.mojang.blaze3d.pipeline.RenderTarget;
+import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gl.Framebuffer;
-import net.minecraft.client.util.Window;
+import net.minecraft.client.Minecraft;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
@@ -26,14 +26,14 @@ public static void request(double mouseX, double mouseY, Consumer callbac
public static void processIfPending() {
if (pendingRequest == null) return;
- MinecraftClient client = MinecraftClient.getInstance();
- Framebuffer framebuffer = client.getFramebuffer();
+ Minecraft client = Minecraft.getInstance();
+ RenderTarget framebuffer = client.getMainRenderTarget();
Window window = client.getWindow();
int windowWidth = window.getWidth();
int windowHeight = window.getHeight();
- int framebufferWidth = framebuffer.textureWidth;
- int framebufferHeight = framebuffer.textureHeight;
+ int framebufferWidth = framebuffer.width;
+ int framebufferHeight = framebuffer.height;
double scaleX = (double) framebufferWidth / windowWidth;
double scaleY = (double) framebufferHeight / windowHeight;
@@ -50,11 +50,9 @@ public static void processIfPending() {
// Make sure rendering is complete
RenderSystem.assertOnRenderThread();
-
// buffer to store the pixel data
ByteBuffer buffer = BufferUtils.createByteBuffer(4);
-
GL11.glReadPixels(x, y, 1, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
int red = buffer.get(0) & 0xFF;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java
index 48b5779..3dfaa37 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/TextureHelper.java
@@ -1,8 +1,8 @@
package com.tanishisherewith.dynamichud.helpers;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.texture.NativeImage;
-import net.minecraft.util.Identifier;
+import com.mojang.blaze3d.platform.NativeImage;
+import net.minecraft.client.Minecraft;
+import net.minecraft.resources.Identifier;
import java.io.IOException;
import java.io.InputStream;
@@ -11,11 +11,11 @@
* This class is entirely untested so some issues may occur which in case should be reported immediately.
*/
public class TextureHelper {
- static MinecraftClient mc = MinecraftClient.getInstance();
+ static Minecraft mc = Minecraft.getInstance();
public static NativeImage loadTexture(Identifier textureId) {
if (mc.getResourceManager().getResource(textureId).isPresent()) {
- try (InputStream inputStream = mc.getResourceManager().getResource(textureId).get().getInputStream()) {
+ try (InputStream inputStream = mc.getResourceManager().getResource(textureId).get().open()) {
return NativeImage.read(inputStream);
} catch (IOException e) {
throw new RuntimeException("Failed to load texture " + textureId, e);
@@ -35,7 +35,7 @@ public static NativeImage resizeTexture(NativeImage image, int newWidth, int new
int srcX = x * oldWidth / newWidth;
int srcY = y * oldHeight / newHeight;
- result.setColorArgb(x, y, image.getColorArgb(srcX, srcY));
+ result.setPixelABGR(x, y, image.getPixel(srcX, srcY));
}
}
@@ -58,10 +58,10 @@ public static NativeImage resizeTextureUsingBilinearInterpolation(NativeImage im
y_diff = (y_ratio * i) - y;
// Indexes of the 4 surrounding pixels
- a = image.getColorArgb(x, y);
- b = image.getColorArgb(x + 1, y);
- c = image.getColorArgb(x, y + 1);
- d = image.getColorArgb(x + 1, y + 1);
+ a = image.getPixel(x, y);
+ b = image.getPixel(x + 1, y);
+ c = image.getPixel(x, y + 1);
+ d = image.getPixel(x + 1, y + 1);
// Blue element
blue = (a & 0xff) * (1 - x_diff) * (1 - y_diff) + (b & 0xff) * (x_diff) * (1 - y_diff) +
@@ -75,7 +75,7 @@ public static NativeImage resizeTextureUsingBilinearInterpolation(NativeImage im
red = ((a >> 16) & 0xff) * (1 - x_diff) * (1 - y_diff) + ((b >> 16) & 0xff) * (x_diff) * (1 - y_diff) +
((c >> 16) & 0xff) * (y_diff) * (1 - x_diff) + ((d >> 16) & 0xff) * (x_diff * y_diff);
- result.setColorArgb(j, i,
+ result.setPixelABGR(j, i,
((((int) red) << 16) & 0xff0000) |
((((int) green) << 8) & 0xff00) |
((int) blue) & 0xff);
@@ -92,7 +92,7 @@ public static NativeImage invertTexture(NativeImage image) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- int argb = image.getColorArgb(x, y);
+ int argb = image.getPixel(x, y);
int alpha = (argb >> 24) & 0xFF;
int red = 255 - ((argb >> 16) & 0xFF);
@@ -101,7 +101,7 @@ public static NativeImage invertTexture(NativeImage image) {
int newArgb = (alpha << 24) | (red << 16) | (green << 8) | blue;
- result.setColorArgb(x, y, newArgb);
+ result.setPixelABGR(x, y, newArgb);
}
}
@@ -123,7 +123,7 @@ public static NativeImage rotateTexture(NativeImage image, int degrees) {
int newY = (int) ((x - centerX) * Math.sin(angle) + (y - centerY) * Math.cos(angle) + centerY);
if (newX >= 0 && newX < width && newY >= 0 && newY < height) {
- result.setColorArgb(newY, newX, image.getColorArgb(x, y));
+ result.setPixelABGR(newY, newX, image.getPixel(x, y));
}
}
}
@@ -138,7 +138,7 @@ private static NativeImage flipTextureHorizontally(NativeImage image) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- result.setColorArgb(width - x - 1, y, image.getColorArgb(x, y));
+ result.setPixelABGR(width - x - 1, y, image.getPixel(x, y));
}
}
@@ -152,7 +152,7 @@ private static NativeImage flipTextureVertically(NativeImage image) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- result.setColorArgb(x, height - y - 1, image.getColorArgb(x, y));
+ result.setPixelABGR(x, height - y - 1, image.getPixel(x, y));
}
}
@@ -174,7 +174,7 @@ public static NativeImage applyGrayScaleFilter(NativeImage image) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- int argb = image.getColorArgb(x, y);
+ int argb = image.getPixel(x, y);
int alpha = (argb >> 24) & 0xFF;
int red = (argb >> 16) & 0xFF;
@@ -184,7 +184,7 @@ public static NativeImage applyGrayScaleFilter(NativeImage image) {
int gray = (red + green + blue) / 3;
int newArgb = (alpha << 24) | (gray << 16) | (gray << 8) | gray;
- result.setColorArgb(x, y, newArgb);
+ result.setPixelABGR(x, y, newArgb);
}
}
@@ -196,7 +196,7 @@ public static NativeImage cropTexture(NativeImage image, int x, int y, int width
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
- result.setColorArgb(j, i, image.getColorArgb(x + j, y + i));
+ result.setPixelABGR(j, i, image.getPixel(x + j, y + i));
}
}
@@ -210,7 +210,7 @@ public static NativeImage tintTexture(NativeImage image, int color) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- int argb = image.getColorArgb(x, y);
+ int argb = image.getPixel(x, y);
int alpha = (argb >> 24) & 0xFF;
int red = ((argb >> 16) & 0xFF) * ((color >> 16) & 0xFF) / 255;
@@ -219,7 +219,7 @@ public static NativeImage tintTexture(NativeImage image, int color) {
int newArgb = (alpha << 24) | (red << 16) | (green << 8) | blue;
- result.setColorArgb(x, y, newArgb);
+ result.setPixelABGR(x, y, newArgb);
}
}
@@ -233,8 +233,8 @@ public static NativeImage overlayTexture(NativeImage image, NativeImage overlay)
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- int argb1 = image.getColorArgb(x, y);
- int argb2 = overlay.getColorArgb(x, y);
+ int argb1 = image.getPixel(x, y);
+ int argb2 = overlay.getPixel(x, y);
int alpha = Math.max((argb1 >> 24) & 0xFF, (argb2 >> 24) & 0xFF);
int red = Math.min(255, ((argb1 >> 16) & 0xFF) + ((argb2 >> 16) & 0xFF));
@@ -243,7 +243,7 @@ public static NativeImage overlayTexture(NativeImage image, NativeImage overlay)
int newArgb = (alpha << 24) | (red << 16) | (green << 8) | blue;
- result.setColorArgb(x, y, newArgb);
+ result.setPixelABGR(x, y, newArgb);
}
}
@@ -258,7 +258,7 @@ public static int getAverageColor(NativeImage image) {
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
- int argb = image.getColorArgb(x, y);
+ int argb = image.getPixel(x, y);
redTotal += (argb >> 16) & 0xFF;
greenTotal += (argb >> 8) & 0xFF;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/helpers/animationhelper/animations/MathAnimations.java b/src/main/java/com/tanishisherewith/dynamichud/helpers/animationhelper/animations/MathAnimations.java
index 6850fff..028e442 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/helpers/animationhelper/animations/MathAnimations.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/helpers/animationhelper/animations/MathAnimations.java
@@ -2,8 +2,10 @@
import com.tanishisherewith.dynamichud.helpers.animationhelper.Easing;
import com.tanishisherewith.dynamichud.helpers.animationhelper.EasingType;
-import net.minecraft.util.math.Vec2f;
-import net.minecraft.util.math.random.Random;
+import net.minecraft.util.RandomSource;
+import net.minecraft.world.phys.Vec2;
+
+import java.util.Random;
public class MathAnimations {
/// SHAKE: Random offset animation with smooth decay
@@ -14,8 +16,8 @@ public static float shake(float intensity, float frequency, float decay) {
}
/// 2D Shake with different X/Y frequencies
- public static Vec2f shake2D(float intensity, float freqX, float freqY) {
- return new Vec2f(
+ public static Vec2 shake2D(float intensity, float freqX, float freqY) {
+ return new Vec2(
(float) Math.sin(System.currentTimeMillis() * freqX) * intensity,
(float) Math.cos(System.currentTimeMillis() * freqY) * intensity
);
@@ -23,16 +25,16 @@ public static Vec2f shake2D(float intensity, float freqX, float freqY) {
/// FLICKER: Random flashing effect
public static float flicker(float min, float max, float chance) {
- Random rand = Random.create();
+ RandomSource rand = RandomSource.create();
return rand.nextFloat() < chance ?
min + (max - min) * rand.nextFloat() :
max;
}
/// CIRCULAR MOTION: Perfect for rotation/orbital animations
- public static Vec2f circularMotion(float radius, float speed, float phase) {
+ public static Vec2 circularMotion(float radius, float speed, float phase) {
double angle = Math.toRadians((System.currentTimeMillis() * speed) % 360 + phase);
- return new Vec2f(
+ return new Vec2(
(float) (Math.cos(angle) * radius),
(float) (Math.sin(angle) * radius)
);
@@ -68,9 +70,9 @@ public static float pulse1(float base, float amplitude, float frequency) {
}
/// SPIRAL: Circular motion with expanding radius
- public static Vec2f spiral(float baseRadius, float expansionRate, float speed) {
+ public static Vec2 spiral(float baseRadius, float expansionRate, float speed) {
float t = System.currentTimeMillis() / 1000f;
- return new Vec2f(
+ return new Vec2(
(float) ((baseRadius + expansionRate * t) * Math.cos(t * speed)),
(float) ((baseRadius + expansionRate * t) * Math.sin(t * speed))
);
diff --git a/src/main/java/com/tanishisherewith/dynamichud/integration/DefaultIntegrationImpl.java b/src/main/java/com/tanishisherewith/dynamichud/integration/DefaultIntegrationImpl.java
index 33ae2b7..50bc203 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/integration/DefaultIntegrationImpl.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/integration/DefaultIntegrationImpl.java
@@ -4,6 +4,7 @@
import com.tanishisherewith.dynamichud.widgets.GraphWidget;
import com.tanishisherewith.dynamichud.widgets.ItemWidget;
import com.tanishisherewith.dynamichud.widgets.TextWidget;
+import net.minecraft.client.KeyMapping;
/**
* The default implementation for included widgets.
@@ -27,4 +28,9 @@ public void registerCustomWidgets() {
GraphWidget.DATA
);
}
+
+ @Override
+ public KeyMapping getKeyBind() {
+ return null;
+ }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/integration/DynamicHudIntegration.java b/src/main/java/com/tanishisherewith/dynamichud/integration/DynamicHudIntegration.java
index bcc32de..156ccb8 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/integration/DynamicHudIntegration.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/integration/DynamicHudIntegration.java
@@ -1,5 +1,6 @@
package com.tanishisherewith.dynamichud.integration;
+import com.mojang.blaze3d.platform.InputConstants;
import com.tanishisherewith.dynamichud.IntegrationTest;
import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.widget.WidgetData;
@@ -7,8 +8,8 @@
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;
-import net.minecraft.client.option.KeyBinding;
-import net.minecraft.client.util.InputUtil;
+import net.minecraft.client.KeyMapping;
+import net.minecraft.resources.Identifier;
import org.lwjgl.glfw.GLFW;
import java.io.File;
@@ -19,16 +20,6 @@
* @see DefaultIntegrationImpl
*/
public interface DynamicHudIntegration {
- /**
- * The key binding for opening the editor screen.
- */
- KeyBinding EDITOR_SCREEN_KEY_BINDING = KeyBindingHelper.registerKeyBinding(new KeyBinding(
- "DynamicHud Editor Screen",
- InputUtil.Type.KEYSYM,
- GLFW.GLFW_KEY_RIGHT_SHIFT,
- "DynamicHud"
- ));
-
/**
* The filename for the widgets file.
*/
@@ -97,7 +88,5 @@ default File getWidgetsFile() {
*
* @return The keybind.
*/
- default KeyBinding getKeyBind() {
- return EDITOR_SCREEN_KEY_BINDING;
- }
+ KeyMapping getKeyBind();
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/integration/IntegrationManager.java b/src/main/java/com/tanishisherewith/dynamichud/integration/IntegrationManager.java
index 485a616..fbaa215 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/integration/IntegrationManager.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/integration/IntegrationManager.java
@@ -13,8 +13,8 @@
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
-import net.minecraft.client.gui.screen.TitleScreen;
-import net.minecraft.client.option.KeyBinding;
+import net.minecraft.client.KeyMapping;
+import net.minecraft.client.gui.screens.TitleScreen;
import java.io.File;
import java.io.IOException;
@@ -49,8 +49,8 @@ public static List getWidgetRenderers() {
* @param key The key to listen for
* @param screen The AbstractMoveableScreen instance to use to set the screen
*/
- public static void openScreen(KeyBinding key, AbstractMoveableScreen screen) {
- if (key.wasPressed()) {
+ public static void openScreen(KeyMapping key, AbstractMoveableScreen screen) {
+ if (key.isDown()) {
DynamicHUD.MC.setScreen(screen);
}
}
@@ -92,7 +92,7 @@ public static void integrate() {
String modId = metadata.getId();
AbstractMoveableScreen screen;
- KeyBinding binding;
+ KeyMapping binding;
WidgetRenderer widgetRenderer;
File widgetsFile;
try {
@@ -161,7 +161,7 @@ public static void integrate() {
ClientTickEvents.START_CLIENT_TICK.register((client) -> {
if (BooleanPool.get("WarningScreenFlag")) return;
- if (DynamicHUD.MC.currentScreen instanceof TitleScreen) {
+ if (DynamicHUD.MC.screen instanceof TitleScreen) {
DynamicHUD.MC.setScreen(new WarningScreen(bad_implementations));
BooleanPool.put("WarningScreenFlag", true);
}
@@ -185,13 +185,13 @@ private static List> getRegisteredInt
}
/**
- * This makes it so that if minecraft is launched with the program arguments
+ * If minecraft is launched with the program arguments
*
* {@code --dynamicHudTest true}
*
- * then it will
- * load the {@link com.tanishisherewith.dynamichud.IntegrationTest} class as an entrypoint, eliminating any errors due to human incapacity of
- * adding/removing a single line from the `fabric.mod.json`
+ * then it wil load the {@link com.tanishisherewith.dynamichud.IntegrationTest} class as an entrypoint,
+ * eliminating any errors due to human incapacity of adding/removing a single line from the `fabric.mod.json`
+ * This is for myself.
*/
private static EntrypointContainer getTestIntegration() {
DynamicHudIntegration testIntegration;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/internal/IBufferBuilder.java b/src/main/java/com/tanishisherewith/dynamichud/internal/IBufferBuilder.java
new file mode 100644
index 0000000..0aaabea
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/internal/IBufferBuilder.java
@@ -0,0 +1,8 @@
+package com.tanishisherewith.dynamichud.internal;
+
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import com.mojang.blaze3d.vertex.VertexFormatElement;
+
+public interface IBufferBuilder {
+ VertexConsumer dynamicHUD$writeGenericFloats(VertexFormatElement element, float... values);
+}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/internal/IRenderLayer.java b/src/main/java/com/tanishisherewith/dynamichud/internal/IRenderLayer.java
deleted file mode 100644
index 3dbc1a2..0000000
--- a/src/main/java/com/tanishisherewith/dynamichud/internal/IRenderLayer.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.tanishisherewith.dynamichud.internal;
-
-import org.joml.Vector4f;
-
-public interface IRenderLayer {
- /**
- * Set uniform u to the value described by v4f, formatted as a vec4 (4 floats)
- * @param u Name
- * @param v4f Value
- */
- default void dynamichud$setUniform(String u, Vector4f v4f) {
- float[] v = new float[]{v4f.x, v4f.y, v4f.z, v4f.w};
- dynamichud$setUniform(u, v);
- }
-
- /**
- * Set uniform u to the value of v, should be an int[], float[] or Matrix4f
- * @param u Name
- * @param v Value
- */
- void dynamichud$setUniform(String u, Object v);
-}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/internal/WarningScreen.java b/src/main/java/com/tanishisherewith/dynamichud/internal/WarningScreen.java
index 2b7ef4b..204760e 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/internal/WarningScreen.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/internal/WarningScreen.java
@@ -1,12 +1,13 @@
package com.tanishisherewith.dynamichud.internal;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.client.gui.widget.ButtonWidget;
-import net.minecraft.text.OrderedText;
-import net.minecraft.text.Text;
-import net.minecraft.util.Formatting;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.Skin;
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.network.chat.Component;
+import net.minecraft.util.FormattedCharSequence;
import net.minecraft.util.Util;
import java.awt.*;
@@ -17,52 +18,53 @@ public class WarningScreen extends Screen {
private final List modErrors;
public WarningScreen(List modErrors) {
- super(Text.of("DynamicHUD Warning"));
+ super(Component.literal("DynamicHUD Warning"));
this.modErrors = modErrors;
}
@Override
protected void init() {
- ButtonWidget confirmButton = ButtonWidget.builder(Text.of("I Understand"), button -> MinecraftClient.getInstance().setScreen(null))
- .dimensions(this.width / 2 - 100, this.height - 40, 200, 20)
- .narrationSupplier((e) -> Text.literal("I understand"))
+ Button confirmButton = Button.builder(Component.literal("I Understand"), button -> Minecraft.getInstance().setScreen(null))
+ .bounds(this.width / 2 - 100, this.height - 40, 200, 20)
+ .createNarration((e) -> Component.literal("I understand"))
.build();
- ButtonWidget logs_folder = ButtonWidget.builder(Text.of("Open logs"), button -> {
- File logsFolder = new File(MinecraftClient.getInstance().runDirectory, "logs");
- Util.getOperatingSystem().open(logsFolder);
+ Button logs_folder = Button.builder(Component.literal("Open logs"), button -> {
+ File logsFolder = new File(Minecraft.getInstance().gameDirectory, "logs");
+ Util.getPlatform().openFile(logsFolder);
})
- .dimensions(this.width / 2 - 100, this.height - 70, 200, 20)
- .narrationSupplier((e) -> Text.literal("Open logs"))
+ .bounds(this.width / 2 - 100, this.height - 70, 200, 20)
+ .createNarration((e) -> Component.literal("Open logs"))
.build();
// Add "I Understand" button
- this.addDrawableChild(confirmButton);
- this.addDrawableChild(logs_folder);
+ this.addRenderableWidget(confirmButton);
+ this.addRenderableWidget(logs_folder);
}
@Override
- public void render(DrawContext context, int mouseX, int mouseY, float delta) {
- super.render(context, mouseX, mouseY, delta);
+ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
+ super.render(graphics, mouseX, mouseY, delta);
- context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 20, 0xFFFFFF);
- context.drawCenteredTextWithShadow(this.textRenderer, "Mods with bad implementation of DynamicHUD found!", this.width / 2, 35, Color.ORANGE.getRGB());
+ graphics.drawCenteredString(this.font, this.title, this.width / 2, 20, 0xFFFFFF);
+ graphics.drawCenteredString(this.font, "Mods with bad implementation of DynamicHUD found!", this.width / 2, 35, Color.ORANGE.getRGB());
int y = 60;
for (ModError error : modErrors) {
- Text modName = Text.literal("> \"" + error.modName() + "\"").formatted(Formatting.RED);
- context.drawText(this.textRenderer, modName, this.width / 2 - 100, y, -1, false);
- List errorMessage = this.textRenderer.wrapLines(Text.literal("Error: " + error.errorMessage()), this.width / 2);
+ Component modName = Component.literal("> \"" + error.modName() + "\"").withStyle(ChatFormatting.RED);
+ graphics.drawString(this.font, modName, this.width / 2 - 100, y, -1, false);
+ List errorMessage =
+ this.font.split(Component.literal("Error: " + error.errorMessage()), this.width / 2);
- if (mouseX >= this.width / 2 - 100 && mouseX <= this.width / 2 - 100 + this.textRenderer.getWidth(modName) && mouseY >= y && mouseY <= y + this.textRenderer.fontHeight) {
- context.drawOrderedTooltip(textRenderer, errorMessage, mouseX, mouseY);
+ if (Skin.isMouseOver(mouseX,mouseY,(double) this.width / 2 - 102, y - 1, this.font.width(modName) + 4,this.font.lineHeight + 2)) {
+ graphics.setTooltipForNextFrame(errorMessage, mouseX, mouseY);
}
y += 11; // Space between mod errors
}
y += 5;
- context.drawCenteredTextWithShadow(this.textRenderer, Text.of("Please report this problem to the respective mod owners."), this.width / 2, y, -1);
- context.drawCenteredTextWithShadow(this.textRenderer, Text.literal("Widgets of these mods won't work.").formatted(Formatting.YELLOW), this.width / 2, y + 10, -1);
- context.drawCenteredTextWithShadow(this.textRenderer, Text.literal("Check latest.log for more details").formatted(Formatting.ITALIC), this.width / 2, y + 30, -1);
+ graphics.drawCenteredString(this.font, Component.literal("Please report this problem to the respective mod owners."), this.width / 2, y, -1);
+ graphics.drawCenteredString(this.font, Component.literal("Widgets of these mods won't work.").withStyle(ChatFormatting.YELLOW), this.width / 2, y + 10, -1);
+ graphics.drawCenteredString(this.font, Component.literal("Check latest.log for more details").withStyle(ChatFormatting.ITALIC), this.width / 2, y + 30, -1);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/mixins/BufferBuilderMixin.java b/src/main/java/com/tanishisherewith/dynamichud/mixins/BufferBuilderMixin.java
new file mode 100644
index 0000000..8f2e442
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/mixins/BufferBuilderMixin.java
@@ -0,0 +1,33 @@
+package com.tanishisherewith.dynamichud.mixins;
+
+import com.mojang.blaze3d.vertex.BufferBuilder;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import com.mojang.blaze3d.vertex.VertexFormatElement;
+import com.tanishisherewith.dynamichud.internal.IBufferBuilder;
+import org.lwjgl.system.MemoryUtil;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
+
+@Mixin(BufferBuilder.class)
+public abstract class BufferBuilderMixin implements VertexConsumer, IBufferBuilder {
+
+ @Shadow
+ protected abstract long beginElement(VertexFormatElement element);
+
+ /**
+ * The "Library" secret sauce.
+ * This allows you to write N floats to a custom GENERIC element.
+ */
+ @Unique
+ public VertexConsumer dynamicHUD$writeGenericFloats(VertexFormatElement element, float... values) {
+ long addr = this.beginElement(element);
+ if (addr != -1L) {
+ for (int i = 0; i < values.length; i++) {
+ // We use the same MemoryUtil Mojang uses in addVertex and setUv
+ MemoryUtil.memPutFloat(addr + (i * 4L), values[i]);
+ }
+ }
+ return this;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/mixins/MinecraftMixin.java b/src/main/java/com/tanishisherewith/dynamichud/mixins/MinecraftMixin.java
new file mode 100644
index 0000000..5a20cd4
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/mixins/MinecraftMixin.java
@@ -0,0 +1,15 @@
+package com.tanishisherewith.dynamichud.mixins;
+
+import com.tanishisherewith.dynamichud.DynamicHUD;
+import com.tanishisherewith.dynamichud.integration.IntegrationManager;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.main.GameConfig;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(Minecraft.class)
+public abstract class MinecraftMixin {
+
+}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java b/src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java
index 5b0367a..ba6887b 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java
@@ -2,11 +2,14 @@
import com.llamalad7.mixinextras.sugar.Local;
import com.tanishisherewith.dynamichud.config.GlobalConfig;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.client.gui.screen.option.OptionsScreen;
-import net.minecraft.client.gui.widget.ButtonWidget;
-import net.minecraft.client.gui.widget.DirectionalLayoutWidget;
-import net.minecraft.text.Text;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
+import net.minecraft.client.gui.layouts.LayoutSettings;
+import net.minecraft.client.gui.layouts.LinearLayout;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.client.gui.screens.options.OptionsScreen;
+import net.minecraft.network.chat.Component;
+import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -18,21 +21,30 @@
@Mixin(OptionsScreen.class)
public abstract class OptionsScreenMixin extends Screen {
@Shadow
- protected abstract ButtonWidget createButton(Text message, Supplier screenSupplier);
+ protected abstract Button openScreenButton(Component component, Supplier supplier);
- protected OptionsScreenMixin(Text title) {
+ @Shadow
+ @Final
+ private HeaderAndFooterLayout layout;
+
+ protected OptionsScreenMixin(Component title) {
super(title);
}
- @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/GridWidget$Adder;add(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget;", ordinal = 0))
- private void init(CallbackInfo ci, @Local(ordinal = 0) DirectionalLayoutWidget directionalLayoutWidget) {
- DirectionalLayoutWidget directionalLayoutWidget2 = directionalLayoutWidget.add(DirectionalLayoutWidget.horizontal());
-
- directionalLayoutWidget2.getMainPositioner().marginLeft(-26).marginY(-28);
-
- ButtonWidget widget = createButton(Text.of("DH"), () -> GlobalConfig.get().createYACLGUI());
- widget.setDimensions(20, 20);
-
- directionalLayoutWidget2.add(widget);
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "INVOKE",
+ target = "Lnet/minecraft/client/gui/layouts/LinearLayout;addChild(Lnet/minecraft/client/gui/layouts/LayoutElement;)Lnet/minecraft/client/gui/layouts/LayoutElement;",
+ ordinal = 1 // this is where the FOV row is added
+ )
+ )
+ private void injectDHLayout(CallbackInfo ci, @Local(ordinal = 0) LinearLayout header) {
+ LinearLayout dhLayout = header.addChild(LinearLayout.vertical(), layoutSettings -> layoutSettings.paddingLeft(-20));
+
+ Button dhButton = openScreenButton(Component.literal("DH"), () -> GlobalConfig.get().createYACLGUI());
+ dhButton.setWidth(20);
+
+ dhLayout.addChild(dhButton);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/mixins/RenderLayerMixin.java b/src/main/java/com/tanishisherewith/dynamichud/mixins/RenderLayerMixin.java
deleted file mode 100644
index cc4795f..0000000
--- a/src/main/java/com/tanishisherewith/dynamichud/mixins/RenderLayerMixin.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.tanishisherewith.dynamichud.mixins;
-
-
-import com.llamalad7.mixinextras.sugar.Local;
-import com.mojang.blaze3d.systems.RenderPass;
-import com.tanishisherewith.dynamichud.internal.IRenderLayer;
-import net.minecraft.client.render.BuiltBuffer;
-import net.minecraft.client.render.RenderLayer;
-import org.joml.Matrix4f;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Unique;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-import java.util.HashMap;
-import java.util.Map;
-
-@Mixin(RenderLayer.MultiPhase.class)
-public class RenderLayerMixin implements IRenderLayer {
- @Unique
- private final Map uniforms = new HashMap<>();
-
- @Override
- public void dynamichud$setUniform(String u, Object v) {
- if (v == null) uniforms.remove(u);
- else uniforms.put(u, v);
- }
-
- @Inject(method = "draw", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderPass;drawIndexed(II)V"))
- void beforeDraw(BuiltBuffer par1, CallbackInfo ci, @Local(ordinal = 0) RenderPass pass) {
- uniforms.forEach((k, v) -> {
- switch (v) {
- case float[] fa -> pass.setUniform(k, fa);
- case int[] ia -> pass.setUniform(k, ia);
- case Matrix4f mat -> pass.setUniform(k, mat);
- default -> throw new IllegalStateException("Unknown uniform type " + v.getClass() + " (" + v + ")");
- }
- });
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/mixins/ScreenMixin.java b/src/main/java/com/tanishisherewith/dynamichud/mixins/ScreenMixin.java
index 21446b4..bf685ba 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/mixins/ScreenMixin.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/mixins/ScreenMixin.java
@@ -3,9 +3,8 @@
import com.tanishisherewith.dynamichud.integration.IntegrationManager;
import com.tanishisherewith.dynamichud.widget.WidgetManager;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.screens.Screen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -21,19 +20,19 @@ public abstract class ScreenMixin {
public int height;
@Inject(at = @At("RETURN"), method = "render")
- private void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
+ private void render(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
for (WidgetRenderer widgetRenderer : IntegrationManager.getWidgetRenderers()) {
- widgetRenderer.renderWidgets(context, mouseX, mouseY);
+ widgetRenderer.renderWidgets(graphics, mouseX, mouseY);
}
}
//Injected before the screen is actually resized to get the new and also the old dimensions.
@Inject(at = @At("HEAD"), method = "resize")
- private void onScreenResize(MinecraftClient client, int width, int height, CallbackInfo ci) {
+ private void onScreenResize(int i, int j, CallbackInfo ci) {
WidgetManager.onScreenResized(width, height, this.width, this.height);
}
- @Inject(at = @At("HEAD"), method = "close")
+ @Inject(at = @At("HEAD"), method = "onClose")
private void onClose(CallbackInfo ci) {
for (WidgetRenderer widgetRenderer : IntegrationManager.getWidgetRenderers()) {
widgetRenderer.onCloseScreen();
diff --git a/src/main/java/com/tanishisherewith/dynamichud/renderstates/GeometryRenderState.java b/src/main/java/com/tanishisherewith/dynamichud/renderstates/GeometryRenderState.java
new file mode 100644
index 0000000..8926ee4
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/renderstates/GeometryRenderState.java
@@ -0,0 +1,38 @@
+package com.tanishisherewith.dynamichud.renderstates;
+
+import com.mojang.blaze3d.pipeline.RenderPipeline;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import net.minecraft.client.gui.render.TextureSetup;
+import net.minecraft.client.gui.render.state.GuiElementRenderState;
+import org.jetbrains.annotations.Nullable;
+import org.joml.Matrix3x2fStack;
+
+// State for Geometric Shapes (Circles, Arcs, Fans)
+public record GeometryRenderState(
+ RenderPipeline pipeline,
+ Matrix3x2fStack pose,
+ float[] vertices, // Flat array: [x1, y1, x2, y2, ...]
+ int[] colors, // Parallel array of ARGB colors
+ @Nullable ScreenRectangle scissorArea
+) implements GuiElementRenderState {
+
+ public record VertexData(float x, float y, int color) {}
+
+ @Override
+ public void buildVertices(VertexConsumer consumer) {
+ for (int i = 0; i < vertices.length / 2; i++) {
+ consumer.addVertexWith2DPose(pose, vertices[i * 2], vertices[i * 2 + 1])
+ .setColor(colors[i]);
+ }
+ }
+
+ @Override
+ public TextureSetup textureSetup() {
+ return TextureSetup.noTexture();
+ }
+ @Override
+ public @Nullable ScreenRectangle bounds() {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/renderstates/GradientShadowRenderState.java b/src/main/java/com/tanishisherewith/dynamichud/renderstates/GradientShadowRenderState.java
new file mode 100644
index 0000000..1e4af63
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/renderstates/GradientShadowRenderState.java
@@ -0,0 +1,44 @@
+package com.tanishisherewith.dynamichud.renderstates;
+
+import com.mojang.blaze3d.pipeline.RenderPipeline;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import net.minecraft.client.gui.render.TextureSetup;
+import net.minecraft.client.gui.render.state.GuiElementRenderState;
+import org.jetbrains.annotations.Nullable;
+import org.joml.Matrix3x2fc;
+import org.jspecify.annotations.NonNull;
+
+import java.util.List;
+
+//TODO: just use fillGradient in GuiGraphics
+public record GradientShadowRenderState(
+ List points,
+ float bottomY,
+ int startColor,
+ int endColor,
+ Matrix3x2fc pose,
+ RenderPipeline pipeline,
+ @Nullable ScreenRectangle scissorArea
+) implements GuiElementRenderState {
+
+ @Override
+ public void buildVertices(@NonNull VertexConsumer consumer) {
+ for (float[] point : points) {
+ float x = point[0];
+ float y = point[1];
+
+ consumer.addVertexWith2DPose(pose, x, y).setColor(startColor);
+ consumer.addVertexWith2DPose(pose, x, bottomY).setColor(endColor);
+ }
+ }
+ @Override
+ public TextureSetup textureSetup() {
+ return TextureSetup.noTexture();
+ }
+
+ @Override
+ public @org.jspecify.annotations.Nullable ScreenRectangle bounds() {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/tanishisherewith/dynamichud/renderstates/InterpolatedCurveRenderState.java b/src/main/java/com/tanishisherewith/dynamichud/renderstates/InterpolatedCurveRenderState.java
new file mode 100644
index 0000000..96031ee
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/renderstates/InterpolatedCurveRenderState.java
@@ -0,0 +1,59 @@
+package com.tanishisherewith.dynamichud.renderstates;
+
+import com.mojang.blaze3d.pipeline.RenderPipeline;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import net.minecraft.client.gui.render.TextureSetup;
+import net.minecraft.client.gui.render.state.GuiElementRenderState;
+import org.jetbrains.annotations.Nullable;
+import org.joml.Matrix3x2fc;
+import org.jspecify.annotations.NonNull;
+
+import java.util.List;
+
+public record InterpolatedCurveRenderState(
+ List points,
+ float thickness,
+ int color,
+ Matrix3x2fc pose,
+ RenderPipeline pipeline,
+ @Nullable ScreenRectangle scissorArea
+) implements GuiElementRenderState {
+
+ @Override
+ public void buildVertices(@NonNull VertexConsumer consumer) {
+ consumer.addVertexWith2DPose(pose, 10, 10).setColor(color);
+ consumer.addVertexWith2DPose(pose, 100, 10).setColor(color);
+ consumer.addVertexWith2DPose(pose, 10, 20).setColor(color);
+ consumer.addVertexWith2DPose(pose, 100, 20).setColor(color);
+ /*
+ for (int i = 0; i < points.size(); i++) {
+ float[] point = points.get(i);
+ float x = point[0];
+ float y = point[1];
+
+ float dx = (i < points.size() - 1) ? points.get(i + 1)[0] - x : x - points.get(i - 1)[0];
+ float dy = (i < points.size() - 1) ? points.get(i + 1)[1] - y : y - points.get(i - 1)[1];
+ float length = (float) Math.sqrt(dx * dx + dy * dy);
+ if (length == 0) continue;
+
+ float offsetX = (thickness * 0.5f * dy) / length;
+ float offsetY = (thickness * 0.5f * -dx) / length;
+
+ consumer.addVertexWith2DPose(pose, x + offsetX, y + offsetY).setColor(color);
+ consumer.addVertexWith2DPose(pose, x - offsetX, y - offsetY).setColor(color);
+ }
+
+ */
+ }
+
+ @Override
+ public TextureSetup textureSetup() {
+ return TextureSetup.noTexture();
+ }
+
+ @Override
+ public @Nullable ScreenRectangle bounds() {
+ return null;
+ }
+}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/renderstates/QuadColorRectRenderState.java b/src/main/java/com/tanishisherewith/dynamichud/renderstates/QuadColorRectRenderState.java
new file mode 100644
index 0000000..4921a73
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/renderstates/QuadColorRectRenderState.java
@@ -0,0 +1,42 @@
+package com.tanishisherewith.dynamichud.renderstates;
+
+import com.mojang.blaze3d.pipeline.RenderPipeline;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import net.minecraft.client.gui.render.TextureSetup;
+import net.minecraft.client.gui.render.state.GuiElementRenderState;
+import org.joml.Matrix3x2f;
+import org.jspecify.annotations.Nullable;
+
+import java.awt.*;
+
+public record QuadColorRectRenderState(
+ RenderPipeline pipeline,
+ Matrix3x2f pose,
+ float x,
+ float y,
+ float width,
+ float height,
+ int[] color,
+ ScreenRectangle bounds,
+ ScreenRectangle scissorArea
+) implements GuiElementRenderState {
+
+ @Override
+ public void buildVertices(VertexConsumer vertices) {
+ vertices.addVertexWith2DPose(this.pose(),x, y).setColor(this.color[1]);
+ vertices.addVertexWith2DPose(this.pose(), x, y + height).setColor(this.color[2]);
+ vertices.addVertexWith2DPose(this.pose(), x + width, y + height).setColor(this.color[3]);
+ vertices.addVertexWith2DPose(this.pose(), x + width, y).setColor(this.color[0]);
+ }
+
+ @Override
+ public TextureSetup textureSetup() {
+ return TextureSetup.noTexture();
+ }
+
+ @Override
+ public @Nullable ScreenRectangle bounds() {
+ return this.scissorArea != null ? this.scissorArea.intersection(bounds) : this.bounds;
+ }
+}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/renderstates/RoundedRectRenderState.java b/src/main/java/com/tanishisherewith/dynamichud/renderstates/RoundedRectRenderState.java
new file mode 100644
index 0000000..01a6788
--- /dev/null
+++ b/src/main/java/com/tanishisherewith/dynamichud/renderstates/RoundedRectRenderState.java
@@ -0,0 +1,57 @@
+package com.tanishisherewith.dynamichud.renderstates;
+
+import com.mojang.blaze3d.pipeline.RenderPipeline;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import com.tanishisherewith.dynamichud.internal.IBufferBuilder;
+import com.tanishisherewith.dynamichud.utils.CustomRenderLayers;
+import net.minecraft.client.gui.navigation.ScreenRectangle;
+import net.minecraft.client.gui.render.TextureSetup;
+import net.minecraft.client.gui.render.state.GuiElementRenderState;
+import org.jetbrains.annotations.Nullable;
+import org.joml.Matrix3x2fc;
+import org.joml.Vector4f;
+import org.jspecify.annotations.NonNull;
+
+public record RoundedRectRenderState(
+ RenderPipeline pipeline,
+ Matrix3x2fc pose,
+ float x,
+ float y,
+ float width,
+ float height,
+ float thickness,
+ int[] colors,
+ Vector4f roundness,
+ @Nullable ScreenRectangle scissorArea,
+ @Nullable ScreenRectangle bounds
+) implements GuiElementRenderState {
+
+ @Override
+ public void buildVertices(@NonNull VertexConsumer consumer) {
+ if (consumer instanceof IBufferBuilder builder) {
+ float[][] uvs = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
+ float[][] coords = {{x, y}, {x, y + height}, {x + width, y + height}, {x + width, y}};
+
+ for (int i = 0; i < 4; i++) {
+ consumer.addVertexWith2DPose(pose, coords[i][0], coords[i][1])
+ .setColor(colors[i % colors.length])
+ .setUv(uvs[i][0], uvs[i][1]);
+
+ builder.dynamicHUD$writeGenericFloats(CustomRenderLayers.ELM_WIDTH_HEIGHT, width, height);
+
+ builder.dynamicHUD$writeGenericFloats(CustomRenderLayers.ELM_ROUNDNESS,
+ roundness.x, roundness.y, roundness.z, roundness.w);
+ }
+ }
+ }
+
+ @Override
+ public TextureSetup textureSetup() {
+ return TextureSetup.noTexture();
+ }
+
+ @Override
+ public @org.jspecify.annotations.Nullable ScreenRectangle bounds() {
+ return this.scissorArea != null ? this.scissorArea.intersection(this.bounds) : this.bounds;
+ }
+}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java b/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java
index 55ad285..5dcf628 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/screens/AbstractMoveableScreen.java
@@ -1,12 +1,19 @@
package com.tanishisherewith.dynamichud.screens;
import com.tanishisherewith.dynamichud.config.GlobalConfig;
+import com.tanishisherewith.dynamichud.utils.Util;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuManager;
import com.tanishisherewith.dynamichud.widget.Widget;
import com.tanishisherewith.dynamichud.widget.WidgetRenderer;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.text.Text;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.client.input.CharacterEvent;
+import net.minecraft.client.input.KeyEvent;
+import net.minecraft.client.input.MouseButtonEvent;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.entity.vehicle.minecart.Minecart;
+import org.jspecify.annotations.NonNull;
import org.lwjgl.glfw.GLFW;
public abstract class AbstractMoveableScreen extends Screen {
@@ -15,7 +22,7 @@ public abstract class AbstractMoveableScreen extends Screen {
/**
* Constructs a AbstractMoveableScreen object.
*/
- public AbstractMoveableScreen(Text title, WidgetRenderer renderer) {
+ public AbstractMoveableScreen(Component title, WidgetRenderer renderer) {
super(title);
this.widgetRenderer = renderer;
}
@@ -26,92 +33,95 @@ protected void init() {
}
@Override
- public void onDisplayed() {
- super.onDisplayed();
+ public void added() {
+ super.added();
widgetRenderer.isInEditor = true;
}
@Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- widgetRenderer.mouseDragged(mouseX, mouseY, button, deltaX, deltaY, GlobalConfig.get().getSnapSize());
- ContextMenuManager.getInstance().mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
- return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
+ public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) {
+ widgetRenderer.mouseDragged(event.x(), event.y(), event.button(),
+ dx, dy,
+ GlobalConfig.get().getSnapSize());
+ ContextMenuManager.getInstance().mouseDragged(event.x(), event.y(), event.button(),
+ dx, dy);
+ return super.mouseDragged(event, dx, dy);
}
@Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- if (widgetRenderer.mouseClicked(mouseX, mouseY, button)) {
- handleClickOnWidget(widgetRenderer.selectedWidget, mouseX, mouseY, button);
+ public boolean mouseClicked(MouseButtonEvent event, boolean bl) {
+ if (widgetRenderer.mouseClicked(event.x(), event.y(), event.button())) {
+ handleClickOnWidget(widgetRenderer.selectedWidget, event.x(), event.y(), event.button());
}
- ContextMenuManager.getInstance().mouseClicked(mouseX, mouseY, button);
- return super.mouseClicked(mouseX, mouseY, button);
+ ContextMenuManager.getInstance().mouseClicked(event.x(), event.y(), event.button());
+ return super.mouseClicked(event, bl);
}
@Override
- public boolean charTyped(char chr, int modifiers) {
- widgetRenderer.charTyped(chr, modifiers);
- ContextMenuManager.getInstance().charTyped(chr, modifiers);
- return super.charTyped(chr, modifiers);
+ public boolean charTyped(CharacterEvent event) {
+ widgetRenderer.charTyped((char) event.codepoint(), event.modifiers());
+ ContextMenuManager.getInstance().charTyped((char) event.codepoint(), event.modifiers());
+ return super.charTyped(event);
}
@Override
- public boolean mouseReleased(double mouseX, double mouseY, int button) {
- widgetRenderer.mouseReleased(mouseX, mouseY, button);
- ContextMenuManager.getInstance().mouseReleased(mouseX, mouseY, button);
- return super.mouseReleased(mouseX, mouseY, button);
+ public boolean mouseReleased(MouseButtonEvent event) {
+ widgetRenderer.mouseReleased(event.x(), event.y(), event.button());
+ ContextMenuManager.getInstance().mouseReleased(event.x(), event.y(), event.button());
+ return super.mouseReleased(event);
}
@Override
- public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
- widgetRenderer.keyPressed(keyCode, scanCode, modifiers);
- ContextMenuManager.getInstance().keyPressed(keyCode, scanCode, modifiers);
- if (widgetRenderer.selectedWidget != null && (keyCode == GLFW.GLFW_KEY_DELETE || keyCode == GLFW.GLFW_KEY_BACKSPACE)) {
- // trayWidget.minimizeWidget(widgetRenderer.selectedWidget);
+ public boolean keyPressed(KeyEvent event) {
+ widgetRenderer.keyPressed(event.key(), event.scancode(), event.modifiers());
+ ContextMenuManager.getInstance().keyPressed(event.key(), event.scancode(), event.modifiers());
+ if (widgetRenderer.selectedWidget != null &&
+ (event.key() == GLFW.GLFW_KEY_DELETE || event.key() == GLFW.GLFW_KEY_BACKSPACE)) {
+ // trayWidget.minimizeWidget(widgetRenderer.selectedWidget);
}
-
- return super.keyPressed(keyCode, scanCode, modifiers);
+ return super.keyPressed(event);
}
@Override
- public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
- widgetRenderer.keyReleased(keyCode, scanCode, modifiers);
- ContextMenuManager.getInstance().keyReleased(keyCode, scanCode, modifiers);
- return super.keyReleased(keyCode, scanCode, modifiers);
+ public boolean keyReleased(KeyEvent event) {
+ widgetRenderer.keyReleased(event.key(), event.scancode(), event.modifiers());
+ ContextMenuManager.getInstance().keyReleased(event.key(), event.scancode(), event.modifiers());
+ return super.keyReleased(event);
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
- widgetRenderer.mouseScrolled(mouseX, mouseY, verticalAmount, horizontalAmount);
- ContextMenuManager.getInstance().mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
- return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
+ public boolean mouseScrolled(double x, double y, double horizontalAmount, double verticalAmount) {
+ widgetRenderer.mouseScrolled(x, y, verticalAmount, horizontalAmount);
+ ContextMenuManager.getInstance().mouseScrolled(x, y, horizontalAmount, verticalAmount);
+ return super.mouseScrolled(x, y, horizontalAmount, verticalAmount);
}
/**
* Renders this screen and its widgets on the screen.
*
- * @param drawContext The matrix stack used for rendering
+ * @param graphics The matrix stack used for rendering
* @param mouseX The current x position of the mouse cursor
* @param mouseY The current y position of the mouse cursor
* @param delta The time elapsed since the last frame in seconds
*/
@Override
- public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
- if (this.client.world == null) {
- renderInGameBackground(drawContext);
+ public void render(@NonNull GuiGraphics graphics, int mouseX, int mouseY, float delta) {
+ if (this.minecraft.level == null) {
+ renderBackground(graphics,mouseX,mouseY,delta);
}
- drawContext.drawText(client.textRenderer, title, client.getWindow().getScaledWidth() / 2 - client.textRenderer.getWidth(title.getString()) / 2, textRenderer.fontHeight / 2, -1, true);
+ graphics.drawCenteredString(this.font, this.title, this.width / 2, this.font.lineHeight / 2,-1);
// Draw each widget
- widgetRenderer.renderWidgets(drawContext, mouseX, mouseY);
+ widgetRenderer.renderWidgets(graphics, mouseX, mouseY);
- ContextMenuManager.getInstance().renderAll(drawContext, mouseX, mouseY);
+ ContextMenuManager.getInstance().renderAll(graphics, mouseX, mouseY);
if (GlobalConfig.get().shouldDisplayDescriptions()) {
for (Widget widget : widgetRenderer.getWidgets()) {
if (widget == null || widget.isShiftDown) continue;
if (widget.getWidgetBox().isMouseOver(mouseX, mouseY)) {
- drawContext.drawTooltip(client.textRenderer, widget.tooltipText, mouseX, mouseY);
+ graphics.setTooltipForNextFrame(this.font, widget.tooltipText, mouseX, mouseY);
break;
}
}
@@ -122,16 +132,15 @@ public void handleClickOnWidget(Widget widget, double mouseX, double mouseY, int
}
@Override
- public void close() {
+ public void onClose() {
widgetRenderer.isInEditor = false;
widgetRenderer.onCloseScreen();
ContextMenuManager.getInstance().onClose();
- super.close();
+ super.onClose();
}
@Override
- public boolean shouldPause() {
+ public boolean isPauseScreen() {
return false;
}
}
-
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/CustomRenderLayers.java b/src/main/java/com/tanishisherewith/dynamichud/utils/CustomRenderLayers.java
index df17c3d..5e395c3 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/CustomRenderLayers.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/CustomRenderLayers.java
@@ -3,94 +3,116 @@
import com.mojang.blaze3d.pipeline.BlendFunction;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.platform.DestFactor;
-import com.mojang.blaze3d.platform.LogicOp;
import com.mojang.blaze3d.platform.SourceFactor;
+import com.mojang.blaze3d.shaders.UniformType;
+import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormatElement;
-import com.tanishisherewith.dynamichud.internal.IRenderLayer;
-import net.minecraft.client.gl.RenderPipelines;
-import net.minecraft.client.gl.UniformType;
-import net.minecraft.client.render.RenderLayer;
-import net.minecraft.client.render.VertexFormats;
-import net.minecraft.client.util.math.Vector2f;
-import net.minecraft.util.Identifier;
-import net.minecraft.util.Util;
+import net.minecraft.client.renderer.RenderPipelines;
+import net.minecraft.resources.Identifier;
import org.joml.Vector4f;
-import java.awt.*;
-import java.util.function.Function;
public class CustomRenderLayers {
- public static RenderLayer QUADS_CUSTOM_BLEND = RenderLayer.of(
- "dynamichud/quads_custom_blend",
- 1536,
- false,
- true,
- RenderPipelines.register(RenderPipeline.builder(RenderPipelines.POSITION_COLOR_SNIPPET)
- .withLocation(Identifier.of("dynamichud", "pipeline/quad_custom_blend_func"))
- .withVertexFormat(VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.QUADS)
- .withBlend(new BlendFunction(SourceFactor.DST_ALPHA, DestFactor.ONE_MINUS_DST_ALPHA))
- .build()
- ),
- RenderLayer.MultiPhaseParameters.builder().build(false)
- );
+ public static final RenderPipeline COLOR_LINE = RenderPipeline.builder()
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "color_line"))
+ .withVertexFormat(DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.DEBUG_LINES)
+ .withFragmentShader(Identifier.withDefaultNamespace("position_color"))
+ .withVertexShader(Identifier.withDefaultNamespace("position_color"))
+ .build();
+
+ // Width/Height in UV1
+ public static final VertexFormatElement ELM_WIDTH_HEIGHT =
+ new VertexFormatElement(1, 2, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.UV, 8);
+
+ // Roundness in UV2
+ public static final VertexFormatElement ELM_ROUNDNESS =
+ new VertexFormatElement(2, 4, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.UV, 16);
+
+ public static final VertexFormat ROUNDED_FORMAT = VertexFormat.builder()
+ .add("Position", VertexFormatElement.POSITION)
+ .add("Color", VertexFormatElement.COLOR)
+ .add("UV0", VertexFormatElement.UV0)
+ .add("WidthHeight", ELM_WIDTH_HEIGHT)
+ .add("Roundness", ELM_ROUNDNESS)
+ .build();
+
- public static RenderLayer TRIANGLE_FAN_CUSTOM_BLEND = RenderLayer.of(
- "dynamichud/triangle_fan_custom_blend",
- 1536,
- false,
- true,
- RenderPipelines.register(RenderPipeline.builder(RenderPipelines.POSITION_COLOR_SNIPPET)
- .withLocation(Identifier.of("dynamichud", "pipeline/triangle_fan_custom_blend_func"))
- .withVertexFormat(VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.TRIANGLE_FAN)
- .withBlend(new BlendFunction(SourceFactor.DST_ALPHA, DestFactor.ONE_MINUS_DST_ALPHA))
+ public static final RenderPipeline ROUNDED_RECT = RenderPipelines.register(
+ RenderPipeline.builder()
+ .withVertexFormat(ROUNDED_FORMAT, VertexFormat.Mode.QUADS)
+ .withBlend(new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA))
+ .withFragmentShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded"))
+ .withVertexShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded"))
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "pipeline/rounded"))
+ .withUniform("Roundness", UniformType.UNIFORM_BUFFER)
+ .withUniform("widthHeight", UniformType.UNIFORM_BUFFER)
.build()
- ),
- RenderLayer.MultiPhaseParameters.builder().build(false)
);
- public static RenderLayer TRIANGLE_STRIP = RenderLayer.of(
- "dynamichud/triangle_strip",
- 1536,
- false,
- true,
- RenderPipelines.register(RenderPipeline.builder(RenderPipelines.POSITION_COLOR_SNIPPET)
- .withLocation(Identifier.of("dynamichud", "pipeline/triangle_strip"))
- .withVertexFormat(VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.TRIANGLE_STRIP)
- .withBlend(BlendFunction.TRANSLUCENT)
+
+ public static final RenderPipeline ROUNDED_RECT_OUTLINE = RenderPipelines.register(
+ RenderPipeline.builder()
+ .withVertexFormat(ROUNDED_FORMAT, VertexFormat.Mode.QUADS)
+ .withBlend(new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA))
+ .withFragmentShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded_outline"))
+ .withVertexShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded"))
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "pipeline/rounded_outline"))
+ .withUniform("Roundness", UniformType.UNIFORM_BUFFER)
+ .withUniform("widthHeight", UniformType.UNIFORM_BUFFER)
+ .withUniform("Thickness", UniformType.UNIFORM_BUFFER)
.build()
- ),
- RenderLayer.MultiPhaseParameters.builder().build(false)
);
- private static final RenderPipeline ROUNDED = RenderPipelines.register(RenderPipeline.builder(RenderPipelines.MATRICES_COLOR_SNIPPET)
+ public static RenderPipeline QUADS_CUSTOM_BLEND = RenderPipelines.register(RenderPipeline.builder(RenderPipelines.GUI_SNIPPET)
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "pipeline/quad_custom_blend_func"))
+ .withVertexFormat(DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS)
+ .withBlend(new BlendFunction(SourceFactor.DST_ALPHA, DestFactor.ONE_MINUS_DST_ALPHA))
+ .build()
+ );
+
+ public static RenderPipeline TRIANGLE_FAN_CUSTOM_BLEND = RenderPipelines.register(RenderPipeline.builder(RenderPipelines.GUI_SNIPPET)
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "pipeline/triangle_fan_custom_blend_func"))
+ .withVertexFormat(DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.TRIANGLE_FAN)
+ .withBlend(new BlendFunction(SourceFactor.DST_ALPHA, DestFactor.ONE_MINUS_DST_ALPHA))
+ .build()
+ );
+ public static RenderPipeline TRIANGLE_STRIP = RenderPipelines.register(RenderPipeline.builder(RenderPipelines.GUI_SNIPPET)
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "pipeline/triangle_strip"))
+ .withVertexFormat(DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.TRIANGLE_STRIP)
+ .withBlend(BlendFunction.TRANSLUCENT)
+ .build()
+ );
+
+ /*
+ private static final RenderPipeline ROUNDED = RenderPipelines.register(RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET)
.withBlend(BlendFunction.TRANSLUCENT)
.withVertexFormat(VertexFormat.builder()
.add("Position", VertexFormatElement.POSITION)
.add("UV0", VertexFormatElement.UV0)
.add("Color", VertexFormatElement.COLOR)
- .build(), VertexFormat.DrawMode.QUADS)
+ .build(), VertexFormat.Mode.QUADS)
.withCull(true)
.withColorLogic(LogicOp.NONE)
- .withFragmentShader(Identifier.of("dynamichud", "core/rounded"))
- .withVertexShader(Identifier.of("dynamichud", "core/rounded"))
- .withLocation(Identifier.of("dynamichud", "pipeline/rounded"))
- .withUniform("Roundness", UniformType.VEC4)
- .withUniform("widthHeight", UniformType.VEC2)
+ .withFragmentShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded"))
+ .withVertexShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded"))
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "pipeline/rounded"))
+ .withUniform("Roundness", UniformType.UNIFORM_BUFFER)
+ .withUniform("widthHeight", UniformType.UNIFORM_BUFFER)
.build());
- private static final RenderPipeline ROUNDED_OUTLINE = RenderPipelines.register(RenderPipeline.builder(RenderPipelines.MATRICES_COLOR_SNIPPET)
+ private static final RenderPipeline ROUNDED_OUTLINE = RenderPipelines.register(RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET)
.withBlend(BlendFunction.TRANSLUCENT)
.withVertexFormat(VertexFormat.builder()
.add("Position", VertexFormatElement.POSITION)
.add("UV0", VertexFormatElement.UV0)
.add("Color", VertexFormatElement.COLOR)
- .build(), VertexFormat.DrawMode.QUADS)
+ .build(), VertexFormat.Mode.QUADS)
.withCull(true)
.withColorLogic(LogicOp.NONE)
- .withFragmentShader(Identifier.of("dynamichud", "core/rounded_outline"))
- .withVertexShader(Identifier.of("dynamichud", "core/rounded"))
- .withLocation(Identifier.of("dynamichud", "pipeline/rounded_outline"))
- .withUniform("Thickness", UniformType.VEC4)
+ .withFragmentShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded_outline"))
+ .withVertexShader(Identifier.fromNamespaceAndPath("dynamichud", "core/rounded"))
+ .withLocation(Identifier.fromNamespaceAndPath("dynamichud", "pipeline/rounded_outline"))
+ .withUniform("Thickness", UniformType)
.withUniform("Roundness", UniformType.VEC4)
.withUniform("widthHeight", UniformType.VEC2)
.build());
@@ -121,14 +143,15 @@ public class CustomRenderLayers {
.build(false)
);
((IRenderLayer) rl).dynamichud$setUniform("Roundness", params.roundness);
- ((IRenderLayer) rl).dynamichud$setUniform("Thickness", new Vector4f(params.thickness,0f,0f,0f));
+ ((IRenderLayer) rl).dynamichud$setUniform("Thickness", new Vector4f(params.thickness, 0f, 0f, 0f));
((IRenderLayer) rl).dynamichud$setUniform("widthHeight", params.widthHeight);
return rl;
});
+ */
private static int getNewVertexFormatElementsId() {
- for(int id = 0; id < 32; id++) {
+ for (int id = 0; id < 32; id++) {
if (VertexFormatElement.byId(id) == null) {
return id;
}
@@ -137,6 +160,9 @@ private static int getNewVertexFormatElementsId() {
}
- public record RoundedParameters(Vector4f roundness, float[] widthHeight){}
- public record OutlineParameters(Vector4f roundness, float thickness, float[] widthHeight){}
+ public record RoundedParameters(Vector4f roundness, float[] widthHeight) {
+ }
+
+ public record OutlineParameters(Vector4f roundness, float thickness, float[] widthHeight) {
+ }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/Util.java b/src/main/java/com/tanishisherewith/dynamichud/utils/Util.java
index 4210d61..c6ae850 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/Util.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/Util.java
@@ -4,8 +4,8 @@
public class Util {
public static Quadrant getQuadrant(int x, int y) {
- int screenWidth = DynamicHUD.MC.getWindow().getScaledWidth();
- int screenHeight = DynamicHUD.MC.getWindow().getScaledHeight();
+ int screenWidth = DynamicHUD.MC.getWindow().getGuiScaledWidth();
+ int screenHeight = DynamicHUD.MC.getWindow().getGuiScaledHeight();
if (x < screenWidth / 2) {
if (y < screenHeight / 2) {
@@ -35,4 +35,8 @@ public static boolean warnIfTrue(boolean expression, String message, Object... o
if (expression) DynamicHUD.logger.warn(message, objects);
return expression;
}
+
+ public static boolean isSafeToContinue() {
+ return DynamicHUD.MC.getWindow() != null && DynamicHUD.MC.font != null;
+ }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java
index 48a2cf6..65da6a9 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenu.java
@@ -9,9 +9,8 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.DefaultContextMenuScreenFactory;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
import com.tanishisherewith.dynamichud.widget.WidgetBox;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.util.math.MathHelper;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.screens.Screen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
@@ -72,7 +71,7 @@ public void addOption(Option> option) {
options.add(option);
}
- public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
+ public void render(GuiGraphics graphics, int x, int y, int mouseX, int mouseY) {
if (newScreenFlag && screenFactory != null) {
DynamicHUD.MC.setScreen(screenFactory.create(this, properties));
return;
@@ -83,12 +82,12 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY
update();
if (scale <= 0.0f || newScreenFlag) return;
- DrawHelper.scaleAndPosition(drawContext.getMatrices(), x, y, scale);
+ DrawHelper.scaleAndPosition(graphics.pose(), x, y, scale);
properties.getSkin().setContextMenu(this);
- properties.getSkin().renderContextMenu(drawContext, this, mouseX, mouseY);
+ properties.getSkin().renderContextMenu(graphics, this, mouseX, mouseY);
- DrawHelper.stopScaling(drawContext.getMatrices());
+ DrawHelper.stopScaling(graphics.pose());
}
public void update() {
@@ -104,7 +103,7 @@ public void update() {
scale -= 0.1f;
}
- scale = MathHelper.clamp(scale, 0, 1.0f);
+ scale = Math.clamp(scale, 0, 1.0f);
}
public void close() {
@@ -121,7 +120,7 @@ public void close() {
public void open() {
shouldDisplay = true;
update();
- parentScreen = DynamicHUD.MC.currentScreen;
+ parentScreen = DynamicHUD.MC.screen;
if (properties.getSkin().shouldCreateNewScreen()) {
newScreenFlag = true;
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java
index 70edde9..c2b05f7 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuManager.java
@@ -1,7 +1,7 @@
package com.tanishisherewith.dynamichud.utils.contextmenu;
import com.tanishisherewith.dynamichud.utils.Input;
-import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.GuiGraphics;
import java.util.ArrayList;
import java.util.List;
@@ -21,11 +21,11 @@ public void registerProvider(ContextMenuProvider provider) {
providers.add(provider);
}
- public void renderAll(DrawContext drawContext, int mouseX, int mouseY) {
+ public void renderAll(GuiGraphics graphics, int mouseX, int mouseY) {
for (ContextMenuProvider provider : providers) {
ContextMenu> contextMenu = provider.getContextMenu();
if (contextMenu != null) {
- contextMenu.render(drawContext, contextMenu.getX(), contextMenu.getY(), mouseX, mouseY);
+ contextMenu.render(graphics, contextMenu.getX(), contextMenu.getY(), mouseX, mouseY);
}
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java
index 1ccfce4..eeba531 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreen.java
@@ -3,35 +3,37 @@
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.text.Text;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.client.input.KeyEvent;
+import net.minecraft.client.input.MouseButtonEvent;
+import net.minecraft.network.chat.Component;
public class ContextMenuScreen extends Screen {
ContextMenu> contextMenu;
ContextMenuProperties properties;
protected ContextMenuScreen(ContextMenu> menu, ContextMenuProperties properties) {
- super(Text.of("ContextMenu screen"));
+ super(Component.literal("ContextMenu screen"));
this.contextMenu = menu;
this.properties = properties;
}
@Override
- public void onDisplayed() {
- super.onDisplayed();
+ public void added() {
+ super.added();
contextMenu.setVisible(true);
}
@Override
- public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
+ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
contextMenu.update();
- DrawHelper.scaleAndPosition(drawContext.getMatrices(), (float) width / 2, (float) height / 2, contextMenu.getScale());
+ DrawHelper.scaleAndPosition(graphics.pose(), (float) width / 2, (float) height / 2, contextMenu.getScale());
properties.getSkin().setContextMenu(contextMenu);
- properties.getSkin().renderContextMenu(drawContext, contextMenu, mouseX, mouseY);
+ properties.getSkin().renderContextMenu(graphics, contextMenu, mouseX, mouseY);
- DrawHelper.stopScaling(drawContext.getMatrices());
+ DrawHelper.stopScaling(graphics.pose());
if (contextMenu.getScale() <= 0 && !contextMenu.isVisible()) {
contextMenu.close();
@@ -39,48 +41,48 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
}
@Override
- protected void renderDarkening(DrawContext context) {
+ public void renderBackground(GuiGraphics guiGraphics, int i, int j, float f) {
}
@Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- contextMenu.mouseClicked(mouseX, mouseY, button);
- return super.mouseClicked(mouseX, mouseY, button);
+ public boolean mouseClicked(MouseButtonEvent event, boolean bl) {
+ contextMenu.mouseClicked(event.x(), event.y(), event.button());
+ return super.mouseClicked(event, bl);
}
@Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- contextMenu.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
- return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
+ public boolean mouseDragged(MouseButtonEvent event, double dx, double dy) {
+ contextMenu.mouseDragged(event.x(), event.y(), event.button(), dx, dy);
+ return super.mouseDragged(event, dx, dy);
}
@Override
- public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
- contextMenu.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
- return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
+ public boolean mouseScrolled(double x, double y, double horizontalAmount, double verticalAmount) {
+ contextMenu.mouseScrolled(x, y, horizontalAmount, verticalAmount);
+ return super.mouseScrolled(x, y, horizontalAmount, verticalAmount);
}
@Override
- public boolean mouseReleased(double mouseX, double mouseY, int button) {
- contextMenu.mouseReleased(mouseX, mouseY, button);
- return super.mouseReleased(mouseX, mouseY, button);
+ public boolean mouseReleased(MouseButtonEvent event) {
+ contextMenu.mouseReleased(event.x(), event.y(), event.button());
+ return super.mouseReleased(event);
}
@Override
- public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
- contextMenu.keyReleased(keyCode, scanCode, modifiers);
- return super.keyReleased(keyCode, scanCode, modifiers);
+ public boolean keyReleased(KeyEvent event) {
+ contextMenu.keyReleased(event.key(), event.scancode(), event.modifiers());
+ return super.keyReleased(event);
}
@Override
- public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
- contextMenu.keyPressed(keyCode, scanCode, modifiers);
- return super.keyPressed(keyCode, scanCode, modifiers);
+ public boolean keyPressed(KeyEvent event) {
+ contextMenu.keyPressed(event.key(), event.scancode(), event.modifiers());
+ return super.keyPressed(event);
}
@Override
- public void close() {
+ public void onClose() {
contextMenu.close();
contextMenu.setVisible(false);
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenFactory.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenFactory.java
index 6dea3ec..b66b0c7 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenFactory.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenFactory.java
@@ -2,7 +2,7 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
-import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screens.Screen;
/**
* We will use this interface to provide the context menu with the screen required by its skins.
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenRegistry.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenRegistry.java
index 3bd3646..3e8ee1d 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenRegistry.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/ContextMenuScreenRegistry.java
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen;
-import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screens.Screen;
public class ContextMenuScreenRegistry {
public Class extends Screen> screenKlass;
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/DefaultContextMenuScreenFactory.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/DefaultContextMenuScreenFactory.java
index b156347..1b0bbc9 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/DefaultContextMenuScreenFactory.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/contextmenuscreen/DefaultContextMenuScreenFactory.java
@@ -2,7 +2,7 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
-import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screens.Screen;
/**
* Default implementation of the {@link ContextMenuScreenFactory} providing a {@link ContextMenuScreen}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java
index fb3d782..a20ce5f 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutContext.java
@@ -3,27 +3,11 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option;
//This was supposed to be used for something bigger but that got scraped.
-public class LayoutContext {
- private final Offset indent;
- private final Option> parentOption;
-
+public record LayoutContext(Offset indent, Option> parentOption) {
public LayoutContext() {
this(Offset.zero(), null);
}
- public LayoutContext(Offset margin, Option> parentOption) {
- this.indent = margin;
- this.parentOption = parentOption;
- }
-
- public Offset getIndent() {
- return indent;
- }
-
- public Option> getParentOption() {
- return parentOption;
- }
-
// Builder-style methods for creating new contexts
public LayoutContext withIndent(Offset indent) {
return new LayoutContext(indent, this.parentOption);
@@ -57,28 +41,20 @@ public int getEffectiveHeight(int baseHeight) {
return baseHeight + indent.top;
}
- public static class Offset {
- public final int left;
- public final int top;
-
- public Offset(int all) {
- this(all, all);
- }
-
- public Offset(int horizontal, int vertical) {
- this.left = horizontal;
- this.top = vertical;
- }
+ public record Offset(int left, int top) {
+ public Offset(int all) {
+ this(all, all);
+ }
public static Offset zero() {
- return new Offset(0);
+ return new Offset(0);
+ }
+
+ public Offset add(Offset other) {
+ return new Offset(
+ this.left + other.left,
+ this.top + other.top
+ );
+ }
}
-
- public Offset add(Offset other) {
- return new Offset(
- this.left + other.left,
- this.top + other.top
- );
- }
- }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java
index d5f3b55..a4764d8 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/BooleanOption.java
@@ -1,8 +1,8 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
import com.tanishisherewith.dynamichud.utils.BooleanPool;
-import net.minecraft.screen.ScreenTexts;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.CommonComponents;
+import net.minecraft.network.chat.Component;
import org.lwjgl.glfw.GLFW;
import java.util.function.Consumer;
@@ -12,21 +12,21 @@
public class BooleanOption extends Option {
private final BooleanType booleanType;
- public BooleanOption(Text name, Supplier getter, Consumer setter, BooleanType booleanType) {
+ public BooleanOption(Component name, Supplier getter, Consumer setter, BooleanType booleanType) {
super(name, getter, setter);
this.booleanType = booleanType;
this.renderer.init(this);
}
- public BooleanOption(Text name, Supplier getter, Consumer setter) {
+ public BooleanOption(Component name, Supplier getter, Consumer setter) {
this(name, getter, setter, BooleanType.TRUE_FALSE);
}
- public BooleanOption(Text name, boolean defaultValue) {
+ public BooleanOption(Component name, boolean defaultValue) {
this(name, defaultValue, BooleanType.TRUE_FALSE);
}
- public BooleanOption(Text name, boolean defaultValue, BooleanType type) {
+ public BooleanOption(Component name, boolean defaultValue, BooleanType type) {
this(name, () -> BooleanPool.get(name.getString()), value -> BooleanPool.put(name.getString(), value), type);
BooleanPool.put(name.getString(), defaultValue);
}
@@ -46,17 +46,17 @@ public BooleanType getBooleanType() {
}
public enum BooleanType {
- ON_OFF(ScreenTexts::onOrOff),
- TRUE_FALSE(aBoolean -> aBoolean ? Text.of("True") : Text.of("False")),
- YES_NO(aBoolean -> aBoolean ? ScreenTexts.YES : ScreenTexts.NO);
+ ON_OFF(aBoolean -> aBoolean ? CommonComponents.OPTION_ON : CommonComponents.OPTION_OFF),
+ TRUE_FALSE(aBoolean -> aBoolean ? Component.literal("True") : Component.literal("False")),
+ YES_NO(aBoolean -> aBoolean ? CommonComponents.GUI_YES : CommonComponents.GUI_NO);
- private final Function function;
+ private final Function function;
- BooleanType(Function function) {
+ BooleanType(Function function) {
this.function = function;
}
- public Text getText(boolean val) {
+ public Component getText(boolean val) {
return function.apply(val);
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java
index 9471f7c..c0f341d 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ColorOption.java
@@ -2,7 +2,7 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption.ColorGradient;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
import java.awt.*;
import java.util.function.Consumer;
@@ -13,7 +13,7 @@ public class ColorOption extends Option {
private ContextMenu> parentMenu = null;
private ColorGradient colorGradient = null;
- public ColorOption(Text name, Supplier getter, Consumer setter, ContextMenu> parentMenu) {
+ public ColorOption(Component name, Supplier getter, Consumer setter, ContextMenu> parentMenu) {
super(name, getter, setter);
this.parentMenu = parentMenu;
this.colorGradient = new ColorGradient(x + this.parentMenu.getWidth(), y - 10, get(), this::set, 50, 100);
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java
index 27d8ec6..14208f4 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/DoubleOption.java
@@ -2,8 +2,8 @@
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.text.Text;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.Validate;
import org.lwjgl.glfw.GLFW;
@@ -18,7 +18,7 @@ public class DoubleOption extends Option {
ContextMenu> parentMenu;
private boolean isDragging = false;
- public DoubleOption(Text name, double minValue, double maxValue, float step, Supplier getter, Consumer setter, ContextMenu> parentMenu) {
+ public DoubleOption(Component name, double minValue, double maxValue, float step, Supplier getter, Consumer setter, ContextMenu> parentMenu) {
super(name, getter, setter);
this.value = get();
this.minValue = minValue;
@@ -31,10 +31,10 @@ public DoubleOption(Text name, double minValue, double maxValue, float step, Sup
this.renderer.init(this);
}
- public void drawSlider(DrawContext drawContext, int sliderX, int sliderY, int sliderWidth, double handleX) {
- DrawHelper.drawRectangle(drawContext, sliderX, sliderY, sliderWidth, 2, 0xFFFFFFFF);
+ public void drawSlider(GuiGraphics graphics, int sliderX, int sliderY, int sliderWidth, double handleX) {
+ DrawHelper.drawRectangle(graphics, sliderX, sliderY, sliderWidth, 2, 0xFFFFFFFF);
if (handleX - sliderX > 0) {
- DrawHelper.drawRectangle(drawContext, (float) sliderX, (float) sliderY, (float) ((value - minValue) / (maxValue - minValue) * (width - 3)), 2, Color.ORANGE.getRGB());
+ DrawHelper.drawRectangle(graphics, (float) sliderX, (float) sliderY, (float) ((value - minValue) / (maxValue - minValue) * (width - 3)), 2, Color.ORANGE.getRGB());
}
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java
index 1eab358..f71cee2 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/EnumOption.java
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -9,7 +9,7 @@ public class EnumOption> extends Option {
private final E[] values;
private int currentIndex = 0;
- public EnumOption(Text name, Supplier getter, Consumer setter, E[] values) {
+ public EnumOption(Component name, Supplier getter, Consumer setter, E[] values) {
super(name, getter, setter);
this.values = values;
this.value = get();
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java
index d407242..d948664 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/ListOption.java
@@ -1,6 +1,6 @@
package com.tanishisherewith.dynamichud.utils.contextmenu.options;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
import java.util.List;
import java.util.function.Consumer;
@@ -10,7 +10,7 @@ public class ListOption extends Option {
private final List values;
private int currentIndex = 0;
- public ListOption(Text name, Supplier getter, Consumer setter, List values) {
+ public ListOption(Component name, Supplier getter, Consumer setter, List values) {
super(name, getter, setter);
this.values = values;
this.value = getter.get();
diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java
index be4bf94..137b4c6 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java
@@ -5,15 +5,15 @@
import com.tanishisherewith.dynamichud.utils.Input;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.text.Text;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.network.chat.Component;
import java.util.function.Consumer;
import java.util.function.Supplier;
public abstract class Option implements Input {
- public Text name, description = Text.empty();
+ public Component name, description = Component.empty();
public T value = null;
protected int x, y;
protected int width = 0;
@@ -22,16 +22,16 @@ public abstract class Option implements Input {
protected Supplier getter;
protected Consumer setter;
protected T defaultValue = null;
- protected MinecraftClient mc = MinecraftClient.getInstance();
+ protected Minecraft mc = Minecraft.getInstance();
protected ContextMenuProperties properties;
protected SkinRenderer
*
- * @param context DrawContext Object
+ * @param graphics GuiGraphics Object
* @param mouseX X position of mouse.
* @param mouseY Y position of mouse
*/
- public abstract void renderWidget(DrawContext context, int mouseX, int mouseY);
+ public abstract void renderWidget(GuiGraphics graphics, int mouseX, int mouseY);
/**
* Renders the widget in the editor screen with a background.
* Override this method without super call to remove the background.
* Could also be used to display placeholder values.
*/
- private void renderWidgetInEditor(DrawContext context, int mouseX, int mouseY) {
- //drawWidgetBackground(context);
+ private void renderWidgetInEditor(GuiGraphics graphics, int mouseX, int mouseY) {
+ //drawWidgetBackground(graphics);
- renderWidget(context, mouseX, mouseY);
+ renderWidget(graphics, mouseX, mouseY);
}
@Override
@@ -233,8 +232,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
/* Input related methods. Override with **super call** to add your own input-based code like contextMenu */
public void clampPosition() {
- this.x = (int) MathHelper.clamp(this.x, 0, mc.getWindow().getScaledWidth() - getWidth());
- this.y = (int) MathHelper.clamp(this.y, 0, mc.getWindow().getScaledHeight() - getHeight());
+ this.x = (int) org.joml.Math.clamp(this.x, 0, mc.getWindow().getGuiScaledWidth() - getWidth());
+ this.y = (int) org.joml.Math.clamp(this.y, 0, mc.getWindow().getGuiScaledHeight() - getHeight());
}
@Override
@@ -252,8 +251,8 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del
// Higher the snapSize, more the grid boxes
if (this.isShiftDown) {
// Calculate the size of each snap box
- int snapBoxWidth = mc.getWindow().getScaledWidth() / snapSize;
- int snapBoxHeight = mc.getWindow().getScaledHeight() / snapSize;
+ int snapBoxWidth = mc.getWindow().getGuiScaledWidth() / snapSize;
+ int snapBoxHeight = mc.getWindow().getGuiScaledHeight() / snapSize;
// Calculate the index of the snap box that the new position would be in and
// snap the new position to the top-left corner of the snap box
@@ -261,10 +260,10 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del
newY = (newY / snapBoxHeight) * snapBoxHeight;
}
- this.x = (int) MathHelper.clamp(newX, 0, mc.getWindow().getScaledWidth() - getWidth());
- this.y = (int) MathHelper.clamp(newY, 0, mc.getWindow().getScaledHeight() - getHeight());
+ this.x = (int) org.joml.Math.clamp(newX, 0, mc.getWindow().getGuiScaledWidth() - getWidth());
+ this.y = (int) org.joml.Math.clamp(newY, 0, mc.getWindow().getGuiScaledHeight() - getHeight());
- calculateOffset(x, y, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); // Set initial offset
+ calculateOffset(x, y, mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight()); // Set initial offset
return true;
}
@@ -311,11 +310,11 @@ public void onClose() {
* Displays a faint grayish background if enabled or faint reddish background if disabled.
* Drawn with 2 pixel offset to all sides
*/
- protected void drawWidgetBackground(DrawContext context) {
+ protected void drawWidgetBackground(GuiGraphics graphics) {
int backgroundColor = this.isVisible() ? GlobalConfig.get().getHudActiveColor().getRGB() : GlobalConfig.get().getHudInactiveColor().getRGB();
WidgetBox box = this.getWidgetBox();
- DrawHelper.drawRectangle(context,
+ DrawHelper.drawRectangle(graphics,
box.x,
box.y,
box.getWidth(),
@@ -324,13 +323,13 @@ protected void drawWidgetBackground(DrawContext context) {
}
/**
- * Set the tooltip text of the widget
+ * Set the tooltip Component of the widget
*/
- protected void setTooltipText(Text text) {
- this.tooltipText = text;
+ protected void setTooltipText(Component Component) {
+ this.tooltipText = Component;
}
- public void readFromTag(NbtCompound tag) {
+ public void readFromTag(CompoundTag tag) {
modId = tag.getString("modId").orElse("unknown");
uid = tag.contains("UID") ? new UID(tag.getString("UID").get()) : UID.generate();
// x = tag.getInt("x");
@@ -348,7 +347,7 @@ public void readFromTag(NbtCompound tag) {
*
* @param tag The tag to write to
*/
- public void writeToTag(NbtCompound tag) {
+ public void writeToTag(CompoundTag tag) {
tag.putString("name", DATA.name());
tag.putString("modId", modId);
tag.putString("UID", uid.getUniqueID());
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
index 1f0f05e..1e1aab6 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetManager.java
@@ -2,10 +2,9 @@
import com.tanishisherewith.dynamichud.DynamicHUD;
import com.tanishisherewith.dynamichud.mixins.ScreenMixin;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.nbt.NbtElement;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtIo;
-import net.minecraft.nbt.NbtList;
import java.io.DataOutputStream;
import java.io.File;
@@ -128,8 +127,8 @@ public static void onScreenResized(int newWidth, int newHeight, int previousWidt
* @param file The file to save to
*/
public static void saveWidgets(File file, List widgets) throws IOException {
- NbtCompound rootTag = new NbtCompound();
- NbtList widgetList = new NbtList();
+ CompoundTag rootTag = new CompoundTag();
+ ListTag widgetList = new ListTag();
printInfo("Saving widgets");
@@ -140,7 +139,7 @@ public static void saveWidgets(File file, List widgets) throws IOExcepti
Set widgetSet = new HashSet<>();
for (Widget widget : widgets) {
- NbtCompound widgetTag = new NbtCompound();
+ CompoundTag widgetTag = new CompoundTag();
//I faced this exception once and had to spend 10 minutes trying to find it. P.S. It leaves 0 stacktrace message
try {
widget.writeToTag(widgetTag);
@@ -190,20 +189,20 @@ public static List loadWidgets(File file) throws IOException {
file = new File(file.getAbsolutePath() + ".backup");
}
- NbtCompound rootTag = NbtIo.read(file.toPath());
+ CompoundTag rootTag = NbtIo.read(file.toPath());
if (rootTag == null) {
printWarn("RootTag is null. File is either empty or corrupted: " + file);
return Collections.emptyList();
}
- NbtList widgetList = rootTag.getList("widgets").orElse(null);
+ ListTag widgetList = rootTag.getList("widgets").orElse(null);
if (widgetList == null) {
printWarn("WidgetList is null. File is empty: " + file);
return Collections.emptyList();
}
List widgetsToAdd = new ArrayList<>();
for (int i = 0; i < widgetList.size(); i++) {
- NbtCompound widgetTag = widgetList.getCompound(i).orElse(null);
+ CompoundTag widgetTag = widgetList.getCompound(i).orElse(null);
if(widgetTag == null) continue;
WidgetData> widgetData = widgetDataMap.get(widgetTag.getString("name").orElse("unknown"));
if (widgetData == null) {
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java
index d0bc2f1..cd6df72 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widget/WidgetRenderer.java
@@ -6,10 +6,9 @@
import com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen;
import com.tanishisherewith.dynamichud.utils.Input;
import com.tanishisherewith.dynamichud.utils.contextmenu.contextmenuscreen.ContextMenuScreenRegistry;
-import dev.isxander.yacl3.gui.YACLScreen;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.screen.GameMenuScreen;
-import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.screens.PauseScreen;
+import net.minecraft.client.gui.screens.Screen;
import org.lwjgl.glfw.GLFW;
import java.util.List;
@@ -21,19 +20,19 @@ public class WidgetRenderer implements Input {
public Widget selectedWidget = null;
List widgets;
private boolean renderInGameHud = true;
- private int Z_Index = -1;
+ //private int Z_Index = -1;
/**
* Add the list of widgets the widgetRenderer should render
*
- * By default, it adds the {@link GameMenuScreen} to allow rendering of the widgets in the pause/main menu screen.
+ * By default, it adds the {@link PauseScreen} to allow rendering of the widgets in the pause/main menu screen.
*
* @param widgets List of widgets to render
*/
public WidgetRenderer(List widgets) {
this.widgets = widgets;
// Render in GameMenuScreen
- this.allowedScreens = screen -> screen.getClass() == GameMenuScreen.class ||
+ this.allowedScreens = screen -> screen.getClass() == PauseScreen.class ||
System.getInstances(ContextMenuScreenRegistry.class, DynamicHUD.MOD_ID).stream().anyMatch(registry -> registry.screenKlass == screen.getClass());
}
@@ -88,22 +87,22 @@ private boolean renderInDebugScreen() {
if (GlobalConfig.get().renderInDebugScreen()) {
return true;
}
- return !DynamicHUD.MC.getDebugHud().shouldShowDebugHud();
+ return !DynamicHUD.MC.getDebugOverlay().showDebugScreen();
}
- public void renderWidgets(DrawContext context, int mouseX, int mouseY) {
+ public void renderWidgets(GuiGraphics graphics, int mouseX, int mouseY) {
if (WidgetManager.getWidgets().isEmpty() || !renderInDebugScreen()) return;
- Screen currentScreen = DynamicHUD.MC.currentScreen;
+ Screen currentScreen = DynamicHUD.MC.screen;
- context.getMatrices().push();
- context.getMatrices().translate(0, 0, Z_Index);
+ // graphics.pose().pushMatrix();
+ // graphics.pose().translate(0, 0,Z_Index);
//Render in editing screen
if (currentScreen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
widget.isInEditor = true;
- widget.renderInEditor(context, mouseX, mouseY);
+ widget.renderInEditor(graphics, mouseX, mouseY);
}
return;
}
@@ -111,15 +110,15 @@ public void renderWidgets(DrawContext context, int mouseX, int mouseY) {
if ((currentScreen == null && renderInGameHud) || allowedScreens.test(currentScreen)) {
for (Widget widget : widgets) {
widget.isInEditor = false;
- widget.render(context, 0, 0);
+ widget.render(graphics, 0, 0);
}
}
- context.getMatrices().pop();
+ //graphics.pose().popMatrix();
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
- Screen currentScreen = DynamicHUD.MC.currentScreen;
+ Screen currentScreen = DynamicHUD.MC.screen;
if (currentScreen == null) {
return false;
}
@@ -139,7 +138,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
@Override
public void mouseScrolled(double mouseX, double mouseY, double vAmount, double hAmount) {
- Screen currentScreen = DynamicHUD.MC.currentScreen;
+ Screen currentScreen = DynamicHUD.MC.screen;
if (currentScreen == null) {
return;
}
@@ -155,7 +154,7 @@ public void charTyped(char c, int modifiers) {
}
public void onCloseScreen() {
- if (DynamicHUD.MC.currentScreen instanceof AbstractMoveableScreen) {
+ if (DynamicHUD.MC.screen instanceof AbstractMoveableScreen) {
for (Widget widget : widgets) {
widget.onClose();
}
@@ -168,7 +167,7 @@ public List getWidgets() {
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
- Screen currentScreen = DynamicHUD.MC.currentScreen;
+ Screen currentScreen = DynamicHUD.MC.screen;
if (currentScreen == null) {
return false;
}
@@ -186,7 +185,7 @@ public final boolean mouseDragged(double mouseX, double mouseY, int button, doub
}
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY, int snapSize) {
- Screen currentScreen = DynamicHUD.MC.currentScreen;
+ Screen currentScreen = DynamicHUD.MC.screen;
if (currentScreen == null) {
return false;
}
@@ -206,7 +205,7 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del
@Override
public void keyPressed(int key, int scanCode, int modifiers) {
- Screen currentScreen = DynamicHUD.MC.currentScreen;
+ Screen currentScreen = DynamicHUD.MC.screen;
if (currentScreen instanceof AbstractMoveableScreen && (key == GLFW.GLFW_KEY_LEFT_SHIFT || key == GLFW.GLFW_KEY_RIGHT_SHIFT)) {
for (Widget widget : widgets) {
widget.isShiftDown = true;
@@ -216,7 +215,7 @@ public void keyPressed(int key, int scanCode, int modifiers) {
@Override
public void keyReleased(int key, int scanCode, int modifiers) {
- Screen currentScreen = DynamicHUD.MC.currentScreen;
+ Screen currentScreen = DynamicHUD.MC.screen;
if (currentScreen instanceof AbstractMoveableScreen && (key == GLFW.GLFW_KEY_LEFT_SHIFT || key == GLFW.GLFW_KEY_RIGHT_SHIFT)) {
for (Widget widget : widgets) {
widget.isShiftDown = false;
@@ -224,8 +223,8 @@ public void keyReleased(int key, int scanCode, int modifiers) {
}
}
- public WidgetRenderer withZIndex(int z_Index) {
- this.Z_Index = z_Index;
- return this;
- }
+ // public WidgetRenderer withZIndex(int z_Index) {
+ // this.Z_Index = z_Index;
+ // return this;
+ // }
}
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/GraphWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/GraphWidget.java
index e2e0d44..574ae6c 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/GraphWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/GraphWidget.java
@@ -3,9 +3,11 @@
import com.tanishisherewith.dynamichud.config.GlobalConfig;
import com.tanishisherewith.dynamichud.helpers.ColorHelper;
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
-import com.tanishisherewith.dynamichud.helpers.animationhelper.animations.MathAnimations;
+import com.tanishisherewith.dynamichud.renderstates.GradientShadowRenderState;
+import com.tanishisherewith.dynamichud.renderstates.InterpolatedCurveRenderState;
import com.tanishisherewith.dynamichud.utils.CustomRenderLayers;
import com.tanishisherewith.dynamichud.utils.DynamicValueRegistry;
+import com.tanishisherewith.dynamichud.utils.Util;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuManager;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
@@ -18,12 +20,11 @@
import com.tanishisherewith.dynamichud.widget.WidgetBox;
import com.tanishisherewith.dynamichud.widget.WidgetData;
import com.twelvemonkeys.lang.Validate;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.render.VertexConsumer;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.text.Text;
-import net.minecraft.util.math.MathHelper;
-import org.joml.Matrix4f;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.render.TextureSetup;
+import net.minecraft.client.renderer.RenderPipelines;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.chat.Component;
import java.awt.*;
import java.util.ArrayList;
@@ -86,10 +87,11 @@ private void internal_init() {
this.widgetBox = new WidgetBox(x, y, (int) width, (int) height);
this.stepY = height / (gridLines + 1);
this.valueStep = (maxValue - minValue) / (gridLines + 1);
- this.scale = (float) MathHelper.clamp((stepY / 9.5), 0.0f, 1.0f);
+ this.scale = (float) Math.clamp((stepY / 9.5), 0.0f, 1.0f);
+
computeOffset();
- setTooltipText(Text.of("Graph displaying: " + label));
+ setTooltipText(Component.literal("Graph displaying: " + label));
}
public GraphWidget() {
@@ -126,7 +128,7 @@ public void addDataPoint(Float value) {
}
int index = (head) % maxDataPoints;
- dataPoints[index] = MathHelper.clamp(value, minValue, maxValue);
+ dataPoints[index] = Math.clamp(value, minValue, maxValue);
head = (head + 1) % maxDataPoints; // Buffer full, overwrite oldest and move head
}
@@ -161,53 +163,26 @@ private List getInterpolatedPoints() {
}
// draw a continuous interpolated curve
- private void drawInterpolatedCurve(DrawContext drawContext, List points, int color, float thickness) {
+ private void drawInterpolatedCurve(GuiGraphics graphics, List points, int color, float thickness) {
if (points.size() < 2) return;
- drawContext.draw(vcp -> {
- Matrix4f matrix = drawContext.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(CustomRenderLayers.TRIANGLE_STRIP);
-
- for (int i = 0; i < points.size(); i++) {
- float[] point = points.get(i);
- float x = point[0];
- float y = point[1];
-
- // Create a thick line by offsetting vertices perpendicular to the curve
- float dx = (i < points.size() - 1) ? points.get(i + 1)[0] - x : x - points.get(i - 1)[0];
- float dy = (i < points.size() - 1) ? points.get(i + 1)[1] - y : y - points.get(i - 1)[1];
- float length = (float) Math.sqrt(dx * dx + dy * dy);
- if (length == 0) continue;
-
- float offsetX = (thickness * 0.5f * dy) / length;
- float offsetY = (thickness * 0.5f * -dx) / length;
-
- consumer.vertex(matrix, x + offsetX, y + offsetY, 0).color(color);
- consumer.vertex(matrix, x - offsetX, y - offsetY, 0).color(color);
- }
- });
+ graphics.guiRenderState.submitGuiElement(
+ new InterpolatedCurveRenderState(points, thickness, color, graphics.pose(), CustomRenderLayers.QUADS_CUSTOM_BLEND, graphics.scissorStack.peek())
+ );
}
+
// draw a gradient shadow under the curve
- private void drawGradientShadow(DrawContext context, List points, float bottomY, int startColor, int endColor) {
+ private void drawGradientShadow(GuiGraphics graphics, List points, float bottomY, int startColor, int endColor) {
if (points.size() < 2) return;
- context.draw(vcp -> {
- Matrix4f matrix = context.getMatrices().peek().getPositionMatrix();
- VertexConsumer consumer = vcp.getBuffer(CustomRenderLayers.TRIANGLE_STRIP);
-
- for (float[] point : points) {
- float x = point[0];
- float y = point[1];
-
- consumer.vertex(matrix, x, y, 0).color(startColor);
- consumer.vertex(matrix, x, bottomY, 0).color(endColor);
- }
- });
+ graphics.guiRenderState.submitGuiElement(
+ new GradientShadowRenderState(points,bottomY, startColor, endColor, graphics.pose(), CustomRenderLayers.TRIANGLE_STRIP, graphics.scissorStack.peek())
+ );
}
@Override
- public void renderWidget(DrawContext context, int mouseX, int mouseY) {
+ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY) {
if (valueSupplier != null) {
addDataPoint(getValue());
}
@@ -217,12 +192,12 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY) {
if(graphColorRainbow) graphColor = ColorHelper.getRainbowColor(100);
- DrawHelper.enableScissor(widgetBox);
+ // DrawHelper.enableScissor(widgetBox);
// Draw gradient background with rounded.fsh corners
if (!isInEditor) {
DrawHelper.drawRoundedRectangle(
- context,
+ graphics,
x + offset,
y,
false,
@@ -242,18 +217,18 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY) {
for (int i = 1; i <= gridLines; i++) {
float yPos = y + stepY * i;
- DrawHelper.drawHorizontalLine(context, x + offset, width, yPos, 0.5f, 0x4DFFFFFF); // Semi-transparent white
+ DrawHelper.drawHorizontalLine(graphics, x + offset, width, yPos, 0.5f, 0x4DFFFFFF); // Semi-transparent white
// Draw value labels on the left axis
float value = maxValue - (i * valueStep);
String valueText = formatValue(value);
- float texWidth = mc.textRenderer.getWidth(valueText) * scale;
+ float texWidth = mc.font.width(valueText) * scale;
- //Scale the text to its proper position and size with grid lines
- DrawHelper.scaleAndPosition(context.getMatrices(), x - 2, yPos, scale);
- context.drawText(mc.textRenderer, valueText, Math.round(x + offset - texWidth), (int) (yPos - (mc.textRenderer.fontHeight * scale) / 2.0f), 0xFFFFFFFF, true);
- DrawHelper.stopScaling(context.getMatrices());
+ //Scale the Component to its proper position and size with grid lines
+ DrawHelper.scaleAndPosition(graphics.pose(), x - 2, yPos, scale);
+ graphics.drawString(mc.font, valueText, Math.round(x + offset - texWidth), (int) (yPos - (mc.font.lineHeight * scale) / 2.0f), 0xFFFFFFFF, true);
+ DrawHelper.stopScaling(graphics.pose());
}
// Update the offsets for the rest of the elements drawn.
@@ -263,50 +238,49 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY) {
float stepX = width / 5; // 5 vertical lines
for (int i = 1; i < 5; i++) {
float xPos = x + stepX * i;
- DrawHelper.drawVerticalLine(context, xPos, y, height, 0.5f, 0x4DFFFFFF);
+ DrawHelper.drawVerticalLine(graphics, xPos, y, height, 0.5f, 0x4DFFFFFF);
}
}
// Draw interpolated graph curve
List points = getInterpolatedPoints();
- drawInterpolatedCurve(context, points, graphColor.getRGB(), lineThickness);
+ drawInterpolatedCurve(graphics, points, graphColor.getRGB(), lineThickness);
// Draw shadow effect under the graph
drawGradientShadow(
- context, points, y + height,
+ graphics, points, y + height,
ColorHelper.changeAlpha(graphColor, 50).getRGB(),
0x00000000
);
-
DrawHelper.drawChromaText(
- context, label,
+ graphics, label,
x + 5, y + 5,
1.0f, 0.8f, 1.0f, 0.05f, true
);
// Draw axes
- DrawHelper.drawHorizontalLine(context, x, width, y + height - 1, 1.0f, 0xFFFFFFFF); // X-axis
- DrawHelper.drawVerticalLine(context, x, y, height, 1.0f, 0xFFFFFFFF); // Y-axis
+ DrawHelper.drawHorizontalLine(graphics, x, width, y + height - 1, 1.0f, 0xFFFFFFFF); // X-axis
+ DrawHelper.drawVerticalLine(graphics, x, y, height, 1.0f, 0xFFFFFFFF); // Y-axis
// Draw min and max value labels with formatted values
/*
DrawHelper.scaleAndPosition(context.getMatrices(),x - 5,y,0.5f);
String formattedMaxVal = formatValue(maxValue);
- context.drawText(mc.textRenderer, formattedMaxVal, x - 5 - mc.textRenderer.getWidth(formattedMaxVal), y - 4, 0xFFFFFFFF, true);
+ context.drawText(mc.font, formattedMaxVal, x - 5 - mc.font.width(formattedMaxVal), y - 4, 0xFFFFFFFF, true);
DrawHelper.stopScaling(context.getMatrices());
*/
- DrawHelper.scaleAndPosition(context.getMatrices(), x - 5, y + height, 0.5f);
+ DrawHelper.scaleAndPosition(graphics.pose(), x - 5, y + height, 0.5f);
String formattedMinVal = formatValue(minValue);
- context.drawText(mc.textRenderer, formattedMinVal, x - mc.textRenderer.getWidth(formattedMinVal), (int) (y + height - 4), 0xFFFFFFFF, true);
- DrawHelper.stopScaling(context.getMatrices());
+ graphics.drawString(mc.font, formattedMinVal, x - mc.font.width(formattedMinVal), (int) (y + height - 4), 0xFFFFFFFF, true);
+ DrawHelper.stopScaling(graphics.pose());
if(showGrid) x -= offset;
this.widgetBox.setDimensions(x, y, width + offset, height, shouldScale, GlobalConfig.get().getScale());
- DrawHelper.disableScissor();
+ // DrawHelper.disableScissor();
if (menu != null) menu.set(getX(), getY(), (int) Math.ceil(getHeight()));
}
@@ -332,12 +306,12 @@ public void createMenu() {
ContextMenuProperties properties = ContextMenuProperties.builder().build();
menu = new ContextMenu<>(getX(), (int) (getY() + widgetBox.getHeight()), properties);
- menu.addOption(new BooleanOption(Text.of("Show Grid"),
+ menu.addOption(new BooleanOption(Component.literal("Show Grid"),
() -> this.showGrid, value -> this.showGrid = value,
BooleanOption.BooleanType.YES_NO)
- .description(Text.of("Shows a grid and Y axis values"))
+ .description(Component.literal("Shows a grid and Y axis values"))
);
- menu.addOption(new DoubleOption(Text.of("Number of Grid Lines"),
+ menu.addOption(new DoubleOption(Component.literal("Number of Grid Lines"),
1, 25, 1,
() -> (double) this.gridLines, value -> {
this.setGridLines(value.intValue());
@@ -345,36 +319,35 @@ public void createMenu() {
}, menu)
.renderWhen(() -> this.showGrid)
);
- menu.addOption(new ColorOption(Text.of("Graph Line Color"),
+ menu.addOption(new ColorOption(Component.literal("Graph Line Color"),
() -> this.graphColor, value -> this.graphColor = value, menu)
- .description(Text.of("Specify the color you want for the graph's lines"))
+ .description(Component.literal("Specify the color you want for the graph's lines"))
);
- menu.addOption(new BooleanOption(Text.of("Rainbow Graph Line Color"),
+ menu.addOption(new BooleanOption(Component.literal("Rainbow Graph Line Color"),
() -> this.graphColorRainbow, value -> this.graphColorRainbow = value)
- .description(Text.of("Color your graph line with funny rainbow"))
+ .description(Component.literal("Color your graph line with funny rainbow"))
.withComplexity(Option.Complexity.Pro)
);
- menu.addOption(new ColorOption(Text.of("Graph Background Color"),
+ menu.addOption(new ColorOption(Component.literal("Graph Background Color"),
() -> this.backgroundColor, value -> this.backgroundColor = value, menu)
- .description(Text.of("Specify the color you want for the graph's background"))
+ .description(Component.literal("Specify the color you want for the graph's background"))
);
- menu.addOption(new DoubleOption(Text.of("Line Thickness"),
+ menu.addOption(new DoubleOption(Component.literal("Line Thickness"),
0.5f, 5.0f, 0.1f,
() -> (double) this.lineThickness, value -> this.lineThickness = value.floatValue(), menu)
);
}
private void computeOffset(){
- // The first text is usually the largest but a negative value may occupy more width so we check the first and last text.
+ // The first Component is usually the largest but a negative value may occupy more width so we check the first and last Component.
// Idk how this will break.
- if(mc.textRenderer == null) return;
String firstText = formatValue(maxValue - valueStep);
String lastText = formatValue(maxValue - (gridLines * valueStep));
offset = Math.max(
- (int) Math.ceil(mc.textRenderer.getWidth(firstText) * this.scale),
- (int) Math.ceil(mc.textRenderer.getWidth(lastText) * this.scale)
+ (int) Math.ceil(mc.font.width(firstText) * this.scale),
+ (int) Math.ceil(mc.font.width(lastText) * this.scale)
);
}
@@ -456,7 +429,7 @@ public void setGridLines(int gridLines) {
this.gridLines = gridLines;
this.stepY = height / (gridLines + 1);
this.valueStep = (maxValue - minValue) / (gridLines + 1);
- this.scale = (float) MathHelper.clamp((stepY / 9.5), 0.0f, 1.0f);
+ this.scale = (float) Math.clamp((stepY / 9.5), 0.0f, 1.0f);
}
public boolean isShowGrid() {
@@ -490,7 +463,7 @@ public void onClose() {
}
@Override
- public void writeToTag(NbtCompound tag) {
+ public void writeToTag(CompoundTag tag) {
super.writeToTag(tag);
tag.putFloat("width", width);
tag.putFloat("height", height);
@@ -508,7 +481,7 @@ public void writeToTag(NbtCompound tag) {
}
@Override
- public void readFromTag(NbtCompound tag) {
+ public void readFromTag(CompoundTag tag) {
super.readFromTag(tag);
this.width = tag.getFloat("width").orElse(100f);
this.height = tag.getFloat("height").orElse(50f);
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java
index 9140d2c..48bd7ac 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/ItemWidget.java
@@ -3,10 +3,10 @@
import com.tanishisherewith.dynamichud.config.GlobalConfig;
import com.tanishisherewith.dynamichud.widget.Widget;
import com.tanishisherewith.dynamichud.widget.WidgetData;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.item.Item;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NbtCompound;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
/**
* This is just an example widget, not supposed to be used.
@@ -25,21 +25,21 @@ public ItemWidget() {
}
@Override
- public void renderWidget(DrawContext context, int mouseX, int mouseY) {
- context.drawItem(item, x, y);
+ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY) {
+ graphics.renderItem(item, x, y);
widgetBox.setDimensions(getX(), getY(), 16, 16, this.shouldScale, GlobalConfig.get().getScale());
}
@Override
- public void writeToTag(NbtCompound tag) {
+ public void writeToTag(CompoundTag tag) {
super.writeToTag(tag);
- tag.putInt("ItemID", Item.getRawId(item.getItem()));
+ tag.putInt("ItemID", Item.getId(item.getItem()));
}
@Override
- public void readFromTag(NbtCompound tag) {
+ public void readFromTag(CompoundTag tag) {
super.readFromTag(tag);
- item = Item.byRawId(tag.getInt("ItemID").orElse(0)).getDefaultStack();
+ item = Item.byId(tag.getInt("ItemID").orElse(0)).getDefaultInstance();
}
public void setItemStack(ItemStack item) {
diff --git a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
index f85a8d7..a286d51 100644
--- a/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
+++ b/src/main/java/com/tanishisherewith/dynamichud/widgets/TextWidget.java
@@ -8,21 +8,28 @@
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties;
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProvider;
import com.tanishisherewith.dynamichud.utils.contextmenu.options.*;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.MinecraftSkin;
+import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.ModernSkin;
import com.tanishisherewith.dynamichud.widget.DynamicValueWidget;
import com.tanishisherewith.dynamichud.widget.WidgetData;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.nbt.NbtCompound;
-import net.minecraft.text.Text;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.chat.Component;
+import javax.swing.*;
import java.awt.Color;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
public class TextWidget extends DynamicValueWidget implements ContextMenuProvider {
- public static WidgetData DATA = new WidgetData<>("TextWidget", "Display Text on screen", TextWidget::new);
+ public static WidgetData DATA = new WidgetData<>("TextWidget", "Display Component on screen", TextWidget::new);
private ContextMenu> menu;
public Color textColor;
- protected boolean shadow; // Whether to draw a shadow behind the text
- protected boolean rainbow; // Whether to apply a rainbow effect to the text
+ protected boolean shadow; // Whether to draw a shadow behind the Component
+ protected boolean rainbow; // Whether to apply a rainbow effect to the Component
protected int rainbowSpeed = 2; //Speed of the rainbow effect
protected float rainbowSpread = 0.01f, rainbowSaturation = 1.0f, rainbowBrightness = 1.0f;
@@ -44,62 +51,98 @@ public TextWidget(String registryID, String registryKey, boolean shadow, boolean
}
public void createMenu() {
- menu = new ContextMenu<>(getX(), getY(),ContextMenuProperties.createGenericSimplified());
+ menu = new ContextMenu<>(getX(), getY(),ContextMenuProperties.builder().skin(new ModernSkin()).build());
- menu.addOption(new BooleanOption(Text.of("Shadow"),
+ menu.addOption(new BooleanOption(Component.literal("Shadow"),
() -> this.shadow, value -> this.shadow = value,
BooleanOption.BooleanType.ON_OFF)
- .description(Text.of("Adds shadow to your text"))
+ .description(Component.literal("Adds shadow to your Component"))
);
- menu.addOption(new BooleanOption(Text.of("Rainbow"),
+ menu.addOption(new BooleanOption(Component.literal("Rainbow"),
() -> this.rainbow, value -> this.rainbow = value,
BooleanOption.BooleanType.ON_OFF)
- .description(Text.of("Adds rainbow effect to your text"))
+ .description(Component.literal("Adds rainbow effect to your Component"))
);
- menu.addOption(new ColorOption(Text.of("Text Color"),
+ menu.addOption(new ColorOption(Component.literal("Component Color"),
() -> this.textColor, value -> this.textColor = value, menu)
- .description(Text.of("Specify the color you want to add to your text"))
+ .description(Component.literal("Specify the color you want to add to your Component"))
.renderWhen(() -> !this.rainbow)
);
- menu.addOption(new DoubleOption(Text.of("Rainbow Speed"),
+ menu.addOption(new DoubleOption(Component.literal("Rainbow Speed"),
1, 5.0f, 1,
() -> (double) this.rainbowSpeed, value -> this.rainbowSpeed = value.intValue(), menu)
.renderWhen(() -> this.rainbow)
);
- menu.addOption(new DoubleOption(Text.of("Rainbow Spread"),
+ menu.addOption(new DoubleOption(Component.literal("Rainbow Spread"),
0.001f, 0.15f, 0.001f,
() -> (double) this.rainbowSpread, value -> this.rainbowSpread = value.floatValue(), menu)
.renderWhen(() -> this.rainbow)
.withComplexity(Option.Complexity.Enhanced)
);
- menu.addOption(new DoubleOption(Text.of("Rainbow Saturation"),
+ menu.addOption(new DoubleOption(Component.literal("Rainbow Saturation"),
0, 1.0f, 0.1f,
() -> (double) this.rainbowSaturation, value -> this.rainbowSaturation = value.floatValue(), menu)
.renderWhen(() -> this.rainbow)
.withComplexity(Option.Complexity.Pro)
);
- menu.addOption(new DoubleOption(Text.of("Rainbow Brightness"),
+ menu.addOption(new DoubleOption(Component.literal("Rainbow Brightness"),
0, 1.0f, 0.01f,
() -> (double) this.rainbowBrightness, value -> this.rainbowBrightness = value.floatValue(), menu)
.renderWhen(() -> this.rainbow)
.withComplexity(Option.Complexity.Pro)
);
+ // Runnable Option
+ AtomicBoolean ran = new AtomicBoolean(false);
+ menu.addOption(new RunnableOption(Component.literal("Reset Position"),
+ ran::get, ran::set,
+ () -> this.setPosition(0, 0))
+ .description(Component.literal("Reset widget to default position")));
+
+ // List Option
+ AtomicReference style = new AtomicReference<>("Style1");
+ List styles = Arrays.asList("Style1", "Style2", "Style3");
+ menu.addOption(new ListOption<>(Component.literal("Text Style"),
+ style::get, style::set, styles)
+ .description(Component.literal("Choose a text style")));
+
+ // Enum Option
+ menu.addOption(new EnumOption<>(Component.literal("Alignment"),
+ () -> GroupLayout.Alignment.CENTER, value -> {}, GroupLayout.Alignment.values())
+ .description(Component.literal("Set text alignment")));
+
+ // Option Group
+ OptionGroup group = new OptionGroup(Component.literal("Display Options"));
+ group.addOption(new BooleanOption(Component.literal("Bold Text"),
+ () -> false, value -> {}, BooleanOption.BooleanType.YES_NO)
+ .description(Component.literal("Enable bold text")));
+ group.addOption(new DoubleOption(Component.literal("Font Size"),
+ 8.0, 24.0, 1.0f,
+ () -> 12.0, value -> {}, menu)
+ .description(Component.literal("Adjust font size")));
+ menu.addOption(group);
+
+ // SubMenu Option
+ SubMenuOption subMenu = (SubMenuOption) new SubMenuOption(Component.literal("Advanced Settings"), menu)
+ .description(Component.literal("Open advanced settings"));
+ subMenu.getSubMenu().addOption(new BooleanOption(Component.literal("Some Boolean"),
+ () -> false, value -> {}, BooleanOption.BooleanType.TRUE_FALSE)
+ .description(Component.literal("True/False")));
+ menu.addOption(subMenu);
}
@Override
- public void renderWidget(DrawContext drawContext, int mouseX, int mouseY) {
+ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY) {
if (menu == null) return;
//int color = rainbow ? ColorHelper.getColorFromHue((System.currentTimeMillis() % (5000 * rainbowSpeed) / (5000f * rainbowSpeed))) : textColor.getRGB();
int color = textColor.getRGB();
if (valueSupplier != null) {
- String text = getValue();
+ String Component = getValue();
if (rainbow) {
- DrawHelper.drawChromaText(drawContext, text, getX() + 2, getY() + 2, rainbowSpeed / 2f, rainbowSaturation, rainbowBrightness, rainbowSpread, shadow);
+ DrawHelper.drawChromaText(graphics, Component, getX() + 2, getY() + 2, rainbowSpeed / 2f, rainbowSaturation, rainbowBrightness, rainbowSpread, shadow);
} else {
- drawContext.drawText(mc.textRenderer, text, getX() + 2, getY() + 2, color, shadow);
+ graphics.drawString(mc.font, Component, getX() + 2, getY() + 2, color, shadow);
}
- drawContext.draw();
- widgetBox.setDimensions(getX(), getY(), mc.textRenderer.getWidth(text) + 3, mc.textRenderer.fontHeight + 2, this.shouldScale, GlobalConfig.get().getScale());
+ widgetBox.setDimensions(getX(), getY(), mc.font.width(Component) + 3, mc.font.lineHeight + 2, this.shouldScale, GlobalConfig.get().getScale());
}
menu.set(getX(), getY(), (int) Math.ceil(getHeight()));
@@ -118,7 +161,7 @@ public void onClose() {
}
@Override
- public void writeToTag(NbtCompound tag) {
+ public void writeToTag(CompoundTag tag) {
super.writeToTag(tag);
tag.putBoolean("Shadow", shadow);
tag.putBoolean("Rainbow", rainbow);
@@ -130,7 +173,7 @@ public void writeToTag(NbtCompound tag) {
}
@Override
- public void readFromTag(NbtCompound tag) {
+ public void readFromTag(CompoundTag tag) {
super.readFromTag(tag);
shadow = tag.getBoolean("Shadow").orElse(false);
rainbow = tag.getBoolean("Rainbow").orElse(false);
diff --git a/src/main/resources/dynamichud.mixins.json b/src/main/resources/dynamichud.mixins.json
index f60e286..caa9633 100644
--- a/src/main/resources/dynamichud.mixins.json
+++ b/src/main/resources/dynamichud.mixins.json
@@ -1,6 +1,5 @@
{
"required": true,
- "minVersion": "0.8",
"package": "com.tanishisherewith.dynamichud.mixins",
"compatibilityLevel": "JAVA_21",
"mixins": [
@@ -10,7 +9,11 @@
"defaultRequire": 1
},
"client": [
- "OptionsScreenMixin",
- "RenderLayerMixin"
- ]
+ "BufferBuilderMixin",
+ "MinecraftMixin",
+ "OptionsScreenMixin"
+ ],
+ "overwrites": {
+ "requireAnnotations": true
+ }
}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index a6ef3cf..a416a25 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -26,7 +26,10 @@
]
},
"mixins": [
- "dynamichud.mixins.json"
+ {
+ "config": "dynamichud.mixins.json",
+ "environment": "client"
+ }
],
"depends": {
"fabricloader": ">=${loader_version}",