mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-18 16:45:42 +01:00
43 lines
2.7 KiB
Diff
43 lines
2.7 KiB
Diff
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/net/minecraft/world/item/Item.java b/src/main/java/net/minecraft/world/item/Item.java
|
|
index 7c9ef73983c2c7f4b7386a472e5a79dce7fa7ea7..0486a3158eb81947f78cef11aa4d4f141c40dfb5 100644
|
|
--- a/src/main/java/net/minecraft/world/item/Item.java
|
|
+++ b/src/main/java/net/minecraft/world/item/Item.java
|
|
@@ -274,6 +274,7 @@ public class Item implements IMaterial {
|
|
return false;
|
|
}
|
|
|
|
+ public Multimap<AttributeBase, AttributeModifier> getAttributesForSlot(EnumItemSlot enumItemSlot) { return a(enumItemSlot); } // Paper - OBFHELPER
|
|
public Multimap<AttributeBase, AttributeModifier> a(EnumItemSlot enumitemslot) {
|
|
return ImmutableMultimap.of();
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index a386beea01056a7fb448596ba45342d832a4c63d..6cb8608f8238c4a8c346b92ba672c8cc1c0cbcc4 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -495,6 +495,19 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
return this.getItem(itemToBeRepaired.getType()).canRepair(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial));
|
|
}
|
|
|
|
+ @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) {
|
|
+ Item item = this.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<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> attributeMapBuilder = com.google.common.collect.ImmutableMultimap.builder();
|
|
+ item.getAttributesForSlot(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(equipmentSlot)).forEach((attributeBase, attributeModifier) -> {
|
|
+ attributeMapBuilder.put(org.bukkit.Registry.ATTRIBUTE.get(CraftNamespacedKey.fromMinecraft(net.minecraft.core.IRegistry.ATTRIBUTE.getKey(attributeBase))), org.bukkit.craftbukkit.attribute.CraftAttributeInstance.convert(attributeModifier));
|
|
+ });
|
|
+ return attributeMapBuilder.build();
|
|
+ }
|
|
+
|
|
@Override
|
|
public int getProtocolVersion() {
|
|
return net.minecraft.SharedConstants.getGameVersion().getProtocolVersion();
|