From 245940b29948dd8b3ec9a4d0d035927dbf8d6535 Mon Sep 17 00:00:00 2001 From: Emma Triphora Date: Thu, 4 Jul 2024 12:34:52 -0400 Subject: [PATCH] Fix hovering over old items crashing the game --- .../java/coffee/waffle/emcutils/feature/UsableItems.java | 9 +++++++-- .../waffle/emcutils/feature/VaultScreenHandler.java | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java b/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java index 3b6b139..cf9e829 100644 --- a/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java +++ b/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java @@ -97,9 +97,14 @@ private static long getSecondsUntilUsable(ItemStack item) { if (useTimerLine == -1) return 0L; String unparsed = originalLore.get(useTimerLine + 1).getAsString(); - long time = Long.parseLong(unparsed.substring(1, unparsed.length() - 1)); + try { + long time = Long.parseLong(unparsed.substring(1, unparsed.length() - 1)); - return Math.max(0, (time - System.currentTimeMillis()) / 1000L); + return Math.max(0, (time - System.currentTimeMillis()) / 1000L); + } catch (NumberFormatException e) { + // item has not been used since before NBT format was changed and is therefore safe to use + return 0; + } } public static String formatTime(long seconds, int depth) { diff --git a/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreenHandler.java b/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreenHandler.java index b6f2131..15973af 100644 --- a/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreenHandler.java +++ b/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreenHandler.java @@ -39,6 +39,7 @@ public boolean canUse(PlayerEntity player) { return this.inventory.canPlayerUse(player); } + @Override public ItemStack quickMove(PlayerEntity player, int index) { ItemStack itemStack = ItemStack.EMPTY; Slot slot = this.slots.get(index);