diff options
Diffstat (limited to 'src/client/java/dev/isxander/yacl')
56 files changed, 749 insertions, 778 deletions
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(); } |