From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic 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 917b14b338e151c5168a5f7e8a68eea206857500..5770fbf1e5c32e342c8366688d8514b35f48a075 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -493,6 +493,19 @@ public final class CraftMagicNumbers implements UnsafeValues { return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial)); } + @Override + public com.google.common.collect.Multimap getItemAttributes(org.bukkit.Material material, org.bukkit.inventory.EquipmentSlot equipmentSlot) { + Item item = CraftMagicNumbers.getItem(material); + if (item == null) { + throw new IllegalArgumentException(material + " is not an item and therefore does not have attributes"); + } + com.google.common.collect.ImmutableMultimap.Builder attributeMapBuilder = com.google.common.collect.ImmutableMultimap.builder(); + item.getDefaultAttributeModifiers(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(equipmentSlot)).forEach((attributeBase, attributeModifier) -> { + attributeMapBuilder.put(org.bukkit.Registry.ATTRIBUTE.get(CraftNamespacedKey.fromMinecraft(net.minecraft.core.Registry.ATTRIBUTE.getKey(attributeBase))), org.bukkit.craftbukkit.attribute.CraftAttributeInstance.convert(attributeModifier)); + }); + return attributeMapBuilder.build(); + } + @Override public int getProtocolVersion() { return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion();