2014-06-30 00:47:08 +00:00
|
|
|
/*
|
|
|
|
* 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.extent.clipboard;
|
|
|
|
|
2019-10-31 03:04:15 +00:00
|
|
|
import com.boydti.fawe.object.clipboard.DelegateClipboard;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.jnbt.CompoundTag;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
2019-10-31 03:04:15 +00:00
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
import com.sk89q.worldedit.util.Location;
|
2019-06-04 15:48:30 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
2019-06-04 15:48:30 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
2019-10-31 03:04:15 +00:00
|
|
|
|
2019-10-31 13:12:23 +00:00
|
|
|
import javax.annotation.Nullable;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.io.Closeable;
|
2019-10-31 03:04:15 +00:00
|
|
|
import java.io.IOException;
|
2014-06-30 00:47:08 +00:00
|
|
|
import java.util.List;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.util.UUID;
|
2019-10-31 13:12:23 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
/**
|
2018-08-12 14:03:07 +00:00
|
|
|
* Stores block data as a multi-dimensional array of {@link BlockState}s and
|
2014-06-30 00:47:08 +00:00
|
|
|
* other data as lists or maps.
|
|
|
|
*/
|
2019-10-31 03:04:15 +00:00
|
|
|
public class BlockArrayClipboard extends DelegateClipboard implements Clipboard, Closeable {
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2019-07-22 20:42:40 +00:00
|
|
|
private Region region;
|
2019-01-09 07:13:44 +00:00
|
|
|
private BlockVector3 origin;
|
2019-06-04 15:48:30 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public BlockArrayClipboard(Region region) {
|
2019-10-31 03:04:15 +00:00
|
|
|
this(region, UUID.randomUUID());
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
2019-06-04 15:48:30 +00:00
|
|
|
*
|
2014-07-26 07:29:12 +00:00
|
|
|
* <p>The origin will be placed at the region's lowest minimum point.</p>
|
2014-06-30 00:47:08 +00:00
|
|
|
*
|
|
|
|
* @param region the bounding region
|
|
|
|
*/
|
2018-08-12 14:03:07 +00:00
|
|
|
public BlockArrayClipboard(Region region, UUID clipboardId) {
|
2019-10-31 03:04:15 +00:00
|
|
|
this(region, Clipboard.create(region.getDimensions(), clipboardId));
|
2018-08-12 14:03:07 +00:00
|
|
|
checkNotNull(region);
|
|
|
|
this.region = region.clone();
|
|
|
|
this.origin = region.getMinimumPoint();
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:04:15 +00:00
|
|
|
public BlockArrayClipboard(Region region, Clipboard clipboard) {
|
|
|
|
super(clipboard);
|
2014-06-30 00:47:08 +00:00
|
|
|
checkNotNull(region);
|
|
|
|
this.region = region.clone();
|
2014-07-02 09:56:21 +00:00
|
|
|
this.origin = region.getMinimumPoint();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
2019-10-31 03:04:15 +00:00
|
|
|
public void close() throws IOException {
|
|
|
|
if (getParent() instanceof Closeable) {
|
|
|
|
((Closeable) getParent()).close();
|
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Region getRegion() {
|
2018-10-24 06:50:15 +00:00
|
|
|
return region;
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 15:54:13 +00:00
|
|
|
public void setRegion(Region region) {
|
|
|
|
this.region = region;
|
|
|
|
}
|
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getOrigin() {
|
2014-07-02 09:56:21 +00:00
|
|
|
return origin;
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public void setOrigin(BlockVector3 origin) {
|
2014-07-02 09:56:21 +00:00
|
|
|
this.origin = origin;
|
2019-10-31 03:04:15 +00:00
|
|
|
getParent().setOrigin(origin.subtract(region.getMinimumPoint()));
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getMinimumPoint() {
|
2014-06-30 00:47:08 +00:00
|
|
|
return region.getMinimumPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getMaximumPoint() {
|
2014-06-30 00:47:08 +00:00
|
|
|
return region.getMaximumPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockState getBlock(BlockVector3 position) {
|
2014-06-30 00:47:08 +00:00
|
|
|
if (region.contains(position)) {
|
2019-10-31 03:04:15 +00:00
|
|
|
int x = position.getBlockX()- origin.getX();
|
|
|
|
int y = position.getBlockY()- origin.getY();
|
|
|
|
int z = position.getBlockZ()- origin.getZ();
|
|
|
|
return getParent().getBlock(x, y, z);
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
2019-06-04 15:48:30 +00:00
|
|
|
|
|
|
|
return BlockTypes.AIR.getDefaultState();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
2019-01-31 15:08:58 +00:00
|
|
|
public BaseBlock getFullBlock(BlockVector3 position) {
|
2019-06-28 14:01:51 +00:00
|
|
|
if(region.contains(position)) {
|
2019-10-31 03:04:15 +00:00
|
|
|
int x = position.getBlockX()- origin.getX();
|
|
|
|
int y = position.getBlockY()- origin.getY();
|
|
|
|
int z = position.getBlockZ()- origin.getZ();
|
|
|
|
return getParent().getFullBlock(x, y, z);
|
2019-06-28 14:01:51 +00:00
|
|
|
}
|
2019-07-22 20:42:40 +00:00
|
|
|
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-27 00:14:00 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
|
|
|
if (region.contains(position)) {
|
|
|
|
final int x = position.getBlockX();
|
|
|
|
final int y = position.getBlockY();
|
|
|
|
final int z = position.getBlockZ();
|
2018-08-12 14:03:07 +00:00
|
|
|
return setBlock(x, y, z, block);
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-21 01:52:35 +00:00
|
|
|
@Override
|
2019-06-28 14:01:51 +00:00
|
|
|
public boolean setTile(int x, int y, int z, CompoundTag tag) {
|
2019-10-31 03:04:15 +00:00
|
|
|
x -= origin.getX();
|
|
|
|
y -= origin.getY();
|
|
|
|
z -= origin.getZ();
|
|
|
|
return getParent().setTile(x, y, z, tag);
|
2019-06-28 14:01:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 15:48:30 +00:00
|
|
|
public boolean setTile(BlockVector3 position, CompoundTag tag) {
|
2019-06-28 14:01:51 +00:00
|
|
|
return setTile(position.getX(), position.getY(), position.getZ(), tag);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-27 00:39:10 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
|
2019-10-31 03:04:15 +00:00
|
|
|
x -= origin.getX();
|
|
|
|
y -= origin.getY();
|
|
|
|
z -= origin.getZ();
|
|
|
|
return getParent().setBlock(x, y, z, block);
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 00:14:00 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasBiomes() {
|
2019-10-31 03:04:15 +00:00
|
|
|
return getParent().hasBiomes();
|
2019-06-27 00:14:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-17 07:21:13 +00:00
|
|
|
@Override
|
2019-02-16 07:27:00 +00:00
|
|
|
public BiomeType getBiome(BlockVector2 position) {
|
2019-06-28 14:01:51 +00:00
|
|
|
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
|
2019-10-31 03:04:15 +00:00
|
|
|
return getParent().getBiomeType(v.getX(), v.getZ());
|
2014-07-17 07:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-16 07:27:00 +00:00
|
|
|
public boolean setBiome(BlockVector2 position, BiomeType biome) {
|
2019-10-31 13:12:23 +00:00
|
|
|
int x = position.getBlockX() - origin.getX();
|
|
|
|
int z = position.getBlockZ() - origin.getZ();
|
2019-10-31 03:04:15 +00:00
|
|
|
return getParent().setBiome(x, 0, z, biome);
|
2014-07-17 07:21:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 23:35:55 +00:00
|
|
|
@Override
|
|
|
|
public boolean setBiome(int x, int y, int z, BiomeType biome) {
|
2019-10-31 13:12:23 +00:00
|
|
|
x -= origin.getX();
|
|
|
|
y -= origin.getY();
|
|
|
|
z -= origin.getZ();
|
|
|
|
return getParent().setBiome(x, y, z, biome);
|
2019-10-31 03:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<? extends Entity> getEntities(Region region) {
|
2019-10-31 13:12:23 +00:00
|
|
|
region = region.clone();
|
|
|
|
region.shift(origin);
|
|
|
|
return getParent().getEntities(region);
|
2019-10-03 23:35:55 +00:00
|
|
|
}
|
|
|
|
|
2019-10-31 03:04:15 +00:00
|
|
|
@Override
|
2014-06-30 00:47:08 +00:00
|
|
|
@Nullable
|
2019-10-31 03:04:15 +00:00
|
|
|
public Entity createEntity(Location location, BaseEntity entity) {
|
2019-10-31 13:12:23 +00:00
|
|
|
return getParent().createEntity(location, entity);
|
2019-10-31 03:04:15 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
@Override
|
2019-10-31 03:04:15 +00:00
|
|
|
@Nullable
|
|
|
|
public void removeEntity(int x, int y, int z, UUID uuid) {
|
2019-10-31 13:12:23 +00:00
|
|
|
x -= origin.getX();
|
|
|
|
y -= origin.getY();
|
|
|
|
z -= origin.getZ();
|
|
|
|
getParent().removeEntity(x, y, z, uuid);
|
2019-10-31 03:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getBlock(int x, int y, int z) {
|
2019-10-31 13:12:23 +00:00
|
|
|
x -= origin.getX();
|
|
|
|
y -= origin.getY();
|
|
|
|
z -= origin.getZ();
|
|
|
|
return getParent().getBlock(x, y, z);
|
2019-10-31 03:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BaseBlock getFullBlock(int x, int y, int z) {
|
2019-10-31 13:12:23 +00:00
|
|
|
x -= origin.getX();
|
|
|
|
y -= origin.getY();
|
|
|
|
z -= origin.getZ();
|
|
|
|
return getParent().getFullBlock(x, y, z);
|
2019-10-31 03:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BiomeType getBiomeType(int x, int z) {
|
2019-10-31 13:12:23 +00:00
|
|
|
x -= origin.getX();
|
|
|
|
z -= origin.getZ();
|
|
|
|
return getParent().getBiomeType(x, z);
|
2019-10-31 03:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores entity data.
|
|
|
|
*/
|
|
|
|
public static class ClipboardEntity implements Entity {
|
|
|
|
private final BaseEntity entity;
|
|
|
|
private final Clipboard clipboard;
|
|
|
|
private final double x, y, z;
|
|
|
|
private final float yaw, pitch;
|
|
|
|
|
|
|
|
public ClipboardEntity(Location loc, BaseEntity entity) {
|
|
|
|
this((Clipboard) loc.getExtent(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getYaw(), loc.getPitch(), entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ClipboardEntity(Clipboard clipboard, double x, double y, double z, float yaw, float pitch, BaseEntity entity) {
|
|
|
|
checkNotNull(entity);
|
|
|
|
checkNotNull(clipboard);
|
|
|
|
this.clipboard = clipboard;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
this.yaw = yaw;
|
|
|
|
this.pitch = pitch;
|
|
|
|
this.entity = new BaseEntity(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean remove() {
|
|
|
|
clipboard.removeEntity(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public <T> T getFacet(Class<? extends T> cls) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the entity state. This is not a copy.
|
|
|
|
*
|
|
|
|
* @return the entity
|
|
|
|
*/
|
|
|
|
BaseEntity getEntity() {
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BaseEntity getState() {
|
|
|
|
return new BaseEntity(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location getLocation() {
|
|
|
|
return new Location(clipboard, x, y, z, yaw, pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Extent getExtent() {
|
|
|
|
return clipboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean setLocation(Location loc) {
|
|
|
|
clipboard.removeEntity(this);
|
|
|
|
Entity result = clipboard.createEntity(loc, entity);
|
|
|
|
return result != null;
|
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
2019-06-04 15:48:30 +00:00
|
|
|
}
|