Jump to content

[1.8.9] Avoiding repetitive JSON files?


zerofall

Recommended Posts

I am working on a mod that has LOTS of items (not blocks), and I am getting tired of creating so many JSON item model files. They are all the EXACT same, except for the "layer0" path (and the image names are all the same as the unlocalized names). Is there a way around this so I don't have a hundred JSON files that are almost identical?

Link to comment
Share on other sites

Forge's blockstates format may be useful here. You can specify a default model (e.g.

builtin/generated

) and transform set (e.g.

forge:default-item

) and then specify the textures in each variant. Despite the name, Forge allows it to be used for items as well as blocks.

 

For the

ModelResourceLocation

passed to

ModelLoader.setCustomModelResourceLocation

or returned from

ItemMeshDefinition#getModelLocation

, use the location of the blockstates file as the domain and path (e.g.

<modid>:<name>

, which maps to assets/<modid>/blockstates/<name>.json) and the variant in the blockstates file as the variant.

 

If you're using an

ItemMeshDefinition

with

ModelLoader.setCustomMeshDefinition

, you need to call

ModelBakery.registerItemVariants

with the same

ModelResourceLocation

s yourself. If you're using

ModelLoader.setCustomModelResourceLocation

,

ModelBakery.registerItemVariants

is called for you.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I'm not sure if I understand what you mean, but I think I am already doing this. Example JSON files:

 

standard_item.json

{
    "parent":"builtin/generated",
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 1.7, 1.7, 1.7 ]
        }
    }
}

 

 

exampleItem1.json:

{
    "parent":"test:item/standard_item",
    "textures": {
        "layer0":"test:items/exampleItem1"
    }
}

 

Code used to register model:

public static void registerRenderer(Item item) {
    Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.modId + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}

 

My problem is that for the "exampleItem1.json" file... I have tons of them... and SURELY there is a way around that. Is there a way that I can have them all use the same JSON file, and pass in the unlocalized name as a variable into the JSON file (or something like that)?

Link to comment
Share on other sites

Thanks for the tips. So I can use 1 JSON file with 100 lines instead of 100 JSON files... but I am still wondering if there is a way to have 1 short, dynamic JSON file that passes in the unlocalized name instead? Or maybe a way to do this that goes around JSON files all together?

Link to comment
Share on other sites

You CAN get what you want.

The question is SHOULD you?

You've spent more time looking for a way around it then it would take to write a small script to generate the files.

Combined with the fact that if you DO figure a way around it you are doing nothing but limiting the flexibility that resource pack creators have over your items.

 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.