This commit is contained in:
Jesse Boyd 2016-10-24 19:38:25 +11:00
parent b71c3ec43e
commit f13c01a177
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 122 additions and 4 deletions

View File

@ -79,6 +79,7 @@ import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.PasteBuilder;
import com.sk89q.worldedit.session.SessionManager; import com.sk89q.worldedit.session.SessionManager;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder; import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
@ -356,9 +357,10 @@ public class Fawe {
ToolUtilCommands.inject(); // Fixes + Translations ToolUtilCommands.inject(); // Fixes + Translations
GeneralCommands.inject(); // Translations + gmask args GeneralCommands.inject(); // Translations + gmask args
// Schematic // Schematic
SchematicReader.inject(); SchematicReader.inject(); // Optimizations
SchematicWriter.inject(); SchematicWriter.inject(); // Optimizations
ClipboardFormat.inject(); ClipboardFormat.inject(); // Optimizations + new formats + api
PasteBuilder.inject(); // Optimizations
// Brushes/Tools // Brushes/Tools
GravityBrush.inject(); // Fix for instant placement assumption GravityBrush.inject(); // Fix for instant placement assumption
LongRangeBuildTool.inject(); LongRangeBuildTool.inject();

View File

@ -155,6 +155,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
width = dimensions.getBlockX(); width = dimensions.getBlockX();
height = dimensions.getBlockY(); height = dimensions.getBlockY();
length = dimensions.getBlockZ(); length = dimensions.getBlockZ();
area = width * length;
long size = width * height * length * 2l + HEADER_SIZE; long size = width * height * length * 2l + HEADER_SIZE;
raf.setLength(size); raf.setLength(size);
raf.seek(2); raf.seek(2);
@ -278,13 +279,17 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
} }
} }
public int getIndex(int x, int y, int z) {
return x + ((ylast == y) ? ylasti : (ylasti = (ylast = y) * area)) + ((zlast == z) ? zlasti : (zlasti = (zlast = z) * width));
}
@Override @Override
public BaseBlock getBlock(int x, int y, int z) { public BaseBlock getBlock(int x, int y, int z) {
try { try {
if (raf == null) { if (raf == null) {
open(); open();
} }
int i = x + ((ylast == y) ? ylasti : (ylasti = ((ylast = y)) * area)) + ((zlast == z) ? zlasti : (zlasti = (zlast = z) * width)); int i = getIndex(x, y, z);
if (i != last + 1) { if (i != last + 1) {
raf.seek((HEADER_SIZE) + (i << 1)); raf.seek((HEADER_SIZE) + (i << 1));
lastAccessed = System.currentTimeMillis(); lastAccessed = System.currentTimeMillis();

View File

@ -0,0 +1,111 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.session;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.world.registry.WorldData;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Builds an operation to paste the contents of a clipboard.
*/
public class PasteBuilder {
private final Clipboard clipboard;
private final WorldData worldData;
private final Transform transform;
private final Extent targetExtent;
private final WorldData targetWorldData;
private Vector to = new Vector();
private boolean ignoreAirBlocks;
/**
* Create a new instance.
*
* @param holder the clipboard holder
* @param targetExtent an extent
* @param targetWorldData world data of the target
*/
public PasteBuilder(ClipboardHolder holder, Extent targetExtent, WorldData targetWorldData) {
checkNotNull(holder);
checkNotNull(targetExtent);
checkNotNull(targetWorldData);
this.clipboard = holder.getClipboard();
this.worldData = holder.getWorldData();
this.transform = holder.getTransform();
this.targetExtent = targetExtent;
this.targetWorldData = targetWorldData;
}
/**
* Set the target location.
*
* @param to the target location
* @return this builder instance
*/
public PasteBuilder to(Vector to) {
this.to = to;
return this;
}
/**
* Set whether air blocks in the source are skipped over when pasting.
*
* @return this builder instance
*/
public PasteBuilder ignoreAirBlocks(boolean ignoreAirBlocks) {
this.ignoreAirBlocks = ignoreAirBlocks;
return this;
}
/**
* Build the operation.
*
* @return the operation
*/
public Operation build() {
Extent extent = clipboard;
if (!transform.isIdentity()) {
extent = new BlockTransformExtent(extent, transform, targetWorldData.getBlockRegistry());
}
ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to);
System.out.println(clipboard.getRegion());
copy.setTransform(transform);
if (ignoreAirBlocks) {
copy.setSourceMask(new ExistingBlockMask(clipboard));
}
return copy;
}
public static Class<?> inject() {
return PasteBuilder.class;
}
}