mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 22:43:14 +01:00
702864d8f8
Updated Upstream (Bukkit/CraftBukkit) 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: fa99e752 PR-1007: Add ItemMeta#getAsComponentString() 94a91782 Fix copy-pasted BlockType.Typed documentation 9b34ac8c Largely restore deprecated PotionData API 51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5 702d15fe Fix Javadoc reference 42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them 237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more 87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent CraftBukkit Changes: 4af0f22e8 SPIGOT-7664: Item meta should prevail over block states c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot 124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects 66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API 6118e5398 Fix regression listening to minecraft:brand custom payloads c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check 12360a7ec Remove unused imports 147b098b4 PR-1397: Add ItemMeta#getAsComponentString() 428aefe0e Largely restore deprecated PotionData API afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them 8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets 0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA 2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent 741b84480 PR-1390: Improve internal handling of damage sources 0364df4e1 SPIGOT-7657: Error when loading angry entities
518 lines
32 KiB
Diff
518 lines
32 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sat, 27 Apr 2024 20:56:17 -0700
|
|
Subject: [PATCH] General ItemMeta fixes
|
|
|
|
== AT ==
|
|
private-f net/minecraft/world/item/ItemStack components
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
@@ -0,0 +0,0 @@ public final class ItemStack implements DataComponentHolder {
|
|
} finally {
|
|
world.captureBlockStates = false;
|
|
}
|
|
- DataComponentPatch newData = this.getComponentsPatch();
|
|
+ DataComponentPatch newData = this.components.asPatch(); // Paper - Directly access components as patch instead of getComponentsPatch as said method yields EMPTY on items with count 0
|
|
int newCount = this.getCount();
|
|
this.setCount(oldCount);
|
|
this.restorePatch(oldData);
|
|
@@ -0,0 +0,0 @@ public final class ItemStack implements DataComponentHolder {
|
|
public void setItem(Item item) {
|
|
this.bukkitStack = null; // Paper
|
|
this.item = item;
|
|
+ // Paper start - change base component prototype
|
|
+ final DataComponentPatch patch = this.getComponentsPatch();
|
|
+ this.components = new PatchedDataComponentMap(this.item.components());
|
|
+ this.applyComponents(patch);
|
|
+ // Paper end - change base component prototype
|
|
}
|
|
// CraftBukkit end
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
@@ -0,0 +0,0 @@ public abstract class BlockEntity {
|
|
CompoundTag nbttagcompound = new CompoundTag();
|
|
|
|
this.saveAdditional(nbttagcompound, registryLookup);
|
|
+ // Paper start - store PDC here as well
|
|
+ if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) {
|
|
+ nbttagcompound.put("PublicBukkitValues", this.persistentDataContainer.toTagCompound());
|
|
+ }
|
|
+ // Paper end
|
|
return nbttagcompound;
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
@@ -0,0 +0,0 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
|
|
return nbt;
|
|
}
|
|
|
|
+ // Paper start - properly save blockentity itemstacks
|
|
+ public CompoundTag getSnapshotCustomNbtOnly() {
|
|
+ this.applyTo(this.snapshot);
|
|
+ final CompoundTag nbt = this.snapshot.saveCustomOnly(this.getRegistryAccess());
|
|
+ this.snapshot.removeComponentsFromTag(nbt);
|
|
+ return nbt;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
// copies the data of the given tile entity to this block state
|
|
protected void load(T tileEntity) {
|
|
if (tileEntity != null && tileEntity != this.snapshot) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
|
|
// Paper end - improve handled tags on type change
|
|
// Paper start
|
|
public static void applyMetaToItem(net.minecraft.world.item.ItemStack itemStack, ItemMeta itemMeta) {
|
|
- final CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
|
+ // Paper start - support updating profile after resolving it
|
|
+ final CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator() {
|
|
+ @Override
|
|
+ void skullCallback(final com.mojang.authlib.GameProfile gameProfile) {
|
|
+ itemStack.set(DataComponents.PROFILE, new net.minecraft.world.item.component.ResolvableProfile(gameProfile));
|
|
+ }
|
|
+ };
|
|
+ // Paper end - support updating profile after resolving it
|
|
((CraftMetaItem) itemMeta).applyToItem(tag);
|
|
itemStack.applyComponents(tag.build());
|
|
}
|
|
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
|
|
}
|
|
|
|
if (!((CraftMetaItem) itemMeta).isEmpty()) {
|
|
- CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
|
+ // Paper start - support updating profile after resolving it
|
|
+ CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator() {
|
|
+ @Override
|
|
+ void skullCallback(final com.mojang.authlib.GameProfile gameProfile) {
|
|
+ item.set(DataComponents.PROFILE, new net.minecraft.world.item.component.ResolvableProfile(gameProfile));
|
|
+ }
|
|
+ };
|
|
+ // Paper end - support updating profile after resolving it
|
|
|
|
((CraftMetaItem) itemMeta).applyToItem(tag);
|
|
item.restorePatch(tag.build());
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
|
|
void applyToItem(CraftMetaItem.Applicator tag) {
|
|
super.applyToItem(tag);
|
|
|
|
+ if (this.patterns.isEmpty()) return; // Paper - don't write empty patterns
|
|
List<BannerPatternLayers.Layer> newPatterns = new ArrayList<>();
|
|
|
|
for (Pattern p : this.patterns) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|
super.applyToItem(tag);
|
|
|
|
if (this.blockEntityTag != null) {
|
|
- tag.put(CraftMetaBlockState.BLOCK_ENTITY_TAG, CustomData.of(this.blockEntityTag.getSnapshotNBTWithoutComponents()));
|
|
+ // Paper start - accurately replicate logic for creating ItemStack from BlockEntity
|
|
+ // taken from BlockEntity#saveToItem and BlockItem#setBlockEntityData
|
|
+ CompoundTag nbt = this.blockEntityTag.getSnapshotCustomNbtOnly();
|
|
+ nbt.remove("id");
|
|
+ if (!nbt.isEmpty()) {
|
|
+ BlockEntity.addEntityType(nbt, this.blockEntityTag.getTileEntity().getType());
|
|
+ tag.put(CraftMetaBlockState.BLOCK_ENTITY_TAG, CustomData.of(nbt));
|
|
+ }
|
|
+ // Paper end
|
|
|
|
for (TypedDataComponent<?> component : this.blockEntityTag.collectComponents()) {
|
|
- tag.putIfAbsent(component);
|
|
+ if (CraftMetaItem.DEFAULT_HANDLED_DCTS.contains(component.type())) continue; // Paper - if the component type was already handled by CraftMetaItem, don't add it again
|
|
+ tag.builder.set(component);
|
|
}
|
|
}
|
|
}
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
|
Preconditions.checkArgument(blockStateType == blockState.getClass() && blockState instanceof CraftBlockEntityState, "Invalid blockState for " + this.material);
|
|
|
|
this.blockEntityTag = (CraftBlockEntityState<?>) blockState;
|
|
+ // Paper start - when a new BlockState is set, the components from that block entity
|
|
+ // have to be used to update the fields on CraftMetaItem
|
|
+ final PatchedDataComponentMap patchedMap = new net.minecraft.core.component.PatchedDataComponentMap(this.blockEntityTag.getHandle().getBlock().asItem().components());
|
|
+ final net.minecraft.core.component.DataComponentMap map = this.blockEntityTag.collectComponents();
|
|
+ patchedMap.setAll(map);
|
|
+ this.updateFromPatch(patchedMap.asPatch(), null);
|
|
+ // Paper end
|
|
}
|
|
|
|
private static Material shieldToBannerHack() {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
|
|
}
|
|
}
|
|
|
|
- this.resolved = SerializableMeta.getObject(Boolean.class, map, CraftMetaBookSigned.RESOLVED.BUKKIT, true);
|
|
- this.generation = SerializableMeta.getObject(Integer.class, map, CraftMetaBookSigned.GENERATION.BUKKIT, true);
|
|
+ this.resolved = SerializableMeta.getBoolean(map, CraftMetaBookSigned.RESOLVED.BUKKIT); // Paper - General ItemMeta fixes
|
|
+ this.generation = SerializableMeta.getObjectOptionally(Integer.class, map, CraftMetaBookSigned.GENERATION.BUKKIT, true).orElse(0); // Paper - General ItemMeta Fixes
|
|
}
|
|
|
|
@Override
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
|
|
for (Component page : this.pages) {
|
|
list.add(Filterable.passThrough(page));
|
|
}
|
|
- itemData.put(CraftMetaBookSigned.BOOK_CONTENT, new WrittenBookContent(Filterable.from(FilteredText.passThrough(this.title)), this.author, this.generation, list, this.resolved));
|
|
+ itemData.put(CraftMetaBookSigned.BOOK_CONTENT, new WrittenBookContent(Filterable.from(FilteredText.passThrough(this.title == null ? "" : this.title)), this.author == null ? "" : this.author, this.generation, list, this.resolved));
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
}
|
|
|
|
Iterable<?> effects = SerializableMeta.getObject(Iterable.class, map, CraftMetaFirework.EXPLOSIONS.BUKKIT, true);
|
|
- this.safelyAddEffects(effects);
|
|
+ this.safelyAddEffects(effects, false); // Paper - limit firework effects
|
|
}
|
|
|
|
@Override
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
return !(this.effects == null || this.effects.isEmpty());
|
|
}
|
|
|
|
- void safelyAddEffects(Iterable<?> collection) {
|
|
+ void safelyAddEffects(Iterable<?> collection, final boolean throwOnOversize) { // Paper
|
|
if (collection == null || (collection instanceof Collection && ((Collection<?>) collection).isEmpty())) {
|
|
return;
|
|
}
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
|
|
for (Object obj : collection) {
|
|
Preconditions.checkArgument(obj instanceof FireworkEffect, "%s in %s is not a FireworkEffect", obj, collection);
|
|
+ // Paper start - limit firework effects
|
|
+ if (effects.size() + 1 > Fireworks.MAX_EXPLOSIONS) {
|
|
+ if (throwOnOversize) {
|
|
+ throw new IllegalArgumentException("Cannot have more than " + Fireworks.MAX_EXPLOSIONS + " firework effects");
|
|
+ } else {
|
|
+ continue;
|
|
+ }
|
|
+ }
|
|
+ // Paper end - limit firework effects
|
|
effects.add((FireworkEffect) obj);
|
|
}
|
|
}
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
}
|
|
|
|
List<FireworkExplosion> effects = new ArrayList<>();
|
|
- for (FireworkEffect effect : this.effects) {
|
|
- effects.add(CraftMetaFirework.getExplosion(effect));
|
|
+ // Paper start - fix NPE with effects list being null
|
|
+ if (this.effects != null) {
|
|
+ for (FireworkEffect effect : this.effects) {
|
|
+ effects.add(CraftMetaFirework.getExplosion(effect));
|
|
+ }
|
|
}
|
|
+ // Paper end
|
|
|
|
itemTag.put(CraftMetaFirework.FIREWORKS, new Fireworks(this.power, effects));
|
|
}
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
@Override
|
|
public void addEffect(FireworkEffect effect) {
|
|
Preconditions.checkArgument(effect != null, "FireworkEffect cannot be null");
|
|
+ Preconditions.checkArgument(this.effects == null || this.effects.size() + 1 <= Fireworks.MAX_EXPLOSIONS, "cannot have more than %s firework effects", Fireworks.MAX_EXPLOSIONS); // Paper - limit firework effects
|
|
if (this.effects == null) {
|
|
this.effects = new ArrayList<FireworkEffect>();
|
|
}
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
@Override
|
|
public void addEffects(FireworkEffect... effects) {
|
|
Preconditions.checkArgument(effects != null, "effects cannot be null");
|
|
+ // Paper start - limit firework effects
|
|
+ final int initialSize = this.effects == null ? 0 : this.effects.size();
|
|
+ Preconditions.checkArgument(initialSize + effects.length <= Fireworks.MAX_EXPLOSIONS, "Cannot have more than %s firework effects", Fireworks.MAX_EXPLOSIONS);
|
|
+ // Paper end - limit firework effects
|
|
if (effects.length == 0) {
|
|
return;
|
|
}
|
|
@@ -0,0 +0,0 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
@Override
|
|
public void addEffects(Iterable<FireworkEffect> effects) {
|
|
Preconditions.checkArgument(effects != null, "effects cannot be null");
|
|
- this.safelyAddEffects(effects);
|
|
+ this.safelyAddEffects(effects, true); // Paper - limit firework effects
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
}
|
|
}
|
|
|
|
- static final class Applicator {
|
|
+ static abstract class Applicator { // Paper - support updating profile after resolving it
|
|
|
|
- private final DataComponentPatch.Builder builder = DataComponentPatch.builder();
|
|
+ final DataComponentPatch.Builder builder = DataComponentPatch.builder(); // Paper - private -> package-private
|
|
+ void skullCallback(com.mojang.authlib.GameProfile gameProfile) {} // Paper - support updating profile after resolving it
|
|
|
|
<T> Applicator put(ItemMetaKeyType<T> key, T value) {
|
|
this.builder.set(key.TYPE, value);
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
this.enchantments = new EnchantmentMap(meta.enchantments); // Paper
|
|
}
|
|
|
|
- if (meta.hasAttributeModifiers()) {
|
|
+ if (meta.attributeModifiers != null) { // Paper
|
|
this.attributeModifiers = LinkedHashMultimap.create(meta.attributeModifiers);
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
}
|
|
|
|
CraftMetaItem(DataComponentPatch tag, Set<DataComponentType<?>> extraHandledTags) { // Paper - improve handled tags on type changes
|
|
+ // Paper start - properly support data components in BlockEntity
|
|
+ this.updateFromPatch(tag, extraHandledTags);
|
|
+ }
|
|
+ protected final void updateFromPatch(DataComponentPatch tag, Set<DataComponentType<?>> extraHandledTags) {
|
|
+ // Paper end - properly support data components in BlockEntity
|
|
CraftMetaItem.getOrEmpty(tag, CraftMetaItem.NAME).ifPresent((component) -> {
|
|
this.displayName = component;
|
|
});
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
Map<?, ?> mods = SerializableMeta.getObject(Map.class, map, key.BUKKIT, true);
|
|
Multimap<Attribute, AttributeModifier> result = LinkedHashMultimap.create();
|
|
if (mods == null) {
|
|
- return result;
|
|
+ return null; // Paper - null is different from an empty map
|
|
}
|
|
|
|
for (Object obj : mods.keySet()) {
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
}
|
|
|
|
void applyModifiers(Multimap<Attribute, AttributeModifier> modifiers, CraftMetaItem.Applicator tag) {
|
|
- if (modifiers == null || modifiers.isEmpty()) {
|
|
- if (this.hasItemFlag(ItemFlag.HIDE_ATTRIBUTES)) {
|
|
- tag.put(CraftMetaItem.ATTRIBUTES, new ItemAttributeModifiers(Collections.emptyList(), false));
|
|
- }
|
|
+ if (modifiers == null/* || modifiers.isEmpty()*/) { // Paper - empty modifiers has a specific meaning, they should still be saved
|
|
+ // Paper - don't save ItemFlag if the underlying data isn't present
|
|
return;
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
|
|
@Overridden
|
|
boolean isEmpty() {
|
|
- return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null); // Paper
|
|
+ return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasDamage() || this.hasMaxDamage() || this.attributeModifiers != null || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null); // Paper
|
|
}
|
|
|
|
// Paper start
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
|
|
@Override
|
|
public void lore(final List<? extends net.kyori.adventure.text.Component> lore) {
|
|
+ Preconditions.checkArgument(lore == null || lore.size() <= ItemLore.MAX_LINES, "lore cannot have more than %s lines", ItemLore.MAX_LINES); // Paper - limit lore lines
|
|
this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(lore) : null;
|
|
}
|
|
// Paper end
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
// Paper end
|
|
@Override
|
|
public void setLore(List<String> lore) {
|
|
+ Preconditions.checkArgument(lore == null || lore.size() <= ItemLore.MAX_LINES, "lore cannot have more than %s lines", ItemLore.MAX_LINES); // Paper - limit lore lines
|
|
if (lore == null || lore.isEmpty()) {
|
|
this.lore = null;
|
|
} else {
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
// Paper start
|
|
@Override
|
|
public void setLoreComponents(List<net.md_5.bungee.api.chat.BaseComponent[]> lore) {
|
|
+ Preconditions.checkArgument(lore == null || lore.size() <= ItemLore.MAX_LINES, "lore cannot have more than %s lines", ItemLore.MAX_LINES); // Paper - limit lore lines
|
|
if (lore == null) {
|
|
this.lore = null;
|
|
} else {
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
|
|
@Override
|
|
public String getAsString() {
|
|
- CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
|
+ CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator() {}; // Paper - support updating profile after resolving it
|
|
this.applyToItem(tag);
|
|
DataComponentPatch patch = tag.build();
|
|
Tag nbt = DataComponentPatch.CODEC.encodeStart(MinecraftServer.getDefaultRegistryAccess().createSerializationContext(NbtOps.INSTANCE), patch).getOrThrow();
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
|
|
@Override
|
|
public String getAsComponentString() {
|
|
- CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
|
|
+ CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator() {}; // Paper
|
|
this.applyToItem(tag);
|
|
DataComponentPatch patch = tag.build();
|
|
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
if (first == null || second == null) {
|
|
return false;
|
|
}
|
|
+ if (first.isEmpty() && second.isEmpty()) return true; // Paper - empty modifiers are equivalent
|
|
for (Map.Entry<Attribute, AttributeModifier> entry : first.entries()) {
|
|
if (!second.containsEntry(entry.getKey(), entry.getValue())) {
|
|
return false;
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
&& (this.hasCustomModelData() ? that.hasCustomModelData() && this.customModelData.equals(that.customModelData) : !that.hasCustomModelData())
|
|
&& (this.hasBlockData() ? that.hasBlockData() && this.blockData.equals(that.blockData) : !that.hasBlockData())
|
|
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
|
|
- && (this.hasAttributeModifiers() ? that.hasAttributeModifiers() && CraftMetaItem.compareModifiers(this.attributeModifiers, that.attributeModifiers) : !that.hasAttributeModifiers())
|
|
+ && (this.attributeModifiers != null ? that.attributeModifiers != null && CraftMetaItem.compareModifiers(this.attributeModifiers, that.attributeModifiers) : that.attributeModifiers == null) // Paper - track only null modifiers
|
|
&& (this.unhandledTags.equals(that.unhandledTags))
|
|
&& (Objects.equals(this.customTag, that.customTag))
|
|
&& (this.persistentDataContainer.equals(that.persistentDataContainer))
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
hash = 61 * hash + (this.hasFood() ? this.food.hashCode() : 0);
|
|
hash = 61 * hash + (this.hasDamage() ? this.damage : 0);
|
|
hash = 61 * hash + (this.hasMaxDamage() ? 1231 : 1237);
|
|
- hash = 61 * hash + (this.hasAttributeModifiers() ? this.attributeModifiers.hashCode() : 0);
|
|
+ hash = 61 * hash + (this.attributeModifiers != null ? this.attributeModifiers.hashCode() : 0); // Paper - track only null attributes
|
|
hash = 61 * hash + (this.canPlaceOnPredicates != null ? this.canPlaceOnPredicates.hashCode() : 0); // Paper
|
|
hash = 61 * hash + (this.canBreakPredicates != null ? this.canBreakPredicates.hashCode() : 0); // Paper
|
|
hash = 61 * hash + this.version;
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
if (this.enchantments != null) {
|
|
clone.enchantments = new EnchantmentMap(this.enchantments); // Paper
|
|
}
|
|
- if (this.hasAttributeModifiers()) {
|
|
+ if (this.attributeModifiers != null) { // Paper
|
|
clone.attributeModifiers = LinkedHashMultimap.create(this.attributeModifiers);
|
|
}
|
|
if (this.customTag != null) {
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
}
|
|
|
|
static void serializeModifiers(Multimap<Attribute, AttributeModifier> modifiers, ImmutableMap.Builder<String, Object> builder, ItemMetaKey key) {
|
|
- if (modifiers == null || modifiers.isEmpty()) {
|
|
+ if (modifiers == null/* || modifiers.isEmpty()*/) { // Paper - null and an empty map have different behaviors
|
|
return;
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
// Paper start - improve checking handled tags
|
|
@org.jetbrains.annotations.VisibleForTesting
|
|
public static final Map<Class<? extends CraftMetaItem>, Set<DataComponentType<?>>> HANDLED_DCTS_PER_TYPE = new HashMap<>();
|
|
- private static final Set<DataComponentType<?>> DEFAULT_HANDLED_DCTS = Set.of(
|
|
+ protected static final Set<DataComponentType<?>> DEFAULT_HANDLED_DCTS = Set.of(
|
|
CraftMetaItem.NAME.TYPE,
|
|
CraftMetaItem.ITEM_NAME.TYPE,
|
|
CraftMetaItem.LORE.TYPE,
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
@@ -0,0 +0,0 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
|
// Fill in textures
|
|
PlayerProfile ownerProfile = new CraftPlayerProfile(this.profile); // getOwnerProfile may return null
|
|
if (ownerProfile.getTextures().isEmpty()) {
|
|
- ownerProfile.update().thenAccept((filledProfile) -> {
|
|
+ ownerProfile.update().thenAcceptAsync((filledProfile) -> { // Paper - run on main thread
|
|
this.setOwnerProfile(filledProfile);
|
|
- tag.put(CraftMetaSkull.SKULL_PROFILE, new ResolvableProfile(this.profile));
|
|
- });
|
|
+ tag.skullCallback(this.profile); // Paper - actually set profile on itemstack
|
|
+ }, ((org.bukkit.craftbukkit.CraftServer) org.bukkit.Bukkit.getServer()).getServer()); // Paper - run on main thread
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java b/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java
|
|
@@ -0,0 +0,0 @@ public final class SerializableMeta implements ConfigurationSerializable {
|
|
}
|
|
throw new IllegalArgumentException(field + "(" + object + ") is not a valid " + clazz);
|
|
}
|
|
+
|
|
+ // Paper start - General ItemMeta Fixes
|
|
+ public static <T> java.util.Optional<T> getObjectOptionally(Class<T> clazz, Map<?, ?> map, Object field, boolean nullable) {
|
|
+ final Object object = map.get(field);
|
|
+
|
|
+ if (clazz.isInstance(object)) {
|
|
+ return java.util.Optional.of(clazz.cast(object));
|
|
+ }
|
|
+ if (object == null) {
|
|
+ if (!nullable) {
|
|
+ throw new NoSuchElementException(map + " does not contain " + field);
|
|
+ }
|
|
+ return java.util.Optional.empty();
|
|
+ }
|
|
+ throw new IllegalArgumentException(field + "(" + object + ") is not a valid " + clazz);
|
|
+ }
|
|
+ // Paper end - General ItemMeta Fixes
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java b/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java
|
|
@@ -0,0 +0,0 @@ public final class CraftFoodComponent implements FoodComponent {
|
|
|
|
@Override
|
|
public void setEatSeconds(float eatSeconds) {
|
|
+ Preconditions.checkArgument(eatSeconds > 0, "Eat seconds must be positive"); // Paper - validate eat_seconds
|
|
this.handle = new FoodProperties(this.handle.nutrition(), this.handle.saturation(), this.handle.canAlwaysEat(), eatSeconds, this.handle.effects());
|
|
}
|
|
|
|
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
|
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
|
@@ -0,0 +0,0 @@ public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase {
|
|
public void testNBTTagStoring() {
|
|
CraftMetaItem itemMeta = this.createComplexItemMeta();
|
|
|
|
- CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator();
|
|
+ CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator() {}; // Paper
|
|
itemMeta.applyToItem(compound);
|
|
|
|
assertEquals(itemMeta, new CraftMetaItem(compound.build(), null)); // Paper
|
|
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
|
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
|
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest extends AbstractTestingBase {
|
|
public void testNBTTagStoring() {
|
|
CraftMetaItem itemMeta = this.createComplexItemMeta();
|
|
|
|
- CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator();
|
|
+ CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator() {}; // Paper
|
|
itemMeta.applyToItem(compound);
|
|
|
|
assertEquals(itemMeta, new CraftMetaItem(compound.build(), null)); // Paper
|
|
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest extends AbstractTestingBase {
|
|
assertEquals(List.of(), container.get(PersistentDataContainerTest.requestKey("list"), PersistentDataType.LIST.strings()));
|
|
|
|
// Write and read the entire container to NBT
|
|
- final CraftMetaItem.Applicator storage = new CraftMetaItem.Applicator();
|
|
+ final CraftMetaItem.Applicator storage = new CraftMetaItem.Applicator() {}; // Paper
|
|
craftItem.applyToItem(storage);
|
|
|
|
final CraftMetaItem readItem = new CraftMetaItem(storage.build(), null); // Paper
|