Fix NPE when getting destroy speed of air (#6989)

This commit is contained in:
SoSeDiK 2021-12-02 03:48:15 +02:00
parent d1eed05360
commit 05a5f029d5

View File

@ -19,10 +19,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ net.minecraft.world.item.ItemStack nmsItemStack; + net.minecraft.world.item.ItemStack nmsItemStack;
+ if (itemStack instanceof CraftItemStack) { + if (itemStack instanceof CraftItemStack) {
+ nmsItemStack = ((CraftItemStack) itemStack).handle; + nmsItemStack = ((CraftItemStack) itemStack).handle;
+ if (nmsItemStack == null) {
+ nmsItemStack = net.minecraft.world.item.ItemStack.EMPTY;
+ }
+ } else { + } else {
+ nmsItemStack = CraftItemStack.asNMSCopy(itemStack); + nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
+ } + }
+ float speed = nmsItemStack.getItem().getDestroySpeed(nmsItemStack, this.getNMS().getBlock().defaultBlockState()); + float speed = nmsItemStack.getDestroySpeed(this.getNMS().getBlock().defaultBlockState());
+ if (speed > 1.0F && considerEnchants) { + if (speed > 1.0F && considerEnchants) {
+ int enchantLevel = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.BLOCK_EFFICIENCY, nmsItemStack); + int enchantLevel = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.BLOCK_EFFICIENCY, nmsItemStack);
+ if (enchantLevel > 0) { + if (enchantLevel > 0) {