3535import net .minecraft .core .Registry ;
3636import net .minecraft .core .SectionPos ;
3737import net .minecraft .nbt .IntTag ;
38+ import net .minecraft .nbt .NbtUtils ;
3839import net .minecraft .server .level .ServerLevel ;
3940import net .minecraft .sounds .SoundEvents ;
4041import net .minecraft .util .BitStorage ;
4142import net .minecraft .util .ZeroBitStorage ;
4243import net .minecraft .world .entity .Entity ;
4344import net .minecraft .world .entity .EntityType ;
45+ import net .minecraft .world .entity .decoration .LeashFenceKnotEntity ;
4446import net .minecraft .world .level .LightLayer ;
4547import net .minecraft .world .level .biome .Biome ;
4648import net .minecraft .world .level .block .entity .BeaconBlockEntity ;
@@ -736,6 +738,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
736738
737739 syncTasks [1 ] = () -> {
738740 Iterator <CompoundTag > iterator = entities .iterator ();
741+ Map <BlockPos , LeashFenceKnotEntity > leashRef = new HashMap <>();
739742 while (iterator .hasNext ()) {
740743 final CompoundTag nativeTag = iterator .next ();
741744 final Map <String , Tag <?, ?>> entityTagMap = nativeTag .getValue ();
@@ -759,12 +762,30 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
759762 if (entity != null ) {
760763 final net .minecraft .nbt .CompoundTag tag = (net .minecraft .nbt .CompoundTag ) adapter .fromNative (
761764 nativeTag );
765+ if (entityTagMap .containsKey ("Leash" )) {
766+ var leashTag = (net .minecraft .nbt .CompoundTag ) adapter .fromNative (
767+ entityTagMap .get ("Leash" )) ;
768+ final LeashFenceKnotEntity leashEntity = leashRef .get (NbtUtils .readBlockPos (leashTag ));
769+ if (leashEntity != null ) {
770+ tag .put ("Leash" , NbtUtils .writeBlockPos (leashEntity .pos ));
771+ }
772+ }
773+
762774 for (final String name : Constants .NO_COPY_ENTITY_NBT_FIELDS ) {
763775 tag .remove (name );
764776 }
765777 entity .load (tag );
766778 entity .absMoveTo (x , y , z , yaw , pitch );
767779 entity .setUUID (nativeTag .getUUID ());
780+ if (entity instanceof LeashFenceKnotEntity leashFenceKnotEntity ) {
781+ var leashTag = (net .minecraft .nbt .CompoundTag ) adapter .fromNative (
782+ entityTagMap .get ("OldPos" )) ;
783+ if (leashTag != null ) {
784+ leashRef .put (new BlockPos (leashTag .getInt ("X" ), leashTag .getInt ("Y" ),
785+ leashTag .getInt ("Z" )),
786+ leashFenceKnotEntity );
787+ }
788+ }
768789 if (!nmsWorld .addFreshEntity (entity , CreatureSpawnEvent .SpawnReason .CUSTOM )) {
769790 LOGGER .warn (
770791 "Error creating entity of type `{}` in world `{}` at location `{},{},{}`" ,
0 commit comments