-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy path1035-DataComponent-API.patch
More file actions
4804 lines (4783 loc) · 199 KB
/
Copy path1035-DataComponent-API.patch
File metadata and controls
4804 lines (4783 loc) · 199 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sun, 28 Apr 2024 19:53:01 -0400
Subject: [PATCH] DataComponent API
Exposes the data component logic used by vanilla ItemStack to API
consumers as a version-specific API.
The types and methods introduced by this patch do not follow the general
API deprecation contracts and will be adapted to each new minecraft
release without backwards compatibility measures.
== AT ==
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
new file mode 100644
index 0000000000000000000000000000000000000000..4a49f65cae1354afbcd4afda07581790e06094be
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/ComponentAdapter.java
@@ -0,0 +1,36 @@
+package io.papermc.paper.datacomponent;
+
+import java.util.function.Function;
+import net.minecraft.core.component.DataComponentType;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.util.NullOps;
+import net.minecraft.util.Unit;
+import org.bukkit.craftbukkit.CraftRegistry;
+
+public record ComponentAdapter<NMS, API>(
+ DataComponentType<NMS> type,
+ Function<API, NMS> apiToVanilla,
+ Function<NMS, API> vanillaToApi,
+ boolean codecValidation
+) {
+ static final Function<Void, Unit> API_TO_UNIT_CONVERTER = $ -> Unit.INSTANCE;
+
+ public boolean isValued() {
+ return this.apiToVanilla != API_TO_UNIT_CONVERTER;
+ }
+
+ public NMS toVanilla(final API value) {
+ final NMS nms = this.apiToVanilla.apply(value);
+ if (this.codecValidation) {
+ this.type.codecOrThrow().encodeStart(CraftRegistry.getMinecraftRegistry().createSerializationContext(NullOps.INSTANCE), nms).ifError(error -> {
+ throw new IllegalArgumentException("Failed to encode data component %s (%s)".formatted(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(this.type), error.message()));
+ });
+ }
+
+ return nms;
+ }
+
+ public API fromVanilla(final NMS value) {
+ 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
new file mode 100644
index 0000000000000000000000000000000000000000..ee7adf16febfb508b14ff1453e73c75a42be7d26
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/ComponentAdapters.java
@@ -0,0 +1,171 @@
+package io.papermc.paper.datacomponent;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.datacomponent.item.PaperBannerPatternLayers;
+import io.papermc.paper.datacomponent.item.PaperBlockItemDataProperties;
+import io.papermc.paper.datacomponent.item.PaperBundleContents;
+import io.papermc.paper.datacomponent.item.PaperChargedProjectiles;
+import io.papermc.paper.datacomponent.item.PaperConsumable;
+import io.papermc.paper.datacomponent.item.PaperCustomModelData;
+import io.papermc.paper.datacomponent.item.PaperDamageResistant;
+import io.papermc.paper.datacomponent.item.PaperDeathProtection;
+import io.papermc.paper.datacomponent.item.PaperDyedItemColor;
+import io.papermc.paper.datacomponent.item.PaperEnchantable;
+import io.papermc.paper.datacomponent.item.PaperEquippable;
+import io.papermc.paper.datacomponent.item.PaperFireworks;
+import io.papermc.paper.datacomponent.item.PaperFoodProperties;
+import io.papermc.paper.datacomponent.item.PaperItemAdventurePredicate;
+import io.papermc.paper.datacomponent.item.PaperItemArmorTrim;
+import io.papermc.paper.datacomponent.item.PaperItemAttributeModifiers;
+import io.papermc.paper.datacomponent.item.PaperItemContainerContents;
+import io.papermc.paper.datacomponent.item.PaperItemEnchantments;
+import io.papermc.paper.datacomponent.item.PaperItemLore;
+import io.papermc.paper.datacomponent.item.PaperItemTool;
+import io.papermc.paper.datacomponent.item.PaperJukeboxPlayable;
+import io.papermc.paper.datacomponent.item.PaperLodestoneTracker;
+import io.papermc.paper.datacomponent.item.PaperMapDecorations;
+import io.papermc.paper.datacomponent.item.PaperMapId;
+import io.papermc.paper.datacomponent.item.PaperMapItemColor;
+import io.papermc.paper.datacomponent.item.PaperOminousBottleAmplifier;
+import io.papermc.paper.datacomponent.item.PaperPotDecorations;
+import io.papermc.paper.datacomponent.item.PaperPotionContents;
+import io.papermc.paper.datacomponent.item.PaperRepairable;
+import io.papermc.paper.datacomponent.item.PaperResolvableProfile;
+import io.papermc.paper.datacomponent.item.PaperSeededContainerLoot;
+import io.papermc.paper.datacomponent.item.PaperSuspiciousStewEffects;
+import io.papermc.paper.datacomponent.item.PaperUnbreakable;
+import io.papermc.paper.datacomponent.item.PaperUseCooldown;
+import io.papermc.paper.datacomponent.item.PaperUseRemainder;
+import io.papermc.paper.datacomponent.item.PaperWritableBookContent;
+import io.papermc.paper.datacomponent.item.PaperWrittenBookContent;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import net.minecraft.core.component.DataComponentType;
+import net.minecraft.core.component.DataComponents;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.core.registries.Registries;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.util.Unit;
+import net.minecraft.world.item.Rarity;
+import net.minecraft.world.item.component.MapPostProcessing;
+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 {
+
+ static final Function<Unit, Void> UNIT_TO_API_CONVERTER = $ -> {
+ throw new UnsupportedOperationException("Cannot convert the Unit type to an API value");
+ };
+
+ static final Map<ResourceKey<DataComponentType<?>>, ComponentAdapter<?, ?>> ADAPTERS = new HashMap<>();
+
+ public static void bootstrap() {
+ registerIdentity(DataComponents.MAX_STACK_SIZE);
+ registerIdentity(DataComponents.MAX_DAMAGE);
+ registerIdentity(DataComponents.DAMAGE);
+ 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.LORE, PaperItemLore::new);
+ register(DataComponents.RARITY, nms -> ItemRarity.valueOf(nms.name()), api -> Rarity.valueOf(api.name()));
+ register(DataComponents.ENCHANTMENTS, PaperItemEnchantments::new);
+ register(DataComponents.CAN_PLACE_ON, PaperItemAdventurePredicate::new);
+ register(DataComponents.CAN_BREAK, PaperItemAdventurePredicate::new);
+ register(DataComponents.ATTRIBUTE_MODIFIERS, PaperItemAttributeModifiers::new);
+ register(DataComponents.CUSTOM_MODEL_DATA, PaperCustomModelData::new);
+ registerUntyped(DataComponents.HIDE_ADDITIONAL_TOOLTIP);
+ registerUntyped(DataComponents.HIDE_TOOLTIP);
+ registerIdentity(DataComponents.REPAIR_COST);
+ // registerUntyped(DataComponents.CREATIVE_SLOT_LOCK);
+ registerIdentity(DataComponents.ENCHANTMENT_GLINT_OVERRIDE);
+ registerUntyped(DataComponents.INTANGIBLE_PROJECTILE);
+ register(DataComponents.FOOD, PaperFoodProperties::new);
+ register(DataComponents.CONSUMABLE, PaperConsumable::new);
+ register(DataComponents.USE_REMAINDER, PaperUseRemainder::new);
+ register(DataComponents.USE_COOLDOWN, PaperUseCooldown::new);
+ register(DataComponents.DAMAGE_RESISTANT, PaperDamageResistant::new);
+ register(DataComponents.TOOL, PaperItemTool::new);
+ register(DataComponents.ENCHANTABLE, PaperEnchantable::new);
+ register(DataComponents.EQUIPPABLE, PaperEquippable::new);
+ register(DataComponents.REPAIRABLE, PaperRepairable::new);
+ registerUntyped(DataComponents.GLIDER);
+ register(DataComponents.TOOLTIP_STYLE, PaperAdventure::asAdventure, PaperAdventure::asVanilla);
+ register(DataComponents.DEATH_PROTECTION, PaperDeathProtection::new);
+ register(DataComponents.STORED_ENCHANTMENTS, PaperItemEnchantments::new);
+ register(DataComponents.DYED_COLOR, PaperDyedItemColor::new);
+ register(DataComponents.MAP_COLOR, PaperMapItemColor::new);
+ register(DataComponents.MAP_ID, PaperMapId::new);
+ register(DataComponents.MAP_DECORATIONS, PaperMapDecorations::new);
+ register(DataComponents.MAP_POST_PROCESSING, nms -> io.papermc.paper.item.MapPostProcessing.valueOf(nms.name()), api -> MapPostProcessing.valueOf(api.name()));
+ register(DataComponents.CHARGED_PROJECTILES, PaperChargedProjectiles::new);
+ register(DataComponents.BUNDLE_CONTENTS, PaperBundleContents::new);
+ register(DataComponents.POTION_CONTENTS, PaperPotionContents::new);
+ register(DataComponents.SUSPICIOUS_STEW_EFFECTS, PaperSuspiciousStewEffects::new);
+ register(DataComponents.WRITTEN_BOOK_CONTENT, PaperWrittenBookContent::new);
+ register(DataComponents.WRITABLE_BOOK_CONTENT, PaperWritableBookContent::new);
+ register(DataComponents.TRIM, PaperItemArmorTrim::new);
+ // debug stick state
+ // entity data
+ // bucket entity data
+ // block entity data
+ register(DataComponents.INSTRUMENT, CraftMusicInstrument::minecraftHolderToBukkit, CraftMusicInstrument::bukkitToMinecraftHolder);
+ register(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, PaperOminousBottleAmplifier::new);
+ register(DataComponents.JUKEBOX_PLAYABLE, PaperJukeboxPlayable::new);
+ register(DataComponents.RECIPES,
+ nms -> transformUnmodifiable(nms, PaperAdventure::asAdventureKey),
+ api -> transformUnmodifiable(api, key -> PaperAdventure.asVanilla(Registries.RECIPE, key))
+ );
+ register(DataComponents.LODESTONE_TRACKER, PaperLodestoneTracker::new);
+ register(DataComponents.FIREWORK_EXPLOSION, CraftMetaFirework::getEffect, CraftMetaFirework::getExplosion);
+ register(DataComponents.FIREWORKS, PaperFireworks::new);
+ register(DataComponents.PROFILE, PaperResolvableProfile::new);
+ register(DataComponents.NOTE_BLOCK_SOUND, PaperAdventure::asAdventure, PaperAdventure::asVanilla);
+ register(DataComponents.BANNER_PATTERNS, PaperBannerPatternLayers::new);
+ register(DataComponents.BASE_COLOR, nms -> DyeColor.getByWoolData((byte) nms.getId()), api -> net.minecraft.world.item.DyeColor.byId(api.getWoolData()));
+ register(DataComponents.POT_DECORATIONS, PaperPotDecorations::new);
+ register(DataComponents.CONTAINER, PaperItemContainerContents::new);
+ register(DataComponents.BLOCK_STATE, PaperBlockItemDataProperties::new);
+ // bees
+ // register(DataComponents.LOCK, PaperLockCode::new);
+ register(DataComponents.CONTAINER_LOOT, PaperSeededContainerLoot::new);
+
+ // TODO: REMOVE THIS... we want to build the PR... so lets just make things UNTYPED!
+ for (final Map.Entry<ResourceKey<DataComponentType<?>>, DataComponentType<?>> componentType : BuiltInRegistries.DATA_COMPONENT_TYPE.entrySet()) {
+ if (!ADAPTERS.containsKey(componentType.getKey())) {
+ registerUntyped((DataComponentType<Unit>) componentType.getValue());
+ }
+ }
+ }
+
+ public static void registerUntyped(final DataComponentType<Unit> type) {
+ registerInternal(type, UNIT_TO_API_CONVERTER, ComponentAdapter.API_TO_UNIT_CONVERTER, false);
+ }
+
+ private static <COMMON> void registerIdentity(final DataComponentType<COMMON> type) {
+ registerInternal(type, Function.identity(), Function.identity(), true);
+ }
+
+ private static <NMS, API extends Handleable<NMS>> void register(final DataComponentType<NMS> type, final Function<NMS, API> vanillaToApi) {
+ registerInternal(type, vanillaToApi, Handleable::getHandle, false);
+ }
+
+ private static <NMS, API> void register(final DataComponentType<NMS> type, final Function<NMS, API> vanillaToApi, final Function<API, NMS> apiToVanilla) {
+ registerInternal(type, vanillaToApi, apiToVanilla, false);
+ }
+
+ private static <NMS, API> void registerInternal(final DataComponentType<NMS> type, final Function<NMS, API> vanillaToApi, final Function<API, NMS> apiToVanilla, final boolean codecValidation) {
+ final ResourceKey<DataComponentType<?>> key = BuiltInRegistries.DATA_COMPONENT_TYPE.getResourceKey(type).orElseThrow();
+ if (ADAPTERS.containsKey(key)) {
+ throw new IllegalStateException("Duplicate adapter registration for " + key);
+ }
+ ADAPTERS.put(key, new ComponentAdapter<>(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
new file mode 100644
index 0000000000000000000000000000000000000000..f0d4ec462eee47840e91bac888ae46045b493f07
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/PaperComponentType.java
@@ -0,0 +1,109 @@
+package io.papermc.paper.datacomponent;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import net.minecraft.core.component.DataComponentMap;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.core.registries.Registries;
+import org.bukkit.NamespacedKey;
+import org.bukkit.Registry;
+import org.bukkit.craftbukkit.CraftRegistry;
+import org.bukkit.craftbukkit.util.Handleable;
+import org.jspecify.annotations.Nullable;
+
+public abstract class PaperComponentType<T, NMS> implements DataComponentType, Handleable<net.minecraft.core.component.DataComponentType<NMS>> {
+
+ static {
+ ComponentAdapters.bootstrap();
+ }
+
+ public static <T> net.minecraft.core.component.DataComponentType<T> bukkitToMinecraft(final DataComponentType type) {
+ return CraftRegistry.bukkitToMinecraft(type);
+ }
+
+ public static DataComponentType minecraftToBukkit(final net.minecraft.core.component.DataComponentType<?> type) {
+ return CraftRegistry.minecraftToBukkit(type, Registries.DATA_COMPONENT_TYPE, Registry.DATA_COMPONENT_TYPE);
+ }
+
+ public static Set<DataComponentType> minecraftToBukkit(final Set<net.minecraft.core.component.DataComponentType<?>> nmsTypes) {
+ final Set<DataComponentType> types = new HashSet<>(nmsTypes.size());
+ for (final net.minecraft.core.component.DataComponentType<?> nmsType : nmsTypes) {
+ types.add(PaperComponentType.minecraftToBukkit(nmsType));
+ }
+ return Collections.unmodifiableSet(types);
+ }
+
+ public static <B, M> @Nullable B convertDataComponentValue(final DataComponentMap map, final PaperComponentType.ValuedImpl<B, M> type) {
+ final net.minecraft.core.component.DataComponentType<M> nms = bukkitToMinecraft(type);
+ final M nmsValue = map.get(nms);
+ if (nmsValue == null) {
+ return null;
+ }
+ return type.getAdapter().fromVanilla(nmsValue);
+ }
+
+ private final NamespacedKey key;
+ private final net.minecraft.core.component.DataComponentType<NMS> type;
+ private final ComponentAdapter<NMS, T> adapter;
+
+ public PaperComponentType(final NamespacedKey key, final net.minecraft.core.component.DataComponentType<NMS> type, final ComponentAdapter<NMS, T> adapter) {
+ this.key = key;
+ this.type = type;
+ this.adapter = adapter;
+ }
+
+ @Override
+ public NamespacedKey getKey() {
+ return this.key;
+ }
+
+ @Override
+ public boolean isPersistent() {
+ return !this.type.isTransient();
+ }
+
+ public ComponentAdapter<NMS, T> getAdapter() {
+ return this.adapter;
+ }
+
+ @Override
+ public net.minecraft.core.component.DataComponentType<NMS> getHandle() {
+ return this.type;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <NMS> DataComponentType of(final NamespacedKey key, final net.minecraft.core.component.DataComponentType<NMS> type) {
+ final ComponentAdapter<NMS, ?> adapter = (ComponentAdapter<NMS, ?>) ComponentAdapters.ADAPTERS.get(BuiltInRegistries.DATA_COMPONENT_TYPE.getResourceKey(type).orElseThrow());
+ if (adapter == null) {
+ throw new IllegalArgumentException("No adapter found for " + key);
+ }
+ if (adapter.isValued()) {
+ return new ValuedImpl<>(key, type, adapter);
+ } else {
+ return new NonValuedImpl<>(key, type, adapter);
+ }
+ }
+
+ public static final class NonValuedImpl<T, NMS> extends PaperComponentType<T, NMS> implements NonValued {
+
+ NonValuedImpl(
+ final NamespacedKey key,
+ final net.minecraft.core.component.DataComponentType<NMS> type,
+ final ComponentAdapter<NMS, T> adapter
+ ) {
+ super(key, type, adapter);
+ }
+ }
+
+ public static final class ValuedImpl<T, NMS> extends PaperComponentType<T, NMS> implements Valued<T> {
+
+ ValuedImpl(
+ final NamespacedKey key,
+ final net.minecraft.core.component.DataComponentType<NMS> type,
+ final ComponentAdapter<NMS, T> adapter
+ ) {
+ super(key, type, adapter);
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridgesImpl.java b/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridgesImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..9111c3095986bea43d5eb06763cbe287f6853434
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/ItemComponentTypesBridgesImpl.java
@@ -0,0 +1,239 @@
+package io.papermc.paper.datacomponent.item;
+
+import com.destroystokyo.paper.profile.PlayerProfile;
+import com.google.common.base.Preconditions;
+import io.papermc.paper.registry.PaperRegistries;
+import io.papermc.paper.registry.set.PaperRegistrySets;
+import io.papermc.paper.registry.set.RegistryKeySet;
+import io.papermc.paper.registry.tag.TagKey;
+import io.papermc.paper.text.Filtered;
+import net.kyori.adventure.key.Key;
+import net.kyori.adventure.util.TriState;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.core.registries.Registries;
+import net.minecraft.world.item.component.OminousBottleAmplifier;
+import org.bukkit.JukeboxSong;
+import org.bukkit.block.BlockType;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.damage.DamageType;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.ItemType;
+import org.bukkit.inventory.meta.trim.ArmorTrim;
+import org.bukkit.map.MapCursor;
+import org.jspecify.annotations.Nullable;
+
+public final class ItemComponentTypesBridgesImpl implements ItemComponentTypesBridge {
+
+ @Override
+ public ChargedProjectiles.Builder chargedProjectiles() {
+ return new PaperChargedProjectiles.BuilderImpl();
+ }
+
+ @Override
+ public PotDecorations.Builder potDecorations() {
+ return new PaperPotDecorations.BuilderImpl();
+ }
+
+ @Override
+ public Unbreakable.Builder unbreakable() {
+ return new PaperUnbreakable.BuilderImpl();
+ }
+
+ @Override
+ public ItemLore.Builder lore() {
+ return new PaperItemLore.BuilderImpl();
+ }
+
+ @Override
+ public ItemEnchantments.Builder enchantments() {
+ return new PaperItemEnchantments.BuilderImpl();
+ }
+
+ @Override
+ public ItemAttributeModifiers.Builder modifiers() {
+ return new PaperItemAttributeModifiers.BuilderImpl();
+ }
+
+ @Override
+ public FoodProperties.Builder food() {
+ return new PaperFoodProperties.BuilderImpl();
+ }
+
+ @Override
+ public DyedItemColor.Builder dyedItemColor() {
+ return new PaperDyedItemColor.BuilderImpl();
+ }
+
+ @Override
+ public PotionContents.Builder potionContents() {
+ return new PaperPotionContents.BuilderImpl();
+ }
+
+ @Override
+ public BundleContents.Builder bundleContents() {
+ return new PaperBundleContents.BuilderImpl();
+ }
+
+ @Override
+ public SuspiciousStewEffects.Builder suspiciousStewEffects() {
+ return new PaperSuspiciousStewEffects.BuilderImpl();
+ }
+
+ @Override
+ public MapItemColor.Builder mapItemColor() {
+ return new PaperMapItemColor.BuilderImpl();
+ }
+
+ @Override
+ public MapDecorations.Builder mapDecorations() {
+ return new PaperMapDecorations.BuilderImpl();
+ }
+
+ @Override
+ public MapDecorations.DecorationEntry decorationEntry(final MapCursor.Type type, final double x, final double z, final float rotation) {
+ return PaperMapDecorations.PaperDecorationEntry.toApi(type, x, z, rotation);
+ }
+
+ @Override
+ public SeededContainerLoot.Builder seededContainerLoot(final Key lootTableKey) {
+ return new PaperSeededContainerLoot.BuilderImpl(lootTableKey);
+ }
+
+ @Override
+ public ItemContainerContents.Builder itemContainerContents() {
+ return new PaperItemContainerContents.BuilderImpl();
+ }
+
+ @Override
+ public JukeboxPlayable.Builder jukeboxPlayable(final JukeboxSong song) {
+ return new PaperJukeboxPlayable.BuilderImpl(song);
+ }
+
+ @Override
+ public Tool.Builder tool() {
+ return new PaperItemTool.BuilderImpl();
+ }
+
+ @Override
+ public Tool.Rule rule(final RegistryKeySet<BlockType> blocks, final @Nullable Float speed, final TriState correctForDrops) {
+ return PaperItemTool.PaperRule.fromUnsafe(blocks, speed, correctForDrops);
+ }
+
+ @Override
+ public ItemAdventurePredicate.Builder itemAdventurePredicate() {
+ return new PaperItemAdventurePredicate.BuilderImpl();
+ }
+
+ @Override
+ public WrittenBookContent.Builder writtenBookContent(final Filtered<String> title, final String author) {
+ return new PaperWrittenBookContent.BuilderImpl(title, author);
+ }
+
+ @Override
+ public WritableBookContent.Builder writeableBookContent() {
+ return new PaperWritableBookContent.BuilderImpl();
+ }
+
+ @Override
+ public ItemArmorTrim.Builder itemArmorTrim(final ArmorTrim armorTrim) {
+ return new PaperItemArmorTrim.BuilderImpl(armorTrim);
+ }
+
+ @Override
+ public LodestoneTracker.Builder lodestoneTracker() {
+ return new PaperLodestoneTracker.BuilderImpl();
+ }
+
+ @Override
+ public Fireworks.Builder fireworks() {
+ return new PaperFireworks.BuilderImpl();
+ }
+
+ @Override
+ public ResolvableProfile.Builder resolvableProfile() {
+ return new PaperResolvableProfile.BuilderImpl();
+ }
+
+ @Override
+ public ResolvableProfile resolvableProfile(final PlayerProfile profile) {
+ return PaperResolvableProfile.toApi(profile);
+ }
+
+ @Override
+ public BannerPatternLayers.Builder bannerPatternLayers() {
+ return new PaperBannerPatternLayers.BuilderImpl();
+ }
+
+ @Override
+ public BlockItemDataProperties.Builder blockItemStateProperties() {
+ return new PaperBlockItemDataProperties.BuilderImpl();
+ }
+
+ @Override
+ public MapId mapId(final int id) {
+ return new PaperMapId(new net.minecraft.world.level.saveddata.maps.MapId(id));
+ }
+
+ @Override
+ public UseRemainder useRemainder(final ItemStack itemStack) {
+ Preconditions.checkArgument(itemStack != null, "Item cannot be null");
+ Preconditions.checkArgument(!itemStack.isEmpty(), "Remaining item cannot be empty!");
+ return new PaperUseRemainder(
+ new net.minecraft.world.item.component.UseRemainder(CraftItemStack.asNMSCopy(itemStack))
+ );
+ }
+
+ @Override
+ public Consumable.Builder consumable() {
+ return new PaperConsumable.BuilderImpl();
+ }
+
+ @Override
+ public UseCooldown.Builder useCooldown(final float seconds) {
+ Preconditions.checkArgument(seconds > 0, "seconds must be positive, was %s", seconds);
+ return new PaperUseCooldown.BuilderImpl(seconds);
+ }
+
+ @Override
+ public DamageResistant damageResistant(final TagKey<DamageType> types) {
+ return new PaperDamageResistant(new net.minecraft.world.item.component.DamageResistant(PaperRegistries.toNms(types)));
+ }
+
+ @Override
+ public Enchantable enchantable(final int level) {
+ return new PaperEnchantable(new net.minecraft.world.item.enchantment.Enchantable(level));
+ }
+
+ @Override
+ public Repairable repairable(final RegistryKeySet<ItemType> types) {
+ return new PaperRepairable(new net.minecraft.world.item.enchantment.Repairable(
+ PaperRegistrySets.convertToNms(Registries.ITEM, BuiltInRegistries.BUILT_IN_CONVERSIONS.lookup(), types)
+ ));
+ }
+
+ @Override
+ public Equippable.Builder equippable(EquipmentSlot slot) {
+ return new PaperEquippable.BuilderImpl(slot);
+ }
+
+ @Override
+ public DeathProtection.Builder deathProtection() {
+ return new PaperDeathProtection.BuilderImpl();
+ }
+
+ @Override
+ public CustomModelData customModelData(final int id) {
+ return new PaperCustomModelData(new net.minecraft.world.item.component.CustomModelData(id));
+ }
+
+ @Override
+ public PaperOminousBottleAmplifier ominousBottleAmplifier(final int amplifier) {
+ Preconditions.checkArgument(OminousBottleAmplifier.MIN_AMPLIFIER <= amplifier && amplifier <= OminousBottleAmplifier.MAX_AMPLIFIER,
+ "amplifier must be between %s-%s, was %s", OminousBottleAmplifier.MIN_AMPLIFIER, OminousBottleAmplifier.MAX_AMPLIFIER, amplifier
+ );
+ return new PaperOminousBottleAmplifier(
+ new OminousBottleAmplifier(amplifier)
+ );
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperBannerPatternLayers.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperBannerPatternLayers.java
new file mode 100644
index 0000000000000000000000000000000000000000..ca49c2d2e1edcf6c4f7a5ca6c9ba96920aa385f4
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperBannerPatternLayers.java
@@ -0,0 +1,62 @@
+package io.papermc.paper.datacomponent.item;
+
+import io.papermc.paper.registry.RegistryAccess;
+import io.papermc.paper.registry.RegistryKey;
+import io.papermc.paper.util.MCUtil;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import org.bukkit.DyeColor;
+import org.bukkit.block.banner.Pattern;
+import org.bukkit.block.banner.PatternType;
+import org.bukkit.craftbukkit.CraftRegistry;
+import org.bukkit.craftbukkit.block.banner.CraftPatternType;
+import org.bukkit.craftbukkit.util.Handleable;
+import org.jetbrains.annotations.Unmodifiable;
+
+public record PaperBannerPatternLayers(
+ net.minecraft.world.level.block.entity.BannerPatternLayers impl
+) implements BannerPatternLayers, Handleable<net.minecraft.world.level.block.entity.BannerPatternLayers> {
+
+ private static List<Pattern> convert(final net.minecraft.world.level.block.entity.BannerPatternLayers nmsPatterns) {
+ return MCUtil.transformUnmodifiable(nmsPatterns.layers(), input -> {
+ final Optional<PatternType> type = CraftRegistry.unwrapAndConvertHolder(RegistryAccess.registryAccess().getRegistry(RegistryKey.BANNER_PATTERN), input.pattern());
+ return new Pattern(Objects.requireNonNull(DyeColor.getByWoolData((byte) input.color().getId())), type.orElseThrow(() -> new IllegalStateException("Inlined banner patterns are not supported yet in the API!")));
+ });
+ }
+
+ @Override
+ public net.minecraft.world.level.block.entity.BannerPatternLayers getHandle() {
+ return this.impl;
+ }
+
+ @Override
+ public @Unmodifiable List<Pattern> patterns() {
+ return convert(impl);
+ }
+
+ static final class BuilderImpl implements BannerPatternLayers.Builder {
+
+ private final net.minecraft.world.level.block.entity.BannerPatternLayers.Builder builder = new net.minecraft.world.level.block.entity.BannerPatternLayers.Builder();
+
+ @Override
+ public BannerPatternLayers.Builder add(final Pattern pattern) {
+ this.builder.add(
+ CraftPatternType.bukkitToMinecraftHolder(pattern.getPattern()),
+ net.minecraft.world.item.DyeColor.byId(pattern.getColor().getWoolData())
+ );
+ return this;
+ }
+
+ @Override
+ public BannerPatternLayers.Builder addAll(final List<Pattern> patterns) {
+ patterns.forEach(this::add);
+ return this;
+ }
+
+ @Override
+ public BannerPatternLayers build() {
+ return new PaperBannerPatternLayers(this.builder.build());
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperBlockItemDataProperties.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperBlockItemDataProperties.java
new file mode 100644
index 0000000000000000000000000000000000000000..5757e16c5948a6897bc61005ea7260940a49abfe
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperBlockItemDataProperties.java
@@ -0,0 +1,50 @@
+package io.papermc.paper.datacomponent.item;
+
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
+import java.util.Map;
+import net.minecraft.world.item.component.BlockItemStateProperties;
+import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.block.state.BlockState;
+import org.bukkit.block.BlockType;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.craftbukkit.block.CraftBlockType;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.craftbukkit.util.Handleable;
+
+public record PaperBlockItemDataProperties(
+ BlockItemStateProperties impl
+) implements BlockItemDataProperties, Handleable<BlockItemStateProperties> {
+
+ @Override
+ public BlockData createBlockData(final BlockType blockType) {
+ final Block block = CraftBlockType.bukkitToMinecraftNew(blockType);
+ final BlockState defaultState = block.defaultBlockState();
+ return this.impl.apply(defaultState).createCraftBlockData();
+ }
+
+ @Override
+ public BlockData applyTo(final BlockData blockData) {
+ final BlockState state = ((CraftBlockData) blockData).getState();
+ return this.impl.apply(state).createCraftBlockData();
+ }
+
+ @Override
+ public BlockItemStateProperties getHandle() {
+ return this.impl;
+ }
+
+ static final class BuilderImpl implements BlockItemDataProperties.Builder {
+
+ private final Map<String, String> properties = new Object2ObjectOpenHashMap<>();
+
+ // TODO when BlockProperty API is merged
+
+ @Override
+ public BlockItemDataProperties build() {
+ if (this.properties.isEmpty()) {
+ return new PaperBlockItemDataProperties(BlockItemStateProperties.EMPTY);
+ }
+ return new PaperBlockItemDataProperties(new BlockItemStateProperties(new Object2ObjectOpenHashMap<>(this.properties)));
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperBundleContents.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperBundleContents.java
new file mode 100644
index 0000000000000000000000000000000000000000..ba95ce77dbddb90fd2616c9112fd74051dddc3ee
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperBundleContents.java
@@ -0,0 +1,51 @@
+package io.papermc.paper.datacomponent.item;
+
+import com.google.common.base.Preconditions;
+import io.papermc.paper.util.MCUtil;
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import java.util.List;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.Handleable;
+import org.bukkit.inventory.ItemStack;
+
+public record PaperBundleContents(
+ net.minecraft.world.item.component.BundleContents impl
+) implements BundleContents, Handleable<net.minecraft.world.item.component.BundleContents> {
+
+ @Override
+ public net.minecraft.world.item.component.BundleContents getHandle() {
+ return this.impl;
+ }
+
+ @Override
+ public List<ItemStack> contents() {
+ return MCUtil.transformUnmodifiable((List<net.minecraft.world.item.ItemStack>) this.impl.items(), CraftItemStack::asBukkitCopy);
+ }
+
+ static final class BuilderImpl implements BundleContents.Builder {
+
+ private final List<net.minecraft.world.item.ItemStack> items = new ObjectArrayList<>();
+
+ @Override
+ public BundleContents.Builder add(final ItemStack stack) {
+ Preconditions.checkArgument(stack != null, "stack cannot be null");
+ Preconditions.checkArgument(!stack.isEmpty(), "stack cannot be empty");
+ this.items.add(CraftItemStack.asNMSCopy(stack));
+ return this;
+ }
+
+ @Override
+ public BundleContents.Builder addAll(final List<ItemStack> stacks) {
+ stacks.forEach(this::add);
+ return this;
+ }
+
+ @Override
+ public BundleContents build() {
+ if (this.items.isEmpty()) {
+ return new PaperBundleContents(net.minecraft.world.item.component.BundleContents.EMPTY);
+ }
+ return new PaperBundleContents(new net.minecraft.world.item.component.BundleContents(new ObjectArrayList<>(this.items)));
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperChargedProjectiles.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperChargedProjectiles.java
new file mode 100644
index 0000000000000000000000000000000000000000..2129dd67fd02a13f6e6fbdfb07505dc64307a3f0
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperChargedProjectiles.java
@@ -0,0 +1,51 @@
+package io.papermc.paper.datacomponent.item;
+
+import com.google.common.base.Preconditions;
+import io.papermc.paper.util.MCUtil;
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.Handleable;
+import org.bukkit.inventory.ItemStack;
+
+public record PaperChargedProjectiles(
+ net.minecraft.world.item.component.ChargedProjectiles impl
+) implements ChargedProjectiles, Handleable<net.minecraft.world.item.component.ChargedProjectiles> {
+
+ @Override
+ public net.minecraft.world.item.component.ChargedProjectiles getHandle() {
+ return this.impl;
+ }
+
+ @Override
+ public List<ItemStack> projectiles() {
+ return MCUtil.transformUnmodifiable(this.impl.getItems() /*makes copies internally*/, CraftItemStack::asCraftMirror);
+ }
+
+ static final class BuilderImpl implements ChargedProjectiles.Builder {
+
+ private final List<net.minecraft.world.item.ItemStack> items = new ArrayList<>();
+
+ @Override
+ public ChargedProjectiles.Builder add(final ItemStack stack) {
+ Preconditions.checkArgument(stack != null, "stack cannot be null");
+ Preconditions.checkArgument(!stack.isEmpty(), "stack cannot be empty");
+ this.items.add(CraftItemStack.asNMSCopy(stack));
+ return this;
+ }
+
+ @Override
+ public ChargedProjectiles.Builder addAll(final List<ItemStack> stacks) {
+ stacks.forEach(this::add);
+ return this;
+ }
+
+ @Override
+ public ChargedProjectiles build() {
+ if (this.items.isEmpty()) {
+ return new PaperChargedProjectiles(net.minecraft.world.item.component.ChargedProjectiles.EMPTY);
+ }
+ return new PaperChargedProjectiles(net.minecraft.world.item.component.ChargedProjectiles.of(this.items));
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperConsumable.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperConsumable.java
new file mode 100644
index 0000000000000000000000000000000000000000..0bc2bad71d6945ca24f37008effc903a84466004
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperConsumable.java
@@ -0,0 +1,126 @@
+package io.papermc.paper.datacomponent.item;
+
+import com.google.common.base.Preconditions;
+import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.datacomponent.item.consumable.ConsumeEffect;
+import io.papermc.paper.datacomponent.item.consumable.ItemUseAnimation;
+import io.papermc.paper.datacomponent.item.consumable.PaperConsumableEffects;
+import io.papermc.paper.util.MCUtil;
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import java.util.List;
+import net.kyori.adventure.key.Key;
+import net.minecraft.core.Holder;
+import net.minecraft.sounds.SoundEvent;
+import net.minecraft.sounds.SoundEvents;
+import org.bukkit.craftbukkit.util.Handleable;
+import org.checkerframework.checker.index.qual.NonNegative;
+import org.jetbrains.annotations.Unmodifiable;
+
+public record PaperConsumable(
+ net.minecraft.world.item.component.Consumable impl
+) implements Consumable, Handleable<net.minecraft.world.item.component.Consumable> {
+
+ private static final ItemUseAnimation[] VALUES = ItemUseAnimation.values();
+
+ @Override
+ public net.minecraft.world.item.component.Consumable getHandle() {
+ return this.impl;
+ }
+
+ @Override
+ public @NonNegative float consumeSeconds() {
+ return this.impl.consumeSeconds();
+ }
+
+ @Override
+ public ItemUseAnimation animation() {
+ return VALUES[this.impl.animation().ordinal()];
+ }
+
+ @Override
+ public Key sound() {
+ return PaperAdventure.asAdventure(this.impl.sound().value().location());
+ }
+
+ @Override
+ public boolean hasConsumeParticles() {
+ return this.impl.hasConsumeParticles();
+ }
+
+ @Override
+ public @Unmodifiable List<ConsumeEffect> consumeEffects() {
+ return MCUtil.transformUnmodifiable(this.impl.onConsumeEffects(), PaperConsumableEffects::fromNms);
+ }
+
+ @Override
+ public Consumable.Builder toBuilder() {
+ return new BuilderImpl()
+ .consumeSeconds(this.consumeSeconds())
+ .animation(this.animation())
+ .sound(this.sound())
+ .addEffects(this.consumeEffects());
+ }
+
+ static final class BuilderImpl implements Builder {
+
+ private static final net.minecraft.world.item.ItemUseAnimation[] VALUES = net.minecraft.world.item.ItemUseAnimation.values();
+
+ private float consumeSeconds = net.minecraft.world.item.component.Consumable.DEFAULT_CONSUME_SECONDS;
+ private net.minecraft.world.item.ItemUseAnimation consumeAnimation = net.minecraft.world.item.ItemUseAnimation.EAT;
+ private Holder<SoundEvent> eatSound = SoundEvents.GENERIC_EAT;
+ private boolean hasConsumeParticles = true;
+ private final List<net.minecraft.world.item.consume_effects.ConsumeEffect> effects = new ObjectArrayList<>();
+
+ @Override
+ public Builder consumeSeconds(final @NonNegative float consumeSeconds) {
+ Preconditions.checkArgument(consumeSeconds >= 0, "consumeSeconds must be non-negative, was %s", consumeSeconds);
+ this.consumeSeconds = consumeSeconds;
+ return this;
+ }
+
+ @Override
+ public Builder animation(final ItemUseAnimation animation) {
+ this.consumeAnimation = VALUES[animation.ordinal()];
+ return this;
+ }
+
+ @Override
+ public Builder sound(final Key sound) {
+ this.eatSound = PaperAdventure.resolveSound(sound);
+ return this;
+ }
+
+ @Override
+ public Builder hasConsumeParticles(final boolean hasConsumeParticles) {
+ this.hasConsumeParticles = hasConsumeParticles;
+ return this;
+ }
+
+ @Override
+ public Builder addEffect(final ConsumeEffect effect) {
+ this.effects.add(PaperConsumableEffects.toNms(effect));
+ return this;
+ }
+
+ @Override
+ public Builder addEffects(final List<ConsumeEffect> effects) {
+ for (final ConsumeEffect effect : effects) {
+ this.effects.add(PaperConsumableEffects.toNms(effect));
+ }
+ return this;
+ }
+
+ @Override
+ public Consumable build() {
+ return new PaperConsumable(
+ new net.minecraft.world.item.component.Consumable(
+ this.consumeSeconds,
+ this.consumeAnimation,
+ this.eatSound,
+ this.hasConsumeParticles,
+ new ObjectArrayList<>(this.effects)
+ )
+ );
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperCustomModelData.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperCustomModelData.java
new file mode 100644
index 0000000000000000000000000000000000000000..8373d882e8b927e74961d5ed2d548b2db6dacdaf
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperCustomModelData.java
@@ -0,0 +1,18 @@
+package io.papermc.paper.datacomponent.item;
+
+import org.bukkit.craftbukkit.util.Handleable;
+
+public record PaperCustomModelData(
+ net.minecraft.world.item.component.CustomModelData impl
+) implements CustomModelData, Handleable<net.minecraft.world.item.component.CustomModelData> {
+
+ @Override
+ public net.minecraft.world.item.component.CustomModelData getHandle() {
+ return this.impl;
+ }
+
+ @Override
+ public int id() {
+ return this.impl.value();
+ }
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperDamageResistant.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperDamageResistant.java
new file mode 100644
index 0000000000000000000000000000000000000000..adc986c8b3d65e3fb91a8951048194bbe4052b74
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperDamageResistant.java
@@ -0,0 +1,21 @@
+package io.papermc.paper.datacomponent.item;
+
+import io.papermc.paper.registry.PaperRegistries;
+import io.papermc.paper.registry.tag.TagKey;
+import org.bukkit.craftbukkit.util.Handleable;
+import org.bukkit.damage.DamageType;