Skip to content

Commit 59d3299

Browse files
committed
Add dirty workaround to fix leashes when copy entities
1.19.4 ONLY
1 parent b73f63d commit 59d3299

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2

worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
import net.minecraft.core.Registry;
3636
import net.minecraft.core.SectionPos;
3737
import net.minecraft.nbt.IntTag;
38+
import net.minecraft.nbt.NbtUtils;
3839
import net.minecraft.server.level.ServerLevel;
3940
import net.minecraft.sounds.SoundEvents;
4041
import net.minecraft.util.BitStorage;
4142
import net.minecraft.util.ZeroBitStorage;
4243
import net.minecraft.world.entity.Entity;
4344
import net.minecraft.world.entity.EntityType;
45+
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
4446
import net.minecraft.world.level.LightLayer;
4547
import net.minecraft.world.level.biome.Biome;
4648
import 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

Comments
 (0)