From 3fa1cae055f2ad1b6cd0bb9d30f72928ab61a3ea Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:42:58 +0100 Subject: [PATCH] Enforce safe stack copying, fixes #593 --- .../UTPickupNotificationOverlay.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/pickupnotification/UTPickupNotificationOverlay.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/pickupnotification/UTPickupNotificationOverlay.java index 175f0e17..477a7b52 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/pickupnotification/UTPickupNotificationOverlay.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/pickupnotification/UTPickupNotificationOverlay.java @@ -45,7 +45,14 @@ private static boolean isStackEmpty(ItemStack stack) private static ItemStack safeCopy(ItemStack stack) { - return stack.copy(); + try + { + return stack.copy(); + } + catch (Exception e) + { + return ItemStack.EMPTY; + } } private final List changeEntries = Lists.newArrayList(); @@ -291,12 +298,12 @@ public void utPUNClientTick(TickEvent.ClientTickEvent event) ItemStack stack = player.inventory.getStackInSlot(i); ItemStack old = previous[i]; if (isChangeMeaningful(old, stack)) changes.add(Pair.of(old, stack)); - previous[i] = stack.copy(); + previous[i] = safeCopy(stack); } ItemStack stackInCursor = player.inventory.getItemStack(); if (isChangeMeaningful(stackInCursor, previousInCursor)) changes.add(Pair.of(previousInCursor, stackInCursor)); - previousInCursor = stackInCursor.copy(); + previousInCursor = safeCopy(stackInCursor); if (UTConfigTweaks.MISC.PICKUP_NOTIFICATION.utPUNExperience) {