2424import net .minecraft .core .HolderLookup ;
2525import net .minecraft .nbt .CompoundTag ;
2626import net .minecraft .nbt .NbtUtils ;
27+ import net .minecraft .nbt .Tag ;
2728import net .minecraft .network .RegistryFriendlyByteBuf ;
2829import net .minecraft .network .codec .ByteBufCodecs ;
2930import net .minecraft .network .codec .StreamCodec ;
@@ -135,7 +136,7 @@ public void write(HolderLookup.Provider provider, CompoundTag nbtTags) {
135136 NBTUtils .writeEnum (nbtTags , SerializationConstants .PATH_TYPE , pathType );
136137 }
137138 if (!itemStack .isEmpty ()) {
138- itemStack .save (provider , nbtTags );
139+ nbtTags . put ( SerializationConstants . ITEM , itemStack .save (provider ) );
139140 }
140141 }
141142
@@ -146,7 +147,11 @@ public void read(HolderLookup.Provider provider, CompoundTag nbtTags) {
146147 NBTUtils .setEnumIfPresent (nbtTags , SerializationConstants .IDLE_DIR , Direction ::from3DDataValue , dir -> idleDir = dir );
147148 NBTUtils .setBlockPosIfPresent (nbtTags , SerializationConstants .HOME_LOCATION , coord -> homeLocation = coord );
148149 NBTUtils .setEnumIfPresent (nbtTags , SerializationConstants .PATH_TYPE , Path .BY_ID , type -> pathType = type );
149- itemStack = ItemStack .parseOptional (provider , nbtTags );
150+ if (nbtTags .contains (SerializationConstants .ITEM , Tag .TAG_COMPOUND )) {
151+ itemStack = ItemStack .parseOptional (provider , nbtTags .getCompound (SerializationConstants .ITEM ));
152+ } else {//TODO - 1.22: Remove this legacy way of loading data
153+ itemStack = ItemStack .parseOptional (provider , nbtTags );
154+ }
150155 }
151156
152157 private void setPath (Level world , @ NotNull List <BlockPos > path , @ NotNull Path type , boolean updateFlowing ) {
0 commit comments