-
Notifications
You must be signed in to change notification settings - Fork 0
Data
roidrole edited this page Mar 26, 2026
·
5 revisions
Provides utilities for IData.
Importing class
import mods.ctintegration.data.DataUtil;| Method | Parameter | Return Type | Description |
|---|---|---|---|
| fromJson | json as string | IData | Converts a json String to IData. Returns null if errored |
| fromSNBT | nbt as string | IData | Converts an NBT string into IData. Returns null if errored |
| parse | data as string | IData | Attempts to parse a data string as JSON, and as NBT if it fails |
| toNBTString | data as IData | string | Converts an IData to NBT string representation |
| getRawString | data as IData | string | Discard the type definitions. Output is what you get when calling String.valueof() on the basic types (string, double, etc) For lists and maps this just simply cast them to string |
| toJson | data as IData | string | Converts an IData to JSON. Some properties might be lost, such as type definitions |
| read | filePath as string | IData | Reads the content of a json file. The file path is relative to the instance directory, and should contain .json |
| write | filePath as string, data as IData | void | Write data to the specified file. Will create a file if it doesn't exist |
| readSNBT | filePath as string | IData | Reads the content of as snbt file. The file path is relative to the instance directory, and should contain .snbt |
| writeSNBT | filePath as string, data as IData | void | Write data to the specified file. Will create a file if it doesn't exist |
Performance tip : file operations can be pretty expensive, you should at least set the output to a value if using the same file multiple times. You should also avoid unnecessary read() and write() operation for data that didn't change.
The reader can read pretty JSON data (including with comment via json5), but the writer will always write on the same line. Both reader and writer supports nulls.
You can now call these methods on an IData object.
| Method | Return Type |
|---|---|
| toNBTString() | string |
| getRawString() | string |
| toJson() | string |