use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.
the class ClipboardSpline method pasteBlocks.
@Override
protected int pasteBlocks(BlockVector3 target, Vector3 offset, double angle) throws MaxChangedBlocksException {
RoundedTransform transform = new RoundedTransform(new AffineTransform().translate(offset).rotateY(angle));
if (!this.transform.isIdentity()) {
transform = transform.combine(this.transform);
}
if (!originalTransform.isIdentity()) {
transform = transform.combine(originalTransform);
}
// Pasting
Clipboard clipboard = clipboardHolder.getClipboard();
clipboard.setOrigin(center.subtract(centerOffset).round());
clipboardHolder.setTransform(transform);
BlockVector3 functionOffset = target.subtract(clipboard.getOrigin());
final int offX = functionOffset.getBlockX();
final int offY = functionOffset.getBlockY();
final int offZ = functionOffset.getBlockZ();
Operation operation = clipboardHolder.createPaste(editSession).to(target).ignoreAirBlocks(true).filter(v -> buffer.add(v.getBlockX() + offX, v.getBlockY() + offY, v.getBlockZ() + offZ)).build();
Operations.completeLegacy(operation);
// Cleanup
clipboardHolder.setTransform(originalTransform);
clipboard.setOrigin(originalOrigin);
return operation instanceof ForwardExtentCopy ? ((ForwardExtentCopy) operation).getAffected() : 0;
}
use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.
the class SchemGen method spawn.
@Override
public boolean spawn(Random random, int x, int z) throws WorldEditException {
mutable.mutX(x);
mutable.mutZ(z);
int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), this.extent.getMinY(), this.extent.getMaxY(), Integer.MIN_VALUE, Integer.MAX_VALUE);
if (y == Integer.MIN_VALUE || y == Integer.MAX_VALUE) {
return false;
}
mutable.mutY(y);
if (!mask.test(mutable)) {
return false;
}
mutable.mutY(y + 1);
ClipboardHolder holder = clipboards.get(ThreadLocalRandom.current().nextInt(clipboards.size()));
if (randomRotate) {
holder.setTransform(new AffineTransform().rotateY(ThreadLocalRandom.current().nextInt(4) * 90));
}
Clipboard clipboard = holder.getClipboard();
Transform transform = holder.getTransform();
if (transform.isIdentity()) {
clipboard.paste(extent, mutable, false);
} else {
clipboard.paste(extent, mutable, false, transform);
}
mutable.mutY(y);
return true;
}
use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.
the class FlattenedClipboardTransform method getTransformedRegion.
/**
* Get the transformed region.
*
* @return the transformed region
*/
public Region getTransformedRegion() {
Region region = original.getRegion();
Vector3 minimum = region.getMinimumPoint().toVector3();
Vector3 maximum = region.getMaximumPoint().toVector3();
Transform transformAround = new CombinedTransform(new AffineTransform().translate(original.getOrigin().multiply(-1)), transform, new AffineTransform().translate(original.getOrigin()));
Vector3[] corners = new Vector3[] { minimum, maximum, minimum.withX(maximum.getX()), minimum.withY(maximum.getY()), minimum.withZ(maximum.getZ()), maximum.withX(minimum.getX()), maximum.withY(minimum.getY()), maximum.withZ(minimum.getZ()) };
for (int i = 0; i < corners.length; i++) {
corners[i] = transformAround.apply(corners[i]);
}
Vector3 newMinimum = corners[0];
Vector3 newMaximum = corners[0];
for (int i = 1; i < corners.length; i++) {
newMinimum = newMinimum.getMinimum(corners[i]);
newMaximum = newMaximum.getMaximum(corners[i]);
}
// After transformation, the points may not really sit on a block,
// so we should expand the region for edge cases
newMinimum = newMinimum.floor();
newMaximum = newMaximum.ceil();
return new CuboidRegion(newMinimum.toBlockPoint(), newMaximum.toBlockPoint());
}
use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.
the class BackwardsExtentBlockCopy method resume.
@Override
public Operation resume(RunContext run) throws WorldEditException {
CuboidRegion destRegion = transform(this.transform, this.region);
Transform inverse = this.transform.inverse();
for (BlockVector3 pt : destRegion) {
BlockVector3 copyFrom = transform(inverse, pt);
if (region.contains(copyFrom)) {
if (function.apply(pt)) {
affected++;
}
}
}
return null;
}
use of com.sk89q.worldedit.math.transform.Transform in project FastAsyncWorldEdit by IntellectualSites.
the class ClipboardCommands method download.
// FAWE start
@Command(name = "download", aliases = { "/download" }, desc = "Downloads your clipboard through the configured web interface")
@Deprecated
@CommandPermissions({ "worldedit.clipboard.download" })
public void download(final Actor actor, final LocalSession session, @Arg(name = "format", desc = "String", def = "fast") final String formatName) throws WorldEditException {
final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) {
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
return;
}
actor.print(Caption.of("fawe.web.generating.link", formatName));
ClipboardHolder holder = session.getClipboard();
URL url;
if (holder instanceof MultiClipboardHolder) {
MultiClipboardHolder multi = (MultiClipboardHolder) holder;
Set<File> files = new HashSet<>();
Set<URI> invalid = new HashSet<>();
for (ClipboardHolder cur : multi.getHolders()) {
if (cur instanceof URIClipboardHolder) {
URIClipboardHolder uriHolder = (URIClipboardHolder) cur;
URI uri = uriHolder.getUri();
File file = new File(uri.getPath());
if (file.exists() && file.isFile()) {
files.add(file.getAbsoluteFile());
} else if (!uri.getPath().isEmpty()) {
invalid.add(uri);
}
}
}
final LocalConfiguration config = WorldEdit.getInstance().getConfiguration();
final File working = WorldEdit.getInstance().getWorkingDirectoryFile(config.saveDir).getAbsoluteFile();
url = MainUtil.upload(null, null, "zip", new RunnableVal<>() {
@Override
public void run(OutputStream out) {
try (ZipOutputStream zos = new ZipOutputStream(out)) {
for (File file : files) {
String fileName = file.getName();
if (MainUtil.isInSubDirectory(working, file)) {
fileName = working.toURI().relativize(file.toURI()).getPath();
}
ZipEntry ze = new ZipEntry(fileName);
zos.putNextEntry(ze);
Files.copy(file.toPath(), zos);
zos.closeEntry();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
} else {
Clipboard clipboard = holder.getClipboard();
final Transform transform = holder.getTransform();
final Clipboard target;
// If we have a transform, bake it into the copy
if (!transform.isIdentity()) {
final FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform);
target = new BlockArrayClipboard(result.getTransformedRegion(), actor.getUniqueId());
target.setOrigin(clipboard.getOrigin());
Operations.completeLegacy(result.copyTo(target));
} else {
target = clipboard;
}
if (format == BuiltInClipboardFormat.PNG) {
try {
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
ClipboardWriter writer = format.getWriter(baos);
writer.write(target);
baos.flush();
url = ImgurUtility.uploadImage(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
url = null;
}
} else {
if (Settings.settings().WEB.URL.isEmpty()) {
actor.print(Caption.of("fawe.error.setting.disable", "web.url"));
return;
}
url = FaweAPI.upload(target, format);
}
}
if (url == null) {
actor.print(Caption.of("fawe.web.generating.link.failed"));
} else {
String urlText = url.toString();
actor.print(Caption.of("fawe.web.download.link", urlText).clickEvent(ClickEvent.openUrl(urlText)));
}
}
Aggregations