consider enchants for destroy speed

This commit is contained in:
Jake Potrebic 2021-01-03 23:18:34 -08:00
parent 4c24cd0ef3
commit aad9b036bc
2 changed files with 25 additions and 3 deletions

View file

@ -3,6 +3,7 @@ From: Ineusia <ineusia@yahoo.com>
Date: Mon, 26 Oct 2020 11:37:48 -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/block/Block.java b/src/main/java/org/bukkit/block/Block.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@ -22,6 +23,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @return the speed that this Block will be mined by the given {@link ItemStack}
+ */
+ @NotNull
+ float getDestroySpeed(@NotNull ItemStack itemStack);
+ public default float getDestroySpeed(@NotNull ItemStack itemStack) {
+ return getDestroySpeed(itemStack, false);
+ }
+
+ /**
+ * Gets the speed at which this blook will be destroyed by a given {@link org.bukkit.inventory.ItemStack}
+ * <p>
+ * Default value is 1.0
+ * @param itemStack {@link org.bukkit.inventory.ItemStack} used to mine this Block
+ * @param considerEnchants true to look at enchants on the itemstack
+ * @return the speed that this Block will be mined by the given {@link org.bukkit.inventory.ItemStack}
+ */
+ @NotNull
+ float getDestroySpeed(@NotNull ItemStack itemStack, boolean considerEnchants);
// Paper end
}

View file

@ -3,6 +3,7 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@ -14,14 +15,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
+
+ @Override
+ public float getDestroySpeed(ItemStack itemStack) {
+ public float getDestroySpeed(ItemStack itemStack, boolean considerEnchants) {
+ net.minecraft.server.ItemStack nmsItemStack;
+ if (itemStack instanceof CraftItemStack) {
+ nmsItemStack = ((CraftItemStack) itemStack).getHandle();
+ } else {
+ nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
+ }
+ return nmsItemStack.getItem().getDestroySpeed(nmsItemStack, this.getNMSBlock().getBlockData());
+ float speed = nmsItemStack.getItem().getDestroySpeed(nmsItemStack, this.getNMSBlock().getBlockData());
+ if (speed > 1.0F && considerEnchants) {
+ int enchantLevel = net.minecraft.server.EnchantmentManager.getEnchantmentLevel(net.minecraft.server.Enchantments.DIG_SPEED, nmsItemStack);
+ if (enchantLevel > 0) {
+ speed += enchantLevel * enchantLevel + 1;
+ }
+ }
+ return speed;
+ }
// Paper end
}