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;
|
2019-06-27 00:14:00 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
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;
|
|
|
|
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;
|
2019-06-04 15:48:30 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2019-06-27 00:14:00 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
2019-06-04 15:48:30 +00:00
|
|
|
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-03-31 16:09:20 +00:00
|
|
|
|
2019-06-04 15:48:30 +00:00
|
|
|
import javax.annotation.Nullable;
|
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;
|
|
|
|
|
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;
|
2019-06-27 00:14:00 +00:00
|
|
|
private BaseBlock[][][] blocks;
|
|
|
|
private BiomeType[][] biomes = null;
|
2018-08-12 14:03:07 +00:00
|
|
|
public FaweClipboard IMP;
|
2019-01-09 07:13:44 +00:00
|
|
|
private BlockVector3 size;
|
|
|
|
private final List<ClipboardEntity> entities = new ArrayList<>();
|
2019-06-04 15:48:30 +00:00
|
|
|
|
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();
|
2019-06-27 00:14:00 +00:00
|
|
|
this.blocks = new BaseBlock[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.
|
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) {
|
|
|
|
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();
|
2019-06-27 00:14:00 +00:00
|
|
|
this.blocks = new BaseBlock[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.IMP = clipboard;
|
2019-06-27 00:14:00 +00:00
|
|
|
this.blocks = new BaseBlock[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();
|
2019-06-27 00:14:00 +00:00
|
|
|
this.blocks = new BaseBlock[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() {
|
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;
|
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-06-27 00:14:00 +00:00
|
|
|
if (region.contains(entity.getLocation().toVector().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)) {
|
2019-06-04 15:48:30 +00:00
|
|
|
BlockVector3 v = position.subtract(region.getMinimumPoint());
|
|
|
|
return IMP.getBlock(v.getX(),v.getY(),v.getZ()).toImmutableState();
|
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
|
|
|
|
|
|
|
@Override
|
2019-01-09 07:13:44 +00:00
|
|
|
public BlockState getLazyBlock(BlockVector3 position) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return getBlock(position);
|
|
|
|
}
|
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-06-04 15:48:30 +00:00
|
|
|
if (region.contains(position)) {
|
|
|
|
BlockVector3 v = position.subtract(region.getMinimumPoint());
|
|
|
|
return IMP.getBlock(v.getX(),v.getY(),v.getZ());
|
2019-03-25 17:31:12 +00:00
|
|
|
}
|
2019-06-04 15:48:30 +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-06-04 15:48:30 +00:00
|
|
|
public boolean setTile(BlockVector3 position, CompoundTag tag) {
|
|
|
|
BlockVector3 v = position.subtract(region.getMinimumPoint());
|
|
|
|
return IMP.setTile(v.getX(), v.getY(), v.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-06-04 15:48:30 +00:00
|
|
|
BlockVector3 position = BlockVector3.at(x, y, z);
|
|
|
|
BlockVector3 v = position.subtract(region.getMinimumPoint());
|
|
|
|
return IMP.setBlock(v.getX(), v.getY(), v.getZ(), block);
|
2014-06-30 00:47:08 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 00:14:00 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasBiomes() {
|
|
|
|
return biomes != null;
|
|
|
|
}
|
|
|
|
|
2014-07-17 07:21:13 +00:00
|
|
|
@Override
|
2019-02-16 07:27:00 +00:00
|
|
|
public BiomeType getBiome(BlockVector2 position) {
|
2019-06-27 00:14:00 +00:00
|
|
|
if (biomes != null
|
|
|
|
&& position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) {
|
|
|
|
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
|
|
|
|
BiomeType biomeType = biomes[v.getBlockX()][v.getBlockZ()];
|
|
|
|
if (biomeType != null) {
|
|
|
|
return IMP.getBiome(v.getX(), v.getZ());
|
|
|
|
//TODO Remove the line above and replace with this: return biomeType;
|
|
|
|
}
|
|
|
|
return IMP.getBiome(v.getX(), v.getZ());
|
|
|
|
}
|
|
|
|
return BiomeTypes.OCEAN;
|
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-06-27 00:14:00 +00:00
|
|
|
if (position.containedWithin(getMinimumPoint().toBlockVector2(), getMaximumPoint().toBlockVector2())) {
|
|
|
|
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
|
|
|
|
IMP.setBiome(v.getX(), v.getZ(), biome);
|
|
|
|
if (biomes == null) {
|
|
|
|
biomes = new BiomeType[region.getWidth()][region.getLength()];
|
|
|
|
}
|
|
|
|
biomes[v.getBlockX()][v.getBlockZ()] = biome;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
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
|
|
|
}
|
2019-06-04 15:48:30 +00:00
|
|
|
}
|