diff options
author | isXander <xandersmith2008@gmail.com> | 2023-01-19 21:15:26 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-01-19 21:15:26 +0000 |
commit | ee53b51a1e8d88085c75f227f4710b68c03b19c8 (patch) | |
tree | 77a942242a982757da040a6120950bad30e49f77 /src/client/java/dev/isxander/yacl/gui/controllers | |
parent | ffdd6e5ceacd71c76c55a8716702d4d6da17c7ab (diff) | |
download | YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.gz YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.bz2 YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.zip |
mojmap
Diffstat (limited to 'src/client/java/dev/isxander/yacl/gui/controllers')
22 files changed, 266 insertions, 266 deletions
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()); } |