2022-01-01 04:05:42 +01:00
|
|
|
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
|
2024-04-06 21:53:39 +02:00
|
|
|
index 79977c677b4348bbfc8dcd4cb5e4c01c6fceb354..31898e8425c524277bd07b139a898fe5f9fe344d 100644
|
2022-01-01 04:05:42 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2024-04-06 21:53:39 +02:00
|
|
|
@@ -564,6 +564,19 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
2022-01-01 04:05:42 +01:00
|
|
|
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) -> {
|
2023-09-23 04:06:03 +02:00
|
|
|
+ attributeMapBuilder.put(CraftAttribute.stringToBukkit(net.minecraft.core.registries.BuiltInRegistries.ATTRIBUTE.getKey(attributeBase).toString()), CraftAttributeInstance.convert(attributeModifier, equipmentSlot));
|
2022-01-01 04:05:42 +01:00
|
|
|
+ });
|
|
|
|
+ return attributeMapBuilder.build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public int getProtocolVersion() {
|
|
|
|
return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion();
|