From af62f368306bc6002f47f3e6f6045b1bde020ac1 Mon Sep 17 00:00:00 2001 From: glisco Date: Sat, 18 May 2024 17:07:04 +0200 Subject: [PATCH] more robust triggering of associated entry from tooltip --- gradle.properties | 2 +- .../AssociatedEntryTooltipComponent.java | 11 +++++++++++ .../lavender/mixin/DrawContextMixin.java | 18 ++++++++++-------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2c35987..9520e79 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.15.9 # Mod Properties - mod_version = 0.1.8 + mod_version = 0.1.9 maven_group = io.wispforest archives_base_name = lavender diff --git a/src/main/java/io/wispforest/lavender/client/AssociatedEntryTooltipComponent.java b/src/main/java/io/wispforest/lavender/client/AssociatedEntryTooltipComponent.java index a88d198..f099c6e 100644 --- a/src/main/java/io/wispforest/lavender/client/AssociatedEntryTooltipComponent.java +++ b/src/main/java/io/wispforest/lavender/client/AssociatedEntryTooltipComponent.java @@ -5,8 +5,11 @@ import io.wispforest.owo.ui.container.Containers; import io.wispforest.owo.ui.container.FlowLayout; import io.wispforest.owo.ui.core.*; +import io.wispforest.owo.ui.util.Delta; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.tooltip.TooltipComponent; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; @@ -17,6 +20,7 @@ public class AssociatedEntryTooltipComponent implements TooltipComponent { + public static float entryTriggerProgress = 0f; public static @Nullable WeakReference tooltipStack = null; private final FlowLayout layout; @@ -61,4 +65,11 @@ public int getHeight() { public int getWidth(TextRenderer textRenderer) { return this.layout.width(); } + + static { + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (Screen.hasAltDown()) return; + entryTriggerProgress += Delta.compute(entryTriggerProgress, 0f, .125f); + }); + } } diff --git a/src/main/java/io/wispforest/lavender/mixin/DrawContextMixin.java b/src/main/java/io/wispforest/lavender/mixin/DrawContextMixin.java index 92dbb95..01831b5 100644 --- a/src/main/java/io/wispforest/lavender/mixin/DrawContextMixin.java +++ b/src/main/java/io/wispforest/lavender/mixin/DrawContextMixin.java @@ -1,5 +1,7 @@ package io.wispforest.lavender.mixin; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; import io.wispforest.lavender.book.LavenderBookItem; import io.wispforest.lavender.book.BookLoader; import io.wispforest.lavender.client.AssociatedEntryTooltipComponent; @@ -12,21 +14,20 @@ import net.minecraft.client.gui.tooltip.TooltipComponent; import net.minecraft.client.gui.tooltip.TooltipPositioner; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.ArrayList; import java.util.List; +import static io.wispforest.lavender.client.AssociatedEntryTooltipComponent.entryTriggerProgress; + @Mixin(DrawContext.class) public class DrawContextMixin { - @Unique - private static float entryTriggerProgress = 0f; - @Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V", at = @At("HEAD")) - private void injectTooltipComponents(TextRenderer textRenderer, List components, int x, int y, TooltipPositioner positioner, CallbackInfo ci) { + private void injectTooltipComponents(TextRenderer textRenderer, List components, int x, int y, TooltipPositioner positioner, CallbackInfo ci, @Local(argsOnly = true) LocalRef> componentsRef) { var client = MinecraftClient.getInstance(); if (AssociatedEntryTooltipComponent.tooltipStack != null && AssociatedEntryTooltipComponent.tooltipStack.get() != null) { @@ -51,8 +52,11 @@ private void injectTooltipComponents(TextRenderer textRenderer, List(components); components.add(new AssociatedEntryTooltipComponent(LavenderBookItem.itemOf(book), associatedEntry, entryTriggerProgress)); - entryTriggerProgress += Delta.compute(entryTriggerProgress, Screen.hasAltDown() ? 1.35f : 0f, client.getLastFrameDuration() * .125); + componentsRef.set(components); + + entryTriggerProgress += Delta.compute(entryTriggerProgress, Screen.hasAltDown() ? 1.35f : 0f, client.getLastFrameDuration() * .125f); if (entryTriggerProgress >= .95) { LavenderBookScreen.pushEntry(book, associatedEntry); @@ -68,7 +72,5 @@ private void injectTooltipComponents(TextRenderer textRenderer, List