fix rotation of entities in clipboard

This commit is contained in:
wea_ondara 2020-07-26 18:26:21 +02:00
parent 950f343339
commit a38c82304a
3 changed files with 47 additions and 4 deletions

View File

@ -40,6 +40,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -436,6 +437,11 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable
public List<? extends Entity> getEntities() {
return new ArrayList<>(entities);
}
@Override
public List<? extends Entity> getEntities(Region region) {
return new ArrayList<>(entities.stream().filter(e -> region.contains(e.getLocation().toBlockPoint())).collect(Collectors.toList()));
}
@Override
public void removeEntity(Entity entity) {

View File

@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
public class MemoryOptimizedClipboard extends LinearClipboard {
@ -291,11 +292,15 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
return new ArrayList<>(entities);
}
@Override
public List<? extends Entity> getEntities(Region region) {
return new ArrayList<>(entities.stream().filter(e -> region.contains(e.getLocation().toBlockPoint())).collect(Collectors.toList()));
}
@Override
public void removeEntity(Entity entity) {
if (entity instanceof ClipboardEntity) {
this.entities.remove(entity);
}
}
}

View File

@ -45,6 +45,7 @@ import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.stream.Collectors;
/**
* Stores block data as a multi-dimensional array of {@link BlockState}s and
@ -197,18 +198,49 @@ public class BlockArrayClipboard implements Clipboard {
public List<? extends Entity> getEntities(Region region) {
region = region.clone();
region.shift(BlockVector3.ZERO.subtract(origin));
return getParent().getEntities(region);
return getParent().getEntities(region).stream().map(e ->
{
if (e instanceof ClipboardEntity) {
ClipboardEntity ce = (ClipboardEntity) e;
Location oldloc = ce.getLocation();
Location loc = new Location(oldloc.getExtent(),
oldloc.getX() + origin.getBlockX(),
oldloc.getY() + origin.getBlockY(),
oldloc.getZ() + origin.getBlockZ(),
oldloc.getYaw(), oldloc.getPitch());
return new ClipboardEntity(loc, ce.entity);
}
return e;
}).collect(Collectors.toList());
}
@Override
public List<? extends Entity> getEntities() {
return getParent().getEntities();
return getParent().getEntities().stream().map(e ->
{
if (e instanceof ClipboardEntity) {
ClipboardEntity ce = (ClipboardEntity) e;
Location oldloc = ce.getLocation();
Location loc = new Location(oldloc.getExtent(),
oldloc.getX() + origin.getBlockX(),
oldloc.getY() + origin.getBlockY(),
oldloc.getZ() + origin.getBlockZ(),
oldloc.getYaw(), oldloc.getPitch());
return new ClipboardEntity(loc, ce.entity);
}
return e;
}).collect(Collectors.toList());
}
@Override
@Nullable
public Entity createEntity(Location location, BaseEntity entity) {
return getParent().createEntity(location, entity);
Location l = new Location(location.getExtent(),
location.getX() - origin.getBlockX(),
location.getY() - origin.getBlockY(),
location.getZ() - origin.getBlockZ(),
location.getYaw(), location.getPitch());
return getParent().createEntity(l, entity);
}
@Override