ItemStack#getMaxItemUseDuration

Allows you to determine how long it takes to use a usable/consumable item
This commit is contained in:
Aikar 2018-06-05 23:01:16 -04:00
parent b97e5124e4
commit 2e423c8954
No known key found for this signature in database
GPG Key ID: 401ADFC9891FAAFE
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,29 @@
From dca114a3fa37ef6bb99e05cce391850e6cdb0937 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 5 Jun 2018 22:59:50 -0400
Subject: [PATCH] ItemStack#getMaxItemUseDuration
Allows you to determine how long it takes to use a usable/consumable item
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index 567706ac..82240129 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -632,5 +632,14 @@ public class ItemStack implements Cloneable, ConfigurationSerializable {
public String getI18NDisplayName() {
return Bukkit.getServer().getItemFactory().getI18NDisplayName(this);
}
+
+ public int getMaxItemUseDuration() {
+ Material material = Material.getMaterial(type);
+ if (material == null || !material.isItem()) {
+ return 0;
+ }
+ // Requires access to NMS
+ return ensureServerConversions().getMaxItemUseDuration();
+ }
// Paper end
}
--
2.17.1

View File

@ -0,0 +1,40 @@
From 3b7b48e9015f695e3e59130a51a7a06dae7cbc11 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 5 Jun 2018 23:00:29 -0400
Subject: [PATCH] ItemStack#getMaxItemUseDuration
Allows you to determine how long it takes to use a usable/consumable item
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 985237d86..908fb280a 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -560,6 +560,7 @@ public final class ItemStack {
this.getItem().b(this, world, entityhuman);
}
+ public int getItemUseMaxDuration() { return m(); } // Paper - OBFHELPER
public int m() {
return this.getItem().e(this);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index aa99254ff..be6589dbf 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -180,6 +180,13 @@ public final class CraftItemStack extends ItemStack {
return (handle == null) ? Material.AIR.getMaxStackSize() : handle.getItem().getMaxStackSize();
}
+ // Paper start
+ @Override
+ public int getMaxItemUseDuration() {
+ return handle == null ? 0 : handle.getItemUseMaxDuration();
+ }
+ // Paper end
+
@Override
public void addUnsafeEnchantment(Enchantment ench, int level) {
Validate.notNull(ench, "Cannot add null enchantment");
--
2.17.1