formatting for compressed data tree

This commit is contained in:
Sen 2025-05-28 18:12:28 +02:00
parent 815c52e5d7
commit b01b602728
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
16 changed files with 78 additions and 19 deletions

View file

@ -8,8 +8,12 @@ abstract class Tag {
abstract void write(DataOutput output) throws IOException; abstract void write(DataOutput output) throws IOException;
abstract void read(DataInput input, int depth, SizeTracker tracker) throws IOException; abstract void read(DataInput input, int depth, SizeTracker tracker) throws IOException;
public abstract String toString(); public abstract String toString();
protected abstract TagType getType(); abstract TagType getType();
public abstract Tag copy(); public abstract Tag copy();
String toString(int indent, int depth) {
return this.toString();
}
public boolean equals(Object other) { public boolean equals(Object other) {
return other instanceof Tag && this.getType() == ((Tag)other).getType(); return other instanceof Tag && this.getType() == ((Tag)other).getType();

View file

@ -23,7 +23,7 @@ class TagBool extends Tag {
this.data = input.readBoolean(); this.data = input.readBoolean();
} }
protected TagType getType() { TagType getType() {
return TagType.BOOLEAN; return TagType.BOOLEAN;
} }

View file

@ -23,7 +23,7 @@ class TagByte extends Tag {
this.data = input.readByte(); this.data = input.readByte();
} }
protected TagType getType() { TagType getType() {
return TagType.BYTE; return TagType.BYTE;
} }

View file

@ -28,7 +28,7 @@ class TagByteArray extends Tag {
input.readFully(this.data); input.readFully(this.data);
} }
protected TagType getType() { TagType getType() {
return TagType.BYTE_ARRAY; return TagType.BYTE_ARRAY;
} }

View file

@ -23,7 +23,7 @@ class TagChar extends Tag {
this.data = input.readChar(); this.data = input.readChar();
} }
protected TagType getType() { TagType getType() {
return TagType.CHAR; return TagType.CHAR;
} }

View file

@ -23,7 +23,7 @@ class TagDouble extends Tag {
this.data = input.readDouble(); this.data = input.readDouble();
} }
protected TagType getType() { TagType getType() {
return TagType.DOUBLE; return TagType.DOUBLE;
} }

View file

@ -23,7 +23,7 @@ class TagFloat extends Tag {
this.data = input.readFloat(); this.data = input.readFloat();
} }
protected TagType getType() { TagType getType() {
return TagType.FLOAT; return TagType.FLOAT;
} }

View file

@ -23,7 +23,7 @@ class TagInt extends Tag {
this.data = input.readInt(); this.data = input.readInt();
} }
protected TagType getType() { TagType getType() {
return TagType.INT; return TagType.INT;
} }

View file

@ -32,7 +32,7 @@ class TagIntArray extends Tag {
} }
} }
protected TagType getType() { TagType getType() {
return TagType.INT_ARRAY; return TagType.INT_ARRAY;
} }

View file

@ -5,6 +5,7 @@ import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import common.util.Util;
class TagList extends Tag { class TagList extends Tag {
private List<TagObject> list; private List<TagObject> list;
@ -37,7 +38,7 @@ class TagList extends Tag {
} }
} }
protected TagType getType() { TagType getType() {
return TagType.LIST; return TagType.LIST;
} }
@ -46,11 +47,22 @@ class TagList extends Tag {
for(int z = 0; z < this.list.size(); z++) { for(int z = 0; z < this.list.size(); z++) {
if(z != 0) if(z != 0)
sb.append(','); sb.append(',');
sb.append(z).append(':').append(this.list.get(z)); sb.append(this.list.get(z).toString());
} }
return sb.append(']').toString(); return sb.append(']').toString();
} }
String toString(int indent, int depth) {
StringBuilder sb = new StringBuilder("[");
String prefix = Util.repeatString(' ', indent * (depth + 1));
for(int z = 0; z < this.list.size(); z++) {
if(z != 0)
sb.append(',');
sb.append('\n').append(prefix).append(this.list.get(z).toString(indent, depth + 1));
}
return sb.append('\n').append(Util.repeatString(' ', indent * depth)).append('}').toString();
}
public Tag copy() { public Tag copy() {
TagList list = new TagList(new ArrayList<TagObject>(this.list.size())); TagList list = new TagList(new ArrayList<TagObject>(this.list.size()));
for(TagObject tag : this.list) { for(TagObject tag : this.list) {

View file

@ -23,7 +23,7 @@ class TagLong extends Tag {
this.data = input.readLong(); this.data = input.readLong();
} }
protected TagType getType() { TagType getType() {
return TagType.LONG; return TagType.LONG;
} }

View file

@ -10,14 +10,18 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import common.collect.Lists; import common.collect.Lists;
import common.collect.Maps; import common.collect.Maps;
import common.util.Util;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -60,7 +64,7 @@ public class TagObject extends Tag {
return this.tags.keySet(); return this.tags.keySet();
} }
protected TagType getType() { TagType getType() {
return TagType.OBJECT; return TagType.OBJECT;
} }
@ -248,17 +252,39 @@ public class TagObject extends Tag {
public void remove(String key) { public void remove(String key) {
this.tags.remove(key); this.tags.remove(key);
} }
private List<Entry<String, Tag>> getSortedEntries() {
List<Entry<String, Tag>> list = Lists.newArrayList(this.tags.entrySet());
Collections.sort(list, (e1, e2) -> e1.getValue().getType() == TagType.OBJECT && e2.getValue().getType() != TagType.OBJECT ? 1 : (
e2.getValue().getType() == TagType.OBJECT && e1.getValue().getType() != TagType.OBJECT ? -1 : (
(e1.getValue().getType() == TagType.LIST || e1.getValue().getType() == TagType.STRING_ARRAY) &&
e2.getValue().getType() != TagType.LIST && e2.getValue().getType() != TagType.STRING_ARRAY ? 1 : (
(e2.getValue().getType() == TagType.LIST || e2.getValue().getType() == TagType.STRING_ARRAY) &&
e1.getValue().getType() != TagType.LIST && e1.getValue().getType() != TagType.STRING_ARRAY ? -1 : e1.getKey().compareTo(e2.getKey())))));
return list;
}
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("{"); StringBuilder sb = new StringBuilder("{");
for(Entry<String, Tag> entry : this.tags.entrySet()) { for(Entry<String, Tag> entry : this.getSortedEntries()) {
if(sb.length() != 1) if(sb.length() != 1)
sb.append(','); sb.append(',');
sb.append(entry.getKey()).append(':').append(entry.getValue()); sb.append(entry.getKey()).append(':').append(entry.getValue().toString());
} }
return sb.append('}').toString(); return sb.append('}').toString();
} }
String toString(int indent, int depth) {
StringBuilder sb = new StringBuilder("{");
String prefix = Util.repeatString(' ', indent * (depth + 1));
for(Entry<String, Tag> entry : this.getSortedEntries()) {
if(sb.length() != 1)
sb.append(',');
sb.append('\n').append(prefix).append(entry.getKey()).append(": ").append(entry.getValue().toString(indent, depth + 1));
}
return sb.append('\n').append(Util.repeatString(' ', indent * depth)).append('}').toString();
}
public boolean isEmpty() { public boolean isEmpty() {
return this.tags.isEmpty(); return this.tags.isEmpty();
} }
@ -301,6 +327,10 @@ public class TagObject extends Tag {
} }
} }
} }
public String format(int indent) {
return indent == 0 ? this.toString() : this.toString(indent, 0);
}
public static void write(TagObject tag, DataOutput out) throws IOException { public static void write(TagObject tag, DataOutput out) throws IOException {
tag.write(out); tag.write(out);

View file

@ -23,7 +23,7 @@ class TagShort extends Tag {
this.data = input.readShort(); this.data = input.readShort();
} }
protected TagType getType() { TagType getType() {
return TagType.SHORT; return TagType.SHORT;
} }

View file

@ -27,7 +27,7 @@ class TagString extends Tag {
tracker.read(2 * this.data.length()); tracker.read(2 * this.data.length());
} }
protected TagType getType() { TagType getType() {
return TagType.STRING; return TagType.STRING;
} }

View file

@ -5,6 +5,8 @@ import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import common.util.Util;
class TagStringArray extends Tag { class TagStringArray extends Tag {
private String[] data; private String[] data;
@ -32,7 +34,7 @@ class TagStringArray extends Tag {
} }
} }
protected TagType getType() { TagType getType() {
return TagType.STRING_ARRAY; return TagType.STRING_ARRAY;
} }
@ -46,6 +48,17 @@ class TagStringArray extends Tag {
return sb.append("]").toString(); return sb.append("]").toString();
} }
String toString(int indent, int depth) {
StringBuilder sb = new StringBuilder("[");
String prefix = Util.repeatString(' ', indent * (depth + 1));
for(int z = 0; z < this.data.length; z++) {
if(z != 0)
sb.append(',');
sb.append('\n').append(prefix).append("\"" + this.data[z].replace("\"", "\\\"") + "\"");
}
return sb.append('\n').append(Util.repeatString(' ', indent * depth)).append("]").toString();
}
public Tag copy() { public Tag copy() {
String[] data = new String[this.data.length]; String[] data = new String[this.data.length];
System.arraycopy(this.data, 0, data, 0, this.data.length); System.arraycopy(this.data, 0, data, 0, this.data.length);

View file

@ -16,7 +16,7 @@ public class CommandSeed extends Command {
public Object exec(CommandEnvironment env, Executor exec, WorldServer world, boolean dump) { public Object exec(CommandEnvironment env, Executor exec, WorldServer world, boolean dump) {
if(dump) if(dump)
exec.logConsole("Daten: %s", world.dimension.dumpTags().toString()); exec.logConsole("Daten: %s", world.dimension.dumpTags().format(4));
exec.logConsole("Startwert von %s: %d", world.dimension.getFormattedName(false), world.dimension.getSeed()); exec.logConsole("Startwert von %s: %d", world.dimension.getFormattedName(false), world.dimension.getSeed());
return world.dimension.getSeed(); return world.dimension.getSeed();
} }