From 0e3d5c112e42b5fd8957905d32078a3a8b59ce96 Mon Sep 17 00:00:00 2001 From: viciscat <51047087+viciscat@users.noreply.github.com> Date: Fri, 24 May 2024 23:49:37 +0200 Subject: [PATCH 1/2] git blame says it's kevin's fault --- src/main/java/de/hysky/skyblocker/debug/Debug.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/hysky/skyblocker/debug/Debug.java b/src/main/java/de/hysky/skyblocker/debug/Debug.java index d642ca5bc2..ffcc48b767 100644 --- a/src/main/java/de/hysky/skyblocker/debug/Debug.java +++ b/src/main/java/de/hysky/skyblocker/debug/Debug.java @@ -48,7 +48,7 @@ public static void init() { ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> { if (screen instanceof HandledScreen handledScreen) { ScreenKeyboardEvents.afterKeyPress(screen).register((_screen, key, scancode, modifier) -> { - if (key == GLFW.GLFW_KEY_U && client.player != null) { + if (key == GLFW.GLFW_KEY_U && client.player != null && ((HandledScreenAccessor) handledScreen).getFocusedSlot() != null && ((HandledScreenAccessor) handledScreen).getFocusedSlot().hasStack()) { client.player.sendMessage(Text.literal("[Skyblocker Debug] Hovered Item: " + SkyblockerMod.GSON_COMPACT.toJson(ItemStack.CODEC.encodeStart(JsonOps.INSTANCE, ((HandledScreenAccessor) handledScreen).getFocusedSlot().getStack())))); } }); From df0644e23f66bc504323aa245448af4c6075b3f7 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Fri, 24 May 2024 18:06:08 -0400 Subject: [PATCH 2/2] Fixing the fix (with variables) --- src/main/java/de/hysky/skyblocker/debug/Debug.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/debug/Debug.java b/src/main/java/de/hysky/skyblocker/debug/Debug.java index ffcc48b767..16d91635ab 100644 --- a/src/main/java/de/hysky/skyblocker/debug/Debug.java +++ b/src/main/java/de/hysky/skyblocker/debug/Debug.java @@ -16,6 +16,7 @@ import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.item.ItemStack; import net.minecraft.predicate.entity.EntityPredicates; +import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.lwjgl.glfw.GLFW; @@ -48,8 +49,9 @@ public static void init() { ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> { if (screen instanceof HandledScreen handledScreen) { ScreenKeyboardEvents.afterKeyPress(screen).register((_screen, key, scancode, modifier) -> { - if (key == GLFW.GLFW_KEY_U && client.player != null && ((HandledScreenAccessor) handledScreen).getFocusedSlot() != null && ((HandledScreenAccessor) handledScreen).getFocusedSlot().hasStack()) { - client.player.sendMessage(Text.literal("[Skyblocker Debug] Hovered Item: " + SkyblockerMod.GSON_COMPACT.toJson(ItemStack.CODEC.encodeStart(JsonOps.INSTANCE, ((HandledScreenAccessor) handledScreen).getFocusedSlot().getStack())))); + Slot focusedSlot = ((HandledScreenAccessor) handledScreen).getFocusedSlot(); + if (key == GLFW.GLFW_KEY_U && client.player != null && focusedSlot != null && focusedSlot.hasStack()) { + client.player.sendMessage(Text.literal("[Skyblocker Debug] Hovered Item: " + SkyblockerMod.GSON_COMPACT.toJson(ItemStack.CODEC.encodeStart(JsonOps.INSTANCE, focusedSlot.getStack())))); } }); }