aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0656-Attributes-API-for-item-defaults.patch
blob: dd2a25bfc917497e866e6fe5bb8e688e724a381f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 8 May 2021 15:01:54 -0700
Subject: [PATCH] Attributes API for item defaults


diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index cdd1c1a5486d3a8a08642aec9a752b2eaeeb8f96..0a4a9a151c8f58cd44497bf43c3bed8f9a7d87c5 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -540,6 +540,19 @@ public final class CraftMagicNumbers implements UnsafeValues {
         return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial));
     }
 
+    @Override
+    public Multimap<Attribute, AttributeModifier> getItemAttributes(Material material, EquipmentSlot equipmentSlot) {
+        Item item = CraftMagicNumbers.getItem(material);
+        if (item == null) {
+            throw new IllegalArgumentException(material + " is not an item and therefore does not have attributes");
+        }
+        ImmutableMultimap.Builder<Attribute, AttributeModifier> attributeMapBuilder = ImmutableMultimap.builder();
+        item.getDefaultAttributeModifiers(CraftEquipmentSlot.getNMS(equipmentSlot)).forEach((attributeBase, attributeModifier) -> {
+            attributeMapBuilder.put(CraftAttributeMap.fromMinecraft(net.minecraft.core.Registry.ATTRIBUTE.getKey(attributeBase).toString()), CraftAttributeInstance.convert(attributeModifier, equipmentSlot));
+        });
+        return attributeMapBuilder.build();
+    }
+
     @Override
     public int getProtocolVersion() {
         return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion();