Skip to content

Commit

Permalink
Fix pasting leashed entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
wizjany committed Jun 28, 2019
1 parent 927ae6d commit 6493ef1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -23,6 +23,7 @@

import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompoundTagBuilder;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
Expand Down Expand Up @@ -138,6 +139,23 @@ private BaseEntity transformNbtData(BaseEntity state) {
CompoundTag tag = state.getNbtData();

if (tag != null) {
// Handle leashed entities
Tag leashTag = tag.getValue().get("Leash");
if (leashTag instanceof CompoundTag) {
CompoundTag leashCompound = (CompoundTag) leashTag;
if (leashCompound.containsKey("X")) { // leashed to a fence
Vector3 tilePosition = Vector3.at(leashCompound.asInt("X"), leashCompound.asInt("Y"), leashCompound.asInt("Z"));
BlockVector3 newLeash = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint();
return new BaseEntity(state.getType(), tag.createBuilder()
.put("Leash", leashCompound.createBuilder()
.putInt("X", newLeash.getBlockX())
.putInt("Y", newLeash.getBlockY())
.putInt("Z", newLeash.getBlockZ())
.build()
).build());
}
}

// Handle hanging entities (paintings, item frames, etc.)
boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ");
boolean hasFacing = tag.containsKey("Facing");
Expand Down
Expand Up @@ -46,7 +46,9 @@
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.FlatRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.entity.EntityTypes;

import java.util.Comparator;
import java.util.List;

/**
Expand Down Expand Up @@ -317,6 +319,7 @@ public Operation resume(RunContext run) throws WorldEditException {
ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform);
entityCopy.setRemoving(removingEntities);
List<? extends Entity> entities = Lists.newArrayList(source.getEntities(region));
entities.sort(Comparator.comparing(e -> e.getState() != null && e.getState().getType() != EntityTypes.LEASH_KNOT));
entities.removeIf(entity -> {
EntityProperties properties = entity.getFacet(EntityProperties.class);
return properties != null && !properties.isPasteable();
Expand Down

0 comments on commit 6493ef1

Please sign in to comment.