Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How can I get/write a list of some types? #268

Open
ChenCMD opened this issue Feb 24, 2024 · 9 comments
Open

[Question] How can I get/write a list of some types? #268

ChenCMD opened this issue Feb 24, 2024 · 9 comments

Comments

@ChenCMD
Copy link

ChenCMD commented Feb 24, 2024

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
@tr7zw
Copy link
Owner

tr7zw commented Mar 24, 2024

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.

@ChenCMD
Copy link
Author

ChenCMD commented Mar 24, 2024

nvm, Thanks for the reply.

Get the list.

Maybe I'm just missed how to do this, but how do you do it?

@tr7zw
Copy link
Owner

tr7zw commented Mar 25, 2024

comp.getStringList("SomeList").add("some Element");

@ChenCMD
Copy link
Author

ChenCMD commented Mar 26, 2024

Hmmm, do we use getStringList even if the element type is not String?

@tr7zw
Copy link
Owner

tr7zw commented Mar 26, 2024

What do you mean? It returns a literal normal Java List<String>.

@ChenCMD
Copy link
Author

ChenCMD commented Mar 27, 2024

I understand the case where the element type is String.
So how do I get it if the element type is Short etc?

@tr7zw
Copy link
Owner

tr7zw commented Mar 28, 2024

Nbt doesn't have short lists. Mojang never needed it, so they haven't added it.

@ChenCMD
Copy link
Author

ChenCMD commented Mar 28, 2024

Ummm, it is not used by default, but you can use it in commands and such.

@tr7zw
Copy link
Owner

tr7zw commented Mar 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants