From 87717ba8b771fbf7003c38a5bcf7764ef1caa936 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz Date: Sat, 29 Apr 2023 13:22:52 +0200 Subject: [PATCH 1/7] Fix passage entities --- .../java/com/fastasyncworldedit/core/queue/IChunkExtent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IChunkExtent.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IChunkExtent.java index 615f5fb504..02f5c7278e 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IChunkExtent.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/IChunkExtent.java @@ -135,7 +135,7 @@ default Entity createEntity(Location location, BaseEntity entity, UUID uuid) { posList.add(LinDoubleTag.of(location.y())); posList.add(LinDoubleTag.of(location.z())); map.put("Pos", LinListTag.of(LinTagType.doubleTag(), posList)); - + // Todo: Add again rotation NbtUtils.addUUIDToMap(map, uuid); chunk.entity(FaweCompoundTag.of(LinCompoundTag.of(map))); From 487b2ba80b8342527a439c76222ba2f4cbfb8f95 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz Date: Sat, 29 Apr 2023 16:01:50 +0200 Subject: [PATCH 2/7] Add dirty workaround to fix leashes when copy entities 1.19.4 ONLY --- .../fawe/v1_20_R3/PaperweightGetBlocks.java | 2 ++ .../worldedit/extent/clipboard/Clipboard.java | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightGetBlocks.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightGetBlocks.java index b08afe5456..1f0c6592b8 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightGetBlocks.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightGetBlocks.java @@ -676,12 +676,14 @@ protected > T internalCall( if (entity != null) { final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin( linTag); + // TODO: TheMeinerLP: Add LeashKnot again for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } entity.load(tag); entity.absMoveTo(x, y, z, yaw, pitch); entity.setUUID(NbtUtils.uuid(nativeTag)); + // TODO: TheMeinerLP: Add LeashKnot again if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) { LOGGER.warn( "Error creating entity of type `{}` in world `{}` at location `{},{},{}`", diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index be702ae4d4..bfca59357f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -27,6 +27,9 @@ import com.fastasyncworldedit.core.function.visitor.Order; import com.fastasyncworldedit.core.queue.Filter; import com.fastasyncworldedit.core.util.MaskTraverser; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSessionBuilder; import com.sk89q.worldedit.WorldEdit; @@ -49,6 +52,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.entity.EntityTypes; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -59,6 +63,7 @@ import java.io.IOException; import java.io.OutputStream; import java.net.URI; +import java.util.HashMap; import java.util.Iterator; import java.util.UUID; @@ -430,11 +435,29 @@ default void paste(Extent extent, BlockVector3 to, boolean pasteAir, boolean pas continue; } Location pos = entity.getLocation(); - Location newPos = new Location(pos.getExtent(), pos.x() + entityOffsetX, - pos.y() + entityOffsetY, pos.z() + entityOffsetZ, pos.getYaw(), - pos.getPitch() - ); - extent.createEntity(newPos, entity.getState()); + if (entity.getType().equals(EntityTypes.LEASH_KNOT)) { + var state = entity.getState(); + var nbtData = new HashMap<>(state.getNbtData().getValue()); + var posAsMap = new HashMap(); + posAsMap.put("X", new IntTag(pos.getBlockX())); + posAsMap.put("Y", new IntTag(pos.getBlockY())); + posAsMap.put("Z", new IntTag(pos.getBlockZ())); + nbtData.put("OldPos", new CompoundTag(posAsMap)); + state.setNbtData(new CompoundTag(nbtData)); + Location newPos = new Location(pos.getExtent(), pos.x() + entityOffsetX, + pos.y() + entityOffsetY, pos.z() + entityOffsetZ, pos.getYaw(), + pos.getPitch() + ); + + extent.createEntity(newPos, state); + } else { + Location newPos = new Location(pos.getExtent(), pos.x() + entityOffsetX, + pos.y() + entityOffsetY, pos.z() + entityOffsetZ, pos.getYaw(), + pos.getPitch() + ); + + extent.createEntity(newPos, entity.getState()); + } } } if (close) { From 171e8cad6ba2170a49f52798d4f060693e9647f5 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz Date: Sat, 29 Apr 2023 16:08:42 +0200 Subject: [PATCH 3/7] Add 1.19.3 support for leash copy --- .../adapter/impl/fawe/v1_20_R4/PaperweightGetBlocks.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightGetBlocks.java b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightGetBlocks.java index a03f3d9475..cffc830167 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightGetBlocks.java +++ b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightGetBlocks.java @@ -654,6 +654,7 @@ protected > T internalCall( syncTasks[1] = () -> { Iterator iterator = entities.iterator(); + // TODO: TheMeinerLP: Add LeashKnot again while (iterator.hasNext()) { final FaweCompoundTag nativeTag = iterator.next(); final LinCompoundTag linTag = nativeTag.linTag(); @@ -677,12 +678,14 @@ protected > T internalCall( if (entity != null) { final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin( linTag); + // TODO: TheMeinerLP: Add LeashKnot again for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } entity.load(tag); entity.absMoveTo(x, y, z, yaw, pitch); entity.setUUID(NbtUtils.uuid(nativeTag)); + // TODO: TheMeinerLP: Add LeashKnot again if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) { LOGGER.warn( "Error creating entity of type `{}` in world `{}` at location `{},{},{}`", From ac4e151bff71457a58f09d95344ae7e1f74b613d Mon Sep 17 00:00:00 2001 From: Phillipp Glanz Date: Sat, 29 Apr 2023 16:08:58 +0200 Subject: [PATCH 4/7] Add 1.18.X support for leash copy --- .../adapter/impl/fawe/v1_21_R1/PaperweightGetBlocks.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightGetBlocks.java b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightGetBlocks.java index 9fbc1ef64e..d83fd1f47f 100644 --- a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightGetBlocks.java +++ b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightGetBlocks.java @@ -652,6 +652,7 @@ protected > T internalCall( syncTasks[1] = () -> { Iterator iterator = entities.iterator(); + // TODO: TheMeinerLP: Add LeashKnot again while (iterator.hasNext()) { final FaweCompoundTag nativeTag = iterator.next(); final LinCompoundTag linTag = nativeTag.linTag(); @@ -674,12 +675,14 @@ protected > T internalCall( Entity entity = type.create(nmsWorld); if (entity != null) { final CompoundTag tag = (CompoundTag) adapter.fromNativeLin(linTag); + // TODO: TheMeinerLP: Add LeashKnot again for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } entity.load(tag); entity.absMoveTo(x, y, z, yaw, pitch); entity.setUUID(NbtUtils.uuid(nativeTag)); + // TODO: TheMeinerLP: Add LeashKnot again if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) { LOGGER.warn( "Error creating entity of type `{}` in world `{}` at location `{},{},{}`", From b44d08eff5126b78219bdb7d3a16a89380d15ca6 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz Date: Sat, 29 Apr 2023 16:01:50 +0200 Subject: [PATCH 5/7] Add dirty workaround to fix leashes when copy entities 1.19.4 ONLY --- .../bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java index be0203337e..9e194c99b8 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java @@ -653,6 +653,7 @@ protected > T internalCall( syncTasks[1] = () -> { Iterator iterator = entities.iterator(); + // TODO: TheMeinerLP: Add LeashKnot again while (iterator.hasNext()) { final FaweCompoundTag nativeTag = iterator.next(); final LinCompoundTag linTag = nativeTag.linTag(); @@ -675,6 +676,7 @@ protected > T internalCall( Entity entity = type.create(nmsWorld); if (entity != null) { final CompoundTag tag = (CompoundTag) adapter.fromNativeLin(linTag); + // TODO: TheMeinerLP: Add LeashKnot again for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.remove(name); } From 3a188d0a52d8dd95dd55dd9a38cc312003f022ac Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:58:22 +0200 Subject: [PATCH 6/7] Fix 1.205 and 1.21 compatible --- .../java/com/sk89q/worldedit/extent/clipboard/Clipboard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index bfca59357f..d108c52dc7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -438,7 +438,7 @@ default void paste(Extent extent, BlockVector3 to, boolean pasteAir, boolean pas if (entity.getType().equals(EntityTypes.LEASH_KNOT)) { var state = entity.getState(); var nbtData = new HashMap<>(state.getNbtData().getValue()); - var posAsMap = new HashMap(); + var posAsMap = new HashMap>(); posAsMap.put("X", new IntTag(pos.getBlockX())); posAsMap.put("Y", new IntTag(pos.getBlockY())); posAsMap.put("Z", new IntTag(pos.getBlockZ())); From 9ec03daa49b1166e9c0db63ec7dc76260464a859 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Wed, 9 Apr 2025 09:20:18 +0200 Subject: [PATCH 7/7] Refactor leash entity handling in clipboard copy --- .../worldedit/extent/clipboard/Clipboard.java | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index d108c52dc7..1968f166c6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -435,29 +435,11 @@ default void paste(Extent extent, BlockVector3 to, boolean pasteAir, boolean pas continue; } Location pos = entity.getLocation(); - if (entity.getType().equals(EntityTypes.LEASH_KNOT)) { - var state = entity.getState(); - var nbtData = new HashMap<>(state.getNbtData().getValue()); - var posAsMap = new HashMap>(); - posAsMap.put("X", new IntTag(pos.getBlockX())); - posAsMap.put("Y", new IntTag(pos.getBlockY())); - posAsMap.put("Z", new IntTag(pos.getBlockZ())); - nbtData.put("OldPos", new CompoundTag(posAsMap)); - state.setNbtData(new CompoundTag(nbtData)); - Location newPos = new Location(pos.getExtent(), pos.x() + entityOffsetX, - pos.y() + entityOffsetY, pos.z() + entityOffsetZ, pos.getYaw(), - pos.getPitch() - ); - - extent.createEntity(newPos, state); - } else { - Location newPos = new Location(pos.getExtent(), pos.x() + entityOffsetX, - pos.y() + entityOffsetY, pos.z() + entityOffsetZ, pos.getYaw(), - pos.getPitch() - ); - - extent.createEntity(newPos, entity.getState()); - } + Location newPos = new Location(pos.getExtent(), pos.x() + entityOffsetX, + pos.y() + entityOffsetY, pos.z() + entityOffsetZ, pos.getYaw(), + pos.getPitch() + ); + extent.createEntity(newPos, entity.getState()); } } if (close) {