Jump to content

Change vanilla item model based off of name/lore


Miclebrick

Recommended Posts

I'm trying to make a mod that changes vanilla item model based off of its name or lore. But before I get to that, I'm trying to get it to even change the model in the first place! Nothing seems to happen. Am I missing anything?

 

Main mod file:

http://pastebin.com/KKhrD2bC

 

CustomItemModel:

http://pastebin.com/sEXEffZ9

 

TestDiamondSwordModel:

http://pastebin.com/hbjSJsaN

Link to comment
Share on other sites

Make a class that implements

ICustomModelLoader

. In

accepts

return true if it is the RL for your Item. In loadModel return a new IModel. In the IModel:

bake

: return a new instance of your ISmartItemModel.

getDependencies

/

getTextures

: Return ImmutableList.of() (the empty list).

getDefaultState

: Return TRSRTransformation.identiy.

 

Then register your loader using

ModelLoaderRegistry.registerLoader

in preInit. You now no longer need the bake event handler.

The difference for you is that you have a texture to return and you will probably be using IBakedModle instead of ISmartItemModel

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

I haven't done that myself but minecrafts model loader also implements ICustomModelLoader so if you look around through that you should be able to see how they do it.

 

In case you don't know:

right click -> the 3 opens are a great way to trace through classes and method calls.

 

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

I discovered in ItemModelMesher:

 

public IBakedModel getItemModel(ItemStack stack)

    {

        Item item = stack.getItem();

        IBakedModel ibakedmodel = this.getItemModel(item, this.getMetadata(stack));

 

        if (ibakedmodel == null)

        {

            ItemMeshDefinition itemmeshdefinition = (ItemMeshDefinition)this.shapers.get(item);

 

            if (itemmeshdefinition != null)

            {

                ibakedmodel = this.modelManager.getModel(itemmeshdefinition.getModelLocation(stack));

            }

        }

 

        if (ibakedmodel == null)

        {

            ibakedmodel = this.modelManager.getMissingModel();

        }

 

        return ibakedmodel;

    }

 

Does that mean that it's only called for nonexistent meshes? (It checks if baked mesh is null first)

Link to comment
Share on other sites

@SuppressWarnings("unchecked")

private void removeItemFromMesher(Item item, int meta) {

try {

Field field1 = ItemModelMesher.class.getDeclaredField("simpleShapesCache");

field1.setAccessible(true);

Map<Integer, IBakedModel> simpleShapesCache = (Map<Integer, IBakedModel>) field1.get(getMesher());

simpleShapesCache.remove(getIndex(item, meta));

field1.set(getMesher(), simpleShapesCache);

Field field2 = ItemModelMesher.class.getDeclaredField("simpleShapes");

field2.setAccessible(true);

Map<Integer, ModelResourceLocation> simpleShapes = (Map<Integer, ModelResourceLocation>) field2.get(getMesher());

simpleShapes.remove(getIndex(item, meta));

field2.set(getMesher(), simpleShapes);

} catch (NoSuchFieldException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SecurityException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

 

 

I tried doing this on postinit, but it did nothing.

Link to comment
Share on other sites

I GOT IT TO WORK WITH ICUSTOMMODELLOADER! :D

 

It now looks like a potato unless it is named Apple, in which case it looks like an apple. It works as expected :)

 

My new code: http://pastebin.com/bQAWSUVx

 

Now that I know how, I can use that same concept to make an actual system for it. (Code is very hacky, so anyone reading this shouldn't copy and paste ;))

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.