Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-19 17:30:08 +01:00
chore: start on reader (class exists at least)
Dieser Commit ist enthalten in:
Ursprung
7905ee0e86
Commit
f740ab064a
@ -0,0 +1,45 @@
|
||||
package com.fastasyncworldedit.core.extent.clipboard.io;
|
||||
|
||||
import com.sk89q.jnbt.NBTConstants;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("removal") // JNBT
|
||||
public class FastSchematicReaderV3 implements ClipboardReader {
|
||||
|
||||
private final DataInputStream dataStream;
|
||||
private final NBTInputStream nbtStream;
|
||||
|
||||
public FastSchematicReaderV3(DataInputStream dataInputStream, NBTInputStream inputStream) {
|
||||
this.dataStream = Objects.requireNonNull(dataInputStream, "dataInputStream");
|
||||
this.nbtStream = Objects.requireNonNull(inputStream, "inputStream");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clipboard read() throws IOException {
|
||||
final DataFixer dataFixer =
|
||||
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataFixer();
|
||||
dataStream.skipNBytes(1 + 2); // 1 Byte = TAG_Compound, 2 Bytes = Short (Length of tag name = "")
|
||||
dataStream.skipNBytes(1 + 2 + 9); // as above + 9 bytes = "Schematic"
|
||||
|
||||
byte type;
|
||||
while ((type = dataStream.readByte()) != NBTConstants.TYPE_END) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
nbtStream.close(); // closes the DataInputStream implicitly
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,6 @@ import com.fastasyncworldedit.core.util.IOUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.NBTConstants;
|
||||
import com.sk89q.jnbt.NBTOutputStream;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
@ -30,14 +29,13 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings("removal") // Yes, JNBT is deprecated - we know
|
||||
public class FastSchematicWriterV3 implements ClipboardWriter {
|
||||
|
||||
private static final int CURRENT_VERSION = 3;
|
||||
public static final int CURRENT_VERSION = 3;
|
||||
|
||||
private static final int MAX_SIZE = Short.MAX_VALUE - Short.MIN_VALUE;
|
||||
private final NBTOutputStream outputStream;
|
||||
|
@ -61,7 +61,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
|
||||
FAST_NEW("new_fast") { // For testing purposes
|
||||
@Override
|
||||
public ClipboardReader getReader(final InputStream inputStream) throws IOException {
|
||||
return SPONGE_V3_SCHEMATIC.getReader(inputStream);
|
||||
return SPONGE_V3_SCHEMATIC.getReader(inputStream); // TODO: use FastSchematicReaderV3 when finished
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,6 +80,36 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
|
||||
@Override
|
||||
public boolean isFormat(final File file) {
|
||||
return FAST.isFormat(file);
|
||||
/**
|
||||
* TODO: test if this actually works
|
||||
* try (final DataInputStream stream = new DataInputStream(new GZIPInputStream(Files.newInputStream(file.toPath())));
|
||||
* final NBTInputStream nbt = new NBTInputStream(stream)) {
|
||||
* if (stream.readByte() != NBTConstants.TYPE_COMPOUND) {
|
||||
* return false;
|
||||
* }
|
||||
* stream.readShort(); // TAG name length ("" = 0), no need to read name as no bytes are written for root tag
|
||||
* if (stream.readByte() != NBTConstants.TYPE_COMPOUND) {
|
||||
* return false;
|
||||
* }
|
||||
* stream.readShort(); // TAG name length ("Schematic" = 9)
|
||||
* stream.skipNBytes(9); // "Schematic"
|
||||
*
|
||||
* // We can't guarantee the specific order of nbt data, so scan and skip, if required
|
||||
* do {
|
||||
* byte type = stream.readByte();
|
||||
* String name = stream.readUTF();
|
||||
* if (type == NBTConstants.TYPE_END) {
|
||||
* return false;
|
||||
* }
|
||||
* if (type == NBTConstants.TYPE_INT && name.equals("Version")) {
|
||||
* return stream.readInt() == FastSchematicWriterV3.CURRENT_VERSION;
|
||||
* }
|
||||
* nbt.readTagPayloadLazy(type, 1);
|
||||
* } while (true);
|
||||
* } catch (IOException ignored) {
|
||||
* }
|
||||
* return false;
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren