NbtTag
Abstract class used by all the NBT types
Methods
isEnd()
Whether this tag is of type End
.
A method exists for each type. They are excluded from the docs for brevity.
isNumber()
Whether this tag is a byte, short, int, long, float or double.
isArray()
Whether this tag is a bytearray, intarray or longarray.
isListOrArray()
Whether this tag is a list, bytearray, intarray or longarray.
getAsNumber()
Returns the number
representation of this tag. If this is not a number, returns 0
.
getAsString()
Returns the string
representation of this tag. If this is not a string, returns ''
.
getId()
Returns the NbtType
of this tag.
toString()
Returns the compact SNBT representation of this tag.
toPrettyString(indent, depth)
Returns the compact SNBT representation of this tag. indent
is the indentation string for each level, it defaults to two spaces. depth
is the current level, it defaults to 0
.
toJson()
Serializes the tag to a format which can be represented by JSON. This can be necessary when using workers.
toJsonWithId()
Serializes the tag to a format which can be represented by JSON, also including the ID.
toBytes(output)
Writes the bytes of this tag to the DataOutput
.
Static methods
create(id)
:
Creates an NbtTag
of a certain type with default values.
fromString(input)
Parses an SNBT string to get an NbtTag. input
can be either a string
or a StringReader
.
fromJson(value, id)
Turns the serialized format created by toJson()
back into an NbtTag
.
fromJsonWithId(value)
Turns the serialized format created by toJsonWithId()
back into an NbtTag
.
fromBytes(input, id)
Reads the bytes from the DataInput
to create an NbtTag
. id
defaults to a compound if not given.