[Question] How can I get/write a list of some types?
ChenCMD opened this issue · 9 comments
I want to retrieve or write a list of types whose elements are part of the NBTCompound
type for general-purpose NBT operations, but I am stuck because I do not know how to retrieve some list types (Byte
/Short
/ByteArray
/IntArray
/LongArray
/nested list) and how to set the list I am stuck because I don't know how to get some list types (Byte
/Short
/ByteArray
/IntArray
/LongArray
/nested list) and how to set list types.
What should I do?
For example, the NBTCompound types getInteger and getIntegerList exist, but getShortList does not exist even though getShort does.
Just to be sure, here are the SNBT expressions for each and what is missing.
Name | SNBT representation | get method available | set method available |
---|---|---|---|
StringList | ["", "", ""] |
o | x |
ByteList | [0b, 1b, 2b] |
x | x |
ShortList | [0s, 1s, 2s] |
x | x |
IntegerList | [0, 1, 2, 3] |
o | x |
LongList | [0L, 1L, 2L] |
o | x |
FloatList | [0f, 1f, 2f] |
o | x |
DoubleList | [0d, 1d, 2d] |
o | x |
ByteArrayList | [[B; 0b, 1b, 2b], [B; 3b, 4b, 5b]] |
x | x |
IntArrayList | [[I; 0, 1, 2, 3], [I; 4, 5, 6, 7]] |
x | x |
LongArrayList | [[L; 0L, 1L, 2L], [L; 3L, 4L, 5L]] |
x | x |
CompoundList | [{a: 1, b: 2, c: 3}, {x: 4, y: 5}] |
o | △ (If the key is present then getCompoundList(key).addCompound() ) |
NestedList | [[0b, 1b], [2s, 3s], [4, 5], [6L]] |
x | x |
Oops, didn't see this issue. There is no setter because the list is linked to the NBT. Just get the list and start adding stuff.
The missing list types are because Minecraft doesn't use them and therefore doesn't provide methods.
nvm, Thanks for the reply.
Get the list.
Maybe I'm just missed how to do this, but how do you do it?
I understand the case where the element type is String
.
So how do I get it if the element type is Short
etc?
I guess so far the reason it's been not added is: "why?".
Doubt there are more than 10 people so far that used stuff like the IntArrayList, which has just been added since Minecraft uses it somewhere. So nobody so far asked about stuff like short lists 😅.
From what you listed, ByteList, ShortList, ByteArrayList, LongArrayList might be doable and work, but just haven't had any use-case yet.
IntArrayList already is a thing, you missed that one.
CompoundList not sure what you mean with your setter info? The key does not need to be present.
NestedList EHHH unsure if the mc parser is even able to handle that one right. Certainly wouldn't work with the current reflection setup, as this would be a List<List<NBTBase>>
. Doubt that it's a good idea to even try to support this.