From aa73fb203aacd3f150b1d52346cde514237cdef1 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Thu, 26 Nov 2020 17:42:10 +0200 Subject: Update to 20w48a, migrate to using TooltipComponent internally --- .../cottonmc/cotton/gui/impl/access/ScreenAccessor.java | 16 ++++++++++++++++ .../cottonmc/cotton/gui/widget/TooltipBuilder.java | 12 +++++++----- .../io/github/cottonmc/cotton/gui/widget/WWidget.java | 7 ++++--- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/access/ScreenAccessor.java (limited to 'src') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/access/ScreenAccessor.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/ScreenAccessor.java new file mode 100644 index 0000000..0d97e7c --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/access/ScreenAccessor.java @@ -0,0 +1,16 @@ +package io.github.cottonmc.cotton.gui.impl.access; + +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.tooltip.TooltipComponent; +import net.minecraft.client.util.math.MatrixStack; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.List; + +@Mixin(Screen.class) +public interface ScreenAccessor { + @Invoker("method_32633") + void callRenderTooltipFromComponents(MatrixStack matrices, List components, int x, int y); +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java index f99df0a..4997bb2 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/TooltipBuilder.java @@ -2,11 +2,11 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.gui.tooltip.TooltipComponent; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -16,10 +16,10 @@ import java.util.List; */ @Environment(EnvType.CLIENT) public final class TooltipBuilder { - final List lines = new ArrayList<>(); + final List components = new ArrayList<>(); int size() { - return lines.size(); + return components.size(); } /** @@ -30,7 +30,7 @@ public final class TooltipBuilder { */ public TooltipBuilder add(Text... lines) { for (Text line : lines) { - this.lines.add(line.asOrderedText()); + components.add(TooltipComponent.createOrderedTextTooltipComponent(line.asOrderedText())); } return this; @@ -43,7 +43,9 @@ public final class TooltipBuilder { * @return this builder */ public TooltipBuilder add(OrderedText... lines) { - Collections.addAll(this.lines, lines); + for (OrderedText line : lines) { + components.add(TooltipComponent.createOrderedTextTooltipComponent(line)); + } return this; } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index cd3c31b..7c36e55 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -8,6 +8,7 @@ import net.minecraft.client.util.math.MatrixStack; import com.google.common.annotations.Beta; import io.github.cottonmc.cotton.gui.GuiDescription; +import io.github.cottonmc.cotton.gui.impl.access.ScreenAccessor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -356,8 +357,8 @@ public class WWidget { if (builder.size() == 0) return; - Screen screen = MinecraftClient.getInstance().currentScreen; - screen.renderOrderedTooltip(matrices, builder.lines, tX+x, tY+y); + ScreenAccessor screen = (ScreenAccessor) MinecraftClient.getInstance().currentScreen; + screen.callRenderTooltipFromComponents(matrices, builder.components, tX+x, tY+y); } /** @@ -370,7 +371,7 @@ public class WWidget { if (host != null) { this.host = host; } else { - LOGGER.warn("Validating {} with a null host", this); + LOGGER.warn("Validating {} with a null host", this); } } -- cgit