WIP clipboard offsets

TODO schem load -> BlockArrayClipboard
This commit is contained in:
Jesse Boyd 2019-11-11 22:34:33 +00:00
parent 599a4dfebc
commit cfa147cf76
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
10 changed files with 466 additions and 61 deletions

View File

@ -322,7 +322,6 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk {
if ((!full && !get.hasSection(layer)) || !filter.appliesLayer(this, layer)) {
continue;
}
System.out.println("Apply layer " + full);
block.init(get, set, layer);
block.filter(filter);
}

View File

@ -14,7 +14,6 @@ import java.util.function.Supplier;
public class WorldCopyClipboard extends ReadOnlyClipboard {
public final int mx, my, mz;
private final boolean hasBiomes;
private final boolean hasEntities;
private Extent extent;
@ -28,10 +27,6 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
super(region);
this.hasBiomes = hasBiomes;
this.hasEntities = hasEntities;
final BlockVector3 origin = region.getMinimumPoint();
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.supplier = supplier;
}
@ -46,17 +41,17 @@ public class WorldCopyClipboard extends ReadOnlyClipboard {
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
return getExtent().getFullBlock(mx + x, my + y, mz + z);
return getExtent().getFullBlock(x, y, z);
}
@Override
public BlockState getBlock(int x, int y, int z) {
return getExtent().getBlock(mx + x, my + y, mz + z);
return getExtent().getBlock(x, y, z);
}
@Override
public BiomeType getBiomeType(int x, int z) {
return getExtent().getBiomeType(mx + x, mz + z);
return getExtent().getBiomeType(x, z);
}
@Override

View File

@ -23,22 +23,16 @@ public class WorldCutClipboard extends WorldCopyClipboard {
@Override
public BaseBlock getFullBlock(int x, int y, int z) {
int xx = mx + x;
int yy = my + y;
int zz = mz + z;
Extent extent = getExtent();
BaseBlock block = extent.getFullBlock(xx, yy, zz);
extent.setBlock(xx, yy, zz, BlockTypes.AIR.getDefaultState());
BaseBlock block = extent.getFullBlock(x, y, z);
extent.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
return block;
}
@Override
public BlockState getBlock(int x, int y, int z) {
int xx = mx + x;
int yy = my + y;
int zz = mz + z;
Extent extent = getExtent();
BlockState block = extent.getBlock(xx, yy, zz);
BlockState block = extent.getBlock(x, y, z);
extent.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
return block;
}

View File

@ -191,9 +191,8 @@ public class ClipboardCommands {
session.setClipboard(null);
ReadOnlyClipboard lazyClipboard = ReadOnlyClipboard.of(region, !skipEntities, copyBiomes);
BlockArrayClipboard clipboard = new BlockArrayClipboard(region, lazyClipboard);
clipboard.setOrigin(session.getPlacementPosition(actor));
session.setClipboard(new ClipboardHolder(clipboard));
lazyClipboard.setOrigin(session.getPlacementPosition(actor));
session.setClipboard(new ClipboardHolder(lazyClipboard));
BBC.COMMAND_COPY.send(actor, region.getArea());
if (!actor.hasPermission("fawe.tips")) {
BBC.TIP_PASTE.or(BBC.TIP_LAZYCOPY, BBC.TIP_DOWNLOAD, BBC.TIP_ROTATE, BBC.TIP_COPYPASTE, BBC.TIP_REPLACE_MARKER, BBC.TIP_COPY_PATTERN).send(actor);
@ -226,9 +225,8 @@ public class ClipboardCommands {
// session.setClipboard(null);
//
// ReadOnlyClipboard lazyClipboard = new WorldCutClipboard(editSession, region, !skipEntities, copyBiomes);
// BlockArrayClipboard clipboard = new BlockArrayClipboard(region, lazyClipboard);
// clipboard.setOrigin(session.getPlacementPosition(actor));
// session.setClipboard(new ClipboardHolder(clipboard));
// session.setClipboard(new ClipboardHolder(lazyClipboard));
// BBC.COMMAND_CUT_LAZY.send(actor, region.getArea());
// }
@ -462,6 +460,7 @@ public class ClipboardCommands {
BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(actor);
checkPaste(actor, editSession, to, holder, clipboard);
Operation operation = holder
.createPaste(editSession)
.to(to)

View File

@ -293,6 +293,7 @@ public final class PlatformCommandManager {
.map(actor -> {
EditSession editSession = localSession.createEditSession(actor);
editSession.enableStandardMode();
Request.request().setEditSession(editSession);
return editSession;
});
});

View File

@ -60,6 +60,7 @@ public class ProvideBindings extends Bindings {
public EditSession editSession(LocalSession localSession, Player player) {
EditSession editSession = localSession.createEditSession(player);
editSession.enableStandardMode();
Request.request().setEditSession(editSession);
return editSession;
}

View File

@ -19,8 +19,8 @@
package com.sk89q.worldedit.extent.clipboard;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.object.clipboard.DelegateClipboard;
import com.google.common.collect.Iterators;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
@ -29,6 +29,8 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.visitor.Order;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector2;
import com.sk89q.worldedit.math.OffsetBlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -39,7 +41,6 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@ -68,16 +69,12 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
*/
public BlockArrayClipboard(Region region, UUID clipboardId) {
this(region, Clipboard.create(region.getDimensions(), clipboardId));
checkNotNull(region);
this.region = region.clone();
this.offset = region.getMinimumPoint();
}
public BlockArrayClipboard(Region region, Clipboard clipboard) {
super(clipboard);
checkNotNull(region);
this.region = region.clone();
this.offset = region.getMinimumPoint();
setRegion(region);
}
@Override
@ -87,6 +84,7 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
public void setRegion(Region region) {
this.region = region;
this.offset = region.getMinimumPoint();
}
@Override
@ -237,17 +235,21 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
@Override
public Iterator<BlockVector3> iterator() {
return getParent().iterator();
OffsetBlockVector3 mutable = new OffsetBlockVector3(offset);
return Iterators.transform(getParent().iterator(), mutable::init);
}
@Override
public Iterator<BlockVector2> iterator2d() {
return getParent().iterator2d();
MutableBlockVector2 mutable = new MutableBlockVector2();
return Iterators.transform(getParent().iterator2d(), input ->
mutable.setComponents(input.getX() + offset.getX(), input.getZ() + offset.getZ()));
}
@Override
public Iterator<BlockVector3> iterator(Order order) {
return getParent().iterator(order);
OffsetBlockVector3 mutable = new OffsetBlockVector3(offset);
return Iterators.transform(getParent().iterator(order), mutable::init);
}
/**

View File

@ -51,6 +51,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.Regions;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nullable;
@ -69,7 +70,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* Specifies an object that implements something suitable as a "clipboard."
*/
public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable {
public static Clipboard create(Region region) {
static Clipboard create(Region region) {
checkNotNull(region);
checkNotNull(region.getWorld(),
"World cannot be null (use the other constructor for the region)");
@ -78,7 +79,7 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable {
return ReadOnlyClipboard.of(session, region);
}
public static Clipboard create(BlockVector3 size, UUID uuid) {
static Clipboard create(BlockVector3 size, UUID uuid) {
if (Settings.IMP.CLIPBOARD.USE_DISK) {
return new DiskOptimizedClipboard(size, uuid);
} else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) {
@ -323,7 +324,6 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable {
}
default void paste(Extent extent, BlockVector3 to, boolean pasteAir) {
Region region = this.getRegion().clone();
final BlockVector3 origin = this.getOrigin();
final boolean copyBiomes = this.hasBiomes();
@ -332,33 +332,21 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable {
final int rely = to.getBlockY() - origin.getBlockY();
final int relz = to.getBlockZ() - origin.getBlockZ();
Operation visitor = new RegionVisitor(region, new RegionFunction() {
// MutableBlockVector2 mpos2d_2 = new MutableBlockVector2();
MutableBlockVector2 mpos2d = new MutableBlockVector2();
{
mpos2d.setComponents(Integer.MIN_VALUE, Integer.MIN_VALUE);
MutableBlockVector2 mpos2d = new MutableBlockVector2();
mpos2d.setComponents(Integer.MIN_VALUE, Integer.MIN_VALUE);
for (BlockVector3 pos : this) {
BaseBlock block = pos.getFullBlock(this);
int xx = pos.getX() + relx;
int zz = pos.getZ() + relz;
if (copyBiomes && xx != mpos2d.getBlockX() && zz != mpos2d.getBlockZ()) {
mpos2d.setComponents(xx, zz);
extent.setBiome(mpos2d, Clipboard.this.getBiome(pos.toBlockVector2()));
}
@Override
public boolean apply(BlockVector3 mutable) throws WorldEditException {
BlockState block = getBlock(mutable);
int xx = mutable.getBlockX() + relx;
int zz = mutable.getBlockZ() + relz;
if (copyBiomes && xx != mpos2d.getBlockX() && zz != mpos2d.getBlockZ()) {
mpos2d.setComponents(xx, zz);
// extent.setBiome(mpos2d, clipboard.getBiome(mpos2d_2.setComponents(mutable.getBlockX(), mutable.getBlockZ())));
extent.setBiome(mpos2d, Clipboard.this
.getBiome(BlockVector2.at(mutable.getBlockX(), mutable.getBlockZ())));
}
if (!pasteAir && block.getBlockType().getMaterial().isAir()) {
return false;
}
extent.setBlock(xx, mutable.getBlockY() + rely, zz, block);
return false;
if (!pasteAir && block.getBlockType().getMaterial().isAir()) {
continue;
}
});
Operations.completeBlindly(visitor);
extent.setBlock(xx, pos.getY() + rely, zz, block);
}
// Entity offset is the paste location subtract the clipboard origin (entity's location is already relative to the world origin)
final int entityOffsetX = to.getBlockX() - origin.getBlockX();
final int entityOffsetY = to.getBlockY() - origin.getBlockY();

View File

@ -0,0 +1,402 @@
package com.sk89q.worldedit.math;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.Comparator;
public class DelegateBlockVector3 extends BlockVector3 {
private BlockVector3 parent;
public DelegateBlockVector3 init(BlockVector3 parent) {
this.parent = parent;
return this;
}
public static BlockVector3 at(double x, double y, double z) {
return BlockVector3.at(x, y, z);
}
public static BlockVector3 at(int x, int y, int z) {
return BlockVector3.at(x, y, z);
}
public static boolean isLongPackable(BlockVector3 location) {
return BlockVector3.isLongPackable(location);
}
public static void checkLongPackable(BlockVector3 location) {
BlockVector3.checkLongPackable(location);
}
public static BlockVector3 fromLongPackedForm(long packed) {
return BlockVector3.fromLongPackedForm(packed);
}
public static Comparator<BlockVector3> sortByCoordsYzx() {
return BlockVector3.sortByCoordsYzx();
}
@Override
public MutableBlockVector3 setComponents(double x, double y, double z) {
return parent.setComponents(x, y, z);
}
@Override
public MutableBlockVector3 setComponents(int x, int y, int z) {
return parent.setComponents(x, y, z);
}
@Override
public MutableBlockVector3 mutX(double x) {
return parent.mutX(x);
}
@Override
public MutableBlockVector3 mutY(double y) {
return parent.mutY(y);
}
@Override
public MutableBlockVector3 mutZ(double z) {
return parent.mutZ(z);
}
@Override
public MutableBlockVector3 mutX(int x) {
return parent.mutX(x);
}
@Override
public MutableBlockVector3 mutY(int y) {
return parent.mutY(y);
}
@Override
public MutableBlockVector3 mutZ(int z) {
return parent.mutZ(z);
}
@Override
public BlockVector3 toImmutable() {
return parent.toImmutable();
}
@Override
public long toLongPackedForm() {
return parent.toLongPackedForm();
}
@Override
public int getX() {
return parent.getX();
}
@Override
public int getBlockX() {
return parent.getBlockX();
}
@Override
public BlockVector3 withX(int x) {
return parent.withX(x);
}
@Override
public int getY() {
return parent.getY();
}
@Override
public int getBlockY() {
return parent.getBlockY();
}
@Override
public BlockVector3 withY(int y) {
return parent.withY(y);
}
@Override
public int getZ() {
return parent.getZ();
}
@Override
public int getBlockZ() {
return parent.getBlockZ();
}
@Override
public BlockVector3 withZ(int z) {
return parent.withZ(z);
}
@Override
public BlockVector3 add(BlockVector3 other) {
return parent.add(other);
}
@Override
public BlockVector3 add(int x, int y, int z) {
return parent.add(x, y, z);
}
@Override
public BlockVector3 add(BlockVector3... others) {
return parent.add(others);
}
@Override
public BlockVector3 subtract(BlockVector3 other) {
return parent.subtract(other);
}
@Override
public BlockVector3 subtract(int x, int y, int z) {
return parent.subtract(x, y, z);
}
@Override
public BlockVector3 subtract(BlockVector3... others) {
return parent.subtract(others);
}
@Override
public BlockVector3 multiply(BlockVector3 other) {
return parent.multiply(other);
}
@Override
public BlockVector3 multiply(int x, int y, int z) {
return parent.multiply(x, y, z);
}
@Override
public BlockVector3 multiply(BlockVector3... others) {
return parent.multiply(others);
}
@Override
public BlockVector3 multiply(int n) {
return parent.multiply(n);
}
@Override
public BlockVector3 divide(BlockVector3 other) {
return parent.divide(other);
}
@Override
public BlockVector3 divide(int x, int y, int z) {
return parent.divide(x, y, z);
}
@Override
public BlockVector3 divide(int n) {
return parent.divide(n);
}
@Override
public BlockVector3 shr(int x, int y, int z) {
return parent.shr(x, y, z);
}
@Override
public BlockVector3 shr(int n) {
return parent.shr(n);
}
@Override
public BlockVector3 shl(int x, int y, int z) {
return parent.shl(x, y, z);
}
@Override
public BlockVector3 shl(int n) {
return parent.shl(n);
}
@Override
public double length() {
return parent.length();
}
@Override
public int lengthSq() {
return parent.lengthSq();
}
@Override
public double distance(BlockVector3 other) {
return parent.distance(other);
}
@Override
public int distanceSq(BlockVector3 other) {
return parent.distanceSq(other);
}
@Override
public BlockVector3 normalize() {
return parent.normalize();
}
@Override
public double dot(BlockVector3 other) {
return parent.dot(other);
}
@Override
public BlockVector3 cross(BlockVector3 other) {
return parent.cross(other);
}
@Override
public boolean containedWithin(BlockVector3 min, BlockVector3 max) {
return parent.containedWithin(min, max);
}
@Override
public BlockVector3 clampY(int min, int max) {
return parent.clampY(min, max);
}
@Override
public BlockVector3 floor() {
return parent.floor();
}
@Override
public BlockVector3 ceil() {
return parent.ceil();
}
@Override
public BlockVector3 round() {
return parent.round();
}
@Override
public BlockVector3 abs() {
return parent.abs();
}
@Override
public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) {
return parent.transform2D(angle, aboutX, aboutZ, translateX, translateZ);
}
@Override
public double toPitch() {
return parent.toPitch();
}
@Override
public double toYaw() {
return parent.toYaw();
}
@Override
public BlockVector3 getMinimum(BlockVector3 v2) {
return parent.getMinimum(v2);
}
@Override
public BlockVector3 getMaximum(BlockVector3 v2) {
return parent.getMaximum(v2);
}
@Override
public boolean setOrdinal(Extent orDefault, int ordinal) {
return parent.setOrdinal(orDefault, ordinal);
}
@Override
public boolean setBlock(Extent orDefault, BlockState state) {
return parent.setBlock(orDefault, state);
}
@Override
public boolean setFullBlock(Extent orDefault, BaseBlock block) {
return parent.setFullBlock(orDefault, block);
}
@Override
public boolean setBiome(Extent orDefault, BiomeType biome) {
return parent.setBiome(orDefault, biome);
}
@Override
public int getOrdinal(Extent orDefault) {
return parent.getOrdinal(orDefault);
}
@Override
public char getOrdinalChar(Extent orDefault) {
return parent.getOrdinalChar(orDefault);
}
@Override
public BlockState getBlock(Extent orDefault) {
return parent.getBlock(orDefault);
}
@Override
public BaseBlock getFullBlock(Extent orDefault) {
return parent.getFullBlock(orDefault);
}
@Override
public CompoundTag getNbtData(Extent orDefault) {
return parent.getNbtData(orDefault);
}
@Override
public BlockState getOrdinalBelow(Extent orDefault) {
return parent.getOrdinalBelow(orDefault);
}
@Override
public BlockState getStateAbove(Extent orDefault) {
return parent.getStateAbove(orDefault);
}
@Override
public BlockState getStateRelativeY(Extent orDefault, int y) {
return parent.getStateRelativeY(orDefault, y);
}
@Override
public BlockVector2 toBlockVector2() {
return parent.toBlockVector2();
}
@Override
public Vector3 toVector3() {
return parent.toVector3();
}
@Override
public boolean equals(Object obj) {
return parent.equals(obj);
}
@Override
public int hashCode() {
return parent.hashCode();
}
@Override
public String toString() {
return parent.toString();
}
@Override
public BlockVector3 plus(BlockVector3 other) {
return parent.plus(other);
}
}

View File

@ -0,0 +1,24 @@
package com.sk89q.worldedit.math;
public class OffsetBlockVector3 extends DelegateBlockVector3 {
private final BlockVector3 offset;
public OffsetBlockVector3(BlockVector3 offset) {
this.offset = offset;
}
@Override
public int getX() {
return super.getX() + offset.getX();
}
@Override
public int getY() {
return super.getY() + offset.getY();
}
@Override
public int getZ() {
return super.getZ() + offset.getZ();
}
}