mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-04 01:39:54 +01:00
46 lines
3.2 KiB
Diff
46 lines
3.2 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/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java
|
|
index 7e3826b271b2db3b48e6e21ac2e66911bf8993aa..393a19335c52b6e63d37aacdfbeff93e1795c421 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java
|
|
@@ -72,4 +72,10 @@ public class CraftAttributeInstance implements AttributeInstance {
|
|
public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms) {
|
|
return new AttributeModifier(nms.getId(), nms.getName(), nms.getAmount(), AttributeModifier.Operation.values()[nms.getOperation().ordinal()]);
|
|
}
|
|
+
|
|
+ // Paper start - construct using slot
|
|
+ public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms, org.bukkit.inventory.EquipmentSlot slot) {
|
|
+ return new AttributeModifier(nms.getId(), nms.getName(), nms.getAmount(), AttributeModifier.Operation.values()[nms.getOperation().ordinal()], slot);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index d88515fcaab8672bc1ace12554372a0b6ab57947..ff1f178b69efc4f167cb34095b7fd3acd4d00680 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -499,6 +499,19 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(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 = CraftMagicNumbers.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.getDefaultAttributeModifiers(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(equipmentSlot)).forEach((attributeBase, attributeModifier) -> {
|
|
+ attributeMapBuilder.put(org.bukkit.Registry.ATTRIBUTE.get(CraftNamespacedKey.fromMinecraft(net.minecraft.core.Registry.ATTRIBUTE.getKey(attributeBase))), org.bukkit.craftbukkit.attribute.CraftAttributeInstance.convert(attributeModifier, equipmentSlot));
|
|
+ });
|
|
+ return attributeMapBuilder.build();
|
|
+ }
|
|
+
|
|
@Override
|
|
public int getProtocolVersion() {
|
|
return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion();
|