Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
52a05907c7
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 97c59261 PR-1073: Make Biome an interface a38581aa Fix further javadoc errors 8271c490 Fix javadoc error 8a9ecf29 PR-1072: Fix bad naming for Vault State methods 6dd58108 PR-1071: Make Fluid an interface and add missing entry ed2cdfc3 PR-1070: Make Attribute an interface and align names with the new minecraft ones 63472efb PR-1069: Add missing winter drop experimental annotation to pale boats CraftBukkit Changes: 7235ad7b0 PR-1501: Make Biome an interface 602904003 PR-1500: Rename implementation for Vault State methods 75f26f79f PR-1499: Make Fluid an interface and add missing entry 4cfd87adc PR-1498: Make Attribute an interface and align names with the new minecraft ones 6bb0db5cb SPIGOT-7928: ExactChoice acts as MaterialChoice 3eaf3a13c SPIGOT-7929: Error when setting EquippableComponent abbf57bac SPIGOT-7930: Fix spawning entities with SummonEntityEffect 92d6ab6cf PR-1497: Move boat field rename entries to below key renaming, so that keys are also renamed abfe292aa PR-1496: Use correct Fluid class on Tags type check c7aab7fa7 SPIGOT-7923: Fix Dispenser logic to avoid firing empty projectiles
81 Zeilen
5.3 KiB
Diff
81 Zeilen
5.3 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] Improve item default attribute API
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java
|
|
index de0eba19c0c963adb4f17cea22333240021fd801..3b171a08bd0bedfe224905feb5838d2540199bce 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java
|
|
@@ -75,7 +75,7 @@ public class CraftAttributeInstance implements AttributeInstance {
|
|
return new AttributeModifier(CraftNamespacedKey.fromMinecraft(nms.id()), nms.amount(), AttributeModifier.Operation.values()[nms.operation().ordinal()], org.bukkit.inventory.EquipmentSlotGroup.ANY);
|
|
}
|
|
|
|
- public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms, EquipmentSlot slot) {
|
|
- return new AttributeModifier(CraftNamespacedKey.fromMinecraft(nms.id()), nms.amount(), AttributeModifier.Operation.values()[nms.operation().ordinal()], slot.getGroup());
|
|
+ public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms, net.minecraft.world.entity.EquipmentSlotGroup slot) { // Paper
|
|
+ return new AttributeModifier(CraftNamespacedKey.fromMinecraft(nms.id()), nms.amount(), AttributeModifier.Operation.values()[nms.operation().ordinal()], org.bukkit.craftbukkit.CraftEquipmentSlot.getSlot(slot)); // Paper
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
index 68756419ac6ee292db9569eab380a5c14d748002..6d76cc1db3ac3f1ae74c13511937fb86082a0b3d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
@@ -197,16 +197,33 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
|
|
// return CraftEquipmentSlot.getSlot(EntityInsentient.getEquipmentSlotForItem(CraftItemStack.asNMSCopy(ItemStack.of(this))));
|
|
// }
|
|
|
|
+ // Paper start - improve default attribute API
|
|
+ @Override
|
|
+ public @NotNull Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers() {
|
|
+ return this.getDefaultAttributeModifiers(sg -> true);
|
|
+ }
|
|
+ // Paper end - improve default attribute API
|
|
+
|
|
@Override
|
|
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot slot) {
|
|
+ // Paper start - improve/fix item default attribute API
|
|
+ final net.minecraft.world.entity.EquipmentSlot nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
|
+ return this.getDefaultAttributeModifiers(sg -> sg.test(nmsSlot));
|
|
+ }
|
|
+
|
|
+ private Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(final java.util.function.Predicate<net.minecraft.world.entity.EquipmentSlotGroup> slotPredicate) {
|
|
+ // Paper end - improve/fix item default attribute API
|
|
ImmutableMultimap.Builder<Attribute, AttributeModifier> defaultAttributes = ImmutableMultimap.builder();
|
|
|
|
ItemAttributeModifiers nmsDefaultAttributes = this.item.components().getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
|
-
|
|
- nmsDefaultAttributes.forEach(CraftEquipmentSlot.getNMS(slot), (key, value) -> {
|
|
- Attribute attribute = CraftAttribute.minecraftToBukkit(key.value());
|
|
- defaultAttributes.put(attribute, CraftAttributeInstance.convert(value, slot));
|
|
- });
|
|
+ // Paper start - improve/fix item default attribute API
|
|
+ for (final net.minecraft.world.item.component.ItemAttributeModifiers.Entry entry : nmsDefaultAttributes.modifiers()) {
|
|
+ if (!slotPredicate.test(entry.slot())) continue;
|
|
+ final Attribute attribute = CraftAttribute.minecraftHolderToBukkit(entry.attribute());
|
|
+ final AttributeModifier modifier = CraftAttributeInstance.convert(entry.modifier(), entry.slot());
|
|
+ defaultAttributes.put(attribute, modifier);
|
|
+ }
|
|
+ // Paper end - improve/fix item default attribute API
|
|
|
|
return defaultAttributes.build();
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 079cb08b92061bb14952cf4ad2bda61e154f4438..6855210dc58f455b5af05d9c039da55e8dfc93f1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -386,7 +386,11 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
|
|
@Override
|
|
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(Material material, EquipmentSlot slot) {
|
|
- return material.getDefaultAttributeModifiers(slot);
|
|
+ // Paper start - delegate to method on ItemType
|
|
+ final org.bukkit.inventory.ItemType item = material.asItemType();
|
|
+ Preconditions.checkArgument(item != null, material + " is not an item and does not have default attributes");
|
|
+ return item.getDefaultAttributeModifiers(slot);
|
|
+ // Paper end - delegate to method on ItemType
|
|
}
|
|
|
|
@Override
|