Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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)?

Posted

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?

Posted

Sure, ya registry name would work. I guess I'm hoping for something like this:

 

anyItem.json:

{
    "parent":"test:item/standard_item",
    "textures": {
        "layer0":"test:items/#this.registryName#"
    }
}

Posted

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I can't understand the logs, so I'm hoping someone could tell me what's causing the issues. https://pastebin.com/d1XPxCes
    • Hello I'm currently making an Item that thrusts you to viewing direction, and I referenced riptide code of trident for my item. @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { if(!pLevel.isClientSide() && pUsedHand == InteractionHand.MAIN_HAND && pPlayer.isOnGround()){ Impale(pPlayer, pUsedHand); pPlayer.getCooldowns().addCooldown(this, 40); } return super.use(pLevel, pPlayer, pUsedHand); } public void Impale(Player pPlayer, InteractionHand pUsedHand) { float playerYRot = pPlayer.getYRot(); float xForce = -Mth.sin(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float yForce = 100.6F; float zForce = Mth.cos(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float stabilizedForce = Mth.sqrt(xForce * xForce + zForce * zForce); xForce /= stabilizedForce; zForce /= stabilizedForce; pPlayer.push((double)xForce, (double)yForce, (double)zForce); pPlayer.sendSystemMessage(Component.literal(playerYRot + " " + xForce + " " + yForce + " " + zForce + " " + stabilizedForce + "shoo")); } I sure edited a lot from source code but this isn't working somehow? the sendSystemMessage works correctly. It prints value of variables and string, but the force isn't applying to player. how can I make this to work? Thanks.
    • i tried putting a modpack together and cant get this working no matter what i have tried log: https://pastebin.com/uqz1aKiY
    • We have an event for an Entity being struck by lighting, but doesn't look like we have one for Blocks. And unfortunately, looking at it, the LightingBolt entity doesn't have any context on why it was registered, so you wouldn't be able to get the source context. What are you trying to accomplish with this event?
    • Hey guys, I'm trying to use the simple planes mod https://www.curseforge.com/minecraft/mc-mods/simple-planes with a nuclear bombs mod https://www.curseforge.com/minecraft/mc-mods/nuclear-bombs . The simple planes mod has a cargo plane that can drop tnt, and i want it to work with the nuclear bombs. I added this JSON file from chatGPT to the payloads folder in simple planes (because the nukes couldn't even get stored in the plane in the first place), but this only allows the nuke to drop but doesn't explode: https://mclo.gs/3uEQIX2 . This nuke mod requires a redstone signal and then manual activation, which makes this tougher i imagine. If someone could write me a code for the payload folder for simpleplanes, something that even tampers with the nuke mod, or any general suggestions that would be great!  Many Thanks
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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