Data - roidrole/Roids-Tweaker GitHub Wiki

Provides utilities for IData.

Importing class

import mods.ctintegration.data.DataUtil;

Methods

Method Parameter Return Type Description
fromJSON json as string IData Converts a json String or NBT string representation to IData, returns null if errored
parse json as string IData Does the same thing as above, just with a different name
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

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.

IData expansion

You can now call these methods on an IData object.

Method Return Type
toNBTString() string
getRawString() string
toJson() string