From b389cfed152a8e99205fe7901544cfdad4a20e71 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 30 Dec 2024 16:56:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtooltip=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84NPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/tooltip/ClientGunImageTooltip.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java index 042c3fa9a..80d75e5ab 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/tooltip/ClientGunImageTooltip.java @@ -29,16 +29,11 @@ public class ClientGunImageTooltip implements ClientTooltipComponent { protected final int width; protected final int height; protected final ItemStack stack; - protected GunItem gunItem = null; public ClientGunImageTooltip(GunImageComponent tooltip) { this.width = tooltip.width; this.height = tooltip.height; this.stack = tooltip.stack; - if (this.stack.getItem() instanceof GunItem gunItem1) { - this.gunItem = gunItem1; - } - } @Override @@ -74,7 +69,10 @@ public class ClientGunImageTooltip implements ClientTooltipComponent { } protected boolean shouldRenderEditTooltip() { - return gunItem.canCustom(stack); + if (this.stack.getItem() instanceof GunItem gunItem) { + return gunItem.canCustom(stack); + } + return false; } protected boolean shouldRenderPerks() { @@ -105,14 +103,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent { * 获取武器射速的文本组件 */ protected Component getRpmComponent() { - if (!gunItem.autoWeapon(this.stack)) { - return Component.literal(""); - } else { + if (this.stack.getItem() instanceof GunItem gunItem && gunItem.autoWeapon(this.stack)) { return Component.translatable("des.superbwarfare.tips.rpm").withStyle(ChatFormatting.GRAY) .append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal(new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "RPM", 0) + ItemNBTTool.getDouble(stack, "customRpm", 0))) .withStyle(ChatFormatting.GREEN)); } + return Component.literal(""); } /**