Merge pull request #4333 from ZacSharp/pr/1.19.4/misc/toolset/fixHardnessCrash

Fix NPE in break time calculation
This commit is contained in:
leijurv 2024-04-24 12:49:15 -07:00 committed by GitHub
commit b31e0a87cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -177,7 +177,13 @@ public class ToolSet {
* @return how long it would take in ticks
*/
public static double calculateSpeedVsBlock(ItemStack item, BlockState state) {
float hardness = state.getDestroySpeed(null, null);
float hardness;
try {
hardness = state.getDestroySpeed(null, null);
} catch (NullPointerException npe) {
// can't easily determine the hardness so treat it as unbreakable
return -1;
}
if (hardness < 0) {
return -1;
}