Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "open guide" hotkey not working for items in Emi because they were changing each frame #7965

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/main/java/appeng/client/guidebook/hotkey/OpenGuideHotkey.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package appeng.client.guidebook.hotkey;

import java.util.List;
import java.util.Objects;

import com.google.common.base.Strings;
import com.mojang.blaze3d.platform.InputConstants;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand Down Expand Up @@ -43,8 +45,8 @@ public final class OpenGuideHotkey {

private static boolean newTick = true;

// The last itemstack the tooltip was being shown for
private static ItemStack lastStack;
// The previous item the tooltip was being shown for
private static ResourceLocation previousItemId;
@Nullable
private static PageAnchor guidebookPage;
// Full ticks since the button was held (reduces slowly when not held)
Expand Down Expand Up @@ -133,15 +135,16 @@ private static Component makeProgressBar(float progress) {
}

private static void update(ItemStack itemStack) {
if (itemStack != lastStack) {
lastStack = itemStack;
var itemId = itemStack.getItemHolder()
.unwrapKey()
.map(ResourceKey::location)
.orElse(null);

if (!Objects.equals(itemId, previousItemId)) {
previousItemId = itemId;
guidebookPage = null;
ticksKeyHeld = 0;

var itemId = itemStack.getItemHolder()
.unwrapKey()
.map(ResourceKey::location)
.orElse(null);
if (itemId == null) {
return;
}
Expand Down