aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0511-Add-Destroy-Speed-API.patch
blob: a2b7640feebefcafbeaa15b19f7ba57eb22566ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ineusia <ineusia@yahoo.com>
Date: Mon, 26 Oct 2020 11:48:06 -0500
Subject: [PATCH] Add Destroy Speed API

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>

diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index 2c1efaecf220588d8b74946194bf340871e57004..653dcec33f83ab490af424faa6ede7df07d41742 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -678,5 +678,26 @@ public class CraftBlock implements Block {
     public String translationKey() {
         return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
     }
+
+    @Override
+    public float getDestroySpeed(ItemStack itemStack, boolean considerEnchants) {
+        net.minecraft.world.item.ItemStack nmsItemStack;
+        if (itemStack instanceof CraftItemStack) {
+            nmsItemStack = ((CraftItemStack) itemStack).handle;
+            if (nmsItemStack == null) {
+                nmsItemStack = net.minecraft.world.item.ItemStack.EMPTY;
+            }
+        } else {
+            nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
+        }
+        float speed = nmsItemStack.getDestroySpeed(this.getNMS().getBlock().defaultBlockState());
+        if (speed > 1.0F && considerEnchants) {
+            int enchantLevel = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.BLOCK_EFFICIENCY, nmsItemStack);
+            if (enchantLevel > 0) {
+                speed += enchantLevel * enchantLevel + 1;
+            }
+        }
+        return speed;
+    }
     // Paper end
 }