diff options
author | isXander <xandersmith2008@gmail.com> | 2023-01-19 21:15:26 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-01-19 21:15:26 +0000 |
commit | ee53b51a1e8d88085c75f227f4710b68c03b19c8 (patch) | |
tree | 77a942242a982757da040a6120950bad30e49f77 | |
parent | ffdd6e5ceacd71c76c55a8716702d4d6da17c7ab (diff) | |
download | YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.gz YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.bz2 YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.zip |
mojmap
66 files changed, 921 insertions, 1223 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 3a52db9..4769d21 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -60,15 +60,19 @@ loom { repositories { mavenCentral() maven("https://maven.terraformersmc.com") + maven("https://maven.quiltmc.org/repository/release") } val minecraftVersion: String by project val fabricLoaderVersion: String by project -val yarnBuild: String by project +val qmBuild: String by project dependencies { minecraft("com.mojang:minecraft:$minecraftVersion") - mappings("net.fabricmc:yarn:$minecraftVersion+build.$yarnBuild:v2") + mappings(loom.layered { + mappings("org.quiltmc:quilt-mappings:$minecraftVersion+build.$qmBuild:intermediary-v2") + officialMojangMappings() + }) modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion") "modClientImplementation"(fabricApi.module("fabric-resource-loader-v0", "0.69.1+1.19.3")) diff --git a/gradle.properties b/gradle.properties index 292f0c1..9b9df7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx3G minecraftVersion=1.19.3 fabricLoaderVersion=0.14.11 -yarnBuild=1 +qmBuild=17 modId=yet-another-config-lib modName=YetAnotherConfigLib diff --git a/src/client/java/dev/isxander/yacl/api/Binding.java b/src/client/java/dev/isxander/yacl/api/Binding.java index 91158d3..ba5a2c0 100644 --- a/src/client/java/dev/isxander/yacl/api/Binding.java +++ b/src/client/java/dev/isxander/yacl/api/Binding.java @@ -1,8 +1,8 @@ package dev.isxander.yacl.api; import dev.isxander.yacl.impl.GenericBindingImpl; -import dev.isxander.yacl.mixin.client.SimpleOptionAccessor; -import net.minecraft.client.option.SimpleOption; +import dev.isxander.yacl.mixin.client.OptionInstanceAccessor; +import net.minecraft.client.OptionInstance; import org.apache.commons.lang3.Validate; import java.util.function.Consumer; @@ -35,15 +35,15 @@ public interface Binding<T> { } /** - * Creates a {@link Binding} for Minecraft's {@link SimpleOption} + * Creates a {@link Binding} for Minecraft's {@link OptionInstance} */ - static <T> Binding<T> minecraft(SimpleOption<T> minecraftOption) { + static <T> Binding<T> minecraft(OptionInstance<T> minecraftOption) { Validate.notNull(minecraftOption, "`minecraftOption` must not be null"); return new GenericBindingImpl<>( - ((SimpleOptionAccessor<T>) (Object) minecraftOption).getDefaultValue(), - minecraftOption::getValue, - minecraftOption::setValue + ((OptionInstanceAccessor<T>) (Object) minecraftOption).getInitialValue(), + minecraftOption::get, + minecraftOption::set ); } diff --git a/src/client/java/dev/isxander/yacl/api/ButtonOption.java b/src/client/java/dev/isxander/yacl/api/ButtonOption.java index 2025840..88e1c4b 100644 --- a/src/client/java/dev/isxander/yacl/api/ButtonOption.java +++ b/src/client/java/dev/isxander/yacl/api/ButtonOption.java @@ -2,13 +2,9 @@ package dev.isxander.yacl.api; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.impl.ButtonOptionImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; @@ -19,7 +15,7 @@ public interface ButtonOption extends Option<BiConsumer<YACLScreen, ButtonOption */ BiConsumer<YACLScreen, ButtonOption> action(); - static Builder createBuilder() { + static dev.isxander.yacl.api.ButtonOption.Builder createBuilder() { return new ButtonOptionImpl.BuilderImpl(); } @@ -29,7 +25,7 @@ public interface ButtonOption extends Option<BiConsumer<YACLScreen, ButtonOption * * @see Option#name() */ - Builder name(@NotNull Text name); + dev.isxander.yacl.api.ButtonOption.Builder name(@NotNull Component name); /** * Sets the tooltip to be used by the option. @@ -38,9 +34,9 @@ public interface ButtonOption extends Option<BiConsumer<YACLScreen, ButtonOption * * @param tooltips text lines - merged with a new-line on {@link Option.Builder#build()}. */ - Builder tooltip(@NotNull Text... tooltips); + dev.isxander.yacl.api.ButtonOption.Builder tooltip(@NotNull Component... tooltips); - Builder action(@NotNull BiConsumer<YACLScreen, ButtonOption> action); + dev.isxander.yacl.api.ButtonOption.Builder action(@NotNull BiConsumer<YACLScreen, ButtonOption> action); /** * Action to be executed upon button press @@ -48,14 +44,14 @@ public interface ButtonOption extends Option<BiConsumer<YACLScreen, ButtonOption * @see ButtonOption#action() */ @Deprecated - Builder action(@NotNull Consumer<YACLScreen> action); + dev.isxander.yacl.api.ButtonOption.Builder action(@NotNull Consumer<YACLScreen> action); /** * Sets if the option can be configured * * @see Option#available() */ - Builder available(boolean available); + dev.isxander.yacl.api.ButtonOption.Builder available(boolean available); /** * Sets the controller for the option. @@ -63,7 +59,7 @@ public interface ButtonOption extends Option<BiConsumer<YACLScreen, ButtonOption * * @see dev.isxander.yacl.gui.controllers */ - Builder controller(@NotNull Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> control); + dev.isxander.yacl.api.ButtonOption.Builder controller(@NotNull Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> control); ButtonOption build(); } diff --git a/src/client/java/dev/isxander/yacl/api/ConfigCategory.java b/src/client/java/dev/isxander/yacl/api/ConfigCategory.java index eecb9cb..0e8d1e5 100644 --- a/src/client/java/dev/isxander/yacl/api/ConfigCategory.java +++ b/src/client/java/dev/isxander/yacl/api/ConfigCategory.java @@ -2,16 +2,10 @@ package dev.isxander.yacl.api; import com.google.common.collect.ImmutableList; import dev.isxander.yacl.impl.ConfigCategoryImpl; -import dev.isxander.yacl.impl.OptionGroupImpl; -import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; /** * Separates {@link Option}s or {@link OptionGroup}s into multiple distinct sections. @@ -22,7 +16,7 @@ public interface ConfigCategory { /** * Name of category, displayed as a button on the left column. */ - @NotNull Text name(); + @NotNull Component name(); /** * Gets every {@link OptionGroup} in this category. @@ -33,7 +27,7 @@ public interface ConfigCategory { * Tooltip (or description) of the category. * Rendered on hover. */ - @NotNull Text tooltip(); + @NotNull Component tooltip(); /** * Creates a builder to construct a {@link ConfigCategory} @@ -48,7 +42,7 @@ public interface ConfigCategory { * * @see ConfigCategory#name() */ - Builder name(@NotNull Text name); + Builder name(@NotNull Component name); /** * Adds an option to the root group of the category. @@ -91,7 +85,7 @@ public interface ConfigCategory { * * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. */ - Builder tooltip(@NotNull Text... tooltips); + Builder tooltip(@NotNull Component... tooltips); ConfigCategory build(); } diff --git a/src/client/java/dev/isxander/yacl/api/Controller.java b/src/client/java/dev/isxander/yacl/api/Controller.java index 7bf7e7f..0b8e2ed 100644 --- a/src/client/java/dev/isxander/yacl/api/Controller.java +++ b/src/client/java/dev/isxander/yacl/api/Controller.java @@ -3,7 +3,7 @@ package dev.isxander.yacl.api; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; /** * Provides a widget to control the option. @@ -17,7 +17,7 @@ public interface Controller<T> { /** * Gets the formatted value based on {@link Option#pendingValue()} */ - Text formatValue(); + Component formatValue(); /** * Provides a widget to display diff --git a/src/client/java/dev/isxander/yacl/api/LabelOption.java b/src/client/java/dev/isxander/yacl/api/LabelOption.java index 0e8202b..05c7214 100644 --- a/src/client/java/dev/isxander/yacl/api/LabelOption.java +++ b/src/client/java/dev/isxander/yacl/api/LabelOption.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.api; import dev.isxander.yacl.impl.LabelOptionImpl; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -9,19 +9,19 @@ import java.util.Collection; /** * A label option is an easier way of creating a label with a {@link dev.isxander.yacl.gui.controllers.LabelController}. * This option is immutable and cannot be disabled. Tooltips are supported through - * {@link Text} styling. + * {@link Component} styling. */ -public interface LabelOption extends Option<Text> { - @NotNull Text label(); +public interface LabelOption extends Option<Component> { + @NotNull Component label(); /** * Creates a new label option with the given label, skipping a builder for ease. */ - static LabelOption create(@NotNull Text label) { + static LabelOption create(@NotNull Component label) { return new LabelOptionImpl(label); } - static Builder createBuilder() { + static dev.isxander.yacl.api.LabelOption.Builder createBuilder() { return new LabelOptionImpl.BuilderImpl(); } @@ -29,12 +29,12 @@ public interface LabelOption extends Option<Text> { /** * Appends a line to the label */ - Builder line(@NotNull Text line); + dev.isxander.yacl.api.LabelOption.Builder line(@NotNull Component line); /** * Appends multiple lines to the label */ - Builder lines(@NotNull Collection<? extends Text> lines); + dev.isxander.yacl.api.LabelOption.Builder lines(@NotNull Collection<? extends Component> lines); LabelOption build(); } diff --git a/src/client/java/dev/isxander/yacl/api/ListOption.java b/src/client/java/dev/isxander/yacl/api/ListOption.java index 54ed3a5..adbdc29 100644 --- a/src/client/java/dev/isxander/yacl/api/ListOption.java +++ b/src/client/java/dev/isxander/yacl/api/ListOption.java @@ -1,11 +1,8 @@ package dev.isxander.yacl.api; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.impl.ListOptionImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -61,7 +58,7 @@ public interface ListOption<T> extends OptionGroup, Option<List<T>> { * * @see ListOption#name() */ - Builder<T> name(@NotNull Text name); + Builder<T> name(@NotNull Component name); /** * Sets the tooltip to be used by the list. It is displayed like a normal @@ -70,9 +67,9 @@ public interface ListOption<T> extends OptionGroup, Option<List<T>> { * Can be invoked twice to append more lines. * No need to wrap the text yourself, the gui does this itself. * - * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. + * @param tooltips text lines - merged with a new-line on {@link dev.isxander.yacl.api.ListOption.Builder#build()}. */ - Builder<T> tooltip(@NotNull Text... tooltips); + Builder<T> tooltip(@NotNull Component... tooltips); /** * Sets the value that is used when creating new entries diff --git a/src/client/java/dev/isxander/yacl/api/NameableEnum.java b/src/client/java/dev/isxander/yacl/api/NameableEnum.java index 793b230..4b04057 100644 --- a/src/client/java/dev/isxander/yacl/api/NameableEnum.java +++ b/src/client/java/dev/isxander/yacl/api/NameableEnum.java @@ -1,10 +1,10 @@ package dev.isxander.yacl.api; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; /** * Used for the default value formatter of {@link dev.isxander.yacl.gui.controllers.cycling.EnumController} */ public interface NameableEnum { - Text getDisplayName(); + Component getDisplayName(); } diff --git a/src/client/java/dev/isxander/yacl/api/Option.java b/src/client/java/dev/isxander/yacl/api/Option.java index 9b4ff7b..faa6f1c 100644 --- a/src/client/java/dev/isxander/yacl/api/Option.java +++ b/src/client/java/dev/isxander/yacl/api/Option.java @@ -2,10 +2,7 @@ package dev.isxander.yacl.api; import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.impl.OptionImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import org.apache.commons.lang3.Validate; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -13,19 +10,18 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import java.util.stream.Stream; public interface Option<T> { /** * Name of the option */ - @NotNull Text name(); + @NotNull Component name(); /** * Tooltip (or description) of the option. * Rendered on hover. */ - @NotNull Text tooltip(); + @NotNull Component tooltip(); /** * Widget provider for a type of option. @@ -128,7 +124,7 @@ public interface Option<T> { * * @see Option#name() */ - Builder<T> name(@NotNull Text name); + Builder<T> name(@NotNull Component name); /** * Sets the tooltip to be used by the option. @@ -137,7 +133,7 @@ public interface Option<T> { * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. */ @SuppressWarnings("unchecked") - Builder<T> tooltip(@NotNull Function<T, Text>... tooltipGetter); + Builder<T> tooltip(@NotNull Function<T, Component>... tooltipGetter); /** * Sets the tooltip to be used by the option. @@ -146,7 +142,7 @@ public interface Option<T> { * * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. */ - Builder<T> tooltip(@NotNull Text... tooltips); + Builder<T> tooltip(@NotNull Component... tooltips); /** * Sets the controller for the option. diff --git a/src/client/java/dev/isxander/yacl/api/OptionFlag.java b/src/client/java/dev/isxander/yacl/api/OptionFlag.java index 7a5c23f..51d57e4 100644 --- a/src/client/java/dev/isxander/yacl/api/OptionFlag.java +++ b/src/client/java/dev/isxander/yacl/api/OptionFlag.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.api; import dev.isxander.yacl.gui.RequireRestartScreen; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import java.util.function.Consumer; @@ -10,14 +10,14 @@ import java.util.function.Consumer; * Each flag is executed only once per save, no matter the amount of options with the flag. */ @FunctionalInterface -public interface OptionFlag extends Consumer<MinecraftClient> { +public interface OptionFlag extends Consumer<Minecraft> { /** Warns the user that a game restart is required for the changes to take effect */ - OptionFlag GAME_RESTART = client -> client.setScreen(new RequireRestartScreen(client.currentScreen)); + OptionFlag GAME_RESTART = client -> client.setScreen(new RequireRestartScreen(client.screen)); /** Reloads chunks upon applying (F3+A) */ - OptionFlag RELOAD_CHUNKS = client -> client.worldRenderer.reload(); + OptionFlag RELOAD_CHUNKS = client -> client.levelRenderer.allChanged(); - OptionFlag WORLD_RENDER_UPDATE = client -> client.worldRenderer.scheduleTerrainUpdate(); + OptionFlag WORLD_RENDER_UPDATE = client -> client.levelRenderer.needsUpdate(); - OptionFlag ASSET_RELOAD = MinecraftClient::reloadResourcesConcurrently; + OptionFlag ASSET_RELOAD = Minecraft::delayTextureReload; } diff --git a/src/client/java/dev/isxander/yacl/api/OptionGroup.java b/src/client/java/dev/isxander/yacl/api/OptionGroup.java index 8dd9c14..9f78071 100644 --- a/src/client/java/dev/isxander/yacl/api/OptionGroup.java +++ b/src/client/java/dev/isxander/yacl/api/OptionGroup.java @@ -2,14 +2,10 @@ package dev.isxander.yacl.api; import com.google.common.collect.ImmutableList; import dev.isxander.yacl.impl.OptionGroupImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; /** * Serves as a separator between multiple chunks of options @@ -21,12 +17,12 @@ public interface OptionGroup { * Name of the option group, displayed as a separator in the option lists. * Can be empty. */ - Text name(); + Component name(); /** * Tooltip displayed on hover. */ - Text tooltip(); + Component tooltip(); /** * List of all options in the group @@ -53,20 +49,20 @@ public interface OptionGroup { interface Builder { /** - * Sets name of the group, can be {@link Text#empty()} to just separate options, like sodium. + * Sets name of the group, can be {@link Component#empty()} to just separate options, like sodium. * * @see OptionGroup#name() */ - Builder name(@NotNull Text name); + Builder name(@NotNull Component name); /** * Sets the tooltip to be used by the option group. * Can be invoked twice to append more lines. - * No need to wrap the text yourself, the gui does this itself. + * No need to wrap the Component yourself, the gui does this itself. * - * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. + * @param tooltips Component lines - merged with a new-line on {@link Builder#build()}. */ - Builder tooltip(@NotNull Text... tooltips); + Builder tooltip(@NotNull Component... tooltips); /** * Adds an option to group. diff --git a/src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java b/src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java index 7bcc821..3641fad 100644 --- a/src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java +++ b/src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java @@ -2,15 +2,11 @@ package dev.isxander.yacl.api; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.impl.PlaceholderCategoryImpl; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; import java.util.function.BiFunction; /** @@ -21,7 +17,7 @@ public interface PlaceholderCategory extends ConfigCategory { /** * Function to create a screen to open upon changing to this category */ - BiFunction<MinecraftClient, YACLScreen, Screen> screen(); + BiFunction<Minecraft, YACLScreen, Screen> screen(); static Builder createBuilder() { return new PlaceholderCategoryImpl.BuilderImpl(); @@ -33,23 +29,23 @@ public interface PlaceholderCategory extends ConfigCategory { * * @see ConfigCategory#name() */ - Builder name(@NotNull Text name); + Builder name(@NotNull Component name); /** * Sets the tooltip to be used by the category. * Can be invoked twice to append more lines. - * No need to wrap the text yourself, the gui does this itself. + * No need to wrap the Component yourself, the gui does this itself. * - * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. + * @param tooltips Component lines - merged with a new-line on {@link dev.isxander.yacl.api.PlaceholderCategory.Builder#build()}. */ - Builder tooltip(@NotNull Text... tooltips); + Builder tooltip(@NotNull Component... tooltips); /** * Screen to open upon selecting this category * * @see PlaceholderCategory#screen() */ - Builder screen(@NotNull BiFunction<MinecraftClient, YACLScreen, Screen> screenFunction); + Builder screen(@NotNull BiFunction<Minecraft, YACLScreen, Screen> screenFunction); PlaceholderCategory build(); } diff --git a/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java b/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java index f9a71d3..c6da1d1 100644 --- a/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java +++ b/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java @@ -4,16 +4,12 @@ import com.google.common.collect.ImmutableList; import dev.isxander.yacl.config.ConfigInstance; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.impl.YetAnotherConfigLibImpl; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; -import java.util.function.BiFunction; import java.util.function.Consumer; /** @@ -24,7 +20,7 @@ public interface YetAnotherConfigLib { /** * Title of the GUI. Only used for Minecraft narration. */ - Text title(); + Component title(); /** * Gets all config categories. @@ -69,7 +65,7 @@ public interface YetAnotherConfigLib { * * @see YetAnotherConfigLib#title() */ - Builder title(@NotNull Text title); + Builder title(@NotNull Component title); /** * Adds a new category. diff --git a/src/client/java/dev/isxander/yacl/gui/AbstractWidget.java b/src/client/java/dev/isxander/yacl/gui/AbstractWidget.java index 529748d..c6d2b09 100644 --- a/src/client/java/dev/isxander/yacl/gui/AbstractWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/AbstractWidget.java @@ -1,25 +1,24 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.utils.Dimension; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.widget.ClickableWidget; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.sound.SoundEvents; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.sounds.SoundEvents; import java.awt.Color; -public abstract class AbstractWidget implements Element, Drawable, Selectable { - protected final MinecraftClient client = MinecraftClient.getInstance(); - protected final TextRenderer textRenderer = client.textRenderer; +public abstract class AbstractWidget implements GuiEventListener, Renderable, NarratableEntry { + protected final Minecraft client = Minecraft.getInstance(); + protected final Font textRenderer = client.font; protected final int inactiveColor = 0xFFA0A0A0; private Dimension<Integer> dim; @@ -28,7 +27,7 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { this.dim = dim; } - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { } @@ -51,8 +50,8 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { } @Override - public SelectionType getType() { - return SelectionType.NONE; + public NarrationPriority narrationPriority() { + return NarrationPriority.NONE; } public void unfocus() { @@ -64,11 +63,11 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { } @Override - public void appendNarrations(NarrationMessageBuilder builder) { + public void updateNarration(NarrationElementOutput builder) { } - protected void drawButtonRect(MatrixStack matrices, int x1, int y1, int x2, int y2, boolean hovered, boolean enabled) { + protected void drawButtonRect(PoseStack matrices, int x1, int y1, int x2, int y2, boolean hovered, boolean enabled) { if (x1 > x2) { int xx1 = x1; x1 = x2; @@ -82,15 +81,15 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { int width = x2 - x1; int height = y2 - y1; - RenderSystem.setShader(GameRenderer::getPositionTexProgram); - RenderSystem.setShaderTexture(0, ClickableWidget.WIDGETS_TEXTURE); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShaderTexture(0, net.minecraft.client.gui.components.AbstractWidget.WIDGETS_LOCATION); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); int i = !enabled ? 0 : hovered ? 2 : 1; RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); - DrawableHelper.drawTexture(matrices, x1, y1, 0, 0, 46 + i * 20, width / 2, height, 256, 256); - DrawableHelper.drawTexture(matrices, x1 + width / 2, y1, 0, 200 - width / 2f, 46 + i * 20, width / 2, height, 256, 256); + GuiComponent.blit(matrices, x1, y1, 0, 0, 46 + i * 20, width / 2, height, 256, 256); + GuiComponent.blit(matrices, x1 + width / 2, y1, 0, 200 - width / 2f, 46 + i * 20, width / 2, height, 256, 256); } protected int multiplyColor(int hex, float amount) { @@ -103,6 +102,6 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { } public void playDownSound() { - MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } } diff --git a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java b/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java index 71a8e4e..41286ff 100644 --- a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java @@ -2,23 +2,23 @@ package dev.isxander.yacl.gui; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.ConfigCategory; import dev.isxander.yacl.gui.utils.GuiUtils; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; import java.util.List; public class CategoryListWidget extends ElementListWidgetExt<CategoryListWidget.CategoryEntry> { private final YACLScreen yaclScreen; - public CategoryListWidget(MinecraftClient client, YACLScreen yaclScreen, int screenWidth, int screenHeight) { + public CategoryListWidget(Minecraft client, YACLScreen yaclScreen, int screenWidth, int screenHeight) { super(client, 0, 0, screenWidth / 3, yaclScreen.searchFieldWidget.getY() - 5, true); this.yaclScreen = yaclScreen; setRenderBackground(false); - setRenderHorizontalShadows(false); + setRenderTopAndBottom(false); for (ConfigCategory category : yaclScreen.config.categories()) { addEntry(new CategoryEntry(category)); @@ -26,7 +26,7 @@ public class CategoryListWidget extends ElementListWidgetExt<CategoryListWidget. } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { GuiUtils.enableScissor(0, 0, width, height); super.render(matrices, mouseX, mouseY, delta); RenderSystem.disableScissor(); @@ -43,12 +43,12 @@ public class CategoryListWidget extends ElementListWidgetExt<CategoryListWidget. } @Override - protected int getScrollbarPositionX() { + protected int getScrollbarPosition() { return width - 2; } @Override - protected void renderBackground(MatrixStack matrices) { + protected void renderBackground(PoseStack matrices) { } @@ -68,8 +68,8 @@ public class CategoryListWidget extends ElementListWidgetExt<CategoryListWidget. } @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - if (mouseY > bottom) { + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + if (mouseY > y1) { mouseY = -20; } @@ -77,7 +77,7 @@ public class CategoryListWidget extends ElementListWidgetExt<CategoryListWidget. categoryButton.render(matrices, mouseX, mouseY, tickDelta); } - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float tickDelta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float tickDelta) { categoryButton.renderHoveredTooltip(matrices); } @@ -87,12 +87,12 @@ public class CategoryListWidget extends ElementListWidgetExt<CategoryListWidget. } @Override - public List<? extends Element> children() { + public List<? extends GuiEventListener> children() { return ImmutableList.of(categoryButton); } @Override - public List<? extends Selectable> selectableChildren() { + public List<? extends NarratableEntry> narratables() { return ImmutableList.of(categoryButton); } } diff --git a/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java b/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java index 3c5d8d2..f47a09b 100644 --- a/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java @@ -1,14 +1,14 @@ package dev.isxander.yacl.gui; import dev.isxander.yacl.api.ConfigCategory; -import net.minecraft.client.sound.SoundManager; +import net.minecraft.client.sounds.SoundManager; public class CategoryWidget extends TooltipButtonWidget { private final int categoryIndex; public CategoryWidget(YACLScreen screen, ConfigCategory category, int categoryIndex, int x, int y, int width, int height) { super(screen, x, y, width, height, category.name(), category.tooltip(), btn -> { - screen.searchFieldWidget.setText(""); + screen.searchFieldWidget.setValue(""); screen.changeCategory(categoryIndex); }); this.categoryIndex = categoryIndex; diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java index 708c6bf..e28509e 100644 --- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java +++ b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java @@ -1,24 +1,23 @@ package dev.isxander.yacl.gui; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.widget.ElementListWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.MathHelper; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.ContainerObjectSelectionList; +import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; -public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ElementListWidget<E> { +public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList<E> { protected final int x, y; private double smoothScrollAmount = getScrollAmount(); private boolean returnSmoothAmount = false; private final boolean doSmoothScrolling; - public ElementListWidgetExt(MinecraftClient client, int x, int y, int width, int height, boolean smoothScrolling) { + public ElementListWidgetExt(Minecraft client, int x, int y, int width, int height, boolean smoothScrolling) { super(client, width, height, y, y + height, 22); - this.x = x; + this.x = this.x0 = x; this.y = y; - this.left = x; - this.right = this.left + width; + this.x1 = this.x0 + width; this.doSmoothScrolling = smoothScrolling; } @@ -30,22 +29,22 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten } @Override - protected void renderBackground(MatrixStack matrices) { + protected void renderBackground(PoseStack matrices) { // render transparent background if in-game. - setRenderBackground(client.world == null); - if (client.world != null) - fill(matrices, left, top, right, bottom, 0x6B000000); + setRenderBackground(minecraft.level == null); + if (minecraft.level != null) + fill(matrices, x0, y0, x1, y1, 0x6B000000); } @Override - protected int getScrollbarPositionX() { + protected int getScrollbarPosition() { // default implementation does not respect left/right - return this.right - 2; + return this.x1 - 2; } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - smoothScrollAmount = MathHelper.lerp(MinecraftClient.getInstance().getLastFrameDuration() * 0.5, smoothScrollAmount, getScrollAmount()); + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { + smoothScrollAmount = Mth.lerp(Minecraft.getInstance().getDeltaFrameTime() * 0.5, smoothScrollAmount, getScrollAmount()); returnSmoothAmount = true; super.render(matrices, mouseX, mouseY, delta); returnSmoothAmount = false; @@ -67,7 +66,7 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten this.smoothScrollAmount = getScrollAmount(); } - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { for (E entry : children()) { entry.postRender(matrices, mouseX, mouseY, delta); } @@ -78,10 +77,10 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten protected E getEntryAtPosition(double x, double y) { y += getScrollAmount(); - if (x < this.left || x > this.right) + if (x < this.x0 || x > this.x1) return null; - int currentY = this.top - headerHeight + 4; + int currentY = this.y0 - headerHeight + 4; for (E entry : children()) { if (y >= currentY && y <= currentY + entry.getItemHeight()) { return entry; @@ -107,41 +106,41 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten @Override protected void centerScrollOn(E entry) { - double d = (this.bottom - this.top) / -2d; - for (int i = 0; i < this.children().indexOf(entry) && i < this.getEntryCount(); i++) + double d = (this.height) / -2d; + for (int i = 0; i < this.children().indexOf(entry) && i < this.getItemCount(); i++) d += children().get(i).getItemHeight(); this.setScrollAmount(d); } @Override protected int getRowTop(int index) { - int integer = top + 4 - (int) this.getScrollAmount() + headerHeight; + int integer = y0 + 4 - (int) this.getScrollAmount() + headerHeight; for (int i = 0; i < children().size() && i < index; i++) integer += children().get(i).getItemHeight(); return integer; } @Override - protected void renderList(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void renderList(PoseStack matrices, int mouseX, int mouseY, float delta) { int left = this.getRowLeft(); int right = this.getRowWidth(); - int count = this.getEntryCount(); + int count = this.getItemCount(); for(int i = 0; i < count; ++i) { E entry = children().get(i); int top = this.getRowTop(i); int bottom = top + entry.getItemHeight(); int entryHeight = entry.getItemHeight() - 4; - if (bottom >= this.top && top <= this.bottom) { - this.renderEntry(matrices, mouseX, mouseY, delta, i, left, top, right, entryHeight); + if (bottom >= this.y0 && top <= this.y1) { + this.renderItem(matrices, mouseX, mouseY, delta, i, left, top, right, entryHeight); } } } /* END cloth config code */ - public abstract static class Entry<E extends ElementListWidgetExt.Entry<E>> extends ElementListWidget.Entry<E> { - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public abstract static class Entry<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList.Entry<E> { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { } diff --git a/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java b/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java index 36e0852..3b66b6a 100644 --- a/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java @@ -1,27 +1,27 @@ package dev.isxander.yacl.gui; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; -import net.minecraft.util.math.MathHelper; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; -public class LowProfileButtonWidget extends ButtonWidget { - public LowProfileButtonWidget(int x, int y, int width, int height, Text message, PressAction onPress) { - super(x, y, width, height, message, onPress, DEFAULT_NARRATION_SUPPLIER); +public class LowProfileButtonWidget extends Button { + public LowProfileButtonWidget(int x, int y, int width, int height, Component message, OnPress onPress) { + super(x, y, width, height, message, onPress, DEFAULT_NARRATION); } - public LowProfileButtonWidget(int x, int y, int width, int height, Text message, PressAction onPress, Tooltip tooltip) { + public LowProfileButtonWidget(int x, int y, int width, int height, Component message, OnPress onPress, Tooltip tooltip) { this(x, y, width, height, message, onPress); setTooltip(tooltip); } @Override - public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { - if (!isHovered() || !active) { + public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) { + if (!isHoveredOrFocused() || !active) { int j = this.active ? 0xFFFFFF : 0xA0A0A0; - drawCenteredText(matrices, MinecraftClient.getInstance().textRenderer, this.getMessage(), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24); + drawCenteredString(matrices, Minecraft.getInstance().font, this.getMessage(), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, j | Mth.ceil(this.alpha * 255.0F) << 24); } else { super.renderButton(matrices, mouseX, mouseY, delta); } diff --git a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java index efeab14..097f076 100644 --- a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -1,20 +1,20 @@ package dev.isxander.yacl.gui; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.*; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.Selectable; -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.util.math.MatrixStack; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -23,9 +23,9 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr private final YACLScreen yaclScreen; private boolean singleCategory = false; - private ImmutableList<Entry> viewableChildren; + private ImmutableList<dev.isxander.yacl.gui.OptionListWidget.Entry> viewableChildren; - public OptionListWidget(YACLScreen screen, MinecraftClient client, int width, int height) { + public OptionListWidget(YACLScreen screen, Minecraft client, int width, int height) { super(client, width / 3, 0, width / 3 * 2 + 1, height, true); this.yaclScreen = screen; @@ -64,7 +64,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr groupSeparatorEntry = null; } - List<Entry> optionEntries = new ArrayList<>(); + List<dev.isxander.yacl.gui.OptionListWidget.Entry> optionEntries = new ArrayList<>(); // add empty entry to make sure users know it's empty not just bugging out if (groupSeparatorEntry instanceof ListGroupSeparatorEntry listGroupSeparatorEntry) { @@ -101,7 +101,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr return; } - for (Entry entry : groupSeparator.childEntries) + for (dev.isxander.yacl.gui.OptionListWidget.Entry entry : groupSeparator.childEntries) super.removeEntry(entry); groupSeparator.childEntries.clear(); @@ -113,7 +113,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr return; } - Entry lastEntry = groupSeparator; + dev.isxander.yacl.gui.OptionListWidget.Entry lastEntry = groupSeparator; for (ListOptionEntry<?> listOptionEntry : listOption.options()) { OptionEntry optionEntry = new OptionEntry(listOptionEntry, category, listOption, groupSeparator, listOptionEntry.controller().provideWidget(yaclScreen, getDefaultEntryDimension())); addEntryBelow(lastEntry, optionEntry); @@ -127,7 +127,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } public void expandAllGroups() { - for (Entry entry : super.children()) { + for (dev.isxander.yacl.gui.OptionListWidget.Entry entry : super.children()) { if (entry instanceof GroupSeparatorEntry groupSeparatorEntry) { groupSeparatorEntry.setExpanded(true); } @@ -141,7 +141,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - for (Entry child : children()) { + for (dev.isxander.yacl.gui.OptionListWidget.Entry child : children()) { if (child != getEntryAtPosition(mouseX, mouseY) && child instanceof OptionEntry optionEntry) optionEntry.widget.unfocus(); } @@ -153,7 +153,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr public boolean mouseScrolled(double mouseX, double mouseY, double amount) { super.mouseScrolled(mouseX, mouseY, amount); - for (Entry child : children()) { + for (dev.isxander.yacl.gui.OptionListWidget.Entry child : children()) { if (child.mouseScrolled(mouseX, mouseY, amount)) break; } @@ -163,7 +163,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - for (Entry child : children()) { + for (dev.isxander.yacl.gui.OptionListWidget.Entry child : children()) { if (child.keyPressed(keyCode, scanCode, modifiers)) return true; } @@ -173,7 +173,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr @Override public boolean charTyped(char chr, int modifiers) { - for (Entry child : children()) { + for (dev.isxander.yacl.gui.OptionListWidget.Entry child : children()) { if (child.charTyped(chr, modifiers)) return true; } @@ -182,16 +182,16 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - protected int getScrollbarPositionX() { - return right - (int)(width * 0.05f); + protected int getScrollbarPosition() { + return x1 - (int)(width * 0.05f); } public void recacheViewableChildren() { - this.viewableChildren = ImmutableList.copyOf(super.children().stream().filter(Entry::isViewable).toList()); + this.viewableChildren = ImmutableList.copyOf(super.children().stream().filter(dev.isxander.yacl.gui.OptionListWidget.Entry::isViewable).toList()); // update y positions before they need to be rendered are rendered int i = 0; - for (Entry entry : viewableChildren) { + for (dev.isxander.yacl.gui.OptionListWidget.Entry entry : viewableChildren) { if (entry instanceof OptionEntry optionEntry) optionEntry.widget.setDimension(optionEntry.widget.getDimension().withY(getRowTop(i))); i++; @@ -224,8 +224,8 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public boolean removeEntryWithoutScrolling(Entry entry) { - boolean ret = super.removeEntryWithoutScrolling(entry); + public boolean removeEntryFromTop(Entry entry) { + boolean ret = super.removeEntryFromTop(entry); recacheViewableChildren(); return ret; } @@ -243,7 +243,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } protected boolean isHovered() { - return Objects.equals(getHoveredEntry(), this); + return Objects.equals(getHovered(), this); } } @@ -271,7 +271,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr this.groupName = group.name().getString().toLowerCase(); if (option.canResetToDefault() && this.widget.canReset()) { this.widget.setDimension(this.widget.getDimension().expanded(-20, 0)); - this.resetButton = new TextScaledButtonWidget(widget.getDimension().xLimit(), -50, 20, 20, 2f, Text.of("\u21BB"), button -> { + this.resetButton = new TextScaledButtonWidget(widget.getDimension().xLimit(), -50, 20, 20, 2f, Component.literal("\u21BB"), button -> { option.requestSetDefault(); }); option.addListener((opt, val) -> this.resetButton.active = !opt.isPendingValueDefault() && opt.available()); @@ -282,7 +282,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { widget.setDimension(widget.getDimension().withY(y)); widget.render(matrices, mouseX, mouseY, tickDelta); @@ -294,7 +294,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { widget.postRender(matrices, mouseX, mouseY, delta); } @@ -329,7 +329,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public List<? extends Selectable> selectableChildren() { + public List<? extends NarratableEntry> narratables() { if (resetButton == null) return ImmutableList.of(widget); @@ -337,7 +337,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public List<? extends Element> children() { + public List<? extends GuiEventListener> children() { if (resetButton == null) return ImmutableList.of(widget); @@ -347,13 +347,13 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr public class GroupSeparatorEntry extends Entry { protected final OptionGroup group; - protected final MultilineText wrappedName; - protected final MultilineText wrappedTooltip; + protected final MultiLineLabel wrappedName; + protected final MultiLineLabel wrappedTooltip; protected final LowProfileButtonWidget expandMinimizeButton; protected final Screen screen; - protected final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; + protected final Font font = Minecraft.getInstance().font; protected boolean groupExpanded; @@ -364,15 +364,15 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr private GroupSeparatorEntry(OptionGroup group, Screen screen) { this.group = group; this.screen = screen; - this.wrappedName = MultilineText.create(textRenderer, group.name(), getRowWidth() - 45); - this.wrappedTooltip = MultilineText.create(textRenderer, group.tooltip(), screen.width / 3 * 2 - 10); + this.wrappedName = MultiLineLabel.create(font, group.name(), getRowWidth() - 45); + this.wrappedTooltip = MultiLineLabel.create(font, group.tooltip(), screen.width / 3 * 2 - 10); this.groupExpanded = !group.collapsed(); - this.expandMinimizeButton = new LowProfileButtonWidget(0, 0, 20, 20, Text.empty(), btn -> onExpandButtonPress()); + this.expandMinimizeButton = new LowProfileButtonWidget(0, 0, 20, 20, Component.empty(), btn -> onExpandButtonPress()); updateExpandMinimizeText(); } @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { this.y = y; int buttonY = y + entryHeight / 2 - expandMinimizeButton.getHeight() / 2 + 1; @@ -381,13 +381,13 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr expandMinimizeButton.setX(x); expandMinimizeButton.render(matrices, mouseX, mouseY, tickDelta); - wrappedName.drawCenterWithShadow(matrices, x + entryWidth / 2, y + getYPadding()); + wrappedName.renderCentered(matrices, x + entryWidth / 2, y + getYPadding()); } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { if ((isHovered() && !expandMinimizeButton.isMouseOver(mouseX, mouseY)) || expandMinimizeButton.isFocused()) { - YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, getRowLeft() + getRowWidth() / 2, y - 3, y + getItemHeight() + 3, screen.width, screen.height); + YACLScreen.renderMultilineTooltip(matrices, font, wrappedTooltip, getRowLeft() + getRowWidth() / 2, y - 3, y + getItemHeight() + 3, screen.width, screen.height); } } @@ -409,7 +409,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } protected void updateExpandMinimizeText() { - expandMinimizeButton.setMessage(Text.of(isExpanded() ? "▼" : "▶")); + expandMinimizeButton.setMessage(Component.literal(isExpanded() ? "▼" : "▶")); } public void setChildEntries(List<? extends Entry> childEntries) { @@ -424,7 +424,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr @Override public int getItemHeight() { - return Math.max(wrappedName.count(), 1) * textRenderer.fontHeight + getYPadding() * 2; + return Math.max(wrappedName.getLineCount(), 1) * font.lineHeight + getYPadding() * 2; } private int getYPadding() { @@ -432,23 +432,23 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public List<? extends Selectable> selectableChildren() { - return ImmutableList.of(new Selectable() { + public List<? extends NarratableEntry> narratables() { + return ImmutableList.of(new NarratableEntry() { @Override - public Selectable.SelectionType getType() { - return Selectable.SelectionType.HOVERED; + public NarratableEntry.NarrationPriority narrationPriority() { + return NarrationPriority.HOVERED; } @Override - public void appendNarrations(NarrationMessageBuilder builder) { - builder.put(NarrationPart.TITLE, group.name()); - builder.put(NarrationPart.HINT, group.tooltip()); + public void updateNarration(NarrationElementOutput builder) { + builder.add(NarratedElementType.TITLE, group.name()); + builder.add(NarratedElementType.HINT, group.tooltip()); } }); } @Override - public List<? extends Element> children() { + public List<? extends GuiEventListener> children() { return ImmutableList.of(expandMinimizeButton); } } @@ -462,13 +462,13 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr super(group, screen); this.listOption = group; - this.resetListButton = new TextScaledButtonWidget(getRowRight() - 20, -50, 20, 20, 2f, Text.of("\u21BB"), button -> { + this.resetListButton = new TextScaledButtonWidget(getRowRight() - 20, -50, 20, 20, 2f, Component.literal("\u21BB"), button -> { group.requestSetDefault(); }); group.addListener((opt, val) -> this.resetListButton.active = !opt.isPendingValueDefault() && opt.available()); this.resetListButton.active = !group.isPendingValueDefault() && group.available(); - this.addListButton = new TooltipButtonWidget(yaclScreen, resetListButton.getX() - 20, -50, 20, 20, Text.of("+"), Text.translatable("yacl.list.add_top"), btn -> { + this.addListButton = new TooltipButtonWidget(yaclScreen, resetListButton.getX() - 20, -50, 20, 20, Component.literal("+"), Component.translatable("yacl.list.add_top"), btn -> { group.insertNewEntryToTop(); setExpanded(true); }); @@ -478,7 +478,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { updateExpandMinimizeText(); // update every render because option could become available/unavailable at any time super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta); @@ -493,7 +493,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { minimizeIfUnavailable(); // cannot run in render because it *should* cause a ConcurrentModificationException (but doesn't) super.postRender(matrices, mouseX, mouseY, delta); @@ -516,7 +516,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public List<? extends Element> children() { + public List<? extends GuiEventListener> children() { return ImmutableList.of(expandMinimizeButton, addListButton, resetListButton); } } @@ -533,8 +533,8 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - drawCenteredText(matrices, MinecraftClient.getInstance().textRenderer, Text.translatable("yacl.list.empty").formatted(Formatting.DARK_GRAY, Formatting.ITALIC), x + entryWidth / 2, y, -1); + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + drawCenteredString(matrices, Minecraft.getInstance().font, Component.translatable("yacl.list.empty").withStyle(ChatFormatting.DARK_GRAY, ChatFormatting.ITALIC), x + entryWidth / 2, y, -1); } @Override @@ -551,12 +551,12 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public List<? extends Element> children() { + public List<? extends GuiEventListener> children() { return ImmutableList.of(); } @Override - public List<? extends Selectable> selectableChildren() { + public List<? extends NarratableEntry> narratables() { return ImmutableList.of(); } } diff --git a/src/client/java/dev/isxander/yacl/gui/RequireRestartScreen.java b/src/client/java/dev/isxander/yacl/gui/RequireRestartScreen.java index 3c46738..18b6033 100644 --- a/src/client/java/dev/isxander/yacl/gui/RequireRestartScreen.java +++ b/src/client/java/dev/isxander/yacl/gui/RequireRestartScreen.java @@ -1,16 +1,21 @@ package dev.isxander.yacl.gui; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ConfirmScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.ConfirmScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; public class RequireRestartScreen extends ConfirmScreen { public RequireRestartScreen(Screen parent) { super(option -> { - if (option) MinecraftClient.getInstance().scheduleStop(); - else MinecraftClient.getInstance().setScreen(parent); - }, Text.translatable("yacl.restart.title").formatted(Formatting.RED, Formatting.BOLD), Text.translatable("yacl.restart.message"), Text.translatable("yacl.restart.yes"), Text.translatable("yacl.restart.no")); + if (option) Minecraft.getInstance().stop(); + else Minecraft.getInstance().setScreen(parent); + }, + Component.translatable("yacl.restart.title").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), + Component.translatable("yacl.restart.message"), + Component.translatable("yacl.restart.yes"), + Component.translatable("yacl.restart.no") + ); } } diff --git a/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java b/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java index 3cfe75e..103831d 100644 --- a/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java @@ -1,37 +1,37 @@ package dev.isxander.yacl.gui; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.network.chat.Component; -public class SearchFieldWidget extends TextFieldWidget { - private Text emptyText; +public class SearchFieldWidget extends EditBox { + private Component emptyText; private final YACLScreen yaclScreen; - private final TextRenderer textRenderer; + private final Font font; private boolean isEmpty = true; - public SearchFieldWidget(YACLScreen yaclScreen, TextRenderer textRenderer, int x, int y, int width, int height, Text text, Text emptyText) { - super(textRenderer, x, y, width, height, text); - setChangedListener(string -> update()); - setTextPredicate(string -> !string.endsWith(" ") && !string.startsWith(" ")); + public SearchFieldWidget(YACLScreen yaclScreen, Font font, int x, int y, int width, int height, Component text, Component emptyText) { + super(font, x, y, width, height, text); + setResponder(string -> update()); + setFilter(string -> !string.endsWith(" ") && !string.startsWith(" ")); this.yaclScreen = yaclScreen; - this.textRenderer = textRenderer; + this.font = font; this.emptyText = emptyText; } @Override - public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) { super.renderButton(matrices, mouseX, mouseY, delta); if (isVisible() && isEmpty()) { - textRenderer.drawWithShadow(matrices, emptyText, getX() + 4, this.getY() + (this.height - 8) / 2f, 0x707070); + font.drawShadow(matrices, emptyText, getX() + 4, this.getY() + (this.height - 8) / 2f, 0x707070); } } private void update() { boolean wasEmpty = isEmpty; - isEmpty = getText().isEmpty(); + isEmpty = getValue().isEmpty(); if (isEmpty && wasEmpty) return; @@ -49,18 +49,18 @@ public class SearchFieldWidget extends TextFieldWidget { } public String getQuery() { - return getText().toLowerCase(); + return getValue().toLowerCase(); } public boolean isEmpty() { return isEmpty; } - public Text getEmptyText() { + public Component getEmptyText() { return emptyText; } - public void setEmptyText(Text emptyText) { + public void setEmptyText(Component emptyText) { this.emptyText = emptyText; } } diff --git a/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java b/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java index 2d0a99c..76ba14f 100644 --- a/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java @@ -1,44 +1,44 @@ package dev.isxander.yacl.gui; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; -import net.minecraft.util.math.MathHelper; - -public class TextScaledButtonWidget extends ButtonWidget { +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.util.Mth; + +public class TextScaledButtonWidget extends Button { public float textScale; - public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Text message, PressAction onPress) { - super(x, y, width, height, message, onPress, DEFAULT_NARRATION_SUPPLIER); + public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Component message, OnPress onPress) { + super(x, y, width, height, message, onPress, DEFAULT_NARRATION); this.textScale = textScale; } - public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Text message, PressAction onPress, Tooltip tooltip) { + public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Component message, OnPress onPress, Tooltip tooltip) { this(x, y, width, height, textScale, message, onPress); setTooltip(tooltip); } @Override - public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) { // prevents super from rendering text - Text message = getMessage(); - setMessage(Text.empty()); + Component message = getMessage(); + setMessage(Component.empty()); super.renderButton(matrices, mouseX, mouseY, delta); setMessage(message); int j = this.active ? 16777215 : 10526880; - OrderedText orderedText = getMessage().asOrderedText(); - TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; + FormattedCharSequence orderedText = getMessage().getVisualOrderText(); + Font font = Minecraft.getInstance().font; - matrices.push(); - matrices.translate(((this.getX() + this.width / 2f) - textRenderer.getWidth(orderedText) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale, 0); + matrices.pushPose(); + matrices.translate(((this.getX() + this.width / 2f) - font.width(orderedText) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale, 0); matrices.scale(textScale, textScale, 1); - textRenderer.drawWithShadow(matrices, orderedText, 0, 0, j | MathHelper.ceil(this.alpha * 255.0F) << 24); - matrices.pop(); + font.drawShadow(matrices, orderedText, 0, 0, j | Mth.ceil(this.alpha * 255.0F) << 24); + matrices.popPose(); } } diff --git a/src/client/java/dev/isxander/yacl/gui/TooltipButtonWidget.java b/src/client/java/dev/isxander/yacl/gui/TooltipButtonWidget.java index 359e8d0..1395a3f 100644 --- a/src/client/java/dev/isxander/yacl/gui/TooltipButtonWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/TooltipButtonWidget.java @@ -1,35 +1,34 @@ package dev.isxander.yacl.gui; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; public class TooltipButtonWidget extends TextScaledButtonWidget { protected final Screen screen; - protected MultilineText wrappedDescription; + protected MultiLineLabel wrappedDescription; - public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Text message, float textScale, Text tooltip, PressAction onPress) { + public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Component message, float textScale, Component tooltip, Button.OnPress onPress) { super(x, y, width, height, textScale, message, onPress); this.screen = screen; setTooltip(tooltip); } - public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Text message, Text tooltip, PressAction onPress) { + public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Component message, Component tooltip, Button.OnPress onPress) { this(screen, x, y, width, height, message, 1, tooltip, onPress); } - public void renderHoveredTooltip(MatrixStack matrices) { - if (isHovered()) { - YACLScreen.renderMultilineTooltip(matrices, MinecraftClient.getInstance().textRenderer, wrappedDescription, getX() + width / 2, getY() - 4, getY() + height + 4, screen.width, screen.height); + public void renderHoveredTooltip(PoseStack matrices) { + if (isHoveredOrFocused()) { + YACLScreen.renderMultilineTooltip(matrices, Minecraft.getInstance().font, wrappedDescription, getX() + width / 2, getY() - 4, getY() + height + 4, screen.width, screen.height); } } - public void setTooltip(Text tooltip) { - wrappedDescription = MultilineText.create(MinecraftClient.getInstance().textRenderer, tooltip, screen.width / 3 - 5); + public void setTooltip(Component tooltip) { + wrappedDescription = MultiLineLabel.create(Minecraft.getInstance().font, tooltip, screen.width / 3 - 5); } } diff --git a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java index 07ecfeb..ee5c7dd 100644 --- a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java @@ -1,23 +1,23 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.*; import dev.isxander.yacl.api.*; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.api.utils.MutableDimension; import dev.isxander.yacl.api.utils.OptionUtils; import dev.isxander.yacl.gui.utils.GuiUtils; import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.tooltip.TooltipBackgroundRenderer; -import net.minecraft.client.render.*; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.screen.ScreenTexts; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; import org.joml.Matrix4f; import java.util.HashSet; @@ -35,7 +35,7 @@ public class YACLScreen extends Screen { public TooltipButtonWidget finishedSaveButton, cancelResetButton, undoButton; public SearchFieldWidget searchFieldWidget; - public Text saveButtonMessage, saveButtonTooltipMessage; + public Component saveButtonMessage, saveButtonTooltipMessage; private int saveButtonMessageTime; @@ -60,8 +60,8 @@ public class YACLScreen extends Screen { actionDim.y(), actionDim.width(), actionDim.height(), - Text.empty(), - Text.empty(), + Component.empty(), + Component.empty(), btn -> finishOrSave() ); actionDim.expand(-actionDim.width() / 2 - 2, 0).move(-actionDim.width() / 2 - 2, -22); @@ -71,8 +71,8 @@ public class YACLScreen extends Screen { actionDim.y(), actionDim.width(), actionDim.height(), - Text.empty(), - Text.empty(), + Component.empty(), + Component.empty(), btn -> cancelOrReset() ); actionDim.move(actionDim.width() + 4, 0); @@ -82,38 +82,38 @@ public class YACLScreen extends Screen { actionDim.y(), actionDim.width(), actionDim.height(), - Text.translatable("yacl.gui.undo"), - Text.translatable("yacl.gui.undo.tooltip"), + Component.translatable("yacl.gui.undo"), + Component.translatable("yacl.gui.undo.tooltip"), btn -> undo() ); searchFieldWidget = new SearchFieldWidget( this, - textRenderer, + font, width / 3 / 2 - paddedWidth / 2 + 1, undoButton.getY() - 22, paddedWidth - 2, 18, - Text.translatable("gui.recipebook.search_hint"), - Text.translatable("gui.recipebook.search_hint") + Component.translatable("gui.recipebook.search_hint"), + Component.translatable("gui.recipebook.search_hint") ); - categoryList = new CategoryListWidget(client, this, width, height); - addSelectableChild(categoryList); + categoryList = new CategoryListWidget(minecraft, this, width, height); + addWidget(categoryList); updateActionAvailability(); - addDrawableChild(searchFieldWidget); - addDrawableChild(cancelResetButton); - addDrawableChild(undoButton); - addDrawableChild(finishedSaveButton); + addRenderableWidget(searchFieldWidget); + addRenderableWidget(cancelResetButton); + addRenderableWidget(undoButton); + addRenderableWidget(finishedSaveButton); - optionList = new OptionListWidget(this, client, width, height); - addSelectableChild(optionList); + optionList = new OptionListWidget(this, minecraft, width, height); + addWidget(optionList); config.initConsumer().accept(this); } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { renderBackground(matrices); super.render(matrices, mouseX, mouseY, delta); @@ -124,7 +124,7 @@ public class YACLScreen extends Screen { categoryList.postRender(matrices, mouseX, mouseY, delta); optionList.postRender(matrices, mouseX, mouseY, delta); - for (Element child : children()) { + for (GuiEventListener child : children()) { if (child instanceof TooltipButtonWidget tooltipButtonWidget) { tooltipButtonWidget.renderHoveredTooltip(matrices); } @@ -151,14 +151,14 @@ public class YACLScreen extends Screen { }); config.saveFunction().run(); - flags.forEach(flag -> flag.accept(client)); - } else close(); + flags.forEach(flag -> flag.accept(minecraft)); + } else onClose(); } protected void cancelOrReset() { if (pendingChanges()) { // if pending changes, button acts as a cancel button OptionUtils.forEachOptions(config, Option::forgetPendingValue); - close(); + onClose(); } else { // if not, button acts as a reset button OptionUtils.forEachOptions(config, Option::requestSetDefault); } @@ -191,7 +191,7 @@ public class YACLScreen extends Screen { return; if (idx != -1 && config.categories().get(idx) instanceof PlaceholderCategory placeholderCategory) { - client.setScreen(placeholderCategory.screen().apply(client, this)); + minecraft.setScreen(placeholderCategory.screen().apply(minecraft, this)); } else { currentCategoryIdx = idx; optionList.refreshOptions(); @@ -206,10 +206,10 @@ public class YACLScreen extends Screen { boolean pendingChanges = pendingChanges(); undoButton.active = pendingChanges; - finishedSaveButton.setMessage(pendingChanges ? Text.translatable("yacl.gui.save") : GuiUtils.translatableFallback("yacl.gui.done", ScreenTexts.DONE)); - finishedSaveButton.setTooltip(pendingChanges ? Text.translatable("yacl.gui.save.tooltip") : Text.translatable("yacl.gui.finished.tooltip")); - cancelResetButton.setMessage(pendingChanges ? GuiUtils.translatableFallback("yacl.gui.cancel", ScreenTexts.CANCEL) : Text.translatable("controls.reset")); - cancelResetButton.setTooltip(pendingChanges ? Text.translatable("yacl.gui.cancel.tooltip") : Text.translatable("yacl.gui.reset.tooltip")); + finishedSaveButton.setMessage(pendingChanges ? Component.translatable("yacl.gui.save") : GuiUtils.translatableFallback("yacl.gui.done", CommonComponents.GUI_DONE)); + finishedSaveButton.setTooltip(pendingChanges ? Component.translatable("yacl.gui.save.tooltip") : Component.translatable("yacl.gui.finished.tooltip")); + cancelResetButton.setMessage(pendingChanges ? GuiUtils.translatableFallback("yacl.gui.cancel", CommonComponents.GUI_CANCEL) : Component.translatable("controls.reset")); + cancelResetButton.setTooltip(pendingChanges ? Component.translatable("yacl.gui.cancel.tooltip") : Component.translatable("yacl.gui.reset.tooltip")); } @Override @@ -233,7 +233,7 @@ public class YACLScreen extends Screen { } } - private void setSaveButtonMessage(Text message, Text tooltip) { + private void setSaveButtonMessage(Component message, Component tooltip) { saveButtonMessage = message; saveButtonTooltipMessage = tooltip; saveButtonMessageTime = 0; @@ -255,22 +255,22 @@ public class YACLScreen extends Screen { @Override public boolean shouldCloseOnEsc() { if (pendingChanges()) { - setSaveButtonMessage(Text.translatable("yacl.gui.save_before_exit").formatted(Formatting.RED), Text.translatable("yacl.gui.save_before_exit.tooltip")); + setSaveButtonMessage(Component.translatable("yacl.gui.save_before_exit").withStyle(ChatFormatting.RED), Component.translatable("yacl.gui.save_before_exit.tooltip")); return false; } return true; } @Override - public void close() { - client.setScreen(parent); + public void onClose() { + minecraft.setScreen(parent); } - public static void renderMultilineTooltip(MatrixStack matrices, TextRenderer textRenderer, MultilineText text, int centerX, int yAbove, int yBelow, int screenWidth, int screenHeight) { - if (text.count() > 0) { - int maxWidth = text.getMaxWidth(); - int lineHeight = textRenderer.fontHeight + 1; - int height = text.count() * lineHeight - 1; + public static void renderMultilineTooltip(PoseStack matrices, Font font, MultiLineLabel text, int centerX, int yAbove, int yBelow, int screenWidth, int screenHeight) { + if (text.getLineCount() > 0) { + int maxWidth = text.getWidth(); + int lineHeight = font.lineHeight + 1; + int height = text.getLineCount() * lineHeight - 1; int belowY = yBelow + 12; int aboveY = yAbove - height + 12; @@ -280,19 +280,19 @@ public class YACLScreen extends Screen { if (maxBelow < -8) y = maxBelow > minAbove ? belowY : aboveY; - int x = Math.max(centerX - text.getMaxWidth() / 2 - 12, -6); + int x = Math.max(centerX - text.getWidth() / 2 - 12, -6); int drawX = x + 12; int drawY = y - 12; - matrices.push(); - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferBuilder = tessellator.getBuffer(); - RenderSystem.setShader(GameRenderer::getPositionColorProgram); - bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); - Matrix4f matrix4f = matrices.peek().getPositionMatrix(); - TooltipBackgroundRenderer.render( - DrawableHelper::fillGradient, + matrices.pushPose(); + Tesselator tesselator = Tesselator.getInstance(); + BufferBuilder bufferBuilder = tesselator.getBuilder(); + RenderSystem.setShader(GameRenderer::getPositionColorShader); + bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); + Matrix4f matrix4f = matrices.last().pose(); + TooltipRenderUtil.renderTooltipBackground( + GuiComponent::fillGradient, matrix4f, bufferBuilder, drawX, @@ -305,14 +305,14 @@ public class YACLScreen extends Screen { RenderSystem.disableTexture(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.disableBlend(); RenderSystem.enableTexture(); matrices.translate(0.0, 0.0, 400.0); - text.drawWithShadow(matrices, drawX, drawY, lineHeight, -1); + text.renderLeftAligned(matrices, drawX, drawY, lineHeight, -1); - matrices.pop(); + matrices.popPose(); } } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java b/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java index 7666dff..e57cdd2 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java @@ -1,12 +1,12 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.platform.InputConstants; import dev.isxander.yacl.api.ButtonOption; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.BiConsumer; @@ -15,10 +15,10 @@ import java.util.function.BiConsumer; * and renders a {@link} Text on the right. */ public class ActionController implements Controller<BiConsumer<YACLScreen, ButtonOption>> { - public static final Text DEFAULT_TEXT = Text.translatable("yacl.control.action.execute"); + public static final Component DEFAULT_TEXT = Component.translatable("yacl.control.action.execute"); private final ButtonOption option; - private final Text text; + private final Component text; /** * Constructs an action controller @@ -36,7 +36,7 @@ public class ActionController implements Controller<BiConsumer<YACLScreen, Butto * @param option bound option * @param text text to display */ - public ActionController(ButtonOption option, Text text) { + public ActionController(ButtonOption option, Component text) { this.option = option; this.text = text; @@ -54,7 +54,7 @@ public class ActionController implements Controller<BiConsumer<YACLScreen, Butto * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return text; } @@ -94,7 +94,7 @@ public class ActionController implements Controller<BiConsumer<YACLScreen, Butto return false; } - if (keyCode == InputUtil.GLFW_KEY_ENTER || keyCode == InputUtil.GLFW_KEY_SPACE || keyCode == InputUtil.GLFW_KEY_KP_ENTER) { + if (keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_SPACE || keyCode == InputConstants.KEY_NUMPADENTER) { executeAction(); return true; } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java b/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java index 3a8e5c3..d97b418 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java @@ -1,41 +1,40 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.screen.ScreenTexts; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import org.lwjgl.glfw.GLFW; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; import java.util.function.Function; /** - * This controller renders a simple formatted {@link Text} + * This controller renders a simple formatted {@link Component} */ public class BooleanController implements Controller<Boolean> { - public static final Function<Boolean, Text> ON_OFF_FORMATTER = (state) -> + public static final Function<Boolean, Component> ON_OFF_FORMATTER = (state) -> state - ? ScreenTexts.ON - : ScreenTexts.OFF; + ? CommonComponents.OPTION_ON + : CommonComponents.OPTION_OFF; - public static final Function<Boolean, Text> TRUE_FALSE_FORMATTER = (state) -> + public static final Function<Boolean, Component> TRUE_FALSE_FORMATTER = (state) -> state - ? Text.translatable("yacl.control.boolean.true") - : Text.translatable("yacl.control.boolean.false"); + ? Component.translatable("yacl.control.boolean.true") + : Component.translatable("yacl.control.boolean.false"); - public static final Function<Boolean, Text> YES_NO_FORMATTER = (state) -> + public static final Function<Boolean, Component> YES_NO_FORMATTER = (state) -> state - ? ScreenTexts.YES - : ScreenTexts.NO; + ? CommonComponents.GUI_YES + : CommonComponents.GUI_NO; private final Option<Boolean> option; - private final Function<Boolean, Text> valueFormatter; + private final Function<Boolean, Component> valueFormatter; private final boolean coloured; /** @@ -63,10 +62,10 @@ public class BooleanController implements Controller<Boolean> { * Constructs a tickbox controller * * @param option bound option - * @param valueFormatter format value into any {@link Text} + * @param valueFormatter format value into any {@link Component} * @param coloured value format is green or red depending on the state */ - public BooleanController(Option<Boolean> option, Function<Boolean, Text> valueFormatter, boolean coloured) { + public BooleanController(Option<Boolean> option, Function<Boolean, Component> valueFormatter, boolean coloured) { this.option = option; this.valueFormatter = valueFormatter; this.coloured = coloured; @@ -84,7 +83,7 @@ public class BooleanController implements Controller<Boolean> { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } @@ -109,7 +108,7 @@ public class BooleanController implements Controller<Boolean> { } @Override - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { } @@ -133,9 +132,9 @@ public class BooleanController implements Controller<Boolean> { } @Override - protected Text getValueText() { + protected Component getValueText() { if (control.coloured()) { - return super.getValueText().copy().formatted(control.option().pendingValue() ? Formatting.GREEN : Formatting.RED); + return super.getValueText().copy().withStyle(control.option().pendingValue() ? ChatFormatting.GREEN : ChatFormatting.RED); } return super.getValueText(); @@ -147,7 +146,7 @@ public class BooleanController implements Controller<Boolean> { return false; } - if (keyCode == InputUtil.GLFW_KEY_ENTER || keyCode == InputUtil.GLFW_KEY_SPACE || keyCode == InputUtil.GLFW_KEY_KP_ENTER) { + if (keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_SPACE || keyCode == InputConstants.KEY_NUMPADENTER) { toggleSetting(); return true; } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java b/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java index 9626a9e..473407b 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java @@ -1,6 +1,7 @@ package dev.isxander.yacl.gui.controllers; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.api.utils.MutableDimension; @@ -8,11 +9,10 @@ import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.string.IStringController; import dev.isxander.yacl.gui.controllers.string.StringControllerElement; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import java.awt.Color; import java.util.List; @@ -62,11 +62,11 @@ public class ColorController implements IStringController<Color> { } @Override - public Text formatValue() { - MutableText text = Text.literal("#"); - text.append(Text.literal(toHex(option().pendingValue().getRed())).formatted(Formatting.RED)); - text.append(Text.literal(toHex(option().pendingValue().getGreen())).formatted(Formatting.GREEN)); - text.append(Text.literal(toHex(option().pendingValue().getBlue())).formatted(Formatting.BLUE)); + public Component formatValue() { + MutableComponent text = Component.literal("#"); + text.append(Component.literal(toHex(option().pendingValue().getRed())).withStyle(ChatFormatting.RED)); + text.append(Component.literal(toHex(option().pendingValue().getGreen())).withStyle(ChatFormatting.GREEN)); + text.append(Component.literal(toHex(option().pendingValue().getBlue())).withStyle(ChatFormatting.BLUE)); if (allowAlpha()) text.append(toHex(option().pendingValue().getAlpha())); return text; } @@ -114,13 +114,13 @@ public class ColorController implements IStringController<Color> { } @Override - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { if (isHovered()) { colorPreviewDim.move(-inputFieldBounds.width() - 5, 0); super.drawValueText(matrices, mouseX, mouseY, delta); } - DrawableHelper.fill(matrices, colorPreviewDim.x(), colorPreviewDim.y(), colorPreviewDim.xLimit(), colorPreviewDim.yLimit(), colorController.option().pendingValue().getRGB()); + GuiComponent.fill(matrices, colorPreviewDim.x(), colorPreviewDim.y(), colorPreviewDim.xLimit(), colorPreviewDim.yLimit(), colorController.option().pendingValue().getRGB()); drawOutline(matrices, colorPreviewDim.x(), colorPreviewDim.y(), colorPreviewDim.xLimit(), colorPreviewDim.yLimit(), 1, 0xFF000000); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index ae54ca4..90c0e20 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -1,27 +1,27 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.utils.GuiUtils; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; public abstract class ControllerWidget<T extends Controller<?>> extends AbstractWidget { protected final T control; - protected MultilineText wrappedTooltip; + protected MultiLineLabel wrappedTooltip; protected final YACLScreen screen; protected boolean focused = false; protected boolean hovered = false; - protected final Text modifiedOptionName; + protected final Component modifiedOptionName; protected final String optionNameString; public ControllerWidget(T control, YACLScreen screen, Dimension<Integer> dim) { @@ -30,22 +30,22 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract this.screen = screen; control.option().addListener((opt, pending) -> updateTooltip()); updateTooltip(); - this.modifiedOptionName = control.option().name().copy().formatted(Formatting.ITALIC); + this.modifiedOptionName = control.option().name().copy().withStyle(ChatFormatting.ITALIC); this.optionNameString = control.option().name().getString().toLowerCase(); } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { hovered = isMouseOver(mouseX, mouseY); - Text name = control.option().changed() ? modifiedOptionName : control.option().name(); - Text shortenedName = Text.literal(GuiUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).fillStyle(name.getStyle()); + Component name = control.option().changed() ? modifiedOptionName : control.option().name(); + Component shortenedName = Component.literal(GuiUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).setStyle(name.getStyle()); drawButtonRect(matrices, getDimension().x(), getDimension().y(), getDimension().xLimit(), getDimension().yLimit(), isHovered(), isAvailable()); - matrices.push(); + matrices.pushPose(); matrices.translate(getDimension().x() + getXPadding(), getTextY(), 0); - textRenderer.drawWithShadow(matrices, shortenedName, 0, 0, getValueColor()); - matrices.pop(); + textRenderer.drawShadow(matrices, shortenedName, 0, 0, getValueColor()); + matrices.popPose(); drawValueText(matrices, mouseX, mouseY, delta); if (isHovered()) { @@ -54,26 +54,26 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { if (hovered || focused) { YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); } } - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { } - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { - Text valueText = getValueText(); - matrices.push(); - matrices.translate(getDimension().xLimit() - textRenderer.getWidth(valueText) - getXPadding(), getTextY(), 0); - textRenderer.drawWithShadow(matrices, valueText, 0, 0, getValueColor()); - matrices.pop(); + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { + Component valueText = getValueText(); + matrices.pushPose(); + matrices.translate(getDimension().xLimit() - textRenderer.width(valueText) - getXPadding(), getTextY(), 0); + textRenderer.drawShadow(matrices, valueText, 0, 0, getValueColor()); + matrices.popPose(); } private void updateTooltip() { - this.wrappedTooltip = MultilineText.create(textRenderer, control.option().tooltip(), screen.width / 3 * 2 - 10); + this.wrappedTooltip = MultiLineLabel.create(textRenderer, control.option().tooltip(), screen.width / 3 * 2 - 10); } protected int getControlWidth() { @@ -87,7 +87,7 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract protected abstract int getHoveredControlWidth(); protected int getUnhoveredControlWidth() { - return textRenderer.getWidth(getValueText()); + return textRenderer.width(getValueText()); } protected int getXPadding() { @@ -98,7 +98,7 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract return 2; } - protected Text getValueText() { + protected Component getValueText() { return control.formatValue(); } @@ -115,15 +115,15 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract return true; } - protected void drawOutline(MatrixStack matrices, int x1, int y1, int x2, int y2, int width, int color) { - DrawableHelper.fill(matrices, x1, y1, x2, y1 + width, color); - DrawableHelper.fill(matrices, x2, y1, x2 - width, y2, color); - DrawableHelper.fill(matrices, x1, y2, x2, y2 - width, color); - DrawableHelper.fill(matrices, x1, y1, x1 + width, y2, color); + protected void drawOutline(PoseStack matrices, int x1, int y1, int x2, int y2, int width, int color) { + GuiComponent.fill(matrices, x1, y1, x2, y1 + width, color); + GuiComponent.fill(matrices, x2, y1, x2 - width, y2, color); + GuiComponent.fill(matrices, x1, y2, x2, y2 - width, color); + GuiComponent.fill(matrices, x1, y1, x1 + width, y2, color); } protected float getTextY() { - return getDimension().y() + getDimension().height() / 2f - textRenderer.fontHeight / 2f; + return getDimension().y() + getDimension().height() / 2f - textRenderer.lineHeight / 2f; } @Override @@ -146,13 +146,13 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract } @Override - public SelectionType getType() { - return focused ? SelectionType.FOCUSED : isHovered() ? SelectionType.HOVERED : SelectionType.NONE; + public NarrationPriority narrationPriority() { + return focused ? NarrationPriority.FOCUSED : isHovered() ? NarrationPriority.HOVERED : NarrationPriority.NONE; } @Override - public void appendNarrations(NarrationMessageBuilder builder) { - builder.put(NarrationPart.TITLE, control.option().name()); - builder.put(NarrationPart.HINT, control.option().tooltip()); + public void updateNarration(NarrationElementOutput builder) { + builder.add(NarratedElementType.TITLE, control.option().name()); + builder.add(NarratedElementType.HINT, control.option().tooltip()); } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java b/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java index 960c950..0017b59 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java @@ -1,28 +1,31 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.ItemStack; -import net.minecraft.text.*; +import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.world.item.ItemStack; import java.util.List; /** * Simply renders some text as a label. */ -public class LabelController implements Controller<Text> { - private final Option<Text> option; +public class LabelController implements Controller<Component> { + private final Option<Component> option; /** * Constructs a label controller * * @param option bound option */ - public LabelController(Option<Text> option) { + public LabelController(Option<Component> option) { this.option = option; } @@ -30,12 +33,12 @@ public class LabelController implements Controller<Text> { * {@inheritDoc} */ @Override - public Option<Text> option() { + public Option<Component> option() { return option; } @Override - public Text formatValue() { + public Component formatValue() { return option().pendingValue(); } @@ -45,8 +48,8 @@ public class LabelController implements Controller<Text> { } public class LabelControllerElement extends AbstractWidget { - private List<OrderedText> wrappedText; - protected MultilineText wrappedTooltip; + private List<FormattedCharSequence> wrappedText; + protected MultiLineLabel wrappedTooltip; protected final YACLScreen screen; @@ -59,38 +62,38 @@ public class LabelController implements Controller<Text> { } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { updateText(); float y = getDimension().y(); - for (OrderedText text : wrappedText) { - textRenderer.drawWithShadow(matrices, text, getDimension().x() + getXPadding(), y + getYPadding(), option().available() ? -1 : 0xFFA0A0A0); - y += textRenderer.fontHeight; + for (FormattedCharSequence text : wrappedText) { + textRenderer.drawShadow(matrices, text, getDimension().x() + getXPadding(), y + getYPadding(), option().available() ? -1 : 0xFFA0A0A0); + y += textRenderer.lineHeight; } } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { if (isMouseOver(mouseX, mouseY)) { YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); Style style = getStyle(mouseX, mouseY); if (style != null && style.getHoverEvent() != null) { HoverEvent hoverEvent = style.getHoverEvent(); - HoverEvent.ItemStackContent itemStackContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ITEM); + HoverEvent.ItemStackInfo itemStackContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ITEM); if (itemStackContent != null) { - ItemStack stack = itemStackContent.asStack(); - screen.renderTooltip(matrices, screen.getTooltipFromItem(stack), stack.getTooltipData(), mouseX, mouseY); + ItemStack stack = itemStackContent.getItemStack(); + screen.renderTooltip(matrices, screen.getTooltipFromItem(stack), stack.getTooltipImage(), mouseX, mouseY); } else { - HoverEvent.EntityContent entityContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ENTITY); + HoverEvent.EntityTooltipInfo entityContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ENTITY); if (entityContent != null) { if (this.client.options.advancedItemTooltips) { - screen.renderTooltip(matrices, entityContent.asTooltip(), mouseX, mouseY); + screen.renderComponentTooltip(matrices, entityContent.getTooltipLines(), mouseX, mouseY); } } else { - Text text = hoverEvent.getValue(HoverEvent.Action.SHOW_TEXT); + Component text = hoverEvent.getValue(HoverEvent.Action.SHOW_TEXT); if (text != null) { - MultilineText multilineText = MultilineText.create(textRenderer, text, getDimension().width()); + MultiLineLabel multilineText = MultiLineLabel.create(textRenderer, text, getDimension().width()); YACLScreen.renderMultilineTooltip(matrices, textRenderer, multilineText, getDimension().centerX(), getDimension().y(), getDimension().yLimit(), screen.width, screen.height); } } @@ -105,7 +108,7 @@ public class LabelController implements Controller<Text> { return false; Style style = getStyle((int) mouseX, (int) mouseY); - return screen.handleTextClick(style); + return screen.handleComponentClicked(style); } protected Style getStyle(int mouseX, int mouseY) { @@ -114,13 +117,13 @@ public class LabelController implements Controller<Text> { int x = mouseX - getDimension().x(); int y = mouseY - getDimension().y() - getYPadding(); - int line = y / textRenderer.fontHeight; + int line = y / textRenderer.lineHeight; if (x < 0 || x > getDimension().xLimit()) return null; if (y < 0 || y > getDimension().yLimit()) return null; if (line < 0 || line >= wrappedText.size()) return null; - return textRenderer.getTextHandler().getStyleAt(wrappedText.get(line), x); + return textRenderer.getSplitter().componentStyleAtWidth(wrappedText.get(line), x); } private int getXPadding() { @@ -132,12 +135,12 @@ public class LabelController implements Controller<Text> { } private void updateText() { - wrappedText = textRenderer.wrapLines(formatValue(), getDimension().width() - getXPadding() * 2); - setDimension(getDimension().withHeight(wrappedText.size() * textRenderer.fontHeight + getYPadding() * 2)); + wrappedText = textRenderer.split(formatValue(), getDimension().width() - getXPadding() * 2); + setDimension(getDimension().withHeight(wrappedText.size() * textRenderer.lineHeight + getYPadding() * 2)); } private void updateTooltip() { - this.wrappedTooltip = MultilineText.create(textRenderer, option().tooltip(), screen.width / 3 * 2 - 10); + this.wrappedTooltip = MultiLineLabel.create(textRenderer, option().tooltip(), screen.width / 3 * 2 - 10); } @Override diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java b/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java index 0a5d581..1acccf1 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java @@ -1,20 +1,20 @@ package dev.isxander.yacl.gui.controllers; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.ListOption; import dev.isxander.yacl.api.ListOptionEntry; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.*; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.ParentElement; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.events.ContainerEventHandler; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import java.util.List; -public class ListEntryWidget extends AbstractWidget implements ParentElement { +public class ListEntryWidget extends AbstractWidget implements ContainerEventHandler { private final TooltipButtonWidget removeButton, moveUpButton, moveDownButton; private final AbstractWidget entryWidget; @@ -23,7 +23,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { private final String optionNameString; - private Element focused; + private GuiEventListener focused; private boolean dragging; public ListEntryWidget(YACLScreen screen, ListOptionEntry<?> listOptionEntry, AbstractWidget entryWidget) { @@ -36,12 +36,12 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { Dimension<Integer> dim = entryWidget.getDimension(); entryWidget.setDimension(dim.clone().move(20 * 2, 0).expand(-20 * 3, 0)); - removeButton = new TooltipButtonWidget(screen, dim.xLimit() - 20, dim.y(), 20, 20, Text.of("\u274c"), Text.translatable("yacl.list.remove"), btn -> { + removeButton = new TooltipButtonWidget(screen, dim.xLimit() - 20, dim.y(), 20, 20, Component.literal("\u274c"), Component.translatable("yacl.list.remove"), btn -> { listOption.removeEntry(listOptionEntry); updateButtonStates(); }); - moveUpButton = new TooltipButtonWidget(screen, dim.x(), dim.y(), 20, 20, Text.of("\u2191"), Text.translatable("yacl.list.move_up"), btn -> { + moveUpButton = new TooltipButtonWidget(screen, dim.x(), dim.y(), 20, 20, Component.literal("\u2191"), Component.translatable("yacl.list.move_up"), btn -> { int index = listOption.indexOf(listOptionEntry) - 1; if (index >= 0) { listOption.removeEntry(listOptionEntry); @@ -50,7 +50,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } }); - moveDownButton = new TooltipButtonWidget(screen, dim.x() + 20, dim.y(), 20, 20, Text.of("\u2193"), Text.translatable("yacl.list.move_down"), btn -> { + moveDownButton = new TooltipButtonWidget(screen, dim.x() + 20, dim.y(), 20, 20, Component.literal("\u2193"), Component.translatable("yacl.list.move_down"), btn -> { int index = listOption.indexOf(listOptionEntry) + 1; if (index < listOption.options().size()) { listOption.removeEntry(listOptionEntry); @@ -63,7 +63,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { updateButtonStates(); // update every render in case option becomes available/unavailable removeButton.setY(getDimension().y()); @@ -78,7 +78,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { removeButton.renderHoveredTooltip(matrices); moveUpButton.renderHoveredTooltip(matrices); moveDownButton.renderHoveredTooltip(matrices); @@ -96,8 +96,8 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public void appendNarrations(NarrationMessageBuilder builder) { - entryWidget.appendNarrations(builder); + public void updateNarration(NarrationElementOutput builder) { + entryWidget.updateNarration(builder); } @Override @@ -106,7 +106,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public List<? extends Element> children() { + public List<? extends GuiEventListener> children() { return ImmutableList.of(moveUpButton, moveDownButton, entryWidget, removeButton); } @@ -122,12 +122,12 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { @Nullable @Override - public Element getFocused() { + public GuiEventListener getFocused() { return focused; } @Override - public void setFocused(@Nullable Element focused) { + public void setFocused(@Nullable GuiEventListener focused) { this.focused = focused; } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java b/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java index b0ae449..3f615db 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java @@ -1,14 +1,14 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.network.chat.Component; /** * This controller renders a tickbox @@ -37,8 +37,8 @@ public class TickBoxController implements Controller<Boolean> { * {@inheritDoc} */ @Override - public Text formatValue() { - return Text.empty(); + public Component formatValue() { + return Component.empty(); } /** @@ -55,7 +55,7 @@ public class TickBoxController implements Controller<Boolean> { } @Override - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { int outlineSize = 10; int outlineX1 = getDimension().xLimit() - getXPadding() - outlineSize; int outlineY1 = getDimension().centerY() - outlineSize / 2; @@ -68,13 +68,13 @@ public class TickBoxController implements Controller<Boolean> { drawOutline(matrices, outlineX1 + 1, outlineY1 + 1, outlineX2 + 1, outlineY2 + 1, 1, shadowColor); drawOutline(matrices, outlineX1, outlineY1, outlineX2, outlineY2, 1, color); if (control.option().pendingValue()) { - DrawableHelper.fill(matrices, outlineX1 + 3, outlineY1 + 3, outlineX2 - 1, outlineY2 - 1, shadowColor); - DrawableHelper.fill(matrices, outlineX1 + 2, outlineY1 + 2, outlineX2 - 2, outlineY2 - 2, color); + GuiComponent.fill(matrices, outlineX1 + 3, outlineY1 + 3, outlineX2 - 1, outlineY2 - 1, shadowColor); + GuiComponent.fill(matrices, outlineX1 + 2, outlineY1 + 2, outlineX2 - 2, outlineY2 - 2, color); } } @Override - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { if (!isHovered()) drawHoveredControl(matrices, mouseX, mouseY, delta); } @@ -109,7 +109,7 @@ public class TickBoxController implements Controller<Boolean> { return false; } - if (keyCode == InputUtil.GLFW_KEY_ENTER || keyCode == InputUtil.GLFW_KEY_SPACE || keyCode == InputUtil.GLFW_KEY_KP_ENTER) { + if (keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_SPACE || keyCode == InputConstants.KEY_NUMPADENTER) { toggleSetting(); return true; } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java index 246fbec..b2fa776 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java @@ -1,10 +1,10 @@ package dev.isxander.yacl.gui.controllers.cycling; +import com.mojang.blaze3d.platform.InputConstants; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; +import net.minecraft.client.gui.screens.Screen; public class CyclingControllerElement extends ControllerWidget<ICyclingController<?>> { @@ -39,11 +39,11 @@ public class CyclingControllerElement extends ControllerWidget<ICyclingControlle return false; switch (keyCode) { - case InputUtil.GLFW_KEY_LEFT, InputUtil.GLFW_KEY_DOWN -> + case InputConstants.KEY_LEFT, InputConstants.KEY_DOWN -> cycleValue(-1); - case InputUtil.GLFW_KEY_RIGHT, InputUtil.GLFW_KEY_UP -> + case InputConstants.KEY_RIGHT, InputConstants.KEY_UP -> cycleValue(1); - case InputUtil.GLFW_KEY_ENTER, InputUtil.GLFW_KEY_SPACE, InputUtil.GLFW_KEY_KP_ENTER -> + case InputConstants.KEY_RETURN, InputConstants.KEY_SPACE, InputConstants.KEY_NUMPADENTER -> cycleValue(Screen.hasControlDown() || Screen.hasShiftDown() ? -1 : 1); default -> { return false; diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java index 3b14066..34f2cc9 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java @@ -2,7 +2,7 @@ package dev.isxander.yacl.gui.controllers.cycling; import com.google.common.collect.ImmutableList; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.Function; @@ -12,7 +12,7 @@ import java.util.function.Function; */ public class CyclingListController<T> implements ICyclingController<T> { private final Option<T> option; - private final Function<T, Text> valueFormatter; + private final Function<T, Component> valueFormatter; private final ImmutableList<T> values; /** @@ -22,7 +22,7 @@ public class CyclingListController<T> implements ICyclingController<T> { * @param values the values to cycle through */ public CyclingListController(Option<T> option, Iterable<T> values) { - this(option, values, value -> Text.of(value.toString())); + this(option, values, value -> Component.literal(value.toString())); } /** @@ -31,7 +31,7 @@ public class CyclingListController<T> implements ICyclingController<T> { * @param values the values to cycle through * @param valueFormatter function of how to convert each value to a string to display */ - public CyclingListController(Option<T> option, Iterable<T> values, Function<T, Text> valueFormatter) { + public CyclingListController(Option<T> option, Iterable<T> values, Function<T, Component> valueFormatter) { this.option = option; this.valueFormatter = valueFormatter; this.values = ImmutableList.copyOf(values); @@ -49,7 +49,7 @@ public class CyclingListController<T> implements ICyclingController<T> { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java index bc9f46d..ebd2cb6 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java @@ -2,8 +2,8 @@ package dev.isxander.yacl.gui.controllers.cycling; import dev.isxander.yacl.api.NameableEnum; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; -import net.minecraft.util.TranslatableOption; +import net.minecraft.network.chat.Component; +import net.minecraft.util.OptionEnum; import java.util.Arrays; import java.util.function.Function; @@ -16,20 +16,20 @@ import java.util.function.Function; * @param <T> enum type */ public class EnumController<T extends Enum<T>> extends CyclingListController<T> { - public static <T extends Enum<T>> Function<T, Text> getDefaultFormatter() { + public static <T extends Enum<T>> Function<T, Component> getDefaultFormatter() { return value -> { if (value instanceof NameableEnum nameableEnum) return nameableEnum.getDisplayName(); - if (value instanceof TranslatableOption translatableOption) - return translatableOption.getText(); - return Text.of(value.toString()); + if (value instanceof OptionEnum translatableOption) + return translatableOption.getCaption(); + return Component.literal(value.toString()); }; } /** * Constructs a cycling enum controller with a default value formatter and all values being available. * The default value formatter first searches if the - * enum is a {@link NameableEnum} or {@link TranslatableOption} else, just uses {@link Enum#toString()} + * enum is a {@link NameableEnum} or {@link OptionEnum} else, just uses {@link Enum#toString()} * * @param option bound option */ @@ -41,9 +41,9 @@ public class EnumController<T extends Enum<T>> extends CyclingListController<T> * Constructs a cycling enum controller with all values being available. * * @param option bound option - * @param valueFormatter format the enum into any {@link Text} + * @param valueFormatter format the enum into any {@link Component} */ - public EnumController(Option<T> option, Function<T, Text> valueFormatter) { + public EnumController(Option<T> option, Function<T, Component> valueFormatter) { this(option, valueFormatter, option.typeClass().getEnumConstants()); } @@ -51,10 +51,10 @@ public class EnumController<T extends Enum<T>> extends CyclingListController<T> * Constructs a cycling enum controller. * * @param option bound option - * @param valueFormatter format the enum into any {@link Text} + * @param valueFormatter format the enum into any {@link Component} * @param availableValues all enum constants that can be cycled through */ - public EnumController(Option<T> option, Function<T, Text> valueFormatter, T[] availableValues) { + public EnumController(Option<T> option, Function<T, Component> valueFormatter, T[] availableValues) { super(option, Arrays.asList(availableValues), valueFormatter); } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java index 54c7476..8e044b1 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -13,13 +13,13 @@ public class DoubleSliderController implements ISliderController<Double> { /** * Formats doubles to two decimal places */ - public static final Function<Double, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.2f", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function<Double, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,.2f", value).replaceAll("[\u00a0\u202F]", " ")); private final Option<Double> option; private final double min, max, interval; - private final Function<Double, Text> valueFormatter; + private final Function<Double, Component> valueFormatter; /** * Constructs a {@link ISliderController} for doubles @@ -41,9 +41,9 @@ public class DoubleSliderController implements ISliderController<Double> { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public DoubleSliderController(Option<Double> option, double min, double max, double interval, Function<Double, Text> valueFormatter) { + public DoubleSliderController(Option<Double> option, double min, double max, double interval, Function<Double, Component> valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -67,7 +67,7 @@ public class DoubleSliderController implements ISliderController<Double> { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java index 84ca9a2..25f2206 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -13,13 +13,13 @@ public class FloatSliderController implements ISliderController<Float> { /** * Formats floats to one decimal place */ - public static final Function<Float, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.1f", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function<Float, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,.1f", value).replaceAll("[\u00a0\u202F]", " ")); private final Option<Float> option; private final float min, max, interval; - private final Function<Float, Text> valueFormatter; + private final Function<Float, Component> valueFormatter; /** * Constructs a {@link ISliderController} for floats @@ -41,9 +41,9 @@ public class FloatSliderController implements ISliderController<Float> { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public FloatSliderController(Option<Float> option, float min, float max, float interval, Function<Float, Text> valueFormatter) { + public FloatSliderController(Option<Float> option, float min, float max, float interval, Function<Float, Component> valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -67,7 +67,7 @@ public class FloatSliderController implements ISliderController<Float> { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java index 50ec9d2..4a68497 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -10,13 +10,13 @@ import java.util.function.Function; * {@link ISliderController} for integers. */ public class IntegerSliderController implements ISliderController<Integer> { - public static final Function<Integer, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function<Integer, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); private final Option<Integer> option; private final int min, max, interval; - private final Function<Integer, Text> valueFormatter; + private final Function<Integer, Component> valueFormatter; /** * Constructs a {@link ISliderController} for integers @@ -38,9 +38,9 @@ public class IntegerSliderController implements ISliderController<Integer> { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public IntegerSliderController(Option<Integer> option, int min, int max, int interval, Function<Integer, Text> valueFormatter) { + public IntegerSliderController(Option<Integer> option, int min, int max, int interval, Function<Integer, Component> valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -64,7 +64,7 @@ public class IntegerSliderController implements ISliderController<Integer> { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java index 3038402..681e7cf 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -10,13 +10,13 @@ import java.util.function.Function; * {@link ISliderController} for longs. */ public class LongSliderController implements ISliderController<Long> { - public static final Function<Long, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function<Long, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); private final Option<Long> option; private final long min, max, interval; - private final Function<Long, Text> valueFormatter; + private final Function<Long, Component> valueFormatter; /** * Constructs a {@link ISliderController} for longs @@ -38,9 +38,9 @@ public class LongSliderController implements ISliderController<Long> { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public LongSliderController(Option<Long> option, long min, long max, long interval, Function<Long, Text> valueFormatter) { + public LongSliderController(Option<Long> option, long min, long max, long interval, Function<Long, Component> valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -64,7 +64,7 @@ public class LongSliderController implements ISliderController<Long> { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java index ea4e262..ddfdd4d 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java @@ -1,13 +1,13 @@ package dev.isxander.yacl.gui.controllers.slider; +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.MathHelper; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.util.Mth; public class SliderControllerElement extends ControllerWidget<ISliderController<?>> { private final double min, max, interval; @@ -27,32 +27,32 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { super.render(matrices, mouseX, mouseY, delta); calculateInterpolation(); } @Override - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { // track - DrawableHelper.fill(matrices, sliderBounds.x(), sliderBounds.centerY() - 1, sliderBounds.xLimit(), sliderBounds.centerY(), -1); + GuiComponent.fill(matrices, sliderBounds.x(), sliderBounds.centerY() - 1, sliderBounds.xLimit(), sliderBounds.centerY(), -1); // track shadow - DrawableHelper.fill(matrices, sliderBounds.x() + 1, sliderBounds.centerY(), sliderBounds.xLimit() + 1, sliderBounds.centerY() + 1, 0xFF404040); + GuiComponent.fill(matrices, sliderBounds.x() + 1, sliderBounds.centerY(), sliderBounds.xLimit() + 1, sliderBounds.centerY() + 1, 0xFF404040); // thumb shadow - DrawableHelper.fill(matrices, getThumbX() - getThumbWidth() / 2 + 1, sliderBounds.y() + 1, getThumbX() + getThumbWidth() / 2 + 1, sliderBounds.yLimit() + 1, 0xFF404040); + GuiComponent.fill(matrices, getThumbX() - getThumbWidth() / 2 + 1, sliderBounds.y() + 1, getThumbX() + getThumbWidth() / 2 + 1, sliderBounds.yLimit() + 1, 0xFF404040); // thumb - DrawableHelper.fill(matrices, getThumbX() - getThumbWidth() / 2, sliderBounds.y(), getThumbX() + getThumbWidth() / 2, sliderBounds.yLimit(), -1); + GuiComponent.fill(matrices, getThumbX() - getThumbWidth() / 2, sliderBounds.y(), getThumbX() + getThumbWidth() / 2, sliderBounds.yLimit(), -1); } @Override - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { - matrices.push(); + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { + matrices.pushPose(); if (isHovered()) matrices.translate(-(sliderBounds.width() + 6 + getThumbWidth() / 2f), 0, 0); super.drawValueText(matrices, mouseX, mouseY, delta); - matrices.pop(); + matrices.popPose(); } @Override @@ -76,7 +76,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< } public void incrementValue(double amount) { - control.setPendingValue(MathHelper.clamp(control.pendingValue() + interval * amount, min, max)); + control.setPendingValue(Mth.clamp(control.pendingValue() + interval * amount, min, max)); calculateInterpolation(); } @@ -104,8 +104,8 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< return false; switch (keyCode) { - case InputUtil.GLFW_KEY_LEFT, InputUtil.GLFW_KEY_DOWN -> incrementValue(-1); - case InputUtil.GLFW_KEY_RIGHT, InputUtil.GLFW_KEY_UP -> incrementValue(1); + case InputConstants.KEY_LEFT, InputConstants.KEY_DOWN -> incrementValue(-1); + case InputConstants.KEY_RIGHT, InputConstants.KEY_UP -> incrementValue(1); default -> { return false; } @@ -126,7 +126,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< } protected double roundToInterval(double value) { - return MathHelper.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping + return Mth.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping } @Override @@ -135,7 +135,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< } protected void calculateInterpolation() { - interpolation = MathHelper.clamp((float) ((control.pendingValue() - control.min()) * 1 / control.range()), 0f, 1f); + interpolation = Mth.clamp((float) ((control.pendingValue() - control.min()) * 1 / control.range()), 0f, 1f); } @Override @@ -157,7 +157,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { if (super.isMouseOver(mouseX, mouseY)) super.postRender(matrices, mouseX, mouseY, delta); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java index 553e278..6a603d2 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java @@ -5,7 +5,7 @@ import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; /** * A controller that can be any type but can input and output a string. @@ -29,8 +29,8 @@ public interface IStringController<T> extends Controller<T> { * {@inheritDoc} */ @Override - default Text formatValue() { - return Text.of(getString()); + default Component formatValue() { + return Component.literal(getString()); } default boolean isInputValid(String input) { diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java index b4358f4..2723089 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java @@ -1,16 +1,16 @@ package dev.isxander.yacl.gui.controllers.string; +import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; import dev.isxander.yacl.gui.utils.GuiUtils; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import java.util.function.Consumer; @@ -28,7 +28,7 @@ public class StringControllerElement extends ControllerWidget<IStringController< protected float ticks; - private final Text emptyText; + private final Component emptyText; public StringControllerElement(IStringController<?> control, YACLScreen screen, Dimension<Integer> dim, boolean instantApply) { super(control, screen, dim); @@ -36,48 +36,48 @@ public class StringControllerElement extends ControllerWidget<IStringController< inputField = control.getString(); inputFieldFocused = false; selectionLength = 0; - emptyText = Text.literal("Click to type...").formatted(Formatting.GRAY); + emptyText = Component.literal("Click to type...").withStyle(ChatFormatting.GRAY); control.option().addListener((opt, val) -> inputField = control.getString()); setDimension(dim); } @Override - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { } @Override - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { - Text valueText = getValueText(); - if (!isHovered()) valueText = Text.literal(GuiUtils.shortenString(valueText.getString(), textRenderer, getMaxUnwrapLength(), "...")).setStyle(valueText.getStyle()); + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { + Component valueText = getValueText(); + if (!isHovered()) valueText = Component.literal(GuiUtils.shortenString(valueText.getString(), textRenderer, getMaxUnwrapLength(), "...")).setStyle(valueText.getStyle()); - matrices.push(); - int textX = getDimension().xLimit() - textRenderer.getWidth(valueText) + renderOffset - getXPadding(); + matrices.pushPose(); + int textX = getDimension().xLimit() - textRenderer.width(valueText) + renderOffset - getXPadding(); matrices.translate(textX, getTextY(), 0); GuiUtils.enableScissor(inputFieldBounds.x(), inputFieldBounds.y() - 2, inputFieldBounds.width() + 1, inputFieldBounds.height() + 4); - textRenderer.drawWithShadow(matrices, valueText, 0, 0, getValueColor()); - matrices.pop(); + textRenderer.drawShadow(matrices, valueText, 0, 0, getValueColor()); + matrices.popPose(); if (isHovered()) { ticks += delta; String text = getValueText().getString(); - DrawableHelper.fill(matrices, inputFieldBounds.x(), inputFieldBounds.yLimit(), inputFieldBounds.xLimit(), inputFieldBounds.yLimit() + 1, -1); - DrawableHelper.fill(matrices, inputFieldBounds.x() + 1, inputFieldBounds.yLimit() + 1, inputFieldBounds.xLimit() + 1, inputFieldBounds.yLimit() + 2, 0xFF404040); + GuiComponent.fill(matrices, inputFieldBounds.x(), inputFieldBounds.yLimit(), inputFieldBounds.xLimit(), inputFieldBounds.yLimit() + 1, -1); + GuiComponent.fill(matrices, inputFieldBounds.x() + 1, inputFieldBounds.yLimit() + 1, inputFieldBounds.xLimit() + 1, inputFieldBounds.yLimit() + 2, 0xFF404040); if (inputFieldFocused || focused) { - int caretX = textX + textRenderer.getWidth(text.substring(0, caretPos)) - 1; + int caretX = textX + textRenderer.width(text.substring(0, caretPos)) - 1; if (text.isEmpty()) caretX = inputFieldBounds.x() + inputFieldBounds.width() / 2; if (ticks % 20 <= 10) { - DrawableHelper.fill(matrices, caretX, inputFieldBounds.y(), caretX + 1, inputFieldBounds.yLimit(), -1); + GuiComponent.fill(matrices, caretX, inputFieldBounds.y(), caretX + 1, inputFieldBounds.yLimit(), -1); } if (selectionLength != 0) { - int selectionX = textX + textRenderer.getWidth(text.substring(0, caretPos + selectionLength)); - DrawableHelper.fill(matrices, caretX, inputFieldBounds.y() - 1, selectionX, inputFieldBounds.yLimit(), 0x803030FF); + int selectionX = textX + textRenderer.width(text.substring(0, caretPos + selectionLength)); + GuiComponent.fill(matrices, caretX, inputFieldBounds.y() - 1, selectionX, inputFieldBounds.yLimit(), 0x803030FF); } } } @@ -93,12 +93,12 @@ public class StringControllerElement extends ControllerWidget<IStringController< caretPos = getDefaultCaretPos(); } else { // gets the appropriate caret position for where you click - int textX = (int) mouseX - (inputFieldBounds.xLimit() - textRenderer.getWidth(getValueText())); + int textX = (int) mouseX - (inputFieldBounds.xLimit() - textRenderer.width(getValueText())); int pos = -1; int currentWidth = 0; for (char ch : inputField.toCharArray()) { pos++; - int charLength = textRenderer.getWidth(String.valueOf(ch)); + int charLength = textRenderer.width(String.valueOf(ch)); if (currentWidth + charLength / 2 > textX) { // if more than halfway past the characters select in front of that char caretPos = pos; break; @@ -129,11 +129,11 @@ public class StringControllerElement extends ControllerWidget<IStringController< return false; switch (keyCode) { - case InputUtil.GLFW_KEY_ESCAPE, InputUtil.GLFW_KEY_ENTER -> { + case InputConstants.KEY_ESCAPE, InputConstants.KEY_RETURN -> { unfocus(); return true; } - case InputUtil.GLFW_KEY_LEFT -> { + case InputConstants.KEY_LEFT -> { if (Screen.hasShiftDown()) { if (Screen.hasControlDown()) { int spaceChar = findSpaceIndex(true); @@ -157,7 +157,7 @@ public class StringControllerElement extends ControllerWidget<IStringController< return true; } - case InputUtil.GLFW_KEY_RIGHT -> { + case InputConstants.KEY_RIGHT -> { if (Screen.hasShiftDown()) { if (Screen.hasControlDown()) { int spaceChar = findSpaceIndex(false); @@ -181,11 +181,11 @@ public class StringControllerElement extends ControllerWidget<IStringController< return true; } - case InputUtil.GLFW_KEY_BACKSPACE -> { + case InputConstants.KEY_BACKSPACE -> { doBackspace(); return true; } - case InputUtil.GLFW_KEY_DELETE -> { + case InputConstants.KEY_DELETE -> { doDelete(); return true; } @@ -205,13 +205,13 @@ public class StringControllerElement extends ControllerWidget<IStringController< } protected boolean doPaste() { - this.write(client.keyboard.getClipboard()); + this.write(client.keyboardHandler.getClipboard()); return true; } protected boolean doCopy() { if (selectionLength != 0) { - client.keyboard.setClipboard(getSelection()); + client.keyboardHandler.setClipboard(getSelection()); return true; } return false; @@ -219,7 +219,7 @@ public class StringControllerElement extends ControllerWidget<IStringController< protected boolean doCut() { if (selectionLength != 0) { - client.keyboard.setClipboard(getSelection()); + client.keyboardHandler.setClipboard(getSelection()); this.write(""); return true; } @@ -234,13 +234,13 @@ public class StringControllerElement extends ControllerWidget<IStringController< } protected void checkRenderOffset() { - if (textRenderer.getWidth(inputField) < getUnshiftedLength()) { + if (textRenderer.width(inputField) < getUnshiftedLength()) { renderOffset = 0; return; } - int textX = getDimension().xLimit() - textRenderer.getWidth(inputField) - getXPadding(); - int caretX = textX + textRenderer.getWidth(inputField.substring(0, caretPos)) - 1; + int textX = getDimension().xLimit() - textRenderer.width(inputField) - getXPadding(); + int caretX = textX + textRenderer.width(inputField.substring(0, caretPos)) - 1; int minX = getDimension().xLimit() - getXPadding() - getUnshiftedLength(); int maxX = minX + getUnshiftedLength(); @@ -371,8 +371,8 @@ public class StringControllerElement extends ControllerWidget<IStringController< public void setDimension(Dimension<Integer> dim) { super.setDimension(dim); - int width = Math.max(6, Math.min(textRenderer.getWidth(getValueText()), getUnshiftedLength())); - inputFieldBounds = Dimension.ofInt(dim.xLimit() - getXPadding() - width, dim.centerY() - textRenderer.fontHeight / 2, width, textRenderer.fontHeight); + int width = Math.max(6, Math.min(textRenderer.width(getValueText()), getUnshiftedLength())); + inputFieldBounds = Dimension.ofInt(dim.xLimit() - getXPadding() - width, dim.centerY() - textRenderer.lineHeight / 2, width, textRenderer.lineHeight); } @Override @@ -391,14 +391,14 @@ public class StringControllerElement extends ControllerWidget<IStringController< @Override protected int getHoveredControlWidth() { - return Math.min(textRenderer.getWidth(getValueText()), getUnshiftedLength()); + return Math.min(textRenderer.width(getValueText()), getUnshiftedLength()); } @Override - protected Text getValueText() { + protected Component getValueText() { if (!inputFieldFocused && inputField.isEmpty()) return emptyText; - return instantApply || !inputFieldFocused ? control.formatValue() : Text.of(inputField); + return instantApply || !inputFieldFocused ? control.formatValue() : Component.literal(inputField); } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java index 8933df3..df28241 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java @@ -2,9 +2,8 @@ package dev.isxander.yacl.gui.controllers.string.number; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.gui.controllers.slider.DoubleSliderController; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; -import java.math.BigDecimal; import java.util.function.Function; /** @@ -21,7 +20,7 @@ public class DoubleFieldController extends NumberFieldController<Double> { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public DoubleFieldController(Option<Double> option, double min, double max, Function<Double, Text> formatter) { + public DoubleFieldController(Option<Double> option, double min, double max, Function<Double, Component> formatter) { super(option, formatter); this.min = min; this.max = max; @@ -47,7 +46,7 @@ public class DoubleFieldController extends NumberFieldController<Double> { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public DoubleFieldController(Option<Double> option, Function<Double, Text> formatter) { + public DoubleFieldController(Option<Double> option, Function<Double, Component> formatter) { this(option, -Double.MAX_VALUE, Double.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java index b1eb3a2..957100a 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java @@ -2,9 +2,8 @@ package dev.isxander.yacl.gui.controllers.string.number; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.gui.controllers.slider.FloatSliderController; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; -import java.math.BigDecimal; import java.util.function.Function; /** @@ -21,7 +20,7 @@ public class FloatFieldController extends NumberFieldController<Float> { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public FloatFieldController(Option<Float> option, float min, float max, Function<Float, Text> formatter) { + public FloatFieldController(Option<Float> option, float min, float max, Function<Float, Component> formatter) { super(option, formatter); this.min = min; this.max = max; @@ -47,7 +46,7 @@ public class FloatFieldController extends NumberFieldController<Float> { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public FloatFieldController(Option<Float> option, Function<Float, Text> formatter) { + public FloatFieldController(Option<Float> option, Function<Float, Component> formatter) { this(option, -Float.MAX_VALUE, Float.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java index 50eecec..2d64a3a 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java @@ -2,7 +2,7 @@ package dev.isxander.yacl.gui.controllers.string.number; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.gui.controllers.slider.IntegerSliderController; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.Function; @@ -20,7 +20,7 @@ public class IntegerFieldController extends NumberFieldController<Integer> { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public IntegerFieldController(Option<Integer> option, int min, int max, Function<Integer, Text> formatter) { + public IntegerFieldController(Option<Integer> option, int min, int max, Function<Integer, Component> formatter) { super(option, formatter); this.min = min; this.max = max; @@ -46,7 +46,7 @@ public class IntegerFieldController extends NumberFieldController<Integer> { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public IntegerFieldController(Option<Integer> option, Function<Integer, Text> formatter) { + public IntegerFieldController(Option<Integer> option, Function<Integer, Component> formatter) { this(option, -Integer.MAX_VALUE, Integer.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java index 516de74..a640621 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java @@ -2,7 +2,7 @@ package dev.isxander.yacl.gui.controllers.string.number; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.gui.controllers.slider.LongSliderController; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.Function; @@ -20,7 +20,7 @@ public class LongFieldController extends NumberFieldController<Long> { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public LongFieldController(Option<Long> option, long min, long max, Function<Long, Text> formatter) { + public LongFieldController(Option<Long> option, long min, long max, Function<Long, Component> formatter) { super(option, formatter); this.min = min; this.max = max; @@ -46,7 +46,7 @@ public class LongFieldController extends NumberFieldController<Long> { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public LongFieldController(Option<Long> option, Function<Long, Text> formatter) { + public LongFieldController(Option<Long> option, Function<Long, Component> formatter) { this(option, -Long.MAX_VALUE, Long.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java index bf0354a..4240849 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java @@ -7,8 +7,8 @@ import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.slider.ISliderController; import dev.isxander.yacl.gui.controllers.string.IStringController; import dev.isxander.yacl.gui.controllers.string.StringControllerElement; -import net.minecraft.text.Text; -import net.minecraft.util.math.MathHelper; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; import java.text.DecimalFormatSymbols; import java.util.function.Function; @@ -20,9 +20,9 @@ import java.util.function.Function; */ public abstract class NumberFieldController<T extends Number> implements ISliderController<T>, IStringController<T> { private final Option<T> option; - private final Function<T, Text> displayFormatter; + private final Function<T, Component> displayFormatter; - public NumberFieldController(Option<T> option, Function<T, Text> displayFormatter) { + public NumberFieldController(Option<T> option, Function<T, Component> displayFormatter) { this.option = option; this.displayFormatter = displayFormatter; } @@ -35,7 +35,7 @@ public abstract class NumberFieldController<T extends Number> implements ISlider @Override public void setFromString(String value) { if (value.isEmpty() || value.equals(".") || value.equals("-")) value = "0"; - setPendingValue(MathHelper.clamp(Double.parseDouble(cleanupNumberString(value)), min(), max())); + setPendingValue(Mth.clamp(Double.parseDouble(cleanupNumberString(value)), min(), max())); } @Override @@ -49,7 +49,7 @@ public abstract class NumberFieldController<T extends Number> implements ISlider } @Override - public Text formatValue() { + public Component formatValue() { return displayFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java b/src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java index b1f0148..aa8bbaa 100644 --- a/src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java +++ b/src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java @@ -1,32 +1,32 @@ package dev.isxander.yacl.gui.utils; +import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.util.Window; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Language; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.locale.Language; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; public class GuiUtils { - public static MutableText translatableFallback(String key, Text fallback) { - if (Language.getInstance().hasTranslation(key)) - return Text.translatable(key); + public static MutableComponent translatableFallback(String key, Component fallback) { + if (Language.getInstance().has(key)) + return Component.translatable(key); return fallback.copy(); } public static void enableScissor(int x, int y, int width, int height) { - Window window = MinecraftClient.getInstance().getWindow(); - double d = window.getScaleFactor(); - RenderSystem.enableScissor((int)(x * d), (int)((window.getScaledHeight() - y - height) * d), (int)(width * d), (int)(height * d)); + Window window = Minecraft.getInstance().getWindow(); + double d = window.getGuiScale(); + RenderSystem.enableScissor((int)(x * d), (int)((window.getGuiScaledHeight() - y - height) * d), (int)(width * d), (int)(height * d)); } - public static String shortenString(String string, TextRenderer textRenderer, int maxWidth, String suffix) { + public static String shortenString(String string, Font font, int maxWidth, String suffix) { if (string.isEmpty()) return string; boolean firstIter = true; - while (textRenderer.getWidth(string) > maxWidth) { + while (font.width(string) > maxWidth) { string = string.substring(0, Math.max(string.length() - 1 - (firstIter ? 1 : suffix.length() + 1), 0)).trim(); string += suffix; diff --git a/src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java b/src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java index 25260c4..33cb474 100644 --- a/src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java @@ -3,8 +3,8 @@ package dev.isxander.yacl.impl; import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.api.*; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -18,16 +18,16 @@ import java.util.function.Function; @ApiStatus.Internal public final class ButtonOptionImpl implements ButtonOption { - private final Text name; - private final Text tooltip; + private final Component name; + private final Component tooltip; private final BiConsumer<YACLScreen, ButtonOption> action; private boolean available; private final Controller<BiConsumer<YACLScreen, ButtonOption>> controller; private final Binding<BiConsumer<YACLScreen, ButtonOption>> binding; public ButtonOptionImpl( - @NotNull Text name, - @Nullable Text tooltip, + @NotNull Component name, + @Nullable Component tooltip, @NotNull BiConsumer<YACLScreen, ButtonOption> action, boolean available, @NotNull Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> controlGetter @@ -41,12 +41,12 @@ public final class ButtonOptionImpl implements ButtonOption { } @Override - public @NotNull Text name() { + public @NotNull Component name() { return name; } @Override - public @NotNull Text tooltip() { + public @NotNull Component tooltip() { return tooltip; } @@ -144,14 +144,14 @@ public final class ButtonOptionImpl implements ButtonOption { @ApiStatus.Internal public static final class BuilderImpl implements ButtonOption.Builder { - private Text name; - private final List<Text> tooltipLines = new ArrayList<>(); + private Component name; + private final List<Component> tooltipLines = new ArrayList<>(); private boolean available = true; private Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> controlGetter; private BiConsumer<YACLScreen, ButtonOption> action; @Override - public ButtonOption.Builder name(@NotNull Text name) { + public ButtonOption.Builder name(@NotNull Component name) { Validate.notNull(name, "`name` cannot be null"); this.name = name; @@ -159,7 +159,7 @@ public final class ButtonOptionImpl implements ButtonOption { } @Override - public ButtonOption.Builder tooltip(@NotNull Text... tooltips) { + public ButtonOption.Builder tooltip(@NotNull Component... tooltips) { Validate.notNull(tooltips, "`tooltips` cannot be empty"); tooltipLines.addAll(List.of(tooltips)); @@ -203,9 +203,9 @@ public final class ButtonOptionImpl implements ButtonOption { Validate.notNull(controlGetter, "`control` must not be null when building `Option`"); Validate.notNull(action, "`action` must not be null when building `Option`"); - MutableText concatenatedTooltip = Text.empty(); + MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; - for (Text line : tooltipLines) { + for (Component line : tooltipLines) { if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java index 6879e17..efbd8c9 100644 --- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java @@ -6,8 +6,8 @@ import dev.isxander.yacl.api.ListOption; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionGroup; import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -18,18 +18,18 @@ import java.util.List; @ApiStatus.Internal public final class ConfigCategoryImpl implements ConfigCategory { - private final Text name; + private final Component name; private final ImmutableList<OptionGroup> groups; - private final Text tooltip; + private final Component tooltip; - public ConfigCategoryImpl(Text name, ImmutableList<OptionGroup> groups, Text tooltip) { + public ConfigCategoryImpl(Component name, ImmutableList<OptionGroup> groups, Component tooltip) { this.name = name; this.groups = groups; this.tooltip = tooltip; } @Override - public @NotNull Text name() { + public @NotNull Component name() { return name; } @@ -39,21 +39,21 @@ public final class ConfigCategoryImpl implements ConfigCategory { } @Override - public @NotNull Text tooltip() { + public @NotNull Component tooltip() { return tooltip; } @ApiStatus.Internal public static final class BuilderImpl implements Builder { - private Text name; + private Component name; private final List<Option<?>> rootOptions = new ArrayList<>(); private final List<OptionGroup> groups = new ArrayList<>(); - private final List<Text> tooltipLines = new ArrayList<>(); + private final List<Component> tooltipLines = new ArrayList<>(); @Override - public Builder name(@NotNull Text name) { + public Builder name(@NotNull Component name) { Validate.notNull(name, "`name` cannot be null"); this.name = name; @@ -101,7 +101,7 @@ public final class ConfigCategoryImpl implements ConfigCategory { } @Override - public Builder tooltip(@NotNull Text... tooltips) { + public Builder tooltip(@NotNull Component... tooltips) { Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); tooltipLines.addAll(List.of(tooltips)); @@ -113,14 +113,14 @@ public final class ConfigCategoryImpl implements ConfigCategory { Validate.notNull(name, "`name` must not be null to build `ConfigCategory`"); List<OptionGroup> combinedGroups = new ArrayList<>(); - combinedGroups.add(new OptionGroupImpl(Text.empty(), Text.empty(), ImmutableList.copyOf(rootOptions), false, true)); + combinedGroups.add(new OptionGroupImpl(Component.empty(), Component.empty(), ImmutableList.copyOf(rootOptions), false, true)); combinedGroups.addAll(groups); Validate.notEmpty(combinedGroups, "at least one option must be added to build `ConfigCategory`"); - MutableText concatenatedTooltip = Text.empty(); + MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; - for (Text line : tooltipLines) { + for (Component line : tooltipLines) { if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java b/src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java index a816b82..b6c3c09 100644 --- a/src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java @@ -3,8 +3,8 @@ package dev.isxander.yacl.impl; import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.api.*; import dev.isxander.yacl.gui.controllers.LabelController; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -17,40 +17,40 @@ import java.util.function.BiConsumer; @ApiStatus.Internal public final class LabelOptionImpl implements LabelOption { - private final Text label; - private final Text name = Text.literal("Label Option"); - private final Text tooltip = Text.empty(); + private final Component label; + private final Component name = Component.literal("Label Option"); + private final Component tooltip = Component.empty(); private final LabelController labelController; - private final Binding<Text> binding; + private final Binding<Component> binding; - public LabelOptionImpl(Text label) { + public LabelOptionImpl(Component label) { this.label = label; this.labelController = new LabelController(this); this.binding = Binding.immutable(label); } @Override - public @NotNull Text label() { + public @NotNull Component label() { return label; } @Override - public @NotNull Text name() { + public @NotNull Component name() { return name; } @Override - public @NotNull Text tooltip() { + public @NotNull Component tooltip() { return tooltip; } @Override - public @NotNull Controller<Text> controller() { + public @NotNull Controller<Component> controller() { return labelController; } @Override - public @NotNull Binding<Text> binding() { + public @NotNull Binding<Component> binding() { return binding; } @@ -65,8 +65,8 @@ public final class LabelOptionImpl implements LabelOption { } @Override - public @NotNull Class<Text> typeClass() { - return Text.class; + public @NotNull Class<Component> typeClass() { + return Component.class; } @Override @@ -80,12 +80,12 @@ public final class LabelOptionImpl implements LabelOption { } @Override - public @NotNull Text pendingValue() { + public @NotNull Component pendingValue() { return label; } @Override - public void requestSet(Text value) { + public void requestSet(Component value) { } @@ -115,16 +115,16 @@ public final class LabelOptionImpl implements LabelOption { } @Override - public void addListener(BiConsumer<Option<Text>, Text> changedListener) { + public void addListener(BiConsumer<Option<Component>, Component> changedListener) { } @ApiStatus.Internal public static final class BuilderImpl implements LabelOption.Builder { - private final List<Text> lines = new ArrayList<>(); + private final List<Component> lines = new ArrayList<>(); @Override - public Builder line(@NotNull Text line) { + public dev.isxander.yacl.api.LabelOption.Builder line(@NotNull Component line) { Validate.notNull(line, "`line` must not be null"); this.lines.add(line); @@ -132,15 +132,15 @@ public final class LabelOptionImpl implements LabelOption { } @Override - public Builder lines(@NotNull Collection<? extends Text> lines) { + public dev.isxander.yacl.api.LabelOption.Builder lines(@NotNull Collection<? extends Component> lines) { this.lines.addAll(lines); return this; } @Override public LabelOption build() { - MutableText text = Text.empty(); - Iterator<Text> iterator = lines.iterator(); + MutableComponent text = Component.empty(); + Iterator<Component> iterator = lines.iterator(); while (iterator.hasNext()) { text.append(iterator.next()); diff --git a/src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java b/src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java index 98188dc..c15efe6 100644 --- a/src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java @@ -5,7 +5,7 @@ import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ListEntryWidget; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -29,13 +29,13 @@ public final class ListOptionEntryImpl<T> implements ListOptionEntry<T> { } @Override - public @NotNull Text name() { - return Text.empty(); + public @NotNull Component name() { + return Component.empty(); } @Override - public @NotNull Text tooltip() { - return Text.empty(); + public @NotNull Component tooltip() { + return Component.empty(); } @Override @@ -119,7 +119,7 @@ public final class ListOptionEntryImpl<T> implements ListOptionEntry<T> { } @Override - public Text formatValue() { + public Component formatValue() { return controller.formatValue(); } diff --git a/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java b/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java index fb74601..e7230b0 100644 --- a/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java @@ -3,8 +3,8 @@ package dev.isxander.yacl.impl; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.api.*; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -18,8 +18,8 @@ import java.util.stream.Collectors; @ApiStatus.Internal public final class ListOptionImpl<T> implements ListOption<T> { - private final Text name; - private final Text tooltip; + private final Component name; + private final Component tooltip; private final Binding<List<T>> binding; private final T initialValue; private final List<ListOptionEntry<T>> entries; @@ -31,7 +31,7 @@ public final class ListOptionImpl<T> implements ListOption<T> { private final List<BiConsumer<Option<List<T>>, List<T>>> listeners; private final List<Runnable> refreshListeners; - public ListOptionImpl(@NotNull Text name, @NotNull Text tooltip, @NotNull Binding<List<T>> binding, @NotNull T initialValue, @NotNull Class<T> typeClass, @NotNull Function<ListOptionEntry<T>, Controller<T>> controllerFunction, ImmutableSet<OptionFlag> flags, boolean collapsed, boolean available) { + public ListOptionImpl(@NotNull Component name, @NotNull Component tooltip, @NotNull Binding<List<T>> binding, @NotNull T initialValue, @NotNull Class<T> typeClass, @NotNull Function<ListOptionEntry<T>, Controller<T>> controllerFunction, ImmutableSet<OptionFlag> flags, boolean collapsed, boolean available) { this.name = name; this.tooltip = tooltip; this.binding = binding; @@ -48,12 +48,12 @@ public final class ListOptionImpl<T> implements ListOption<T> { } @Override - public @NotNull Text name() { + public @NotNull Component name() { return this.name; } @Override - public @NotNull Text tooltip() { + public @NotNull Component tooltip() { return this.tooltip; } @@ -211,8 +211,8 @@ public final class ListOptionImpl<T> implements ListOption<T> { @ApiStatus.Internal public static final class BuilderImpl<T> implements ListOption.Builder<T> { - private Text name = Text.empty(); - private final List<Text> tooltipLines = new ArrayList<>(); + private Component name = Component.empty(); + private final List<Component> tooltipLines = new ArrayList<>(); private Function<ListOptionEntry<T>, Controller<T>> controllerFunction; private Binding<List<T>> binding = null; private final Set<OptionFlag> flags = new HashSet<>(); @@ -226,7 +226,7 @@ public final class ListOptionImpl<T> implements ListOption<T> { } @Override - public ListOption.Builder<T> name(@NotNull Text name) { + public ListOption.Builder<T> name(@NotNull Component name) { Validate.notNull(name, "`name` must not be null"); this.name = name; @@ -234,7 +234,7 @@ public final class ListOptionImpl<T> implements ListOption<T> { } @Override - public ListOption.Builder<T> tooltip(@NotNull Text... tooltips) { + public ListOption.Builder<T> tooltip(@NotNull Component... tooltips) { Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); tooltipLines.addAll(List.of(tooltips)); @@ -309,9 +309,9 @@ public final class ListOptionImpl<T> implements ListOption<T> { Validate.notNull(binding, "`binding` must not be null"); Validate.notNull(initialValue, "`initialValue` must not be null"); - MutableText concatenatedTooltip = Text.empty(); + MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; - for (Text line : tooltipLines) { + for (Component line : tooltipLines) { if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java index 1612a7e..0f883d9 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java @@ -4,8 +4,8 @@ import com.google.common.collect.ImmutableList; import dev.isxander.yacl.api.ListOption; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionGroup; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -16,13 +16,13 @@ import java.util.List; @ApiStatus.Internal public final class OptionGroupImpl implements OptionGroup { - private final @NotNull Text name; - private final @NotNull Text tooltip; + private final @NotNull Component name; + private final @NotNull Component tooltip; private final ImmutableList<? extends Option<?>> options; private final boolean collapsed; private final boolean isRoot; - public OptionGroupImpl(@NotNull Text name, @NotNull Text tooltip, ImmutableList<? extends Option<?>> options, boolean collapsed, boolean isRoot) { + public OptionGroupImpl(@NotNull Component name, @NotNull Component tooltip, ImmutableList<? extends Option<?>> options, boolean collapsed, boolean isRoot) { this.name = name; this.tooltip = tooltip; this.options = options; @@ -31,12 +31,12 @@ public final class OptionGroupImpl implements OptionGroup { } @Override - public @NotNull Text name() { + public @NotNull Component name() { return name; } @Override - public @NotNull Text tooltip() { + public @NotNull Component tooltip() { return tooltip; } @@ -57,13 +57,13 @@ public final class OptionGroupImpl implements OptionGroup { @ApiStatus.Internal public static final class BuilderImpl implements OptionGroup.Builder { - private Text name = Text.empty(); - private final List<Text> tooltipLines = new ArrayList<>(); + private Component name = Component.empty(); + private final List<Component> tooltipLines = new ArrayList<>(); private final List<Option<?>> options = new ArrayList<>(); private boolean collapsed = false; @Override - public Builder name(@NotNull Text name) { + public Builder name(@NotNull Component name) { Validate.notNull(name, "`name` must not be null"); this.name = name; @@ -71,7 +71,7 @@ public final class OptionGroupImpl implements OptionGroup { } @Override - public Builder tooltip(@NotNull Text... tooltips) { + public Builder tooltip(@NotNull Component... tooltips) { Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); tooltipLines.addAll(List.of(tooltips)); @@ -110,9 +110,9 @@ public final class OptionGroupImpl implements OptionGroup { public OptionGroup build() { Validate.notEmpty(options, "`options` must not be empty to build `OptionGroup`"); - MutableText concatenatedTooltip = Text.empty(); + MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; - for (Text line : tooltipLines) { + for (Component line : tooltipLines) { if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java index d2815e1..d333e36 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java @@ -5,9 +5,9 @@ import dev.isxander.yacl.api.Binding; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.OptionFlag; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -22,8 +22,8 @@ import java.util.stream.Stream; @ApiStatus.Internal public final class OptionImpl<T> implements Option<T> { - private final Text name; - private Text tooltip; + private final Component name; + private Component tooltip; private final Controller<T> controller; private final Binding<T> binding; private boolean available; @@ -37,8 +37,8 @@ public final class OptionImpl<T> implements Option<T> { private final List<BiConsumer<Option<T>, T>> listeners; public OptionImpl( - @NotNull Text name, - @Nullable Function<T, Text> tooltipGetter, + @NotNull Component name, + @Nullable Function<T, Component> tooltipGetter, @NotNull Function<Option<T>, Controller<T>> controlGetter, @NotNull Binding<T> binding, boolean available, @@ -59,12 +59,12 @@ public final class OptionImpl<T> implements Option<T> { } @Override - public @NotNull Text name() { + public @NotNull Component name() { return name; } @Override - public @NotNull Text tooltip() { + public @NotNull Component tooltip() { return tooltip; } @@ -145,9 +145,9 @@ public final class OptionImpl<T> implements Option<T> { @ApiStatus.Internal public static class BuilderImpl<T> implements Option.Builder<T> { - private Text name = Text.literal("Name not specified!").formatted(Formatting.RED); + private Component name = Component.literal("Name not specified!").withStyle(ChatFormatting.RED); - private final List<Function<T, Text>> tooltipGetters = new ArrayList<>(); + private final List<Function<T, Component>> tooltipGetters = new ArrayList<>(); private Function<Option<T>, Controller<T>> controlGetter; @@ -168,7 +168,7 @@ public final class OptionImpl<T> implements Option<T> { } @Override - public Option.Builder<T> name(@NotNull Text name) { + public Option.Builder<T> name(@NotNull Component name) { Validate.notNull(name, "`name` cannot be null"); this.name = name; @@ -177,7 +177,7 @@ public final class OptionImpl<T> implements Option<T> { @Override @SafeVarargs - public final Option.Builder<T> tooltip(@NotNull Function<T, Text>... tooltipGetter) { + public final Option.Builder<T> tooltip(@NotNull Function<T, Component>... tooltipGetter) { Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); this.tooltipGetters.addAll(List.of(tooltipGetter)); @@ -185,10 +185,10 @@ public final class OptionImpl<T> implements Option<T> { } @Override - public Option.Builder<T> tooltip(@NotNull Text... tooltips) { + public Option.Builder<T> tooltip(@NotNull Component... tooltips) { Validate.notNull(tooltips, "`tooltips` cannot be empty"); - this.tooltipGetters.addAll(Stream.of(tooltips).map(text -> (Function<T, Text>) t -> text).toList()); + this.tooltipGetters.addAll(Stream.of(tooltips).map(Component -> (Function<T, Component>) t -> Component).toList()); return this; } @@ -264,10 +264,10 @@ public final class OptionImpl<T> implements Option<T> { Validate.notNull(binding, "`binding` must not be null when building `Option`"); Validate.isTrue(!instant || flags.isEmpty(), "instant application does not support option flags"); - Function<T, Text> concatenatedTooltipGetter = value -> { - MutableText concatenatedTooltip = Text.empty(); + Function<T, Component> concatenatedTooltipGetter = value -> { + MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; - for (Function<T, Text> line : tooltipGetters) { + for (Function<T, Component> line : tooltipGetters) { if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java index 738b9e2..0b77466 100644 --- a/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java @@ -1,14 +1,13 @@ package dev.isxander.yacl.impl; import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.api.ConfigCategory; import dev.isxander.yacl.api.OptionGroup; import dev.isxander.yacl.api.PlaceholderCategory; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -19,11 +18,11 @@ import java.util.function.BiFunction; @ApiStatus.Internal public final class PlaceholderCategoryImpl implements PlaceholderCategory { - private final Text name; - private final BiFunction<MinecraftClient, YACLScreen, Screen> screen; - private final Text tooltip; + private final Component name; + private final BiFunction<Minecraft, YACLScreen, Screen> screen; + private final Component tooltip; - public PlaceholderCategoryImpl(Text name, BiFunction<MinecraftClient, YACLScreen, Screen> screen, Text tooltip) { + public PlaceholderCategoryImpl(Component name, BiFunction<Minecraft, YACLScreen, Screen> screen, Component tooltip) { this.name = name; this.screen = screen; this.tooltip = tooltip; @@ -35,30 +34,30 @@ public final class PlaceholderCategoryImpl implements PlaceholderCategory { } @Override - public @NotNull Text name() { + public @NotNull Component name() { return name; } @Override - public BiFunction<MinecraftClient, YACLScreen, Screen> screen() { + public BiFunction<Minecraft, YACLScreen, Screen> screen() { return screen; } @Override - public @NotNull Text tooltip() { + public @NotNull Component tooltip() { return tooltip; } @ApiStatus.Internal public static final class BuilderImpl implements PlaceholderCategory.Builder { - private Text name; + private Component name; - private final List<Text> tooltipLines = new ArrayList<>(); + private final List<Component> tooltipLines = new ArrayList<>(); - private BiFunction<MinecraftClient, YACLScreen, Screen> screenFunction; + private BiFunction<Minecraft, YACLScreen, Screen> screenFunction; @Override - public Builder name(@NotNull Text name) { + public Builder name(@NotNull Component name) { Validate.notNull(name, "`name` cannot be null"); this.name = name; @@ -66,7 +65,7 @@ public final class PlaceholderCategoryImpl implements PlaceholderCategory { } @Override - public Builder tooltip(@NotNull Text... tooltips) { + public Builder tooltip(@NotNull Component... tooltips) { Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); tooltipLines.addAll(List.of(tooltips)); @@ -74,7 +73,7 @@ public final class PlaceholderCategoryImpl implements PlaceholderCategory { } @Override - public Builder screen(@NotNull BiFunction<MinecraftClient, YACLScreen, Screen> screenFunction) { + public Builder screen(@NotNull BiFunction<Minecraft, YACLScreen, Screen> screenFunction) { Validate.notNull(screenFunction, "`screenFunction` cannot be null"); this.screenFunction = screenFunction; @@ -85,9 +84,9 @@ public final class PlaceholderCategoryImpl implements PlaceholderCategory { public PlaceholderCategory build() { Validate.notNull(name, "`name` must not be null to build `ConfigCategory`"); - MutableText concatenatedTooltip = Text.empty(); + MutableComponent concatenatedTooltip = Component.empty(); boolean first = true; - for (Text line : tooltipLines) { + for (Component line : tooltipLines) { if (!first) concatenatedTooltip.append("\n"); first = false; diff --git a/src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java b/src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java index 576c1bf..21c776a 100644 --- a/src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java @@ -6,8 +6,8 @@ import dev.isxander.yacl.api.PlaceholderCategory; import dev.isxander.yacl.api.YetAnotherConfigLib; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -15,19 +15,18 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Objects; import java.util.function.Consumer; @ApiStatus.Internal public final class YetAnotherConfigLibImpl implements YetAnotherConfigLib { - private final Text title; + private final Component title; private final ImmutableList<ConfigCategory> categories; private final Runnable saveFunction; private final Consumer<YACLScreen> initConsumer; private boolean generated = false; - public YetAnotherConfigLibImpl(Text title, ImmutableList<ConfigCategory> categories, Runnable saveFunction, Consumer<YACLScreen> initConsumer) { + public YetAnotherConfigLibImpl(Component title, ImmutableList<ConfigCategory> categories, Runnable saveFunction, Consumer<YACLScreen> initConsumer) { this.title = title; this.categories = categories; this.saveFunction = saveFunction; @@ -45,7 +44,7 @@ public final class YetAnotherConfigLibImpl implements YetAnotherConfigLib { } @Override - public Text title() { + public Component title() { return title; } @@ -66,13 +65,13 @@ public final class YetAnotherConfigLibImpl implements YetAnotherConfigLib { @ApiStatus.Internal public static final class BuilderImpl implements YetAnotherConfigLib.Builder { - private Text title; + private Component title; private final List<ConfigCategory> categories = new ArrayList<>(); private Runnable saveFunction = () -> {}; private Consumer<YACLScreen> initConsumer = screen -> {}; @Override - public YetAnotherConfigLib.Builder title(@NotNull Text title) { + public YetAnotherConfigLib.Builder title(@NotNull Component title) { Validate.notNull(title, "`title` cannot be null"); this.title = title; diff --git a/src/client/java/dev/isxander/yacl/mixin/client/SimpleOptionAccessor.java b/src/client/java/dev/isxander/yacl/mixin/client/OptionInstanceAccessor.java index 4333f37..b8df39f 100644 --- a/src/client/java/dev/isxander/yacl/mixin/client/SimpleOptionAccessor.java +++ b/src/client/java/dev/isxander/yacl/mixin/client/OptionInstanceAccessor.java @@ -1,13 +1,13 @@ package dev.isxander.yacl.mixin.client; -import net.minecraft.client.option.SimpleOption; +import net.minecraft.client.OptionInstance; import org.jetbrains.annotations.ApiStatus; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @ApiStatus.Internal -@Mixin(SimpleOption.class) -public interface SimpleOptionAccessor<T> { +@Mixin(OptionInstance.class) +public interface OptionInstanceAccessor<T> { @Accessor - T getDefaultValue(); + T getInitialValue(); } diff --git a/src/client/resources/yet-another-config-lib.client.mixins.json b/src/client/resources/yet-another-config-lib.client.mixins.json index 2367a67..6aeab10 100644 --- a/src/client/resources/yet-another-config-lib.client.mixins.json +++ b/src/client/resources/yet-another-config-lib.client.mixins.json @@ -6,6 +6,6 @@ "defaultRequire": 1 }, "client": [ - "SimpleOptionAccessor" + "OptionInstanceAccessor" ] } diff --git a/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java b/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java index 40c2c99..c607606 100644 --- a/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java +++ b/src/main/java/dev/isxander/yacl/config/GsonConfigInstance.java @@ -2,8 +2,8 @@ package dev.isxander.yacl.config; import com.google.gson.*; import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; import java.awt.*; import java.io.IOException; @@ -17,7 +17,7 @@ import java.util.function.UnaryOperator; * Uses GSON to serialize and deserialize config data from JSON to a file. * * Only fields annotated with {@link ConfigEntry} are included in the JSON. - * {@link Text}, {@link Style} and {@link Color} have default type adapters, so there is no need to provide them in your GSON instance. + * {@link Component}, {@link Style} and {@link Color} have default type adapters, so there is no need to provide them in your GSON instance. * GSON is automatically configured to format fields as {@code lower_camel_case}. * * @param <T> config data type @@ -43,7 +43,7 @@ public class GsonConfigInstance<T> extends ConfigInstance<T> { this.path = path; this.gson = builder .setExclusionStrategies(new ConfigExclusionStrategy()) - .registerTypeHierarchyAdapter(Text.class, new Text.Serializer()) + .registerTypeHierarchyAdapter(Component.class, new Component.Serializer()) .registerTypeHierarchyAdapter(Style.class, new Style.Serializer()) .registerTypeHierarchyAdapter(Color.class, new ColorTypeAdapter()) .serializeNulls() diff --git a/src/main/java/dev/isxander/yacl/config/NbtConfigInstance.java b/src/main/java/dev/isxander/yacl/config/NbtConfigInstance.java deleted file mode 100644 index 784f58f..0000000 --- a/src/main/java/dev/isxander/yacl/config/NbtConfigInstance.java +++ /dev/null @@ -1,276 +0,0 @@ -package dev.isxander.yacl.config; - -import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.nbt.*; - -import java.awt.*; -import java.io.DataOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.lang.reflect.*; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.*; -import java.util.List; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; - -/** - * Uses {@link net.minecraft.nbt} to serialize and deserialize to and from an NBT file. - * Data can be written as compressed GZIP or uncompressed NBT. - * - * You can optionally provide custom implementations for handling certain classes if the default - * handling fails with {@link NbtSerializer} - * - * @param <T> config data type - * @deprecated Using NBT for config is not very practical, implementation flawed, does not support upcoming lists. - */ -@Deprecated -@SuppressWarnings("unchecked") -public class NbtConfigInstance<T> extends ConfigInstance<T> { - private final Path path; - private final boolean compressed; - private final NbtSerializerHolder nbtSerializerHolder; - - /** - * Constructs an instance with compression on - * - * @param configClass config data type class - * @param path file to write nbt to - */ - public NbtConfigInstance(Class<T> configClass, Path path) { - this(configClass, path, holder -> holder, true); - } - - /** - * @param configClass config data type class - * @param path file to write nbt to - * @param serializerHolderBuilder allows you to add custom serializers - * @param compressed whether to compress the NBT - */ - public NbtConfigInstance(Class<T> configClass, Path path, UnaryOperator<NbtSerializerHolder> serializerHolderBuilder, boolean compressed) { - super(configClass); - this.path = path; - this.compressed = compressed; - this.nbtSerializerHolder = serializerHolderBuilder.apply(new NbtSerializerHolder()); - } - - @Override - public void save() { - YACLConstants.LOGGER.info("Saving {}...", getConfigClass().getSimpleName()); - - NbtCompound nbt; - try { - nbt = (NbtCompound) serializeObject(getConfig(), nbtSerializerHolder, field -> field.isAnnotationPresent(ConfigEntry.class)); - } catch (IllegalAccessException e) { - YACLConstants.LOGGER.error("Failed to convert '{}' -> NBT", getConfigClass().getName(), e); - return; - } - - try(FileOutputStream fos = new FileOutputStream(path.toFile())) { - if (Files.notExists(path)) - Files.createFile(path); - - if (compressed) - NbtIo.writeCompressed(nbt, fos); - else - NbtIo.write(nbt, new DataOutputStream(fos)); - } catch (IOException e) { - YACLConstants.LOGGER.error("Failed to write NBT to '{}'", path, e); - } - } - - @Override - public void load() { - if (Files.notExists(path)) { - save(); - return; - } - - YACLConstants.LOGGER.info("Loading {}...", getConfigClass().getSimpleName()); - NbtCompound nbt; - try { - nbt = compressed ? NbtIo.readCompressed(path.toFile()) : NbtIo.read(path.toFile()); - } catch (IOException e) { - YACLConstants.LOGGER.error("Failed to read NBT file '{}'", path, e); - return; - } - - try { - setConfig(deserializeObject(nbt, getConfigClass(), nbtSerializerHolder, field -> field.isAnnotationPresent(ConfigEntry.class))); - } catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException e) { - YACLConstants.LOGGER.error("Failed to convert NBT -> '{}'", getConfigClass().getName(), e); - } - } - - public Path getPath() { - return this.path; - } - - public boolean isUsingCompression() { - return this.compressed; - } - - private static NbtElement serializeObject(Object object, NbtSerializerHolder serializerHolder, Predicate<Field> topLevelPredicate) throws IllegalAccessException { - if (serializerHolder.hasSerializer(object.getClass())) { - return serializerHolder.serialize(object); - } - else if (object instanceof Object[] ol) { - NbtList nbtList = new NbtList(); - for (Object obj : ol) - nbtList.add(serializeObject(obj, serializerHolder, field -> true)); - return nbtList; - } else { - NbtCompound compound = new NbtCompound(); - Field[] fields = object.getClass().getDeclaredFields(); - for (Field field : fields) { - if (Modifier.isStatic(field.getModifiers()) || !topLevelPredicate.test(field)) - continue; - - System.out.println(field.getName()); - field.setAccessible(true); - - String key = toCamelCase(field.getName()); - NbtElement value = serializeObject(field.get(object), serializerHolder, f -> true); - compound.put(key, value); - } - - return compound; - } - } - - private static <T> T deserializeObject(NbtElement element, Class<T> type, NbtSerializerHolder serializerHolder, Predicate<Field> topLevelPredicate) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { - if (serializerHolder.hasSerializer(type)) - return serializerHolder.get(type).deserialize(element, type); - else if (type == Array.class) { - List<Object> list = new ArrayList<>(); - - Class<?> arrayType = Array.newInstance(type.getComponentType(), 0).getClass(); - NbtList nbtList = (NbtList) element; - for (NbtElement nbtElement : nbtList) { - list.add(deserializeObject(nbtElement, arrayType, serializerHolder, field -> true)); - } - - return (T) list.toArray(); - } else { - if (!(element instanceof NbtCompound compound)) - throw new IllegalStateException("Cannot deserialize " + type.getName()); - - T object = type.getConstructor().newInstance(); - Field[] fields = type.getDeclaredFields(); - for (Field field : fields) { - if (Modifier.isStatic(field.getModifiers()) || !topLevelPredicate.test(field)) - continue; - - field.setAccessible(true); - String key = toCamelCase(field.getName()); - if (!compound.contains(key)) - continue; - field.set(object, deserializeObject(compound.get(key), field.getType(), serializerHolder, f -> true)); - } - - return object; - } - } - - /* shamelessly stolen from gson */ - private static String toCamelCase(String name) { - StringBuilder translation = new StringBuilder(); - for (int i = 0, length = name.length(); i < length; i++) { - char character = name.charAt(i); - if (Character.isUpperCase(character) && translation.length() != 0) { - translation.append('_'); - } - translation.append(character); - } - return translation.toString().toLowerCase(Locale.ENGLISH); - } - - public static class NbtSerializerHolder { - private final Map<Class<?>, NbtSerializer<?>> serializerMap = new HashMap<>(); - - private NbtSerializerHolder() { - register(boolean.class, NbtSerializer.<Boolean, NbtByte>simple(b -> b ? NbtByte.ONE : NbtByte.ZERO, nbt -> nbt.byteValue() != 0)); - register(Boolean.class, NbtSerializer.<Boolean, NbtByte>simple(b -> b ? NbtByte.ONE : NbtByte.ZERO, nbt -> nbt.byteValue() != 0)); - register(int.class, NbtSerializer.simple(NbtInt::of, NbtInt::intValue)); - register(Integer.class, NbtSerializer.simple(NbtInt::of, NbtInt::intValue));register(int[].class, NbtSerializer.simple(NbtIntArray::new, NbtIntArray::getIntArray)); - register(float.class, NbtSerializer.simple(NbtFloat::of, NbtFloat::floatValue)); - register(Float.class, NbtSerializer.simple(NbtFloat::of, NbtFloat::floatValue)); - register(double.class, NbtSerializer.simple(NbtDouble::of, NbtDouble::doubleValue)); - register(Double.class, NbtSerializer.simple(NbtDouble::of, NbtDouble::doubleValue)); - register(short.class, NbtSerializer.simple(NbtShort::of, NbtShort::shortValue)); - register(Short.class, NbtSerializer.simple(NbtShort::of, NbtShort::shortValue)); - register(byte.class, NbtSerializer.simple(NbtByte::of, NbtByte::byteValue)); - register(Byte.class, NbtSerializer.simple(NbtByte::of, NbtByte::byteValue)); - register(byte[].class, NbtSerializer.simple(NbtByteArray::new, NbtByteArray::getByteArray)); - register(long.class, NbtSerializer.simple(NbtLong::of, NbtLong::longValue)); - register(Long.class, NbtSerializer.simple(NbtLong::of, NbtLong::longValue)); - register(long[].class, NbtSerializer.simple(NbtLongArray::new, NbtLongArray::getLongArray)); - register(String.class, NbtSerializer.simple(NbtString::of, NbtString::asString)); - register(Enum.class, NbtSerializer.simple(e -> NbtString.of(e.name()), (nbt, type) -> Arrays.stream(type.getEnumConstants()).filter(e -> e.name().equals(nbt.asString())).findFirst().orElseThrow())); - - register(Color.class, new ColorSerializer()); - } - - public <T> NbtSerializerHolder register(Class<T> clazz, NbtSerializer<T> serializer) { - serializerMap.put(clazz, serializer); - return this; - } - - public <T> NbtSerializer<T> get(Class<T> clazz) { - return (NbtSerializer<T>) search(clazz).findFirst().orElseThrow().getValue(); - } - - public boolean hasSerializer(Class<?> clazz) { - return search(clazz).findAny().isPresent(); - } - - public NbtElement serialize(Object object) { - return ((NbtSerializer<Object>) get(object.getClass())).serialize(object); - } - - private Stream<Map.Entry<Class<?>, NbtSerializer<?>>> search(Class<?> type) { - return serializerMap.entrySet().stream().filter(entry -> entry.getKey().isAssignableFrom(type)); - } - } - - public interface NbtSerializer<T> { - NbtElement serialize(T object); - - T deserialize(NbtElement element, Class<T> type); - - static <T, U extends NbtElement> NbtSerializer<T> simple(Function<T, U> serializer, Function<U, T> deserializer) { - return simple(serializer, (nbt, type) -> deserializer.apply(nbt)); - } - - static <T, U extends NbtElement> NbtSerializer<T> simple(Function<T, U> serializer, BiFunction<U, Class<T>, T> deserializer) { - return new NbtSerializer<>() { - @Override - public NbtElement serialize(T object) { - return serializer.apply(object); - } - - @Override - public T deserialize(NbtElement element, Class<T> type) { - return deserializer.apply((U) element, type); - } - }; - } - } - - public static class ColorSerializer implements NbtSerializer<Color> { - - @Override - public NbtElement serialize(Color object) { - return NbtInt.of(object.getRGB()); - } - - @Override - public Color deserialize(NbtElement element, Class<Color> type) { - return new Color(((NbtInt) element).intValue(), true); - } - } -} diff --git a/src/main/resources/assets/yet-another-config-lib/lang/ru_ru.json b/src/main/resources/assets/yet-another-config-lib/lang/ru_ru.json index 5a4dfbe..5725d34 100644 --- a/src/main/resources/assets/yet-another-config-lib/lang/ru_ru.json +++ b/src/main/resources/assets/yet-another-config-lib/lang/ru_ru.json @@ -1,24 +1,24 @@ -{
- "yacl.control.boolean.true": "§atrue",
- "yacl.control.boolean.false": "§cfalse",
-
- "yacl.control.action.execute": "Выполнить",
-
- "yacl.gui.save": "Сохранить",
- "yacl.gui.save.tooltip": "Сохранить изменения до следующего редактирования.",
- "yacl.gui.finished.tooltip": "Закрыть меню.",
- "yacl.gui.cancel": "Назад",
- "yacl.gui.cancel.tooltip": "Отменить изменения и закрыть настройки.",
- "yacl.gui.reset.tooltip": "Сбросить все настройки до значений по умолчанию (их можно восстановить).",
- "yacl.gui.undo": "Отменить",
- "yacl.gui.undo.tooltip": "Вернуть все настройки к состоянию, в котором они были до изменений.",
- "yacl.gui.fail_apply": "Не удалось сохранить",
- "yacl.gui.fail_apply.tooltip": "Возникла ошибка; изменения невозможно применить.",
- "yacl.gui.save_before_exit": "Сохраните перед закрытием",
- "yacl.gui.save_before_exit.tooltip": "Сохраните или отмените изменения, чтобы закрыть настройки.",
-
- "yacl.restart.title": "Настройки требуют перезагрузки.",
- "yacl.restart.message": "Одна или несколько настроек требует перезапуска игры для применения изменений.",
- "yacl.restart.yes": "Закрыть Minecraft",
- "yacl.restart.no": "Игнорировать"
-}
+{ + "yacl.control.boolean.true": "§atrue", + "yacl.control.boolean.false": "§cfalse", + + "yacl.control.action.execute": "Выполнить", + + "yacl.gui.save": "Сохранить", + "yacl.gui.save.tooltip": "Сохранить изменения до следующего редактирования.", + "yacl.gui.finished.tooltip": "Закрыть меню.", + "yacl.gui.cancel": "Назад", + "yacl.gui.cancel.tooltip": "Отменить изменения и закрыть настройки.", + "yacl.gui.reset.tooltip": "Сбросить все настройки до значений по умолчанию (их можно восстановить).", + "yacl.gui.undo": "Отменить", + "yacl.gui.undo.tooltip": "Вернуть все настройки к состоянию, в котором они были до изменений.", + "yacl.gui.fail_apply": "Не удалось сохранить", + "yacl.gui.fail_apply.tooltip": "Возникла ошибка; изменения невозможно применить.", + "yacl.gui.save_before_exit": "Сохраните перед закрытием", + "yacl.gui.save_before_exit.tooltip": "Сохраните или отмените изменения, чтобы закрыть настройки.", + + "yacl.restart.title": "Настройки требуют перезагрузки.", + "yacl.restart.message": "Одна или несколько настроек требует перезапуска игры для применения изменений.", + "yacl.restart.yes": "Закрыть Minecraft", + "yacl.restart.no": "Игнорировать" +} diff --git a/src/main/resources/assets/yet-another-config-lib/lang/zh_tw.json b/src/main/resources/assets/yet-another-config-lib/lang/zh_tw.json index 74b3004..67d05a7 100644 --- a/src/main/resources/assets/yet-another-config-lib/lang/zh_tw.json +++ b/src/main/resources/assets/yet-another-config-lib/lang/zh_tw.json @@ -1,23 +1,23 @@ -{
- "yacl.control.boolean.true": "是",
- "yacl.control.boolean.false": "否",
-
- "yacl.control.action.execute": "執行",
-
- "yacl.gui.save": "儲存變更",
- "yacl.gui.save.tooltip": "儲存你的變更。",
- "yacl.gui.finished.tooltip": "關閉介面。",
- "yacl.gui.cancel.tooltip": "取消變更並關閉介面。",
- "yacl.gui.reset.tooltip": "重設所有選項到預設。(這可以復原!)",
- "yacl.gui.undo": "復原",
- "yacl.gui.undo.tooltip": "將所有選項恢復成編輯前的狀態。",
- "yacl.gui.fail_apply": "套用失敗",
- "yacl.gui.fail_apply.tooltip": "發生錯誤,無法套用變更。",
- "yacl.gui.save_before_exit": "在離開時儲存!",
- "yacl.gui.save_before_exit.tooltip": "儲存或是取消並離開介面。",
-
- "yacl.restart.title": "變更設定需要重開遊戲!",
- "yacl.restart.message": "一個或多個選項需要你重開遊戲才能套用變更。",
- "yacl.restart.yes": "關閉 Minecraft",
- "yacl.restart.no": "忽略"
-}
+{ + "yacl.control.boolean.true": "是", + "yacl.control.boolean.false": "否", + + "yacl.control.action.execute": "執行", + + "yacl.gui.save": "儲存變更", + "yacl.gui.save.tooltip": "儲存你的變更。", + "yacl.gui.finished.tooltip": "關閉介面。", + "yacl.gui.cancel.tooltip": "取消變更並關閉介面。", + "yacl.gui.reset.tooltip": "重設所有選項到預設。(這可以復原!)", + "yacl.gui.undo": "復原", + "yacl.gui.undo.tooltip": "將所有選項恢復成編輯前的狀態。", + "yacl.gui.fail_apply": "套用失敗", + "yacl.gui.fail_apply.tooltip": "發生錯誤,無法套用變更。", + "yacl.gui.save_before_exit": "在離開時儲存!", + "yacl.gui.save_before_exit.tooltip": "儲存或是取消並離開介面。", + + "yacl.restart.title": "變更設定需要重開遊戲!", + "yacl.restart.message": "一個或多個選項需要你重開遊戲才能套用變更。", + "yacl.restart.yes": "關閉 Minecraft", + "yacl.restart.no": "忽略" +} diff --git a/src/main/resources/yacl.accesswidener b/src/main/resources/yacl.accesswidener index 5769125..99093ea 100644 --- a/src/main/resources/yacl.accesswidener +++ b/src/main/resources/yacl.accesswidener @@ -1,4 +1,4 @@ accessWidener v1 named -extendable method net/minecraft/client/gui/widget/EntryListWidget children ()Ljava/util/List; -extendable method net/minecraft/client/gui/widget/EntryListWidget getEntryAtPosition (DD)Lnet/minecraft/client/gui/widget/EntryListWidget$Entry; +extendable method net/minecraft/client/gui/components/AbstractSelectionList children ()Ljava/util/List; +extendable method net/minecraft/client/gui/components/AbstractSelectionList getEntryAtPosition (DD)Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry; diff --git a/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java b/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java index 12bae2f..1ab4f1d 100644 --- a/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java +++ b/src/testmod/java/dev/isxander/yacl/test/config/GuiTest.java @@ -13,14 +13,13 @@ import dev.isxander.yacl.gui.controllers.string.number.DoubleFieldController; import dev.isxander.yacl.gui.controllers.string.number.FloatFieldController; import dev.isxander.yacl.gui.controllers.string.number.IntegerFieldController; import dev.isxander.yacl.gui.controllers.string.number.LongFieldController; -import dev.isxander.yacl.test.ExampleMod; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.option.GraphicsMode; -import net.minecraft.client.toast.SystemToast; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.Text; +import net.minecraft.client.GraphicsStatus; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.toasts.SystemToast; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; import java.awt.Color; import java.util.List; @@ -28,20 +27,20 @@ import java.util.List; public class GuiTest { public static Screen getModConfigScreenFactory(Screen parent) { return YetAnotherConfigLib.create(ExampleConfig.INSTANCE, (defaults, config, builder) -> builder - .title(Text.of("Test Suites")) + .title(Component.literal("Test Suites")) .category(ConfigCategory.createBuilder() - .name(Text.of("Suites")) + .name(Component.literal("Suites")) .option(ButtonOption.createBuilder() - .name(Text.of("Full Test Suite")) + .name(Component.literal("Full Test Suite")) .controller(ActionController::new) - .action((screen, opt) -> MinecraftClient.getInstance().setScreen(getFullTestSuite(screen))) + .action((screen, opt) -> Minecraft.getInstance().setScreen(getFullTestSuite(screen))) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("Wiki")) + .name(Component.literal("Wiki")) .option(ButtonOption.createBuilder() - .name(Text.of("Get Started")) + .name(Component.literal("Get Started")) .controller(ActionController::new) - .action((screen, opt) -> MinecraftClient.getInstance().setScreen(getWikiGetStarted(screen))) + .action((screen, opt) -> Minecraft.getInstance().setScreen(getWikiGetStarted(screen))) .build()) .build()) .build()) @@ -51,17 +50,17 @@ public class GuiTest { private static Screen getFullTestSuite(Screen parent) { return YetAnotherConfigLib.create(ExampleConfig.INSTANCE, (defaults, config, builder) -> builder - .title(Text.of("Test GUI")) + .title(Component.literal("Test GUI")) .category(ConfigCategory.createBuilder() - .name(Text.of("Control Examples")) - .tooltip(Text.of("Example Category Description")) + .name(Component.literal("Control Examples")) + .tooltip(Component.literal("Example Category Description")) .group(OptionGroup.createBuilder() - .name(Text.of("Boolean Controllers")) - .tooltip(Text.of("Test!")) + .name(Component.literal("Boolean Controllers")) + .tooltip(Component.literal("Test!")) .collapsed(true) .option(Option.createBuilder(boolean.class) - .name(Text.of("Boolean Toggle")) - .tooltip(value -> Text.of("A simple toggle button that contains the value '" + value + "'")) + .name(Component.literal("Boolean Toggle")) + .tooltip(value -> Component.literal("A simple toggle button that contains the value '" + value + "'")) .binding( defaults.booleanToggle, () -> config.booleanToggle, @@ -71,18 +70,18 @@ public class GuiTest { .flag(OptionFlag.GAME_RESTART) .build()) .option(Option.createBuilder(boolean.class) - .name(Text.of("Custom Boolean Toggle")) - .tooltip(Text.of("You can customize these controllers like this!")) + .name(Component.literal("Custom Boolean Toggle")) + .tooltip(Component.literal("You can customize these controllers like this!")) .binding( defaults.customBooleanToggle, () -> config.customBooleanToggle, (value) -> config.customBooleanToggle = value ) - .controller(opt -> new BooleanController(opt, state -> state ? Text.of("Amazing") : Text.of("Not Amazing"), true)) + .controller(opt -> new BooleanController(opt, state -> state ? Component.literal("Amazing") : Component.literal("Not Amazing"), true)) .build()) .option(Option.createBuilder(boolean.class) - .name(Text.of("Tick Box")) - .tooltip(Text.of("There are even alternate methods of displaying the same data type!")) + .name(Component.literal("Tick Box")) + .tooltip(Component.literal("There are even alternate methods of displaying the same data type!")) .binding( defaults.tickbox, () -> config.tickbox, @@ -92,9 +91,9 @@ public class GuiTest { .build()) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("Slider Controllers")) + .name(Component.literal("Slider Controllers")) .option(Option.createBuilder(int.class) - .name(Text.of("Int Slider")) + .name(Component.literal("Int Slider")) .instant(true) .binding( defaults.intSlider, @@ -105,7 +104,7 @@ public class GuiTest { .controller(opt -> new IntegerSliderController(opt, 0, 3, 1)) .build()) .option(Option.createBuilder(double.class) - .name(Text.of("Double Slider")) + .name(Component.literal("Double Slider")) .binding( defaults.doubleSlider, () -> config.doubleSlider, @@ -114,7 +113,7 @@ public class GuiTest { .controller(opt -> new DoubleSliderController(opt, 0, 3, 0.05)) .build()) .option(Option.createBuilder(float.class) - .name(Text.of("Float Slider")) + .name(Component.literal("Float Slider")) .binding( defaults.floatSlider, () -> config.floatSlider, @@ -123,7 +122,7 @@ public class GuiTest { .controller(opt -> new FloatSliderController(opt, 0, 3, 0.1f)) .build()) .option(Option.createBuilder(long.class) - .name(Text.of("Long Slider")) + .name(Component.literal("Long Slider")) .binding( defaults.longSlider, () -> config.longSlider, @@ -133,9 +132,9 @@ public class GuiTest { .build()) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("Input Field Controllers")) + .name(Component.literal("Input Field Controllers")) .option(Option.createBuilder(String.class) - .name(Text.of("Text Option")) + .name(Component.literal("Component Option")) .binding( defaults.textField, () -> config.textField, @@ -144,7 +143,7 @@ public class GuiTest { .controller(StringController::new) .build()) .option(Option.createBuilder(Color.class) - .name(Text.of("Color Option")) + .name(Component.literal("Color Option")) .binding( defaults.colorOption, () -> config.colorOption, @@ -154,9 +153,9 @@ public class GuiTest { .build()) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("Number Fields")) + .name(Component.literal("Number Fields")) .option(Option.createBuilder(double.class) - .name(Text.of("Double Field")) + .name(Component.literal("Double Field")) .binding( defaults.doubleField, () -> config.doubleField, @@ -165,7 +164,7 @@ public class GuiTest { .controller(DoubleFieldController::new) .build()) .option(Option.createBuilder(float.class) - .name(Text.of("Float Field")) + .name(Component.literal("Float Field")) .binding( defaults.floatField, () -> config.floatField, @@ -174,7 +173,7 @@ public class GuiTest { .controller(FloatFieldController::new) .build()) .option(Option.createBuilder(int.class) - .name(Text.of("Integer Field")) + .name(Component.literal("Integer Field")) .binding( defaults.intField, () -> config.intField, @@ -183,7 +182,7 @@ public class GuiTest { .controller(IntegerFieldController::new) .build()) .option(Option.createBuilder(long.class) - .name(Text.of("Long Field")) + .name(Component.literal("Long Field")) .binding( defaults.longField, () -> config.longField, @@ -193,9 +192,9 @@ public class GuiTest { .build()) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("Enum Controllers")) + .name(Component.literal("Enum Controllers")) .option(Option.createBuilder(ExampleConfig.Alphabet.class) - .name(Text.of("Enum Cycler")) + .name(Component.literal("Enum Cycler")) .binding( defaults.enumOption, () -> config.enumOption, @@ -205,41 +204,41 @@ public class GuiTest { .build()) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("Options that aren't really options")) + .name(Component.literal("Options that aren't really options")) .option(ButtonOption.createBuilder() - .name(Text.of("Button \"Option\"")) - .action((screen, opt) -> SystemToast.add(MinecraftClient.getInstance().getToastManager(), SystemToast.Type.TUTORIAL_HINT, Text.of("Button Pressed"), Text.of("Button option was invoked!"))) + .name(Component.literal("Button \"Option\"")) + .action((screen, opt) -> SystemToast.add(Minecraft.getInstance().getToasts(), SystemToast.SystemToastIds.TUTORIAL_HINT, Component.literal("Button Pressed"), Component.literal("Button option was invoked!"))) .controller(ActionController::new) .build()) .option(LabelOption.create( - Text.empty() - .append(Text.literal("a").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("a"))))) - .append(Text.literal("b").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("b"))))) - .append(Text.literal("c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("c"))))) - .append(Text.literal("e").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("e"))))) - .styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://isxander.dev")))) + Component.empty() + .append(Component.literal("a").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("a"))))) + .append(Component.literal("b").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("b"))))) + .append(Component.literal("c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("c"))))) + .append(Component.literal("e").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("e"))))) + .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://isxander.dev")))) ) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("Minecraft Bindings")) - .tooltip(Text.of("YACL can also bind Minecraft options!")) + .name(Component.literal("Minecraft Bindings")) + .tooltip(Component.literal("YACL can also bind Minecraft options!")) .option(Option.createBuilder(boolean.class) - .name(Text.of("Minecraft AutoJump")) - .tooltip(Text.of("You can even bind minecraft options!")) - .binding(Binding.minecraft(MinecraftClient.getInstance().options.getAutoJump())) + .name(Component.literal("Minecraft AutoJump")) + .tooltip(Component.literal("You can even bind minecraft options!")) + .binding(Binding.minecraft(Minecraft.getInstance().options.autoJump())) .controller(TickBoxController::new) .build()) - .option(Option.createBuilder(GraphicsMode.class) - .name(Text.of("Minecraft Graphics Mode")) - .binding(Binding.minecraft(MinecraftClient.getInstance().options.getGraphicsMode())) + .option(Option.createBuilder(GraphicsStatus.class) + .name(Component.literal("Minecraft Graphics Mode")) + .binding(Binding.minecraft(Minecraft.getInstance().options.graphicsMode())) .controller(EnumController::new) .build()) .build()) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("List Test")) + .name(Component.literal("List Test")) .group(ListOption.createBuilder(String.class) - .name(Text.of("String List")) + .name(Component.literal("String List")) .binding( defaults.stringList, () -> config.stringList, @@ -249,7 +248,7 @@ public class GuiTest { .initial("") .build()) .group(ListOption.createBuilder(Integer.class) - .name(Text.of("Slider List")) + .name(Component.literal("Slider List")) .binding( defaults.intList, () -> config.intList, @@ -259,21 +258,21 @@ public class GuiTest { .initial(0) .available(false) .build()) - .group(ListOption.createBuilder(Text.class) - .name(Text.of("Useless Label List")) - .binding(Binding.immutable(List.of(Text.of("It's quite impressive that literally every single controller works, without problem.")))) + .group(ListOption.createBuilder(Component.class) + .name(Component.literal("Useless Label List")) + .binding(Binding.immutable(List.of(Component.literal("It's quite impressive that literally every single controller works, without problem.")))) .controller(LabelController::new) - .initial(Text.of("Initial label")) + .initial(Component.literal("Initial label")) .build()) .build()) .category(PlaceholderCategory.createBuilder() - .name(Text.of("Placeholder Category")) + .name(Component.literal("Placeholder Category")) .screen((client, yaclScreen) -> new RequireRestartScreen(yaclScreen)) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Group Test")) + .name(Component.literal("Group Test")) .option(Option.createBuilder(boolean.class) - .name(Text.of("Root Test")) + .name(Component.literal("Root Test")) .binding( defaults.groupTestRoot, () -> config.groupTestRoot, @@ -282,9 +281,9 @@ public class GuiTest { .controller(TickBoxController::new) .build()) .group(OptionGroup.createBuilder() - .name(Text.of("First Group")) + .name(Component.literal("First Group")) .option(Option.createBuilder(boolean.class) - .name(Text.of("First Group Test 1")) + .name(Component.literal("First Group Test 1")) .binding( defaults.groupTestFirstGroup, () -> config.groupTestFirstGroup, @@ -293,7 +292,7 @@ public class GuiTest { .controller(TickBoxController::new) .build()) .option(Option.createBuilder(boolean.class) - .name(Text.of("First Group Test 2")) + .name(Component.literal("First Group Test 2")) .binding( defaults.groupTestFirstGroup2, () -> config.groupTestFirstGroup2, @@ -303,9 +302,9 @@ public class GuiTest { .build()) .build()) .group(OptionGroup.createBuilder() - .name(Text.empty()) + .name(Component.empty()) .option(Option.createBuilder(boolean.class) - .name(Text.of("Second Group Test")) + .name(Component.literal("Second Group Test")) .binding( defaults.groupTestSecondGroup, () -> config.groupTestSecondGroup, @@ -316,9 +315,9 @@ public class GuiTest { .build()) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Scroll Test")) + .name(Component.literal("Scroll Test")) .option(Option.createBuilder(int.class) - .name(Text.of("Int Slider that is cut off because the slider")) + .name(Component.literal("Int Slider that is cut off because the slider")) .binding( defaults.scrollingSlider, () -> config.scrollingSlider, @@ -327,97 +326,97 @@ public class GuiTest { .controller(opt -> new IntegerSliderController(opt, 0, 10, 1)) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .option(ButtonOption.createBuilder() - .name(Text.of("Option")) + .name(Component.literal("Option")) .action((screen, opt) -> {}) .controller(ActionController::new) .build()) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .category(ConfigCategory.createBuilder() - .name(Text.of("Category Test")) + .name(Component.literal("Category Test")) .build()) .save(() -> { - MinecraftClient.getInstance().options.write(); + Minecraft.getInstance().options.save(); ExampleConfig.INSTANCE.save(); }) ) @@ -428,16 +427,16 @@ public class GuiTest { private static Screen getWikiGetStarted(Screen parent) { return YetAnotherConfigLib.createBuilder() - .title(Text.literal("Used for narration. Could be used to render a title in the future.")) + .title(Component.literal("Used for narration. Could be used to render a title in the future.")) .category(ConfigCategory.createBuilder() - .name(Text.literal("Name of the category")) - .tooltip(Text.literal("This text will appear as a tooltip when you hover or focus the button with Tab. There is no need to add \n to wrap as YACL will do it for you.")) + .name(Component.literal("Name of the category")) + .tooltip(Component.literal("This Component will appear as a tooltip when you hover or focus the button with Tab. There is no need to add \n to wrap as YACL will do it for you.")) .group(OptionGroup.createBuilder() - .name(Text.literal("Name of the group")) - .tooltip(Text.literal("This text will appear when you hover over the name or focus on the collapse button with Tab.")) + .name(Component.literal("Name of the group")) + .tooltip(Component.literal("This Component will appear when you hover over the name or focus on the collapse button with Tab.")) .option(Option.createBuilder(boolean.class) - .name(Text.literal("Boolean Option")) - .tooltip(Text.literal("This text will appear as a tooltip when you hover over the option.")) + .name(Component.literal("Boolean Option")) + .tooltip(Component.literal("This Component will appear as a tooltip when you hover over the option.")) .binding(true, () -> myBooleanOption, newVal -> myBooleanOption = newVal) .controller(TickBoxController::new) .build()) diff --git a/src/testmod/java/dev/isxander/yacl/test/mixins/TitleScreenMixin.java b/src/testmod/java/dev/isxander/yacl/test/mixins/TitleScreenMixin.java index 2f65b96..eac9ff4 100644 --- a/src/testmod/java/dev/isxander/yacl/test/mixins/TitleScreenMixin.java +++ b/src/testmod/java/dev/isxander/yacl/test/mixins/TitleScreenMixin.java @@ -1,10 +1,10 @@ package dev.isxander.yacl.test.mixins; import dev.isxander.yacl.test.config.GuiTest; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,14 +16,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; */ @Mixin(TitleScreen.class) public abstract class TitleScreenMixin extends Screen { - protected TitleScreenMixin(Text title) { + protected TitleScreenMixin(Component title) { super(title); } @Inject(method = "init", at = @At("RETURN")) private void injectTestButton(CallbackInfo ci) { - addDrawableChild(ButtonWidget.builder(Text.of("YACL"), button -> client.setScreen(GuiTest.getModConfigScreenFactory(client.currentScreen))) - .position(0, 0) + addRenderableWidget(Button.builder(Component.literal("YACL"), button -> minecraft.setScreen(GuiTest.getModConfigScreenFactory(minecraft.screen))) + .pos(0, 0) .width(50) .build()); } |