Skip to content

Commit

Permalink
Fix hovering over old items crashing the game
Browse files Browse the repository at this point in the history
  • Loading branch information
triphora committed Jul 4, 2024
1 parent 55b76c0 commit 245940b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 245940b

Please sign in to comment.