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 --- gradle.properties | 10 +++++----- .../cottonmc/cotton/gui/impl/access/ScreenAccessor.java | 16 ++++++++++++++++ .../cottonmc/cotton/gui/widget/TooltipBuilder.java | 12 +++++++----- .../io/github/cottonmc/cotton/gui/widget/WWidget.java | 7 ++++--- 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/impl/access/ScreenAccessor.java diff --git a/gradle.properties b/gradle.properties index 0bf317a..be7ce1c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.16.3 - yarn_mappings=1.16.3+build.47 - loader_version=0.10.2+build.210 + minecraft_version=20w48a + yarn_mappings=20w48a+build.1 + loader_version=0.10.8 # Mod Properties - mod_version = 3.2.2 + mod_version = 4.0.0-beta.1 maven_group = io.github.cottonmc archives_base_name = LibGui # Dependencies - fabric_version=0.24.0+build.411-1.16 + fabric_version=0.26.4+1.17 jankson_version=3.0.1+j1.2.0 modmenu_version=1.14.6+build.31 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