#Read any JSON File or Folder from any loaded mod or Minecraft **FORGE & FABRIC**

57 messages · Page 1 of 1 (latest)

rotund pasture
#

Just drop the file read_json_from_mod.js (on Gist link at the bottom) at startup_scripts and use like below:

at client_scripts:

ClientEvents.highPriorityAssets(event => {
  let json = global.readJsonFileFromMod("assets", "minecraft", "minecraft:blockstates/acacia_button.json")
  console.log(JsonIO.toPrettyString(json))
  let json2 = global.readJsonFileFromMod("assets", "create", "create:models/entity/crafting_blueprint_large.json")
  console.log(JsonIO.toPrettyString(json2))
  let json3 = global.readJsonFileFromMod("assets", "create", "create:blockstates/analog_lever.json")
  console.log(JsonIO.toPrettyString(json3))
  let jsonFolder = global.readJsonFolderFromMod("assets", "bloodmagic", "schematics")
  console.log(jsonFolder)
  let jsonFolder2 = global.readJsonFolderFromMod("assets", "bloodmagic", "schematics/room_pools", (rl => rl.path.contains("dungeon")))
  console.log(jsonFolder2)

})

at server_scripts: (works for low/highPriorityData)

ServerEvents.highPriorityData(event => {
    let json = global.readJsonFileFromMod("data", "bloodmagic", "bloodmagic:living_armor/fire_resist.json")
    console.log(JsonIO.toPrettyString(json))
    let json2 = global.readJsonFileFromMod("data", "bloodmagic", "forge:loot_modifiers/global_loot_modifiers.json")
    console.log(JsonIO.toPrettyString(json2))
    let json3 = global.readJsonFileFromMod("data", "minecraft", "minecraft:trim_material/copper.json")
    console.log(JsonIO.toPrettyString(json3))
    let jsonFolder = global.readJsonFolderFromMod("data", "minecraft", "trim_material")
    console.log(jsonFolder)
    let jsonFolder2 = global.readJsonFolderFromMod("data", "minecraft", "trim_material", (rl => rl.path.contains("redstone")))
    console.log(jsonFolder2)
})

This is great for when you need to add dynamic custom datapack files that depends on some mod files.

https://gist.github.com/pietro-lopes/1471e43c6acef411fd98f10908185fae

atomic meadow
ocean juniper
#

Awesome. What are you using it for?

atomic meadow
#

Can this read all the file names in the path? Because I may need to create a mapping based on the file name.

rotund pasture
ocean juniper
#

That's very awesome

rotund pasture
atomic meadow
rotund pasture
#

so you wanted this list?

atomic meadow
#

yep

rotund pasture
#

@atomic meadow

#

soon

rotund pasture
#

Check gist link with updated methods

#

Read any JSON File or Folder from any loaded mod or Minecraft FORGE ONLY

sturdy moss
#

Oh shoot! That’s what you were looking for right @atomic meadow

atomic meadow
#

wait a min, does this unsupport fabric?

rotund pasture
atomic meadow
#

In terms of debugging, Fabric is more convenient and faster than Forge, so I like to use Fabric to develop scripts, even though there may be fewer mods.

rotund pasture
#

Read any JSON File or Folder from any loaded mod or Minecraft FORGE & FABRIC

#

added Fabric support 👌

atomic meadow
#

👍

atomic meadow
#

||iirc, try catch is not working on kubejs?||

rotund pasture
#

it works

#

there are some instances that try-catch doesn't work, but it does when it does

#

also, the warn message will be on startup.log

atomic meadow
#

it does when it does
lamo_3

rotund pasture
#

¯_(ツ)_/¯

#

just a Rhino moment

pearl forum
#

question! has anyone found a way to do this in 1.18.2?

narrow gorge
atomic meadow
#

I find this script in All The Mods - Gravitas²heh

rotund pasture
#

yes, because I'm the dev there 🤣

#

I could remove since I don't use it anymore

#

🤔

rotund pasture
#

@hasty jungle here is how to read any mod json

hasty jungle
#

i did see this but its not working :P

#

i'm using connector to load numismatic overhaul

#

that probably has something to do with it

rotund pasture
#

show what you tried

#

need to see code

hasty jungle
#
ServerEvents.highPriorityData(e => {
    let json = global.readJsonFileFromMod('data', 'numismatic-overhaul', 'numismatic-overhaul:villager_trades/cartographer.json')
    console.log(JsonIO.toPrettyString(json))
})
#

wouldnt be surprised if the hyphen in their mod id is causing problems too

rotund pasture
#

@hasty jungle hmm, originally this is a Fabric mod?

rotund pasture
#

yeah, that certainly messes with code

#

:/

hasty jungle
#

aw okay

rustic yacht
#

Would this also be possible to code in 1.16? or is there some function that doesn't exist on that version that this relies on?

rotund pasture
rustic yacht
rustic yacht
#

what there are datapack events in 1.16?

#

also I would want to read blockstates and models from blocks from vanilla and also from mods

rustic yacht
#

so this wouldn't work because there's no assets event?