mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-31 12:41:25 +01:00
consider enchants for destroy speed
This commit is contained in:
parent
aaef1d5cca
commit
616b1f3cd0
@ -3,12 +3,13 @@ From: Ineusia <ineusia@yahoo.com>
|
|||||||
Date: Mon, 26 Oct 2020 11:37:48 -0500
|
Date: Mon, 26 Oct 2020 11:37:48 -0500
|
||||||
Subject: [PATCH] Add Destroy Speed API
|
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
|
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
|
||||||
index 7616c5601adee3cbe0e5f722646a2458b535ab77..6933fd6ad353a2d008c4a64c52a64bf36bd8035c 100644
|
index 7616c5601adee3cbe0e5f722646a2458b535ab77..7f1b6e0a397f97fce22e209cd3eefe1d8ffd1174 100644
|
||||||
--- a/src/main/java/org/bukkit/block/Block.java
|
--- a/src/main/java/org/bukkit/block/Block.java
|
||||||
+++ b/src/main/java/org/bukkit/block/Block.java
|
+++ b/src/main/java/org/bukkit/block/Block.java
|
||||||
@@ -581,5 +581,16 @@ public interface Block extends Metadatable {
|
@@ -581,5 +581,29 @@ public interface Block extends Metadatable {
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
String getTranslationKey();
|
String getTranslationKey();
|
||||||
@ -22,6 +23,19 @@ index 7616c5601adee3cbe0e5f722646a2458b535ab77..6933fd6ad353a2d008c4a64c52a64bf3
|
|||||||
+ * @return the speed that this Block will be mined by the given {@link ItemStack}
|
+ * @return the speed that this Block will be mined by the given {@link ItemStack}
|
||||||
+ */
|
+ */
|
||||||
+ @NotNull
|
+ @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
|
// Paper end
|
||||||
}
|
}
|
||||||
|
@ -3,25 +3,33 @@ From: Ineusia <ineusia@yahoo.com>
|
|||||||
Date: Mon, 26 Oct 2020 11:48:06 -0500
|
Date: Mon, 26 Oct 2020 11:48:06 -0500
|
||||||
Subject: [PATCH] Add Destroy Speed API
|
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
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
index 3baf7b75c65c9beba40945ba904315251b5b7a64..6fde449aca446001145e49b5859725f840cc317c 100644
|
index 3baf7b75c65c9beba40945ba904315251b5b7a64..83fe1f9f4f2ec6e1440575d621d836d5e968c790 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
@@ -757,5 +757,16 @@ public class CraftBlock implements Block {
|
@@ -757,5 +757,23 @@ public class CraftBlock implements Block {
|
||||||
public String getTranslationKey() {
|
public String getTranslationKey() {
|
||||||
return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
|
return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public float getDestroySpeed(ItemStack itemStack) {
|
+ public float getDestroySpeed(ItemStack itemStack, boolean considerEnchants) {
|
||||||
+ net.minecraft.server.ItemStack nmsItemStack;
|
+ net.minecraft.server.ItemStack nmsItemStack;
|
||||||
+ if (itemStack instanceof CraftItemStack) {
|
+ if (itemStack instanceof CraftItemStack) {
|
||||||
+ nmsItemStack = ((CraftItemStack) itemStack).getHandle();
|
+ nmsItemStack = ((CraftItemStack) itemStack).getHandle();
|
||||||
+ } else {
|
+ } else {
|
||||||
+ nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
+ 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
|
// Paper end
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user