#Json Class Writing/Reading - Trying to make a custom Research System for my modpack

8 messages · Page 1 of 1 (latest)

austere echo
#

Hi! Ive been working on a custom research system for my modpack, however for the sake of making it easier and having smaller code, I was curious if KubeJS can utilize reading json files from datapacks or smth? If so, how?

In essence for the actual thing Im trying to do, Im trying to figure out how to create a simple instancable class containing essentially strings for both the game stage it unlocks, its description, its name and stuff to write into the ui ive made for it as well. Alongside storing "Goals", essentially just items that can be provided to gain progress for research, which would likely be tracked through an int or smth. This may also require figuring out how to add new data storage to the player n whatnot which I also need to figure out. Also to be clear I know how constructors work I just wanna know how KubeJS does it if it can.

Im not asking for the code necessarily, just asking for where to look for this stuff since the API is kinda sparse. Ik I probably have to use stuff like ClassJS but was curious what else I'd need to do (Also already intending to use both GameStages, RecipeStages and StageJS for this as well, mostly asking for ppl familiar with those addons)

stoic crowBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

charred gale
#

you can use json and nbt files

wispy trellisBOT
#

Here's a simple snippet showing how to use JsonIO to read/write JSON files anywhere within the Minecraft folder:

// Reading the contents of the file from the given path
let config = JsonIO.read('kubejs/config/myawesomeconfig.json')  // GSON format
let configObject = JSON.parse(config.asString())                // JS Object format

// Writing to an existing/new file
JsonIO.write('kubejs/config/myawesomeconfig.json', {settings: 'creeper', weirdblock: 'minecraft:end_gateway'})


austere echo
#

Ic ic!

charred gale
#

keep in mind the json files can only be in the minecraft folder and not outside of it

austere echo
#

Nod

#

Actually just realized I could prooobably like
Just store that info by tracking which stages they got unlocked, ty!