2024-04-06 21:53:39 +02:00
|
|
|
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.
|
|
|
|
|
2024-04-06 23:44:27 +02:00
|
|
|
== AT ==
|
|
|
|
public net/minecraft/world/entity/LivingEntity completeUsingItem()V
|
|
|
|
public net/minecraft/server/level/ServerPlayer completeUsingItem()V
|
|
|
|
|
2024-04-06 21:53:39 +02:00
|
|
|
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
|
2024-10-21 00:06:54 +02:00
|
|
|
index 73c72b8cdece357193afb3c5f474e055086311ea..2612e5016646591bb65ac255804b612b348a32fd 100644
|
2024-04-06 21:53:39 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -864,4 +864,53 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
2024-04-06 21:53:39 +02:00
|
|
|
getHandle().setShieldBlockingDelay(delay);
|
|
|
|
}
|
|
|
|
// Paper end
|
|
|
|
+
|
|
|
|
+ // Paper start - active item API
|
|
|
|
+ @Override
|
2024-04-06 23:44:27 +02:00
|
|
|
+ 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
|
2024-04-06 21:53:39 +02:00
|
|
|
+ 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");
|
2024-06-14 14:11:52 +02:00
|
|
|
+ Preconditions.checkArgument(ticks <= this.getHandle().getUseItem().getUseDuration(this.getHandle()), "ticks must be <= item use duration");
|
2024-04-06 21:53:39 +02:00
|
|
|
+ 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
|
|
|
|
}
|