2024-05-23 20:44:07 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Sat, 8 May 2021 15:02:00 -0700
|
|
|
|
Subject: [PATCH] Improve item default attribute API
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
|
2024-10-21 00:06:54 +02:00
|
|
|
index 052d319e69f22277cb6e379e47380c7dc466d120..eec1e53ce607d36a2e72f16a4a351869fd2f609f 100644
|
2024-05-23 20:44:07 +02:00
|
|
|
--- a/src/main/java/org/bukkit/Material.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Material.java
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -4724,6 +4724,23 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla
|
2024-05-23 20:44:07 +02:00
|
|
|
}
|
|
|
|
// Paper end - item rarity API
|
|
|
|
|
|
|
|
+ // Paper start - item default attributes API
|
|
|
|
+ /**
|
|
|
|
+ * Returns an immutable multimap of attributes for the slot.
|
|
|
|
+ * {@link #isItem()} must be true for this material.
|
|
|
|
+ *
|
|
|
|
+ * @param equipmentSlot the slot to get the attributes for
|
|
|
|
+ * @throws IllegalArgumentException if {@link #isItem()} is false
|
|
|
|
+ * @return an immutable multimap of attributes
|
|
|
|
+ * @deprecated use {@link #getDefaultAttributeModifiers(EquipmentSlot)}
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ @Deprecated(forRemoval = true, since = "1.20.5")
|
|
|
|
+ public Multimap<Attribute, AttributeModifier> getItemAttributes(@NotNull EquipmentSlot equipmentSlot) {
|
|
|
|
+ return this.getDefaultAttributeModifiers(equipmentSlot);
|
|
|
|
+ }
|
|
|
|
+ // Paper end - item default attributes API
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Do not use for any reason.
|
|
|
|
*
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -5431,13 +5448,34 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla
|
2024-05-23 20:44:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - improve default item attribute API
|
|
|
|
+ /**
|
|
|
|
+ * Return an immutable copy of all default {@link Attribute}s and their {@link AttributeModifier}s.
|
|
|
|
+ * <p>
|
|
|
|
+ * Default attributes are those that are always preset on some items, unless
|
|
|
|
+ * they are specifically overridden on that {@link ItemStack}. Examples include
|
|
|
|
+ * the attack damage on weapons or the armor value on armor.
|
|
|
|
+ * <p>
|
|
|
|
+ * Only available when {@link #isItem()} is true.
|
|
|
|
+ *
|
|
|
|
+ * @return the immutable {@link Multimap} with the respective default
|
|
|
|
+ * Attributes and modifiers, or an empty map if no attributes are set.
|
|
|
|
+ */
|
|
|
|
+ public @NotNull @org.jetbrains.annotations.Unmodifiable Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers() {
|
|
|
|
+ final ItemType type = this.asItemType();
|
|
|
|
+ Preconditions.checkArgument(type != null, "The Material is not an item!");
|
|
|
|
+ return type.getDefaultAttributeModifiers();
|
|
|
|
+ }
|
|
|
|
+ // Paper end - improve default item attribute API
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Return an immutable copy of all default {@link Attribute}s and their
|
|
|
|
* {@link AttributeModifier}s for a given {@link EquipmentSlot}.
|
|
|
|
- *
|
|
|
|
- * Default attributes are those that are always preset on some items, such
|
|
|
|
- * as the attack damage on weapons or the armor value on armor.
|
|
|
|
- *
|
|
|
|
+ * <p>
|
|
|
|
+ * Default attributes are those that are always preset on some items, unless
|
|
|
|
+ * they are specifically overridden on that {@link ItemStack}. Examples include
|
|
|
|
+ * the attack damage on weapons or the armor value on armor.
|
|
|
|
+ * <p>
|
|
|
|
* Only available when {@link #isItem()} is true.
|
|
|
|
*
|
|
|
|
* @param slot the {@link EquipmentSlot} to check
|
|
|
|
diff --git a/src/main/java/org/bukkit/inventory/ItemType.java b/src/main/java/org/bukkit/inventory/ItemType.java
|
2024-10-21 00:06:54 +02:00
|
|
|
index 9077257ed935a26af057b9d090f7d819956ebbce..c42cfa76ff73a3ce8a164cb94a9c3f553b005ea5 100644
|
2024-05-23 20:44:07 +02:00
|
|
|
--- a/src/main/java/org/bukkit/inventory/ItemType.java
|
|
|
|
+++ b/src/main/java/org/bukkit/inventory/ItemType.java
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -2256,6 +2256,21 @@ public interface ItemType extends Keyed, Translatable, net.kyori.adventure.trans
|
2024-05-23 20:44:07 +02:00
|
|
|
// @NotNull
|
|
|
|
// EquipmentSlot getEquipmentSlot();
|
|
|
|
|
|
|
|
+ // Paper start - improve default item attribute API
|
|
|
|
+ /**
|
|
|
|
+ * Return an immutable copy of all default {@link Attribute}s and their
|
|
|
|
+ * {@link AttributeModifier}s.
|
|
|
|
+ * <p>
|
|
|
|
+ * Default attributes are those that are always preset on some items, unless
|
|
|
|
+ * they are specifically overridden on that {@link ItemStack}. Examples include
|
|
|
|
+ * the attack damage on weapons or the armor value on armor.
|
|
|
|
+ *
|
|
|
|
+ * @return the immutable {@link Multimap} with the respective default
|
|
|
|
+ * Attributes and modifiers, or an empty map if no attributes are set.
|
|
|
|
+ */
|
|
|
|
+ @NotNull @org.jetbrains.annotations.Unmodifiable Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers();
|
|
|
|
+ // Paper end - improve default item attribute API
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Return an immutable copy of all default {@link Attribute}s and their
|
|
|
|
* {@link AttributeModifier}s for a given {@link EquipmentSlot}.
|