Skip to content

Commit

Permalink
add null check to ToolTier#get
Browse files Browse the repository at this point in the history
closes #249

(cherry picked from commit 71c3966)
  • Loading branch information
deirn committed Feb 15, 2024
1 parent 198f00e commit 430a033
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void onHandleTooltip(ITooltip tooltip, ICommonAccessor accessor, IPluginC
matches = tool.itemPredicate.test(heldStack);
if (highestTier != ToolTier.NONE && heldStack.getItem() instanceof TieredItem tiered) {
var heldTier = ToolTier.get(tiered.getTier());
matches = matches && heldTier.isBetterThanOrEqualTo(highestTier);
matches = matches && heldTier != null && heldTier.isBetterThanOrEqualTo(highestTier);
}
}
component = new ToolComponent(icon, matches);
Expand Down Expand Up @@ -201,7 +201,7 @@ private static MutableComponent getTierText(ToolTier highestTier, ItemStack held
: Component.literal(String.valueOf(highestTier.index));
if (heldStack.getItem() instanceof TieredItem tiered) {
var heldTier = ToolTier.get(tiered.getTier());
tierText.withStyle(heldTier.isBetterThanOrEqualTo(highestTier) ? ChatFormatting.GREEN : ChatFormatting.RED);
tierText.withStyle(heldTier != null && heldTier.isBetterThanOrEqualTo(highestTier) ? ChatFormatting.GREEN : ChatFormatting.RED);
} else {
tierText.withStyle(ChatFormatting.RED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static Collection<ToolTier> all() {
return TIERS.get().values();
}

@Nullable
public static ToolTier get(Tier tier) {
return TIERS.get().get(tier);
}
Expand Down

0 comments on commit 430a033

Please sign in to comment.