Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 02:50:09 +01:00
3b9db2b194
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: bb4e97c6 Add support for Java 23 bc6874dd Bump asm to 9.7.1 50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives 758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds 133a64a7 Improve Registry#getOrThrow messages be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields d1b31df2 PR-1062: Clarify BeaconView documentation 3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion 967a7301 SPIGOT-7906: Increase YAML nesting limit to 100 6ecf033d SPIGOT-7899: Smithing recipes don't require inputs CraftBukkit Changes: 0a7bd6c81 PR-1493: Improve reroute performance and add some tests 54941524c Add support for Java 23 f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius ded183674 Fix HIDE_ENCHANTS flag in items without enchantments 308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter 72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives 11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions 45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set 963459791 Increase outdated build delay fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks 2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event 527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty 5529a1769 Implement base methods for tags 30fbdbaaf Improve Registry#getOrThrow messages 6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields 5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null) d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init 98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent f35bae9ec Fix missing hasJukeboxPlayable 8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item 7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
84 Zeilen
5.5 KiB
Diff
84 Zeilen
5.5 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 66d773cadb74f9176e6cf68a565568034f52ec63..a1f2b9d40d374e8cdbaf916b25fa74b6c0970f81 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
@@ -197,19 +197,36 @@ 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);
|
|
if (nmsDefaultAttributes.modifiers().isEmpty()) {
|
|
nmsDefaultAttributes = this.item.getDefaultAttributeModifiers();
|
|
}
|
|
-
|
|
- 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 78d1b33a554ac8ca0f76585c6b97e35c2d337293..5e8081350b2ec375373d8197bd1f3196652ec9d9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -391,7 +391,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
|