Current Progress #3

This commit is contained in:
IronApollo
2019-01-09 02:13:44 -05:00
parent d4157b7e0e
commit 842b1307c7
221 changed files with 3173 additions and 3041 deletions

View File

@@ -19,25 +19,20 @@
package com.sk89q.worldedit.extent.clipboard;
<<<<<<< HEAD
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
import com.boydti.fawe.object.clipboard.FaweClipboard;
import com.boydti.fawe.object.clipboard.FaweClipboard.ClipboardEntity;
import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
=======
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEditException;
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.operation.Operation;
@@ -46,11 +41,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
<<<<<<< HEAD
=======
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import java.io.Closeable;
@@ -69,16 +60,16 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable {
<<<<<<< HEAD
private Region region;
private Region region;
private BlockVector3 origin;
public FaweClipboard IMP;
private Vector size;
private BlockVector3 size;
private int mx;
private int my;
private int mz;
private Vector origin;
private MutableBlockVector mutable = new MutableBlockVector();
private BlockStateHolder[][][] blocks;
private final List<ClipboardEntity> entities = new ArrayList<>();
public BlockArrayClipboard(Region region) {
checkNotNull(region);
this.region = region.clone();
@@ -88,13 +79,8 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
=======
private final Region region;
private BlockVector3 origin;
private final BlockStateHolder[][][] blocks;
private final List<ClipboardEntity> entities = new ArrayList<>();
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
/**
* Create a new instance.
@@ -112,9 +98,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
<<<<<<< HEAD
public BlockArrayClipboard(Region region, FaweClipboard clipboard) {
checkNotNull(region);
this.region = region.clone();
@@ -124,6 +110,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.IMP = clipboard;
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
public void init(Region region, FaweClipboard fc) {
@@ -136,6 +123,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
@Override
@@ -146,10 +134,6 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public void close() {
IMP.close();
=======
BlockVector3 dimensions = getDimensions();
blocks = new BlockStateHolder[dimensions.getBlockX()][dimensions.getBlockY()][dimensions.getBlockZ()];
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
@Override
@@ -189,15 +173,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public List<? extends Entity> getEntities(Region region) {
<<<<<<< HEAD
List<Entity> filtered = new ArrayList<Entity>();
for (Entity entity : getEntities()) {
if (region.contains(entity.getLocation().toVector())) {
=======
List<Entity> filtered = new ArrayList<>();
for (Entity entity : entities) {
for (Entity entity : getEntities()) {
if (region.contains(entity.getLocation().toVector().toBlockPoint())) {
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
filtered.add(entity);
}
}
@@ -218,18 +196,18 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BlockState getBlock(BlockVector3 position) {
if (region.contains(position)) {
<<<<<<< HEAD
//<<<<<<< HEAD
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
=======
BlockVector3 v = position.subtract(region.getMinimumPoint());
BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
if (block != null) {
return block.toImmutableState();
}
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
//=======
// BlockVector3 v = position.subtract(region.getMinimumPoint());
// BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
// if (block != null) {
// return block.toImmutableState();
// }
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
return EditSession.nullBlock;
}
@@ -239,43 +217,42 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
}
@Override
<<<<<<< HEAD
public BlockState getLazyBlock(Vector position) {
//<<<<<<< HEAD
public BlockState getLazyBlock(BlockVector3 position) {
return getBlock(position);
}
=======
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
//=======
// 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
@Override
public BlockState getFullBlock(Vector position) {
public BlockState getFullBlock(BlockVector3 position) {
return getLazyBlock(position);
}
@Override
<<<<<<< HEAD
public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException {
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
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);
=======
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
if (region.contains(position)) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = block;
return true;
} else {
return false;
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
//=======
// public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
// if (region.contains(position)) {
// BlockVector3 v = position.subtract(region.getMinimumPoint());
// blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = block;
// return true;
// } else {
// return false;
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
return false;
}
@@ -296,28 +273,18 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
}
@Override
<<<<<<< HEAD
public BaseBiome getBiome(Vector2D position) {
public BaseBiome getBiome(BlockVector2 position) {
int x = position.getBlockX() - mx;
int z = position.getBlockZ() - mz;
return IMP.getBiome(x, z);
}
@Override
public boolean setBiome(Vector2D position, BaseBiome biome) {
public boolean setBiome(BlockVector2 position, BaseBiome biome) {
int x = position.getBlockX() - mx;
int z = position.getBlockZ() - mz;
IMP.setBiome(x, z, biome.getId());
return true;
=======
public BaseBiome getBiome(BlockVector2 position) {
return new BaseBiome(0);
}
@Override
public boolean setBiome(BlockVector2 position, BaseBiome biome) {
return false;
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
@Nullable
@@ -345,17 +312,11 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public int getOpacity(int x, int y, int z) {
mutable.mutX(x);
mutable.mutY(y);
mutable.mutZ(z);
return getBlock(mutable).getBlockType().getMaterial().getLightOpacity();
return getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().getLightOpacity();
}
@Override
public int getBrightness(int x, int y, int z) {
mutable.mutX(x);
mutable.mutY(y);
mutable.mutZ(z);
return getBlock(mutable).getBlockType().getMaterial().getLightValue();
return getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().getLightValue();
}
}

View File

@@ -38,12 +38,12 @@ import com.google.gson.Gson;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
@@ -304,7 +304,7 @@ public enum ClipboardFormat {
// summary
// blocks
HashMap<String, Object> map = new HashMap<String, Object>();
Vector dimensions = clipboard.getDimensions();
BlockVector3 dimensions = clipboard.getDimensions();
map.put("width", dimensions.getX());
map.put("height", dimensions.getY());
map.put("length", dimensions.getZ());

View File

@@ -31,6 +31,7 @@ import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@@ -225,7 +226,7 @@ public class MCEditSchematicReader extends NBTSchematicReader {
try {
if (state != null) {
if (tileEntitiesMap.containsKey(pt)) {
clipboard.setBlock(region.getMinimumPoint().add(pt), state.toBaseBlock(new CompoundTag(tileEntitiesMap.get(pt))));
clipboard.setBlock(region.getMinimumPoint().add(pt), /*state.toBaseBlock(new CompoundTag(tileEntitiesMap.get(pt)))*/new BaseBlock(state, new CompoundTag(tileEntitiesMap.get(pt))));
} else {
clipboard.setBlock(region.getMinimumPoint().add(pt), state);
}

View File

@@ -42,12 +42,7 @@ import com.sk89q.jnbt.NamedTag;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
<<<<<<< HEAD
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
=======
import com.sk89q.worldedit.WorldEdit;
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
@@ -108,68 +103,214 @@ public class SpongeSchematicReader extends NBTSchematicReader {
return read(UUID.randomUUID());
}
<<<<<<< HEAD
@Override
public Clipboard read(UUID uuid) throws IOException {
return readVersion1(uuid);
}
=======
private Clipboard readVersion1(Map<String, Tag> schematic) throws IOException {
BlockVector3 origin;
Region region;
Map<String, Tag> metadata = requireTag(schematic, "Metadata", CompoundTag.class).getValue();
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// private Clipboard readVersion1(Map<String, Tag> schematic) throws IOException {
// BlockVector3 origin;
// Region region;
//
// Map<String, Tag> metadata = requireTag(schematic, "Metadata", CompoundTag.class).getValue();
// }
private int width, height, length;
private int offsetX, offsetY, offsetZ;
private char[] palette;
private Vector min;
private BlockVector3 min;
private FaweClipboard fc;
private FaweClipboard setupClipboard(int size, UUID uuid) {
if (fc != null) {
if (fc.getDimensions().getX() == 0) {
fc.setDimensions(new Vector(size, 1, 1));
fc.setDimensions(new BlockVector3(size, 1, 1));
}
return fc;
}
<<<<<<< HEAD
if (Settings.IMP.CLIPBOARD.USE_DISK) {
return fc = new DiskOptimizedClipboard(size, 1, 1, uuid);
} else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) {
return fc = new CPUOptimizedClipboard(size, 1, 1);
} else {
return fc = new MemoryOptimizedClipboard(size, 1, 1);
=======
BlockVector3 min = new BlockVector3(offsetParts[0], offsetParts[1], offsetParts[2]);
if (metadata.containsKey("WEOffsetX")) {
// We appear to have WorldEdit Metadata
int offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue();
int offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue();
int offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue();
BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ);
origin = min.subtract(offset);
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
} else {
origin = min;
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
}
int paletteMax = requireTag(schematic, "PaletteMax", IntTag.class).getValue();
Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue();
if (paletteObject.size() != paletteMax) {
throw new IOException("Differing given palette size to actual size");
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
}
// BlockVector3 min = new BlockVector3(offsetParts[0], offsetParts[1], offsetParts[2]);
//
// if (metadata.containsKey("WEOffsetX")) {
// // We appear to have WorldEdit Metadata
// int offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue();
// int offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue();
// int offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue();
// BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ);
// origin = min.subtract(offset);
// region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
// } else {
// origin = min;
// region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
// }
//
// int paletteMax = requireTag(schematic, "PaletteMax", IntTag.class).getValue();
// Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue();
// if (paletteObject.size() != paletteMax) {
// throw new IOException("Differing given palette size to actual size");
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// private Clipboard readVersion1(UUID uuid) throws IOException {
// width = height = length = offsetX = offsetY = offsetZ = Integer.MIN_VALUE;
//
// final BlockArrayClipboard clipboard = new BlockArrayClipboard(new CuboidRegion(new Vector(0, 0, 0), new Vector(0, 0, 0)), fc);
// FastByteArrayOutputStream blocksOut = new FastByteArrayOutputStream();
// FastByteArrayOutputStream biomesOut = new FastByteArrayOutputStream();
//
// NBTStreamer streamer = new NBTStreamer(inputStream);
// streamer.addReader("Schematic.Width", (BiConsumer<Integer, Short>) (i, v) -> width = v);
// streamer.addReader("Schematic.Height", (BiConsumer<Integer, Short>) (i, v) -> height = v);
// streamer.addReader("Schematic.Length", (BiConsumer<Integer, Short>) (i, v) -> length = v);
// streamer.addReader("Schematic.Offset", (BiConsumer<Integer, int[]>) (i, v) -> min = new BlockVector(v[0], v[1], v[2]));
// streamer.addReader("Schematic.Metadata.WEOffsetX", (BiConsumer<Integer, Integer>) (i, v) -> offsetX = v);
// streamer.addReader("Schematic.Metadata.WEOffsetY", (BiConsumer<Integer, Integer>) (i, v) -> offsetY = v);
// streamer.addReader("Schematic.Metadata.WEOffsetZ", (BiConsumer<Integer, Integer>) (i, v) -> offsetZ = v);
// streamer.addReader("Schematic.Palette", (BiConsumer<Integer, HashMap<String, Tag>>) (i, v) -> {
// palette = new char[v.size()];
// for (Map.Entry<String, Tag> entry : v.entrySet()) {
// BlockState state = BlockState.get(entry.getKey());
// int index = ((IntTag) entry.getValue()).getValue();
// palette[index] = (char) state.getOrdinal();
// }
//<<<<<<< HEAD
// });
// streamer.addReader("Schematic.BlockData.#", new NBTStreamer.LazyReader() {
// @Override
// public void accept(Integer arrayLen, DataInputStream dis) {
// try (FaweOutputStream blocks = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut))) {
// IOUtil.copy(dis, blocks, arrayLen);
// } catch (IOException e) {
// e.printStackTrace();
// }
//=======
// palette.put(id, state);
// }
//
// byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue();
//
// Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
// try {
// List<Map<String, Tag>> tileEntityTags = requireTag(schematic, "TileEntities", ListTag.class).getValue().stream()
// .map(tag -> (CompoundTag) tag)
// .map(CompoundTag::getValue)
// .collect(Collectors.toList());
//
// for (Map<String, Tag> tileEntity : tileEntityTags) {
// int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
// tileEntitiesMap.put(new BlockVector3(pos[0], pos[1], pos[2]), tileEntity);
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// }
// });
// streamer.addReader("Schematic.Biomes.#", new NBTStreamer.LazyReader() {
// @Override
// public void accept(Integer arrayLen, DataInputStream dis) {
// try (FaweOutputStream biomes = new FaweOutputStream(new LZ4BlockOutputStream(biomesOut))) {
// IOUtil.copy(dis, biomes, arrayLen);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// });
// streamer.addReader("Schematic.TileEntities.#", new BiConsumer<Integer, CompoundTag>() {
// @Override
// public void accept(Integer index, CompoundTag value) {
// if (fc == null) {
// setupClipboard(0, uuid);
// }
// int[] pos = value.getIntArray("Pos");
// int x = pos[0];
// int y = pos[1];
// int z = pos[2];
// fc.setTile(x, y, z, value);
// }
// });
// streamer.addReader("Schematic.Entities.#", new BiConsumer<Integer, CompoundTag>() {
// @Override
// public void accept(Integer index, CompoundTag compound) {
// if (fc == null) {
// setupClipboard(0, uuid);
// }
// String id = compound.getString("id");
// if (id.isEmpty()) {
// return;
// }
// ListTag positionTag = compound.getListTag("Pos");
// ListTag directionTag = compound.getListTag("Rotation");
// EntityType type = EntityTypes.parse(id);
// if (type != null) {
// compound.getValue().put("Id", new StringTag(type.getId()));
// BaseEntity state = new BaseEntity(type, compound);
// fc.createEntity(clipboard, positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), (float) directionTag.asDouble(0), (float) directionTag.asDouble(1), state);
// } else {
// Fawe.debug("Invalid entity: " + id);
// }
// }
//<<<<<<< HEAD
// });
// streamer.readFully();
// if (fc == null) setupClipboard(length * width * height, uuid);
// Vector origin = min;
// CuboidRegion region;
// if (offsetX != Integer.MIN_VALUE && offsetY != Integer.MIN_VALUE && offsetZ != Integer.MIN_VALUE) {
// origin = origin.subtract(new Vector(offsetX, offsetY, offsetZ));
// region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE));
// } else {
// region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE));
// }
// if (blocksOut.getSize() != 0) {
// try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(blocksOut.toByteArrays())))) {
// int volume = width * height * length;
// if (palette.length < 128) {
// for (int index = 0; index < volume; index++) {
// BlockState state = BlockTypes.states[palette[fis.read()]];
// fc.setBlock(index, state);
//=======
// // index = (y * length + z) * width + x
// int y = index / (width * length);
// int z = (index % (width * length)) / width;
// int x = (index % (width * length)) % width;
// BlockState state = palette.get(value);
// BlockVector3 pt = new BlockVector3(x, y, z);
// try {
// if (tileEntitiesMap.containsKey(pt)) {
// Map<String, Tag> values = Maps.newHashMap(tileEntitiesMap.get(pt));
// for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) {
// if (handler.isAffectedBlock(state)) {
// handler.updateNBT(state, values);
// }
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
// }
// } else {
// for (int index = 0; index < volume; index++) {
// BlockState state = BlockTypes.states[palette[fis.readVarInt()]];
// fc.setBlock(index, state);
// }
// }
// }
// }
// if (biomesOut.getSize() != 0) {
// try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(biomesOut.toByteArrays())))) {
// int volume = width * length;
// for (int index = 0; index < volume; index++) {
// fc.setBiome(index, fis.read());
// }
// }
// }
// fc.setDimensions(new Vector(width, height, length));
// clipboard.init(region, fc);
// clipboard.setOrigin(origin);
// return clipboard;
// }
private Clipboard readVersion1(UUID uuid) throws IOException {
width = height = length = offsetX = offsetY = offsetZ = Integer.MIN_VALUE;
final BlockArrayClipboard clipboard = new BlockArrayClipboard(new CuboidRegion(new Vector(0, 0, 0), new Vector(0, 0, 0)), fc);
final BlockArrayClipboard clipboard = new BlockArrayClipboard(new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(0, 0, 0)), fc);
FastByteArrayOutputStream blocksOut = new FastByteArrayOutputStream();
FastByteArrayOutputStream biomesOut = new FastByteArrayOutputStream();
@@ -177,7 +318,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
streamer.addReader("Schematic.Width", (BiConsumer<Integer, Short>) (i, v) -> width = v);
streamer.addReader("Schematic.Height", (BiConsumer<Integer, Short>) (i, v) -> height = v);
streamer.addReader("Schematic.Length", (BiConsumer<Integer, Short>) (i, v) -> length = v);
streamer.addReader("Schematic.Offset", (BiConsumer<Integer, int[]>) (i, v) -> min = new BlockVector(v[0], v[1], v[2]));
streamer.addReader("Schematic.Offset", (BiConsumer<Integer, int[]>) (i, v) -> min = new BlockVector3(v[0], v[1], v[2]));
streamer.addReader("Schematic.Metadata.WEOffsetX", (BiConsumer<Integer, Integer>) (i, v) -> offsetX = v);
streamer.addReader("Schematic.Metadata.WEOffsetY", (BiConsumer<Integer, Integer>) (i, v) -> offsetY = v);
streamer.addReader("Schematic.Metadata.WEOffsetZ", (BiConsumer<Integer, Integer>) (i, v) -> offsetZ = v);
@@ -188,7 +329,6 @@ public class SpongeSchematicReader extends NBTSchematicReader {
int index = ((IntTag) entry.getValue()).getValue();
palette[index] = (char) state.getOrdinal();
}
<<<<<<< HEAD
});
streamer.addReader("Schematic.BlockData.#", new NBTStreamer.LazyReader() {
@Override
@@ -198,23 +338,6 @@ public class SpongeSchematicReader extends NBTSchematicReader {
} catch (IOException e) {
e.printStackTrace();
}
=======
palette.put(id, state);
}
byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue();
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
try {
List<Map<String, Tag>> tileEntityTags = requireTag(schematic, "TileEntities", ListTag.class).getValue().stream()
.map(tag -> (CompoundTag) tag)
.map(CompoundTag::getValue)
.collect(Collectors.toList());
for (Map<String, Tag> tileEntity : tileEntityTags) {
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
tileEntitiesMap.put(new BlockVector3(pos[0], pos[1], pos[2]), tileEntity);
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
});
streamer.addReader("Schematic.Biomes.#", new NBTStreamer.LazyReader() {
@@ -261,17 +384,16 @@ public class SpongeSchematicReader extends NBTSchematicReader {
Fawe.debug("Invalid entity: " + id);
}
}
<<<<<<< HEAD
});
streamer.readFully();
if (fc == null) setupClipboard(length * width * height, uuid);
Vector origin = min;
BlockVector3 origin = min;
CuboidRegion region;
if (offsetX != Integer.MIN_VALUE && offsetY != Integer.MIN_VALUE && offsetZ != Integer.MIN_VALUE) {
origin = origin.subtract(new Vector(offsetX, offsetY, offsetZ));
region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE));
origin = origin.subtract(new BlockVector3(offsetX, offsetY, offsetZ));
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
} else {
region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE));
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
}
if (blocksOut.getSize() != 0) {
try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(blocksOut.toByteArrays())))) {
@@ -280,21 +402,6 @@ public class SpongeSchematicReader extends NBTSchematicReader {
for (int index = 0; index < volume; index++) {
BlockState state = BlockTypes.states[palette[fis.read()]];
fc.setBlock(index, state);
=======
// index = (y * length + z) * width + x
int y = index / (width * length);
int z = (index % (width * length)) / width;
int x = (index % (width * length)) % width;
BlockState state = palette.get(value);
BlockVector3 pt = new BlockVector3(x, y, z);
try {
if (tileEntitiesMap.containsKey(pt)) {
Map<String, Tag> values = Maps.newHashMap(tileEntitiesMap.get(pt));
for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) {
if (handler.isAffectedBlock(state)) {
handler.updateNBT(state, values);
}
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
} else {
for (int index = 0; index < volume; index++) {
@@ -312,12 +419,13 @@ public class SpongeSchematicReader extends NBTSchematicReader {
}
}
}
fc.setDimensions(new Vector(width, height, length));
fc.setDimensions(new BlockVector3(width, height, length));
clipboard.init(region, fc);
clipboard.setOrigin(origin);
return clipboard;
}
@Override
public void close() throws IOException {
inputStream.close();

View File

@@ -27,23 +27,14 @@ import com.sk89q.jnbt.NBTConstants;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
<<<<<<< HEAD
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
=======
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
<<<<<<< HEAD
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
=======
import com.sk89q.worldedit.world.block.BaseBlock;
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -83,15 +74,9 @@ public class SpongeSchematicWriter implements ClipboardWriter {
public void write1(Clipboard clipboard) throws IOException {
// metadata
Region region = clipboard.getRegion();
<<<<<<< HEAD
Vector origin = clipboard.getOrigin();
BlockVector min = region.getMinimumPoint().toBlockVector();
Vector offset = min.subtract(origin);
=======
BlockVector3 origin = clipboard.getOrigin();
BlockVector3 min = region.getMinimumPoint();
BlockVector3 offset = min.subtract(origin);
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
int width = region.getWidth();
int height = region.getHeight();
int length = region.getLength();
@@ -104,7 +89,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
if (length > MAX_SIZE) {
throw new IllegalArgumentException("Length of region too large for a .schematic");
}
<<<<<<< HEAD
//<<<<<<< HEAD
// output
final DataOutput rawStream = outputStream.getOutputStream();
outputStream.writeLazyCompoundTag("Schematic", out -> {
@@ -157,49 +142,49 @@ public class SpongeSchematicWriter implements ClipboardWriter {
}));
numTiles[0]++;
tilesOut.writeTagPayload(tile);
=======
Map<String, Tag> schematic = new HashMap<>();
schematic.put("Version", new IntTag(1));
Map<String, Tag> metadata = new HashMap<>();
metadata.put("WEOffsetX", new IntTag(offset.getBlockX()));
metadata.put("WEOffsetY", new IntTag(offset.getBlockY()));
metadata.put("WEOffsetZ", new IntTag(offset.getBlockZ()));
schematic.put("Metadata", new CompoundTag(metadata));
schematic.put("Width", new ShortTag((short) width));
schematic.put("Height", new ShortTag((short) height));
schematic.put("Length", new ShortTag((short) length));
// The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
schematic.put("Offset", new IntArrayTag(new int[]{
min.getBlockX(),
min.getBlockY(),
min.getBlockZ(),
}));
int paletteMax = 0;
Map<String, Integer> palette = new HashMap<>();
List<CompoundTag> tileEntities = new ArrayList<>();
ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
for (int y = 0; y < height; y++) {
int y0 = min.getBlockY() + y;
for (int z = 0; z < length; z++) {
int z0 = min.getBlockZ() + z;
for (int x = 0; x < width; x++) {
int x0 = min.getBlockX() + x;
BlockVector3 point = new BlockVector3(x0, y0, z0);
BaseBlock block = clipboard.getFullBlock(point);
if (block.getNbtData() != null) {
Map<String, Tag> values = new HashMap<>();
for (Map.Entry<String, Tag> entry : block.getNbtData().getValue().entrySet()) {
values.put(entry.getKey(), entry.getValue());
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
//=======
//
// Map<String, Tag> schematic = new HashMap<>();
// schematic.put("Version", new IntTag(1));
//
// Map<String, Tag> metadata = new HashMap<>();
// metadata.put("WEOffsetX", new IntTag(offset.getBlockX()));
// metadata.put("WEOffsetY", new IntTag(offset.getBlockY()));
// metadata.put("WEOffsetZ", new IntTag(offset.getBlockZ()));
//
// schematic.put("Metadata", new CompoundTag(metadata));
//
// schematic.put("Width", new ShortTag((short) width));
// schematic.put("Height", new ShortTag((short) height));
// schematic.put("Length", new ShortTag((short) length));
//
// // The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
// schematic.put("Offset", new IntArrayTag(new int[]{
// min.getBlockX(),
// min.getBlockY(),
// min.getBlockZ(),
// }));
//
// int paletteMax = 0;
// Map<String, Integer> palette = new HashMap<>();
//
// List<CompoundTag> tileEntities = new ArrayList<>();
//
// ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
//
// for (int y = 0; y < height; y++) {
// int y0 = min.getBlockY() + y;
// for (int z = 0; z < length; z++) {
// int z0 = min.getBlockZ() + z;
// for (int x = 0; x < width; x++) {
// int x0 = min.getBlockX() + x;
// BlockVector3 point = new BlockVector3(x0, y0, z0);
// BaseBlock block = clipboard.getFullBlock(point);
// if (block.getNbtData() != null) {
// Map<String, Tag> values = new HashMap<>();
// for (Map.Entry<String, Tag> entry : block.getNbtData().getValue().entrySet()) {
// values.put(entry.getKey(), entry.getValue());
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
int ordinal = block.getOrdinal();
char value = palette[ordinal];
@@ -221,7 +206,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
if (clipboard instanceof BlockArrayClipboard) {
((BlockArrayClipboard) clipboard).IMP.forEach(reader, true);
} else {
for (Vector pt : region) {
for (BlockVector3 pt : region) {
BlockState block = clipboard.getBlock(pt);
int x = pt.getBlockX() - min.getBlockX();
int y = pt.getBlockY() - min.getBlockY();