1111import ch .njol .yggdrasil .YggdrasilSerializable .YggdrasilExtendedSerializable ;
1212import org .bukkit .Bukkit ;
1313import org .bukkit .Material ;
14+ import org .bukkit .NamespacedKey ;
1415import org .bukkit .block .Block ;
1516import org .bukkit .block .BlockState ;
1617import org .bukkit .block .data .BlockData ;
@@ -564,7 +565,7 @@ public boolean matchPlain(ItemData other) {
564565 @ Override
565566 public Fields serialize () throws NotSerializableException {
566567 Fields fields = new Fields (this ); // ItemStack is transient, will be ignored
567- fields .putPrimitive ( "id " , type .ordinal ());
568+ fields .putObject ( "key " , type .getKey ());
568569 fields .putObject ("meta" , stack != null ? stack .getItemMeta () : null );
569570 return fields ;
570571 }
@@ -573,7 +574,16 @@ public Fields serialize() throws NotSerializableException {
573574
574575 @ Override
575576 public void deserialize (Fields fields ) throws StreamCorruptedException , NotSerializableException {
576- this .type = materials [fields .getAndRemovePrimitive ("id" , int .class )];
577+ if (fields .hasField ("key" )) {
578+ NamespacedKey key = fields .getAndRemoveObject ("key" , NamespacedKey .class );
579+ if (key == null )
580+ throw new StreamCorruptedException ("Material key is null" );
581+ this .type = Material .matchMaterial (key .toString ());
582+ } else {
583+ // attempt back compat deserialization, though using ordinals is not reliable
584+ this .type = materials [fields .getAndRemovePrimitive ("id" , int .class )];
585+ }
586+
577587 ItemMeta meta = fields .getAndRemoveObject ("meta" , ItemMeta .class );
578588
579589 // Initialize ItemStack
0 commit comments