From ee53b51a1e8d88085c75f227f4710b68c03b19c8 Mon Sep 17 00:00:00 2001 From: isXander Date: Thu, 19 Jan 2023 21:15:26 +0000 Subject: mojmap --- src/client/java/dev/isxander/yacl/api/Binding.java | 14 +-- .../java/dev/isxander/yacl/api/ButtonOption.java | 20 ++-- .../java/dev/isxander/yacl/api/ConfigCategory.java | 16 +-- .../java/dev/isxander/yacl/api/Controller.java | 4 +- .../java/dev/isxander/yacl/api/LabelOption.java | 16 +-- .../java/dev/isxander/yacl/api/ListOption.java | 11 +- .../java/dev/isxander/yacl/api/NameableEnum.java | 4 +- src/client/java/dev/isxander/yacl/api/Option.java | 16 +-- .../java/dev/isxander/yacl/api/OptionFlag.java | 12 +- .../java/dev/isxander/yacl/api/OptionGroup.java | 20 ++-- .../dev/isxander/yacl/api/PlaceholderCategory.java | 22 ++-- .../dev/isxander/yacl/api/YetAnotherConfigLib.java | 12 +- .../java/dev/isxander/yacl/gui/AbstractWidget.java | 49 ++++---- .../dev/isxander/yacl/gui/CategoryListWidget.java | 28 ++--- .../java/dev/isxander/yacl/gui/CategoryWidget.java | 4 +- .../isxander/yacl/gui/ElementListWidgetExt.java | 57 +++++----- .../isxander/yacl/gui/LowProfileButtonWidget.java | 26 ++--- .../dev/isxander/yacl/gui/OptionListWidget.java | 124 ++++++++++----------- .../isxander/yacl/gui/RequireRestartScreen.java | 21 ++-- .../dev/isxander/yacl/gui/SearchFieldWidget.java | 36 +++--- .../isxander/yacl/gui/TextScaledButtonWidget.java | 44 ++++---- .../dev/isxander/yacl/gui/TooltipButtonWidget.java | 29 +++-- .../java/dev/isxander/yacl/gui/YACLScreen.java | 120 ++++++++++---------- .../yacl/gui/controllers/ActionController.java | 14 +-- .../yacl/gui/controllers/BooleanController.java | 47 ++++---- .../yacl/gui/controllers/ColorController.java | 24 ++-- .../yacl/gui/controllers/ControllerWidget.java | 76 ++++++------- .../yacl/gui/controllers/LabelController.java | 61 +++++----- .../yacl/gui/controllers/ListEntryWidget.java | 34 +++--- .../yacl/gui/controllers/TickBoxController.java | 22 ++-- .../cycling/CyclingControllerElement.java | 10 +- .../controllers/cycling/CyclingListController.java | 10 +- .../gui/controllers/cycling/EnumController.java | 22 ++-- .../controllers/slider/DoubleSliderController.java | 12 +- .../controllers/slider/FloatSliderController.java | 12 +- .../slider/IntegerSliderController.java | 12 +- .../controllers/slider/LongSliderController.java | 12 +- .../slider/SliderControllerElement.java | 40 +++---- .../gui/controllers/string/IStringController.java | 6 +- .../string/StringControllerElement.java | 80 ++++++------- .../string/number/DoubleFieldController.java | 7 +- .../string/number/FloatFieldController.java | 7 +- .../string/number/IntegerFieldController.java | 6 +- .../string/number/LongFieldController.java | 6 +- .../string/number/NumberFieldController.java | 12 +- .../java/dev/isxander/yacl/gui/utils/GuiUtils.java | 28 ++--- .../dev/isxander/yacl/impl/ButtonOptionImpl.java | 28 ++--- .../dev/isxander/yacl/impl/ConfigCategoryImpl.java | 28 ++--- .../dev/isxander/yacl/impl/LabelOptionImpl.java | 44 ++++---- .../isxander/yacl/impl/ListOptionEntryImpl.java | 12 +- .../dev/isxander/yacl/impl/ListOptionImpl.java | 26 ++--- .../dev/isxander/yacl/impl/OptionGroupImpl.java | 26 ++--- .../java/dev/isxander/yacl/impl/OptionImpl.java | 36 +++--- .../yacl/impl/PlaceholderCategoryImpl.java | 39 ++++--- .../yacl/impl/YetAnotherConfigLibImpl.java | 15 ++- .../yacl/mixin/client/OptionInstanceAccessor.java | 13 +++ .../yacl/mixin/client/SimpleOptionAccessor.java | 13 --- 57 files changed, 758 insertions(+), 787 deletions(-) create mode 100644 src/client/java/dev/isxander/yacl/mixin/client/OptionInstanceAccessor.java delete mode 100644 src/client/java/dev/isxander/yacl/mixin/client/SimpleOptionAccessor.java (limited to 'src/client/java/dev') 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 { } /** - * Creates a {@link Binding} for Minecraft's {@link SimpleOption} + * Creates a {@link Binding} for Minecraft's {@link OptionInstance} */ - static Binding minecraft(SimpleOption minecraftOption) { + static Binding minecraft(OptionInstance minecraftOption) { Validate.notNull(minecraftOption, "`minecraftOption` must not be null"); return new GenericBindingImpl<>( - ((SimpleOptionAccessor) (Object) minecraftOption).getDefaultValue(), - minecraftOption::getValue, - minecraftOption::setValue + ((OptionInstanceAccessor) (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 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 action); + dev.isxander.yacl.api.ButtonOption.Builder action(@NotNull BiConsumer action); /** * Action to be executed upon button press @@ -48,14 +44,14 @@ public interface ButtonOption extends Option action); + dev.isxander.yacl.api.ButtonOption.Builder action(@NotNull Consumer 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>> control); + dev.isxander.yacl.api.ButtonOption.Builder controller(@NotNull Function>> 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 { /** * 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 { - @NotNull Text label(); +public interface LabelOption extends Option { + @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 { /** * 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 lines); + dev.isxander.yacl.api.LabelOption.Builder lines(@NotNull Collection 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 extends OptionGroup, Option> { * * @see ListOption#name() */ - Builder name(@NotNull Text name); + Builder 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 extends OptionGroup, Option> { * 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 tooltip(@NotNull Text... tooltips); + Builder 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 { /** * 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 { * * @see Option#name() */ - Builder name(@NotNull Text name); + Builder name(@NotNull Component name); /** * Sets the tooltip to be used by the option. @@ -137,7 +133,7 @@ public interface Option { * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. */ @SuppressWarnings("unchecked") - Builder tooltip(@NotNull Function... tooltipGetter); + Builder tooltip(@NotNull Function... tooltipGetter); /** * Sets the tooltip to be used by the option. @@ -146,7 +142,7 @@ public interface Option { * * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. */ - Builder tooltip(@NotNull Text... tooltips); + Builder 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 { +public interface OptionFlag extends Consumer { /** 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 screen(); + BiFunction 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 screenFunction); + Builder screen(@NotNull BiFunction 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 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 { 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 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 children() { + public List children() { return ImmutableList.of(categoryButton); } @Override - public List selectableChildren() { + public List 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> extends ElementListWidget { +public class ElementListWidgetExt> extends ContainerObjectSelectionList { 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> 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> 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> 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> 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> extends ElementListWidget.Entry { - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public abstract static class Entry> extends ContainerObjectSelectionList.Entry { + 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 viewableChildren; + private ImmutableList 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 optionEntries = new ArrayList<>(); + List 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 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 { + 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 selectableChildren() { + public List narratables() { if (resetButton == null) return ImmutableList.of(widget); @@ -337,7 +337,7 @@ public class OptionListWidget extends ElementListWidgetExt children() { + public List children() { if (resetButton == null) return ImmutableList.of(widget); @@ -347,13 +347,13 @@ public class OptionListWidget extends ElementListWidgetExt 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 childEntries) { @@ -424,7 +424,7 @@ public class OptionListWidget extends ElementListWidgetExt selectableChildren() { - return ImmutableList.of(new Selectable() { + public List 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 children() { + public List children() { return ImmutableList.of(expandMinimizeButton); } } @@ -462,13 +462,13 @@ public class OptionListWidget extends ElementListWidgetExt { + 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 children() { + public List children() { return ImmutableList.of(expandMinimizeButton, addListButton, resetListButton); } } @@ -533,8 +533,8 @@ public class OptionListWidget extends ElementListWidgetExt