From 613a19f70dbb99f743d1b5842b44d621464b5d94 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:44:27 +0200 Subject: [PATCH] Add more item use API (#10304) --- .../api/LivingEntity-Active-Item-API.patch | 29 +++++++++++++++++++ patches/api/Missing-Entity-API.patch | 2 +- .../server/LivingEntity-Active-Item-API.patch | 19 ++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/patches/api/LivingEntity-Active-Item-API.patch b/patches/api/LivingEntity-Active-Item-API.patch index 2557048d86..4bf3bba61a 100644 --- a/patches/api/LivingEntity-Active-Item-API.patch +++ b/patches/api/LivingEntity-Active-Item-API.patch @@ -63,6 +63,35 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + // Paper start - active item API + /** ++ * Starts using the item in the specified hand, making it the ++ * currently active item. When, for example, called on a skeleton, ++ * this will cause it to start drawing its bow. ++ *

++ * Only HAND or OFF_HAND may be used for the hand parameter. ++ *

++ * When used on a player, the client will stop using the item ++ * if right click is held down. ++ *

++ * This method does not make any guarantees about the effect of this method ++ * as such depends on the entity and its state. ++ * ++ * @param hand the hand that contains the item to be used ++ */ ++ @org.jetbrains.annotations.ApiStatus.Experimental ++ void startUsingItem(@NotNull org.bukkit.inventory.EquipmentSlot hand); ++ ++ /** ++ * Finishes using the currently active item. When, for example, a ++ * skeleton is drawing its bow, this will cause it to release and ++ * fire the arrow. ++ *

++ * This method does not make any guarantees about the effect of this method ++ * as such depends on the entity and its state. ++ */ ++ @org.jetbrains.annotations.ApiStatus.Experimental ++ void completeUsingActiveItem(); ++ ++ /** + * Gets the item being actively "used" or consumed. + * + * @return the item diff --git a/patches/api/Missing-Entity-API.patch b/patches/api/Missing-Entity-API.patch index f8b3a61c7c..e326a52d24 100644 --- a/patches/api/Missing-Entity-API.patch +++ b/patches/api/Missing-Entity-API.patch @@ -661,7 +661,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - active item API /** - * Gets the item being actively "used" or consumed. + * Starts using the item in the specified hand, making it the diff --git a/src/main/java/org/bukkit/entity/Llama.java b/src/main/java/org/bukkit/entity/Llama.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/entity/Llama.java diff --git a/patches/server/LivingEntity-Active-Item-API.patch b/patches/server/LivingEntity-Active-Item-API.patch index 56c80ebd5d..8b59ac0d5c 100644 --- a/patches/server/LivingEntity-Active-Item-API.patch +++ b/patches/server/LivingEntity-Active-Item-API.patch @@ -6,6 +6,10 @@ Subject: [PATCH] LivingEntity Active Item API API relating to items being actively used by a LivingEntity such as a bow or eating food. +== AT == +public net/minecraft/world/entity/LivingEntity completeUsingItem()V +public net/minecraft/server/level/ServerPlayer completeUsingItem()V + Co-authored-by: Jake Potrebic diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -19,6 +23,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + // Paper start - active item API + @Override ++ public void startUsingItem(org.bukkit.inventory.EquipmentSlot hand) { ++ Preconditions.checkArgument(hand != null, "hand must not be null"); ++ switch (hand) { ++ case HAND -> getHandle().startUsingItem(InteractionHand.MAIN_HAND); ++ case OFF_HAND -> getHandle().startUsingItem(InteractionHand.OFF_HAND); ++ default -> throw new IllegalArgumentException("hand may only be HAND or OFF_HAND"); ++ } ++ } ++ ++ @Override ++ public void completeUsingActiveItem() { ++ getHandle().completeUsingItem(); ++ } ++ ++ @Override + public ItemStack getActiveItem() { + return this.getHandle().getUseItem().asBukkitMirror(); + }