From d19168614cd34fed3d621ac02ff153eebd7ada61 Mon Sep 17 00:00:00 2001 From: tanishisherewith <120117618+tanishisherewithhh@users.noreply.github.com> Date: Thu, 26 Feb 2026 13:46:04 +0530 Subject: [PATCH] An attempt to 1.21.11 Runs, but rendering is broken. --- build.gradle | 7 +- gradle.properties | 13 +- gradle/wrapper/gradle-wrapper.properties | 5 +- .../dynamichud/DynamicHUD.java | 43 +- .../dynamichud/HudRender.java | 30 - .../dynamichud/IntegrationTest.java | 22 +- .../dynamichud/config/GlobalConfig.java | 56 +- .../dynamichud/helpers/ColorHelper.java | 16 +- .../dynamichud/helpers/DrawHelper.java | 549 ++++++++---------- .../dynamichud/helpers/MouseColorQuery.java | 16 +- .../dynamichud/helpers/TextureHelper.java | 50 +- .../animations/MathAnimations.java | 20 +- .../integration/DefaultIntegrationImpl.java | 6 + .../integration/DynamicHudIntegration.java | 19 +- .../integration/IntegrationManager.java | 20 +- .../dynamichud/internal/IBufferBuilder.java | 8 + .../dynamichud/internal/IRenderLayer.java | 22 - .../dynamichud/internal/WarningScreen.java | 62 +- .../dynamichud/mixins/BufferBuilderMixin.java | 33 ++ .../dynamichud/mixins/MinecraftMixin.java | 15 + .../dynamichud/mixins/OptionsScreenMixin.java | 48 +- .../dynamichud/mixins/RenderLayerMixin.java | 41 -- .../dynamichud/mixins/ScreenMixin.java | 13 +- .../renderstates/GeometryRenderState.java | 38 ++ .../GradientShadowRenderState.java | 44 ++ .../InterpolatedCurveRenderState.java | 59 ++ .../QuadColorRectRenderState.java | 42 ++ .../renderstates/RoundedRectRenderState.java | 57 ++ .../screens/AbstractMoveableScreen.java | 109 ++-- .../dynamichud/utils/CustomRenderLayers.java | 152 +++-- .../dynamichud/utils/Util.java | 8 +- .../utils/contextmenu/ContextMenu.java | 17 +- .../utils/contextmenu/ContextMenuManager.java | 6 +- .../contextmenuscreen/ContextMenuScreen.java | 62 +- .../ContextMenuScreenFactory.java | 2 +- .../ContextMenuScreenRegistry.java | 2 +- .../DefaultContextMenuScreenFactory.java | 2 +- .../contextmenu/layout/LayoutContext.java | 52 +- .../contextmenu/options/BooleanOption.java | 24 +- .../contextmenu/options/ColorOption.java | 4 +- .../contextmenu/options/DoubleOption.java | 12 +- .../utils/contextmenu/options/EnumOption.java | 4 +- .../utils/contextmenu/options/ListOption.java | 4 +- .../utils/contextmenu/options/Option.java | 26 +- .../contextmenu/options/OptionGroup.java | 12 +- .../contextmenu/options/RunnableOption.java | 6 +- .../contextmenu/options/SubMenuOption.java | 10 +- .../options/coloroption/AlphaSlider.java | 10 +- .../options/coloroption/ColorGradient.java | 23 +- .../coloroption/ColorPickerButton.java | 13 +- .../options/coloroption/HueSlider.java | 14 +- .../options/coloroption/SaturationHueBox.java | 13 +- .../contextmenu/skinsystem/ClassicSkin.java | 121 ++-- .../contextmenu/skinsystem/MinecraftSkin.java | 219 ++++--- .../contextmenu/skinsystem/ModernSkin.java | 406 +++++++------ .../utils/contextmenu/skinsystem/Skin.java | 10 +- .../skinsystem/interfaces/GroupableSkin.java | 4 +- .../skinsystem/interfaces/SkinRenderer.java | 4 +- .../utils/handlers/ScrollHandler.java | 9 +- .../dynamichud/widget/DynamicValueWidget.java | 6 +- .../dynamichud/widget/UserManageable.java | 6 - .../dynamichud/widget/Widget.java | 79 ++- .../dynamichud/widget/WidgetManager.java | 17 +- .../dynamichud/widget/WidgetRenderer.java | 51 +- .../dynamichud/widgets/GraphWidget.java | 141 ++--- .../dynamichud/widgets/ItemWidget.java | 20 +- .../dynamichud/widgets/TextWidget.java | 93 ++- src/main/resources/dynamichud.mixins.json | 11 +- src/main/resources/fabric.mod.json | 5 +- 69 files changed, 1663 insertions(+), 1480 deletions(-) delete mode 100644 src/main/java/com/tanishisherewith/dynamichud/HudRender.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/internal/IBufferBuilder.java delete mode 100644 src/main/java/com/tanishisherewith/dynamichud/internal/IRenderLayer.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/mixins/BufferBuilderMixin.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/mixins/MinecraftMixin.java delete mode 100644 src/main/java/com/tanishisherewith/dynamichud/mixins/RenderLayerMixin.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/renderstates/GeometryRenderState.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/renderstates/GradientShadowRenderState.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/renderstates/InterpolatedCurveRenderState.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/renderstates/QuadColorRectRenderState.java create mode 100644 src/main/java/com/tanishisherewith/dynamichud/renderstates/RoundedRectRenderState.java delete mode 100644 src/main/java/com/tanishisherewith/dynamichud/widget/UserManageable.java 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 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> renderer; protected Complexity complexity = Complexity.Simple; - public Option(Text name, Supplier getter, Consumer setter) { + public Option(Component name, Supplier getter, Consumer setter) { this(name, getter, setter, () -> true); } - public Option(Text name, Supplier getter, Consumer setter, Supplier shouldRender, ContextMenuProperties properties) { + public Option(Component name, Supplier getter, Consumer setter, Supplier shouldRender, ContextMenuProperties properties) { this.name = name; this.getter = getter; this.setter = setter; @@ -41,7 +41,7 @@ public Option(Text name, Supplier getter, Consumer setter, Supplier getter, Consumer setter, Supplier shouldRender) { + public Option(Component name, Supplier getter, Consumer setter, Supplier shouldRender) { this(name, getter, setter, shouldRender, ContextMenuProperties.createGenericSimplified()); } @@ -63,13 +63,13 @@ public void updateProperties(ContextMenuProperties properties) { } } - 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) { this.x = x; this.y = y; this.value = get(); // Retrieve the renderer and ensure it is not null - renderer.render(drawContext, this, x, y, mouseX, mouseY); + renderer.render(graphics, this, x, y, mouseX, mouseY); } public boolean mouseClicked(double mouseX, double mouseY, int button) { @@ -163,7 +163,7 @@ public void setPosition(int x, int y) { this.y = y; } - public Option description(Text description) { + public Option description(Component description) { this.description = description; return this; } @@ -177,11 +177,11 @@ public SkinRenderer> getRenderer() { return renderer; } - public Text getName() { + public Component getName() { return name; } - public Text getDescription() { + public Component getDescription() { return description; } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java index 99097fd..ec68a50 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java @@ -2,8 +2,8 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; import java.util.ArrayList; import java.util.Collections; @@ -14,7 +14,7 @@ public class OptionGroup extends Option { private final List> groupOptions = new ArrayList<>(); protected boolean expanded; // Skins can choose to use this or ignore it - public OptionGroup(Text name) { + public OptionGroup(Component name) { super(name, () -> null, (v) -> {}, () -> true); this.expanded = false; } @@ -38,8 +38,8 @@ public void updateProperties(ContextMenuProperties properties) { } @Override - public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) { - super.render(drawContext,x,y,mouseX,mouseY); + public void render(GuiGraphics graphics, int x, int y, int mouseX, int mouseY) { + super.render(graphics,x,y,mouseX,mouseY); } public boolean isExpanded() { @@ -65,7 +65,7 @@ public int getHeight() { public static class OptionGroupRenderer implements SkinRenderer> { @Override - public void render(DrawContext drawContext, Option option, int x, int y, int mouseX, int mouseY) {} + public void render(GuiGraphics graphics, Option option, int x, int y, int mouseX, int mouseY) {} @Override public boolean mouseClicked(Option option2, double mouseX, double mouseY, int button) { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java index 8bc80a1..ce18f5e 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/RunnableOption.java @@ -2,7 +2,7 @@ import com.tanishisherewith.dynamichud.DynamicHUD; import com.tanishisherewith.dynamichud.utils.BooleanPool; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.Consumer; import java.util.function.Supplier; @@ -18,14 +18,14 @@ public class RunnableOption extends Option { * @param setter Return a boolean based on if the task is running or not. * @param task The task to run */ - public RunnableOption(Text name, Supplier getter, Consumer setter, Runnable task) { + public RunnableOption(Component name, Supplier getter, Consumer setter, Runnable task) { super(name, getter, setter); this.name = name; this.task = task; this.renderer.init(this); } - public RunnableOption(Text name, boolean defaultValue, Runnable task) { + public RunnableOption(Component name, boolean defaultValue, Runnable task) { this(name, () -> BooleanPool.get(name.getString()), value -> BooleanPool.put(name.getString(), value), task); BooleanPool.put(name.getString(), defaultValue); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java index 36f7f9b..0b65c86 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java @@ -3,7 +3,7 @@ import com.tanishisherewith.dynamichud.utils.BooleanPool; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.Objects; import java.util.function.Consumer; @@ -19,7 +19,7 @@ public class SubMenuOption extends Option { private final ContextMenu subMenu; - public SubMenuOption(Text name, ContextMenu parentMenu, Supplier getter, Consumer setter, T properties) { + public SubMenuOption(Component name, ContextMenu parentMenu, Supplier getter, Consumer setter, T properties) { super(name, getter, setter); Objects.requireNonNull(parentMenu, "Parent Context Menu cannot be null in [" + name + "] SubMenu option"); this.subMenu = parentMenu.createSubMenu(parentMenu.x + parentMenu.getWidth(), this.y, properties.cloneSkin()); @@ -28,15 +28,15 @@ public SubMenuOption(Text name, ContextMenu this.renderer.init(this); } - public SubMenuOption(Text name, ContextMenu parentMenu, T properties) { + public SubMenuOption(Component name, ContextMenu parentMenu, T properties) { this(name, parentMenu, () -> BooleanPool.get(name.getString()), value -> BooleanPool.put(name.getString(), value), properties); } - public SubMenuOption(Text name, ContextMenu parentMenu, Supplier getter, Consumer setter) { + public SubMenuOption(Component name, ContextMenu parentMenu, Supplier getter, Consumer setter) { this(name, parentMenu, getter, setter, parentMenu.getProperties().cloneWithSkin()); } - public SubMenuOption(Text name, ContextMenu parentMenu) { + public SubMenuOption(Component name, ContextMenu parentMenu) { this(name, parentMenu, () -> BooleanPool.get(name.getString()), value -> BooleanPool.put(name.getString(), value), parentMenu.getProperties().cloneWithSkin()); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java index ef71488..5c37cfd 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/AlphaSlider.java @@ -2,7 +2,7 @@ import com.tanishisherewith.dynamichud.helpers.ColorHelper; import com.tanishisherewith.dynamichud.helpers.DrawHelper; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.GuiGraphics; import java.awt.*; @@ -25,13 +25,13 @@ public AlphaSlider(int x, int y, int width, int height, Color color) { this.alpha = color.getAlpha() / 255f; } - public void render(DrawContext drawContext, int x, int y) { + public void render(GuiGraphics graphics, int x, int y) { this.x = x; this.y = y; - DrawHelper.drawOutlinedBox(drawContext, x - 2, y - 2, x + width + 2, y + height + 2, Color.WHITE.getRGB()); - DrawHelper.drawGradient(drawContext, x, y, width, height, color.getRGB(), ColorHelper.changeAlpha(color, 0).getRGB(), DrawHelper.Direction.TOP_BOTTOM); - drawContext.fill(x - 2, y + alphaHandleY - 1, x + width + 2, y + alphaHandleY + 1, Color.WHITE.getRGB()); + DrawHelper.drawOutlinedBox(graphics, x - 2, y - 2, x + width + 2, y + height + 2, Color.WHITE.getRGB()); + DrawHelper.drawGradient(graphics, x, y, width, height, color.getRGB(), ColorHelper.changeAlpha(color, 0).getRGB(), DrawHelper.Direction.TOP_BOTTOM); + graphics.fill(x - 2, y + alphaHandleY - 1, x + width + 2, y + alphaHandleY + 1, Color.WHITE.getRGB()); } public Color getColor() { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java index 067c45c..14379a8 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorGradient.java @@ -3,14 +3,14 @@ import com.tanishisherewith.dynamichud.config.GlobalConfig; import com.tanishisherewith.dynamichud.helpers.ColorHelper; import com.tanishisherewith.dynamichud.helpers.MouseColorQuery; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import java.awt.*; import java.util.function.Consumer; public class ColorGradient { - final MinecraftClient client = MinecraftClient.getInstance(); + final Minecraft client = Minecraft.getInstance(); private final Consumer onColorSelected; // The callback to call when a color is selected private final HueSlider gradientSlider; private final SaturationHueBox gradientBox; @@ -52,15 +52,15 @@ public void close() { display = false; } - public void render(DrawContext drawContext, int x1, int y1, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, int x1, int y1, int mouseX, int mouseY) { setPos(x1, y1); if (!display) { return; } - gradientSlider.render(drawContext, x, y + client.textRenderer.fontHeight + 4); - gradientBox.render(drawContext, x, y + client.textRenderer.fontHeight + gradientSlider.getHeight() + 10); - // colorPickerButton.render(drawContext, x + 24 + boxSize, y + client.textRenderer.fontHeight + gradientSlider.getHeight() + 8); - alphaSlider.render(drawContext, x + 10 + boxSize, y + client.textRenderer.fontHeight + gradientSlider.getHeight() + 10); + gradientSlider.render(graphics, x, y + client.font.lineHeight + 4); + gradientBox.render(graphics, x, y + client.font.lineHeight + gradientSlider.getHeight() + 10); + // colorPickerButton.render(graphics, x + 24 + boxSize, y + client.font.lineHeight + gradientSlider.getHeight() + 8); + alphaSlider.render(graphics, x + 10 + boxSize, y + client.font.lineHeight + gradientSlider.getHeight() + 10); if (colorPickerButton.isPicking() && GlobalConfig.get().showColorPickerPreview()) { MouseColorQuery.request(mouseX, mouseY, colors -> { @@ -70,11 +70,8 @@ public void render(DrawContext drawContext, int x1, int y1, int mouseX, int mous int blue = colors[2]; //Draw the preview box near the mouse pointer - drawContext.getMatrices().push(); - drawContext.getMatrices().translate(0, 0, 2500); - drawContext.fill(mouseX + 10, mouseY, mouseX + 26, mouseY + 16, -1); - drawContext.fill(mouseX + 11, mouseY + 1, mouseX + 25, mouseY + 15, (red << 16) | (green << 8) | blue | 0xFF000000); - drawContext.getMatrices().pop(); + graphics.fill(mouseX + 10, mouseY, mouseX + 26, mouseY + 16, -1); + graphics.fill(mouseX + 11, mouseY + 1, mouseX + 25, mouseY + 15, (red << 16) | (green << 8) | blue | 0xFF000000); } }); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java index 4d9b711..c4807bc 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/ColorPickerButton.java @@ -1,7 +1,7 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import java.awt.*; @@ -19,15 +19,12 @@ public ColorPickerButton(int x, int y, int width, int height) { this.height = height; } - public void render(DrawContext drawContext, int x, int y) { + public void render(GuiGraphics graphics, int x, int y) { this.x = x; this.y = y; - drawContext.getMatrices().push(); - drawContext.getMatrices().translate(0, 0, 404); // Draw the button - drawContext.fill(x + 2, y + 2, x + width - 2, y + height - 2, isPicking() ? Color.GREEN.getRGB() : 0xFFAAAAAA); - drawContext.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, "Pick", x + width / 2, y + (height - 8) / 2, 0xFFFFFFFF); - drawContext.getMatrices().pop(); + graphics.fill(x + 2, y + 2, x + width - 2, y + height - 2, isPicking() ? Color.GREEN.getRGB() : 0xFFAAAAAA); + graphics.drawCenteredString(Minecraft.getInstance().font, "Pick", x + width / 2, y + (height - 8) / 2, 0xFFFFFFFF); } public int getHeight() { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java index 1c5097d..7d8c009 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java @@ -1,7 +1,7 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption; import com.tanishisherewith.dynamichud.helpers.DrawHelper; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.GuiGraphics; import java.awt.*; @@ -31,20 +31,17 @@ public void setPosition(int x, int y) { this.y = y; } - public void render(DrawContext drawContext, int x, int y) { + public void render(GuiGraphics graphics, int x, int y) { setPosition(x, y); - drawContext.getMatrices().push(); - drawContext.getMatrices().translate(0, 0, 401); - DrawHelper.drawOutlinedBox(drawContext, x - 2, y - 2, x + width + 2, y + height + 2, -1); + DrawHelper.drawOutlinedBox(graphics, x - 2, y - 2, x + width + 2, y + height + 2, -1); // Draw the gradient for (int i = 0; i < width; i++) { float hue = (float) i / width; int color = Color.HSBtoRGB(hue, 1.0f, 1.0f); color = (color & 0x00FFFFFF) | (255 << 24); - drawContext.fill(x + i, y, x + i + 1, y + height, color); + graphics.fill(x + i, y, x + i + 1, y + height, color); } - drawContext.draw(); // Draw the handle @@ -53,8 +50,7 @@ public void render(DrawContext drawContext, int x, int y) { float handleX = x + hue * width - handleWidth / 2.0f; float handleY = y - (handleHeight - height) / 2.0f; - DrawHelper.drawRectangle(drawContext, handleX, handleY, handleWidth, handleHeight, -1); - drawContext.getMatrices().pop(); + DrawHelper.drawRectangle(graphics, handleX, handleY, handleWidth, handleHeight, -1); } public int getHeight() { diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/SaturationHueBox.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/SaturationHueBox.java index 53b8238..348459b 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/SaturationHueBox.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/SaturationHueBox.java @@ -1,7 +1,7 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.options.coloroption; import com.tanishisherewith.dynamichud.helpers.DrawHelper; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.GuiGraphics; import java.awt.*; @@ -21,22 +21,19 @@ public SaturationHueBox(int x, int y, int size) { this.size = size; } - public void render(DrawContext drawContext, int x, int y) { + public void render(GuiGraphics graphics, int x, int y) { setPosition(x, y); - drawContext.getMatrices().push(); - drawContext.getMatrices().translate(0, 0, 406); - DrawHelper.drawOutlinedBox(drawContext, x - 2, y - 2, x + size + 2, y + size + 2, -1); + DrawHelper.drawOutlinedBox(graphics, x - 2, y - 2, x + size + 2, y + size + 2, -1); // Draw the gradient - DrawHelper.drawRoundedGradientRectangle(drawContext, Color.WHITE, Color.getHSBColor(hue, 1.0f, 1.0f),Color.BLACK, Color.BLACK, x, y, size, size, 3); + DrawHelper.drawRoundedGradientRectangle(graphics, Color.WHITE, Color.getHSBColor(hue, 1.0f, 1.0f),Color.BLACK, Color.BLACK, x, y, size, size, 3); // Draw the handle float handleSize = 1f; float handleX = x + 2 + saturation * size - handleSize / 2.0f; float handleY = y + 2 + (1.0f - value) * size - handleSize / 2.0f; - DrawHelper.drawFilledCircle(drawContext, handleX, handleY, handleSize, -1); - drawContext.getMatrices().pop(); + DrawHelper.drawFilledCircle(graphics, handleX, handleY, handleSize, -1); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java index 36ec017..1298a56 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java @@ -5,10 +5,11 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuProperties; import com.tanishisherewith.dynamichud.utils.contextmenu.options.*; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import org.apache.logging.log4j.core.pattern.TextRenderer; +import org.joml.Matrix3x2fStack; import java.awt.*; @@ -32,14 +33,14 @@ public ClassicSkin() { } @Override - public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int mouseX, int mouseY) { + public void renderContextMenu(GuiGraphics graphics, ContextMenu contextMenu, int mouseX, int mouseY) { this.contextMenu = contextMenu; - MatrixStack matrices = drawContext.getMatrices(); + Matrix3x2fStack matrices = graphics.pose(); ContextMenuProperties properties = contextMenu.getProperties(); // Draw the background - drawBackground(drawContext, contextMenu, properties); + drawBackground(graphics, contextMenu, properties); int yOffset = contextMenu.y + 3; int width = 10; @@ -48,10 +49,10 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMen // Adjust mouse coordinates based on the scale if (contextMenu.getProperties().hoverEffect() && contextMenu.isMouseOver(mouseX, mouseY, contextMenu.x + 1, yOffset - 1, contextMenu.getWidth() - 2, option.getHeight())) { - drawBackground(drawContext, contextMenu, properties, yOffset - 1, contextMenu.getWidth(), option.getHeight() + 1, contextMenu.getProperties().getHoverColor().getRGB(), false); + drawBackground(graphics, contextMenu, properties, yOffset - 1, contextMenu.getWidth(), option.getHeight() + 1, contextMenu.getProperties().getHoverColor().getRGB(), false); } - option.render(drawContext, contextMenu.x + 4, yOffset, mouseX, mouseY); + option.render(graphics, contextMenu.x + 4, yOffset, mouseX, mouseY); width = Math.max(width, option.getWidth()); yOffset += option.getHeight() + 1; } @@ -60,19 +61,19 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMen // Draw the border if needed if (properties.shouldDrawBorder()) { - drawBorder(drawContext, contextMenu, properties); + drawBorder(graphics, contextMenu, properties); } } - private void drawBackground(DrawContext drawContext, ContextMenu contextMenu, ContextMenuProperties properties) { - drawBackground(drawContext, contextMenu, properties, contextMenu.y, contextMenu.getWidth(), contextMenu.getHeight(), properties.getBackgroundColor().getRGB(), properties.shadow()); + private void drawBackground(GuiGraphics graphics, ContextMenu contextMenu, ContextMenuProperties properties) { + drawBackground(graphics, contextMenu, properties, contextMenu.y, contextMenu.getWidth(), contextMenu.getHeight(), properties.getBackgroundColor().getRGB(), properties.shadow()); } - private void drawBackground(DrawContext drawContext, ContextMenu contextMenu, ContextMenuProperties properties, int yOffset, int width, int height, int color, boolean shadow) { + private void drawBackground(GuiGraphics graphics, ContextMenu contextMenu, ContextMenuProperties properties, int yOffset, int width, int height, int color, boolean shadow) { if (properties.roundedCorners()) { // Rounded if (shadow) { - DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRoundedRectangleWithShadowBadWay(graphics, contextMenu.x, yOffset, width, @@ -84,7 +85,7 @@ private void drawBackground(DrawContext drawContext, ContextMenu contextMenu, 1 ); } else { - DrawHelper.drawRoundedRectangle(drawContext, + DrawHelper.drawRoundedRectangle(graphics, contextMenu.x, yOffset, width, @@ -96,7 +97,7 @@ private void drawBackground(DrawContext drawContext, ContextMenu contextMenu, } else { // Normal if (shadow) { - DrawHelper.drawRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRectangleWithShadowBadWay(graphics, contextMenu.x, yOffset, width, @@ -107,7 +108,7 @@ private void drawBackground(DrawContext drawContext, ContextMenu contextMenu, 1 ); } else { - DrawHelper.drawRectangle(drawContext, + DrawHelper.drawRectangle(graphics, contextMenu.x, yOffset, width, @@ -118,9 +119,9 @@ private void drawBackground(DrawContext drawContext, ContextMenu contextMenu, } } - private void drawBorder(DrawContext drawContext, ContextMenu contextMenu, ContextMenuProperties properties) { + private void drawBorder(GuiGraphics graphics, ContextMenu contextMenu, ContextMenuProperties properties) { if (properties.roundedCorners()) { - DrawHelper.drawOutlineRoundedBox(drawContext, + DrawHelper.drawOutlineRoundedBox(graphics, contextMenu.x, contextMenu.y, contextMenu.getWidth(), @@ -130,7 +131,7 @@ private void drawBorder(DrawContext drawContext, ContextMenu contextMenu, Con properties.getBorderColor().getRGB() ); } else { - DrawHelper.drawOutlineBox(drawContext, + DrawHelper.drawOutlineBox(graphics, contextMenu.x, contextMenu.y, contextMenu.getWidth(), @@ -148,24 +149,24 @@ public Skin clone() { public static class ClassicBooleanRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, BooleanOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, BooleanOption option, int x, int y, int mouseX, int mouseY) { int color = option.value ? Color.GREEN.getRGB() : Color.RED.getRGB(); - drawContext.drawText(mc.textRenderer, option.name, x, y, color, false); - option.setHeight(mc.textRenderer.fontHeight); - option.setWidth(mc.textRenderer.getWidth(option.name) + 1); + graphics.drawString(mc.font, option.name, x, y, color, false); + option.setHeight(mc.font.lineHeight); + option.setWidth(mc.font.width(option.name) + 1); } } public static class ClassicColorOptionRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, ColorOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, ColorOption option, int x, int y, int mouseX, int mouseY) { int color = option.isVisible ? Color.GREEN.getRGB() : Color.RED.getRGB(); - drawContext.drawText(mc.textRenderer, option.name, x, y, color, false); - option.setHeight(mc.textRenderer.fontHeight); - option.setWidth(mc.textRenderer.getWidth(option.name) + 10); + graphics.drawString(mc.font, option.name, x, y, color, false); + option.setHeight(mc.font.lineHeight); + option.setWidth(mc.font.width(option.name) + 10); int shadowOpacity = Math.min(option.value.getAlpha(), 90); - DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRoundedRectangleWithShadowBadWay(graphics, x + option.getWidth() - 10 + 1, y - 1, 8, @@ -176,32 +177,32 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in 1, 1); - option.getColorGradient().render(drawContext, x + option.getParentMenu().getWidth() + 7, y - 10, mouseX, mouseY); + option.getColorGradient().render(graphics, x + option.getParentMenu().getWidth() + 7, y - 10, mouseX, mouseY); } } public static class ClassicEnumRenderer> implements SkinRenderer> { @Override - public void render(DrawContext drawContext, EnumOption option, int x, int y, int mouseX, int mouseY) { - option.setHeight(mc.textRenderer.fontHeight + 1); - option.setWidth(mc.textRenderer.getWidth(option.name + ": " + option.value.name()) + 1); + public void render(GuiGraphics graphics, EnumOption option, int x, int y, int mouseX, int mouseY) { + option.setHeight(mc.font.lineHeight + 1); + option.setWidth(mc.font.width(option.name + ": " + option.value.name()) + 1); - drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x, y, Color.WHITE.getRGB(), false); - drawContext.drawText(mc.textRenderer, option.value.name(), x + mc.textRenderer.getWidth(option.name + ": ") + 1, y, Color.CYAN.getRGB(), false); + graphics.drawString(mc.font, option.name.copy().append(": "), x, y, Color.WHITE.getRGB(), false); + graphics.drawString(mc.font, option.value.name(), x + mc.font.width(option.name + ": ") + 1, y, Color.CYAN.getRGB(), false); } } public static class ClassicSubMenuRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, SubMenuOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, SubMenuOption option, int x, int y, int mouseX, int mouseY) { int color = option.value ? Color.GREEN.getRGB() : Color.RED.getRGB(); - drawContext.drawText(mc.textRenderer, option.name, x, y, color, false); - drawContext.drawText(mc.textRenderer, option.getSubMenu().isVisible() ? "-" : "+", x + Math.max(option.getParentMenu().getWidth() - 12, mc.textRenderer.getWidth(option.name) + 2), y, color, false); + graphics.drawString(mc.font, option.name, x, y, color, false); + graphics.drawString(mc.font, option.getSubMenu().isVisible() ? "-" : "+", x + Math.max(option.getParentMenu().getWidth() - 12, mc.font.width(option.name) + 2), y, color, false); - option.setHeight(mc.textRenderer.fontHeight); - option.setWidth(mc.textRenderer.getWidth(option.name) + 4); + option.setHeight(mc.font.lineHeight); + option.setWidth(mc.font.width(option.name) + 4); - option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y - 1, mouseX, mouseY); + option.getSubMenu().render(graphics, x + option.getParentMenu().getWidth(), y - 1, mouseX, mouseY); } } @@ -210,41 +211,41 @@ public static class ClassicRunnableRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, DoubleOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, DoubleOption option, int x, int y, int mouseX, int mouseY) { option.setWidth(Math.max(35, contextMenu != null ? contextMenu.getWidth() - option.getProperties().getPadding() - 2 : 0)); option.setHeight(16); // Draw the label - TextRenderer textRenderer = mc.textRenderer; - DrawHelper.scaleAndPosition(drawContext.getMatrices(), x, y, 0.7f); - Text labelText = option.name.copy().append(": " + String.format("%.1f", option.value)); - int labelWidth = textRenderer.getWidth(labelText); + Font font = mc.font; + DrawHelper.scaleAndPosition(graphics.pose(), x, y, 0.7f); + Component labelText = option.name.copy().append(": " + String.format("%.1f", option.value)); + int labelWidth = font.width(labelText); option.setWidth(Math.max(option.getWidth(), labelWidth)); - drawContext.drawTextWithShadow(textRenderer, labelText, x, y + 1, 0xFFFFFFFF); - DrawHelper.stopScaling(drawContext.getMatrices()); + graphics.drawString(font, labelText, x, y + 1, 0xFFFFFFFF,true); + DrawHelper.stopScaling(graphics.pose()); float handleWidth = 3; float handleHeight = 8; double handleX = x + (option.value - option.minValue) / (option.maxValue - option.minValue) * (option.getWidth() - handleWidth); - double handleY = y + textRenderer.fontHeight + 1 + ((2 - handleHeight) / 2); + double handleY = y + font.lineHeight + 1 + ((2 - handleHeight) / 2); // Draw the slider - option.drawSlider(drawContext, x, y + textRenderer.fontHeight + 1, option.getWidth(), handleX); + option.drawSlider(graphics, x, y + font.lineHeight + 1, option.getWidth(), handleX); // Draw the handle - DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRoundedRectangleWithShadowBadWay(graphics, (float) handleX, (float) handleY, handleWidth, @@ -260,12 +261,12 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i public static class ClassicListRenderer implements SkinRenderer> { @Override - public void render(DrawContext drawContext, ListOption option, int x, int y, int mouseX, int mouseY) { - option.setHeight(mc.textRenderer.fontHeight + 1); - option.setWidth(mc.textRenderer.getWidth(option.name + ": " + option.value.toString()) + 1); + public void render(GuiGraphics graphics, ListOption option, int x, int y, int mouseX, int mouseY) { + option.setHeight(mc.font.lineHeight + 1); + option.setWidth(mc.font.width(option.name + ": " + option.value.toString()) + 1); - drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x, y + 1, Color.WHITE.getRGB(), false); - drawContext.drawText(mc.textRenderer, option.value.toString(), x + mc.textRenderer.getWidth(option.name + ": ") + 1, y + 1, Color.CYAN.getRGB(), false); + graphics.drawString(mc.font, option.name.copy().append(": "), x, y + 1, Color.WHITE.getRGB(), false); + graphics.drawString(mc.font, option.value.toString(), x + mc.font.width(option.name + ": ") + 1, y + 1, Color.CYAN.getRGB(), false); } } } \ No newline at end of file diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java index 0593ed0..9aeb548 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java @@ -1,6 +1,5 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem; -import com.mojang.blaze3d.systems.RenderSystem; import com.tanishisherewith.dynamichud.DynamicHUD; import com.tanishisherewith.dynamichud.helpers.DrawHelper; import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu; @@ -9,13 +8,13 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.GroupableSkin; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer; import com.tanishisherewith.dynamichud.utils.handlers.ScrollHandler; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ButtonTextures; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.resources.Identifier; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.network.chat.Component; import org.lwjgl.glfw.GLFW; import java.awt.*; @@ -29,18 +28,18 @@ * It tries to imitate the minecraft look and provides various form of panel shades {@link PanelColor} */ public class MinecraftSkin extends Skin implements GroupableSkin { - public static final ButtonTextures TEXTURES = new ButtonTextures( - Identifier.ofVanilla("widget/button"), - Identifier.ofVanilla("widget/button_disabled"), - Identifier.ofVanilla("widget/button_highlighted") + public static final WidgetSprites TEXTURES = new WidgetSprites( + Identifier.withDefaultNamespace("widget/button"), + Identifier.withDefaultNamespace("widget/button_disabled"), + Identifier.withDefaultNamespace("widget/button_highlighted") ); public static final int DEFAULT_SCROLLBAR_WIDTH = 8; public static final int DEFAULT_PANEL_WIDTH = 248; public static final int DEFAULT_PANEL_HEIGHT = 165; - public static final Identifier DEFAULT_BACKGROUND_PANEL = Identifier.ofVanilla("textures/gui/demo_background.png"); - public static final Identifier SCROLLER_TEXTURE = Identifier.ofVanilla("widget/scroller"); - public static final Identifier SCROLL_BAR_BACKGROUND = Identifier.ofVanilla("widget/scroller_background"); - public static final Identifier GROUP_BACKGROUND = Identifier.of(DynamicHUD.MOD_ID, "textures/minecraftskin/group_panel.png"); + public static final Identifier DEFAULT_BACKGROUND_PANEL = Identifier.withDefaultNamespace("textures/gui/demo_background.png"); + public static final Identifier SCROLLER_TEXTURE = Identifier.withDefaultNamespace("widget/scroller"); + public static final Identifier SCROLL_BAR_BACKGROUND = Identifier.withDefaultNamespace("widget/scroller_background"); + public static final Identifier GROUP_BACKGROUND = Identifier.fromNamespaceAndPath(DynamicHUD.MOD_ID, "textures/minecraftskin/group_panel.png"); private final Identifier BACKGROUND_PANEL; private final int panelWidth; @@ -76,12 +75,12 @@ public MinecraftSkin(PanelColor color) { setCreateNewScreen(true); } - private void enableContextMenuScissor() { - DrawHelper.enableScissor(0, imageY + 3, mc.getWindow().getScaledWidth(), panelHeight - 8); + private void enableContextMenuScissor(GuiGraphics graphics) { + DrawHelper.enableScissor(0, imageY + 3, mc.getWindow().getGuiScaledWidth(), panelHeight - 8,graphics); } private void createGroups() { - OptionGroup generalGroup = new OptionGroup(Text.of("General")); + OptionGroup generalGroup = new OptionGroup(Component.literal("General")); for (Option option : getOptions(contextMenu)) { if (option instanceof OptionGroup og) { optionGroups.add(og); @@ -104,13 +103,13 @@ private void initOptionGroups() { } @Override - public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int mouseX, int mouseY) { + public void renderContextMenu(GuiGraphics graphics, ContextMenu contextMenu, int mouseX, int mouseY) { this.contextMenu = contextMenu; initOptionGroups(); - int screenWidth = mc.getWindow().getScaledWidth(); - int screenHeight = mc.getWindow().getScaledHeight(); + int screenWidth = mc.getWindow().getGuiScaledWidth(); + int screenHeight = mc.getWindow().getGuiScaledHeight(); int centerX = screenWidth / 2; int centerY = screenHeight / 2; @@ -121,64 +120,60 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMen imageX = (screenWidth - panelWidth + 25) / 2; imageY = (screenHeight - panelHeight) / 2; - drawContext.drawTexture(RenderLayer::getGuiTextured, BACKGROUND_PANEL, imageX, imageY, 0, 0, panelWidth, panelHeight, 256, 254,panelColor.getColor()); + graphics.blit(RenderPipelines.GUI_TEXTURED, BACKGROUND_PANEL, imageX, imageY, 0, 0, panelWidth, panelHeight, 256, 254,panelColor.getColor()); - drawSingularButton(drawContext, "X", mouseX, mouseY, imageX + 3, imageY + 3, 14, 14); + drawSingularButton(graphics, "X", mouseX, mouseY, imageX + 3, imageY + 3, 14, 14); //Up and down arrows near the group panel int size = (int) (groupPanelWidth * 0.5f); - drawSingularButton(drawContext, "^", mouseX, mouseY, groupPanelX.getAsInt() + groupPanelWidth / 2 - size / 2, imageY - 14, size, 14, groupScrollHandler.isOffsetWithinBounds(-10)); - drawSingularButton(drawContext, "v", mouseX, mouseY, groupPanelX.getAsInt() + groupPanelWidth / 2 - size / 2, imageY + panelHeight - 2, size, 14, groupScrollHandler.isOffsetWithinBounds(10)); - drawContext.draw(); - // drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(true, isMouseOver(mouseX, mouseY, imageX + 3, imageY + 3, 14, 14)), imageX + 3, imageY + 3, 14, 14); - // drawContext.drawText(mc.textRenderer, "X", imageX + 10 - mc.textRenderer.getWidth("X") / 2, imageY + 6, -1, true); + drawSingularButton(graphics, "^", mouseX, mouseY, groupPanelX.getAsInt() + groupPanelWidth / 2 - size / 2, imageY - 14, size, 14, groupScrollHandler.isOffsetWithinBounds(-10)); + drawSingularButton(graphics, "v", mouseX, mouseY, groupPanelX.getAsInt() + groupPanelWidth / 2 - size / 2, imageY + panelHeight - 2, size, 14, groupScrollHandler.isOffsetWithinBounds(10)); + // graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(true, isMouseOver(mouseX, mouseY, imageX + 3, imageY + 3, 14, 14)), imageX + 3, imageY + 3, 14, 14); + // graphics.drawString(mc.font, "X", imageX + 10 - mc.font.width("X") / 2, imageY + 6, -1, true); - this.enableContextMenuScissor(); + this.enableContextMenuScissor(graphics); contextMenu.setWidth(panelWidth - 4); contextMenu.y = imageY; - renderOptionGroups(drawContext, mouseX, mouseY); - renderSelectedGroupOptions(drawContext, mouseX, mouseY); + renderOptionGroups(graphics, mouseX, mouseY); + renderSelectedGroupOptions(graphics, mouseX, mouseY); contextMenu.setHeight(getContentHeight() + 15); - drawScrollbar(drawContext); + drawScrollbar(graphics); scrollHandler.updateScrollOffset(getMaxScrollOffset()); // Disable scissor after rendering - DrawHelper.disableScissor(); + DrawHelper.disableScissor(graphics); } - public void drawSingularButton(DrawContext drawContext, String text, int mouseX, int mouseY, int x, int y, int width, int height, boolean enabled) { - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(enabled, isMouseOver(mouseX, mouseY, x, y, width, height)), x, y, width, height); - drawContext.drawText(mc.textRenderer, text, x + width / 2 - mc.textRenderer.getWidth(text) / 2, y + mc.textRenderer.fontHeight / 2 - 1, Color.WHITE.getRGB(), true); + public void drawSingularButton(GuiGraphics graphics, String Component, int mouseX, int mouseY, int x, int y, int width, int height, boolean enabled) { + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(enabled, isMouseOver(mouseX, mouseY, x, y, width, height)), x, y, width, height); + graphics.drawString(mc.font, Component, x + width / 2 - mc.font.width(Component) / 2, y + mc.font.lineHeight / 2 - 1, Color.WHITE.getRGB(), true); } - public void drawSingularButton(DrawContext drawContext, String text, int mouseX, int mouseY, int x, int y, int width, int height) { - this.drawSingularButton(drawContext, text, mouseX, mouseY, x, y, width, height, true); + public void drawSingularButton(GuiGraphics graphics, String Component, int mouseX, int mouseY, int x, int y, int width, int height) { + this.drawSingularButton(graphics, Component, mouseX, mouseY, x, y, width, height, true); } - private void renderOptionGroups(DrawContext drawContext, int mouseX, int mouseY) { + private void renderOptionGroups(GuiGraphics graphics, int mouseX, int mouseY) { int groupX = groupPanelX.getAsInt(); int groupY = imageY; - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); - drawContext.drawTexture(RenderLayer::getGuiTextured, GROUP_BACKGROUND, groupX - 10, groupY + 2, 0,0,groupPanelWidth + 20, panelHeight, 80, 158); - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); + graphics.blit(RenderPipelines.GUI_TEXTURED, GROUP_BACKGROUND, groupX - 10, groupY + 2, 0,0,groupPanelWidth + 20, panelHeight - 2, groupPanelWidth + 20, panelHeight - 3); int yOffset = groupY + 12 - groupScrollHandler.getScrollOffset(); for (OptionGroup group : optionGroups) { if (yOffset >= groupY + 12 && yOffset <= groupY + panelHeight - 15) { - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(!group.isExpanded(), isMouseOver(mouseX, mouseY, groupX, yOffset, groupPanelWidth, 20)), groupX, yOffset, groupPanelWidth, 20); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(!group.isExpanded(), isMouseOver(mouseX, mouseY, groupX, yOffset, groupPanelWidth, 20)), groupX, yOffset, groupPanelWidth, 20); - DrawHelper.drawScrollableText(drawContext, mc.textRenderer, group.getName(), groupX + groupPanelWidth / 2, groupX + 2, yOffset, groupX + groupPanelWidth - 2, yOffset + 20, -1); + DrawHelper.drawScrollableText(graphics, mc.font, group.getName(), groupX + groupPanelWidth / 2, groupX + 2, yOffset, groupX + groupPanelWidth - 2, yOffset + 20, -1); - //Scrollable text uses scissor, so we need to enable the context menu scissor again - this.enableContextMenuScissor(); + //Scrollable Component uses scissor, so we need to enable the context menu scissor again + this.enableContextMenuScissor(graphics); yOffset += 20; // Space for the header } @@ -186,24 +181,22 @@ private void renderOptionGroups(DrawContext drawContext, int mouseX, int mouseY) } groupScrollHandler.updateScrollOffset(yOffset - groupY - 12 + groupScrollHandler.getScrollOffset() - panelHeight); - - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); } - private int renderSelectedGroupOptions(DrawContext drawContext, int mouseX, int mouseY) { + private int renderSelectedGroupOptions(GuiGraphics graphics, int mouseX, int mouseY) { int yOffset = imageY + 12 - scrollHandler.getScrollOffset(); for (Option option : selectedGroup.getGroupOptions()) { if (!option.shouldRender()) continue; if (yOffset >= imageY - option.getHeight() && yOffset <= imageY + option.getHeight() + panelHeight) { - option.render(drawContext, imageX + 4, yOffset, mouseX, mouseY); + option.render(graphics, imageX + 4, yOffset, mouseX, mouseY); } yOffset += option.getHeight() + 1; } return yOffset; } - private void drawScrollbar(DrawContext drawContext) { + private void drawScrollbar(GuiGraphics graphics) { if (getMaxScrollOffset() > 0) { int scrollbarX = imageX + panelWidth + 10; int scrollbarY = imageY; @@ -211,8 +204,8 @@ private void drawScrollbar(DrawContext drawContext) { double handleHeight = panelHeight * ratio; int handleY = (int) (scrollbarY + (panelHeight - handleHeight) * ((double) scrollHandler.getScrollOffset() / getMaxScrollOffset())); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, SCROLL_BAR_BACKGROUND, scrollbarX, scrollbarY, DEFAULT_SCROLLBAR_WIDTH, panelHeight); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, SCROLLER_TEXTURE, scrollbarX, handleY, DEFAULT_SCROLLBAR_WIDTH, (int) handleHeight); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SCROLL_BAR_BACKGROUND, scrollbarX, scrollbarY, DEFAULT_SCROLLBAR_WIDTH, panelHeight); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SCROLLER_TEXTURE, scrollbarX, handleY, DEFAULT_SCROLLBAR_WIDTH, (int) handleHeight); } } @@ -238,7 +231,7 @@ public void mouseScrolled(ContextMenu menu, double mouseX, double mouseY, dou public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, int button) { if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { if (isMouseOver(mouseX, mouseY, imageX + 3, imageY + 3, 14, 14)) { - mc.getSoundManager().play(PositionedSoundInstance.master( + mc.getSoundManager().play(SimpleSoundInstance.forUI( SoundEvents.UI_BUTTON_CLICK, 1.0F)); contextMenu.close(); @@ -248,12 +241,12 @@ public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, i int size = (int) (groupPanelWidth * 0.5f); //Up and down button if (groupScrollHandler.isOffsetWithinBounds(-10) && isMouseOver(mouseX, mouseY, groupPanelX.getAsInt() + (double) groupPanelWidth / 2 - size / 2, imageY - 14, size, 14)) { - mc.getSoundManager().play(PositionedSoundInstance.master( + mc.getSoundManager().play(SimpleSoundInstance.forUI( SoundEvents.UI_BUTTON_CLICK, 1.0F)); groupScrollHandler.addOffset(-10); } if (groupScrollHandler.isOffsetWithinBounds(10) && isMouseOver(mouseX, mouseY, groupPanelX.getAsInt() + (double) groupPanelWidth / 2 - size / 2, imageY + panelHeight - 2, size, 14)) { - mc.getSoundManager().play(PositionedSoundInstance.master( + mc.getSoundManager().play(SimpleSoundInstance.forUI( SoundEvents.UI_BUTTON_CLICK, 1.0F)); groupScrollHandler.addOffset(10); } @@ -336,7 +329,7 @@ public int getImageY() { * Group rendering handled already */ @Override - public void renderGroup(DrawContext drawContext, OptionGroup group, int groupX, int groupY, int mouseX, int mouseY) { + public void renderGroup(GuiGraphics graphics, OptionGroup group, int groupX, int groupY, int mouseX, int mouseY) { } public enum PanelColor { @@ -378,9 +371,6 @@ public static PanelColor custom(float red, float green, float blue, float alpha) return custom; } - public void applyColor() { - RenderSystem.setShaderColor(red, green, blue, alpha); - } public int getColor() { return new Color(red,green,blue,alpha).getRGB(); } @@ -388,19 +378,17 @@ public int getColor() { public class MinecraftBooleanRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, BooleanOption option, int x, int y, int mouseX, int mouseY) { - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); + public void render(GuiGraphics graphics, BooleanOption option, int x, int y, int mouseX, int mouseY) { + graphics.drawString(mc.font, option.name, x + 15, y + 25 / 2 - 5, -1, true); option.setPosition(x + panelWidth - 75, y); int width = 50; - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, width, 20); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, width, 20); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - Text text = option.getBooleanType().getText(option.value); + Component Component = option.getBooleanType().getText(option.value); int color = option.value ? Color.GREEN.getRGB() : Color.RED.getRGB(); - drawContext.drawText(mc.textRenderer, text, (int) (option.getX() + (width / 2.0f) - (mc.textRenderer.getWidth(text) / 2.0f)), y + 5, color, true); + graphics.drawString(mc.font, Component, (int) (option.getX() + (width / 2.0f) - (mc.font.width(Component) / 2.0f)), y + 5, color, true); option.setHeight(25); @@ -416,19 +404,16 @@ public boolean mouseClicked(BooleanOption option, double mouseX, double mouseY, public class MinecraftColorOptionRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, ColorOption option, int x, int y, int mouseX, int mouseY) { - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); + public void render(GuiGraphics graphics, ColorOption option, int x, int y, int mouseX, int mouseY) { + graphics.drawString(mc.font, option.name, x + 15, y + 25 / 2 - 5, -1, true); option.setPosition(x + panelWidth - 45, y); int width = 20; - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(!option.isVisible, option.isMouseOver(mouseX, mouseY)), option.getX(), y, width, 20); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(!option.isVisible, option.isMouseOver(mouseX, mouseY)), option.getX(), y, width, 20); int shadowOpacity = Math.min(option.value.getAlpha(), 45); - drawContext.draw(); - DrawHelper.drawRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRectangleWithShadowBadWay(graphics, option.getX() + 4, y + 4, width - 8, @@ -437,18 +422,17 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in shadowOpacity, 1, 1); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); option.setHeight(25); option.setWidth(width); if (option.getColorGradient().getColorPickerButton().isPicking()) { - DrawHelper.disableScissor(); // Disable scissor test for the colorpicker + DrawHelper.disableScissor(graphics); // Disable scissor test for the colorpicker } //TODO: WHAT IS THISSSSS int colorGradientWidth = option.getColorGradient().getBoxSize() + option.getColorGradient().getAlphaSlider().getWidth() + option.getColorGradient().getColorPickerButton().getWidth(); - option.getColorGradient().render(drawContext, x + panelWidth / 2 - colorGradientWidth / 2, y + 12, mouseX, mouseY); + option.getColorGradient().render(graphics, x + panelWidth / 2 - colorGradientWidth / 2, y + 12, mouseX, mouseY); if (option.getColorGradient().shouldDisplay()) { int colorGradientHeight = option.getColorGradient().getBoxSize() + 10 + option.getColorGradient().getGradientSlider().getHeight(); @@ -456,16 +440,16 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in } if (option.getColorGradient().getColorPickerButton().isPicking()) { - DrawHelper.enableScissor(imageX, imageY + 2, panelWidth, panelHeight - 4); + DrawHelper.enableScissor(imageX, imageY + 2, panelWidth, panelHeight - 4, graphics); } } } public class MinecraftDoubleRenderer implements SkinRenderer { - private static final Identifier TEXTURE = Identifier.ofVanilla("widget/slider"); - private static final Identifier HIGHLIGHTED_TEXTURE = Identifier.ofVanilla("widget/slider_highlighted"); - private static final Identifier HANDLE_TEXTURE = Identifier.ofVanilla("widget/slider_handle"); - private static final Identifier HANDLE_HIGHLIGHTED_TEXTURE = Identifier.ofVanilla("widget/slider_handle_highlighted"); + private static final Identifier TEXTURE = Identifier.withDefaultNamespace("widget/slider"); + private static final Identifier HIGHLIGHTED_TEXTURE = Identifier.withDefaultNamespace("widget/slider_highlighted"); + private static final Identifier HANDLE_TEXTURE = Identifier.withDefaultNamespace("widget/slider_handle"); + private static final Identifier HANDLE_HIGHLIGHTED_TEXTURE = Identifier.withDefaultNamespace("widget/slider_handle_highlighted"); @Override public void init(DoubleOption option) { @@ -473,8 +457,8 @@ public void init(DoubleOption option) { } @Override - public void render(DrawContext drawContext, DoubleOption option, int x, int y, int mouseX, int mouseY) { - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); + public void render(GuiGraphics graphics, DoubleOption option, int x, int y, int mouseX, int mouseY) { + graphics.drawString(mc.font, option.name, x + 15, y + 25 / 2 - 5, -1, true); option.setWidth(panelWidth - 150); option.setHeight(25); @@ -483,16 +467,15 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i double sliderX = option.getX() + ((option.value - option.minValue) / (option.maxValue - option.minValue)) * (option.getWidth() - 8); boolean isMouseOverHandle = isMouseOver(mouseX, mouseY, sliderX, y, 10, 20); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, option.isMouseOver(mouseX, mouseY) ? HIGHLIGHTED_TEXTURE : TEXTURE, option.getX(), y, option.getWidth(), 20); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, isMouseOverHandle ? HANDLE_HIGHLIGHTED_TEXTURE : HANDLE_TEXTURE, (int) Math.round(sliderX), y, 8, 20); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - // Determine the number of decimal places in option.step + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, option.isMouseOver(mouseX, mouseY) ? HIGHLIGHTED_TEXTURE : TEXTURE, option.getX(), y, option.getWidth(), 20); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, isMouseOverHandle ? HANDLE_HIGHLIGHTED_TEXTURE : HANDLE_TEXTURE, (int) Math.round(sliderX), y, 8, 20); + + // Determine the number of decimal places in option.step int decimalPlaces = String.valueOf(option.step).split("\\.")[1].length(); // Format option.value to the determined number of decimal places String formattedValue = String.format("%." + decimalPlaces + "f", option.value); - drawContext.drawText(mc.textRenderer, formattedValue, option.getX() + option.getWidth() / 2 - mc.textRenderer.getWidth(formattedValue) / 2, y + 5, 16777215, false); + graphics.drawCenteredString(mc.font, formattedValue, option.getX() + option.getWidth() / 2, y + Math.round((float) mc.font.lineHeight /2), -1); } @Override @@ -506,7 +489,7 @@ public class MinecraftEnumRenderer> implements SkinRenderer option) { for (E enumConstant : option.getValues()) { - int width = mc.textRenderer.getWidth(enumConstant.name()) + 5; + int width = mc.font.width(enumConstant.name()) + 5; if (width > maxWidth) { maxWidth = width; } @@ -514,20 +497,18 @@ private void calculateMaxWidth(EnumOption option) { } @Override - public void render(DrawContext drawContext, EnumOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, EnumOption option, int x, int y, int mouseX, int mouseY) { calculateMaxWidth(option); option.setHeight(25); option.setWidth(maxWidth); - drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true); + graphics.drawString(mc.font, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true); option.setPosition(x + panelWidth - maxWidth - 25, y); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, maxWidth, 20); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - String text = option.get().toString(); - drawContext.drawText(mc.textRenderer, text, option.getX() + maxWidth / 2 - mc.textRenderer.getWidth(text) / 2, y + 5, Color.CYAN.getRGB(), true); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, maxWidth, 20); + String Component = option.get().toString(); + graphics.drawString(mc.font, Component, option.getX() + maxWidth / 2 - mc.font.width(Component) / 2, y + 5, Color.CYAN.getRGB(), true); } } @@ -536,7 +517,7 @@ public class MinecraftListRenderer implements SkinRenderer> { private void calculateMaxWidth(ListOption option) { for (E listValues : option.getValues()) { - int width = mc.textRenderer.getWidth(listValues.toString()) + 5; + int width = mc.font.width(listValues.toString()) + 5; if (width > maxWidth) { maxWidth = width; } @@ -544,40 +525,36 @@ private void calculateMaxWidth(ListOption option) { } @Override - public void render(DrawContext drawContext, ListOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, ListOption option, int x, int y, int mouseX, int mouseY) { calculateMaxWidth(option); option.setHeight(25); option.setWidth(maxWidth); - drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true); + graphics.drawString(mc.font, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true); option.setPosition(x + panelWidth - maxWidth - 25, y); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, maxWidth, 20); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - String text = option.get().toString(); - drawContext.drawText(mc.textRenderer, text, option.getX() + maxWidth / 2 - mc.textRenderer.getWidth(text) / 2, y + 5, Color.CYAN.getRGB(), true); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, maxWidth, 20); + String Component = option.get().toString(); + graphics.drawString(mc.font, Component, option.getX() + maxWidth / 2 - mc.font.width(Component) / 2, y + 5, Color.CYAN.getRGB(), true); } } public class MinecraftSubMenuRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, SubMenuOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, SubMenuOption option, int x, int y, int mouseX, int mouseY) { option.setHeight(20); option.setWidth(30); - drawContext.drawText(mc.textRenderer, option.name, x + 15, y + 25 / 2 - 5, -1, true); + graphics.drawString(mc.font, option.name, x + 15, y + 25 / 2 - 5, -1, true); option.setPosition(x + panelWidth - 55, y); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, option.getWidth(), 20); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - String text = "Open"; - drawContext.drawText(mc.textRenderer, text, option.getX() + option.getWidth() / 2 - mc.textRenderer.getWidth(text) / 2, y + 5, Color.YELLOW.getRGB(), true); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(true, option.isMouseOver(mouseX, mouseY)), option.getX(), y, option.getWidth(), 20); + String Component = "Open"; + graphics.drawString(mc.font, Component, option.getX() + option.getWidth() / 2 - mc.font.width(Component) / 2, y + 5, Color.YELLOW.getRGB(), true); - option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y, mouseX, mouseY); + option.getSubMenu().render(graphics, x + option.getParentMenu().getWidth(), y, mouseX, mouseY); } } @@ -586,18 +563,16 @@ public class MinecraftRunnableRenderer implements SkinRenderer { Color DARK_GREEN = new Color(24, 132, 0, 226); @Override - public void render(DrawContext drawContext, RunnableOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, RunnableOption option, int x, int y, int mouseX, int mouseY) { option.setHeight(25); option.setWidth(26); - drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true); + graphics.drawString(mc.font, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true); option.setPosition(x + panelWidth - 51, y); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - drawContext.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURES.get(!option.value, option.isMouseOver(mouseX, mouseY)), option.getX(), y, option.getWidth(), 20); - drawContext.drawText(mc.textRenderer, "Run", option.getX() + option.getWidth() / 2 - mc.textRenderer.getWidth("Run") / 2, y + 5, option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(), true); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, TEXTURES.get(!option.value, option.isMouseOver(mouseX, mouseY)), option.getX(), y, option.getWidth(), 20); + graphics.drawString(mc.font, "Run", option.getX() + option.getWidth() / 2 - mc.font.width("Run") / 2, y + 5, option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(), true); } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java index 17fc98d..6d3b809 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ModernSkin.java @@ -1,6 +1,5 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem; -import com.mojang.blaze3d.systems.RenderSystem; import com.tanishisherewith.dynamichud.helpers.ColorHelper; import com.tanishisherewith.dynamichud.helpers.DrawHelper; import com.tanishisherewith.dynamichud.helpers.animationhelper.EasingType; @@ -11,14 +10,12 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.GroupableSkin; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer; import com.tanishisherewith.dynamichud.utils.handlers.ScrollHandler; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.OrderedText; -import net.minecraft.text.StringVisitable; -import net.minecraft.text.Text; -import net.minecraft.util.math.MathHelper; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.util.Mth; import org.lwjgl.glfw.GLFW; import java.awt.*; @@ -32,18 +29,18 @@ public class ModernSkin extends Skin implements GroupableSkin { private final Color themeColor; private final float radius; - private final Text defaultToolTipHeader; - private final Text defaultToolTipText; + private final Component defaultToolTipHeader; + private final Component defaultToolTipText; private int contextMenuX = 0, contextMenuY = 0; private int width = 0, height = 0; private float scaledWidth = 0, scaledHeight = 0; - private Text TOOLTIP_TEXT; - private Text TOOLTIP_HEAD; + private Component TOOLTIP_TEXT; + private Component TOOLTIP_HEAD; private static int SCALE_FACTOR = 4; private final ScrollHandler scrollHandler; - public ModernSkin(Color themeColor, float radius, Text defaultToolTipHeader, Text defaultToolTipText) { + public ModernSkin(Color themeColor, float radius, Component defaultToolTipHeader, Component defaultToolTipText) { this.themeColor = themeColor; this.radius = radius; TOOLTIP_TEXT = defaultToolTipText; @@ -65,7 +62,7 @@ public ModernSkin(Color themeColor, float radius, Text defaultToolTipHeader, Tex } public ModernSkin(Color themeColor, float radius) { - this(themeColor, radius, Text.of("Example Tip"), Text.of("Hover over a setting to see its tool-tip (if present) here!")); + this(themeColor, radius, Component.literal("Example Tip"), Component.literal("Hover over a setting to see its tool-tip (if present) here!")); } public ModernSkin(Color themeColor) { @@ -81,33 +78,33 @@ public LayoutContext.Offset getGroupIndent() { return new LayoutContext.Offset(2, 2); } - public void enableSkinScissor() { - DrawHelper.enableScissor(contextMenuX + (int) (width * 0.2f) + 10, contextMenuY + 19, (int) (width * 0.8f - 14), height - 23, SCALE_FACTOR); + public void enableSkinScissor(GuiGraphics graphics) { + DrawHelper.enableScissor(contextMenuX + (int) (width * 0.2f) + 10, contextMenuY + 19, (int) (width * 0.8f - 14), height - 23, SCALE_FACTOR, graphics); } @Override - public void renderGroup(DrawContext drawContext, OptionGroup group, int groupX, int groupY, int mouseX, int mouseY) { - mouseX = (int) (mc.mouse.getX() / SCALE_FACTOR); - mouseY = (int) (mc.mouse.getY() / SCALE_FACTOR); + public void renderGroup(GuiGraphics graphics, OptionGroup group, int groupX, int groupY, int mouseX, int mouseY) { + mouseX = (int) (mc.mouseHandler.xpos() / SCALE_FACTOR); + mouseY = (int) (mc.mouseHandler.ypos() / SCALE_FACTOR); if (group.isExpanded() && group.getHeight() > 20) { - DrawHelper.drawRoundedRectangle(drawContext, + DrawHelper.drawRoundedRectangle(graphics, groupX + 1, groupY + 14, width - groupX - 8 + contextMenuX, group.getHeight() - 16, radius, DARKER_GRAY_2.getRGB()); } - Text groupText = group.name.copy().append(" " + (group.isExpanded() ? "-" : "+")); + Component groupText = group.name.copy().append(" " + (group.isExpanded() ? "-" : "+")); - DrawHelper.drawRoundedRectangle(drawContext, - groupX + 1, groupY + 1, true, true, !group.isExpanded(), !group.isExpanded(), mc.textRenderer.getWidth(groupText) + 6, 16, radius, DARKER_GRAY_2.getRGB()); + DrawHelper.drawRoundedRectangle(graphics, + groupX + 1, groupY + 1, true, true, !group.isExpanded(), !group.isExpanded(), mc.font.width(groupText) + 6, 16, radius, DARKER_GRAY_2.getRGB()); - drawContext.drawText(mc.textRenderer, groupText, groupX + 4, groupY + 4, -1, true); + graphics.drawString(mc.font, groupText, groupX + 4, groupY + 4, -1, true); if (group.isExpanded()) { - int yOffset = groupY + 16 + getGroupIndent().top; + int yOffset = groupY + 16 + getGroupIndent().top(); for (Option option : group.getGroupOptions()) { if (!option.shouldRender()) continue; - option.render(drawContext, groupX + getGroupIndent().left, yOffset, mouseX, mouseY); + option.render(graphics, groupX + getGroupIndent().left(), yOffset, mouseX, mouseY); yOffset += option.getHeight() + 1; } @@ -117,25 +114,25 @@ public void renderGroup(DrawContext drawContext, OptionGroup group, int groupX, } } - private void drawScrollbar(DrawContext drawContext) { + private void drawScrollbar(GuiGraphics graphics) { if (getMaxScrollOffset() > 0) { int scrollbarX = contextMenuX + width + 5; // Position at the right of the panel int scrollbarY = contextMenuY + 19; // Position below the header int handleHeight = (int) ((float) (height - 23) * ((height - 23) / (float) contextMenu.getHeight())); int handleY = scrollbarY + (int) ((float) ((height - 23) - handleHeight) * ((float) scrollHandler.getScrollOffset() / getMaxScrollOffset())); - DrawHelper.drawRoundedRectangle(drawContext, scrollbarX, scrollbarY, 2, height - 23, 1, DARKER_GRAY.getRGB()); - DrawHelper.drawRoundedRectangle(drawContext, scrollbarX, handleY, 2, handleHeight, 1, Color.LIGHT_GRAY.getRGB()); + DrawHelper.drawRoundedRectangle(graphics, scrollbarX, scrollbarY, 2, height - 23, 1, DARKER_GRAY.getRGB()); + DrawHelper.drawRoundedRectangle(graphics, scrollbarX, handleY, 2, handleHeight, 1, Color.LIGHT_GRAY.getRGB()); } } @Override - public void renderContextMenu(DrawContext drawContext, ContextMenu contextMenu, int mouseX, int mouseY) { + public void renderContextMenu(GuiGraphics graphics, ContextMenu contextMenu, int mouseX, int mouseY) { //This is equivalent to "Auto" GUI scale in minecraft options - SCALE_FACTOR = mc.getWindow().calculateScaleFactor(0, mc.forcesUnicodeFont()); + SCALE_FACTOR = mc.getWindow().calculateScale(0, mc.isEnforceUnicode()); - mouseX = (int) (mc.mouse.getX() / SCALE_FACTOR); - mouseY = (int) (mc.mouse.getY() / SCALE_FACTOR); + mouseX = (int) (mc.mouseHandler.xpos() / SCALE_FACTOR); + mouseY = (int) (mc.mouseHandler.ypos() / SCALE_FACTOR); // Apply custom scaling to counteract Minecraft's default scaling DrawHelper.customScaledProjection(SCALE_FACTOR); @@ -144,19 +141,19 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMen contextMenu.set(contextMenuX, contextMenuY, 0); //Background - DrawHelper.drawRoundedRectangle(drawContext, + DrawHelper.drawRoundedRectangle(graphics, contextMenuX, contextMenuY, width, height, radius, DARKER_GRAY.getRGB()); - drawBackButton(drawContext, mouseX, mouseY); + drawBackButton(graphics, mouseX, mouseY); //OptionStartX = Tool-Tip width + padding int optionStartX = contextMenu.x + (int) (width * 0.2f) + 10; //Background behind the options - DrawHelper.drawRoundedRectangle(drawContext, + DrawHelper.drawRoundedRectangle(graphics, optionStartX, contextMenuY + 19, width * 0.8f - 14, height - 23, radius, DARK_GRAY.getRGB()); - enableSkinScissor(); + enableSkinScissor(graphics); int yOffset = contextMenu.y + 19 + 3 - scrollHandler.getScrollOffset(); for (Option option : getOptions(contextMenu)) { if (!option.shouldRender()) continue; @@ -166,59 +163,57 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu contextMen } if (option instanceof OptionGroup group) { - this.renderGroup(drawContext, group, optionStartX + 2, yOffset, mouseX, mouseY); + this.renderGroup(graphics, group, optionStartX + 2, yOffset, mouseX, mouseY); } else { - option.render(drawContext, optionStartX + 2, yOffset, mouseX, mouseY); + option.render(graphics, optionStartX + 2, yOffset, mouseX, mouseY); } yOffset += option.getHeight() + 1; } - drawContext.draw(); - RenderSystem.disableScissor(); + DrawHelper.disableScissor(graphics); contextMenu.setWidth(width); contextMenu.setHeight(yOffset - (contextMenu.y + 19 + 3 - scrollHandler.getScrollOffset()) + 4); scrollHandler.updateScrollOffset(getMaxScrollOffset()); - drawScrollbar(drawContext); + drawScrollbar(graphics); - renderToolTipText(drawContext, mouseX, mouseY); + renderToolTipText(graphics, mouseX, mouseY); //Reset our scaling so minecraft runs normally\ DrawHelper.scaledProjection(); } private void updateContextDimensions() { - scaledWidth = (float) mc.getWindow().getFramebufferWidth() / SCALE_FACTOR; - scaledHeight = (float) mc.getWindow().getFramebufferHeight() / SCALE_FACTOR; + scaledWidth = (float) mc.getWindow().getWidth() / SCALE_FACTOR; + scaledHeight = (float) mc.getWindow().getHeight() / SCALE_FACTOR; contextMenuX = (int) (scaledWidth * 0.1f); contextMenuY = (int) (scaledHeight * 0.1f); width = (int) (scaledWidth * 0.8f); height = (int) (scaledHeight * 0.8f); } - public void drawBackButton(DrawContext drawContext, int mouseX, int mouseY) { + public void drawBackButton(GuiGraphics graphics, int mouseX, int mouseY) { String backText = "< Back"; - int textWidth = mc.textRenderer.getWidth(backText); + int textWidth = mc.font.width(backText); boolean isHoveringOver = isMouseOver(mouseX, mouseY, contextMenuX + 2, contextMenuY + 2, textWidth + 8, 14); int color = isHoveringOver ? themeColor.darker().getRGB() : themeColor.getRGB(); - DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRoundedRectangleWithShadowBadWay(graphics, contextMenuX + 2, contextMenuY + 2, textWidth + 8, 14, radius, color, 125, 2, 2); - drawContext.drawText(mc.textRenderer, backText, contextMenuX + 6, contextMenuY + 5, -1, true); - drawContext.draw(); + graphics.drawString(mc.font, backText, contextMenuX + 6, contextMenuY + 5, -1, true); } - public void renderToolTipText(DrawContext drawContext, int mouseX, int mouseY) { + public void renderToolTipText(GuiGraphics graphics, int mouseX, int mouseY) { int tooltipY = contextMenuY + 19; int toolTipWidth = (int) (width * 0.2f) + 4; int toolTipHeight = (int) (height * 0.16f); if (!TOOLTIP_TEXT.getString().isEmpty()) { - toolTipHeight = Math.max(toolTipHeight, mc.textRenderer.getWrappedLinesHeight(TOOLTIP_TEXT, toolTipWidth)) + 18; + toolTipHeight = Math.max(toolTipHeight, mc.font.wordWrapHeight(TOOLTIP_TEXT, toolTipWidth)) + 18; toolTipHeight = Math.min(height - 23, toolTipHeight); } @@ -226,7 +221,7 @@ public void renderToolTipText(DrawContext drawContext, int mouseX, int mouseY) { // Draw background DrawHelper.drawRoundedRectangle( - drawContext, + graphics, contextMenuX + 2, tooltipY, toolTipWidth, @@ -235,7 +230,7 @@ public void renderToolTipText(DrawContext drawContext, int mouseX, int mouseY) { DARK_GRAY.getRGB() ); DrawHelper.drawHorizontalLine( - drawContext, + graphics, contextMenuX + 2, toolTipWidth, tooltipY + 16, @@ -248,9 +243,9 @@ public void renderToolTipText(DrawContext drawContext, int mouseX, int mouseY) { return; } - //Draw the head text - drawContext.drawText( - mc.textRenderer, + //Draw the head Component + graphics.drawString( + mc.font, TOOLTIP_HEAD, contextMenuX + 4, tooltipY + 4, @@ -258,31 +253,30 @@ public void renderToolTipText(DrawContext drawContext, int mouseX, int mouseY) { true ); - List wrappedText = mc.textRenderer.wrapLines(StringVisitable.styled(TOOLTIP_TEXT.getString(), TOOLTIP_TEXT.getStyle()), toolTipWidth); + List wrappedText = mc.font.split(TOOLTIP_TEXT, toolTipWidth); - DrawHelper.scaleAndPosition(drawContext.getMatrices(), contextMenuX + 4, tooltipY + 19, textScale); + DrawHelper.scaleAndPosition(graphics.pose(), contextMenuX + 4, tooltipY + 19, textScale); - // Draw text + // Draw Component int textY = tooltipY + 19; - for (OrderedText line : wrappedText) { - drawContext.drawText( - mc.textRenderer, + for (FormattedCharSequence line : wrappedText) { + graphics.drawString( + mc.font, line, contextMenuX + 2 + 2, textY, -1, false ); - textY += mc.textRenderer.fontHeight; + textY += mc.font.lineHeight; } - drawContext.draw(); - DrawHelper.stopScaling(drawContext.getMatrices()); + DrawHelper.stopScaling(graphics.pose()); setTooltipText(defaultToolTipHeader, defaultToolTipText); } - public void setTooltipText(Text head_text, Text tooltip_text) { + public void setTooltipText(Component head_text, Component tooltip_text) { TOOLTIP_TEXT = tooltip_text; TOOLTIP_HEAD = head_text; } @@ -305,8 +299,8 @@ public boolean mouseReleased(ContextMenu menu, double mouseX, double mouseY, @Override public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, contextMenuX + width - 5, contextMenuY, 7, height)) { scrollHandler.startDragging(mouseY); @@ -320,7 +314,7 @@ public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, i if (option instanceof OptionGroup group) { if (isMouseOver(mouseX, mouseY, optionStartX + 2, yOffset, - mc.textRenderer.getWidth(group.name + " " + (group.isExpanded() ? "-" : "+")) + 6, + mc.font.width(group.name + " " + (group.isExpanded() ? "-" : "+")) + 6, 16)) { group.setExpanded(!group.isExpanded()); break; @@ -330,8 +324,8 @@ public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, i yOffset += option.getHeight() + 1; } } - if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, contextMenuX + 2, contextMenuY + 2, mc.textRenderer.getWidth("< Back") + 8, 14)) { - mc.getSoundManager().play(PositionedSoundInstance.master( + if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, contextMenuX + 2, contextMenuY + 2, mc.font.width("< Back") + 8, 14)) { + mc.getSoundManager().play(SimpleSoundInstance.forUI( SoundEvents.UI_BUTTON_CLICK, 1.0F)); contextMenu.close(); } @@ -340,8 +334,8 @@ public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, i @Override public boolean mouseDragged(ContextMenu menu, double mouseX, double mouseY, int button, double deltaX, double deltaY) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, contextMenuX + width - 5, contextMenuY, 7, height)) { scrollHandler.updateScrollPosition(mouseY); @@ -357,15 +351,13 @@ public class ModernBooleanRenderer implements SkinRenderer { private long animationStartTime; @Override - public void render(DrawContext drawContext, BooleanOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, BooleanOption option, int x, int y, int mouseX, int mouseY) { int backgroundWidth = (int) (width * 0.8f - 14); option.setHeight(14); option.setPosition(x, y); option.setWidth(backgroundWidth); - MatrixStack matrices = drawContext.getMatrices(); - // Calculate the current progress of the animation int toggleBgX = x + backgroundWidth - 30; // Background @@ -374,7 +366,7 @@ public void render(DrawContext drawContext, BooleanOption option, int x, int y, Color hoveredColor = isMouseOver(mouseX, mouseY, toggleBgX, y + 2, 14, 7) ? backgroundColor.darker() : backgroundColor; DrawHelper.drawRoundedRectangleWithShadowBadWay( - drawContext, + graphics, toggleBgX, y + 2, 14, 7, 3, hoveredColor.getRGB(), @@ -387,11 +379,11 @@ public void render(DrawContext drawContext, BooleanOption option, int x, int y, EasingType easingType = active ? EasingType.EASE_IN_CUBIC : EasingType.EASE_OUT_QUAD; float toggleX = MathAnimations.lerp(startX, endX, animationStartTime, 200f, easingType); - DrawHelper.drawFilledCircle(drawContext, toggleX, y + 2 + 3.3f, 2.8f, Color.WHITE.getRGB()); + DrawHelper.drawFilledCircle(graphics, toggleX, y + 2 + 3.3f, 2.8f, Color.WHITE.getRGB()); // Draw option name - drawContext.drawText( - mc.textRenderer, + graphics.drawString( + mc.font, option.name, x + 2, y + 4, @@ -402,8 +394,8 @@ public void render(DrawContext drawContext, BooleanOption option, int x, int y, @Override public boolean mouseClicked(BooleanOption option, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; int backgroundWidth = (int) (width * 0.8f - 14); int toggleBgX = option.getX() + backgroundWidth - 30; @@ -430,21 +422,21 @@ public void update(ColorOption option) { if (!display) { scale -= ANIMATION_SPEED; } - scale = MathHelper.clamp(scale, 0, 1.0f); + scale = Math.clamp(scale, 0, 1.0f); if (scale <= 0) { option.getColorGradient().close(); } } @Override - public void render(DrawContext drawContext, ColorOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, ColorOption option, int x, int y, int mouseX, int mouseY) { update(option); int backgroundWidth = (int) (width * 0.8f - 14); // Draw option name - drawContext.drawText( - mc.textRenderer, + graphics.drawString( + mc.font, option.name, x + 2, y + 5, @@ -461,7 +453,7 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in //The shape behind the preview Color behindColor = isMouseOver(mouseX, mouseY, x + backgroundWidth - width - 17, y + 1, width + 2, 14) ? getThemeColor().darker().darker() : getThemeColor(); - DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRoundedRectangleWithShadowBadWay(graphics, x + backgroundWidth - width - 17, y + 1, width + 2, @@ -473,8 +465,8 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in 1); //The letter above the shape behind the preview - drawContext.drawText( - mc.textRenderer, + graphics.drawString( + mc.font, option.getColorGradient().shouldDisplay() ? "^" : "v", x + backgroundWidth - 21, y + 4, @@ -483,7 +475,7 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in ); //Preview - DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext, + DrawHelper.drawRoundedRectangleWithShadowBadWay(graphics, x + backgroundWidth - width - 15, y + 2, width - 8, @@ -499,22 +491,22 @@ public void render(DrawContext drawContext, ColorOption option, int x, int y, in option.setWidth(width); if (option.getColorGradient().getColorPickerButton().isPicking()) { - RenderSystem.disableScissor(); //Disable scissor so the color picker preview works + DrawHelper.disableScissor(graphics); //Disable scissor so the color picker preview works } - DrawHelper.scaleAndPosition(drawContext.getMatrices(), x + backgroundWidth / 2.0f, y, scale); - option.getColorGradient().render(drawContext, x + backgroundWidth / 2 - 50, y + 6, mouseX, mouseY); - DrawHelper.stopScaling(drawContext.getMatrices()); + DrawHelper.scaleAndPosition(graphics.pose(), x + backgroundWidth / 2.0f, y, scale); + option.getColorGradient().render(graphics, x + backgroundWidth / 2 - 50, y + 6, mouseX, mouseY); + DrawHelper.stopScaling(graphics.pose()); if (option.getColorGradient().getColorPickerButton().isPicking()) { - enableSkinScissor(); // re-enable the scissor + enableSkinScissor(graphics); // re-enable the scissor } } @Override public boolean mouseClicked(ColorOption option, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, option.getX() + (int) (width * 0.8f - 14) - 37, option.getY(), 22, 16)) { option.isVisible = !option.isVisible; if (option.isVisible) { @@ -531,16 +523,16 @@ public boolean mouseClicked(ColorOption option, double mouseX, double mouseY, in @Override public boolean mouseDragged(ColorOption option, double mouseX, double mouseY, int button, double deltaX, double deltaY) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; option.getColorGradient().mouseDragged(mouseX, mouseY, button); return SkinRenderer.super.mouseDragged(option, mouseX, mouseY, button, deltaX, deltaY); } @Override public boolean mouseReleased(ColorOption option, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; option.getColorGradient().mouseReleased(mouseX, mouseY, button); return SkinRenderer.super.mouseReleased(option, mouseX, mouseY, button); @@ -552,10 +544,10 @@ public class ModernDoubleRenderer implements SkinRenderer { private static final float ANIMATION_SPEED = 0.1f; @Override - public void render(DrawContext drawContext, DoubleOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, DoubleOption option, int x, int y, int mouseX, int mouseY) { // Draw option name - drawContext.drawText( - mc.textRenderer, + graphics.drawString( + mc.font, option.name, x + 2, y, @@ -573,11 +565,11 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i option.setHeight(14); // Smoothly interpolate to the new value - displayValue = MathHelper.lerp(ANIMATION_SPEED, displayValue, option.get()); + displayValue = Mth.lerp(ANIMATION_SPEED, displayValue, option.get()); // Background DrawHelper.drawRoundedRectangle( - drawContext, + graphics, sliderX, y, sliderBackgroundWidth, sliderBackgroundHeight, 1, DARKER_GRAY.getRGB() ); @@ -585,32 +577,32 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i int activeFillWidth = (int) ((displayValue - option.minValue) / (option.maxValue - option.minValue) * option.getWidth()); Color fillColor = isMouseOver(mouseX, mouseY, sliderX, y, sliderBackgroundWidth, sliderBackgroundHeight + 4) ? getThemeColor().darker().darker() : getThemeColor(); DrawHelper.drawRoundedRectangle( - drawContext, + graphics, sliderX, y, activeFillWidth, sliderBackgroundHeight, 2, fillColor.getRGB() ); // Draw slider handle float sliderHandleX = sliderX + activeFillWidth - 5; - DrawHelper.drawFilledCircle(drawContext, sliderHandleX + 5, y + 1, 2, Color.WHITE.getRGB()); - - // Draw value text - String text = String.format("%.2f", displayValue); - DrawHelper.scaleAndPosition(drawContext.getMatrices(), sliderX + 120 - mc.textRenderer.getWidth(text), y + 7, 0.6f); - drawContext.drawText( - mc.textRenderer, - text, - sliderX + sliderBackgroundWidth + 10 - mc.textRenderer.getWidth(text), + DrawHelper.drawFilledCircle(graphics, sliderHandleX + 5, y + 1, 2, Color.WHITE.getRGB()); + + // Draw value Component + String Component = String.format("%.2f", displayValue); + DrawHelper.scaleAndPosition(graphics.pose(), sliderX + 120 - mc.font.width(Component), y + 7, 0.6f); + graphics.drawString( + mc.font, + Component, + sliderX + sliderBackgroundWidth + 10 - mc.font.width(Component), y + 2, -1, true ); - drawContext.getMatrices().pop(); + graphics.pose().popMatrix(); } @Override public boolean mouseClicked(DoubleOption option, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT && isMouseOver(mouseX, mouseY, option.getX() + (int) (width * 0.8f - 14) - 125, option.getY() - 1, option.getWidth() + 2, option.getHeight() + 1)) { option.setDragging(true); return true; @@ -621,7 +613,7 @@ public boolean mouseClicked(DoubleOption option, double mouseX, double mouseY, i @Override public boolean mouseDragged(DoubleOption option, double mouseX, double mouseY, int button, double deltaX, double deltaY) { if (option.isDragging()) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; int backgroundWidth = (int) (width * 0.8f - 14); int sliderBackgroundWidth = 120; int sliderX = option.getX() + backgroundWidth - sliderBackgroundWidth - 10; @@ -643,66 +635,66 @@ public boolean mouseReleased(DoubleOption option, double mouseX, double mouseY, public class ModernEnumRenderer> implements SkinRenderer> { @Override - public void render(DrawContext drawContext, EnumOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, EnumOption option, int x, int y, int mouseX, int mouseY) { // Set dimensions for the main label and dropdown area - option.setHeight(mc.textRenderer.fontHeight + 2); + option.setHeight(mc.font.lineHeight + 2); // Draw main option name and selected option - Text mainLabel = option.name.copy().append(": "); + Component mainLabel = option.name.copy().append(": "); String selectedOption = option.get().toString(); - drawContext.drawText(mc.textRenderer, mainLabel, x + 4, y + 2, -1, false); - Color fillColor = isMouseOver(mouseX, mouseY, x + 4 + mc.textRenderer.getWidth(mainLabel), y, mc.textRenderer.getWidth(selectedOption) + 5, mc.textRenderer.fontHeight + 2) ? getThemeColor().darker().darker() : getThemeColor(); + graphics.drawString(mc.font, mainLabel, x + 4, y + 2, -1, false); + Color fillColor = isMouseOver(mouseX, mouseY, x + 4 + mc.font.width(mainLabel), y, mc.font.width(selectedOption) + 5, mc.font.lineHeight + 2) ? getThemeColor().darker().darker() : getThemeColor(); DrawHelper.drawRoundedRectangle( - drawContext, - x + 4 + mc.textRenderer.getWidth(mainLabel), y, mc.textRenderer.getWidth(selectedOption) + 5, mc.textRenderer.fontHeight + 2, 2, + graphics, + x + 4 + mc.font.width(mainLabel), y, mc.font.width(selectedOption) + 5, mc.font.lineHeight + 2, 2, fillColor.getRGB() ); // "<" and ">" buttons int contextMenuWidth = (int) (width * 0.8f - 14); int leftX = x + contextMenuWidth - 30; - boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.textRenderer.getWidth("<") + 5, mc.textRenderer.fontHeight); - boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.textRenderer.getWidth("<") + 6, y, mc.textRenderer.getWidth(">") + 5, mc.textRenderer.fontHeight); + boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.font.width("<") + 5, mc.font.lineHeight); + boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.font.width("<") + 6, y, mc.font.width(">") + 5, mc.font.lineHeight); // Shadow DrawHelper.drawRoundedRectangle( - drawContext, + graphics, leftX + 1, y + 3, - (mc.textRenderer.getWidth("<") * 2) + 10, mc.textRenderer.fontHeight, 2, + (mc.font.width("<") * 2) + 10, mc.font.lineHeight, 2, ColorHelper.changeAlpha(Color.BLACK, 128).getRGB() ); DrawHelper.drawRoundedRectangle( - drawContext, + graphics, leftX, y + 2, true, false, true, false, - mc.textRenderer.getWidth("<") + 5, mc.textRenderer.fontHeight, 2, + mc.font.width("<") + 5, mc.font.lineHeight, 2, hoveredOverLeft ? getThemeColor().darker().darker().getRGB() : getThemeColor().getRGB() ); DrawHelper.drawRoundedRectangle( - drawContext, - leftX + mc.textRenderer.getWidth("<") + 6, y + 2, + graphics, + leftX + mc.font.width("<") + 6, y + 2, false, true, false, true, - mc.textRenderer.getWidth(">") + 5, mc.textRenderer.fontHeight, 2, + mc.font.width(">") + 5, mc.font.lineHeight, 2, hoveredOverRight ? getThemeColor().darker().darker().getRGB() : getThemeColor().getRGB() ); DrawHelper.drawVerticalLine( - drawContext, - leftX + mc.textRenderer.getWidth("<") + 5, + graphics, + leftX + mc.font.width("<") + 5, y + 2, - mc.textRenderer.fontHeight, + mc.font.lineHeight, 0.7f, Color.WHITE.getRGB() ); - drawContext.drawText(mc.textRenderer, "<", leftX + mc.textRenderer.getWidth("<") / 2 + 1, y + 3, -1, false); - drawContext.drawText(mc.textRenderer, ">", leftX + mc.textRenderer.getWidth("<") + 7 + mc.textRenderer.getWidth(">") / 2, y + 3, -1, false); + graphics.drawString(mc.font, "<", leftX + mc.font.width("<") / 2 + 1, y + 3, -1, false); + graphics.drawString(mc.font, ">", leftX + mc.font.width("<") + 7 + mc.font.width(">") / 2, y + 3, -1, false); - drawContext.drawText(mc.textRenderer, selectedOption, x + 6 + mc.textRenderer.getWidth(mainLabel), y + 2, Color.LIGHT_GRAY.getRGB(), false); + graphics.drawString(mc.font, selectedOption, x + 6 + mc.font.width(mainLabel), y + 2, Color.LIGHT_GRAY.getRGB(), false); } @Override public boolean mouseClicked(EnumOption option, double mouseX, double mouseY, int button) { if (option.getValues().length == 0) return false; - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; int x = option.getX(); int y = option.getY(); @@ -713,9 +705,9 @@ public boolean mouseClicked(EnumOption option, double mouseX, double mouseY, // "<" and ">" buttons int contextMenuWidth = (int) (width * 0.8f - 14); int leftX = x + contextMenuWidth - 30; - boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.textRenderer.getWidth("<") + 5, mc.textRenderer.fontHeight); - boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.textRenderer.getWidth("<") + 6, y, mc.textRenderer.getWidth(">") + 5, mc.textRenderer.fontHeight); - boolean hoveredOverMainLabel = isMouseOver(mouseX, mouseY, x + 4 + mc.textRenderer.getWidth(mainLabel), y, mc.textRenderer.getWidth(selectedOption) + 5, mc.textRenderer.fontHeight + 2); + boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.font.width("<") + 5, mc.font.lineHeight); + boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.font.width("<") + 6, y, mc.font.width(">") + 5, mc.font.lineHeight); + boolean hoveredOverMainLabel = isMouseOver(mouseX, mouseY, x + 4 + mc.font.width(mainLabel), y, mc.font.width(selectedOption) + 5, mc.font.lineHeight + 2); if (hoveredOverLeft || hoveredOverRight || hoveredOverMainLabel) { E[] values = option.getValues(); @@ -741,60 +733,60 @@ public boolean mouseClicked(EnumOption option, double mouseX, double mouseY, public class ModernListRenderer implements SkinRenderer> { @Override - public void render(DrawContext drawContext, ListOption option, int x, int y, int mouseX, int mouseY) { + public void render(GuiGraphics graphics, ListOption option, int x, int y, int mouseX, int mouseY) { // Set dimensions for the main label and dropdown area - option.setHeight(mc.textRenderer.fontHeight + 2); + option.setHeight(mc.font.lineHeight + 2); // Draw main option name and selected option - Text mainLabel = option.name.copy().append(": "); + Component mainLabel = option.name.copy().append(": "); String selectedOption = option.get().toString(); - drawContext.drawText(mc.textRenderer, mainLabel, x + 4, y + 2, -1, false); - Color fillColor = isMouseOver(mouseX, mouseY, x + 4 + mc.textRenderer.getWidth(mainLabel), y, mc.textRenderer.getWidth(selectedOption) + 5, mc.textRenderer.fontHeight + 2) ? getThemeColor().darker().darker() : getThemeColor(); + graphics.drawString(mc.font, mainLabel, x + 4, y + 2, -1, false); + Color fillColor = isMouseOver(mouseX, mouseY, x + 4 + mc.font.width(mainLabel), y, mc.font.width(selectedOption) + 5, mc.font.lineHeight + 2) ? getThemeColor().darker().darker() : getThemeColor(); DrawHelper.drawRoundedRectangle( - drawContext, - x + 4 + mc.textRenderer.getWidth(mainLabel), y, mc.textRenderer.getWidth(selectedOption) + 5, mc.textRenderer.fontHeight + 2, 2, + graphics, + x + 4 + mc.font.width(mainLabel), y, mc.font.width(selectedOption) + 5, mc.font.lineHeight + 2, 2, fillColor.getRGB() ); // "<" and ">" buttons int contextMenuWidth = (int) (width * 0.8f - 14); int leftX = x + contextMenuWidth - 30; - boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.textRenderer.getWidth("<") + 5, mc.textRenderer.fontHeight); - boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.textRenderer.getWidth("<") + 6, y, mc.textRenderer.getWidth(">") + 5, mc.textRenderer.fontHeight); + boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.font.width("<") + 5, mc.font.lineHeight); + boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.font.width("<") + 6, y, mc.font.width(">") + 5, mc.font.lineHeight); // Shadow DrawHelper.drawRoundedRectangle( - drawContext, + graphics, leftX + 1, y + 3, - (mc.textRenderer.getWidth("<") * 2) + 10, mc.textRenderer.fontHeight, 2, + (mc.font.width("<") * 2) + 10, mc.font.lineHeight, 2, ColorHelper.changeAlpha(Color.BLACK, 128).getRGB() ); DrawHelper.drawRoundedRectangle( - drawContext, + graphics, leftX, y + 2, true, false, true, false, - mc.textRenderer.getWidth("<") + 5, mc.textRenderer.fontHeight, 2, + mc.font.width("<") + 5, mc.font.lineHeight, 2, hoveredOverLeft ? getThemeColor().darker().darker().getRGB() : getThemeColor().getRGB() ); DrawHelper.drawRoundedRectangle( - drawContext, - leftX + mc.textRenderer.getWidth("<") + 6, y + 2, + graphics, + leftX + mc.font.width("<") + 6, y + 2, false, true, false, true, - mc.textRenderer.getWidth(">") + 5, mc.textRenderer.fontHeight, 2, + mc.font.width(">") + 5, mc.font.lineHeight, 2, hoveredOverRight ? getThemeColor().darker().darker().getRGB() : getThemeColor().getRGB() ); DrawHelper.drawVerticalLine( - drawContext, - leftX + mc.textRenderer.getWidth("<") + 5, + graphics, + leftX + mc.font.width("<") + 5, y + 2, - mc.textRenderer.fontHeight, + mc.font.lineHeight, 0.7f, Color.WHITE.getRGB() ); - drawContext.drawText(mc.textRenderer, "<", leftX + mc.textRenderer.getWidth("<") / 2 + 1, y + 3, -1, false); - drawContext.drawText(mc.textRenderer, ">", leftX + mc.textRenderer.getWidth("<") + 7 + mc.textRenderer.getWidth(">") / 2, y + 3, -1, false); + graphics.drawString(mc.font, "<", leftX + mc.font.width("<") / 2 + 1, y + 3, -1, false); + graphics.drawString(mc.font, ">", leftX + mc.font.width("<") + 7 + mc.font.width(">") / 2, y + 3, -1, false); - drawContext.drawText(mc.textRenderer, selectedOption, x + 6 + mc.textRenderer.getWidth(mainLabel), y + 2, Color.LIGHT_GRAY.getRGB(), false); + graphics.drawString(mc.font, selectedOption, x + 6 + mc.font.width(mainLabel), y + 2, Color.LIGHT_GRAY.getRGB(), false); } @Override @@ -806,7 +798,7 @@ public boolean mouseClicked(ListOption option, double mouseX, double mouseY, int x = option.getX(); int y = option.getY(); - Text mainLabel = option.name.copy().append(": "); + Component mainLabel = option.name.copy().append(": "); String selectedOption = option.get().toString(); // Calculate positions @@ -814,9 +806,9 @@ public boolean mouseClicked(ListOption option, double mouseX, double mouseY, int leftX = x + contextMenuWidth - 30; // Check hover states - boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.textRenderer.getWidth("<") + 5, mc.textRenderer.fontHeight); - boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.textRenderer.getWidth("<") + 6, y, mc.textRenderer.getWidth(">") + 5, mc.textRenderer.fontHeight); - boolean hoveredOverMainLabel = isMouseOver(mouseX, mouseY, x + 4 + mc.textRenderer.getWidth(mainLabel), y, mc.textRenderer.getWidth(selectedOption) + 5, mc.textRenderer.fontHeight + 2); + boolean hoveredOverLeft = isMouseOver(mouseX, mouseY, leftX, y, mc.font.width("<") + 5, mc.font.lineHeight); + boolean hoveredOverRight = isMouseOver(mouseX, mouseY, leftX + mc.font.width("<") + 6, y, mc.font.width(">") + 5, mc.font.lineHeight); + boolean hoveredOverMainLabel = isMouseOver(mouseX, mouseY, x + 4 + mc.font.width(mainLabel), y, mc.font.width(selectedOption) + 5, mc.font.lineHeight + 2); // Check if any area is clicked if (hoveredOverLeft || hoveredOverRight || hoveredOverMainLabel) { @@ -843,28 +835,28 @@ public boolean mouseClicked(ListOption option, double mouseX, double mouseY, public class ModernSubMenuRenderer implements SkinRenderer { @Override - public void render(DrawContext drawContext, SubMenuOption option, int x, int y, int mouseX, int mouseY) { - mouseX = (int) (mc.mouse.getX() / SCALE_FACTOR); - mouseY = (int) (mc.mouse.getY() / SCALE_FACTOR); + public void render(GuiGraphics graphics, SubMenuOption option, int x, int y, int mouseX, int mouseY) { + mouseX = (int) (mc.mouseHandler.xpos() / SCALE_FACTOR); + mouseY = (int) (mc.mouseHandler.ypos() / SCALE_FACTOR); - String text = "Open"; + String Component = "Open"; int contextMenuWidth = (int) (width * 0.8f - 14); int xPos = x + 4 + contextMenuWidth - 40; option.setPosition(xPos - 1, y); - option.setWidth(mc.textRenderer.getWidth(text) + 5); + option.setWidth(mc.font.width(Component) + 5); option.setHeight(16); - drawContext.drawText(mc.textRenderer, option.name, x + 4, y + 4, -1, false); + graphics.drawString(mc.font, option.name, x + 4, y + 4, -1, false); - drawContext.drawText(mc.textRenderer, text, xPos + 2, y + 4, Color.WHITE.getRGB(), true); + graphics.drawString(mc.font, Component, xPos + 2, y + 4, Color.WHITE.getRGB(), true); - Color fillColor = isMouseOver(mouseX, mouseY, xPos + 2, y + 4, mc.textRenderer.getWidth(text) + 5, mc.textRenderer.fontHeight + 4) ? getThemeColor().darker().darker() : getThemeColor(); + Color fillColor = isMouseOver(mouseX, mouseY, xPos + 2, y + 4, mc.font.width(Component) + 5, mc.font.lineHeight + 4) ? getThemeColor().darker().darker() : getThemeColor(); DrawHelper.drawRoundedRectangleWithShadowBadWay( - drawContext, + graphics, xPos - 1, y + 1, - mc.textRenderer.getWidth(text) + 5, mc.textRenderer.fontHeight + 4, + mc.font.width(Component) + 5, mc.font.lineHeight + 4, 2, fillColor.getRGB(), 180, @@ -872,42 +864,42 @@ public void render(DrawContext drawContext, SubMenuOption option, int x, int y, 1 ); DrawHelper.drawOutlineRoundedBox( - drawContext, + graphics, xPos - 1, y + 1, - mc.textRenderer.getWidth(text) + 5, mc.textRenderer.fontHeight + 4, + mc.font.width(Component) + 5, mc.font.lineHeight + 4, 2, 0.7f, Color.WHITE.getRGB() ); - option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y, mouseX, mouseY); + option.getSubMenu().render(graphics, x + option.getParentMenu().getWidth(), y, mouseX, mouseY); } @Override public void mouseScrolled(SubMenuOption option, double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; SkinRenderer.super.mouseScrolled(option, mouseX, mouseY, horizontalAmount, verticalAmount); } @Override public boolean mouseDragged(SubMenuOption option, double mouseX, double mouseY, int button, double deltaX, double deltaY) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; return SkinRenderer.super.mouseDragged(option, mouseX, mouseY, button, deltaX, deltaY); } @Override public boolean mouseReleased(SubMenuOption option, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; return SkinRenderer.super.mouseReleased(option, mouseX, mouseY, button); } @Override public boolean mouseClicked(SubMenuOption option, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; return SkinRenderer.super.mouseClicked(option, mouseX, mouseY, button); } } @@ -917,25 +909,25 @@ public class ModernRunnableRenderer implements SkinRenderer { Color DARK_GREEN = new Color(24, 132, 0, 226); @Override - public void render(DrawContext drawContext, RunnableOption option, int x, int y, int mouseX, int mouseY) { - String text = "Run ▶"; + public void render(GuiGraphics graphics, RunnableOption option, int x, int y, int mouseX, int mouseY) { + String Component = "Run ▶"; int contextMenuWidth = (int) (width * 0.8f - 14); int xPos = x + 4 + contextMenuWidth - 45; option.setPosition(xPos - 1, y); - option.setWidth(mc.textRenderer.getWidth(text) + 5); - option.setHeight(mc.textRenderer.fontHeight + 6); + option.setWidth(mc.font.width(Component) + 5); + option.setHeight(mc.font.lineHeight + 6); - drawContext.drawText(mc.textRenderer, option.name, x + 4, y + 4, -1, false); + graphics.drawString(mc.font, option.name, x + 4, y + 4, -1, false); - drawContext.drawText(mc.textRenderer, text, xPos + 2, y + 4, option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(), true); + graphics.drawString(mc.font, Component, xPos + 2, y + 4, option.value ? DARK_GREEN.getRGB() : DARK_RED.getRGB(), true); - Color fillColor = isMouseOver(mouseX, mouseY, xPos + 2, y + 4, mc.textRenderer.getWidth(text) + 5, mc.textRenderer.fontHeight + 4) ? getThemeColor().darker().darker() : getThemeColor(); + Color fillColor = isMouseOver(mouseX, mouseY, xPos + 2, y + 4, mc.font.width(Component) + 5, mc.font.lineHeight + 4) ? getThemeColor().darker().darker() : getThemeColor(); DrawHelper.drawRoundedRectangleWithShadowBadWay( - drawContext, + graphics, xPos - 1, y + 1, - mc.textRenderer.getWidth(text) + 5, mc.textRenderer.fontHeight + 4, + mc.font.width(Component) + 5, mc.font.lineHeight + 4, 2, fillColor.getRGB(), 180, @@ -946,8 +938,8 @@ public void render(DrawContext drawContext, RunnableOption option, int x, int y, @Override public boolean mouseClicked(RunnableOption option, double mouseX, double mouseY, int button) { - mouseX = mc.mouse.getX() / SCALE_FACTOR; - mouseY = mc.mouse.getY() / SCALE_FACTOR; + mouseX = mc.mouseHandler.xpos() / SCALE_FACTOR; + mouseY = mc.mouseHandler.ypos() / SCALE_FACTOR; return SkinRenderer.super.mouseClicked(option, mouseX, mouseY, button); } } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java index 5c8e86b..03f8a60 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/Skin.java @@ -5,8 +5,8 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.options.OptionGroup; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.GroupableSkin; import com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces.SkinRenderer; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import java.util.ArrayList; import java.util.HashMap; @@ -15,7 +15,7 @@ import java.util.function.Supplier; public abstract class Skin { - protected static final MinecraftClient mc = MinecraftClient.getInstance(); + protected static final Minecraft mc = Minecraft.getInstance(); protected ContextMenu contextMenu; protected Map>, Supplier>>> renderers = new HashMap<>(); private boolean createNewScreen; @@ -82,7 +82,7 @@ public void setRenderers(Map>, Supplier contextMenu, int mouseX, int mouseY); + public abstract void renderContextMenu(GuiGraphics graphics, ContextMenu contextMenu, int mouseX, int mouseY); public boolean mouseClicked(ContextMenu menu, double mouseX, double mouseY, int button) { return false; @@ -113,7 +113,7 @@ public void setCreateNewScreen(boolean createNewScreen) { this.createNewScreen = createNewScreen; } - protected boolean isMouseOver(double mouseX, double mouseY, double x, double y, double width, double height) { + public static boolean isMouseOver(double mouseX, double mouseY, double x, double y, double width, double height) { return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/GroupableSkin.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/GroupableSkin.java index c93dd52..6319f77 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/GroupableSkin.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/GroupableSkin.java @@ -2,11 +2,11 @@ import com.tanishisherewith.dynamichud.utils.contextmenu.layout.LayoutContext; import com.tanishisherewith.dynamichud.utils.contextmenu.options.OptionGroup; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.GuiGraphics; public interface GroupableSkin { LayoutContext.Offset getGroupIndent(); - void renderGroup(DrawContext drawContext, OptionGroup group, int groupX, int groupY, int mouseX, int mouseY); + void renderGroup(GuiGraphics graphics, OptionGroup group, int groupX, int groupY, int mouseX, int mouseY); } diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/SkinRenderer.java b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/SkinRenderer.java index 89fa741..671c9b1 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/SkinRenderer.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/interfaces/SkinRenderer.java @@ -1,10 +1,10 @@ package com.tanishisherewith.dynamichud.utils.contextmenu.skinsystem.interfaces; import com.tanishisherewith.dynamichud.utils.contextmenu.options.Option; -import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.GuiGraphics; public interface SkinRenderer> { - void render(DrawContext drawContext, T option, int x, int y, int mouseX, int mouseY); + void render(GuiGraphics graphics, T option, int x, int y, int mouseX, int mouseY); default boolean mouseClicked(T option, double mouseX, double mouseY, int button) { return option.mouseClicked(mouseX, mouseY, button); diff --git a/src/main/java/com/tanishisherewith/dynamichud/utils/handlers/ScrollHandler.java b/src/main/java/com/tanishisherewith/dynamichud/utils/handlers/ScrollHandler.java index 2bd9d98..4d10ae4 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/utils/handlers/ScrollHandler.java +++ b/src/main/java/com/tanishisherewith/dynamichud/utils/handlers/ScrollHandler.java @@ -1,6 +1,5 @@ package com.tanishisherewith.dynamichud.utils.handlers; -import net.minecraft.util.math.MathHelper; public class ScrollHandler { protected int scrollOffset; @@ -23,7 +22,7 @@ public void updateScrollOffset(int maxYOffset) { this.maxScrollOffset = maxYOffset; applyMomentum(); - scrollOffset = MathHelper.clamp(scrollOffset, 0, maxScrollOffset); + scrollOffset = Math.clamp(scrollOffset, 0, maxScrollOffset); } public void mouseScrolled(double deltaY) { @@ -41,7 +40,7 @@ public void stopDragging() { } public void addOffset(int offset) { - this.scrollOffset = MathHelper.clamp(scrollOffset + offset, 0, maxScrollOffset); + this.scrollOffset = Math.clamp(scrollOffset + offset, 0, maxScrollOffset); } public void updateScrollPosition(double mouseY) { @@ -50,7 +49,7 @@ public void updateScrollPosition(double mouseY) { double deltaY = lastMouseY - mouseY; // Update the scroll offset based on the mouse movement - scrollOffset = MathHelper.clamp(scrollOffset - (int) (deltaY * SCROLL_SPEED), 0, maxScrollOffset); + scrollOffset = Math.clamp(scrollOffset - (int) (deltaY * SCROLL_SPEED), 0, maxScrollOffset); // Update the last mouse position lastMouseY = mouseY; @@ -62,7 +61,7 @@ private void applyMomentum() { double timeDelta = (currentTime - lastScrollTime) / 1000.0; scrollOffset += (int) (scrollVelocity * timeDelta); scrollVelocity *= 0.9; // Decay factor - scrollOffset = MathHelper.clamp(scrollOffset, 0, maxScrollOffset); + scrollOffset = Math.clamp(scrollOffset, 0, maxScrollOffset); } public int getScrollOffset() { diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/DynamicValueWidget.java b/src/main/java/com/tanishisherewith/dynamichud/widget/DynamicValueWidget.java index 1e8630f..18cc7b9 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widget/DynamicValueWidget.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widget/DynamicValueWidget.java @@ -4,7 +4,7 @@ import com.tanishisherewith.dynamichud.utils.Util; import com.tanishisherewith.dynamichud.widgets.GraphWidget; import com.tanishisherewith.dynamichud.widgets.TextWidget; -import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.CompoundTag; import java.util.function.Supplier; @@ -36,14 +36,14 @@ protected void initializeValueSupplier() { } @Override - public void writeToTag(NbtCompound tag) { + public void writeToTag(CompoundTag tag) { super.writeToTag(tag); tag.putString("RegistryID", registryID); tag.putString("RegistryKey", registryKey); } @Override - public void readFromTag(NbtCompound tag) { + public void readFromTag(CompoundTag tag) { super.readFromTag(tag); registryID = tag.getString("RegistryID").orElse(DynamicValueRegistry.GLOBAL_ID); registryKey = tag.getString("RegistryKey").orElse("null"); diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/UserManageable.java b/src/main/java/com/tanishisherewith/dynamichud/widget/UserManageable.java deleted file mode 100644 index b719d15..0000000 --- a/src/main/java/com/tanishisherewith/dynamichud/widget/UserManageable.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.tanishisherewith.dynamichud.widget; - -//unused -public interface UserManageable { - // Marker interface that a widget is add-able and removable. -} \ No newline at end of file diff --git a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java index a385042..74d4c56 100644 --- a/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java +++ b/src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java @@ -4,15 +4,14 @@ import com.tanishisherewith.dynamichud.helpers.DrawHelper; import com.tanishisherewith.dynamichud.internal.UID; import com.tanishisherewith.dynamichud.utils.Input; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.Text; -import net.minecraft.util.math.MathHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; import org.lwjgl.glfw.GLFW; public abstract class Widget implements Input { - public static MinecraftClient mc = MinecraftClient.getInstance(); + public static Minecraft mc = Minecraft.getInstance(); public WidgetData DATA; /** * This is the UID of the widget used to identify during loading and saving. @@ -39,7 +38,7 @@ public abstract class Widget implements Input { */ public String modId = "unknown"; - public Text tooltipText; + public Component tooltipText; // Boolean to know if the widget is currently being displayed in an instance of AbstractMoveableScreen protected boolean isInEditor = false; @@ -66,7 +65,7 @@ public Widget(WidgetData DATA, String modId, Anchor anchor) { widgetBox = new WidgetBox(0, 0, 0, 0); this.modId = modId; this.anchor = anchor; - this.tooltipText = Text.of(DATA.description()); + this.tooltipText = Component.literal(DATA.description()); init(); } @@ -128,7 +127,7 @@ private int getAnchorY(int screenHeight) { // Update position based on anchor and offset void updatePosition(int screenWidth, int screenHeight) { if (offsetX == 0 || offsetY == 0) { - calculateOffset(x, y, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); + calculateOffset(x, y, mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight()); } int anchorX = getAnchorX(screenWidth); @@ -141,9 +140,9 @@ void updatePosition(int screenWidth, int screenHeight) { public void setPosition(int x, int y) { this.x = x; this.y = y; - if (mc.getWindow() != null) { - calculateOffset(x, y, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); - updatePosition(mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); + if(mc.getWindow() != null) { + calculateOffset(x, y, mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight()); + updatePosition(mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight()); } } @@ -159,17 +158,17 @@ public boolean isOverlapping(Widget other) { /** * Renders the widget on the screen. */ - public final void render(DrawContext drawContext, int mouseX, int mouseY) { + public final void render(GuiGraphics graphics, int mouseX, int mouseY) { if (!isVisible()) return; if (shouldScale) { - DrawHelper.scaleAndPosition(drawContext.getMatrices(), getX(), getY(), GlobalConfig.get().getScale()); + DrawHelper.scaleAndPosition(graphics.pose(), getX(), getY(), GlobalConfig.get().getScale()); } - renderWidget(drawContext, mouseX, mouseY); + renderWidget(graphics, mouseX, mouseY); if (shouldScale) { - DrawHelper.stopScaling(drawContext.getMatrices()); + DrawHelper.stopScaling(graphics.pose()); } clampPosition(); } @@ -177,18 +176,18 @@ public final void render(DrawContext drawContext, int mouseX, int mouseY) { /** * Renders the widget on the editor screen. */ - public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY) { + public final void renderInEditor(GuiGraphics graphics, int mouseX, int mouseY) { if (!isInEditor) return; - drawWidgetBackground(drawContext); + drawWidgetBackground(graphics); if (shouldScale) { - DrawHelper.scaleAndPosition(drawContext.getMatrices(), getX(), getY(), GlobalConfig.get().getScale()); + DrawHelper.scaleAndPosition(graphics.pose(), getX(), getY(), GlobalConfig.get().getScale()); } - renderWidgetInEditor(drawContext, mouseX, mouseY); + renderWidgetInEditor(graphics, mouseX, mouseY); if (shouldScale) { - DrawHelper.stopScaling(drawContext.getMatrices()); + DrawHelper.stopScaling(graphics.pose()); } clampPosition(); } @@ -199,21 +198,21 @@ public final void renderInEditor(DrawContext drawContext, int mouseX, int mouseY * The mouse position values are only passed when in a {@link com.tanishisherewith.dynamichud.screens.AbstractMoveableScreen} screen. *

* - * @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}",