54 lines
2 KiB
Diff
54 lines
2 KiB
Diff
![]() |
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.
|
||
|
|
||
|
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 1c6abeff5b541cdea914ac956f2ab1d2e1c5769f..de52fdc1c94f69de7c5c5099fc586fdeba60b6fa 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||
|
@@ -866,4 +866,38 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||
|
getHandle().setShieldBlockingDelay(delay);
|
||
|
}
|
||
|
// Paper end
|
||
|
+
|
||
|
+ // Paper start - active item API
|
||
|
+ @Override
|
||
|
+ public ItemStack getActiveItem() {
|
||
|
+ return this.getHandle().getUseItem().asBukkitMirror();
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public int getActiveItemRemainingTime() {
|
||
|
+ return this.getHandle().getUseItemRemainingTicks();
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ 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;
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public int getActiveItemUsedTime() {
|
||
|
+ return this.getHandle().getTicksUsingItem();
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public boolean hasActiveItem() {
|
||
|
+ return this.getHandle().isUsingItem();
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public org.bukkit.inventory.EquipmentSlot getActiveItemHand() {
|
||
|
+ return org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(this.getHandle().getUsedItemHand());
|
||
|
+ }
|
||
|
+ // Paper end - active item API
|
||
|
}
|