mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
WIP clipboard offsets
TODO schem load -> BlockArrayClipboard
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user