diff --git a/patches/server/DataComponent-API.patch b/patches/server/DataComponent-API.patch index bd553c86fb..c7fe50a063 100644 --- a/patches/server/DataComponent-API.patch +++ b/patches/server/DataComponent-API.patch @@ -13,11 +13,11 @@ release without backwards compatibility measures. public net/minecraft/world/item/component/ItemContainerContents MAX_SIZE public net/minecraft/world/item/component/ItemContainerContents items -diff --git a/src/main/java/io/papermc/paper/datacomponent/ComponentAdapter.java b/src/main/java/io/papermc/paper/datacomponent/ComponentAdapter.java +diff --git a/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapter.java b/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapter.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 --- /dev/null -+++ b/src/main/java/io/papermc/paper/datacomponent/ComponentAdapter.java ++++ b/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapter.java @@ -0,0 +0,0 @@ +package io.papermc.paper.datacomponent; + @@ -28,7 +28,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import net.minecraft.util.Unit; +import org.bukkit.craftbukkit.CraftRegistry; + -+public record ComponentAdapter( ++public record DataComponentAdapter( + DataComponentType type, + Function apiToVanilla, + Function vanillaToApi, @@ -55,11 +55,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return this.vanillaToApi.apply(value); + } +} -diff --git a/src/main/java/io/papermc/paper/datacomponent/ComponentAdapters.java b/src/main/java/io/papermc/paper/datacomponent/ComponentAdapters.java +diff --git a/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapters.java b/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapters.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 --- /dev/null -+++ b/src/main/java/io/papermc/paper/datacomponent/ComponentAdapters.java ++++ b/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapters.java @@ -0,0 +0,0 @@ +package io.papermc.paper.datacomponent; + @@ -115,19 +115,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.bukkit.DyeColor; +import org.bukkit.craftbukkit.CraftMusicInstrument; +import org.bukkit.craftbukkit.inventory.CraftMetaFirework; -+import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.util.Handleable; +import org.bukkit.inventory.ItemRarity; + +import static io.papermc.paper.util.MCUtil.transformUnmodifiable; + -+public final class ComponentAdapters { ++public final class DataComponentAdapters { + + static final Function UNIT_TO_API_CONVERTER = $ -> { + throw new UnsupportedOperationException("Cannot convert the Unit type to an API value"); + }; + -+ static final Map>, ComponentAdapter> ADAPTERS = new HashMap<>(); ++ static final Map>, DataComponentAdapter> ADAPTERS = new HashMap<>(); + + public static void bootstrap() { + registerIdentity(DataComponents.MAX_STACK_SIZE); @@ -136,7 +135,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + register(DataComponents.UNBREAKABLE, PaperUnbreakable::new); + register(DataComponents.CUSTOM_NAME, PaperAdventure::asAdventure, PaperAdventure::asVanilla); + register(DataComponents.ITEM_NAME, PaperAdventure::asAdventure, PaperAdventure::asVanilla); -+ register(DataComponents.ITEM_MODEL, CraftNamespacedKey::fromMinecraft, CraftNamespacedKey::toMinecraft); ++ register(DataComponents.ITEM_MODEL, PaperAdventure::asAdventure, PaperAdventure::asVanilla); + register(DataComponents.LORE, PaperItemLore::new); + register(DataComponents.RARITY, nms -> ItemRarity.valueOf(nms.name()), api -> Rarity.valueOf(api.name())); + register(DataComponents.ENCHANTMENTS, PaperItemEnchantments::new); @@ -209,7 +208,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + public static void registerUntyped(final DataComponentType type) { -+ registerInternal(type, UNIT_TO_API_CONVERTER, ComponentAdapter.API_TO_UNIT_CONVERTER, false); ++ registerInternal(type, UNIT_TO_API_CONVERTER, DataComponentAdapter.API_TO_UNIT_CONVERTER, false); + } + + private static void registerIdentity(final DataComponentType type) { @@ -229,14 +228,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (ADAPTERS.containsKey(key)) { + throw new IllegalStateException("Duplicate adapter registration for " + key); + } -+ ADAPTERS.put(key, new ComponentAdapter<>(type, apiToVanilla, vanillaToApi, codecValidation && !type.isTransient())); ++ ADAPTERS.put(key, new DataComponentAdapter<>(type, apiToVanilla, vanillaToApi, codecValidation && !type.isTransient())); + } +} -diff --git a/src/main/java/io/papermc/paper/datacomponent/PaperComponentType.java b/src/main/java/io/papermc/paper/datacomponent/PaperComponentType.java +diff --git a/src/main/java/io/papermc/paper/datacomponent/PaperDataComponentType.java b/src/main/java/io/papermc/paper/datacomponent/PaperDataComponentType.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 --- /dev/null -+++ b/src/main/java/io/papermc/paper/datacomponent/PaperComponentType.java ++++ b/src/main/java/io/papermc/paper/datacomponent/PaperDataComponentType.java @@ -0,0 +0,0 @@ +package io.papermc.paper.datacomponent; + @@ -252,10 +251,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.bukkit.craftbukkit.util.Handleable; +import org.jspecify.annotations.Nullable; + -+public abstract class PaperComponentType implements DataComponentType, Handleable> { ++public abstract class PaperDataComponentType implements DataComponentType, Handleable> { + + static { -+ ComponentAdapters.bootstrap(); ++ DataComponentAdapters.bootstrap(); + } + + public static net.minecraft.core.component.DataComponentType bukkitToMinecraft(final DataComponentType type) { @@ -269,12 +268,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public static Set minecraftToBukkit(final Set> nmsTypes) { + final Set types = new HashSet<>(nmsTypes.size()); + for (final net.minecraft.core.component.DataComponentType nmsType : nmsTypes) { -+ types.add(PaperComponentType.minecraftToBukkit(nmsType)); ++ types.add(PaperDataComponentType.minecraftToBukkit(nmsType)); + } + return Collections.unmodifiableSet(types); + } + -+ public static @Nullable B convertDataComponentValue(final DataComponentMap map, final PaperComponentType.ValuedImpl type) { ++ public static @Nullable B convertDataComponentValue(final DataComponentMap map, final PaperDataComponentType.ValuedImpl type) { + final net.minecraft.core.component.DataComponentType nms = bukkitToMinecraft(type); + final M nmsValue = map.get(nms); + if (nmsValue == null) { @@ -285,9 +284,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + private final NamespacedKey key; + private final net.minecraft.core.component.DataComponentType type; -+ private final ComponentAdapter adapter; ++ private final DataComponentAdapter adapter; + -+ public PaperComponentType(final NamespacedKey key, final net.minecraft.core.component.DataComponentType type, final ComponentAdapter adapter) { ++ public PaperDataComponentType(final NamespacedKey key, final net.minecraft.core.component.DataComponentType type, final DataComponentAdapter adapter) { + this.key = key; + this.type = type; + this.adapter = adapter; @@ -303,7 +302,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return !this.type.isTransient(); + } + -+ public ComponentAdapter getAdapter() { ++ public DataComponentAdapter getAdapter() { + return this.adapter; + } + @@ -314,7 +313,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @SuppressWarnings("unchecked") + public static DataComponentType of(final NamespacedKey key, final net.minecraft.core.component.DataComponentType type) { -+ final ComponentAdapter adapter = (ComponentAdapter) ComponentAdapters.ADAPTERS.get(BuiltInRegistries.DATA_COMPONENT_TYPE.getResourceKey(type).orElseThrow()); ++ final DataComponentAdapter adapter = (DataComponentAdapter) DataComponentAdapters.ADAPTERS.get(BuiltInRegistries.DATA_COMPONENT_TYPE.getResourceKey(type).orElseThrow()); + if (adapter == null) { + throw new IllegalArgumentException("No adapter found for " + key); + } @@ -325,23 +324,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + } + -+ public static final class NonValuedImpl extends PaperComponentType implements NonValued { ++ public static final class NonValuedImpl extends PaperDataComponentType implements NonValued { + + NonValuedImpl( + final NamespacedKey key, + final net.minecraft.core.component.DataComponentType type, -+ final ComponentAdapter adapter ++ final DataComponentAdapter adapter + ) { + super(key, type, adapter); + } + } + -+ public static final class ValuedImpl extends PaperComponentType implements Valued { ++ public static final class ValuedImpl extends PaperDataComponentType implements Valued { + + ValuedImpl( + final NamespacedKey key, + final net.minecraft.core.component.DataComponentType type, -+ final ComponentAdapter adapter ++ final DataComponentAdapter adapter + ) { + super(key, type, adapter); + } @@ -3597,7 +3596,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import com.google.common.base.Preconditions; import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.datacomponent.DataComponentType; -+import io.papermc.paper.datacomponent.PaperComponentType; ++import io.papermc.paper.datacomponent.PaperDataComponentType; import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry; import io.papermc.paper.registry.data.PaperGameEventRegistryEntry; import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry; @@ -3605,7 +3604,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 entry(Registries.ATTRIBUTE, RegistryKey.ATTRIBUTE, Attribute.class, CraftAttribute::new), entry(Registries.FLUID, RegistryKey.FLUID, Fluid.class, CraftFluid::new), entry(Registries.SOUND_EVENT, RegistryKey.SOUND_EVENT, Sound.class, CraftSound::new), -+ entry(Registries.DATA_COMPONENT_TYPE, RegistryKey.DATA_COMPONENT_TYPE, DataComponentType.class, PaperComponentType::of), ++ entry(Registries.DATA_COMPONENT_TYPE, RegistryKey.DATA_COMPONENT_TYPE, DataComponentType.class, PaperDataComponentType::of), // data-drivens entry(Registries.BIOME, RegistryKey.BIOME, Biome.class, CraftBiome::new).delayed(), @@ -3613,6 +3612,20 @@ diff --git a/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 @@ import net.minecraft.world.item.enchantment.ItemEnchantments; + import org.bukkit.Material; + import org.bukkit.configuration.serialization.DelegateDeserialization; + import org.bukkit.craftbukkit.enchantments.CraftEnchantment; +-import org.bukkit.craftbukkit.util.CraftLegacy; + import org.bukkit.craftbukkit.util.CraftMagicNumbers; + import org.bukkit.enchantments.Enchantment; + import org.bukkit.inventory.ItemStack; + import org.bukkit.inventory.meta.ItemMeta; + import org.bukkit.material.MaterialData; +-import org.jetbrains.annotations.ApiStatus; + + @DelegateDeserialization(ItemStack.class) + public final class CraftItemStack extends ItemStack { @@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack { this.adjustTagForItemMeta(oldType); // Paper } @@ -3714,7 +3727,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return null; + } -+ return io.papermc.paper.datacomponent.PaperComponentType.convertDataComponentValue(this.handle.getComponents(), (io.papermc.paper.datacomponent.PaperComponentType.ValuedImpl) type); ++ return io.papermc.paper.datacomponent.PaperDataComponentType.convertDataComponentValue(this.handle.getComponents(), (io.papermc.paper.datacomponent.PaperDataComponentType.ValuedImpl) type); + } + + @Override @@ -3722,7 +3735,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return false; + } -+ return this.handle.has(io.papermc.paper.datacomponent.PaperComponentType.bukkitToMinecraft(type)); ++ return this.handle.has(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type)); + } + + @Override @@ -3730,7 +3743,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return java.util.Collections.emptySet(); + } -+ return io.papermc.paper.datacomponent.PaperComponentType.minecraftToBukkit(this.handle.getComponents().keySet()); ++ return io.papermc.paper.datacomponent.PaperDataComponentType.minecraftToBukkit(this.handle.getComponents().keySet()); + } + + @Override @@ -3739,7 +3752,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return; + } -+ this.setDataInternal((io.papermc.paper.datacomponent.PaperComponentType.ValuedImpl) type, value); ++ this.setDataInternal((io.papermc.paper.datacomponent.PaperDataComponentType.ValuedImpl) type, value); + } + + @Override @@ -3747,10 +3760,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return; + } -+ this.setDataInternal((io.papermc.paper.datacomponent.PaperComponentType.NonValuedImpl) type, null); ++ this.setDataInternal((io.papermc.paper.datacomponent.PaperDataComponentType.NonValuedImpl) type, null); + } + -+ private void setDataInternal(final io.papermc.paper.datacomponent.PaperComponentType type, final A value) { ++ private void setDataInternal(final io.papermc.paper.datacomponent.PaperDataComponentType type, final A value) { + this.handle.set(type.getHandle(), type.getAdapter().toVanilla(value)); + } + @@ -3759,7 +3772,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return; + } -+ this.handle.remove(io.papermc.paper.datacomponent.PaperComponentType.bukkitToMinecraft(type)); ++ this.handle.remove(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type)); + } + + @Override @@ -3767,11 +3780,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return; + } -+ this.resetData((io.papermc.paper.datacomponent.PaperComponentType) type); ++ this.resetData((io.papermc.paper.datacomponent.PaperDataComponentType) type); + } + -+ private void resetData(final io.papermc.paper.datacomponent.PaperComponentType type) { -+ final net.minecraft.core.component.DataComponentType nms = io.papermc.paper.datacomponent.PaperComponentType.bukkitToMinecraft(type); ++ private void resetData(final io.papermc.paper.datacomponent.PaperDataComponentType type) { ++ final net.minecraft.core.component.DataComponentType nms = io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type); + final M nmsValue = this.handle.getItem().components().get(nms); + // if nmsValue is null, it will clear any set patch + // if nmsValue is not null, it will still clear any set patch because it will equal the default value @@ -3783,7 +3796,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.isEmpty()) { + return false; + } -+ final net.minecraft.core.component.DataComponentType nms = io.papermc.paper.datacomponent.PaperComponentType.bukkitToMinecraft(type); ++ final net.minecraft.core.component.DataComponentType nms = io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type); + // maybe a more efficient way is to expose the "patch" map in PatchedDataComponentMap and just check if the type exists as a key + return !java.util.Objects.equals(this.handle.get(nms), this.handle.getPrototype().get(nms)); + } @@ -3815,7 +3828,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Collect all the NMS types into a set + java.util.Set> skippingTypes = new java.util.HashSet<>(exclude.size()); + for (io.papermc.paper.datacomponent.DataComponentType api : exclude) { -+ skippingTypes.add(io.papermc.paper.datacomponent.PaperComponentType.bukkitToMinecraft(api)); ++ skippingTypes.add(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(api)); + } + + // Check the patch by first stripping excluded types and then compare the trimmed patches @@ -3844,17 +3857,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - data component API + @Override + public T getDefaultData(final io.papermc.paper.datacomponent.DataComponentType.Valued type) { -+ return io.papermc.paper.datacomponent.PaperComponentType.convertDataComponentValue(this.item.components(), ((io.papermc.paper.datacomponent.PaperComponentType.ValuedImpl) type)); ++ return io.papermc.paper.datacomponent.PaperDataComponentType.convertDataComponentValue(this.item.components(), ((io.papermc.paper.datacomponent.PaperDataComponentType.ValuedImpl) type)); + } + + @Override + public boolean hasDefaultData(final io.papermc.paper.datacomponent.DataComponentType type) { -+ return this.item.components().has(io.papermc.paper.datacomponent.PaperComponentType.bukkitToMinecraft(type)); ++ return this.item.components().has(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type)); + } + + @Override + public java.util.Set getDefaultDataTypes() { -+ return io.papermc.paper.datacomponent.PaperComponentType.minecraftToBukkit(this.item.components().keySet()); ++ return io.papermc.paper.datacomponent.PaperDataComponentType.minecraftToBukkit(this.item.components().keySet()); + } + // Paper end - data component API } @@ -4798,7 +4811,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 register(RegistryKey.MAP_DECORATION_TYPE, MapCursor.Type.class, Registries.MAP_DECORATION_TYPE, CraftMapCursor.CraftType.class, MapDecorationType.class); register(RegistryKey.BANNER_PATTERN, PatternType.class, Registries.BANNER_PATTERN, CraftPatternType.class, BannerPattern.class); register(RegistryKey.MENU, MenuType.class, Registries.MENU, CraftMenuType.class, net.minecraft.world.inventory.MenuType.class); -+ register(RegistryKey.DATA_COMPONENT_TYPE, io.papermc.paper.datacomponent.DataComponentType.class, Registries.DATA_COMPONENT_TYPE, io.papermc.paper.datacomponent.PaperComponentType.class, net.minecraft.core.component.DataComponentType.class); ++ register(RegistryKey.DATA_COMPONENT_TYPE, io.papermc.paper.datacomponent.DataComponentType.class, Registries.DATA_COMPONENT_TYPE, io.papermc.paper.datacomponent.PaperDataComponentType.class, net.minecraft.core.component.DataComponentType.class); } private static void register(RegistryKey registryKey, Class bukkit, ResourceKey registry, Class craft, Class minecraft) { // Paper