diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-11-26 17:42:10 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-11-26 17:42:10 +0200 |
commit | aa73fb203aacd3f150b1d52346cde514237cdef1 (patch) | |
tree | 7cac78fe607efc64d63ea945f7c08b30c2538ed6 /src/main/java/io | |
parent | 66d11270b27d1fb53458c96879d3d3ca37dfeccf (diff) | |
download | LibGui-aa73fb203aacd3f150b1d52346cde514237cdef1.tar.gz LibGui-aa73fb203aacd3f150b1d52346cde514237cdef1.tar.bz2 LibGui-aa73fb203aacd3f150b1d52346cde514237cdef1.zip |
Update to 20w48a, migrate to using TooltipComponent internally
Diffstat (limited to 'src/main/java/io')
3 files changed, 27 insertions, 8 deletions
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<TooltipComponent> 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<OrderedText> lines = new ArrayList<>(); + final List<TooltipComponent> 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); } } |