Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bugs with copy entities from Position A to Position B #2195

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2bdc38a
Fix passage entities
TheMeinerLP Apr 29, 2023
3f009fe
Add dirty workaround to fix leashes when copy entities
TheMeinerLP Apr 29, 2023
a1663ac
Add 1.19.3 support for leash copy
TheMeinerLP Apr 29, 2023
d6fc7a9
Add 1.18.X support for leash copy
TheMeinerLP Apr 29, 2023
4bd4712
Add 1.17.1 support for leash copy
TheMeinerLP Apr 29, 2023
8a3a0a6
Improve formatting
TheMeinerLP Apr 30, 2023
d349cc7
Improve formatting
TheMeinerLP Apr 30, 2023
6c0da37
Improve formatting
TheMeinerLP Apr 30, 2023
cf5e84f
Improve formatting
TheMeinerLP Apr 30, 2023
c5d3031
Fix passage entities
TheMeinerLP Apr 29, 2023
c39d187
Add dirty workaround to fix leashes when copy entities
TheMeinerLP Apr 29, 2023
de6612b
Add 1.19.3 support for leash copy
TheMeinerLP Apr 29, 2023
46ca066
Add 1.18.X support for leash copy
TheMeinerLP Apr 29, 2023
ee3a079
Add 1.17.1 support for leash copy
TheMeinerLP Apr 29, 2023
0593a2a
Improve formatting
TheMeinerLP Apr 30, 2023
40b57ca
Improve formatting
TheMeinerLP Apr 30, 2023
63bc25d
Improve formatting
TheMeinerLP Apr 30, 2023
910ccb7
Improve formatting
TheMeinerLP Apr 30, 2023
36ece47
Merge remote-tracking branch 'refs/remotes/origin/bugfix/2140' into b…
TheMeinerLP Dec 2, 2023
fbad832
Fix passage entities
TheMeinerLP Apr 29, 2023
f547d14
Add dirty workaround to fix leashes when copy entities
TheMeinerLP Apr 29, 2023
cec7a1c
Add 1.19.3 support for leash copy
TheMeinerLP Apr 29, 2023
2263aa5
Add 1.18.X support for leash copy
TheMeinerLP Apr 29, 2023
d4305fa
Improve formatting
TheMeinerLP Apr 30, 2023
b73f63d
Improve formatting
TheMeinerLP Apr 30, 2023
59d3299
Add dirty workaround to fix leashes when copy entities
TheMeinerLP Apr 29, 2023
072cf75
Improve formatting
TheMeinerLP Apr 30, 2023
c22bf45
Merge branch 'bugfix/2140' of https://github.com/TheMeinerLP/FastAsyn…
TheMeinerLP Aug 11, 2024
0282a48
Fix 1.205 and 1.21 compatible
TheMeinerLP Aug 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.BitStorage;
import net.minecraft.util.ZeroBitStorage;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
Expand Down Expand Up @@ -736,6 +738,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz

syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator();
Map<BlockPos, LeashFenceKnotEntity> leashRef = new HashMap<>();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
Expand All @@ -759,12 +762,35 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
nativeTag);
if (entityTagMap.containsKey("Leash")) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("Leash"));
final LeashFenceKnotEntity leashEntity = leashRef.get(NbtUtils.readBlockPos(leashTag));
if (leashEntity != null) {
tag.put("Leash", NbtUtils.writeBlockPos(leashEntity.pos));
}
}

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(nativeTag.getUUID());
if (entity instanceof LeashFenceKnotEntity leashFenceKnotEntity) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("OldPos"));
if (leashTag != null) {
leashRef.put(
new BlockPos(
leashTag.getInt("X"),
leashTag.getInt("Y"),
leashTag.getInt("Z")
),
leashFenceKnotEntity
);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.BitStorage;
import net.minecraft.util.ZeroBitStorage;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
Expand Down Expand Up @@ -735,6 +737,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz

syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator();
Map<BlockPos, LeashFenceKnotEntity> leashRef = new HashMap<>();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
Expand All @@ -758,12 +761,35 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
nativeTag);
if (entityTagMap.containsKey("Leash")) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("Leash"));
final LeashFenceKnotEntity leashEntity = leashRef.get(NbtUtils.readBlockPos(leashTag));
if (leashEntity != null) {
tag.put("Leash", NbtUtils.writeBlockPos(leashEntity.pos));
}
}

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(nativeTag.getUUID());
if (entity instanceof LeashFenceKnotEntity leashFenceKnotEntity) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("OldPos"));
if (leashTag != null) {
leashRef.put(
new BlockPos(
leashTag.getInt("X"),
leashTag.getInt("Y"),
leashTag.getInt("Z")
),
leashFenceKnotEntity
);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.BitStorage;
import net.minecraft.util.ZeroBitStorage;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
Expand Down Expand Up @@ -736,6 +738,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz

syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator();
Map<BlockPos, LeashFenceKnotEntity> leashRef = new HashMap<>();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
Expand All @@ -759,12 +762,34 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
nativeTag);
if (entityTagMap.containsKey("Leash")) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("Leash"));
final LeashFenceKnotEntity leashEntity = leashRef.get(NbtUtils.readBlockPos(leashTag, "Leash"));
if (leashEntity != null) {
tag.put("Leash", NbtUtils.writeBlockPos(leashEntity.pos));
}
}
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(nativeTag.getUUID());
if (entity instanceof LeashFenceKnotEntity leashFenceKnotEntity) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("OldPos"));
if (leashTag != null) {
leashRef.put(
new BlockPos(
leashTag.getInt("X"),
leashTag.getInt("Y"),
leashTag.getInt("Z")
),
leashFenceKnotEntity
);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
import net.minecraft.core.SectionPos;
import net.minecraft.nbt.IntTag;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.BitStorage;
import net.minecraft.util.ZeroBitStorage;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
Expand Down Expand Up @@ -730,6 +732,7 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz

syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator();
Map<BlockPos, LeashFenceKnotEntity> leashRef = new HashMap<>();
while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue();
Expand All @@ -753,12 +756,29 @@ public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finaliz
if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
nativeTag);
if (entityTagMap.containsKey("Leash")) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("Leash")) ;
final LeashFenceKnotEntity leashEntity = leashRef.get(NbtUtils.readBlockPos(leashTag, "Leash"));
if (leashEntity != null) {
tag.put("Leash", NbtUtils.writeBlockPos(leashEntity.getPos()));
}
}
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(nativeTag.getUUID());
if (entity instanceof LeashFenceKnotEntity leashFenceKnotEntity) {
var leashTag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(
entityTagMap.get("OldPos")) ;
if (leashTag != null) {
leashRef.put(new BlockPos(leashTag.getInt("X"), leashTag.getInt("Y"),
leashTag.getInt("Z")),
leashFenceKnotEntity);
}
}
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.FloatTag;
import com.sk89q.jnbt.IntArrayTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.StringTag;
Expand Down Expand Up @@ -133,6 +135,12 @@ default Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
posList.add(new DoubleTag(location.y()));
posList.add(new DoubleTag(location.z()));
map.put("Pos", new ListTag(DoubleTag.class, posList));
if (!map.containsKey("Rotation")) {
List<FloatTag> rotList = new ArrayList<>();
rotList.add(new FloatTag(location.getYaw()));
rotList.add(new FloatTag(location.getPitch()));
map.put("Rotation", new ListTag(FloatTag.class, rotList));
}

NBTUtils.addUUIDToMap(map, uuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -428,11 +433,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<String, Tag<?, ?>>();
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());
}
}
}
}
Expand Down
Loading