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;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.config.Settings;
|
|
|
|
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
|
|
|
|
import com.boydti.fawe.object.clipboard.FaweClipboard;
|
2019-01-09 07:13:44 +00:00
|
|
|
import com.boydti.fawe.object.clipboard.FaweClipboard.ClipboardEntity;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
|
|
|
|
import com.boydti.fawe.object.extent.LightingExtent;
|
|
|
|
import com.sk89q.jnbt.CompoundTag;
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2018-08-10 10:29:06 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockState;
|
2018-12-23 16:19:33 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2018-08-10 10:29:06 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
2014-06-30 00:47:08 +00:00
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operation;
|
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;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BaseBiome;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
2019-03-31 16:09:20 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.io.Closeable;
|
2014-06-30 00:47:08 +00:00
|
|
|
import java.util.ArrayList;
|
2014-07-11 05:22:35 +00:00
|
|
|
import java.util.Collections;
|
2014-06-30 00:47:08 +00:00
|
|
|
import java.util.List;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.util.UUID;
|
2018-07-30 13:26:06 +00:00
|
|
|
import javax.annotation.Nullable;
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
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.
|
|
|
|
*/
|
2018-08-12 14:03:07 +00:00
|
|
|
public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable {
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2019-01-09 07:13:44 +00:00
|
|
|
private Region region;
|
|
|
|
private BlockVector3 origin;
|
2018-08-12 14:03:07 +00:00
|
|
|
public FaweClipboard IMP;
|
2019-01-09 07:13:44 +00:00
|
|
|
private BlockVector3 size;
|
2018-08-12 14:03:07 +00:00
|
|
|
private int mx;
|
|
|
|
private int my;
|
|
|
|
private int mz;
|
2019-01-09 07:13:44 +00:00
|
|
|
private BlockStateHolder[][][] blocks;
|
|
|
|
private final List<ClipboardEntity> entities = new ArrayList<>();
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public BlockArrayClipboard(Region region) {
|
|
|
|
checkNotNull(region);
|
|
|
|
this.region = region.clone();
|
|
|
|
this.size = getDimensions();
|
|
|
|
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
|
|
|
|
this.origin = region.getMinimumPoint();
|
|
|
|
this.mx = origin.getBlockX();
|
|
|
|
this.my = origin.getBlockY();
|
|
|
|
this.mz = origin.getBlockZ();
|
2019-01-09 07:13:44 +00:00
|
|
|
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
2018-08-12 14:03:07 +00:00
|
|
|
* <p>
|
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) {
|
|
|
|
checkNotNull(region);
|
|
|
|
this.region = region.clone();
|
|
|
|
this.size = getDimensions();
|
|
|
|
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ(), clipboardId) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
|
|
|
|
this.origin = region.getMinimumPoint();
|
|
|
|
this.mx = origin.getBlockX();
|
|
|
|
this.my = origin.getBlockY();
|
|
|
|
this.mz = origin.getBlockZ();
|
2019-01-09 07:13:44 +00:00
|
|
|
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockArrayClipboard(Region region, FaweClipboard clipboard) {
|
|
|
|
checkNotNull(region);
|
|
|
|
this.region = region.clone();
|
|
|
|
this.size = getDimensions();
|
|
|
|
this.origin = region.getMinimumPoint();
|
|
|
|
this.mx = origin.getBlockX();
|
|
|
|
this.my = origin.getBlockY();
|
|
|
|
this.mz = origin.getBlockZ();
|
|
|
|
this.IMP = clipboard;
|
2019-01-09 07:13:44 +00:00
|
|
|
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void init(Region region, FaweClipboard fc) {
|
2014-06-30 00:47:08 +00:00
|
|
|
checkNotNull(region);
|
2018-08-12 14:03:07 +00:00
|
|
|
checkNotNull(fc);
|
2014-06-30 00:47:08 +00:00
|
|
|
this.region = region.clone();
|
2018-08-12 14:03:07 +00:00
|
|
|
this.size = getDimensions();
|
|
|
|
this.IMP = fc;
|
2014-07-02 09:56:21 +00:00
|
|
|
this.origin = region.getMinimumPoint();
|
2018-08-12 14:03:07 +00:00
|
|
|
this.mx = origin.getBlockX();
|
|
|
|
this.my = origin.getBlockY();
|
|
|
|
this.mz = origin.getBlockZ();
|
2019-01-09 07:13:44 +00:00
|
|
|
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
|
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
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close() {
|
|
|
|
IMP.close();
|
2018-12-27 00:39:10 +00:00
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Region getRegion() {
|
|
|
|
return region.clone();
|
|
|
|
}
|
|
|
|
|
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;
|
2018-08-12 14:03:07 +00:00
|
|
|
IMP.setOrigin(origin.subtract(region.getMinimumPoint()));
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 09:56:21 +00:00
|
|
|
@Override
|
2018-12-23 16:19:33 +00:00
|
|
|
public BlockVector3 getDimensions() {
|
2014-06-30 00:47:08 +00:00
|
|
|
return region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2014-07-11 05:22:35 +00:00
|
|
|
public List<? extends Entity> getEntities(Region region) {
|
2018-12-23 16:19:33 +00:00
|
|
|
List<Entity> filtered = new ArrayList<>();
|
2019-01-09 07:13:44 +00:00
|
|
|
for (Entity entity : getEntities()) {
|
2019-03-31 16:09:20 +00:00
|
|
|
if (region.contains(entity.getLocation().toBlockPoint())) {
|
2014-07-11 05:22:35 +00:00
|
|
|
filtered.add(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableList(filtered);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<? extends Entity> getEntities() {
|
2018-08-12 14:03:07 +00:00
|
|
|
return IMP.getEntities();
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2014-07-10 21:50:40 +00:00
|
|
|
public Entity createEntity(Location location, BaseEntity entity) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return IMP.createEntity(location.getExtent(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), entity);
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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)) {
|
2018-08-12 14:03:07 +00:00
|
|
|
int x = position.getBlockX() - mx;
|
|
|
|
int y = position.getBlockY() - my;
|
|
|
|
int z = position.getBlockZ() - mz;
|
2019-03-25 17:31:12 +00:00
|
|
|
return IMP.getBlock(x, y, z).toImmutableState();
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
return EditSession.nullBlock;
|
|
|
|
}
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public BlockState getBlockAbs(int x, int y, int z) {
|
2019-03-25 17:31:12 +00:00
|
|
|
return IMP.getBlock(x, y, z).toImmutableState();
|
2018-06-18 12:51:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
@Override
|
2019-01-09 07:13:44 +00:00
|
|
|
//<<<<<<< HEAD
|
|
|
|
public BlockState getLazyBlock(BlockVector3 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return getBlock(position);
|
|
|
|
}
|
2019-01-09 07:13:44 +00:00
|
|
|
//=======
|
|
|
|
// public BaseBlock getFullBlock(BlockVector3 position) {
|
|
|
|
// if (region.contains(position)) {
|
|
|
|
// BlockVector3 v = position.subtract(region.getMinimumPoint());
|
|
|
|
// BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
|
|
|
|
// if (block != null) {
|
|
|
|
// return block.toBaseBlock();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
2018-06-18 12:51:21 +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-03-25 17:31:12 +00:00
|
|
|
if(region.contains(position)) {
|
|
|
|
int x = position.getBlockX() - mx;
|
|
|
|
int y = position.getBlockY() - my;
|
|
|
|
int z = position.getBlockZ() - mz;
|
|
|
|
return IMP.getBlock(x, y, z);
|
|
|
|
}
|
|
|
|
return EditSession.nullBlock.toBaseBlock();
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-27 00:39:10 +00:00
|
|
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (region.contains(location)) {
|
|
|
|
final int x = location.getBlockX();
|
|
|
|
final int y = location.getBlockY();
|
|
|
|
final int z = location.getBlockZ();
|
|
|
|
return setBlock(x, y, z, block);
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean setTile(int x, int y, int z, CompoundTag tag) {
|
|
|
|
x -= mx;
|
|
|
|
y -= my;
|
|
|
|
z -= mz;
|
|
|
|
return IMP.setTile(x, y, z, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 {
|
2018-08-12 14:03:07 +00:00
|
|
|
x -= mx;
|
|
|
|
y -= my;
|
|
|
|
z -= mz;
|
|
|
|
return IMP.setBlock(x, y, z, block);
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
2014-07-17 07:21:13 +00:00
|
|
|
@Override
|
2019-01-09 07:13:44 +00:00
|
|
|
public BaseBiome getBiome(BlockVector2 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
int x = position.getBlockX() - mx;
|
|
|
|
int z = position.getBlockZ() - mz;
|
|
|
|
return IMP.getBiome(x, z);
|
2014-07-17 07:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-01-09 07:13:44 +00:00
|
|
|
public boolean setBiome(BlockVector2 position, BaseBiome biome) {
|
2018-08-12 14:03:07 +00:00
|
|
|
int x = position.getBlockX() - mx;
|
|
|
|
int z = position.getBlockZ() - mz;
|
|
|
|
IMP.setBiome(x, z, biome.getId());
|
|
|
|
return true;
|
2014-07-17 07:21:13 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Operation commit() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-08-12 16:36:39 +00:00
|
|
|
|
2014-06-30 00:47:08 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
|
|
|
public int getLight(int x, int y, int z) {
|
|
|
|
return getBlockLight(x, y, z);
|
|
|
|
}
|
2014-07-16 02:47:47 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
|
|
|
public int getSkyLight(int x, int y, int z) {
|
|
|
|
return 0;
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Override
|
|
|
|
public int getBlockLight(int x, int y, int z) {
|
|
|
|
return getBrightness(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOpacity(int x, int y, int z) {
|
2018-10-19 20:13:32 +00:00
|
|
|
return getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().getLightOpacity();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBrightness(int x, int y, int z) {
|
2018-10-19 20:13:32 +00:00
|
|
|
return getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().getLightValue();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|