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:
e2160a18 Make MapCursor#type not depends on deprecated values

CraftBukkit Changes:
6ce172642 SPIGOT-7761: Ender pearl does not damage or spawn endermites
f5a63f734 SPIGOT-7759: Chunk not there when requested in ChunkUnloadEvent
28287259c Remove unused import
eb9a7dde0 SPIGOT-7757: Cannot set item in Stonecutter Inventory
f8be9d752 Move deserialized removed unhandled tags to dedicated removedTags
a7e576186 Fix potential mutability issue with CraftMetaItem copy constructor
995885452 SPIGOT-7741: Vanilla ItemComponent in commands can't remove components
9ef69aa0b PR-1284: Move ItemType <-> ItemMeta linking to a centralized place
3e82eafbe PR-1420: Fix DirectEntity and CausingEntity Damager for Creepers ignited by Player
c23daa71f SPIGOT-7751: Fix crash caused by arrows from trial spawners
Make MapCursor#type not depends on deprecated values
SPIGOT-7761: Ender pearl does not damage or spawn endermites
This commit is contained in:
Nassim Jahnke 2024-06-15 18:28:18 +02:00
parent 9b3cf41d7a
commit efb91589dc
20 changed files with 311 additions and 278 deletions

View file

@ -4809,13 +4809,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+++ b/src/main/java/org/bukkit/map/MapCursor.java
@@ -0,0 +0,0 @@ public final class MapCursor {
private byte x, y;
private byte direction, type;
private byte direction;
private boolean visible;
- private String caption;
+ private net.kyori.adventure.text.Component caption; // Paper
private Type type;
/**
* Initialize the map cursor.
@@ -0,0 +0,0 @@ public final class MapCursor {
*/
@Deprecated
@ -4838,8 +4838,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* @param type The type (color/style) of the map cursor.
* @param visible Whether the cursor is visible by default.
* @param caption cursor caption
- * @deprecated Magic value
+ * @deprecated Magic value. Use {@link #MapCursor(byte, byte, byte, byte, boolean, net.kyori.adventure.text.Component)}
- * @deprecated Magic value, use {@link #MapCursor(byte, byte, byte, Type, boolean, String)}
+ * @deprecated Magic value. Use {@link #MapCursor(byte, byte, byte, Type, boolean, net.kyori.adventure.text.Component)}
*/
@Deprecated
public MapCursor(byte x, byte y, byte direction, byte type, boolean visible, @Nullable String caption) {
@ -4849,7 +4849,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.visible = visible;
- this.caption = caption;
+ this.caption = caption == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(caption); // Paper
}
+ }
+ // Paper start
+ /**
+ * Initialize the map cursor.
@ -4867,7 +4867,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.x = x; this.y = y; this.visible = visible; this.caption = caption;
+ setDirection(direction);
+ setRawType(type);
+ }
}
+ /**
+ * Initialize the map cursor.
+ *
@ -4889,7 +4889,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* Initialize the map cursor.
@@ -0,0 +0,0 @@ public final class MapCursor {
setDirection(direction);
setType(type);
this.type = type;
this.visible = visible;
- this.caption = caption;
+ this.caption = caption == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(caption); // Paper
@ -4901,11 +4901,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
+ // Paper start
+ /**
+ * Gets the caption on this cursor.
+ *
+ * @return caption
+ */
/**
* Gets the caption on this cursor.
*
* @return caption
*/
+ public net.kyori.adventure.text.@Nullable Component caption() {
+ return this.caption;
+ }
@ -4918,12 +4918,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.caption = caption;
+ }
+ // Paper end
/**
* Gets the caption on this cursor.
*
* @return caption
+ /**
+ * Gets the caption on this cursor.
+ *
+ * @return caption
+ * @deprecated in favour of {@link #caption()}
*/
+ */
@Nullable
+ @Deprecated // Paper
public String getCaption() {

View file

@ -1,30 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Date: Fri, 24 May 2024 20:19:07 +0200
Subject: [PATCH] Allow to define new map cursor types
diff --git a/src/main/java/org/bukkit/map/MapCursor.java b/src/main/java/org/bukkit/map/MapCursor.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/map/MapCursor.java
+++ b/src/main/java/org/bukkit/map/MapCursor.java
@@ -0,0 +0,0 @@ public final class MapCursor {
*/
@Deprecated(forRemoval = true, since = "1.20.2") // Paper
public void setRawType(byte type) {
- if (type < 0 || type > 34) {
- throw new IllegalArgumentException("Type must be in the range 0-34");
+ if (type < 0 || type > Type.UPPER_MAP_CURSOR_TYPE_BOUND) { // Paper
+ throw new IllegalArgumentException("Type must be in the range 0-" + Type.UPPER_MAP_CURSOR_TYPE_BOUND); // Paper
}
this.type = type;
}
@@ -0,0 +0,0 @@ public final class MapCursor {
TRIAL_CHAMBERS(34, "trial_chambers")
;
+ static final int UPPER_MAP_CURSOR_TYPE_BOUND = Type.values().length - 1; // Paper - cached max value of Type
+
private byte value;
private final NamespacedKey key;

View file

@ -1690,7 +1690,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- @Deprecated
+ @org.jetbrains.annotations.ApiStatus.Internal // Paper
public byte getRawType() {
return type;
return type.value;
}
@@ -0,0 +0,0 @@ public final class MapCursor {
* Set the type of this cursor.
@ -1702,8 +1702,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- @Deprecated
+ @Deprecated(forRemoval = true, since = "1.20.2") // Paper
public void setRawType(byte type) {
if (type < 0 || type > 34) {
throw new IllegalArgumentException("Type must be in the range 0-34");
Type enumType = Type.byValue(type);
Preconditions.checkArgument(enumType != null, "Unknown type by id %s", type);
@@ -0,0 +0,0 @@ public final class MapCursor {
* Gets the internal value of the cursor.
*

View file

@ -12,19 +12,26 @@ starting point for future additions in this area.
Fixes GH-559
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
@@ -0,0 +0,0 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
private Class<M> getItemMetaClass(Item item) {
ItemMeta meta = new ItemStack(this.asMaterial()).getItemMeta();
if (meta != null) {
- if (CraftMetaEntityTag.class != meta.getClass() && CraftMetaArmorStand.class != meta.getClass()) {
+ if (CraftMetaEntityTag.class != meta.getClass()/* && CraftMetaArmorStand.class != meta.getClass()*/) { // Paper - CraftMetaArmorStand is implemented in the API via ArmorStandMeta.
return (Class<M>) meta.getClass().getInterfaces()[0];
}
}
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
@@ -0,0 +0,0 @@
package org.bukkit.craftbukkit.inventory;
+import com.destroystokyo.paper.inventory.meta.ArmorStandMeta;
import java.util.function.BiFunction;
import java.util.function.Function;
import net.minecraft.world.item.ItemStack;
@@ -0,0 +0,0 @@ public final class CraftItemMetas {
item -> new CraftMetaSpawnEgg(item.getComponentsPatch()),
(type, meta) -> meta instanceof CraftMetaSpawnEgg spawnEgg ? spawnEgg : new CraftMetaSpawnEgg(meta));
- private static final ItemMetaData<ItemMeta> ARMOR_STAND_META_DATA = new ItemMetaData<>(ItemMeta.class,
+ private static final ItemMetaData<ArmorStandMeta> ARMOR_STAND_META_DATA = new ItemMetaData<>(ArmorStandMeta.class, // paper
item -> new CraftMetaArmorStand(item.getComponentsPatch()),
(type, meta) -> meta instanceof CraftMetaArmorStand armorStand ? armorStand : new CraftMetaArmorStand(meta));
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java

View file

@ -1070,8 +1070,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- });
+ // Paper - RegistryAccess
// Paper start - testing additions
final Thread currentThread = Thread.currentThread();
when(instance.getTag(any(), any(), any())).then(mock -> {
String registry = mock.getArgument(0);
diff --git a/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java b/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java

View file

@ -5121,7 +5121,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- 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 {
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.hasTool() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null);
return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasTool() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null);
}
+ // Paper start

View file

@ -11605,7 +11605,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ // ticket level state
+ private int oldTicketLevel = ChunkHolderManager.MAX_TICKET_LEVEL + 1;
+ public int oldTicketLevel = ChunkHolderManager.MAX_TICKET_LEVEL + 1;
+ private int currentTicketLevel = ChunkHolderManager.MAX_TICKET_LEVEL + 1;
+
+ public int getTicketLevel() {
@ -22635,6 +22635,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
// Paper end
// CraftBukkit start
public LevelChunk getFullChunkNow() {
// Note: We use the oldTicketLevel for isLoaded checks.
- if (!ChunkLevel.fullStatus(this.oldTicketLevel).isOrAfter(FullChunkStatus.FULL)) return null;
+ if (!ChunkLevel.fullStatus(this.newChunkHolder.oldTicketLevel).isOrAfter(FullChunkStatus.FULL)) return null; // Paper - rewrite chunk system
return this.getFullChunkNowUnchecked();
}
@@ -0,0 +0,0 @@ public class ChunkHolder extends GenerationChunkHolder {
// CraftBukkit end
@ -24862,12 +24869,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ };
- return this.chunkAbsent(playerchunk, l) ? GenerationChunkHolder.UNLOADED_CHUNK_FUTURE : playerchunk.scheduleChunkGenerationTask(leastStatus, this.chunkMap);
- }
+ ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().scheduleChunkLoad(
+ chunkX, chunkZ, leastStatus, true,
+ ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.HIGHER,
+ complete
+ );
+
- private boolean chunkAbsent(@Nullable ChunkHolder holder, int maxLevel) {
- return holder == null || holder.oldTicketLevel > maxLevel; // CraftBukkit using oldTicketLevel for isLoaded checks
+ return ret;
+ } else {
+ // can return now
@ -24876,9 +24886,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - rewrite chunk system
}
private boolean chunkAbsent(@Nullable ChunkHolder holder, int maxLevel) {
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
@Override
public boolean hasChunk(int x, int z) {
- ChunkHolder playerchunk = this.getVisibleChunkIfPresent((new ChunkPos(x, z)).toLong());

View file

@ -9,18 +9,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- 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 {
this.damage = meta.damage;
this.maxDamage = meta.maxDamage;
this.unhandledTags = meta.unhandledTags;
this.unhandledTags.copy(meta.unhandledTags.build());
this.removedTags.addAll(meta.removedTags);
- this.persistentDataContainer.putAll(meta.persistentDataContainer.getRaw());
+ this.persistentDataContainer.putAll(meta.persistentDataContainer.getTagsCloned()); // Paper - deep clone NBT tags
this.customTag = meta.customTag;
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
if (this.customTag != null) {
clone.customTag = this.customTag.copy();
}
clone.removedTags = Sets.newHashSet(this.removedTags);
- clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getRaw(), CraftMetaItem.DATA_TYPE_REGISTRY);
+ clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getTagsCloned(), CraftMetaItem.DATA_TYPE_REGISTRY); // Paper - deep clone NBT tags
clone.hideFlag = this.hideFlag;

View file

@ -27,12 +27,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
Set<Map.Entry<DataComponentType<?>, Optional<?>>> keys = tag.entrySet();
for (Map.Entry<DataComponentType<?>, Optional<?>> key : keys) {
- if (!CraftMetaItem.getHandledTags().contains(key.getKey())) {
+ // Paper start - don't lose unhandled tags
+ if (key.getValue().isEmpty()) {
+ this.unhandledTags.remove(key.getKey());
+ } else if (!CraftMetaItem.getHandledTags().contains(key.getKey())) {
key.getValue().ifPresentOrElse((value) -> {
+ // Paper end - don't lose unhandled tags
key.getValue().ifPresent((value) -> {
this.unhandledTags.set((DataComponentType) key.getKey(), value);
}, () -> {
});
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
}
@ -44,4 +46,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }, () -> itemTag.remove(e.getKey()));
}
CompoundTag customTag = (this.customTag != null) ? this.customTag.copy() : null;
for (DataComponentType<?> removed : this.removedTags) {

View file

@ -14,7 +14,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private boolean sweep = false;
private boolean melting = false;
private boolean poison = false;
- private Entity customEntityDamager = null; // This field is a helper for when causing entity damage is not set by vanilla
- private Entity customEntityDamager = null; // This field is a helper for when direct entity damage is not set by vanilla
- private Entity customCausingEntityDamager = null; // This field is a helper for when causing entity damage is not set by vanilla
+ @Nullable
+ private Entity customEventDamager = null; // This field is a helper for when causing entity damage is not set by vanilla // Paper - fix DamageSource API
@ -26,23 +27,38 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- public Entity getDamager() {
- return (this.customEntityDamager != null) ? this.customEntityDamager : this.directEntity;
- }
-
- public Entity getCausingDamager() {
- return (this.customCausingEntityDamager != null) ? this.customCausingEntityDamager : this.causingEntity;
- }
-
- public DamageSource customEntityDamager(Entity entity) {
- // This method is not intended for change the causing entity if is already set
- // also is only necessary if the entity passed is not the direct entity or different from the current causingEntity
- if (this.customEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) {
- return this;
- }
- DamageSource damageSource = this.cloneInstance();
- damageSource.customEntityDamager = entity;
- return damageSource;
+ // Paper start - fix DamageSource API
+ @Nullable
+ public Entity getCustomEventDamager() {
+ return (this.customEventDamager != null) ? this.customEventDamager : this.directEntity;
}
- public DamageSource customEntityDamager(Entity entity) {
- public DamageSource customCausingEntityDamager(Entity entity) {
- // This method is not intended for change the causing entity if is already set
- // also is only necessary if the entity passed is not the direct entity or different from the current causingEntity
- if (this.customEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) {
- if (this.customCausingEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) {
- return this;
+ public DamageSource customEventDamager(Entity entity) {
+ if (this.directEntity != null) {
+ throw new IllegalStateException("Cannot set custom event damager when direct entity is already set (report a bug to Paper)");
}
DamageSource damageSource = this.cloneInstance();
- damageSource.customEntityDamager = entity;
- damageSource.customCausingEntityDamager = entity;
+ damageSource.customEventDamager = entity;
+ // Paper end - fix DamageSource API
return damageSource;
@ -114,7 +130,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (!event.isCancelled()) {
// CraftBukkit end
this.dead = true;
- this.level().explode(this, net.minecraft.world.level.Explosion.getDefaultDamageSource(this.level(), this).customEntityDamager(this.entityIgniter), null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.MOB); // CraftBukkit
- this.level().explode(this, net.minecraft.world.level.Explosion.getDefaultDamageSource(this.level(), this).customCausingEntityDamager(this.entityIgniter), null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.MOB); // CraftBukkit
+ this.level().explode(this, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.MOB); // CraftBukkit // Paper - fix DamageSource API (revert to vanilla, no, just no, don't change this)
this.spawnLingeringCloud();
this.triggerOnDeathMobEffects(Entity.RemovalReason.KILLED);
@ -164,6 +180,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+++ b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java
@@ -0,0 +0,0 @@ public class CraftDamageSource implements DamageSource {
@Override
public org.bukkit.entity.Entity getCausingEntity() {
- net.minecraft.world.entity.Entity entity = this.getHandle().getCausingDamager();
+ net.minecraft.world.entity.Entity entity = this.getHandle().getCustomEventDamager(); // Paper
return (entity != null) ? entity.getBukkitEntity() : null;
}
@Override
public org.bukkit.entity.Entity getDirectEntity() {
- net.minecraft.world.entity.Entity entity = this.getHandle().getDamager();

View file

@ -82,23 +82,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
Set<Map.Entry<DataComponentType<?>, Optional<?>>> keys = tag.entrySet();
for (Map.Entry<DataComponentType<?>, Optional<?>> key : keys) {
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.getDecoder().decode(unhandled));
try {
CompoundTag unhandledTag = NbtIo.readCompressed(buf, NbtAccounter.unlimitedHeap());
- this.unhandledTags.copy(DataComponentPatch.CODEC.parse(MinecraftServer.getDefaultRegistryAccess().createSerializationContext(NbtOps.INSTANCE), unhandledTag).result().get());
DataComponentPatch unhandledPatch = DataComponentPatch.CODEC.parse(MinecraftServer.getDefaultRegistryAccess().createSerializationContext(NbtOps.INSTANCE), unhandledTag).result().get();
- this.unhandledTags.copy(unhandledPatch);
+ // Paper start
+ final net.minecraft.core.component.DataComponentPatch patch = net.minecraft.core.component.DataComponentPatch.CODEC.parse(net.minecraft.server.MinecraftServer.getDefaultRegistryAccess().createSerializationContext(net.minecraft.nbt.NbtOps.INSTANCE), unhandledTag).result().get();
+ CraftMetaItem.getOrEmpty(patch, CraftMetaItem.CAN_PLACE_ON).ifPresent(data -> {
+ CraftMetaItem.getOrEmpty(unhandledPatch, CraftMetaItem.CAN_PLACE_ON).ifPresent(data -> {
+ this.canPlaceOnPredicates = List.copyOf(data.predicates);
+ });
+ CraftMetaItem.getOrEmpty(patch, CraftMetaItem.CAN_BREAK).ifPresent(data -> {
+ CraftMetaItem.getOrEmpty(unhandledPatch, CraftMetaItem.CAN_BREAK).ifPresent(data -> {
+ this.canBreakPredicates = List.copyOf(data.predicates);
+ });
+ this.unhandledTags.copy(patch.forget(type -> type == CraftMetaItem.CAN_PLACE_ON.TYPE || type == CraftMetaItem.CAN_BREAK.TYPE));
+ this.unhandledTags.copy(unhandledPatch.forget(type -> type == CraftMetaItem.CAN_PLACE_ON.TYPE || type == CraftMetaItem.CAN_BREAK.TYPE));
+ // Paper end
} catch (IOException ex) {
Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
}
for (Entry<DataComponentType<?>, Optional<?>> entry : unhandledPatch.entrySet()) {
// Move removed unhandled tags to dedicated removedTags
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
itemTag.put(CraftMetaItem.MAX_DAMAGE, this.maxDamage);
}
@ -119,8 +118,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@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.hasTool() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null);
+ 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.hasTool() || 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.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasTool() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null);
+ return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasTool() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null); // Paper
}
// Paper start
@ -187,8 +186,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end
if (!this.persistentDataContainer.isEmpty()) { // Store custom tags, wrapped in their compound
builder.put(CraftMetaItem.BUKKIT_CUSTOM_TAG.BUKKIT, this.persistentDataContainer.serialize());
if (!this.removedTags.isEmpty()) {
RegistryAccess registryAccess = CraftRegistry.getMinecraftRegistry();
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
CraftMetaItem.MAX_DAMAGE.TYPE,
CraftMetaItem.CUSTOM_DATA.TYPE,

View file

@ -358,8 +358,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
@Override
@@ -0,0 +0,0 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
@Override
public CraftMetaBlockState clone() {
CraftMetaBlockState meta = (CraftMetaBlockState) super.clone();
- if (this.blockEntityTag != null) {
@ -531,9 +529,9 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableAr
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java
@@ -0,0 +0,0 @@ public class CraftMetaColorableArmor extends CraftMetaArmor implements Colorable
Material.WOLF_ARMOR
);
@@ -0,0 +0,0 @@ import org.bukkit.inventory.meta.ColorableArmorMeta;
@DelegateDeserialization(SerializableMeta.class)
public class CraftMetaColorableArmor extends CraftMetaArmor implements ColorableArmorMeta {
- private Color color = DEFAULT_LEATHER_COLOR;
+ private Integer color; // Paper - keep color component consistent with vanilla (top byte is ignored)
@ -889,15 +887,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
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.hasTool() || 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.hasTool() || 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
@ -1059,8 +1048,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- && (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))
&& (this.removedTags.equals(that.removedTags))
&& (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.hasTool() ? this.tool.hashCode() : 0);
hash = 61 * hash + (this.hasJukeboxPlayable() ? this.jukebox.hashCode() : 0);

View file

@ -6189,7 +6189,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end
// CraftBukkit start
public LevelChunk getFullChunkNow() {
return (LevelChunk) this.getChunkIfPresent(ChunkStatus.FULL);
// Note: We use the oldTicketLevel for isLoaded checks.
@@ -0,0 +0,0 @@ public class ChunkHolder extends GenerationChunkHolder {
}
// CraftBukkit end

View file

@ -395,7 +395,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@Override
public FireworkMeta getFireworkMeta() {
- return (FireworkMeta) this.item.getItemMeta();
+ return (FireworkMeta) CraftItemStack.getItemMeta(this.getHandle().getEntityData().get(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM), Material.FIREWORK_ROCKET); // Paper - Expose firework item directly
+ return (FireworkMeta) CraftItemStack.getItemMeta(this.getHandle().getEntityData().get(FireworkRocketEntity.DATA_ID_FIREWORKS_ITEM), org.bukkit.inventory.ItemType.FIREWORK_ROCKET); // Paper - Expose firework item directly
}
@Override
@ -643,7 +643,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - Projectile API
+ @Override
+ public org.bukkit.inventory.meta.PotionMeta getPotionMeta() {
+ return (org.bukkit.inventory.meta.PotionMeta) CraftItemStack.getItemMeta(this.getHandle().getItem(), Material.SPLASH_POTION);
+ return (org.bukkit.inventory.meta.PotionMeta) CraftItemStack.getItemMeta(this.getHandle().getItem(), org.bukkit.inventory.ItemType.SPLASH_POTION);
+ }
+
+ @Override
@ -748,16 +748,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item) {
+ return getItemMeta(item, CraftItemStack.getType(item));
+ return getItemMeta(item, null);
+ }
+ public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item, Material material) {
+ public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item, org.bukkit.inventory.ItemType metaForType) {
+ // Paper end
if (!CraftItemStack.hasItemMeta(item)) {
- return CraftItemFactory.instance().getItemMeta(CraftItemStack.getType(item));
+ return CraftItemFactory.instance().getItemMeta(material); // Paper
return CraftItemFactory.instance().getItemMeta(CraftItemStack.getType(item));
}
- switch (CraftItemStack.getType(item)) {
+ switch (material) { // Paper
case WRITTEN_BOOK:
return new CraftMetaBookSigned(item.getComponentsPatch());
case WRITABLE_BOOK:
+ if (metaForType != null) { return ((CraftItemType<?>) metaForType).getItemMeta(item); } // Paper
return ((CraftItemType<?>) CraftItemType.minecraftToBukkitNew(item.getItem())).getItemMeta(item);
}

View file

@ -9,7 +9,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
return false; // CraftBukkit - Return event status
return true; // CraftBukkit - Return event status
}
- PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause);

View file

@ -355,7 +355,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/test/java/org/bukkit/support/DummyServer.java
+++ b/src/test/java/org/bukkit/support/DummyServer.java
@@ -0,0 +0,0 @@ public final class DummyServer {
return registers.computeIfAbsent(aClass, key -> CraftRegistry.createRegistry(aClass, AbstractTestingBase.REGISTRY_CUSTOM));
return null;
});
+ // Paper start - testing additions

View file

@ -4,30 +4,19 @@ Date: Tue, 11 Jul 2023 11:22:30 -0700
Subject: [PATCH] fix item meta for tadpole buckets
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
@@ -0,0 +0,0 @@ public final class CraftItemFactory implements ItemFactory {
case COD_BUCKET:
case PUFFERFISH_BUCKET:
case SALMON_BUCKET:
+ case TADPOLE_BUCKET: // Paper
case ITEM_FRAME:
case GLOW_ITEM_FRAME:
case PAINTING:
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 {
case COD_BUCKET:
case PUFFERFISH_BUCKET:
case SALMON_BUCKET:
+ case TADPOLE_BUCKET: // Paper
case ITEM_FRAME:
case GLOW_ITEM_FRAME:
case PAINTING:
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
@@ -0,0 +0,0 @@ public final class CraftItemMetas {
if (itemType == ItemType.SUSPICIOUS_STEW) {
return CraftItemMetas.asType(CraftItemMetas.SUSPICIOUS_STEW_META_DATA);
}
- if (itemType == ItemType.COD_BUCKET || itemType == ItemType.PUFFERFISH_BUCKET
+ if (itemType == ItemType.COD_BUCKET || itemType == ItemType.PUFFERFISH_BUCKET || itemType == ItemType.TADPOLE_BUCKET // Paper
|| itemType == ItemType.SALMON_BUCKET || itemType == ItemType.ITEM_FRAME
|| itemType == ItemType.GLOW_ITEM_FRAME || itemType == ItemType.PAINTING) {
return CraftItemMetas.asType(CraftItemMetas.ENTITY_TAG_META_DATA);
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java

View file

@ -4,6 +4,155 @@ Date: Mon, 10 Jul 2023 16:10:15 -0700
Subject: [PATCH] improve checking handled tags in itemmeta
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java
@@ -0,0 +0,0 @@ import org.bukkit.inventory.meta.TropicalFishBucketMeta;
public final class CraftItemMetas {
- public record ItemMetaData<I extends ItemMeta>(Class<I> metaClass, Function<ItemStack, I> fromItemStack,
+ public record ItemMetaData<I extends ItemMeta>(Class<I> metaClass, BiFunction<ItemStack, java.util.Set<net.minecraft.core.component.DataComponentType<?>>, I> fromItemStack,
BiFunction<ItemType.Typed<I>, CraftMetaItem, I> fromItemMeta) {
}
private static final ItemMetaData<ItemMeta> EMPTY_META_DATA = new ItemMetaData<>(ItemMeta.class,
- item -> null,
+ (item, extras) -> null,
(type, meta) -> null);
private static final ItemMetaData<ItemMeta> ITEM_META_DATA = new ItemMetaData<>(ItemMeta.class,
- item -> new CraftMetaItem(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaItem(item.getComponentsPatch(), extras),
(type, meta) -> new CraftMetaItem(meta));
private static final ItemMetaData<BookMeta> SIGNED_BOOK_META_DATA = new ItemMetaData<>(BookMeta.class,
- item -> new CraftMetaBookSigned(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaBookSigned(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaBookSigned signed ? signed : new CraftMetaBookSigned(meta));
private static final ItemMetaData<BookMeta> WRITABLE_BOOK_META_DATA = new ItemMetaData<>(BookMeta.class,
- item -> new CraftMetaBook(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaBook(item.getComponentsPatch(), extras),
(type, meta) -> meta != null && meta.getClass().equals(CraftMetaBook.class) ? (BookMeta) meta : new CraftMetaBook(meta));
private static final ItemMetaData<SkullMeta> SKULL_META_DATA = new ItemMetaData<>(SkullMeta.class,
- item -> new CraftMetaSkull(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaSkull(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaSkull skull ? skull : new CraftMetaSkull(meta));
private static final ItemMetaData<ArmorMeta> ARMOR_META_DATA = new ItemMetaData<>(ArmorMeta.class,
- item -> new CraftMetaArmor(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaArmor(item.getComponentsPatch(), extras),
(type, meta) -> meta != null && meta.getClass().equals(CraftMetaArmor.class) ? (ArmorMeta) meta : new CraftMetaArmor(meta));
private static final ItemMetaData<ColorableArmorMeta> COLORABLE_ARMOR_META_DATA = new ItemMetaData<>(ColorableArmorMeta.class,
- item -> new CraftMetaColorableArmor(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaColorableArmor(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof ColorableArmorMeta colorable ? colorable : new CraftMetaColorableArmor(meta));
private static final ItemMetaData<LeatherArmorMeta> LEATHER_ARMOR_META_DATA = new ItemMetaData<>(LeatherArmorMeta.class,
- item -> new CraftMetaLeatherArmor(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaLeatherArmor(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaLeatherArmor leather ? leather : new CraftMetaLeatherArmor(meta));
private static final ItemMetaData<PotionMeta> POTION_META_DATA = new ItemMetaData<>(PotionMeta.class,
- item -> new CraftMetaPotion(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaPotion(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaPotion potion ? potion : new CraftMetaPotion(meta));
private static final ItemMetaData<MapMeta> MAP_META_DATA = new ItemMetaData<>(MapMeta.class,
- item -> new CraftMetaMap(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaMap(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaMap map ? map : new CraftMetaMap(meta));
private static final ItemMetaData<FireworkMeta> FIREWORK_META_DATA = new ItemMetaData<>(FireworkMeta.class,
- item -> new CraftMetaFirework(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaFirework(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaFirework firework ? firework : new CraftMetaFirework(meta));
private static final ItemMetaData<FireworkEffectMeta> CHARGE_META_DATA = new ItemMetaData<>(FireworkEffectMeta.class,
- item -> new CraftMetaCharge(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaCharge(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaCharge charge ? charge : new CraftMetaCharge(meta));
private static final ItemMetaData<EnchantmentStorageMeta> ENCHANTED_BOOK_META_DATA = new ItemMetaData<>(EnchantmentStorageMeta.class,
- item -> new CraftMetaEnchantedBook(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaEnchantedBook(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaEnchantedBook enchantedBook ? enchantedBook : new CraftMetaEnchantedBook(meta));
private static final ItemMetaData<BannerMeta> BANNER_META_DATA = new ItemMetaData<>(BannerMeta.class,
- item -> new CraftMetaBanner(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaBanner(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaBanner banner ? banner : new CraftMetaBanner(meta));
private static final ItemMetaData<SpawnEggMeta> SPAWN_EGG_META_DATA = new ItemMetaData<>(SpawnEggMeta.class,
- item -> new CraftMetaSpawnEgg(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaSpawnEgg(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaSpawnEgg spawnEgg ? spawnEgg : new CraftMetaSpawnEgg(meta));
private static final ItemMetaData<ArmorStandMeta> ARMOR_STAND_META_DATA = new ItemMetaData<>(ArmorStandMeta.class, // paper
- item -> new CraftMetaArmorStand(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaArmorStand(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaArmorStand armorStand ? armorStand : new CraftMetaArmorStand(meta));
private static final ItemMetaData<KnowledgeBookMeta> KNOWLEDGE_BOOK_META_DATA = new ItemMetaData<>(KnowledgeBookMeta.class,
- item -> new CraftMetaKnowledgeBook(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaKnowledgeBook(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaKnowledgeBook knowledgeBook ? knowledgeBook : new CraftMetaKnowledgeBook(meta));
private static final ItemMetaData<BlockStateMeta> BLOCK_STATE_META_DATA = new ItemMetaData<>(BlockStateMeta.class,
- item -> new CraftMetaBlockState(item.getComponentsPatch(), CraftItemType.minecraftToBukkit(item.getItem())),
+ (item, extras) -> new CraftMetaBlockState(item.getComponentsPatch(), CraftItemType.minecraftToBukkit(item.getItem()), extras),
(type, meta) -> new CraftMetaBlockState(meta, type.asMaterial()));
private static final ItemMetaData<TropicalFishBucketMeta> TROPICAL_FISH_BUCKET_META_DATA = new ItemMetaData<>(TropicalFishBucketMeta.class,
- item -> new CraftMetaTropicalFishBucket(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaTropicalFishBucket(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaTropicalFishBucket tropicalFishBucket ? tropicalFishBucket : new CraftMetaTropicalFishBucket(meta));
private static final ItemMetaData<AxolotlBucketMeta> AXOLOTL_BUCKET_META_DATA = new ItemMetaData<>(AxolotlBucketMeta.class,
- item -> new CraftMetaAxolotlBucket(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaAxolotlBucket(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaAxolotlBucket axolotlBucket ? axolotlBucket : new CraftMetaAxolotlBucket(meta));
private static final ItemMetaData<CrossbowMeta> CROSSBOW_META_DATA = new ItemMetaData<>(CrossbowMeta.class,
- item -> new CraftMetaCrossbow(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaCrossbow(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaCrossbow crossbow ? crossbow : new CraftMetaCrossbow(meta));
private static final ItemMetaData<SuspiciousStewMeta> SUSPICIOUS_STEW_META_DATA = new ItemMetaData<>(SuspiciousStewMeta.class,
- item -> new CraftMetaSuspiciousStew(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaSuspiciousStew(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaSuspiciousStew suspiciousStew ? suspiciousStew : new CraftMetaSuspiciousStew(meta));
private static final ItemMetaData<ItemMeta> ENTITY_TAG_META_DATA = new ItemMetaData<>(ItemMeta.class,
- item -> new CraftMetaEntityTag(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaEntityTag(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaEntityTag entityTag ? entityTag : new CraftMetaEntityTag(meta));
private static final ItemMetaData<CompassMeta> COMPASS_META_DATA = new ItemMetaData<>(CompassMeta.class,
- item -> new CraftMetaCompass(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaCompass(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaCompass compass ? compass : new CraftMetaCompass(meta));
private static final ItemMetaData<BundleMeta> BUNDLE_META_DATA = new ItemMetaData<>(BundleMeta.class,
- item -> new CraftMetaBundle(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaBundle(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaBundle bundle ? bundle : new CraftMetaBundle(meta));
private static final ItemMetaData<MusicInstrumentMeta> MUSIC_INSTRUMENT_META_DATA = new ItemMetaData<>(MusicInstrumentMeta.class,
- item -> new CraftMetaMusicInstrument(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaMusicInstrument(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaMusicInstrument musicInstrument ? musicInstrument : new CraftMetaMusicInstrument(meta));
private static final ItemMetaData<OminousBottleMeta> OMINOUS_BOTTLE_META_DATA = new ItemMetaData<>(OminousBottleMeta.class,
- item -> new CraftMetaOminousBottle(item.getComponentsPatch()),
+ (item, extras) -> new CraftMetaOminousBottle(item.getComponentsPatch(), extras),
(type, meta) -> meta instanceof CraftMetaOminousBottle musicInstrument ? musicInstrument : new CraftMetaOminousBottle(meta));
// We use if instead of a set, since the result gets cached in CraftItemType,
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
@ -33,7 +182,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ newMeta = getItemMeta(this.handle);
+ } else {
+ final java.util.Set<net.minecraft.core.component.DataComponentType<?>> extraHandledDcts = new java.util.HashSet<>(CraftMetaItem.getTopLevelHandledDcts(oldMeta.getClass()));
+ newMeta = getItemMeta(this.handle, CraftItemStack.getType(this.handle), extraHandledDcts);
+ newMeta = getItemMeta(this.handle, CraftItemType.minecraftToBukkitNew(this.handle.getItem()), extraHandledDcts);
+ }
+ this.setItemMeta(newMeta);
+ }
@ -43,141 +192,39 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
final CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator();
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
}
public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item, Material material) {
public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item, org.bukkit.inventory.ItemType metaForType) {
// Paper end
+ // Paper start - handled tags on type change
+ return getItemMeta(item, material, null);
+ return getItemMeta(item, metaForType, null);
+ }
+ public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item, Material material, final java.util.Set<net.minecraft.core.component.DataComponentType<?>> extraHandledDcts) {
+ public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item, org.bukkit.inventory.ItemType metaForType, final java.util.Set<net.minecraft.core.component.DataComponentType<?>> extraHandledDcts) {
+ // Paper end - handled tags on type change
if (!CraftItemStack.hasItemMeta(item)) {
return CraftItemFactory.instance().getItemMeta(material); // Paper
}
switch (material) { // Paper
case WRITTEN_BOOK:
- return new CraftMetaBookSigned(item.getComponentsPatch());
+ return new CraftMetaBookSigned(item.getComponentsPatch(), extraHandledDcts); // Paper
case WRITABLE_BOOK:
- return new CraftMetaBook(item.getComponentsPatch());
+ return new CraftMetaBook(item.getComponentsPatch(), extraHandledDcts); // Paper
case CREEPER_HEAD:
case CREEPER_WALL_HEAD:
case DRAGON_HEAD:
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
case WITHER_SKELETON_WALL_SKULL:
case ZOMBIE_HEAD:
case ZOMBIE_WALL_HEAD:
- return new CraftMetaSkull(item.getComponentsPatch());
+ return new CraftMetaSkull(item.getComponentsPatch(), extraHandledDcts); // Paper
case CHAINMAIL_HELMET:
case CHAINMAIL_CHESTPLATE:
case CHAINMAIL_LEGGINGS:
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
case NETHERITE_LEGGINGS:
case NETHERITE_BOOTS:
case TURTLE_HELMET:
- return new CraftMetaArmor(item.getComponentsPatch());
+ return new CraftMetaArmor(item.getComponentsPatch(), extraHandledDcts); // Paper
case LEATHER_HELMET:
case LEATHER_CHESTPLATE:
case LEATHER_LEGGINGS:
case LEATHER_BOOTS:
case WOLF_ARMOR:
- return new CraftMetaColorableArmor(item.getComponentsPatch());
+ return new CraftMetaColorableArmor(item.getComponentsPatch(), extraHandledDcts); // Paper
case LEATHER_HORSE_ARMOR:
- return new CraftMetaLeatherArmor(item.getComponentsPatch());
+ return new CraftMetaLeatherArmor(item.getComponentsPatch(), extraHandledDcts); // Paper
case POTION:
case SPLASH_POTION:
case LINGERING_POTION:
case TIPPED_ARROW:
- return new CraftMetaPotion(item.getComponentsPatch());
+ return new CraftMetaPotion(item.getComponentsPatch(), extraHandledDcts); // Paper
case FILLED_MAP:
- return new CraftMetaMap(item.getComponentsPatch());
+ return new CraftMetaMap(item.getComponentsPatch(), extraHandledDcts); // Paper
case FIREWORK_ROCKET:
- return new CraftMetaFirework(item.getComponentsPatch());
+ return new CraftMetaFirework(item.getComponentsPatch(), extraHandledDcts); // Paper
case FIREWORK_STAR:
- return new CraftMetaCharge(item.getComponentsPatch());
+ return new CraftMetaCharge(item.getComponentsPatch(), extraHandledDcts); // Paper;
case ENCHANTED_BOOK:
- return new CraftMetaEnchantedBook(item.getComponentsPatch());
+ return new CraftMetaEnchantedBook(item.getComponentsPatch(), extraHandledDcts); // Paper
case BLACK_BANNER:
case BLACK_WALL_BANNER:
case BLUE_BANNER:
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
case WHITE_WALL_BANNER:
case YELLOW_BANNER:
case YELLOW_WALL_BANNER:
- return new CraftMetaBanner(item.getComponentsPatch());
+ return new CraftMetaBanner(item.getComponentsPatch(), extraHandledDcts); // Paper
case ARMADILLO_SPAWN_EGG:
case ALLAY_SPAWN_EGG:
case AXOLOTL_SPAWN_EGG:
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
case ZOMBIE_SPAWN_EGG:
case ZOMBIE_VILLAGER_SPAWN_EGG:
case ZOMBIFIED_PIGLIN_SPAWN_EGG:
- return new CraftMetaSpawnEgg(item.getComponentsPatch());
+ return new CraftMetaSpawnEgg(item.getComponentsPatch(), extraHandledDcts); // Paper
case ARMOR_STAND:
- return new CraftMetaArmorStand(item.getComponentsPatch());
+ return new CraftMetaArmorStand(item.getComponentsPatch(), extraHandledDcts); // Paper
case KNOWLEDGE_BOOK:
- return new CraftMetaKnowledgeBook(item.getComponentsPatch());
+ return new CraftMetaKnowledgeBook(item.getComponentsPatch(), extraHandledDcts); // Paper
case FURNACE:
case CHEST:
case TRAPPED_CHEST:
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
case CRAFTER:
case TRIAL_SPAWNER:
case VAULT:
- return new CraftMetaBlockState(item.getComponentsPatch(), CraftItemType.minecraftToBukkit(item.getItem()));
+ return new CraftMetaBlockState(item.getComponentsPatch(), CraftItemType.minecraftToBukkit(item.getItem()), extraHandledDcts); // Paper
case TROPICAL_FISH_BUCKET:
- return new CraftMetaTropicalFishBucket(item.getComponentsPatch());
+ return new CraftMetaTropicalFishBucket(item.getComponentsPatch(), extraHandledDcts); // Paper
case AXOLOTL_BUCKET:
- return new CraftMetaAxolotlBucket(item.getComponentsPatch());
+ return new CraftMetaAxolotlBucket(item.getComponentsPatch(), extraHandledDcts); // Paper
case CROSSBOW:
- return new CraftMetaCrossbow(item.getComponentsPatch());
+ return new CraftMetaCrossbow(item.getComponentsPatch(), extraHandledDcts); // Paper
case SUSPICIOUS_STEW:
- return new CraftMetaSuspiciousStew(item.getComponentsPatch());
+ return new CraftMetaSuspiciousStew(item.getComponentsPatch(), extraHandledDcts); // Paper
case COD_BUCKET:
case PUFFERFISH_BUCKET:
case SALMON_BUCKET:
@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack {
case ITEM_FRAME:
case GLOW_ITEM_FRAME:
case PAINTING:
- return new CraftMetaEntityTag(item.getComponentsPatch());
+ return new CraftMetaEntityTag(item.getComponentsPatch(), extraHandledDcts); // Paper
case COMPASS:
- return new CraftMetaCompass(item.getComponentsPatch());
+ return new CraftMetaCompass(item.getComponentsPatch(), extraHandledDcts); // Paper
case BUNDLE:
- return new CraftMetaBundle(item.getComponentsPatch());
+ return new CraftMetaBundle(item.getComponentsPatch(), extraHandledDcts); // Paper
case GOAT_HORN:
- return new CraftMetaMusicInstrument(item.getComponentsPatch());
+ return new CraftMetaMusicInstrument(item.getComponentsPatch(), extraHandledDcts); // Paper
case OMINOUS_BOTTLE:
- return new CraftMetaOminousBottle(item.getComponentsPatch());
+ return new CraftMetaOminousBottle(item.getComponentsPatch(), extraHandledDcts); // Paper
default:
- return new CraftMetaItem(item.getComponentsPatch());
+ return new CraftMetaItem(item.getComponentsPatch(), extraHandledDcts); // Paper
return CraftItemFactory.instance().getItemMeta(CraftItemStack.getType(item));
}
- if (metaForType != null) { return ((CraftItemType<?>) metaForType).getItemMeta(item); } // Paper
- return ((CraftItemType<?>) CraftItemType.minecraftToBukkitNew(item.getItem())).getItemMeta(item);
+ if (metaForType != null) { return ((CraftItemType<?>) metaForType).getItemMeta(item, extraHandledDcts); } // Paper
+ return ((CraftItemType<?>) CraftItemType.minecraftToBukkitNew(item.getItem())).getItemMeta(item, extraHandledDcts); // Paper
}
static Material getType(net.minecraft.world.item.ItemStack item) {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
@@ -0,0 +0,0 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
return this.item;
}
- public M getItemMeta(net.minecraft.world.item.ItemStack itemStack) {
- return this.itemMetaData.get().fromItemStack().apply(itemStack);
+ public M getItemMeta(net.minecraft.world.item.ItemStack itemStack, final java.util.Set<net.minecraft.core.component.DataComponentType<?>> extraHandledDcts) {
+ return this.itemMetaData.get().fromItemStack().apply(itemStack, extraHandledDcts);
}
public M getItemMeta(ItemMeta itemMeta) {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
@ -429,13 +476,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - improve checking handled data component types
Set<Map.Entry<DataComponentType<?>, Optional<?>>> keys = tag.entrySet();
for (Map.Entry<DataComponentType<?>, Optional<?>> key : keys) {
// Paper start - don't lose unhandled tags
if (key.getValue().isEmpty()) {
this.unhandledTags.remove(key.getKey());
- } else if (!CraftMetaItem.getHandledTags().contains(key.getKey())) {
+ } else if (!handledTags.contains(key.getKey())) { // Paper - improve checking handled data component types
key.getValue().ifPresentOrElse((value) -> {
// Paper end - don't lose unhandled tags
key.getValue().ifPresent((value) -> {
this.unhandledTags.set((DataComponentType) key.getKey(), value);
}, () -> {
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
this.version = version;
}

@ -1 +1 @@
Subproject commit befcf86d22f9576c361bba18b2ec725e41508a65
Subproject commit e2160a18658bb7d19d303abd7a24605848d6912c

@ -1 +1 @@
Subproject commit a1d2cd1521b97cb4048f990455d78e7c9fb94e82
Subproject commit 6ce17264243172b5e3d14309388e131f025d90f4