mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-03 03:46:42 +00:00
Add a new block metadata framework and fix //rotate and //flip.
Remove the previous Mapping interfaces.
This commit is contained in:
@ -19,9 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.session;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.transform.Identity;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.world.registry.WorldData;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -30,6 +32,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class ClipboardHolder {
|
||||
|
||||
private final WorldData worldData;
|
||||
private final Clipboard clipboard;
|
||||
private Transform transform = new Identity();
|
||||
|
||||
@ -37,10 +40,22 @@ public class ClipboardHolder {
|
||||
* Create a new instance with the given clipboard.
|
||||
*
|
||||
* @param clipboard the clipboard
|
||||
* @param worldData the mapping of blocks, entities, and so on
|
||||
*/
|
||||
public ClipboardHolder(Clipboard clipboard) {
|
||||
public ClipboardHolder(Clipboard clipboard, WorldData worldData) {
|
||||
checkNotNull(clipboard);
|
||||
checkNotNull(worldData);
|
||||
this.clipboard = clipboard;
|
||||
this.worldData = worldData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mapping used for blocks, entities, and so on.
|
||||
*
|
||||
* @return the mapping
|
||||
*/
|
||||
public WorldData getWorldData() {
|
||||
return worldData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,4 +89,13 @@ public class ClipboardHolder {
|
||||
return transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder for an operation to paste this clipboard.
|
||||
*
|
||||
* @return a builder
|
||||
*/
|
||||
public PasteBuilder createPaste(Extent targetExtent, WorldData targetWorldData) {
|
||||
return new PasteBuilder(this, targetExtent, targetWorldData);
|
||||
}
|
||||
|
||||
}
|
||||
|
102
src/main/java/com/sk89q/worldedit/session/PasteBuilder.java
Normal file
102
src/main/java/com/sk89q/worldedit/session/PasteBuilder.java
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.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
|
||||
* @param targetWorldData
|
||||
*/
|
||||
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() {
|
||||
BlockTransformExtent extent = new BlockTransformExtent(clipboard, transform, targetWorldData.getBlockRegistry());
|
||||
ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to);
|
||||
copy.setTransform(transform);
|
||||
if (ignoreAirBlocks) {
|
||||
copy.setSourceMask(new ExistingBlockMask(clipboard));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user