From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 29 Jun 2018 00:21:28 -0400
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 <jake.m.potrebic@gmail.com>
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index bb81e0bfe0692e8f8421758cd21c003978853a08..8f43b8e3ba64ac150f35c6056178934e5de04b2d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -853,4 +853,53 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
getHandle().setShieldBlockingDelay(delay);
}
// Paper end
+
+ // 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");
+ }
+ public void completeUsingActiveItem() {
+ getHandle().completeUsingItem();
+ public ItemStack getActiveItem() {
+ return this.getHandle().getUseItem().asBukkitMirror();
+ public int getActiveItemRemainingTime() {
+ return this.getHandle().getUseItemRemainingTicks();
+ public void setActiveItemRemainingTime(final int ticks) {
+ Preconditions.checkArgument(ticks >= 0, "ticks must be >= 0");
+ Preconditions.checkArgument(ticks <= this.getHandle().getUseItem().getUseDuration(), "ticks must be <= item use duration");
+ this.getHandle().useItemRemaining = ticks;
+ public int getActiveItemUsedTime() {
+ return this.getHandle().getTicksUsingItem();
+ public boolean hasActiveItem() {
+ return this.getHandle().isUsingItem();
+ public org.bukkit.inventory.EquipmentSlot getActiveItemHand() {
+ return org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(this.getHandle().getUsedItemHand());
+ // Paper end - active item API