From d187df6a873530eea2863ba0e6fc77bfef48c8d9 Mon Sep 17 00:00:00 2001 From: LambdAurora Date: Sun, 13 Oct 2024 00:08:08 +0200 Subject: [PATCH] Migrate to mojmap + YALMM. --- build.gradle.kts | 124 +++++++++++++++++- gradle.properties | 4 +- .../dev/lambdaurora/spruceui/SpruceTexts.java | 2 +- .../lambdaurora/spruceui/SpruceTextures.java | 4 +- .../dev/lambdaurora/spruceui/Tooltip.java | 36 ++--- .../dev/lambdaurora/spruceui/Tooltipable.java | 2 +- .../spruceui/background/Background.java | 1 - .../spruceui/background/MenuBackground.java | 8 +- .../spruceui/border/MenuBorder.java | 16 +-- .../spruceui/border/SimpleBorder.java | 13 +- .../spruceui/event/OpenScreenCallback.java | 6 +- .../event/ResolutionChangeCallback.java | 4 +- .../dev/lambdaurora/spruceui/hud/Hud.java | 15 +-- .../spruceui/hud/HudComponent.java | 6 +- .../lambdaurora/spruceui/hud/HudManager.java | 14 +- .../hud/component/TextHudComponent.java | 14 +- .../spruceui/mixin/MinecraftClientMixin.java | 14 +- .../spruceui/option/SpruceBooleanOption.java | 6 +- .../option/SpruceCheckboxBooleanOption.java | 2 +- .../spruceui/option/SpruceCyclingOption.java | 2 +- .../option/SpruceDoubleInputOption.java | 12 +- .../spruceui/option/SpruceDoubleOption.java | 2 +- .../option/SpruceFloatInputOption.java | 12 +- .../option/SpruceIntegerInputOption.java | 12 +- .../spruceui/option/SpruceOption.java | 6 +- .../option/SpruceSeparatorOption.java | 2 +- .../option/SpruceSimpleActionOption.java | 40 ++++-- .../spruceui/option/SpruceStringOption.java | 2 +- .../option/SpruceToggleBooleanOption.java | 2 +- .../spruceui/screen/SpruceHandledScreen.java | 36 ++--- .../spruceui/screen/SpruceScreen.java | 26 ++-- .../spruceui/util/Identifiable.java | 4 +- .../spruceui/util/MultilineText.java | 6 +- .../lambdaurora/spruceui/util/RenderUtil.java | 68 +++++----- .../spruceui/util/ScissorManager.java | 8 +- .../AbstractSpruceBooleanButtonWidget.java | 18 +-- .../widget/AbstractSpruceButtonWidget.java | 29 ++-- .../AbstractSpruceIconButtonWidget.java | 4 +- .../AbstractSprucePressableButtonWidget.java | 2 +- .../spruceui/widget/AbstractSpruceWidget.java | 35 ++--- .../spruceui/widget/SpruceButtonWidget.java | 2 +- .../spruceui/widget/SpruceCheckboxWidget.java | 12 +- .../spruceui/widget/SpruceElement.java | 4 +- .../widget/SpruceIconButtonWidget.java | 2 +- .../spruceui/widget/SpruceLabelWidget.java | 19 ++- .../widget/SpruceSeparatorWidget.java | 8 +- .../spruceui/widget/SpruceSliderWidget.java | 4 +- .../widget/SpruceTexturedButtonWidget.java | 4 +- .../spruceui/widget/SpruceToggleSwitch.java | 12 +- .../spruceui/widget/SpruceWidget.java | 8 +- .../container/SpruceEntryListWidget.java | 83 ++++++------ .../container/SpruceOptionListWidget.java | 18 +-- .../container/tabbed/SpruceTabbedWidget.java | 22 ++-- .../option/SpruceOptionSliderWidget.java | 2 +- .../text/AbstractSpruceTextInputWidget.java | 2 +- .../text/SpruceNamedTextFieldWidget.java | 8 +- .../widget/text/SpruceTextAreaWidget.java | 119 ++++++++--------- .../widget/text/SpruceTextFieldWidget.java | 123 ++++++++--------- .../wrapper/VanillaButtonWrapper.java | 16 +-- .../spruceui/test/SpruceUITest.java | 12 +- .../lambdaurora/spruceui/test/TestEnum.java | 2 +- .../test/gui/SpruceMainMenuScreen.java | 14 +- .../spruceui/test/gui/SpruceOptionScreen.java | 14 +- .../test/gui/SpruceTabbedTestScreen.java | 18 +-- .../test/gui/SpruceTextAreaScreen.java | 8 +- .../spruceui/test/mixin/TitleScreenMixin.java | 8 +- 66 files changed, 634 insertions(+), 529 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c9b17c2d..7bb15859 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,21 @@ +import net.fabricmc.loom.api.mappings.layered.MappingContext +import net.fabricmc.loom.api.mappings.layered.MappingLayer +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace +import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec +import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingLayer +import net.fabricmc.loom.configuration.providers.mappings.utils.DstNameFilterMappingVisitor import net.fabricmc.loom.task.RemapJarTask +import net.fabricmc.loom.util.download.DownloadException +import net.fabricmc.mappingio.MappingVisitor +import net.fabricmc.mappingio.adapter.MappingDstNsReorder +import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch +import net.fabricmc.mappingio.format.proguard.ProGuardFileReader +import net.fabricmc.mappingio.tree.MemoryMappingTree +import java.io.IOException +import java.io.UncheckedIOException +import java.nio.file.Files +import java.nio.file.Path +import java.util.regex.Pattern plugins { id("fabric-loom").version("1.8.+") @@ -36,14 +53,115 @@ repositories { url = uri("https://maven.terraformersmc.com/releases") } maven { - name = "QuiltMC" - url = uri("https://maven.quiltmc.org/repository/release") + name = "Gegy" + url = uri("https://maven.gegy.dev/releases/") + } +} + +// Based off Loom, this is required as the releases at the time of writing this buildscript have +// a flaw with the mapping layering preventing the usage of the usual MojangMappingLayer. +@Suppress("UnstableApiUsage") +internal data class MojangMappingLayer( + val clientMappings: Path, val serverMappings: Path, val nameSyntheticMembers: Boolean, + val intermediaryMappings: MemoryMappingTree, val logger: Logger +) : MappingLayer { + @Throws(IOException::class) + override fun visit(mappingVisitor: MappingVisitor) { + val mojmap = MemoryMappingTree() + + // Filter out field names matching the pattern + val nameFilter = DstNameFilterMappingVisitor(mojmap, SYNTHETIC_NAME_PATTERN) + + // Make official the source namespace + val nsSwitch = MappingSourceNsSwitch(if (nameSyntheticMembers) mojmap else nameFilter, MappingsNamespace.OFFICIAL.toString()) + + Files.newBufferedReader(clientMappings).use { clientBufferedReader -> + Files.newBufferedReader(serverMappings).use { serverBufferedReader -> + ProGuardFileReader.read( + clientBufferedReader, + MappingsNamespace.NAMED.toString(), + MappingsNamespace.OFFICIAL.toString(), + nsSwitch + ) + ProGuardFileReader.read( + serverBufferedReader, + MappingsNamespace.NAMED.toString(), + MappingsNamespace.OFFICIAL.toString(), + nsSwitch + ) + } + } + + intermediaryMappings.accept(MappingDstNsReorder(mojmap, MappingsNamespace.INTERMEDIARY.toString())) + + val switch = MappingSourceNsSwitch(MappingDstNsReorder(mappingVisitor, MappingsNamespace.NAMED.toString()), MappingsNamespace.INTERMEDIARY.toString(), true) + mojmap.accept(switch) + } + + override fun getSourceNamespace(): MappingsNamespace { + return MappingsNamespace.INTERMEDIARY + } + + override fun dependsOn(): List> { + return listOf(IntermediaryMappingLayer::class.java) + } + + companion object { + private val SYNTHETIC_NAME_PATTERN: Pattern = Pattern.compile("^(access|this|val\\\$this|lambda\\$.*)\\$[0-9]+$") + } +} + +@Suppress("UnstableApiUsage") +internal data class MojangMappingsSpec(val nameSyntheticMembers: Boolean) : MappingsSpec { + override fun createLayer(context: MappingContext): MojangMappingLayer { + val versionInfo = context.minecraftProvider().versionInfo + val clientDownload = versionInfo.download(MANIFEST_CLIENT_MAPPINGS) + val serverDownload = versionInfo.download(MANIFEST_SERVER_MAPPINGS) + + if (clientDownload == null) { + throw RuntimeException("Failed to find official mojang mappings for " + context.minecraftVersion()) + } + + val clientMappings = context.workingDirectory("mojang").resolve("client.txt") + val serverMappings = context.workingDirectory("mojang").resolve("server.txt") + + try { + context.download(clientDownload.url()) + .sha1(clientDownload.sha1()) + .downloadPath(clientMappings) + + context.download(serverDownload.url()) + .sha1(serverDownload.sha1()) + .downloadPath(serverMappings) + } catch (e: DownloadException) { + throw UncheckedIOException("Failed to download mappings", e) + } + + return MojangMappingLayer( + clientMappings, + serverMappings, + nameSyntheticMembers, + context.intermediaryTree().get(), + context.logger + ) + } + + companion object { + // Keys in dependency manifest + private const val MANIFEST_CLIENT_MAPPINGS = "client_mappings" + private const val MANIFEST_SERVER_MAPPINGS = "server_mappings" } } dependencies { minecraft("com.mojang:minecraft:${mcVersion}") - mappings("org.quiltmc:quilt-mappings:${mcVersion}+build.${project.property("quilt_mappings")}:intermediary-v2") + @Suppress("UnstableApiUsage") + mappings(loom.layered { + addLayer(MojangMappingsSpec(false)) + // Parchment is currently broken when used with the hacked mojmap layer due to remapping shenanigans. + //parchment("org.parchmentmc.data:parchment-${mcVersion}:${project.property("parchment_mappings")}@zip") + mappings("dev.lambdaurora:yalmm:${mcVersion}+build.${project.property("yalmm_mappings")}") + }) modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") fabricModules.stream().map { fabricApi.module(it, project.property("fabric_api_version") as String) }.forEach { diff --git a/gradle.properties b/gradle.properties index 4d5f152f..b602345e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G -minecraft_version=1.21 -quilt_mappings=2 +minecraft_version=1.21.1 +yalmm_mappings=2 loader_version=0.15.11 # Mod Properties diff --git a/src/main/java/dev/lambdaurora/spruceui/SpruceTexts.java b/src/main/java/dev/lambdaurora/spruceui/SpruceTexts.java index 804ff907..2e99b9ea 100644 --- a/src/main/java/dev/lambdaurora/spruceui/SpruceTexts.java +++ b/src/main/java/dev/lambdaurora/spruceui/SpruceTexts.java @@ -9,7 +9,7 @@ package dev.lambdaurora.spruceui; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; /** * Represents a text utility class. diff --git a/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java b/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java index 2072babf..47f48261 100644 --- a/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java +++ b/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java @@ -9,8 +9,8 @@ package dev.lambdaurora.spruceui; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.util.Identifier; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.Identifier; /** * Contains the identifiers of various useful textures. diff --git a/src/main/java/dev/lambdaurora/spruceui/Tooltip.java b/src/main/java/dev/lambdaurora/spruceui/Tooltip.java index e3744ede..00c2736d 100644 --- a/src/main/java/dev/lambdaurora/spruceui/Tooltip.java +++ b/src/main/java/dev/lambdaurora/spruceui/Tooltip.java @@ -11,11 +11,11 @@ import com.google.common.collect.Queues; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.tooltip.DefaultTooltipPositioner; -import net.minecraft.text.OrderedText; -import net.minecraft.text.StringVisitable; +import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.ApiStatus; import java.util.List; @@ -35,17 +35,17 @@ public class Tooltip implements SprucePositioned { private static boolean delayed = false; private final int x; private final int y; - private final List tooltip; + private final List tooltip; public Tooltip(int x, int y, String tooltip, int parentWidth) { - this(x, y, StringVisitable.plain(tooltip), parentWidth); + this(x, y, FormattedText.of(tooltip), parentWidth); } - public Tooltip(int x, int y, StringVisitable tooltip, int parentWidth) { - this(x, y, MinecraftClient.getInstance().textRenderer.wrapLines(tooltip, Math.max(parentWidth * 2 / 3, 200))); + public Tooltip(int x, int y, FormattedText tooltip, int parentWidth) { + this(x, y, Minecraft.getInstance().font.wrapLines(tooltip, Math.max(parentWidth * 2 / 3, 200))); } - public Tooltip(int x, int y, List tooltip) { + public Tooltip(int x, int y, List tooltip) { this.x = x; this.y = y; this.tooltip = tooltip; @@ -55,11 +55,11 @@ public static Tooltip create(int x, int y, String tooltip, int parentWidth) { return new Tooltip(x, y, tooltip, parentWidth); } - public static Tooltip create(int x, int y, StringVisitable tooltip, int parentWidth) { + public static Tooltip create(int x, int y, FormattedText tooltip, int parentWidth) { return new Tooltip(x, y, tooltip, parentWidth); } - public static Tooltip create(int x, int y, List tooltip) { + public static Tooltip create(int x, int y, List tooltip) { return new Tooltip(x, y, tooltip); } @@ -88,7 +88,7 @@ public boolean shouldRender() { * @param graphics The GuiGraphics instance used to render. */ public void render(GuiGraphics graphics) { - graphics.drawTooltip(MinecraftClient.getInstance().textRenderer, this.tooltip, DefaultTooltipPositioner.INSTANCE, this.x, this.y); + graphics.drawTooltip(Minecraft.getInstance().font, this.tooltip, DefaultTooltipPositioner.INSTANCE, this.x, this.y); } /** @@ -107,10 +107,15 @@ public void queue() { * @param the type of the widget * @since 1.6.0 */ - public static void queueFor(T widget, int mouseX, int mouseY, int tooltipTicks, + public static void queueFor( + T widget, + int mouseX, + int mouseY, + int tooltipTicks, IntConsumer tooltipTicksSetter, long lastTick, - LongConsumer lastTickSetter) { + LongConsumer lastTickSetter + ) { if (widget.isVisible()) { widget.getTooltip().ifPresent(tooltip -> { long currentRender = System.currentTimeMillis(); @@ -125,8 +130,7 @@ public static void queueFor(T widget, int tooltipTicksSetter.accept(0); if (!tooltip.getString().isEmpty() && tooltipTicks >= 45) { - var wrappedTooltipText = MinecraftClient.getInstance().textRenderer.wrapLines( - tooltip, Math.max(widget.getWidth() * 2 / 3, 200)); + var wrappedTooltipText = Minecraft.getInstance().font.wrapLines(tooltip, Math.max(widget.getWidth() * 2 / 3, 200)); if (widget.isMouseHovered()) create(mouseX, mouseY, wrappedTooltipText).queue(); else if (widget.isFocused()) diff --git a/src/main/java/dev/lambdaurora/spruceui/Tooltipable.java b/src/main/java/dev/lambdaurora/spruceui/Tooltipable.java index 2f9acef2..53152ec4 100644 --- a/src/main/java/dev/lambdaurora/spruceui/Tooltipable.java +++ b/src/main/java/dev/lambdaurora/spruceui/Tooltipable.java @@ -9,7 +9,7 @@ package dev.lambdaurora.spruceui; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.Optional; diff --git a/src/main/java/dev/lambdaurora/spruceui/background/Background.java b/src/main/java/dev/lambdaurora/spruceui/background/Background.java index 9f21b85a..5f0770fe 100644 --- a/src/main/java/dev/lambdaurora/spruceui/background/Background.java +++ b/src/main/java/dev/lambdaurora/spruceui/background/Background.java @@ -11,7 +11,6 @@ import dev.lambdaurora.spruceui.widget.SpruceWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.util.math.MatrixStack; /** * Represents a background which can be rendered on a widget. diff --git a/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java b/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java index 41ff3376..ee0fe1a5 100644 --- a/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java +++ b/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java @@ -13,9 +13,9 @@ import dev.lambdaurora.spruceui.SpruceTextures; import dev.lambdaurora.spruceui.widget.SpruceWidget; import dev.lambdaurora.spruceui.widget.WithBorder; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.util.Identifier; +import net.minecraft.resources.Identifier; /** * Represents a background used for menus. @@ -27,7 +27,7 @@ * @since 5.1.0 */ public record MenuBackground(Identifier texture, Identifier inWorldTexture) implements Background { - private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + private static final Minecraft CLIENT = Minecraft.getInstance(); public static final MenuBackground MENU_LIST = new MenuBackground( SpruceTextures.MENU_LIST_BACKGROUND, @@ -56,7 +56,7 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m } RenderSystem.enableBlend(); - Identifier identifier = CLIENT.world == null ? this.inWorldTexture : this.texture; + Identifier identifier = CLIENT.level == null ? this.inWorldTexture : this.texture; graphics.drawTexture( identifier, x, y, diff --git a/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java b/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java index 318039fb..189482f4 100644 --- a/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java +++ b/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java @@ -12,9 +12,9 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.SpruceTextures; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.util.Identifier; +import net.minecraft.resources.Identifier; /** * Represents a typical menu border. @@ -28,7 +28,7 @@ * @since 5.1.0 */ public record MenuBorder(boolean top, boolean right, boolean bottom, boolean left) implements Border { - private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + private static final Minecraft CLIENT = Minecraft.getInstance(); private static final int THICKNESS = 2; public static final MenuBorder LIST = new MenuBorder(true, false, true, false); @@ -39,7 +39,7 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo RenderSystem.enableBlend(); if (this.top) { - Identifier topTexture = CLIENT.world == null ? SpruceTextures.MENU_TOP_BORDER : SpruceTextures.INWORLD_MENU_TOP_BORDER; + Identifier topTexture = CLIENT.level == null ? SpruceTextures.MENU_TOP_BORDER : SpruceTextures.INWORLD_MENU_TOP_BORDER; int width = widget.getWidth(); @@ -53,14 +53,14 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo } if (this.top && this.right) { - Identifier cornerTexture = CLIENT.world == null ? SpruceTextures.MENU_TOP_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_TOP_RIGHT_BORDER; + Identifier cornerTexture = CLIENT.level == null ? SpruceTextures.MENU_TOP_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_TOP_RIGHT_BORDER; graphics.drawTexture(cornerTexture, widget.getEndX() - THICKNESS, widget.getY(), 0, 0, THICKNESS, THICKNESS, THICKNESS, THICKNESS ); } if (this.right) { - Identifier rightTexture = CLIENT.world == null ? SpruceTextures.MENU_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_RIGHT_BORDER; + Identifier rightTexture = CLIENT.level == null ? SpruceTextures.MENU_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_RIGHT_BORDER; int y = widget.getY(); int height = widget.getHeight(); @@ -80,7 +80,7 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo } if (this.bottom && this.right) { - Identifier cornerTexture = CLIENT.world == null + Identifier cornerTexture = CLIENT.level == null ? SpruceTextures.MENU_BOTTOM_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_BOTTOM_RIGHT_BORDER; graphics.drawTexture(cornerTexture, widget.getEndX() - THICKNESS, widget.getEndY() - THICKNESS, 0, 0, THICKNESS, THICKNESS, THICKNESS, THICKNESS @@ -88,7 +88,7 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo } if (this.bottom) { - Identifier bottomTexture = CLIENT.world == null ? SpruceTextures.MENU_BOTTOM_BORDER : SpruceTextures.INWORLD_MENU_BOTTOM_BORDER; + Identifier bottomTexture = CLIENT.level == null ? SpruceTextures.MENU_BOTTOM_BORDER : SpruceTextures.INWORLD_MENU_BOTTOM_BORDER; int width = widget.getWidth(); diff --git a/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java b/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java index f297dbf9..321e5fcf 100644 --- a/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java +++ b/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java @@ -14,8 +14,7 @@ import dev.lambdaurora.spruceui.util.ColorUtil; import dev.lambdaurora.spruceui.widget.SpruceWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.unmapped.C_fpcijbbg; +import net.minecraft.client.renderer.GameRenderer; import java.util.Arrays; @@ -56,7 +55,7 @@ public SimpleBorder(int thickness, int red, int green, int blue, int alpha, int @Override public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mouseY, float delta) { var tessellator = Tessellator.getInstance(); - var buffer = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); RenderSystem.setShader(GameRenderer::getPositionColorShader); int x = widget.getX(); int y = widget.getY(); @@ -83,16 +82,16 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo this.vertex(buffer, x + this.thickness, bottom, focused); this.vertex(buffer, x + this.thickness, y, focused); this.vertex(buffer, x, y, focused); - C_fpcijbbg builtBuffer = buffer.method_60794(); + MeshData builtBuffer = buffer.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } - tessellator.method_60828(); + tessellator.clear(); } private void vertex(BufferBuilder buffer, int x, int y, boolean focused) { int[] color = focused ? this.focusedColor : this.color; - buffer.method_22912(x, y, 0).method_1336(color[0], color[1], color[2], color[3]); + buffer.addVertex(x, y, 0).color(color[0], color[1], color[2], color[3]); } @Override diff --git a/src/main/java/dev/lambdaurora/spruceui/event/OpenScreenCallback.java b/src/main/java/dev/lambdaurora/spruceui/event/OpenScreenCallback.java index 22a45578..5e90d335 100644 --- a/src/main/java/dev/lambdaurora/spruceui/event/OpenScreenCallback.java +++ b/src/main/java/dev/lambdaurora/spruceui/event/OpenScreenCallback.java @@ -10,8 +10,8 @@ package dev.lambdaurora.spruceui.event; import net.fabricmc.fabric.api.event.Event; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; import org.jetbrains.annotations.Nullable; /** @@ -26,5 +26,5 @@ public interface OpenScreenCallback { Event PRE = EventUtil.makeOpenScreenEvent(); Event EVENT = EventUtil.makeOpenScreenEvent(); - void apply(MinecraftClient client, @Nullable Screen screen); + void apply(Minecraft client, @Nullable Screen screen); } diff --git a/src/main/java/dev/lambdaurora/spruceui/event/ResolutionChangeCallback.java b/src/main/java/dev/lambdaurora/spruceui/event/ResolutionChangeCallback.java index 9e70d0f1..19916456 100644 --- a/src/main/java/dev/lambdaurora/spruceui/event/ResolutionChangeCallback.java +++ b/src/main/java/dev/lambdaurora/spruceui/event/ResolutionChangeCallback.java @@ -11,7 +11,7 @@ import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; /** * Represents an event callback which is fired when the Minecraft's resolution is changed. @@ -28,5 +28,5 @@ public interface ResolutionChangeCallback { } }); - void apply(MinecraftClient client); + void apply(Minecraft client); } diff --git a/src/main/java/dev/lambdaurora/spruceui/hud/Hud.java b/src/main/java/dev/lambdaurora/spruceui/hud/Hud.java index c764a30e..4a91b795 100644 --- a/src/main/java/dev/lambdaurora/spruceui/hud/Hud.java +++ b/src/main/java/dev/lambdaurora/spruceui/hud/Hud.java @@ -11,11 +11,10 @@ import com.google.common.collect.ImmutableList; import dev.lambdaurora.spruceui.util.Identifiable; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.render.DeltaTracker; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.Identifier; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -38,7 +37,7 @@ public abstract class Hud implements Identifiable { public Hud(@NotNull Identifier id) { this.identifier = id; - this.translationKey = this.identifier.getNamespace() + ".hud." + this.identifier.getPath() + this.translationKey = this.identifier.namespace() + ".hud." + this.identifier.path() .replace('/', '.'); } @@ -68,8 +67,8 @@ public boolean isEnabled() { public void setEnabled(boolean enabled) { this.enabled = enabled; if (enabled) { - MinecraftClient client = MinecraftClient.getInstance(); - this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight()); + var client = Minecraft.getInstance(); + this.init(client, client.getWindow().getGuiScaledWidth(), client.getWindow().getGuiScaledHeight()); } } @@ -91,7 +90,7 @@ public void setVisible(boolean visible) { this.visible = visible; } - public void init(@NotNull MinecraftClient client, int screenWidth, int screenHeight) { + public void init(@NotNull Minecraft client, int screenWidth, int screenHeight) { this.components.clear(); } diff --git a/src/main/java/dev/lambdaurora/spruceui/hud/HudComponent.java b/src/main/java/dev/lambdaurora/spruceui/hud/HudComponent.java index 9cd9af0d..b7831dd7 100644 --- a/src/main/java/dev/lambdaurora/spruceui/hud/HudComponent.java +++ b/src/main/java/dev/lambdaurora/spruceui/hud/HudComponent.java @@ -10,9 +10,9 @@ package dev.lambdaurora.spruceui.hud; import dev.lambdaurora.spruceui.util.Identifiable; +import net.minecraft.client.DeltaTracker; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.render.DeltaTracker; -import net.minecraft.util.Identifier; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.NotNull; /** @@ -40,7 +40,7 @@ protected HudComponent(Identifier identifier, int x, int y) { * @return This component's translation key. */ public String getTranslationKey() { - return this.identifier.getNamespace() + ".hud.component." + this.identifier.getPath(); + return this.identifier.namespace() + ".hud.component." + this.identifier.path(); } /** diff --git a/src/main/java/dev/lambdaurora/spruceui/hud/HudManager.java b/src/main/java/dev/lambdaurora/spruceui/hud/HudManager.java index 8cc9f94e..11d92c00 100644 --- a/src/main/java/dev/lambdaurora/spruceui/hud/HudManager.java +++ b/src/main/java/dev/lambdaurora/spruceui/hud/HudManager.java @@ -14,8 +14,8 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.Identifier; +import net.minecraft.client.Minecraft; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -45,11 +45,11 @@ public void initialize() { hud.tick(); }); }); - OpenScreenCallback.EVENT.register((client, screen) -> initAll(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight())); - ResolutionChangeCallback.EVENT.register(client -> initAll(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight())); + OpenScreenCallback.EVENT.register((client, screen) -> initAll(client, client.getWindow().getGuiScaledWidth(), client.getWindow().getGuiScaledHeight())); + ResolutionChangeCallback.EVENT.register(client -> initAll(client, client.getWindow().getGuiScaledWidth(), client.getWindow().getGuiScaledHeight())); } - protected static void initAll(@NotNull MinecraftClient client, int screenWidth, int screenHeight) { + protected static void initAll(@NotNull Minecraft client, int screenWidth, int screenHeight) { if (!canRenderHuds(client)) return; HUDS.forEach((id, hud) -> { @@ -93,8 +93,8 @@ public static void unregister(@NotNull Hud hud) { * @param client The client instance. * @return True if the HUDs can be rendered, else false. */ - public static boolean canRenderHuds(@NotNull MinecraftClient client) { - return client.world != null && (!client.options.hudHidden || client.currentScreen != null); + public static boolean canRenderHuds(@NotNull Minecraft client) { + return client.level != null && (!client.options.hideGui || client.screen != null); } /** diff --git a/src/main/java/dev/lambdaurora/spruceui/hud/component/TextHudComponent.java b/src/main/java/dev/lambdaurora/spruceui/hud/component/TextHudComponent.java index 8c731352..0492a61d 100644 --- a/src/main/java/dev/lambdaurora/spruceui/hud/component/TextHudComponent.java +++ b/src/main/java/dev/lambdaurora/spruceui/hud/component/TextHudComponent.java @@ -10,11 +10,11 @@ package dev.lambdaurora.spruceui.hud.component; import dev.lambdaurora.spruceui.hud.HudComponent; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.DeltaTracker; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.render.DeltaTracker; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.network.chat.Text; +import net.minecraft.resources.Identifier; /** * Represents a text HUD component. @@ -24,7 +24,7 @@ * @since 1.3.5 */ public class TextHudComponent extends HudComponent { - protected MinecraftClient client; + protected Minecraft client; protected Text text; protected int color; @@ -34,7 +34,7 @@ public TextHudComponent(Identifier identifier, int x, int y, Text text) { public TextHudComponent(Identifier identifier, int x, int y, Text text, int color) { super(identifier, x, y); - this.client = MinecraftClient.getInstance(); + this.client = Minecraft.getInstance(); this.text = text; this.color = color; } @@ -77,6 +77,6 @@ public void setColor(int color) { @Override public void render(GuiGraphics graphics, DeltaTracker deltaTracker) { - graphics.drawShadowedText(this.client.textRenderer, this.text, this.x, this.y, this.color); + graphics.drawShadowedText(this.client.font, this.text, this.x, this.y, this.color); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/mixin/MinecraftClientMixin.java b/src/main/java/dev/lambdaurora/spruceui/mixin/MinecraftClientMixin.java index afc04df9..4e83983e 100644 --- a/src/main/java/dev/lambdaurora/spruceui/mixin/MinecraftClientMixin.java +++ b/src/main/java/dev/lambdaurora/spruceui/mixin/MinecraftClientMixin.java @@ -11,8 +11,8 @@ import dev.lambdaurora.spruceui.event.OpenScreenCallback; import dev.lambdaurora.spruceui.event.ResolutionChangeCallback; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -25,20 +25,20 @@ * @version 3.2.1 * @since 1.2.0 */ -@Mixin(MinecraftClient.class) +@Mixin(Minecraft.class) public class MinecraftClientMixin { @Inject(method = "setScreen", at = @At("HEAD")) private void onScreenPre(Screen screen, CallbackInfo ci) { - OpenScreenCallback.PRE.invoker().apply((MinecraftClient) (Object) this, screen); + OpenScreenCallback.PRE.invoker().apply((Minecraft) (Object) this, screen); } @Inject(method = "setScreen", at = @At("RETURN")) private void onScreenChange(Screen screen, CallbackInfo ci) { - OpenScreenCallback.EVENT.invoker().apply((MinecraftClient) (Object) this, screen); + OpenScreenCallback.EVENT.invoker().apply((Minecraft) (Object) this, screen); } - @Inject(method = "onResolutionChanged", at = @At("RETURN")) + @Inject(method = "resizeDisplay", at = @At("RETURN")) private void onResolutionChanged(CallbackInfo ci) { - ResolutionChangeCallback.EVENT.invoker().apply((MinecraftClient) (Object) this); + ResolutionChangeCallback.EVENT.invoker().apply((Minecraft) (Object) this); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceBooleanOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceBooleanOption.java index 899cfade..c87df62d 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceBooleanOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceBooleanOption.java @@ -13,8 +13,8 @@ import dev.lambdaurora.spruceui.SpruceTexts; import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.TextFormatting; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; @@ -95,7 +95,7 @@ public Text getDisplayText() { boolean value = this.get(); var toggleText = SpruceTexts.getToggleText(value); if (this.colored) - toggleText = toggleText.copy().setStyle(toggleText.getStyle().withColor(value ? Formatting.GREEN : Formatting.RED)); + toggleText = toggleText.copy().setStyle(toggleText.getStyle().withColor(value ? TextFormatting.GREEN : TextFormatting.RED)); return this.getDisplayText(toggleText); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceCheckboxBooleanOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceCheckboxBooleanOption.java index f8c7bf5f..b8ebe278 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceCheckboxBooleanOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceCheckboxBooleanOption.java @@ -12,7 +12,7 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.widget.SpruceCheckboxWidget; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceCyclingOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceCyclingOption.java index ed92f4a1..9320418e 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceCyclingOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceCyclingOption.java @@ -12,7 +12,7 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleInputOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleInputOption.java index c39ffa53..6b3d308b 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleInputOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleInputOption.java @@ -13,10 +13,10 @@ import dev.lambdaurora.spruceui.widget.SpruceWidget; import dev.lambdaurora.spruceui.widget.text.SpruceNamedTextFieldWidget; import dev.lambdaurora.spruceui.widget.text.SpruceTextFieldWidget; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.TextFormatting; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Text; +import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; @@ -48,9 +48,9 @@ public SpruceWidget createWidget(Position position, int width) { textField.setRenderTextProvider((displayedText, offset) -> { try { Double.parseDouble(textField.getText()); - return OrderedText.forward(displayedText, Style.EMPTY); + return FormattedCharSequence.forward(displayedText, Style.EMPTY); } catch (NumberFormatException e) { - return OrderedText.forward(displayedText, Style.EMPTY.withColor(Formatting.RED)); + return FormattedCharSequence.forward(displayedText, Style.EMPTY.withColor(TextFormatting.RED)); } }); textField.setChangedListener(input -> { diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleOption.java index 1e484d37..8a64b31a 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceDoubleOption.java @@ -12,7 +12,7 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.widget.SpruceWidget; import dev.lambdaurora.spruceui.widget.option.SpruceOptionSliderWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceFloatInputOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceFloatInputOption.java index db380803..68c31ba9 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceFloatInputOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceFloatInputOption.java @@ -13,10 +13,10 @@ import dev.lambdaurora.spruceui.widget.SpruceWidget; import dev.lambdaurora.spruceui.widget.text.SpruceNamedTextFieldWidget; import dev.lambdaurora.spruceui.widget.text.SpruceTextFieldWidget; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.TextFormatting; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Text; +import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; @@ -48,9 +48,9 @@ public SpruceWidget createWidget(Position position, int width) { textField.setRenderTextProvider((displayedText, offset) -> { try { Float.parseFloat(textField.getText()); - return OrderedText.forward(displayedText, Style.EMPTY); + return FormattedCharSequence.forward(displayedText, Style.EMPTY); } catch (NumberFormatException e) { - return OrderedText.forward(displayedText, Style.EMPTY.withColor(Formatting.RED)); + return FormattedCharSequence.forward(displayedText, Style.EMPTY.withColor(TextFormatting.RED)); } }); textField.setChangedListener(input -> { diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceIntegerInputOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceIntegerInputOption.java index 8c8a7b98..ac0da41d 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceIntegerInputOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceIntegerInputOption.java @@ -14,10 +14,10 @@ import dev.lambdaurora.spruceui.widget.SpruceWidget; import dev.lambdaurora.spruceui.widget.text.SpruceNamedTextFieldWidget; import dev.lambdaurora.spruceui.widget.text.SpruceTextFieldWidget; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.TextFormatting; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Text; +import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; @@ -49,9 +49,9 @@ public SpruceWidget createWidget(Position position, int width) { textField.setRenderTextProvider((displayedText, offset) -> { try { Integer.parseInt(textField.getText()); - return OrderedText.forward(displayedText, Style.EMPTY); + return FormattedCharSequence.forward(displayedText, Style.EMPTY); } catch (NumberFormatException e) { - return OrderedText.forward(displayedText, Style.EMPTY.withColor(Formatting.RED)); + return FormattedCharSequence.forward(displayedText, Style.EMPTY.withColor(TextFormatting.RED)); } }); textField.setChangedListener(input -> { diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceOption.java index 8b0e9344..9ccdadcd 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceOption.java @@ -12,8 +12,8 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.util.Nameable; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.text.Text; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -37,7 +37,7 @@ public SpruceOption(String key) { @Override public String getName() { - return I18n.translate(this.key); + return I18n.get(this.key); } public Optional getOptionTooltip() { diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceSeparatorOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceSeparatorOption.java index 71bf9593..c1c49d29 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceSeparatorOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceSeparatorOption.java @@ -12,7 +12,7 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.widget.SpruceSeparatorWidget; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; /** diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceSimpleActionOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceSimpleActionOption.java index 22639a07..75172bd6 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceSimpleActionOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceSimpleActionOption.java @@ -13,8 +13,8 @@ import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; import dev.lambdaurora.spruceui.widget.SpruceTexturedButtonWidget; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.network.chat.Text; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Nullable; /** @@ -68,38 +68,50 @@ public static SpruceSimpleActionOption reset(SpruceButtonWidget.PressAction acti action, tooltip); } - public static SpruceSimpleActionOption textured(String key, SpruceButtonWidget.PressAction action, - int u, int v, int hoveredVOffset, Identifier texture) { + public static SpruceSimpleActionOption textured( + String key, SpruceButtonWidget.PressAction action, + int u, int v, int hoveredVOffset, Identifier texture + ) { return textured(key, action, u, v, hoveredVOffset, texture, null); } - public static SpruceSimpleActionOption textured(String key, SpruceButtonWidget.PressAction action, - int u, int v, int hoveredVOffset, Identifier texture, @Nullable Text tooltip) { + public static SpruceSimpleActionOption textured( + String key, SpruceButtonWidget.PressAction action, + int u, int v, int hoveredVOffset, Identifier texture, @Nullable Text tooltip + ) { return new SpruceSimpleActionOption(key, (position, width, message, action1) -> new SpruceTexturedButtonWidget(position, width, 20, message, action1, u, v, hoveredVOffset, texture), action, tooltip); } - public static SpruceSimpleActionOption textured(String key, SpruceButtonWidget.PressAction action, - int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight) { + public static SpruceSimpleActionOption textured( + String key, SpruceButtonWidget.PressAction action, + int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight + ) { return textured(key, action, u, v, hoveredVOffset, texture, textureWidth, textureHeight, null); } - public static SpruceSimpleActionOption textured(String key, SpruceButtonWidget.PressAction action, - int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, @Nullable Text tooltip) { + public static SpruceSimpleActionOption textured( + String key, SpruceButtonWidget.PressAction action, + int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, @Nullable Text tooltip + ) { return new SpruceSimpleActionOption(key, (position, width, message, action1) -> new SpruceTexturedButtonWidget(position, width, 20, message, action1, u, v, hoveredVOffset, texture, textureWidth, textureHeight), action, tooltip); } - public static SpruceSimpleActionOption texturedWithMessage(String key, SpruceButtonWidget.PressAction action, - int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight) { + public static SpruceSimpleActionOption texturedWithMessage( + String key, SpruceButtonWidget.PressAction action, + int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight + ) { return texturedWithMessage(key, action, u, v, hoveredVOffset, texture, textureWidth, textureHeight, null); } - public static SpruceSimpleActionOption texturedWithMessage(String key, SpruceButtonWidget.PressAction action, - int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, @Nullable Text tooltip) { + public static SpruceSimpleActionOption texturedWithMessage( + String key, SpruceButtonWidget.PressAction action, + int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, @Nullable Text tooltip + ) { return new SpruceSimpleActionOption(key, (position, width, message, action1) -> new SpruceTexturedButtonWidget(position, width, 20, message, true, action1, u, v, hoveredVOffset, texture, textureWidth, textureHeight), diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceStringOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceStringOption.java index 87daa12d..b88cf81d 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceStringOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceStringOption.java @@ -13,7 +13,7 @@ import dev.lambdaurora.spruceui.widget.SpruceWidget; import dev.lambdaurora.spruceui.widget.text.SpruceNamedTextFieldWidget; import dev.lambdaurora.spruceui.widget.text.SpruceTextFieldWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; diff --git a/src/main/java/dev/lambdaurora/spruceui/option/SpruceToggleBooleanOption.java b/src/main/java/dev/lambdaurora/spruceui/option/SpruceToggleBooleanOption.java index 597463d1..7a603470 100644 --- a/src/main/java/dev/lambdaurora/spruceui/option/SpruceToggleBooleanOption.java +++ b/src/main/java/dev/lambdaurora/spruceui/option/SpruceToggleBooleanOption.java @@ -12,7 +12,7 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.widget.SpruceToggleSwitch; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; diff --git a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java index 0e255199..41e98d4c 100644 --- a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java +++ b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java @@ -15,14 +15,14 @@ import dev.lambdaurora.spruceui.util.ScissorManager; import dev.lambdaurora.spruceui.widget.SpruceElement; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Element; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Text; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; import org.lwjgl.glfw.GLFW; import java.util.function.BooleanSupplier; @@ -36,27 +36,27 @@ * @version 5.0.0 * @since 3.3.0 */ -public abstract class SpruceHandledScreen extends HandledScreen implements SprucePositioned, SpruceElement { +public abstract class SpruceHandledScreen extends AbstractContainerScreen implements SprucePositioned, SpruceElement { protected double scaleFactor; - public SpruceHandledScreen(T handler, PlayerInventory inventory, Text title) { + public SpruceHandledScreen(T handler, Inventory inventory, Text title) { super(handler, inventory, title); } @Override - public void setFocusedChild(Element focused) { + public void setFocused(GuiEventListener focused) { var old = this.getFocused(); if (old == focused) return; if (old instanceof SpruceWidget) ((SpruceWidget) old).setFocused(false); - super.setFocusedChild(focused); + super.setFocused(focused); if (focused instanceof SpruceWidget) ((SpruceWidget) focused).setFocused(true); } @Override protected void init() { - this.scaleFactor = this.client.getWindow().getScaleFactor(); + this.scaleFactor = this.client.getWindow().getGuiScale(); } /* Input */ @@ -86,24 +86,24 @@ public boolean onNavigation(NavigationDirection direction, boolean tab) { var iterator = children.listIterator(next); BooleanSupplier hasNext = direction.isLookingForward() ? iterator::hasNext : iterator::hasPrevious; - Supplier nextGetter = direction.isLookingForward() ? iterator::next : iterator::previous; + Supplier nextGetter = direction.isLookingForward() ? iterator::next : iterator::previous; - Element nextElement; + GuiEventListener nextElement; do { if (!hasNext.getAsBoolean()) { - this.setFocusedChild(null); + this.setFocused(null); return false; } nextElement = nextGetter.get(); } while (!this.tryNavigating(nextElement, direction, tab)); - this.setFocusedChild(nextElement); + this.setFocused(nextElement); } return true; } - private boolean tryNavigating(Element element, NavigationDirection direction, boolean tab) { + private boolean tryNavigating(GuiEventListener element, NavigationDirection direction, boolean tab) { if (element instanceof SpruceElement) { return ((SpruceElement) element).onNavigation(direction, tab); } @@ -128,7 +128,7 @@ public void renderTitle(GuiGraphics graphics, int mouseX, int mouseY, float delt public void renderWidgets(GuiGraphics graphics, int mouseX, int mouseY, float delta) { for (var element : this.children()) { - if (element instanceof Drawable drawable) + if (element instanceof Renderable drawable) drawable.render(graphics, mouseX, mouseY, delta); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java index e7bd398d..d97ddd9f 100644 --- a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java +++ b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java @@ -15,11 +15,11 @@ import dev.lambdaurora.spruceui.util.ScissorManager; import dev.lambdaurora.spruceui.widget.SpruceElement; import dev.lambdaurora.spruceui.widget.SpruceWidget; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Element; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Text; import org.lwjgl.glfw.GLFW; import java.util.function.BooleanSupplier; @@ -40,19 +40,19 @@ protected SpruceScreen(Text title) { } @Override - public void setFocusedChild(Element focused) { + public void setFocused(GuiEventListener focused) { var old = this.getFocused(); if (old == focused) return; if (old instanceof SpruceWidget) old.setFocused(false); - super.setFocusedChild(focused); + super.setFocused(focused); if (focused instanceof SpruceWidget) focused.setFocused(true); } @Override protected void init() { - this.scaleFactor = this.client.getWindow().getScaleFactor(); + this.scaleFactor = this.client.getWindow().getGuiScale(); } /* Input */ @@ -81,24 +81,24 @@ public boolean onNavigation(NavigationDirection direction, boolean tab) { var iterator = children.listIterator(next); BooleanSupplier hasNext = direction.isLookingForward() ? iterator::hasNext : iterator::hasPrevious; - Supplier nextGetter = direction.isLookingForward() ? iterator::next : iterator::previous; + Supplier nextGetter = direction.isLookingForward() ? iterator::next : iterator::previous; - Element nextElement; + GuiEventListener nextElement; do { if (!hasNext.getAsBoolean()) { - this.setFocusedChild(null); + this.setFocused(null); return false; } nextElement = nextGetter.get(); } while (!this.tryNavigating(nextElement, direction, tab)); - this.setFocusedChild(nextElement); + this.setFocused(nextElement); } return true; } - private boolean tryNavigating(Element element, NavigationDirection direction, boolean tab) { + private boolean tryNavigating(GuiEventListener element, NavigationDirection direction, boolean tab) { if (element instanceof SpruceElement) { return ((SpruceElement) element).onNavigation(direction, tab); } @@ -123,7 +123,7 @@ public void renderTitle(GuiGraphics graphics, int mouseX, int mouseY, float delt public void renderWidgets(GuiGraphics graphics, int mouseX, int mouseY, float delta) { for (var element : this.children()) { - if (element instanceof Drawable drawable) + if (element instanceof Renderable drawable) drawable.render(graphics, mouseX, mouseY, delta); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/util/Identifiable.java b/src/main/java/dev/lambdaurora/spruceui/util/Identifiable.java index c8086e13..a47729b7 100644 --- a/src/main/java/dev/lambdaurora/spruceui/util/Identifiable.java +++ b/src/main/java/dev/lambdaurora/spruceui/util/Identifiable.java @@ -9,7 +9,7 @@ package dev.lambdaurora.spruceui.util; -import net.minecraft.util.Identifier; +import net.minecraft.resources.Identifier; /** * Represents something that can be identified. @@ -28,6 +28,6 @@ public interface Identifiable extends Nameable { @Override default String getName() { - return this.getIdentifier().getPath(); + return this.getIdentifier().path(); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/util/MultilineText.java b/src/main/java/dev/lambdaurora/spruceui/util/MultilineText.java index 585a7ef2..5023579b 100644 --- a/src/main/java/dev/lambdaurora/spruceui/util/MultilineText.java +++ b/src/main/java/dev/lambdaurora/spruceui/util/MultilineText.java @@ -9,7 +9,7 @@ package dev.lambdaurora.spruceui.util; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -203,7 +203,7 @@ public static Collection wrap(String text, int width) { } public static Collection wrap(Collection text, int width) { - var client = MinecraftClient.getInstance(); + var client = Minecraft.getInstance(); if (client == null) return text; @@ -217,7 +217,7 @@ public static Collection wrap(Collection tex if (line.endsWith("\n")) line = line.substring(0, line.length() - 1); while (!line.isEmpty()) { - var part = client.textRenderer.trimToWidth(line, width); + var part = client.font.plainSubstrByWidth(line, width); line = line.substring(part.length()); lines.add(part); } diff --git a/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java b/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java index 59723ed7..77489652 100644 --- a/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java +++ b/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java @@ -10,13 +10,9 @@ package dev.lambdaurora.spruceui.util; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferRenderer; -import com.mojang.blaze3d.vertex.Tessellator; -import com.mojang.blaze3d.vertex.VertexFormat; -import com.mojang.blaze3d.vertex.VertexFormats; +import com.mojang.blaze3d.vertex.*; import dev.lambdaurora.spruceui.SpruceTextures; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.unmapped.C_fpcijbbg; +import net.minecraft.client.renderer.GameRenderer; public final class RenderUtil { private RenderUtil() { @@ -53,7 +49,7 @@ public static void renderBackgroundTexture(int x, int y, int width, int height, public static void renderBackgroundTexture(int x, int y, int width, int height, float vOffset, int red, int green, int blue, int alpha) { var tessellator = Tessellator.getInstance(); - var bufferBuilder = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR); + var bufferBuilder = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); RenderSystem.setShader(GameRenderer::getPositionTexColorShader); RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); RenderSystem.setShaderTexture(0, SpruceTextures.LEGACY_OPTIONS_BACKGROUND); @@ -61,23 +57,23 @@ public static void renderBackgroundTexture(int x, int y, int width, int height, int right = x + width; int bottom = y + height; - bufferBuilder.method_22912(x, bottom, 0) - .method_22913(0, bottom / 32.f + vOffset) - .method_1336(red, green, blue, alpha); - bufferBuilder.method_22912(right, bottom, 0) - .method_22913(right / 32.f, bottom / 32.f + vOffset) - .method_1336(red, green, blue, alpha); - bufferBuilder.method_22912(right, y, 0) - .method_22913(right / 32.f, y / 32.f + vOffset) - .method_1336(red, green, blue, alpha); - bufferBuilder.method_22912(x, y, 0) - .method_22913(0, y / 32.f + vOffset) - .method_1336(red, green, blue, alpha); - C_fpcijbbg builtBuffer = bufferBuilder.method_60794(); + bufferBuilder.addVertex(x, bottom, 0) + .uv(0, bottom / 32.f + vOffset) + .color(red, green, blue, alpha); + bufferBuilder.addVertex(right, bottom, 0) + .uv(right / 32.f, bottom / 32.f + vOffset) + .color(red, green, blue, alpha); + bufferBuilder.addVertex(right, y, 0) + .uv(right / 32.f, y / 32.f + vOffset) + .color(red, green, blue, alpha); + bufferBuilder.addVertex(x, y, 0) + .uv(0, y / 32.f + vOffset) + .color(red, green, blue, alpha); + MeshData builtBuffer = bufferBuilder.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } - tessellator.method_60828(); + tessellator.clear(); } /** @@ -94,30 +90,30 @@ public static void renderBackgroundTexture(int x, int y, int width, int height, */ public static void renderSelectionBox(int x, int y, int width, int height, int red, int green, int blue, int alpha) { var tessellator = Tessellator.getInstance(); - var bufferBuilder = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); + var bufferBuilder = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); int top = y + height; int right = x + width; RenderSystem.setShader(GameRenderer::getPositionColorShader); RenderSystem.setShaderColor(red / 255.f, green / 255.f, blue / 255.f, alpha / 255.f); - bufferBuilder.method_22912(x, top, 0); - bufferBuilder.method_22912(right, top, 0); - bufferBuilder.method_22912(right, y, 0); - bufferBuilder.method_22912(x, y, 0); - C_fpcijbbg builtBuffer = bufferBuilder.method_60794(); + bufferBuilder.addVertex(x, top, 0); + bufferBuilder.addVertex(right, top, 0); + bufferBuilder.addVertex(right, y, 0); + bufferBuilder.addVertex(x, y, 0); + MeshData builtBuffer = bufferBuilder.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } RenderSystem.setShaderColor(0, 0, 0, 1.f); - bufferBuilder.method_22912(x + 1, top - 1, 0); - bufferBuilder.method_22912(right - 1, top - 1, 0); - bufferBuilder.method_22912(right - 1, y + 1, 0); - bufferBuilder.method_22912(x + 1, y + 1, 0); - builtBuffer = bufferBuilder.method_60794(); + bufferBuilder.addVertex(x + 1, top - 1, 0); + bufferBuilder.addVertex(right - 1, top - 1, 0); + bufferBuilder.addVertex(right - 1, y + 1, 0); + bufferBuilder.addVertex(x + 1, y + 1, 0); + builtBuffer = bufferBuilder.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } - tessellator.method_60828(); + tessellator.clear(); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/util/ScissorManager.java b/src/main/java/dev/lambdaurora/spruceui/util/ScissorManager.java index b5782c01..9a6c53b1 100644 --- a/src/main/java/dev/lambdaurora/spruceui/util/ScissorManager.java +++ b/src/main/java/dev/lambdaurora/spruceui/util/ScissorManager.java @@ -12,7 +12,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import it.unimi.dsi.fastutil.doubles.DoubleArrayList; import it.unimi.dsi.fastutil.doubles.DoubleList; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import java.util.ArrayDeque; import java.util.Deque; @@ -86,9 +86,9 @@ public static void pop() { } private static int adaptY(int y, int height, double scaleFactor) { - var window = MinecraftClient.getInstance().getWindow(); - int tmpHeight = (int) (window.getFramebufferHeight() / scaleFactor); - int scaledHeight = window.getFramebufferHeight() / scaleFactor > (double) tmpHeight ? tmpHeight + 1 : tmpHeight; + var window = Minecraft.getInstance().getWindow(); + int tmpHeight = (int) (window.getHeight() / scaleFactor); + int scaledHeight = window.getHeight() / scaleFactor > (double) tmpHeight ? tmpHeight + 1 : tmpHeight; return (int) (scaleFactor * (scaledHeight - height - y)); } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceBooleanButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceBooleanButtonWidget.java index ae8d184c..db23cb25 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceBooleanButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceBooleanButtonWidget.java @@ -10,7 +10,7 @@ package dev.lambdaurora.spruceui.widget; import dev.lambdaurora.spruceui.Position; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; /** * Represents a pressable button that switches between two states which values are {@code true} and {@code false}. @@ -31,19 +31,21 @@ public AbstractSpruceBooleanButtonWidget(Position position, int width, int heigh this(position, width, height, message, value, true); } - public AbstractSpruceBooleanButtonWidget(Position position, int width, int height, Text message, boolean value, - boolean showMessage) { + public AbstractSpruceBooleanButtonWidget( + Position position, int width, int height, Text message, boolean value, boolean showMessage + ) { this(position, width, height, message, DEFAULT_ACTION, value, showMessage); } - public AbstractSpruceBooleanButtonWidget(Position position, int width, int height, Text message, - PressAction action, boolean value) { + public AbstractSpruceBooleanButtonWidget( + Position position, int width, int height, Text message, PressAction action, boolean value + ) { this(position, width, height, message, action, value, true); } - public AbstractSpruceBooleanButtonWidget(Position position, int width, int height, Text message, - PressAction action, - boolean value, boolean showMessage) { + public AbstractSpruceBooleanButtonWidget( + Position position, int width, int height, Text message, PressAction action, boolean value, boolean showMessage + ) { super(position, width, height, message); this.action = action; this.value = value; diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java index ad34547d..b1c73373 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java @@ -15,11 +15,11 @@ import dev.lambdaurora.spruceui.Tooltipable; import dev.lambdaurora.spruceui.wrapper.VanillaButtonWrapper; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.client.gui.widget.ClickableWidgetStateTextures; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Text; +import net.minecraft.resources.Identifier; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -41,10 +41,9 @@ public abstract class AbstractSpruceButtonWidget extends AbstractSpruceWidget im protected float alpha = 1.f; /** - * @see net.minecraft.client.gui.widget.PressableWidget#TEXTURES + * @see net.minecraft.client.gui.components.AbstractButton#SPRITES */ - protected static final ClickableWidgetStateTextures - BUTTON_TEXTURES = new ClickableWidgetStateTextures( + protected static final WidgetSprites BUTTON_TEXTURES = new WidgetSprites( Identifier.ofDefault("widget/button"), Identifier.ofDefault("widget/button_disabled"), Identifier.ofDefault("widget/button_highlighted") ); @@ -140,7 +139,7 @@ protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY /* Rendering */ protected Identifier getTexture() { - return BUTTON_TEXTURES.getTexture(this.isActive(), this.isFocusedOrHovered()); + return BUTTON_TEXTURES.get(this.isActive(), this.isFocusedOrHovered()); } @Override @@ -153,7 +152,7 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float delta) { int color = this.active ? 16777215 : 10526880; - graphics.drawCenteredShadowedText(this.client.textRenderer, this.getMessage(), + graphics.drawCenteredShadowedText(this.client.font, this.getMessage(), this.getX() + this.getWidth() / 2, this.getY() + (this.getHeight() - 8) / 2, color | MathHelper.ceil(this.alpha * 255.0F) << 24); } @@ -183,12 +182,12 @@ protected Text getNarrationHoveredUsageMessage() { } @Override - public void appendNarrations(NarrationMessageBuilder builder) { - super.appendNarrations(builder); + public void updateNarration(NarrationElementOutput builder) { + super.updateNarration(builder); if (this.isActive()) { - if (this.isFocused()) builder.put(NarrationPart.USAGE, this.getNarrationFocusedUsageMessage()); - else builder.put(NarrationPart.USAGE, this.getNarrationHoveredUsageMessage()); + if (this.isFocused()) builder.add(NarratedElementType.USAGE, this.getNarrationFocusedUsageMessage()); + else builder.add(NarratedElementType.USAGE, this.getNarrationHoveredUsageMessage()); } - this.getTooltip().ifPresent(text -> builder.put(NarrationPart.HINT, text)); + this.getTooltip().ifPresent(text -> builder.add(NarratedElementType.HINT, text)); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceIconButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceIconButtonWidget.java index eef2f0b2..d685c225 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceIconButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceIconButtonWidget.java @@ -11,7 +11,7 @@ import dev.lambdaurora.spruceui.Position; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import net.minecraft.util.math.MathHelper; public abstract class AbstractSpruceIconButtonWidget extends SpruceButtonWidget { @@ -31,7 +31,7 @@ protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float int iconWidth = this.renderIcon(graphics, mouseX, mouseY, delta); if (!this.getMessage().getString().isEmpty()) { int color = this.isActive() ? 16777215 : 10526880; - graphics.drawCenteredShadowedText(this.client.textRenderer, this.getMessage(), + graphics.drawCenteredShadowedText(this.client.font, this.getMessage(), this.getX() + 8 + iconWidth + (this.getWidth() - 8 - iconWidth - 6) / 2, this.getY() + (this.height - 8) / 2, color | MathHelper.ceil(this.getAlpha() * 255.0F) << 24); } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSprucePressableButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSprucePressableButtonWidget.java index 73b14850..6221da3c 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSprucePressableButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSprucePressableButtonWidget.java @@ -10,7 +10,7 @@ package dev.lambdaurora.spruceui.widget; import dev.lambdaurora.spruceui.Position; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.lwjgl.glfw.GLFW; /** diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceWidget.java index 52022e3b..9693d2ad 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceWidget.java @@ -11,14 +11,15 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.navigation.NavigationDirection; -import net.minecraft.client.MinecraftClient; +import net.minecraft.Util; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.util.Util; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.network.chat.Text; +import net.minecraft.sounds.SoundEvents; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -29,7 +30,7 @@ * @since 2.0.0 */ public abstract class AbstractSpruceWidget implements SpruceWidget { - protected final MinecraftClient client = MinecraftClient.getInstance(); + protected final Minecraft client = Minecraft.getInstance(); protected final Position position; private boolean visible; protected int width; @@ -82,10 +83,10 @@ public void setActive(boolean active) { } @Override - public SelectionType getType() { - if (this.focused) return SelectionType.FOCUSED; - else if (this.hovered) return SelectionType.HOVERED; - else return SelectionType.NONE; + public @NotNull NarrationPriority narrationPriority() { + if (this.focused) return NarrationPriority.FOCUSED; + else if (this.hovered) return NarrationPriority.HOVERED; + else return NarrationPriority.NONE; } @Override @@ -161,7 +162,7 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del boolean result = this.onMouseDrag(mouseX, mouseY, button, deltaX, deltaY); if (result) { this.dragging = true; - this.lastDrag = Util.getMeasuringTimeMs(); + this.lastDrag = Util.getMillis(); } return result; } @@ -257,7 +258,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { && mouseX < this.getX() + this.getWidth() && mouseY < this.getY() + this.getHeight(); if (this.dragging && !this.isMouseHovered()) { - if (Util.getMeasuringTimeMs() - this.lastDrag > 60) { + if (Util.getMillis() - this.lastDrag > 60) { this.dragging = false; } } @@ -295,16 +296,16 @@ protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, fl /* Sound */ public void playDownSound() { - this.client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK.value(), 1.f)); + this.client.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 1.f)); } /* Narration */ @Override - public void appendNarrations(NarrationMessageBuilder builder) { + public void updateNarration(NarrationElementOutput builder) { var narrationMessage = this.getNarrationMessage(); if (narrationMessage != null) - builder.put(NarrationPart.TITLE, narrationMessage); + builder.add(NarratedElementType.TITLE, narrationMessage); } /** diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceButtonWidget.java index 7329bdc9..df4e6dd3 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceButtonWidget.java @@ -10,7 +10,7 @@ package dev.lambdaurora.spruceui.widget; import dev.lambdaurora.spruceui.Position; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; /** * Represents a button widget. diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java index 8ea88052..907ce2a6 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java @@ -12,12 +12,10 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.Position; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.Language; +import net.minecraft.locale.Language; +import net.minecraft.network.chat.Text; +import net.minecraft.resources.Identifier; import net.minecraft.util.math.MathHelper; /** @@ -110,8 +108,8 @@ protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float } if (this.showMessage) { - OrderedText message = Language.getInstance().reorder(this.client.textRenderer.trimToWidth(this.getMessage(), this.getWidth() - this.getHeight() - 4)); - graphics.drawShadowedText(MinecraftClient.getInstance().textRenderer, message, this.getX() + this.getHeight() + 4, this.getY() + (this.getHeight() - 8) / 2, + var message = Language.getInstance().getVisualOrder(this.client.font.substrByWidth(this.getMessage(), this.getWidth() - this.getHeight() - 4)); + graphics.drawShadowedText(this.client.font, message, this.getX() + this.getHeight() + 4, this.getY() + (this.getHeight() - 8) / 2, 14737632 | MathHelper.ceil(this.alpha * 255.0F) << 24); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceElement.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceElement.java index 3e4f84ba..7ec30978 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceElement.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceElement.java @@ -10,7 +10,7 @@ package dev.lambdaurora.spruceui.widget; import dev.lambdaurora.spruceui.navigation.NavigationDirection; -import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.components.events.GuiEventListener; /** * Represents an element with navigation and controller input implementation. @@ -19,7 +19,7 @@ * @version 3.0.0 * @since 2.0.0 */ -public interface SpruceElement extends Element { +public interface SpruceElement extends GuiEventListener { /** * Called when navigating in the menu. * diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceIconButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceIconButtonWidget.java index 93d1c432..85de4b9b 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceIconButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceIconButtonWidget.java @@ -11,7 +11,7 @@ import dev.lambdaurora.spruceui.Position; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; public class SpruceIconButtonWidget extends AbstractSpruceIconButtonWidget { public SpruceIconButtonWidget(Position position, int width, int height, Text message, PressAction action) { diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceLabelWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceLabelWidget.java index 35708571..b9d3eafd 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceLabelWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceLabelWidget.java @@ -15,8 +15,8 @@ import dev.lambdaurora.spruceui.border.Border; import dev.lambdaurora.spruceui.border.EmptyBorder; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; +import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -40,7 +40,7 @@ public class SpruceLabelWidget extends AbstractSpruceWidget implements Tooltipab private int baseX; //private final int maxHeight; private Text text; - private List lines; + private List lines; private Text tooltip; private boolean centered; private Border border = EmptyBorder.EMPTY_BORDER; @@ -86,9 +86,9 @@ public Text getText() { */ public void setText(Text text) { this.text = text; - this.lines = this.client.textRenderer.wrapLines(text, this.maxWidth); + this.lines = this.client.font.wrapLines(text, this.maxWidth); - int width = this.lines.stream().mapToInt(this.client.textRenderer::getWidth).max().orElse(this.maxWidth); + int width = this.lines.stream().mapToInt(this.client.font::width).max().orElse(this.maxWidth); if (width > this.maxWidth) { width = this.maxWidth; } @@ -99,7 +99,7 @@ public void setText(Text text) { this.position.setRelativeX(this.baseX); } this.width = width; - this.height = this.lines.size() * this.client.textRenderer.fontHeight + 2; + this.height = this.lines.size() * this.client.font.lineHeight + 2; } /** @@ -174,16 +174,15 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float int y = this.getY() + 2; for (var it = this.lines.iterator(); it.hasNext(); y += 9) { var line = it.next(); - int x = this.centered ? (this.getInnerX() + this.maxWidth / 2) - this.client.textRenderer.getWidth(line) / 2 - : this.getInnerX(); - graphics.drawText(this.client.textRenderer, line, x, y, 10526880, true); + int x = this.centered ? (this.getInnerX() + this.maxWidth / 2) - this.client.font.width(line) / 2 : this.getInnerX(); + graphics.drawText(this.client.font, line, x, y, 10526880, true); } this.getBorder().render(graphics, this, mouseX, mouseY, delta); if (this.tooltip != null) { if (!this.tooltip.getString().isEmpty()) { - var wrappedTooltipText = this.client.textRenderer.wrapLines(this.tooltip, Math.max(this.width / 2, 200)); + var wrappedTooltipText = this.client.font.wrapLines(this.tooltip, Math.max(this.width / 2, 200)); if (this.hovered) Tooltip.create(mouseX, mouseY, wrappedTooltipText).queue(); else if (this.focused) diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSeparatorWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSeparatorWidget.java index bbd03974..9f98859b 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSeparatorWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSeparatorWidget.java @@ -13,9 +13,8 @@ import dev.lambdaurora.spruceui.Tooltip; import dev.lambdaurora.spruceui.Tooltipable; import dev.lambdaurora.spruceui.util.ColorUtil; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -28,7 +27,6 @@ * @since 1.0.1 */ public class SpruceSeparatorWidget extends AbstractSpruceWidget implements Tooltipable { - private final MinecraftClient client = MinecraftClient.getInstance(); private Text title; private Text tooltip; private int tooltipTicks; @@ -86,13 +84,13 @@ public boolean requiresCursor() { @Override protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { if (this.title != null) { - int titleWidth = this.client.textRenderer.getWidth(this.title); + int titleWidth = this.client.font.width(this.title); int titleX = this.getX() + (this.getWidth() / 2 - titleWidth / 2); if (this.width > titleWidth) { graphics.fill(this.getX(), this.getY() + 4, titleX - 5, this.getY() + 6, ColorUtil.TEXT_COLOR); graphics.fill(titleX + titleWidth + 5, this.getY() + 4, this.getX() + this.getWidth(), this.getY() + 6, ColorUtil.TEXT_COLOR); } - graphics.drawShadowedText(this.client.textRenderer, this.title, titleX, this.getY(), ColorUtil.WHITE); + graphics.drawShadowedText(this.client.font, this.title, titleX, this.getY(), ColorUtil.WHITE); } else { graphics.fill(this.getX(), this.getY() + 4, this.getX() + this.getWidth(), this.getY() + 6, ColorUtil.TEXT_COLOR); } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java index bcb2fb58..a900e90c 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java @@ -14,8 +14,8 @@ import dev.lambdaurora.spruceui.Tooltipable; import dev.lambdaurora.spruceui.navigation.NavigationDirection; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.network.chat.Text; +import net.minecraft.resources.Identifier; import net.minecraft.util.math.MathHelper; import java.util.function.Consumer; diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java index 9af997ed..f23b0c14 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java @@ -12,8 +12,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.Position; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.network.chat.Text; +import net.minecraft.resources.Identifier; /** * Represents a textured button widget. diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java index 0928f351..70c951ae 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java @@ -14,9 +14,9 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.SpruceTexts; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.Language; +import net.minecraft.locale.Language; +import net.minecraft.network.chat.Text; +import net.minecraft.resources.Identifier; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; @@ -62,10 +62,10 @@ protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float 18, 18, 68, 36); if (this.showMessage) { - var message = Language.getInstance().reorder( - this.client.textRenderer.trimToWidth(this.getMessage(), this.getWidth() - 40) + var message = Language.getInstance().getVisualOrder( + this.client.font.substrByWidth(this.getMessage(), this.getWidth() - 40) ); - graphics.drawShadowedText(this.client.textRenderer, message, this.getX() + 36, this.getY() + (this.getHeight() - 8) / 2, + graphics.drawShadowedText(this.client.font, message, this.getX() + 36, this.getY() + (this.getHeight() - 8) / 2, 14737632 | MathHelper.ceil(this.alpha * 255.0F) << 24); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceWidget.java index 04e0d034..993fedca 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceWidget.java @@ -11,8 +11,8 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.SprucePositioned; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.narration.NarratableEntry; /** * Represents a widget. @@ -21,7 +21,7 @@ * @version 3.3.0 * @since 1.6.0 */ -public interface SpruceWidget extends SprucePositioned, SpruceElement, Selectable, Drawable { +public interface SpruceWidget extends SprucePositioned, SpruceElement, NarratableEntry, Renderable { /** * Returns the position of the widget. * @@ -115,7 +115,7 @@ default int getEndY() { * @return {@code true} if the widget is hovered, else {@code false} */ default boolean isMouseHovered() { - return this.getType() == SelectionType.HOVERED; + return this.narrationPriority() == NarrationPriority.HOVERED; } /** diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java index fd9600e8..b70ceb45 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java @@ -26,11 +26,10 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.text.Text; -import net.minecraft.unmapped.C_fpcijbbg; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.network.chat.Text; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -343,7 +342,7 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float RenderSystem.enableBlend(); var tessellator = Tessellator.getInstance(); - var buffer = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // Render the transition thingy. if (this.shouldRenderTransition()) { RenderSystem.blendFuncSeparate( @@ -352,30 +351,30 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float ); RenderSystem.setShader(GameRenderer::getPositionColorShader); // TOP - buffer.method_22912(left, top + 4, 0).method_1336(0, 0, 0, 0); - buffer.method_22912(right, top + 4, 0).method_1336(0, 0, 0, 0); - buffer.method_22912(right, top, 0).method_1336(0, 0, 0, 255); - buffer.method_22912(left, top, 0).method_1336(0, 0, 0, 255); + buffer.addVertex(left, top + 4, 0).color(0, 0, 0, 0); + buffer.addVertex(right, top + 4, 0).color(0, 0, 0, 0); + buffer.addVertex(right, top, 0).color(0, 0, 0, 255); + buffer.addVertex(left, top, 0).color(0, 0, 0, 255); // RIGHT - buffer.method_22912(right - 4, bottom, 0).method_1336(0, 0, 0, 0); - buffer.method_22912(right, bottom, 0).method_1336(0, 0, 0, 255); - buffer.method_22912(right, top, 0).method_1336(0, 0, 0, 255); - buffer.method_22912(right - 4, top, 0).method_1336(0, 0, 0, 0); + buffer.addVertex(right - 4, bottom, 0).color(0, 0, 0, 0); + buffer.addVertex(right, bottom, 0).color(0, 0, 0, 255); + buffer.addVertex(right, top, 0).color(0, 0, 0, 255); + buffer.addVertex(right - 4, top, 0).color(0, 0, 0, 0); // BOTTOM - buffer.method_22912(left, bottom, 0).method_1336(0, 0, 0, 255); - buffer.method_22912(right, bottom, 0).method_1336(0, 0, 0, 255); - buffer.method_22912(right, bottom - 4, 0).method_1336(0, 0, 0, 0); - buffer.method_22912(left, bottom - 4, 0).method_1336(0, 0, 0, 0); + buffer.addVertex(left, bottom, 0).color(0, 0, 0, 255); + buffer.addVertex(right, bottom, 0).color(0, 0, 0, 255); + buffer.addVertex(right, bottom - 4, 0).color(0, 0, 0, 0); + buffer.addVertex(left, bottom - 4, 0).color(0, 0, 0, 0); // LEFT - buffer.method_22912(left, bottom, 0).method_1336(0, 0, 0, 255); - buffer.method_22912(left + 4, bottom, 0).method_1336(0, 0, 0, 0); - buffer.method_22912(left + 4, top, 0).method_1336(0, 0, 0, 0); - buffer.method_22912(left, top, 0).method_1336(0, 0, 0, 255); - C_fpcijbbg builtBuffer = buffer.method_60794(); + buffer.addVertex(left, bottom, 0).color(0, 0, 0, 255); + buffer.addVertex(left + 4, bottom, 0).color(0, 0, 0, 0); + buffer.addVertex(left + 4, top, 0).color(0, 0, 0, 0); + buffer.addVertex(left, top, 0).color(0, 0, 0, 255); + MeshData builtBuffer = buffer.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } - tessellator.method_60828(); + tessellator.clear(); } // Scrollbar @@ -405,33 +404,33 @@ protected void renderScrollbar( int endY = this.getEndInnerBorderedY(); RenderSystem.setShader(GameRenderer::getPositionColorShader); - buffer.method_22912(scrollbarX, endY, 0.0f).method_1336(0, 0, 0, 255); - buffer.method_22912(scrollbarEndX, endY, 0.0f).method_1336(0, 0, 0, 255); - buffer.method_22912(scrollbarEndX, y, 0.0f).method_1336(0, 0, 0, 255); - buffer.method_22912(scrollbarX, y, 0.0f).method_1336(0, 0, 0, 255); - buffer.method_22912(scrollbarX, scrollbarY + scrollbarHeight, 0.0f).method_1336(128, 128, 128, 255); - buffer.method_22912(scrollbarEndX, scrollbarY + scrollbarHeight, 0.0f).method_1336(128, 128, 128, 255); - buffer.method_22912(scrollbarEndX, scrollbarY, 0.0f).method_1336(128, 128, 128, 255); - buffer.method_22912(scrollbarX, scrollbarY, 0.0f).method_1336(128, 128, 128, 255); - buffer.method_22912(scrollbarX, scrollbarY + scrollbarHeight - 1, 0.0f).method_1336(192, 192, 192, 255); - buffer.method_22912(scrollbarEndX - 1, scrollbarY + scrollbarHeight - 1, 0.0f).method_1336(192, 192, 192, 255); - buffer.method_22912(scrollbarEndX - 1, scrollbarY, 0.0f).method_1336(192, 192, 192, 255); - buffer.method_22912(scrollbarX, scrollbarY, 0.0f).method_1336(192, 192, 192, 255); - C_fpcijbbg builtBuffer = buffer.method_60794(); + buffer.addVertex(scrollbarX, endY, 0.0f).color(0, 0, 0, 255); + buffer.addVertex(scrollbarEndX, endY, 0.0f).color(0, 0, 0, 255); + buffer.addVertex(scrollbarEndX, y, 0.0f).color(0, 0, 0, 255); + buffer.addVertex(scrollbarX, y, 0.0f).color(0, 0, 0, 255); + buffer.addVertex(scrollbarX, scrollbarY + scrollbarHeight, 0.0f).color(128, 128, 128, 255); + buffer.addVertex(scrollbarEndX, scrollbarY + scrollbarHeight, 0.0f).color(128, 128, 128, 255); + buffer.addVertex(scrollbarEndX, scrollbarY, 0.0f).color(128, 128, 128, 255); + buffer.addVertex(scrollbarX, scrollbarY, 0.0f).color(128, 128, 128, 255); + buffer.addVertex(scrollbarX, scrollbarY + scrollbarHeight - 1, 0.0f).color(192, 192, 192, 255); + buffer.addVertex(scrollbarEndX - 1, scrollbarY + scrollbarHeight - 1, 0.0f).color(192, 192, 192, 255); + buffer.addVertex(scrollbarEndX - 1, scrollbarY, 0.0f).color(192, 192, 192, 255); + buffer.addVertex(scrollbarX, scrollbarY, 0.0f).color(192, 192, 192, 255); + MeshData builtBuffer = buffer.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } - tessellator.method_60828(); + tessellator.clear(); } /* Narration */ - protected void appendPositionNarrations(NarrationMessageBuilder builder, E entry) { + protected void appendPositionNarrations(NarrationElementOutput builder, E entry) { var list = this.children(); if (list.size() > 1) { int i = list.indexOf(entry); if (i != -1) { - builder.put(NarrationPart.POSITION, Text.translatable("narrator.position.list", i + 1, list.size())); + builder.add(NarratedElementType.POSITION, Text.translatable("narrator.position.list", i + 1, list.size())); } } } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceOptionListWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceOptionListWidget.java index 97c63906..fc0016a7 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceOptionListWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceOptionListWidget.java @@ -16,9 +16,9 @@ import dev.lambdaurora.spruceui.widget.AbstractSpruceWidget; import dev.lambdaurora.spruceui.widget.SpruceWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.text.Text; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -82,25 +82,25 @@ public void addAll(SpruceOption[] options) { /* Narration */ @Override - public void appendNarrations(NarrationMessageBuilder builder) { + public void updateNarration(NarrationElementOutput builder) { this.children() .stream() .filter(AbstractSpruceWidget::isMouseHovered) .findFirst() .ifPresentOrElse( hoveredEntry -> { - hoveredEntry.appendNarrations(builder.nextMessage()); + hoveredEntry.updateNarration(builder.nest()); this.appendPositionNarrations(builder, hoveredEntry); }, () -> { var focusedEntry = this.getFocused(); if (focusedEntry != null) { - focusedEntry.appendNarrations(builder.nextMessage()); + focusedEntry.updateNarration(builder.nest()); this.appendPositionNarrations(builder, focusedEntry); } } ); - builder.put(NarrationPart.USAGE, Text.translatable("narration.component_list.usage")); + builder.add(NarratedElementType.USAGE, Text.translatable("narration.component_list.usage")); } public static class OptionEntry extends SpruceEntryListWidget.Entry implements SpruceParentWidget { @@ -225,9 +225,9 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float /* Narration */ @Override - public void appendNarrations(NarrationMessageBuilder builder) { + public void updateNarration(NarrationElementOutput builder) { var focused = this.getFocused(); - if (focused != null) focused.appendNarrations(builder); + if (focused != null) focused.updateNarration(builder); } /* Navigation */ diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/container/tabbed/SpruceTabbedWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/container/tabbed/SpruceTabbedWidget.java index d83ffb1f..c7c3a7bd 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/container/tabbed/SpruceTabbedWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/container/tabbed/SpruceTabbedWidget.java @@ -21,8 +21,8 @@ import dev.lambdaurora.spruceui.widget.container.AbstractSpruceParentWidget; import dev.lambdaurora.spruceui.widget.container.SpruceEntryListWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; +import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -154,7 +154,7 @@ public boolean onNavigation(NavigationDirection direction, boolean tab) { @Override protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { if (this.title != null) { - graphics.drawCenteredShadowedText(this.client.textRenderer, this.title, this.getX() + this.list.getWidth() / 2, + graphics.drawCenteredShadowedText(this.client.font, this.title, this.getX() + this.list.getWidth() / 2, this.getY() + 6, 0xffffffff); } this.list.render(graphics, mouseX, mouseY, delta); @@ -205,16 +205,16 @@ protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, fl } public static class TabEntry extends Entry { - private final List title; - private final List description; + private final List title; + private final List description; private final AbstractSpruceWidget container; private boolean selected; protected TabEntry(SideTabList parent, Text title, @Nullable Text description, AbstractSpruceWidget container) { super(parent, title); - this.title = this.client.textRenderer.wrapLines(title, this.parent.getWidth() - 18); + this.title = this.client.font.wrapLines(title, this.parent.getWidth() - 18); if (description == null) this.description = null; - else this.description = this.client.textRenderer.wrapLines(description, this.parent.getWidth() - 18); + else this.description = this.client.font.wrapLines(description, this.parent.getWidth() - 18); this.container = container; if (container instanceof SpruceEntryListWidget listWidget) { @@ -224,8 +224,8 @@ protected TabEntry(SideTabList parent, Text title, @Nullable Text description, A @Override public int getHeight() { - return 4 + (this.title.size() * this.client.textRenderer.fontHeight + 4) - + (this.description == null ? 0 : this.description.size() * this.client.textRenderer.fontHeight + 4) + 4; + return 4 + (this.title.size() * this.client.font.lineHeight + 4) + + (this.description == null ? 0 : this.description.size() * this.client.font.lineHeight + 4) + 4; } public boolean isSelected() { @@ -258,13 +258,13 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float int y = this.getY() + 4; for (var it = this.title.iterator(); it.hasNext(); y += 9) { var line = it.next(); - graphics.drawText(this.client.textRenderer, line, this.getX() + 4, y, 0xffffff, false); + graphics.drawText(this.client.font, line, this.getX() + 4, y, 0xffffff, false); } if (this.description != null) { y += 4; for (var it = this.description.iterator(); it.hasNext(); y += 9) { var line = it.next(); - graphics.drawText(this.client.textRenderer, line, this.getX() + 8, y, 0xffffff, false); + graphics.drawText(this.client.font, line, this.getX() + 8, y, 0xffffff, false); } } } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/option/SpruceOptionSliderWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/option/SpruceOptionSliderWidget.java index e1c37494..44db18d9 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/option/SpruceOptionSliderWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/option/SpruceOptionSliderWidget.java @@ -12,7 +12,7 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.option.SpruceDoubleOption; import dev.lambdaurora.spruceui.widget.SpruceSliderWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; /** * Represents an option slider widget. diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java index 5105ae63..42602483 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java @@ -19,7 +19,7 @@ import dev.lambdaurora.spruceui.widget.WithBackground; import dev.lambdaurora.spruceui.widget.WithBorder; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; /** * Represents a text input widget. diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceNamedTextFieldWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceNamedTextFieldWidget.java index a21b31f7..04a27150 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceNamedTextFieldWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceNamedTextFieldWidget.java @@ -17,7 +17,7 @@ import dev.lambdaurora.spruceui.widget.WithBackground; import dev.lambdaurora.spruceui.widget.WithBorder; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.text.OrderedText; +import net.minecraft.util.FormattedCharSequence; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -101,11 +101,11 @@ public void setTextPredicate(Predicate textPredicate) { this.getTextFieldWidget().setTextPredicate(textPredicate); } - public BiFunction getRenderTextProvider() { + public BiFunction getRenderTextProvider() { return this.getTextFieldWidget().getRenderTextProvider(); } - public void setRenderTextProvider(BiFunction renderTextProvider) { + public void setRenderTextProvider(BiFunction renderTextProvider) { this.getTextFieldWidget().setRenderTextProvider(renderTextProvider); } @@ -222,7 +222,7 @@ protected boolean onCharTyped(char chr, int keyCode) { @Override protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - graphics.drawShadowedText(this.client.textRenderer, this.getTextFieldWidget().getTitle(), this.getX() + 2, this.getY() + 2, ColorUtil.TEXT_COLOR); + graphics.drawShadowedText(this.client.font, this.getTextFieldWidget().getTitle(), this.getX() + 2, this.getY() + 2, ColorUtil.TEXT_COLOR); this.getTextFieldWidget().render(graphics, mouseX, mouseY, delta); } diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java index 21fb853e..042ec65f 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java @@ -11,23 +11,18 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferRenderer; -import com.mojang.blaze3d.vertex.Tessellator; -import com.mojang.blaze3d.vertex.VertexFormat; -import com.mojang.blaze3d.vertex.VertexFormats; +import com.mojang.blaze3d.vertex.*; import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.border.Border; import dev.lambdaurora.spruceui.navigation.NavigationDirection; import dev.lambdaurora.spruceui.util.ColorUtil; import dev.lambdaurora.spruceui.util.MultilineText; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.text.Text; -import net.minecraft.unmapped.C_fpcijbbg; -import net.minecraft.util.ChatUtil; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.network.chat.Text; +import net.minecraft.util.StringUtil; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -43,7 +38,7 @@ * @since 1.6.3 */ public class SpruceTextAreaWidget extends AbstractSpruceTextInputWidget { - private final TextRenderer textRenderer; + private final Font font; private final MultilineText lines; private final Cursor cursor = new Cursor(true); private final Selection selection = new Selection(); @@ -52,8 +47,8 @@ public class SpruceTextAreaWidget extends AbstractSpruceTextInputWidget { public SpruceTextAreaWidget(Position position, int width, int height, Text title) { super(position, width, height, title); - this.textRenderer = this.client.textRenderer; - this.displayedLines = this.getInnerHeight() / this.textRenderer.fontHeight; + this.font = this.client.font; + this.displayedLines = this.getInnerHeight() / this.font.lineHeight; this.lines = new MultilineText(this.getInnerWidth()); this.cursor.toStart(); this.sanitize(); @@ -288,7 +283,7 @@ public void write(String text) { } protected boolean doesLineOccupyFullSpace(String cursorLine) { - return this.textRenderer.getWidth(cursorLine) >= this.getInnerWidth(); + return this.font.width(cursorLine) >= this.getInnerWidth(); } @Override @@ -321,7 +316,7 @@ public boolean onNavigation(NavigationDirection direction, boolean tab) { @Override protected boolean onCharTyped(char chr, int keyCode) { - if (!this.isEditorActive() || !ChatUtil.method_57175(chr)) + if (!this.isEditorActive() || !StringUtil.isAllowedChatCharacter(chr)) return false; if (this.isEditable()) { @@ -340,12 +335,12 @@ protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) { this.selection.selectAll(); return true; } else if (Screen.isPaste(keyCode)) { - this.write(MinecraftClient.getInstance().keyboard.getClipboard()); + this.write(this.client.keyboardHandler.getClipboard()); return true; } else if (Screen.isCopy(keyCode) || Screen.isCut(keyCode)) { var selected = this.selection.getSelectedText(); if (!selected.isEmpty()) - MinecraftClient.getInstance().keyboard.setClipboard(selected); + this.client.keyboardHandler.setClipboard(selected); if (Screen.isCut(keyCode) && this.isEditable()) { this.selection.erase(); this.sanitize(); @@ -353,45 +348,39 @@ protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) { return true; } - switch (keyCode) { - case GLFW.GLFW_KEY_RIGHT: - return this.onSelectionUpdate(this.cursor::moveRight); - case GLFW.GLFW_KEY_LEFT: - return this.onSelectionUpdate(this.cursor::moveLeft); - case GLFW.GLFW_KEY_UP: - return this.onSelectionUpdate(this.cursor::moveUp); - case GLFW.GLFW_KEY_DOWN: - return this.onSelectionUpdate(this.cursor::moveDown); - case GLFW.GLFW_KEY_END: - return this.onSelectionUpdate(Screen.hasControlDown() ? this.cursor::toEnd : this.cursor::toRowEnd); - case GLFW.GLFW_KEY_HOME: - return this.onSelectionUpdate(Screen.hasControlDown() ? this.cursor::toStart : this.cursor::toLineStart); - case GLFW.GLFW_KEY_PAGE_UP: - return this.onSelectionUpdate(() -> this.cursor.moveVertical(-this.cursor.row)); - case GLFW.GLFW_KEY_PAGE_DOWN: - return this.onSelectionUpdate(() -> this.cursor.moveVertical(this.lines.size() - this.cursor.row)); - case GLFW.GLFW_KEY_ENTER: - case GLFW.GLFW_KEY_KP_ENTER: + return switch (keyCode) { + case GLFW.GLFW_KEY_RIGHT -> this.onSelectionUpdate(this.cursor::moveRight); + case GLFW.GLFW_KEY_LEFT -> this.onSelectionUpdate(this.cursor::moveLeft); + case GLFW.GLFW_KEY_UP -> this.onSelectionUpdate(this.cursor::moveUp); + case GLFW.GLFW_KEY_DOWN -> this.onSelectionUpdate(this.cursor::moveDown); + case GLFW.GLFW_KEY_END -> this.onSelectionUpdate(Screen.hasControlDown() ? this.cursor::toEnd : this.cursor::toRowEnd); + case GLFW.GLFW_KEY_HOME -> this.onSelectionUpdate(Screen.hasControlDown() ? this.cursor::toStart : this.cursor::toLineStart); + case GLFW.GLFW_KEY_PAGE_UP -> this.onSelectionUpdate(() -> this.cursor.moveVertical(-this.cursor.row)); + case GLFW.GLFW_KEY_PAGE_DOWN -> this.onSelectionUpdate(() -> this.cursor.moveVertical(this.lines.size() - this.cursor.row)); + case GLFW.GLFW_KEY_ENTER, GLFW.GLFW_KEY_KP_ENTER -> { if (this.isEditable()) this.insertCharacter('\n'); - return true; - case GLFW.GLFW_KEY_BACKSPACE: + yield true; + } + case GLFW.GLFW_KEY_BACKSPACE -> { if (this.isEditable()) this.eraseCharacter(); - return true; - case GLFW.GLFW_KEY_DELETE: + yield true; + } + case GLFW.GLFW_KEY_DELETE -> { if (this.isEditable()) this.removeCharacterForward(); - return true; - case GLFW.GLFW_KEY_D: + yield true; + } + case GLFW.GLFW_KEY_D -> { if (Screen.hasControlDown() && this.isEditable() && !this.lines.isEmpty()) { this.lines.remove(this.cursor.row); this.sanitize(); } - return true; - default: - return false; - } + yield true; + } + default -> false; + }; } private boolean onSelectionUpdate(Runnable action) { @@ -421,7 +410,7 @@ protected boolean onMouseClick(double mouseX, double mouseY, int button) { this.onSelectionUpdate(() -> { this.cursor.row = row; - this.cursor.lastColumn = this.cursor.column = this.textRenderer.trimToWidth(this.lines.get(row), x).length(); + this.cursor.lastColumn = this.cursor.column = this.font.plainSubstrByWidth(this.lines.get(row), x).length(); }); return true; @@ -472,10 +461,10 @@ protected void drawText(GuiGraphics graphics) { continue; if (line.endsWith("\n")) line = line.substring(0, line.length() - 1); - graphics.drawShadowedText(this.textRenderer, Text.literal(line), textX, lineY, textColor); + graphics.drawShadowedText(this.font, Text.literal(line), textX, lineY, textColor); this.drawSelection(graphics, line, lineY, row); - lineY += this.textRenderer.fontHeight; + lineY += this.font.lineHeight; } } @@ -507,27 +496,27 @@ protected void drawSelection(GuiGraphics graphics, String line, int lineY, int r if (startIndex >= line.length() || startIndex == endIndex) return; - int x = this.getX() + 4 + this.textRenderer.getWidth(line.substring(0, startIndex)); + int x = this.getX() + 4 + this.font.width(line.substring(0, startIndex)); var selected = line.substring(startIndex, endIndex); - int x2 = x + this.textRenderer.getWidth(selected); - int y2 = lineY + this.textRenderer.fontHeight; + int x2 = x + this.font.width(selected); + int y2 = lineY + this.font.lineHeight; var tessellator = Tessellator.getInstance(); - var buffer = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); + var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); RenderSystem.setShader(GameRenderer::getPositionShader); RenderSystem.setShaderColor(0.0f, 0.0f, 1.0f, 1.0f); - buffer.method_22912(x, y2, 0.f); - buffer.method_22912(x2, y2, 0.f); - buffer.method_22912(x2, lineY, 0.f); - buffer.method_22912(x, lineY, 0.f); - C_fpcijbbg builtBuffer = buffer.method_60794(); + buffer.addVertex(x, y2, 0.f); + buffer.addVertex(x2, y2, 0.f); + buffer.addVertex(x2, lineY, 0.f); + buffer.addVertex(x, lineY, 0.f); + MeshData builtBuffer = buffer.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } - tessellator.method_60828(); + tessellator.clear(); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderSystem.disableColorLogicOp(); } @@ -541,7 +530,7 @@ protected void drawCursor(GuiGraphics graphics) { if (!this.isFocused()) return; if (this.lines.isEmpty()) { - graphics.drawShadowedText(this.textRenderer, Text.literal("_"), this.getX(), this.getY() + 4, ColorUtil.TEXT_COLOR); + graphics.drawShadowedText(this.font, Text.literal("_"), this.getX(), this.getY() + 4, ColorUtil.TEXT_COLOR); return; } @@ -549,13 +538,13 @@ protected void drawCursor(GuiGraphics graphics) { int actualRow = this.cursor.row - firstLine; String cursorLine = this.lines.get(this.cursor.row); - int cursorX = this.getX() + 4 + this.textRenderer.getWidth(cursorLine.substring(0, this.cursor.column)); - int cursorY = this.getY() + 4 + actualRow * this.textRenderer.fontHeight; + int cursorX = this.getX() + 4 + this.font.width(cursorLine.substring(0, this.cursor.column)); + int cursorY = this.getY() + 4 + actualRow * this.font.lineHeight; if (this.cursor.row < this.lines.size() - 1 || this.cursor.column < cursorLine.length() || this.doesLineOccupyFullSpace(cursorLine)) graphics.fill(cursorX - 1, cursorY - 1, cursorX, cursorY + 9, ColorUtil.TEXT_COLOR); else - graphics.drawShadowedText(this.textRenderer, "_", cursorX, cursorY, ColorUtil.TEXT_COLOR); + graphics.drawShadowedText(this.font, "_", cursorX, cursorY, ColorUtil.TEXT_COLOR); } /** diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java index bfb5c4c5..34926647 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java @@ -11,27 +11,22 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferRenderer; -import com.mojang.blaze3d.vertex.Tessellator; -import com.mojang.blaze3d.vertex.VertexFormat; -import com.mojang.blaze3d.vertex.VertexFormats; +import com.mojang.blaze3d.vertex.*; import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.Tooltip; import dev.lambdaurora.spruceui.Tooltipable; import dev.lambdaurora.spruceui.navigation.NavigationDirection; import dev.lambdaurora.spruceui.util.ColorUtil; -import net.minecraft.client.MinecraftClient; +import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.unmapped.C_fpcijbbg; -import net.minecraft.util.ChatUtil; -import net.minecraft.util.Util; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Text; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.util.StringUtil; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -85,7 +80,7 @@ public class SpruceTextFieldWidget extends AbstractSpruceTextInputWidget impleme private Consumer changedListener; private Predicate textPredicate; - private BiFunction renderTextProvider; + private BiFunction renderTextProvider; private int firstCharacterIndex = 0; private long editingTime; @@ -100,7 +95,7 @@ public SpruceTextFieldWidget(Position position, int width, int height, Text titl this.changedListener = (input) -> { }; this.textPredicate = Objects::nonNull; - this.renderTextProvider = (input, firstCharacterIndex) -> OrderedText.forward(input, Style.EMPTY); + this.renderTextProvider = (input, firstCharacterIndex) -> FormattedCharSequence.forward(input, Style.EMPTY); } @Override @@ -146,11 +141,11 @@ public void setTextPredicate(Predicate textPredicate) { this.textPredicate = textPredicate; } - public BiFunction getRenderTextProvider() { + public BiFunction getRenderTextProvider() { return this.renderTextProvider; } - public void setRenderTextProvider(BiFunction renderTextProvider) { + public void setRenderTextProvider(BiFunction renderTextProvider) { this.renderTextProvider = renderTextProvider; } @@ -174,10 +169,10 @@ protected void sanitize() { } int width = this.getInnerWidth(); - var string = this.client.textRenderer.trimToWidth(this.text.substring(this.firstCharacterIndex), width); + var string = this.client.font.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), width); int l = string.length() + this.firstCharacterIndex; if (this.cursor.column == this.firstCharacterIndex) { - this.firstCharacterIndex -= this.client.textRenderer.trimToWidth(this.text, width, true).length(); + this.firstCharacterIndex -= this.client.font.plainSubstrByWidth(this.text, width, true).length(); } if (this.cursor.column > l) { @@ -194,7 +189,7 @@ private void onChanged() { this.changedListener.accept(this.text); } - this.editingTime = Util.getMeasuringTimeMs() + 5000L; + this.editingTime = Util.getMillis() + 5000L; } private boolean onSelectionUpdate(Runnable action) { @@ -336,7 +331,7 @@ public boolean onNavigation(NavigationDirection direction, boolean tab) { @Override protected boolean onCharTyped(char chr, int keyCode) { - if (!this.isEditorActive() || !ChatUtil.method_57175(chr)) + if (!this.isEditorActive() || !StringUtil.isAllowedChatCharacter(chr)) return false; if (this.isActive()) { @@ -356,12 +351,12 @@ protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) { this.sanitize(); return true; } else if (Screen.isPaste(keyCode)) { - this.write(MinecraftClient.getInstance().keyboard.getClipboard()); + this.write(this.client.keyboardHandler.getClipboard()); return true; } else if (Screen.isCopy(keyCode) || Screen.isCut(keyCode)) { var selected = this.selection.getSelectedText(); if (!selected.isEmpty()) - MinecraftClient.getInstance().keyboard.setClipboard(selected); + this.client.keyboardHandler.setClipboard(selected); if (Screen.isCut(keyCode)) { this.selection.erase(); this.sanitize(); @@ -369,29 +364,27 @@ protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) { return true; } - switch (keyCode) { - case GLFW.GLFW_KEY_RIGHT: - return this.onSelectionUpdate(this.cursor::moveRight); - case GLFW.GLFW_KEY_LEFT: - return this.onSelectionUpdate(this.cursor::moveLeft); - case GLFW.GLFW_KEY_END: - return this.onSelectionUpdate(this.cursor::toEnd); - case GLFW.GLFW_KEY_HOME: - return this.onSelectionUpdate(this.cursor::toStart); - case GLFW.GLFW_KEY_BACKSPACE: + return switch (keyCode) { + case GLFW.GLFW_KEY_RIGHT -> this.onSelectionUpdate(this.cursor::moveRight); + case GLFW.GLFW_KEY_LEFT -> this.onSelectionUpdate(this.cursor::moveLeft); + case GLFW.GLFW_KEY_END -> this.onSelectionUpdate(this.cursor::toEnd); + case GLFW.GLFW_KEY_HOME -> this.onSelectionUpdate(this.cursor::toStart); + case GLFW.GLFW_KEY_BACKSPACE -> { this.eraseCharacter(); - return true; - case GLFW.GLFW_KEY_DELETE: + yield true; + } + case GLFW.GLFW_KEY_DELETE -> { this.removeCharacterForward(); - return true; - case GLFW.GLFW_KEY_D: + yield true; + } + case GLFW.GLFW_KEY_D -> { if (Screen.hasControlDown() && !this.text.isEmpty()) { this.setText(""); } - return true; - default: - return false; - } + yield true; + } + default -> false; + }; } @Override @@ -402,10 +395,10 @@ protected boolean onMouseClick(double mouseX, double mouseY, int button) { this.setFocused(true); this.onSelectionUpdate(() -> { - var displayedText = this.client.textRenderer.trimToWidth(this.text.substring(this.firstCharacterIndex), + var displayedText = this.client.font.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth()); this.cursor.lastColumn = this.cursor.column = this.firstCharacterIndex - + this.client.textRenderer.trimToWidth(displayedText, x).length(); + + this.client.font.plainSubstrByWidth(displayedText, x).length(); }); return true; @@ -426,7 +419,7 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float if (!this.dragging && this.editingTime == 0) { Tooltip.queueFor(this, mouseX, mouseY, this.tooltipTicks, i -> this.tooltipTicks = i, this.lastTick, i -> this.lastTick = i); - } else if (this.editingTime < Util.getMeasuringTimeMs()) { + } else if (this.editingTime < Util.getMillis()) { this.editingTime = 0; } } @@ -441,10 +434,10 @@ protected void drawText(GuiGraphics graphics) { int x = this.getX() + 4; int y = this.getY() + this.getHeight() / 2 - 4; - var displayedText = this.client.textRenderer.trimToWidth(this.text.substring(this.firstCharacterIndex), + var displayedText = this.client.font.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth()); - graphics.drawShadowedText(this.client.textRenderer, this.renderTextProvider.apply(displayedText, this.firstCharacterIndex), + graphics.drawShadowedText(this.client.font, this.renderTextProvider.apply(displayedText, this.firstCharacterIndex), x, y, textColor); this.drawSelection(displayedText, y); } @@ -465,27 +458,27 @@ protected void drawSelection(String line, int lineY) { if (startIndex >= line.length()) return; - int x = this.getX() + 4 + this.client.textRenderer.getWidth(line.substring(0, startIndex)); + int x = this.getX() + 4 + this.client.font.width(line.substring(0, startIndex)); var selected = line.substring(startIndex, endIndex); - int x2 = x + this.client.textRenderer.getWidth(selected); - int y2 = lineY + this.client.textRenderer.fontHeight; + int x2 = x + this.client.font.width(selected); + int y2 = lineY + this.client.font.lineHeight; var tessellator = Tessellator.getInstance(); - var buffer = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); + var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); RenderSystem.setShader(GameRenderer::getPositionShader); RenderSystem.setShaderColor(0.f, 0.f, 255.f, 255.f); - buffer.method_22912(x, y2, 0.f); - buffer.method_22912(x2, y2, 0.f); - buffer.method_22912(x2, lineY, 0.f); - buffer.method_22912(x, lineY, 0.f); - C_fpcijbbg builtBuffer = buffer.method_60794(); + buffer.addVertex(x, y2, 0.f); + buffer.addVertex(x2, y2, 0.f); + buffer.addVertex(x2, lineY, 0.f); + buffer.addVertex(x, lineY, 0.f); + MeshData builtBuffer = buffer.build(); if (builtBuffer != null) { - BufferRenderer.drawWithShader(builtBuffer); + BufferUploader.drawWithShader(builtBuffer); } - tessellator.method_60828(); + tessellator.clear(); RenderSystem.disableColorLogicOp(); } @@ -501,7 +494,7 @@ protected void drawCursor(GuiGraphics graphics) { int cursorY = this.getY() + this.getHeight() / 2 - 4; if (this.text.isEmpty()) { - graphics.drawShadowedText(this.client.textRenderer, Text.literal("_"), + graphics.drawShadowedText(this.client.font, Text.literal("_"), this.getX() + 4, cursorY, ColorUtil.TEXT_COLOR); return; } @@ -509,22 +502,22 @@ protected void drawCursor(GuiGraphics graphics) { this.cursor.sanitize(); var cursorLine = this.text.substring(this.firstCharacterIndex); - int cursorX = this.getX() + 4 + this.client.textRenderer.getWidth( + int cursorX = this.getX() + 4 + this.client.font.width( cursorLine.substring(0, this.cursor.column - this.firstCharacterIndex) ); if (this.cursor.column - this.firstCharacterIndex < cursorLine.length()) graphics.fill(cursorX - 1, cursorY - 1, cursorX, cursorY + 9, ColorUtil.TEXT_COLOR); else - graphics.drawShadowedText(this.client.textRenderer, "_", cursorX, cursorY, ColorUtil.TEXT_COLOR); + graphics.drawShadowedText(this.client.font, "_", cursorX, cursorY, ColorUtil.TEXT_COLOR); } /* Narration */ @Override - public void appendNarrations(NarrationMessageBuilder builder) { - super.appendNarrations(builder); - this.getTooltip().ifPresent(text -> builder.put(NarrationPart.HINT, text)); + public void updateNarration(NarrationElementOutput builder) { + super.updateNarration(builder); + this.getTooltip().ifPresent(text -> builder.add(NarratedElementType.HINT, text)); } /** diff --git a/src/main/java/dev/lambdaurora/spruceui/wrapper/VanillaButtonWrapper.java b/src/main/java/dev/lambdaurora/spruceui/wrapper/VanillaButtonWrapper.java index ad1f4ed6..ef0a3a8f 100644 --- a/src/main/java/dev/lambdaurora/spruceui/wrapper/VanillaButtonWrapper.java +++ b/src/main/java/dev/lambdaurora/spruceui/wrapper/VanillaButtonWrapper.java @@ -15,8 +15,8 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.widget.ClickableWidget; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.narration.NarrationElementOutput; /** * Represents a vanilla button wrapper for SpruceUI's own button widgets. @@ -26,7 +26,7 @@ * @since 2.0.0 */ @Environment(EnvType.CLIENT) -public class VanillaButtonWrapper extends ClickableWidget implements SpruceElement { +public class VanillaButtonWrapper extends AbstractWidget implements SpruceElement { private final AbstractSpruceButtonWidget widget; public VanillaButtonWrapper(AbstractSpruceButtonWidget widget) { @@ -35,7 +35,7 @@ public VanillaButtonWrapper(AbstractSpruceButtonWidget widget) { } @Override - public void drawWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { this.widget.getPosition().setRelativeY(this.getY()); this.widget.render(graphics, mouseX, mouseY, delta); } @@ -71,12 +71,12 @@ public boolean keyReleased(final int keyCode, final int scanCode, final int modi } @Override - public SelectionType getType() { - return this.widget.getType(); + public NarrationPriority narrationPriority() { + return this.widget.narrationPriority(); } @Override - public void updateNarration(NarrationMessageBuilder builder) { - this.widget.appendNarrations(builder); + public void updateWidgetNarration(NarrationElementOutput builder) { + this.widget.updateNarration(builder); } } diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java b/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java index 24b9bd0c..ad558666 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java @@ -17,9 +17,9 @@ import dev.lambdaurora.spruceui.widget.container.SpruceOptionListWidget; import dev.lambdaurora.spruceui.widget.text.SpruceTextAreaWidget; import net.fabricmc.api.ClientModInitializer; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.toast.SystemToast; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.toasts.SystemToast; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -107,10 +107,10 @@ public SpruceUITest() { // Choose whatever action this option should do. this.actionOption = SpruceSimpleActionOption.of("spruceui_test.option.action", btn -> { - MinecraftClient client = MinecraftClient.getInstance(); - SystemToast toast = SystemToast.create(client, SystemToast.Id.PERIODIC_NOTIFICATION, + Minecraft client = Minecraft.getInstance(); + SystemToast toast = SystemToast.multiline(client, SystemToast.SystemToastId.PERIODIC_NOTIFICATION, Text.literal("Action button pressed!"), Text.literal("I'm a result of the action")); - client.getToastManager().add(toast); + client.getToasts().addToast(toast); }, Text.literal("Represents an option with a simple action.\n" + "It's used like a normal button and a press callback.")); diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/TestEnum.java b/src/testmod/java/dev/lambdaurora/spruceui/test/TestEnum.java index 5882bcce..6590f9d1 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/TestEnum.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/TestEnum.java @@ -10,7 +10,7 @@ package dev.lambdaurora.spruceui.test; import dev.lambdaurora.spruceui.util.Nameable; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.NotNull; /** diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceMainMenuScreen.java b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceMainMenuScreen.java index d0e8c26e..03c79217 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceMainMenuScreen.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceMainMenuScreen.java @@ -14,8 +14,8 @@ import dev.lambdaurora.spruceui.screen.SpruceScreen; import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; /** @@ -36,20 +36,20 @@ protected void init() { super.init(); int startY = this.height / 4 + 48; - this.addDrawableSelectableElement(new SpruceButtonWidget(Position.of(this, this.width / 2 - 100, startY), 200, 20, Text.literal("Option Test"), + this.addRenderableWidget(new SpruceButtonWidget(Position.of(this, this.width / 2 - 100, startY), 200, 20, Text.literal("Option Test"), btn -> this.client.setScreen(new SpruceOptionScreen(this)))); - this.addDrawableSelectableElement(new SpruceButtonWidget(Position.of(this, this.width / 2 - 100, startY += 25), 200, 20, Text.literal("Text Area Test"), + this.addRenderableWidget(new SpruceButtonWidget(Position.of(this, this.width / 2 - 100, startY += 25), 200, 20, Text.literal("Text Area Test"), btn -> this.client.setScreen(new SpruceTextAreaScreen(this)))); - this.addDrawableSelectableElement(new SpruceButtonWidget(Position.of(this, this.width / 2 - 100, startY += 25), 200, 20, Text.literal("Tabbed Screen Test"), + this.addRenderableWidget(new SpruceButtonWidget(Position.of(this, this.width / 2 - 100, startY += 25), 200, 20, Text.literal("Tabbed Screen Test"), btn -> this.client.setScreen(new SpruceTabbedTestScreen(this)))); // Add done button. - this.addDrawableSelectableElement(new SpruceButtonWidget(Position.of(this, this.width / 2 - 75, this.height - 29), 150, 20, SpruceTexts.GUI_DONE, + this.addRenderableWidget(new SpruceButtonWidget(Position.of(this, this.width / 2 - 75, this.height - 29), 150, 20, SpruceTexts.GUI_DONE, btn -> this.client.setScreen(this.parent))); } @Override public void renderTitle(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - guiGraphics.drawCenteredShadowedText(this.textRenderer, this.title, this.width / 2, 8, 16777215); + guiGraphics.drawCenteredShadowedText(this.font, this.title, this.width / 2, 8, 16777215); } } diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceOptionScreen.java b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceOptionScreen.java index 82b9a7f7..60f3a646 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceOptionScreen.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceOptionScreen.java @@ -17,8 +17,8 @@ import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; import dev.lambdaurora.spruceui.widget.container.SpruceOptionListWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; /** @@ -38,7 +38,7 @@ public SpruceOptionScreen(@Nullable Screen parent) { } private int getTextHeight() { - return (5 + this.textRenderer.fontHeight) * 3 + 5; + return (5 + this.font.lineHeight) * 3 + 5; } @Override @@ -50,20 +50,20 @@ protected void init() { this.list = SpruceUITest.get().buildOptionList(Position.of(0, 22), this.width, this.height - 35 - 22); SpruceUITest.get().resetConsumer = btn -> { // Re-initialize the screen to update all the values. - this.init(this.client, this.client.getWindow().getScaledWidth(), this.client.getWindow().getScaledHeight()); + this.init(this.client, this.client.getWindow().getGuiScaledWidth(), this.client.getWindow().getGuiScaledHeight()); }; - this.addDrawableSelectableElement(this.list); + this.addRenderableWidget(this.list); // Add reset button. You can add option buttons outside a button list widget. GameOptions instance is required because of Vanilla limitations. //this.addButton(this.resetOption.createButton(this.client.options, this.width / 2 - 155, this.height - 29, 150)); // Add done button. - this.addDrawableSelectableElement(new SpruceButtonWidget(Position.of(this, this.width / 2 - 155 + 160, this.height - 29), 150, 20, SpruceTexts.GUI_DONE, + this.addRenderableWidget(new SpruceButtonWidget(Position.of(this, this.width / 2 - 155 + 160, this.height - 29), 150, 20, SpruceTexts.GUI_DONE, btn -> this.client.setScreen(this.parent)).asVanilla()); } @Override public void renderTitle(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - guiGraphics.drawCenteredShadowedText(this.textRenderer, this.title, this.width / 2, 8, 16777215); + guiGraphics.drawCenteredShadowedText(this.font, this.title, this.width / 2, 8, 16777215); } } diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTabbedTestScreen.java b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTabbedTestScreen.java index 3044d866..0dde05b0 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTabbedTestScreen.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTabbedTestScreen.java @@ -17,9 +17,9 @@ import dev.lambdaurora.spruceui.widget.SpruceLabelWidget; import dev.lambdaurora.spruceui.widget.container.SpruceContainerWidget; import dev.lambdaurora.spruceui.widget.container.tabbed.SpruceTabbedWidget; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.TextFormatting; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; public class SpruceTabbedTestScreen extends SpruceScreen { @@ -40,27 +40,27 @@ protected void init() { var container = new SpruceContainerWidget(Position.origin(), width, height); container.addChildren((containerWidth, containerHeight, widgetAdder) -> { widgetAdder.accept(new SpruceLabelWidget(Position.of(0, 16), - Text.literal("Hello World!").formatted(Formatting.WHITE), + Text.literal("Hello World!").withStyle(TextFormatting.WHITE), containerWidth, true)); widgetAdder.accept(new SpruceLabelWidget(Position.of(0, 48), Text.literal("This is a tabbed widget. You can switch tabs by using the list on the left.\n" + "It also allows quite a good controller support and arrow key navigation.") - .formatted(Formatting.WHITE), + .withStyle(TextFormatting.WHITE), containerWidth, true)); }); return container; }); this.tabbedWidget.addSeparatorEntry(Text.literal("Separator")); - this.tabbedWidget.addTabEntry(Text.literal("Option Test"), Text.literal("useful for config stuff.").formatted(Formatting.GRAY), + this.tabbedWidget.addTabEntry(Text.literal("Option Test"), Text.literal("useful for config stuff.").withStyle(TextFormatting.GRAY), (width, height) -> SpruceUITest.get().buildOptionList(Position.origin(), width, height)); - this.tabbedWidget.addTabEntry(Text.literal("Text Area"), Text.literal("to edit stuff on multiple lines.").formatted(Formatting.GRAY), + this.tabbedWidget.addTabEntry(Text.literal("Text Area"), Text.literal("to edit stuff on multiple lines.").withStyle(TextFormatting.GRAY), (width, height) -> SpruceUITest.buildTextAreaContainer(Position.origin(), width, height, textArea -> { }, null)); - this.addDrawableSelectableElement(this.tabbedWidget); + this.addRenderableWidget(this.tabbedWidget); // Add done button. - this.addDrawableSelectableElement(new SpruceButtonWidget(Position.of(this, this.width / 2 - 75, this.height - 29), 150, 20, SpruceTexts.GUI_DONE, + this.addRenderableWidget(new SpruceButtonWidget(Position.of(this, this.width / 2 - 75, this.height - 29), 150, 20, SpruceTexts.GUI_DONE, btn -> this.client.setScreen(this.parent)).asVanilla()); } } diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTextAreaScreen.java b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTextAreaScreen.java index 8c562f0c..c78dcf2b 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTextAreaScreen.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/gui/SpruceTextAreaScreen.java @@ -14,8 +14,8 @@ import dev.lambdaurora.spruceui.test.SpruceUITest; import dev.lambdaurora.spruceui.widget.text.SpruceTextAreaWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Text; import org.jetbrains.annotations.Nullable; /** @@ -44,11 +44,11 @@ protected void init() { } this.textArea = textArea; }, btn -> this.client.setScreen(this.parent)); - this.addDrawableSelectableElement(containerWidget); + this.addRenderableWidget(containerWidget); } @Override public void renderTitle(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - guiGraphics.drawCenteredShadowedText(this.textRenderer, this.title, this.width / 2, 8, 16777215); + guiGraphics.drawCenteredShadowedText(this.font, this.title, this.width / 2, 8, 16777215); } } diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/mixin/TitleScreenMixin.java b/src/testmod/java/dev/lambdaurora/spruceui/test/mixin/TitleScreenMixin.java index 543bee90..965ac1c1 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/mixin/TitleScreenMixin.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/mixin/TitleScreenMixin.java @@ -12,9 +12,9 @@ import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.test.gui.SpruceMainMenuScreen; import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.text.Text; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.network.chat.Text; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -28,7 +28,7 @@ protected TitleScreenMixin(Text title) { @Inject(method = "init", at = @At("RETURN")) private void onInit(CallbackInfo ci) { - this.addDrawableSelectableElement(new SpruceButtonWidget(Position.of(0, 0), 150, 20, Text.literal("SpruceUI Test Menu"), + this.addRenderableWidget(new SpruceButtonWidget(Position.of(0, 0), 150, 20, Text.literal("SpruceUI Test Menu"), btn -> this.client.setScreen(new SpruceMainMenuScreen(this))).asVanilla()); } }