Ignore invalid list tag type if the ID is 0; this is written when the list is empty.

This commit is contained in:
Steveice10 2014-04-24 16:43:05 -07:00
parent a2c24ac40f
commit 835829105e

View File

@ -147,7 +147,7 @@ public class ListTag extends Tag implements Iterable<Tag> {
int id = in.readUnsignedByte();
this.type = TagRegistry.getClassFor(id);
this.value = new ArrayList<Tag>();
if(this.type == null) {
if(id != 0 && this.type == null) {
throw new IOException("Unknown tag ID in ListTag: " + id);
}
@ -167,12 +167,17 @@ public class ListTag extends Tag implements Iterable<Tag> {
@Override
public void write(DataOutputStream out) throws IOException {
int id = TagRegistry.getIdFor(this.type);
if(id == -1) {
throw new IOException("ListTag contains unregistered tag class.");
if(this.value.isEmpty()) {
out.writeByte(0);
} else {
int id = TagRegistry.getIdFor(this.type);
if(id == -1) {
throw new IOException("ListTag contains unregistered tag class.");
}
out.writeByte(id);
}
out.writeByte(id);
out.writeInt(this.value.size());
for(Tag tag : this.value) {
tag.write(out);