How can I store an object like ArrayList in the persistent data container?

Sheepion

New member
Feb 27, 2022
9
1
3
China
I want to write something complex into the persistent data container like my own class or an ArrayList
 

_Pesto

New member
Mar 7, 2022
7
0
1
What are you trying to achieve exactly (might be an XY problem). Regardless, I would say if your storing something like a list of strings then store the list as a single string with a delimiter. Storing something like an object seems overkill for PDC but you could store each property into multiple data containers.
 

Sheepion

New member
Feb 27, 2022
9
1
3
China
What are you trying to achieve exactly (might be an XY problem). Regardless, I would say if your storing something like a list of strings then store the list as a single string with a delimiter. Storing something like an object seems overkill for PDC but you could store each property into multiple data containers.
I am trying to add multiple effect to my item, I have wrote a custom potion api to make my own potion. I stored the potion's effect type into the PDC as a String, and it can only store one string, but I want a list of string so that I can add two or more effect into one potion. So I wonder if I can store some object in the PDC to make something more interesting and flexible.
 

electronicboy

Administrator
Staff member
Dec 11, 2021
225
10
38
28
You can store a byte[], in which you can encode whatever date you want into there, generally you'd do a length prefixed array, and then length prefixed strings to simulate a String[], then there's also "just store json", etc
 

Sheepion

New member
Feb 27, 2022
9
1
3
China
What are you trying to achieve exactly (might be an XY problem). Regardless, I would say if your storing something like a list of strings then store the list as a single string with a delimiter. Storing something like an object seems overkill for PDC but you could store each property into multiple data containers.
For example, I can store a list of itemstack in a block's PDC, so I can add the itemstack to the drops when player breaks the block.