From 3b3227b09dd14d305a7ed871011aa40d931caab3 Mon Sep 17 00:00:00 2001 From: slprime Date: Mon, 5 Aug 2024 19:34:59 +0300 Subject: [PATCH] fix hover crash to unnamed item --- src/main/java/codechicken/nei/ItemZoom.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemZoom.java b/src/main/java/codechicken/nei/ItemZoom.java index 23272d898..3aebc09bd 100644 --- a/src/main/java/codechicken/nei/ItemZoom.java +++ b/src/main/java/codechicken/nei/ItemZoom.java @@ -30,6 +30,7 @@ public class ItemZoom extends Widget implements IContainerInputHandler { private Boolean previousKeyboardRepeatEnabled = null; private ItemStack stack = null; + private String displayName = ""; private int availableAreaWidth = 0; private float xPosition = 0; private float yPosition = 0; @@ -61,8 +62,7 @@ public void draw(int mx, int my) { GL11.glPopMatrix(); if (NEIClientConfig.getBooleanSetting("inventory.itemzoom.showName")) { - String dispalyName = NEIClientUtils - .cropText(fontRenderer, this.stack.getDisplayName(), this.availableAreaWidth); + String dispalyName = NEIClientUtils.cropText(fontRenderer, this.displayName, this.availableAreaWidth); drawStringC( dispalyName, (int) ((this.xPosition + size / 2) * screenScale), @@ -114,9 +114,16 @@ public void resize(GuiContainer gui) { this.xPosition += (gui.guiLeft + gui.xSize) * screenScale;; } + try { + this.displayName = stack.getDisplayName(); + } catch (Throwable ignored) { + this.displayName = "Unnamed"; + } + this.stack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(stack), 0); } else { this.stack = null; + this.displayName = ""; } }