From b0d767d55ac824b7758b8da7279776851d690d2f Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Thu, 1 Feb 2024 00:39:49 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20anvil=20NPE=20crash?= =?UTF-8?q?=20in=20some=20packs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../upgrades/anvil/AnvilUpgradeContainer.java | 4 ++++ .../upgrades/anvil/AnvilUpgradeTab.java | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index b8bb1014..4ed98f6b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false mod_id=sophisticatedbackpacks mod_group_id=sophisticatedbackpacks -mod_version=3.19.5 +mod_version=3.19.6 sonar_project_key=sophisticatedbackpacks:SophisticatedBackpacks github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedBackpacks diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeContainer.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeContainer.java index 4e158913..9790eae1 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeContainer.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeContainer.java @@ -13,6 +13,8 @@ import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerType; import net.p3pp3rf1y.sophisticatedcore.util.NBTHelper; +import javax.annotation.Nullable; + public class AnvilUpgradeContainer extends UpgradeContainerBase { private static final String DATA_SHIFT_CLICK_INTO_STORAGE = "shiftClickIntoStorage"; private final Slot resultSlot; @@ -77,6 +79,7 @@ public int getCost() { return anvilMenuDelegate.getCost(); } + @Nullable public String getItemName() { return anvilMenuDelegate.getItemName(); } @@ -95,6 +98,7 @@ public PersistableAnvilMenu(Inventory playerInventory, AnvilUpgradeWrapper wrapp initializing = false; } + @Nullable public String getItemName() { return itemName; } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeTab.java b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeTab.java index eccad19d..3084121a 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeTab.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedbackpacks/upgrades/anvil/AnvilUpgradeTab.java @@ -75,8 +75,9 @@ protected void renderBg(GuiGraphics guiGraphics, Minecraft minecraft, int mouseX private String getInitialNameValue() { ItemStack firstItem = getContainer().getSlots().get(0).getItem(); - if (!firstItem.isEmpty() && !getContainer().getItemName().isEmpty()) { - return getContainer().getItemName(); + String itemName = getContainer().getItemName(); + if (!firstItem.isEmpty() && itemName != null && !itemName.isEmpty()) { + return itemName; } return firstItem.isEmpty() ? "" : firstItem.getHoverName().getString(); }