2024-04-26 08:10:38 +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] Fix item default attributes API
|
|
|
|
|
|
|
|
(previously added this API but upstream also added it)
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2024-04-30 10:21:16 +02:00
|
|
|
index 18d46779f56f97aae264325a5202568d8a06a747..abc5f221e90fb39fe2fa192bcbd0a3bb75444d64 100644
|
2024-04-26 08:10:38 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2024-04-30 10:21:16 +02:00
|
|
|
@@ -395,9 +395,14 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
2024-04-26 08:10:38 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(Material material, EquipmentSlot slot) {
|
|
|
|
- ImmutableMultimap.Builder<Attribute, AttributeModifier> defaultAttributes = ImmutableMultimap.builder();
|
|
|
|
-
|
|
|
|
- ItemAttributeModifiers nmsDefaultAttributes = CraftMagicNumbers.getItem(material).getDefaultAttributeModifiers();
|
|
|
|
+ // Paper start - fix item default attribute API
|
|
|
|
+ final Item item = CraftMagicNumbers.getItem(material);
|
|
|
|
+ if (item == null) {
|
|
|
|
+ throw new IllegalArgumentException(material + " is not an item and therefore does not have attributes");
|
|
|
|
+ }
|
|
|
|
+ final ImmutableMultimap.Builder<Attribute, AttributeModifier> defaultAttributes = ImmutableMultimap.builder();
|
|
|
|
+ ItemAttributeModifiers nmsDefaultAttributes = item.components().getOrDefault(net.minecraft.core.component.DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
|
|
|
+ // Paper end - fix item default attribute API
|
|
|
|
nmsDefaultAttributes.forEach(CraftEquipmentSlot.getNMS(slot), (key, value) -> {
|
|
|
|
Attribute attribute = CraftAttribute.minecraftToBukkit(key.value());
|
|
|
|
defaultAttributes.put(attribute, CraftAttributeInstance.convert(value, slot));
|