2021-06-11 14:02:28 +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: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
|
2021-07-18 09:41:53 +02:00
|
|
|
index 24f5f6c7b1ca21515cdeb053f8e1f56004c800d0..7a8db8d481e9487ea83a640af208242f4987ad28 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- 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 {
|
2021-06-15 04:59:31 +02:00
|
|
|
return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial));
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public com.google.common.collect.Multimap<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> getItemAttributes(org.bukkit.Material material, org.bukkit.inventory.EquipmentSlot equipmentSlot) {
|
2021-06-15 04:59:31 +02:00
|
|
|
+ Item item = CraftMagicNumbers.getItem(material);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (item == null) {
|
|
|
|
+ throw new IllegalArgumentException(material + " is not an item and therefore does not have attributes");
|
|
|
|
+ }
|
|
|
|
+ com.google.common.collect.ImmutableMultimap.Builder<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> attributeMapBuilder = com.google.common.collect.ImmutableMultimap.builder();
|
2021-06-15 04:59:31 +02:00
|
|
|
+ item.getDefaultAttributeModifiers(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(equipmentSlot)).forEach((attributeBase, attributeModifier) -> {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ 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();
|