Jump to content

Help with rendering a .obj file to use as an item model


The_Basset_Hound

Recommended Posts

Hello,

 

I'm pretty new to modding Minecraft and don't understand item models. Could someone walk me through using a .obj file as a model for an item? So far I have been using tutorials meant for using .obj files as models for blocks, and I've seen from a couple of places that all I have to do is add a .obj file extension somewhere, but I'm not sure where.

I have also added the

OBJLoader.INSTANCE.addDomain(SlimeRancher.MODID);

to my mod during preinitialization.

 

Right now I have my vacpack.obj file sitting in my models/item folder along with my vacpack.mtl file. When I test the mod, during loading, I get a slew of errors, the first being

Exception loading model for variant slimerancher:vacpack#inventory for item "slimerancher:vacpack", normal location exception: 
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model slimerancher:item/vacpack with loader VanillaLoader.INSTANCE, skipping

 

If anyone could help me out I'd appreciate it. Also, if I'm missing important information from this post, please tell me and I'll add it asap.

 

Thanks,

Basset

Edited by The_Basset_Hound
Link to comment
Share on other sites

5 hours ago, The_Basset_Hound said:

Also, if I'm missing important information from this post, please tell me and I'll add it asap.

We would need at the very least the whole error report, not just one line that tells "something is wrong" but doesn't tell what exactly is. And since there are multiple errors you should just post your debug.log. Please make sure it is not cluttered with unrelevant issues though.

 

5 hours ago, The_Basset_Hound said:

I have also added the


OBJLoader.INSTANCE.addDomain(SlimeRancher.MODID);

to my mod during preinitialization.

I hope it is not directly in your preinit method but is called through your proxy during preinit.

Link to comment
Share on other sites

Here's a debuglog I generated when starting up the client.

 

5 hours ago, V0idWa1k3r said:

I hope it is not directly in your preinit method but is called through your proxy during preinit.

I don't know what a proxy is and haven't found a good explanation on it, but I'm not calling it straight from my mod's preinit method. Here are the relevant files in pastebin:

 

Thanks for the reply.

Edited by The_Basset_Hound
Link to comment
Share on other sites

1 hour ago, The_Basset_Hound said:

I don't know what a proxy is and haven't found a good explanation on it

https://mcforge.readthedocs.io/en/latest/concepts/sides/#sidedproxy

 

public static void init() {
        OBJLoader.INSTANCE.addDomain(SlimeRancher.MODID);
        indigonium = new SlimeRancherItem("indigonium", CreativeTabs.MATERIALS);
        vacpack = new ItemVacpack();
    }
  • Don't instantinate your stuff in pre-init. This is much, much better than using static initializers but you still should instantinate them in the appropriate registry event.
  • Since ObjLoader is a client-only class this code will crash the client server. You must use a proxy.
public void registerRender() {
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(this.getRegistryName(), "inventory"));
    }

IHasModel(yes, it is one even though there is technically no interface like that) is stupid. All items need models, no exceptions and nothing about model registration requires access to private/protected data in the item. Register your models directly in the ModelRegistryEvent.

 

As for your actual issue:

From what I can tell the game is looking for the item's json file. I don't know if you can trick it into looking for the obj file directly by manipulation the ModelResourceLocation but you can still use obj models for items if you use forge's blockstates since they can be used for items too.

Edited by V0idWa1k3r
Link to comment
Share on other sites

4 minutes ago, V0idWa1k3r said:

this code will crash the client

crash the server*

 

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

6 minutes ago, V0idWa1k3r said:

this code will crash the client.

 

2 minutes ago, larsgerrits said:

crash the server*

?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

8 minutes ago, V0idWa1k3r said:

manipulation the ModelResourceLocation

What he means by this is, try to append .obj to the end of your path in the model resource location.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

10 hours ago, V0idWa1k3r said:

From what I can tell the game is looking for the item's json file. I don't know if you can trick it into looking for the obj file directly by manipulation the ModelResourceLocation but you can still use obj models for items if you use forge's blockstates since they can be used for items too.

Thank you for this. I got it working using blockstates and the model is in the game.

 

Now i'm running into the problem of scaling it down (it's absolutely massive).image.thumb.png.17e1b89b3a78cfa399bb9b4134454cc9.png

 

Also when it is in my inventory, the icon is enormous and covers my screen.

image.thumb.png.f5ad7b96ee814c9277ac2adf9cc6c080.png

 

Where in my json file do I put the "scale" tag? Do I need to make a json for it in my models/item folder as well to scale it down?

 

Here's a link to my blockstate json.

Edited by The_Basset_Hound
Link to comment
Share on other sites

6 hours ago, V0idWa1k3r said:

Scale down your model in your model editing software. This actually looks to me like your model editing software used the wrong metrics.

 

So there's no way to scale it down using forge? I used magicavoxel to create the model and I'm not sure I'm able to scale it down in that. I'd also like to know how to translate and rotate it, like I know you can do when not using blockstates.

Link to comment
Share on other sites

From forge's code I can deduce that you should be able to use a propery by a key of "transform" in your variants. It's value can be

1. a string which is the pointer to a transform specified in code. The defaults are

  • forge:default-block - the block transformation

  • forge:default-item - the item transformation

  • forge:default-tool - a handheld tool-like transformation
    I don't think you can have your own custom transforms like this though since the map is immutable.

2. a primitive that's not a string. I can't find out how it is deserialized in that case though.

3. a json object that contains keys that specify the transform type (like thirdperson for example) with the values of a TRSRTransformation. I assume those would look like your transforms that you use in json files.

Link to comment
Share on other sites

1 hour ago, V0idWa1k3r said:

3. a json object that contains keys that specify the transform type (like thirdperson for example) with the values of a TRSRTransformation. I assume those would look like your transforms that you use in json files.

This looks like it's working thus far. Thank you so much for all of your help.

Edited by The_Basset_Hound
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.