55import com .google .common .collect .ImmutableList ;
66import com .google .common .collect .ImmutableMap ;
77import com .google .common .collect .ImmutableMultimap ;
8- import com .google .common .collect .LinkedHashMultimap ;
98import com .google .common .collect .ImmutableSortedMap ;
9+ import com .google .common .collect .LinkedHashMultimap ;
1010import com .google .common .collect .Lists ;
1111import com .google .common .collect .Multimap ;
1212import com .google .common .collect .SetMultimap ;
1313import com .google .common .collect .Sets ;
1414import com .mojang .logging .LogUtils ;
1515import com .mojang .serialization .DynamicOps ;
16+ import io .papermc .paper .registry .RegistryKey ;
17+ import io .papermc .paper .registry .data .util .Conversions ;
18+ import io .papermc .paper .registry .set .PaperRegistrySets ;
19+ import io .papermc .paper .registry .set .RegistryKeySet ;
20+ import it .unimi .dsi .fastutil .objects .ReferenceLinkedOpenHashSet ;
1621import java .io .ByteArrayInputStream ;
1722import java .io .ByteArrayOutputStream ;
1823import java .io .IOException ;
3742import java .util .Optional ;
3843import java .util .Set ;
3944import java .util .StringJoiner ;
40- import it .unimi .dsi .fastutil .objects .ReferenceLinkedOpenHashSet ;
4145import javax .annotation .Nonnull ;
4246import javax .annotation .Nullable ;
4347import net .minecraft .core .Holder ;
4751import net .minecraft .core .component .DataComponentPatch ;
4852import net .minecraft .core .component .DataComponentType ;
4953import net .minecraft .core .component .DataComponents ;
54+ import net .minecraft .core .registries .BuiltInRegistries ;
5055import net .minecraft .core .registries .Registries ;
5156import net .minecraft .nbt .CompoundTag ;
5257import net .minecraft .nbt .ListTag ;
131136import org .bukkit .tag .DamageTypeTags ;
132137import org .slf4j .Logger ;
133138
139+ import static java .util .Objects .requireNonNull ;
140+
134141/**
135142 * Children must include the following:
136143 *
@@ -1550,7 +1557,11 @@ public boolean isFireResistant() {
15501557
15511558 @ Override
15521559 public void setFireResistant (boolean fireResistant ) {
1553- this .damageResistant = CraftRegistry .getMinecraftRegistry (Registries .DAMAGE_TYPE ).get (net .minecraft .tags .DamageTypeTags .IS_FIRE ).orElseThrow (IllegalStateException ::new );
1560+ if (fireResistant ) {
1561+ this .damageResistant = CraftRegistry .getMinecraftRegistry (Registries .DAMAGE_TYPE ).getOrThrow (net .minecraft .tags .DamageTypeTags .IS_FIRE );
1562+ } else if (this .isFireResistant ()) {
1563+ this .damageResistant = null ;
1564+ }
15541565 }
15551566
15561567 @ Override
@@ -1560,7 +1571,6 @@ public boolean hasDamageResistant() {
15601571
15611572 @ Override
15621573 public Tag <DamageType > getDamageResistant () {
1563- // TODO - snapshot - 26.1 API changes for holder set
15641574 return this .hasDamageResistant () && this .damageResistant .unwrapKey ().isPresent () ? Bukkit .getTag (DamageTypeTags .REGISTRY_DAMAGE_TYPES , CraftNamespacedKey .fromMinecraft (this .damageResistant .unwrapKey ().get ().location ()), DamageType .class ) : null ;
15651575 }
15661576
@@ -1569,6 +1579,20 @@ public void setDamageResistant(Tag<DamageType> tag) {
15691579 this .damageResistant = (tag != null ) ? CraftRegistry .getMinecraftRegistry (Registries .DAMAGE_TYPE ).get (((CraftDamageTag ) tag ).getHandle ().key ()).orElseThrow (IllegalStateException ::new ) : null ;
15701580 }
15711581
1582+ @ Override
1583+ public RegistryKeySet <DamageType > getDamageResistance () {
1584+ return this .damageResistant == null ? null : PaperRegistrySets .convertToApi (RegistryKey .DAMAGE_TYPE , this .damageResistant );
1585+ }
1586+
1587+ @ Override
1588+ public void setDamageResistance (RegistryKeySet <DamageType > types ) {
1589+ if (types == null ) {
1590+ this .damageResistant = null ;
1591+ } else {
1592+ this .damageResistant = PaperRegistrySets .convertToNms (Registries .DAMAGE_TYPE , Conversions .global ().lookup (), types );
1593+ }
1594+ }
1595+
15721596 @ Override
15731597 public boolean hasMaxStackSize () {
15741598 return this .maxStackSize != null ;
@@ -1836,18 +1860,20 @@ public String getAsComponentString() {
18361860 this .applyToItem (tag );
18371861 DataComponentPatch patch = tag .build ();
18381862
1839- RegistryAccess registryAccess = CraftRegistry .getMinecraftRegistry ();
1840- DynamicOps <net .minecraft .nbt .Tag > ops = registryAccess .createSerializationContext (NbtOps .INSTANCE );
1841- Registry <DataComponentType <?>> componentTypeRegistry = registryAccess .lookupOrThrow (Registries .DATA_COMPONENT_TYPE );
1842-
1863+ DynamicOps <net .minecraft .nbt .Tag > ops = CraftRegistry .getMinecraftRegistry ().createSerializationContext (NbtOps .INSTANCE );
18431864 StringJoiner componentString = new StringJoiner ("," , "[" , "]" );
1865+
18441866 for (Entry <DataComponentType <?>, Optional <?>> entry : patch .entrySet ()) {
1845- DataComponentType <?> componentType = entry .getKey ();
1867+ DataComponentType <?> type = entry .getKey ();
1868+ if (type .isTransient ()) {
1869+ continue ;
1870+ }
1871+
18461872 Optional <?> componentValue = entry .getValue ();
1847- String componentKey = componentTypeRegistry . getResourceKey ( componentType ). orElseThrow (). identifier ( ).toString ();
1873+ String componentKey = requireNonNull ( BuiltInRegistries . DATA_COMPONENT_TYPE . getKey ( type ) ).toString ();
18481874
18491875 if (componentValue .isPresent ()) {
1850- net .minecraft .nbt .Tag componentValueAsNBT = (net .minecraft .nbt .Tag ) ((DataComponentType ) componentType ).codecOrThrow ().encodeStart (ops , componentValue .get ()).getOrThrow ();
1876+ net .minecraft .nbt .Tag componentValueAsNBT = (net .minecraft .nbt .Tag ) ((DataComponentType ) type ).codecOrThrow ().encodeStart (ops , componentValue .get ()).getOrThrow ();
18511877 String componentValueAsNBTString = new SnbtPrinterTagVisitor ("" , 0 , new ArrayList <>()).visit (componentValueAsNBT );
18521878 componentString .add (componentKey + "=" + componentValueAsNBTString );
18531879 } else {
@@ -2564,7 +2590,7 @@ private static List<net.minecraft.advancements.criterion.BlockPredicate> convert
25642590 final net .minecraft .core .Registry <net .minecraft .world .level .block .Block > blockRegistry = CraftRegistry .getMinecraftRegistry ().lookupOrThrow (net .minecraft .core .registries .Registries .BLOCK );
25652591 for (final com .destroystokyo .paper .Namespaced namespaced : namespaceds ) {
25662592 if (namespaced instanceof final org .bukkit .NamespacedKey key ) {
2567- predicates .add (net .minecraft .advancements .criterion .BlockPredicate .Builder .block ().of (blockRegistry , CraftBlockType .bukkitToMinecraft (Objects . requireNonNull (org .bukkit .Registry .MATERIAL .get (key )))).build ());
2593+ predicates .add (net .minecraft .advancements .criterion .BlockPredicate .Builder .block ().of (blockRegistry , CraftBlockType .bukkitToMinecraft (requireNonNull (org .bukkit .Registry .MATERIAL .get (key )))).build ());
25682594 } else if (namespaced instanceof final com .destroystokyo .paper .NamespacedTag tag ) {
25692595 predicates .add (net .minecraft .advancements .criterion .BlockPredicate .Builder .block ().of (blockRegistry , net .minecraft .tags .TagKey .create (Registries .BLOCK , Identifier .fromNamespaceAndPath (tag .getNamespace (), tag .getKey ()))).build ());
25702596 }
0 commit comments