diff --git a/patches/api/Add-isCollidable-methods-to-various-places.patch b/patches/api/Add-isCollidable-methods-to-various-places.patch index 370f7137f6..54416c2773 100644 --- a/patches/api/Add-isCollidable-methods-to-various-places.patch +++ b/patches/api/Add-isCollidable-methods-to-various-places.patch @@ -10,7 +10,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +++ b/src/main/java/org/bukkit/Material.java @@ -0,0 +0,0 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla public Multimap getItemAttributes(@NotNull EquipmentSlot equipmentSlot) { - return Bukkit.getUnsafe().getItemAttributes(this, equipmentSlot); + return this.getDefaultAttributeModifiers(equipmentSlot); } + + /** diff --git a/patches/api/Attributes-API-for-item-defaults.patch b/patches/api/Attributes-API-for-item-defaults.patch index 8465c006a3..f84bddf771 100644 --- a/patches/api/Attributes-API-for-item-defaults.patch +++ b/patches/api/Attributes-API-for-item-defaults.patch @@ -3,6 +3,7 @@ From: Jake Potrebic Date: Sat, 8 May 2021 15:02:00 -0700 Subject: [PATCH] Attributes API for item defaults +(Now replaced by upstream's API) diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 @@ -23,33 +24,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * @deprecated use {@link #getDefaultAttributeModifiers(EquipmentSlot)} + */ + @NotNull -+ @Deprecated ++ @Deprecated(forRemoval = true, since = "1.20.5") + public Multimap getItemAttributes(@NotNull EquipmentSlot equipmentSlot) { -+ return Bukkit.getUnsafe().getItemAttributes(this, equipmentSlot); ++ return this.getDefaultAttributeModifiers(equipmentSlot); + } // Paper end /** -diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/UnsafeValues.java -+++ b/src/main/java/org/bukkit/UnsafeValues.java -@@ -0,0 +0,0 @@ public interface UnsafeValues { - */ - public boolean isValidRepairItemStack(@org.jetbrains.annotations.NotNull ItemStack itemToBeRepaired, @org.jetbrains.annotations.NotNull ItemStack repairMaterial); - -+ /** -+ * Returns an immutable multimap of attributes for the material and slot. -+ * {@link Material#isItem()} must be true for this material. -+ * -+ * @param material the material -+ * @param equipmentSlot the slot to get the attributes for -+ * @throws IllegalArgumentException if {@link Material#isItem()} is false -+ * @return an immutable multimap of attributes -+ */ -+ @org.jetbrains.annotations.NotNull -+ public Multimap getItemAttributes(@org.jetbrains.annotations.NotNull Material material, @org.jetbrains.annotations.NotNull EquipmentSlot equipmentSlot); -+ - /** - * Returns the server's protocol version. - * diff --git a/patches/server/Attributes-API-for-item-defaults.patch b/patches/server/Attributes-API-for-item-defaults.patch deleted file mode 100644 index 1111aa83bd..0000000000 --- a/patches/server/Attributes-API-for-item-defaults.patch +++ /dev/null @@ -1,30 +0,0 @@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { - return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial)); - } - -+ @Override -+ public Multimap 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 attributeMapBuilder = ImmutableMultimap.builder(); -+ item.getDefaultAttributeModifiers(CraftEquipmentSlot.getNMS(equipmentSlot)).forEach((attributeBase, attributeModifier) -> { -+ attributeMapBuilder.put(CraftAttribute.stringToBukkit(net.minecraft.core.registries.BuiltInRegistries.ATTRIBUTE.getKey(attributeBase).toString()), CraftAttributeInstance.convert(attributeModifier, equipmentSlot)); -+ }); -+ return attributeMapBuilder.build(); -+ } -+ - @Override - public int getProtocolVersion() { - return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion(); diff --git a/patches/server/Fix-item-default-attributes-API.patch b/patches/server/Fix-item-default-attributes-API.patch new file mode 100644 index 0000000000..94cd302132 --- /dev/null +++ b/patches/server/Fix-item-default-attributes-API.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +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 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { + + @Override + public Multimap getDefaultAttributeModifiers(Material material, EquipmentSlot slot) { +- ImmutableMultimap.Builder 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 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));