schem v2 biomes

Dieser Commit ist enthalten in:
Jesse Boyd 2019-11-01 22:09:50 +01:00
Ursprung 49c51e041c
Commit 88b6d60f8e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
7 geänderte Dateien mit 383 neuen und 351 gelöschten Zeilen

Datei anzeigen

@ -113,7 +113,7 @@ public class MCAChunk implements IChunkSet {
section.blocksLength = -1; section.blocksLength = -1;
}); });
layer.add("Y").withInt((i, y) -> section.layer = y); layer.add("Y").withInt((i, y) -> section.layer = y);
layer.add("Palette").withValue((ValueReader<Map<String, Object>>) (index, map) -> { layer.add("Palette").withElem((ValueReader<Map<String, Object>>) (index, map) -> {
String name = (String) map.get("Name"); String name = (String) map.get("Name");
BlockType type = BlockTypes.get(name); BlockType type = BlockTypes.get(name);
BlockState state = type.getDefaultState(); BlockState state = type.getDefaultState();
@ -137,14 +137,14 @@ public class MCAChunk implements IChunkSet {
section.blocksLength = length; section.blocksLength = length;
}); });
blockStates.withLong((index, value) -> section.blocks[index] = value); blockStates.withLong((index, value) -> section.blocks[index] = value);
level.add("TileEntities").withValue((ValueReader<Map<String, Object>>) (index, value) -> { level.add("TileEntities").withElem((ValueReader<Map<String, Object>>) (index, value) -> {
CompoundTag tile = FaweCache.IMP.asTag(value); CompoundTag tile = FaweCache.IMP.asTag(value);
int x = tile.getInt("x") & 15; int x = tile.getInt("x") & 15;
int y = tile.getInt("y"); int y = tile.getInt("y");
int z = tile.getInt("z") & 15; int z = tile.getInt("z") & 15;
tiles.put(x, y, z, tile); tiles.put(x, y, z, tile);
}); });
level.add("Entities").withValue((ValueReader<Map<String, Object>>) (index, value) -> { level.add("Entities").withElem((ValueReader<Map<String, Object>>) (index, value) -> {
CompoundTag entity = FaweCache.IMP.asTag(value); CompoundTag entity = FaweCache.IMP.asTag(value);
entities.put(entity.getUUID(), entity); entities.put(entity.getUUID(), entity);
}); });

Datei anzeigen

@ -1,5 +0,0 @@
package com.boydti.fawe.jnbt.streamer;
public interface ElemReader<T> extends StreamReader<T> {
void apply(int index, T value);
}

Datei anzeigen

@ -15,7 +15,7 @@ public class StreamDelegate {
private StreamDelegate[] values; private StreamDelegate[] values;
private LazyReader lazyReader; private LazyReader lazyReader;
private ElemReader elemReader; private ValueReader elemReader;
private InfoReader infoReader; private InfoReader infoReader;
private ValueReader valueReader; private ValueReader valueReader;
@ -176,7 +176,7 @@ public class StreamDelegate {
return this; return this;
} }
public StreamDelegate withElem(ElemReader elemReader) { public StreamDelegate withElem(ValueReader elemReader) {
this.elemReader = elemReader; this.elemReader = elemReader;
return this; return this;
} }
@ -204,7 +204,7 @@ public class StreamDelegate {
return valueReader; return valueReader;
} }
public ElemReader getElemReader() { public ValueReader getElemReader() {
return elemReader; return elemReader;
} }

Datei anzeigen

@ -0,0 +1,28 @@
package com.boydti.fawe.object.clipboard;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import java.util.function.BiFunction;
public class LinearClipboardBuilder {
FastByteArrayOutputStream blocksOut = new FastByteArrayOutputStream();
FastByteArrayOutputStream biomesOut = new FastByteArrayOutputStream();
public int width, height, length;
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setLength(int length) {
this.length = length;
}
public LinearClipboard build() {
return null;
}
}

Datei anzeigen

@ -23,7 +23,6 @@ public class ResizableClipboardBuilder extends MemoryOptimizedHistory {
private int maxY = Integer.MIN_VALUE; private int maxY = Integer.MIN_VALUE;
private int maxZ = Integer.MIN_VALUE; private int maxZ = Integer.MIN_VALUE;
public ResizableClipboardBuilder(World world) { public ResizableClipboardBuilder(World world) {
super(world); super(world);
} }

Datei anzeigen

@ -19,7 +19,6 @@
package com.sk89q.jnbt; package com.sk89q.jnbt;
import com.boydti.fawe.jnbt.streamer.ElemReader;
import com.boydti.fawe.jnbt.streamer.StreamDelegate; import com.boydti.fawe.jnbt.streamer.StreamDelegate;
import com.boydti.fawe.jnbt.streamer.ValueReader; import com.boydti.fawe.jnbt.streamer.ValueReader;
@ -27,6 +26,7 @@ import java.io.Closeable;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -247,11 +247,82 @@ public final class NBTInputStream implements Closeable {
} }
return; return;
} }
case NBTConstants.TYPE_LIST: {
int childType = is.readByte();
int length = is.readInt();
StreamDelegate child;
scope.acceptInfo(length, childType);
ValueReader valueReader = scope.getValueReader();
if (valueReader != null) {
List<Object> tagList = readListRaw(depth, childType, length);
valueReader.apply(0, tagList);
return;
}
valueReader = scope.getElemReader();
if (valueReader != null) {
for (int i = 0; i < length; ++i) {
valueReader.apply(i, readTagPayloadRaw(childType, depth + 1));
}
return;
}
child = scope.get0();
if (child == null) {
for (int i = 0; i < length; ++i) {
readTagPaylodLazy(childType, depth + 1);
}
} else {
for (int i = 0; i < length; ++i) {
readTagPaylodLazy(childType, depth + 1, child);
}
}
return;
}
case NBTConstants.TYPE_COMPOUND: {
// readDataPayload
scope.acceptInfo(-1, NBTConstants.TYPE_BYTE);
ValueReader valueReader = scope.getValueReader();
if (valueReader != null) {
valueReader.apply(0, this.readTagPayloadRaw(type, depth));
return;
}
valueReader = scope.getElemReader();
if (valueReader != null) {
for (int i = 0; ; i++) {
int childType = is.readByte();
if (childType == NBTConstants.TYPE_END) {
return;
}
String key = readNamedTagName(childType);
Object value = readTagPayloadRaw(childType, depth + 1);
AbstractMap.SimpleEntry<String, Object> entry = new AbstractMap.SimpleEntry<>(key, value);
valueReader.apply(i, entry);
}
}
while(true) {
int childType = is.readByte();
if (childType == NBTConstants.TYPE_END) {
return;
}
StreamDelegate child = scope.get(is);
if (child == null) {
readTagPaylodLazy(childType, depth + 1);
} else {
readTagPaylodLazy(childType, depth + 1, child);
}
}
}
case NBTConstants.TYPE_BYTE_ARRAY: { case NBTConstants.TYPE_BYTE_ARRAY: {
int length = is.readInt(); int length = is.readInt();
scope.acceptInfo(length, NBTConstants.TYPE_BYTE); scope.acceptInfo(length, NBTConstants.TYPE_BYTE);
if (scope.acceptLazy(length, this)) return; if (scope.acceptLazy(length, this)) return;
ValueReader valueReader = scope.getValueReader(); ValueReader valueReader = scope.getValueReader();
if (valueReader != null) {
byte[] arr = new byte[length];
is.readFully(arr);
valueReader.apply(0, arr);
return;
}
valueReader = scope.getElemReader();
if (valueReader != null) { if (valueReader != null) {
int i = 0; int i = 0;
DataInputStream dis = is; DataInputStream dis = is;
@ -275,69 +346,16 @@ public final class NBTInputStream implements Closeable {
is.skipBytes(length); is.skipBytes(length);
return; return;
} }
case NBTConstants.TYPE_LIST: {
int childType = is.readByte();
int length = is.readInt();
StreamDelegate child;
scope.acceptInfo(length, childType);
ValueReader valueReader = scope.getValueReader();
if (valueReader != null) {
for (int i = 0; i < length; ++i) {
valueReader.apply(i, readTagPayloadRaw(childType, depth + 1));
}
return;
}
child = scope.get0();
if (child == null) {
for (int i = 0; i < length; ++i) {
readTagPaylodLazy(childType, depth + 1);
}
} else {
for (int i = 0; i < length; ++i) {
readTagPaylodLazy(childType, depth + 1, child);
}
}
return;
}
case NBTConstants.TYPE_COMPOUND: {
// readDataPayload
depth++;
scope.acceptInfo(-1, NBTConstants.TYPE_BYTE);
ValueReader valueReader = scope.getValueReader();
if (valueReader != null) {
valueReader.apply(0, this.readDataPayload(type, depth));
return;
}
ElemReader elem = scope.getElemReader();
if (elem != null) {
for (int i = 0; ; i++) {
int childType = is.readByte();
if (childType == NBTConstants.TYPE_END) {
return;
}
is.skipBytes(is.readShort() & 0xFFFF);
Object child = readTagPayloadRaw(childType, depth);
elem.apply(i, child);
}
}
while(true) {
int childType = is.readByte();
if (childType == NBTConstants.TYPE_END) {
return;
}
StreamDelegate child = scope.get(is);
if (child == null) {
readTagPaylodLazy(childType, depth + 1);
} else {
readTagPaylodLazy(childType, depth + 1, child);
}
}
}
case NBTConstants.TYPE_INT_ARRAY: { case NBTConstants.TYPE_INT_ARRAY: {
int length = is.readInt(); int length = is.readInt();
scope.acceptInfo(length, NBTConstants.TYPE_INT); scope.acceptInfo(length, NBTConstants.TYPE_INT);
if (scope.acceptLazy(length, this)) return; if (scope.acceptLazy(length, this)) return;
ValueReader valueReader = scope.getValueReader(); ValueReader valueReader = scope.getValueReader();
if (valueReader != null) {
valueReader.apply(0, readIntArrayRaw(length));
return;
}
valueReader = scope.getElemReader();
if (valueReader != null) { if (valueReader != null) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
valueReader.applyInt(i, is.readInt()); valueReader.applyInt(i, is.readInt());
@ -352,6 +370,11 @@ public final class NBTInputStream implements Closeable {
scope.acceptInfo(length, NBTConstants.TYPE_LONG); scope.acceptInfo(length, NBTConstants.TYPE_LONG);
if (scope.acceptLazy(length, this)) return; if (scope.acceptLazy(length, this)) return;
ValueReader valueReader = scope.getValueReader(); ValueReader valueReader = scope.getValueReader();
if (valueReader != null) {
valueReader.apply(0, readLongArrayRaw(length));
return;
}
valueReader = scope.getElemReader();
if (valueReader != null) { if (valueReader != null) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
valueReader.applyLong(i, is.readLong()); valueReader.applyLong(i, is.readLong());
@ -367,6 +390,18 @@ public final class NBTInputStream implements Closeable {
} }
} }
private List<Object> readListRaw(int depth, int childType, int length) throws IOException {
List<Object> tagList = new ArrayList<>(length);
for (int i = 0; i < length; ++i) {
Object tag = readTagPayloadRaw(childType, depth + 1);
if (tag == null) {
throw new IOException("TAG_End not permitted in a list.");
}
tagList.add(tag);
}
return tagList;
}
public static int getSize(int type) { public static int getSize(int type) {
switch (type) { switch (type) {
default: default:
@ -424,15 +459,7 @@ public final class NBTInputStream implements Closeable {
case NBTConstants.TYPE_LIST: { case NBTConstants.TYPE_LIST: {
int childType = is.readByte(); int childType = is.readByte();
length = is.readInt(); length = is.readInt();
List<Object> tagList = new ArrayList<>(length); return readListRaw(depth, childType, length);
for (int i = 0; i < length; ++i) {
Object tag = readTagPayloadRaw(childType, depth + 1);
if (tag == null) {
throw new IOException("TAG_End not permitted in a list.");
}
tagList.add(tag);
}
return (tagList);
} }
case NBTConstants.TYPE_COMPOUND: { case NBTConstants.TYPE_COMPOUND: {
Map<String, Object> tagMap = new HashMap<>(); Map<String, Object> tagMap = new HashMap<>();
@ -448,43 +475,51 @@ public final class NBTInputStream implements Closeable {
} }
case NBTConstants.TYPE_INT_ARRAY: { case NBTConstants.TYPE_INT_ARRAY: {
length = is.readInt(); length = is.readInt();
int[] data = new int[length]; return readIntArrayRaw(length);
if (buf == null) {
buf = new byte[1024];
}
int index = 0;
while (length > 0) {
int toRead = Math.min(length << 2, buf.length);
is.readFully(buf, 0, toRead);
for (int i = 0; i < toRead; i += 4, index++) {
data[index] = ((buf[i] & 0xFF) << 24) + ((buf[i + 1] & 0xFF) << 16) + ((buf[i + 2] & 0xFF) << 8) + (buf[i + 3] & 0xFF);
}
length -= toRead;
}
return (data);
} }
case NBTConstants.TYPE_LONG_ARRAY: { case NBTConstants.TYPE_LONG_ARRAY: {
length = is.readInt(); length = is.readInt();
long[] data = new long[length]; return readLongArrayRaw(length);
if (buf == null) {
buf = new byte[1024];
}
int index = 0;
while (length > 0) {
int toRead = Math.min(length << 3, buf.length);
is.readFully(buf, 0, toRead);
for (int i = 0; i < toRead; i += 8, index++) {
data[index] = (((long) buf[i] << 56) | ((long) (buf[i + 1] & 255) << 48) | ((long) (buf[i + 2] & 255) << 40) | ((long) (buf[i + 3] & 255) << 32) | ((long) (buf[i + 4] & 255) << 24) | ((buf[i + 5] & 255) << 16) | ((buf[i + 6] & 255) << 8) | (buf[i + 7] & 255));
}
length -= toRead;
}
return (data);
} }
default: default:
throw new IOException("Invalid tag type: " + type + "."); throw new IOException("Invalid tag type: " + type + ".");
} }
} }
private int[] readIntArrayRaw(int length) throws IOException {
int[] data = new int[length];
if (buf == null) {
buf = new byte[1024];
}
int index = 0;
while (length > 0) {
int toRead = Math.min(length << 2, buf.length);
is.readFully(buf, 0, toRead);
for (int i = 0; i < toRead; i += 4, index++) {
data[index] = ((buf[i] & 0xFF) << 24) + ((buf[i + 1] & 0xFF) << 16) + ((buf[i + 2] & 0xFF) << 8) + (buf[i + 3] & 0xFF);
}
length -= toRead;
}
return data;
}
private long[] readLongArrayRaw(int length) throws IOException {
long[] data = new long[length];
if (buf == null) {
buf = new byte[1024];
}
int index = 0;
while (length > 0) {
int toRead = Math.min(length << 3, buf.length);
is.readFully(buf, 0, toRead);
for (int i = 0; i < toRead; i += 8, index++) {
data[index] = (((long) buf[i] << 56) | ((long) (buf[i + 1] & 255) << 48) | ((long) (buf[i + 2] & 255) << 40) | ((long) (buf[i + 3] & 255) << 32) | ((long) (buf[i + 4] & 255) << 24) | ((buf[i + 5] & 255) << 16) | ((buf[i + 6] & 255) << 8) | (buf[i + 7] & 255));
}
length -= toRead;
}
return (data);
}
/** /**
* Reads the payload of a tag given the type. * Reads the payload of a tag given the type.
* *
@ -548,7 +583,6 @@ public final class NBTInputStream implements Closeable {
tagMap.put(namedTag.getName(), tag); tagMap.put(namedTag.getName(), tag);
} }
} }
return new CompoundTag(tagMap); return new CompoundTag(tagMap);
case NBTConstants.TYPE_INT_ARRAY: case NBTConstants.TYPE_INT_ARRAY:
length = is.readInt(); length = is.readInt();
@ -569,84 +603,6 @@ public final class NBTInputStream implements Closeable {
} }
} }
/*
Don't delete please
*/
public Object readDataPayload(int type, int depth) throws IOException {
switch (type) {
case NBTConstants.TYPE_END:
if (depth == 0) {
throw new IOException(
"TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
} else {
return null;
}
case NBTConstants.TYPE_BYTE:
return is.readByte();
case NBTConstants.TYPE_SHORT:
return is.readShort();
case NBTConstants.TYPE_INT:
return is.readInt();
case NBTConstants.TYPE_LONG:
return is.readLong();
case NBTConstants.TYPE_FLOAT:
return is.readFloat();
case NBTConstants.TYPE_DOUBLE:
return is.readDouble();
case NBTConstants.TYPE_BYTE_ARRAY:
int length = is.readInt();
byte[] bytes = new byte[length];
is.readFully(bytes);
return bytes;
case NBTConstants.TYPE_STRING:
length = is.readShort();
bytes = new byte[length];
is.readFully(bytes);
return new String(bytes, NBTConstants.CHARSET);
case NBTConstants.TYPE_LIST:
int childType = is.readByte();
length = is.readInt();
ArrayList<Object> list = new ArrayList<>();
for (int i = 0; i < length; ++i) {
Object obj = readDataPayload(childType, depth + 1);
if (obj == null) {
throw new IOException("TAG_End not permitted in a list.");
}
list.add(obj);
}
return list;
case NBTConstants.TYPE_COMPOUND:
Map<String, Object> map = new HashMap<>();
while (true) {
int newType = is.readByte();
if (newType == NBTConstants.TYPE_END) {
return map;
}
String name = readNamedTagName(newType);
Object data = readDataPayload(newType, depth + 1);
map.put(name, data);
}
case NBTConstants.TYPE_INT_ARRAY: {
length = is.readInt();
int[] data = new int[length];
for (int i = 0; i < length; i++) {
data[i] = is.readInt();
}
return data;
}
case NBTConstants.TYPE_LONG_ARRAY: {
length = is.readInt();
long[] data = new long[length];
for (int i = 0; i < length; i++) {
data[i] = is.readLong();
}
return data;
}
default:
throw new IOException("Invalid tag type: " + type + ".");
}
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
is.close(); is.close();

Datei anzeigen

@ -19,32 +19,51 @@
package com.sk89q.worldedit.extent.clipboard.io; package com.sk89q.worldedit.extent.clipboard.io;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.jnbt.streamer.InfoReader;
import com.boydti.fawe.jnbt.streamer.IntValueReader;
import com.boydti.fawe.jnbt.streamer.StreamDelegate; import com.boydti.fawe.jnbt.streamer.StreamDelegate;
import com.boydti.fawe.jnbt.streamer.ValueReader; import com.boydti.fawe.jnbt.streamer.ValueReader;
import com.boydti.fawe.object.FaweInputStream;
import com.boydti.fawe.object.FaweOutputStream;
import com.boydti.fawe.object.clipboard.CPUOptimizedClipboard; import com.boydti.fawe.object.clipboard.CPUOptimizedClipboard;
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
import com.boydti.fawe.object.clipboard.LinearClipboard; import com.boydti.fawe.object.clipboard.LinearClipboard;
import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard; import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
import com.boydti.fawe.object.io.FastByteArrayOutputStream; import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.object.io.FastByteArraysInputStream;
import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
@ -72,42 +91,10 @@ public class SpongeSchematicReader extends NBTSchematicReader {
this.inputStream = inputStream; this.inputStream = inputStream;
} }
@Override
public Clipboard read() throws IOException {
return read(UUID.randomUUID());
}
@Override
public Clipboard read(UUID uuid) throws IOException {
return reader(uuid);
}
@Override
public Clipboard read(UUID uuid, Function<BlockVector3, Clipboard> createOutput) {
return null;
}
private int width, height, length; private int width, height, length;
private int offsetX, offsetY, offsetZ; private int offsetX, offsetY, offsetZ;
private char[] palette; private char[] palette, biomePalette;
private BlockVector3 min; private BlockVector3 min;
private LinearClipboard fc;
private LinearClipboard setupClipboard(int size, UUID uuid) {
if (fc != null) {
if (fc.getDimensions().getX() == 0) {
// fc.setDimensions(BlockVector3.at(size, 1, 1));
}
return fc;
}
if (Settings.IMP.CLIPBOARD.USE_DISK) {
return fc = new DiskOptimizedClipboard(BlockVector3.at(size, 1, 1), uuid);
} else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) {
return fc = new CPUOptimizedClipboard(BlockVector3.at(size, 1, 1));
} else {
return fc = new MemoryOptimizedClipboard(BlockVector3.at(size, 1, 1));
}
}
private String fix(String palettePart) { private String fix(String palettePart) {
if (fixer == null || dataVersion == -1) return palettePart; if (fixer == null || dataVersion == -1) return palettePart;
@ -124,13 +111,16 @@ public class SpongeSchematicReader extends NBTSchematicReader {
return fixer.fixUp(DataFixer.FixTypes.ENTITY, tag, dataVersion); return fixer.fixUp(DataFixer.FixTypes.ENTITY, tag, dataVersion);
} }
private Clipboard reader(UUID uuid) throws IOException { private FastByteArrayOutputStream blocksOut;
width = height = length = offsetX = offsetY = offsetZ = Integer.MIN_VALUE; private FaweOutputStream blocks;
final BlockArrayClipboard clipboard = new BlockArrayClipboard(new CuboidRegion(BlockVector3.at(0, 0, 0), BlockVector3.at(0, 0, 0)), fc); private FastByteArrayOutputStream biomesOut;
FastByteArrayOutputStream blocksOut = new FastByteArrayOutputStream(); private FaweOutputStream biomes;
FastByteArrayOutputStream biomesOut = new FastByteArrayOutputStream();
private List<Map<String, Object>> tiles;
private List<Map<String, Object>> entities;
public StreamDelegate createDelegate() {
StreamDelegate root = new StreamDelegate(); StreamDelegate root = new StreamDelegate();
StreamDelegate schematic = root.add("Schematic"); StreamDelegate schematic = root.add("Schematic");
schematic.add("DataVersion").withInt((i, v) -> dataVersion = v); schematic.add("DataVersion").withInt((i, v) -> dataVersion = v);
@ -147,135 +137,199 @@ public class SpongeSchematicReader extends NBTSchematicReader {
StreamDelegate paletteDelegate = schematic.add("Palette"); StreamDelegate paletteDelegate = schematic.add("Palette");
paletteDelegate.withValue(new ValueReader<Map<String, Object>>() { paletteDelegate.withValue(new ValueReader<Map<String, Object>>() {
@Override @Override
public void apply(int index, Map<String, Object> value) { public void apply(int ignore, Map<String, Object> v) {
palette = new char[v.size()];
for (Map.Entry<String, Object> entry : v.entrySet()) {
BlockState state = null;
try {
String palettePart = entry.getKey();
palettePart = fix(entry.getKey());
state = BlockState.get(palettePart);
} catch (InputParseException e) {
e.printStackTrace();
}
int index = (int) entry.getValue();
palette[index] = (char) state.getOrdinal();
}
}
});
StreamDelegate blockData = schematic.add("BlockData");
blockData.withInfo((length, type) -> {
blocksOut = new FastByteArrayOutputStream();
blocks = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut));
});
blockData.withInt(new IntValueReader() {
@Override
public void applyInt(int index, int value) {
try {
blocks.writeVarInt(value);
} catch (IOException e) {
e.printStackTrace();
}
}
});
StreamDelegate tilesDelegate = schematic.add("TileEntities");
tilesDelegate.withInfo((length, type) -> tiles = new ArrayList<>(length));
tilesDelegate.withElem(new ValueReader<Map<String, Object>>() {
@Override
public void apply(int index, Map<String, Object> tile) {
tiles.add(tile);
} }
}); });
// schematic.add("Palette", (BiConsumer<Integer, HashMap<String, Tag>>) (i, v) -> { StreamDelegate entitiesDelegate = schematic.add("Entities");
// palette = new char[v.size()]; entitiesDelegate.withInfo((length, type) -> entities = new ArrayList<>(length));
// for (Map.Entry<String, Tag> entry : v.entrySet()) { entitiesDelegate.withElem(new ValueReader<Map<String, Object>>() {
// BlockState state = null; @Override
// try { public void apply(int index, Map<String, Object> entity) {
// String palettePart = fix(entry.getKey()); entities.add(entity);
// state = BlockState.get(palettePart); }
// } catch (InputParseException e) { });
// e.printStackTrace(); StreamDelegate biomeData = schematic.add("BiomeData");
// } biomeData.withInfo(new InfoReader() {
// int index = ((IntTag) entry.getValue()).getValue(); @Override
// palette[index] = (char) state.getOrdinal(); public void apply(int length, int type) {
// } biomesOut = new FastByteArrayOutputStream();
// }); biomes = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut));
// }
// /// readBiomes });
// biomeData.withElem(new IntValueReader() {
// streamer.addReader("Schematic.BlockData", NBTStreamer.ReadType.ELEM, (NBTStreamer.LazyReader) (arrayLen, dis) -> { @Override
// try (FaweOutputStream blocks = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut))) { public void applyInt(int index, int value) {
// IOUtil.copy(dis, blocks, arrayLen); try {
// } catch (IOException e) { biomes.write(value); // byte of varInt
// e.printStackTrace(); } catch (IOException e) {
// } e.printStackTrace();
// }); }
// streamer.addReader("Schematic.BlockData", NBTStreamer.ReadType.ELEM, (NBTStreamer.LazyReader) (arrayLen, dis) -> { }
// try (FaweOutputStream biomes = new FaweOutputStream(new LZ4BlockOutputStream(biomesOut))) { });
// IOUtil.copy(dis, biomes, arrayLen); StreamDelegate biomePaletteDelegate = schematic.add("BiomePalette");
// } catch (IOException e) { biomePaletteDelegate.withInfo(new InfoReader() {
// e.printStackTrace(); @Override
// } public void apply(int length, int type) {
// }); biomePalette = new char[length];
// streamer.addReader("Schematic.TileEntities", NBTStreamer.ReadType.ELEM,(BiConsumer<Integer, CompoundTag>) (index, value) -> { }
// if (fc == null) { });
// setupClipboard(0, uuid); biomePaletteDelegate.withElem(new ValueReader<Map.Entry<String, Number>>() {
// } @Override
// int[] pos = value.getIntArray("Pos"); public void apply(int index, Map.Entry<String, Number> palettePart) {
// int x,y,z; String key = palettePart.getKey();
// if (pos.length != 3) { if (fixer != null) {
// System.out.println("Invalid tile " + value); key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);
// if (!value.containsKey("x") || !value.containsKey("y") || !value.containsKey("z")) { }
// return; BiomeType biome = BiomeTypes.get(key);
// } if (biome == null) {
// x = value.getInt("x"); System.out.println("Unknown biome " + key);
// y = value.getInt("y"); biome = BiomeTypes.FOREST;
// z = value.getInt("z"); }
// } else { int paletteIndex = palettePart.getValue().intValue();
// x = pos[0]; biomePalette[paletteIndex] = (char) biome.getInternalId();
// y = pos[1]; }
// z = pos[2]; });
// } return root;
// Map<String, Tag> values = value.getValue(); }
// Tag id = values.get("Id"); @Override
// if (id != null) { public Clipboard read(UUID uuid, Function<BlockVector3, Clipboard> createOutput) throws IOException {
// values.put("x", new IntTag(x)); StreamDelegate root = createDelegate();
// values.put("y", new IntTag(y)); inputStream.readNamedTagLazy(root);
// values.put("z", new IntTag(z)); BlockVector3 dimensions = BlockVector3.at(width, height, length);
// values.put("id", id); Clipboard clipboard = createOutput.apply(dimensions);
// }
// values.remove("Id"); BlockVector3 origin = min;
// values.remove("Pos"); CuboidRegion region;
// value = fixBlockEntity(value); if (offsetX != Integer.MIN_VALUE && offsetY != Integer.MIN_VALUE && offsetZ != Integer.MIN_VALUE) {
// fc.setTile(x, y, z, value); origin = origin.subtract(BlockVector3.at(offsetX, offsetY, offsetZ));
// }); }
// streamer.addReader("Schematic.Entities", NBTStreamer.ReadType.ELEM,(BiConsumer<Integer, CompoundTag>) (index, compound) -> { region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
// if (fc == null) { if (blocksOut.getSize() != 0) {
// setupClipboard(0, uuid); try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(blocksOut.toByteArrays())))) {
// } int volume = width * height * length;
// Map<String, Tag> value = compound.getValue(); if (palette.length < 128) {
// StringTag id = (StringTag) value.get("Id"); for (int index = 0; index < volume; index++) {
// if (id == null) { BlockState state = BlockTypes.states[palette[fis.read()]];
// id = (StringTag) value.get("id"); clipboard.setBlock(index, state);
// if (id == null) { }
// return; } else {
// } for (int index = 0; index < volume; index++) {
// } else { BlockState state = BlockTypes.states[palette[fis.readVarInt()]];
// value.put("id", id); clipboard.setBlock(index, state);
// value.remove("Id"); }
// } }
// }
// EntityType type = EntityTypes.parse(id.getValue()); }
// if (type != null) { if (biomesOut.getSize() != 0) {
// compound = fixEntity(compound); try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(biomesOut.toByteArrays())))) {
// BaseEntity state = new BaseEntity(type, compound); int volume = width * length;
// Location loc = compound.getEntityLocation(fc); for (int index = 0; index < volume; index++) {
// fc.createEntity(loc, state); clipboard.setBiome(index, BiomeTypes.get(fis.read()));
// } else { }
// Fawe.debug("Invalid entity: " + id); }
// } }
// }); // tiles
// streamer.readFully(); if (tiles != null && !tiles.isEmpty()) {
// if (fc == null) setupClipboard(length * width * height, uuid); for (Map<String, Object> tileRaw : tiles) {
//// fc.setDimensions(BlockVector3.at(width, height, length)); CompoundTag tile = FaweCache.IMP.asTag(tileRaw);
// BlockVector3 origin = min;
// CuboidRegion region; int[] pos = tile.getIntArray("Pos");
// if (offsetX != Integer.MIN_VALUE && offsetY != Integer.MIN_VALUE && offsetZ != Integer.MIN_VALUE) { int x,y,z;
// origin = origin.subtract(BlockVector3.at(offsetX, offsetY, offsetZ)); if (pos.length != 3) {
// } System.out.println("Invalid tile " + tile);
// region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE)); if (!tile.containsKey("x") || !tile.containsKey("y") || !tile.containsKey("z")) {
// if (blocksOut.getSize() != 0) { return null;
// try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(blocksOut.toByteArrays())))) { }
// int volume = width * height * length; x = tile.getInt("x");
// if (palette.length < 128) { y = tile.getInt("y");
// for (int index = 0; index < volume; index++) { z = tile.getInt("z");
// BlockState state = BlockTypes.states[palette[fis.read()]]; } else {
// fc.setBlock(index, state); x = pos[0];
// } y = pos[1];
// } else { z = pos[2];
// for (int index = 0; index < volume; index++) { }
// BlockState state = BlockTypes.states[palette[fis.readVarInt()]]; Map<String, Tag> values = tile.getValue();
// fc.setBlock(index, state); Tag id = values.get("Id");
// } if (id != null) {
// } values.put("x", new IntTag(x));
// } values.put("y", new IntTag(y));
// } values.put("z", new IntTag(z));
// if (biomesOut.getSize() != 0) { values.put("id", id);
// try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(biomesOut.toByteArrays())))) { }
// int volume = width * length; values.remove("Id");
// for (int index = 0; index < volume; index++) { values.remove("Pos");
// fc.setBiome(index, BiomeTypes.get(fis.read()));
// } tile = fixBlockEntity(tile);
// } clipboard.setTile(x, y, z, tile);
// } }
//// clipboard.init(region, fc); }
// clipboard.setOrigin(origin);
// entities
if (entities != null && !entities.isEmpty()) {
for (Map<String, Object> entRaw : entities) {
CompoundTag ent = FaweCache.IMP.asTag(entRaw);
Map<String, Tag> value = ent.getValue();
StringTag id = (StringTag) value.get("Id");
if (id == null) {
id = (StringTag) value.get("id");
if (id == null) {
return null;
}
}
value.put("id", id);
value.remove("Id");
EntityType type = EntityTypes.parse(id.getValue());
if (type != null) {
ent = fixEntity(ent);
BaseEntity state = new BaseEntity(type, ent);
Location loc = ent.getEntityLocation(clipboard);
clipboard.createEntity(loc, state);
} else {
Fawe.debug("Invalid entity: " + id);
}
}
}
clipboard.setOrigin(origin);
return clipboard; return clipboard;
} }