diff --git a/patches/api/Add-Destroy-Speed-API.patch b/patches/api/Add-Destroy-Speed-API.patch index 45a4c573b7..5bf36ae3a6 100644 --- a/patches/api/Add-Destroy-Speed-API.patch +++ b/patches/api/Add-Destroy-Speed-API.patch @@ -10,32 +10,68 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java @@ -0,0 +0,0 @@ public interface Block extends Metadatable, Translatable, net.kyori.adventure.tr - @NotNull @Deprecated(forRemoval = true) String getTranslationKey(); + // Paper end + ++ // Paper start - destroy speed API + /** + * Gets the speed at which this block will be destroyed by a given {@link ItemStack} -+ * -+ *

Default value is 1.0

++ *

++ * Default value is 1.0 + * + * @param itemStack {@link ItemStack} used to mine this Block + * @return the speed that this Block will be mined by the given {@link ItemStack} + */ -+ @NotNull -+ public default float getDestroySpeed(@NotNull ItemStack itemStack) { -+ return getDestroySpeed(itemStack, false); ++ default float getDestroySpeed(final @NotNull ItemStack itemStack) { ++ return this.getBlockData().getDestroySpeed(itemStack); + } + + /** -+ * Gets the speed at which this blook will be destroyed by a given {@link org.bukkit.inventory.ItemStack} ++ * Gets the speed at which this block will be destroyed by a given {@link ItemStack} + *

+ * Default value is 1.0 -+ * @param itemStack {@link org.bukkit.inventory.ItemStack} used to mine this Block ++ * ++ * @param itemStack {@link 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} ++ * @return the speed that this Block will be mined by the given {@link ItemStack} + */ -+ @NotNull -+ float getDestroySpeed(@NotNull ItemStack itemStack, boolean considerEnchants); - // Paper end ++ default float getDestroySpeed(@NotNull ItemStack itemStack, boolean considerEnchants) { ++ return this.getBlockData().getDestroySpeed(itemStack, considerEnchants); ++ } ++ // Paper end - destroy speed API + } +diff --git a/src/main/java/org/bukkit/block/data/BlockData.java b/src/main/java/org/bukkit/block/data/BlockData.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/block/data/BlockData.java ++++ b/src/main/java/org/bukkit/block/data/BlockData.java +@@ -0,0 +0,0 @@ public interface BlockData extends Cloneable { + @NotNull + @ApiStatus.Experimental + BlockState createBlockState(); ++ ++ // Paper start - destroy speed API ++ /** ++ * Gets the speed at which this block will be destroyed by a given {@link ItemStack} ++ *

++ * Default value is 1.0 ++ * ++ * @param itemStack {@link ItemStack} used to mine this Block ++ * @return the speed that this Block will be mined by the given {@link ItemStack} ++ */ ++ default float getDestroySpeed(final @NotNull ItemStack itemStack) { ++ return this.getDestroySpeed(itemStack, false); ++ } ++ ++ /** ++ * Gets the speed at which this block will be destroyed by a given {@link ItemStack} ++ *

++ * Default value is 1.0 ++ * ++ * @param itemStack {@link 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 ItemStack} ++ */ ++ float getDestroySpeed(@NotNull ItemStack itemStack, boolean considerEnchants); ++ // Paper end - destroy speed API } diff --git a/patches/api/Block-Ticking-API.patch b/patches/api/Block-Ticking-API.patch index 233553df59..ec40b4ec81 100644 --- a/patches/api/Block-Ticking-API.patch +++ b/patches/api/Block-Ticking-API.patch @@ -35,9 +35,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/block/data/BlockData.java +++ b/src/main/java/org/bukkit/block/data/BlockData.java @@ -0,0 +0,0 @@ public interface BlockData extends Cloneable { - @NotNull - @ApiStatus.Experimental - BlockState createBlockState(); + */ + float getDestroySpeed(@NotNull ItemStack itemStack, boolean considerEnchants); + // Paper end - destroy speed API + + // Paper start - Tick API + /** @@ -47,5 +47,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @return is ticked randomly + */ + boolean isRandomlyTicked(); -+ // Paper end ++ // Paper end - Tick API } diff --git a/patches/server/Add-Block-isValidTool.patch b/patches/server/Add-Block-isValidTool.patch index 4e4985df4f..7a21e34c08 100644 --- a/patches/server/Add-Block-isValidTool.patch +++ b/patches/server/Add-Block-isValidTool.patch @@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -0,0 +0,0 @@ public class CraftBlock implements Block { - } - return speed; + public String translationKey() { + return this.getNMS().getBlock().getDescriptionId(); } + + public boolean isValidTool(ItemStack itemStack) { diff --git a/patches/server/Add-Destroy-Speed-API.patch b/patches/server/Add-Destroy-Speed-API.patch index 5fbd0c3048..c2a4f4d919 100644 --- a/patches/server/Add-Destroy-Speed-API.patch +++ b/patches/server/Add-Destroy-Speed-API.patch @@ -5,27 +5,20 @@ Subject: [PATCH] Add Destroy Speed API Co-authored-by: Jake Potrebic -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/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -@@ -0,0 +0,0 @@ public class CraftBlock implements Block { - public String translationKey() { - return this.getNMS().getBlock().getDescriptionId(); +--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +@@ -0,0 +0,0 @@ public class CraftBlockData implements BlockData { + public BlockState createBlockState() { + return CraftBlockStates.getBlockState(this.state, null); } + ++ // Paper start - destroy speed API + @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()); ++ public float getDestroySpeed(final ItemStack itemStack, final boolean considerEnchants) { ++ net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.unwrap(itemStack); ++ float speed = nmsItemStack.getDestroySpeed(this.state); + 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) { @@ -34,5 +27,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + return speed; + } - // Paper end ++ // Paper end - destroy speed API } diff --git a/patches/server/Block-Ticking-API.patch b/patches/server/Block-Ticking-API.patch index 26779691a1..2e064734ba 100644 --- a/patches/server/Block-Ticking-API.patch +++ b/patches/server/Block-Ticking-API.patch @@ -35,14 +35,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -0,0 +0,0 @@ public class CraftBlockData implements BlockData { - public BlockState createBlockState() { - return CraftBlockStates.getBlockState(this.state, null); + return speed; } + // Paper end - destroy speed API + + // Paper start - Block tick API + @Override + public boolean isRandomlyTicked() { + return this.state.isRandomlyTicking(); + } -+ // Paper end ++ // Paper end - Block tick API } diff --git a/patches/server/MC-Utils.patch b/patches/server/MC-Utils.patch index a9bc05599f..850a1f90cd 100644 --- a/patches/server/MC-Utils.patch +++ b/patches/server/MC-Utils.patch @@ -7423,6 +7423,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end } +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +@@ -0,0 +0,0 @@ import org.bukkit.material.MaterialData; + @DelegateDeserialization(ItemStack.class) + public final class CraftItemStack extends ItemStack { + ++ // Paper start - MC Utils ++ public static net.minecraft.world.item.ItemStack unwrap(ItemStack bukkit) { ++ if (bukkit instanceof CraftItemStack craftItemStack) { ++ return craftItemStack.handle != null ? craftItemStack.handle : net.minecraft.world.item.ItemStack.EMPTY; ++ } else { ++ return asNMSCopy(bukkit); ++ } ++ } ++ // Paper end - MC Utils ++ + public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) { + if (original instanceof CraftItemStack) { + CraftItemStack stack = (CraftItemStack) original; diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java