Closed Marcono1234 closed 5 years ago
ListTag now uses the correct type when serialising. Deserialisation will detect the type after the first element has been added by deserialisation or later by the user of this library.
The only way one could obtain an empty untyped ListTag is by deserialising an empty ListTag marked as a ListTag of type EndTag.
Setting the type of an empty ListTag manually without adding a new element can be achieved by using one of the ListTag#as...List()
methods.
Currently for empty
ListTag
s the typeEndTag
is used, even if the actual type is a different one. This introduces all kind of type-safety problems, see #14.According to https://wiki.vg/NBT#Specification it is not "required" that
EndTag
is used:Therefore it might be good to at least have this library use the correct type for serialization (but keep deserialization the same for legacy support). The methods
getTypeID()
andgetTypeClass()
should be changed as well.Also
ListTag.typeClass
could beClass<? extends T>
and an non-type-safe list would havenull
as type, or maybe ratherOptional<Class<? extends T>>
to take advantage of some of Optional's methods. This woud prevent some casts which are currently necessary.Let me know if I should write a pull-request for it. Wanted to know your opinion about this first.