13
0
geforkt von Mirrors/Paper

Add more item use API (#10304)

Dieser Commit ist enthalten in:
Tamion 2024-04-06 23:44:27 +02:00
Ursprung 2089697232
Commit 613a19f70d
3 geänderte Dateien mit 49 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -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.
+ * <p>
+ * Only HAND or OFF_HAND may be used for the hand parameter.
+ * <p>
+ * When used on a player, the client will stop using the item
+ * if right click is held down.
+ * <p>
+ * 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.
+ * <p>
+ * 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

Datei anzeigen

@ -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

Datei anzeigen

@ -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 <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
@ -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();
+ }