Paper/patches/server-remapped/0229-LivingEntity-Hand-Raised-Item-Use-API.patch
2021-06-11 14:02:28 +02:00

69 lines
2.8 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 Hand Raised/Item Use API
How long an entity has raised hands to charge an attack or use an item
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 04489a915d11ba970a5188a5a913432ab4ef9faa..205c639d26652befebae925fc6e40976c370710f 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -209,7 +209,7 @@ public abstract class LivingEntity extends Entity {
private float speed;
private int noJumpDelay;
private float absorptionAmount;
- protected ItemStack useItem;
+ public ItemStack useItem; // Paper - public
protected int useItemRemaining;
protected int fallFlyTicks;
private BlockPos lastPos;
@@ -3291,10 +3291,12 @@ public abstract class LivingEntity extends Entity {
return this.useItem;
}
+ public int getItemUseRemainingTime() { return this.getUseItemRemainingTicks(); } // Paper - OBFHELPER
public int getUseItemRemainingTicks() {
return this.useItemRemaining;
}
+ public int getHandRaisedTime() { return this.getTicksUsingItem(); } // Paper - OBFHELPER
public int getTicksUsingItem() {
return this.isUsingItem() ? this.useItem.getUseDuration() - this.getUseItemRemainingTicks() : 0;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 663887d9aecc2823fe7d02a9b108a291cd27102c..6dd7a722e10a2727f68318b880f2726bb816f198 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -709,5 +709,30 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
public void setShieldBlockingDelay(int delay) {
getHandle().setShieldBlockingDelay(delay);
}
+
+ @Override
+ public ItemStack getActiveItem() {
+ return getHandle().useItem.asBukkitMirror();
+ }
+
+ @Override
+ public int getItemUseRemainingTime() {
+ return getHandle().getItemUseRemainingTime();
+ }
+
+ @Override
+ public int getHandRaisedTime() {
+ return getHandle().getHandRaisedTime();
+ }
+
+ @Override
+ public boolean isHandRaised() {
+ return getHandle().isUsingItem();
+ }
+
+ @Override
+ public org.bukkit.inventory.EquipmentSlot getHandRaised() {
+ return getHandle().getUsedItemHand() == net.minecraft.world.InteractionHand.MAIN_HAND ? org.bukkit.inventory.EquipmentSlot.HAND : org.bukkit.inventory.EquipmentSlot.OFF_HAND;
+ }
// Paper end
}