修复tooltip导致的NPE
This commit is contained in:
parent
f4052e7041
commit
b389cfed15
1 changed files with 6 additions and 9 deletions
|
@ -29,16 +29,11 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
||||||
protected final int width;
|
protected final int width;
|
||||||
protected final int height;
|
protected final int height;
|
||||||
protected final ItemStack stack;
|
protected final ItemStack stack;
|
||||||
protected GunItem gunItem = null;
|
|
||||||
|
|
||||||
public ClientGunImageTooltip(GunImageComponent tooltip) {
|
public ClientGunImageTooltip(GunImageComponent tooltip) {
|
||||||
this.width = tooltip.width;
|
this.width = tooltip.width;
|
||||||
this.height = tooltip.height;
|
this.height = tooltip.height;
|
||||||
this.stack = tooltip.stack;
|
this.stack = tooltip.stack;
|
||||||
if (this.stack.getItem() instanceof GunItem gunItem1) {
|
|
||||||
this.gunItem = gunItem1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,8 +69,11 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean shouldRenderEditTooltip() {
|
protected boolean shouldRenderEditTooltip() {
|
||||||
|
if (this.stack.getItem() instanceof GunItem gunItem) {
|
||||||
return gunItem.canCustom(stack);
|
return gunItem.canCustom(stack);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean shouldRenderPerks() {
|
protected boolean shouldRenderPerks() {
|
||||||
return PerkHelper.getPerkByType(stack, Perk.Type.AMMO) != null || PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE) != null || PerkHelper.getPerkByType(stack, Perk.Type.FUNCTIONAL) != null;
|
return PerkHelper.getPerkByType(stack, Perk.Type.AMMO) != null || PerkHelper.getPerkByType(stack, Perk.Type.DAMAGE) != null || PerkHelper.getPerkByType(stack, Perk.Type.FUNCTIONAL) != null;
|
||||||
|
@ -105,14 +103,13 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
|
||||||
* 获取武器射速的文本组件
|
* 获取武器射速的文本组件
|
||||||
*/
|
*/
|
||||||
protected Component getRpmComponent() {
|
protected Component getRpmComponent() {
|
||||||
if (!gunItem.autoWeapon(this.stack)) {
|
if (this.stack.getItem() instanceof GunItem gunItem && gunItem.autoWeapon(this.stack)) {
|
||||||
return Component.literal("");
|
|
||||||
} else {
|
|
||||||
return Component.translatable("des.superbwarfare.tips.rpm").withStyle(ChatFormatting.GRAY)
|
return Component.translatable("des.superbwarfare.tips.rpm").withStyle(ChatFormatting.GRAY)
|
||||||
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
.append(Component.literal("").withStyle(ChatFormatting.RESET))
|
||||||
.append(Component.literal(new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "RPM", 0) + ItemNBTTool.getDouble(stack, "customRpm", 0)))
|
.append(Component.literal(new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "RPM", 0) + ItemNBTTool.getDouble(stack, "customRpm", 0)))
|
||||||
.withStyle(ChatFormatting.GREEN));
|
.withStyle(ChatFormatting.GREEN));
|
||||||
}
|
}
|
||||||
|
return Component.literal("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue