Jump to content

[1.8] Problem loading models for items with metadata


zlotnleo

Recommended Posts

This code works perfectly:

 

 

private static void load_texture(ItemCA item)

    {

        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getUnlocalizedName().substring(5), "inventory"));

        LogHelper.info("Loading model in '"+item.getUnlocalizedName().substring(5)+"'");

    }

 

 

 

However when I overload this method to handle items with metadata they're rendered as cubes (json model file not loading)

 

 

private static void load_texture(ItemCA item, int metastart, int metaend)

    {

        for(int i=metastart;i<=metaend;i++)

        {

            Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, i, new ModelResourceLocation(item.getUnlocalizedName(new ItemStack(item, 1, i)).substring(5), "inventory"));

            LogHelper.info("Loading model in '" + item.getUnlocalizedName(new ItemStack(item, 1, i)).substring(5) + "' for metadata "+i);

        }

    }

 

 

 

Since the first one is working, assets is loading properly etc.

 

The part of log with all the "Loading model..."

 

 

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:coal_piece'

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_white' for metadata 0

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_orange' for metadata 1

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_magenta' for metadata 2

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_lightblue' for metadata 3

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_yellow' for metadata 4

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_lime' for metadata 5

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_pink' for metadata 6

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_gray' for metadata 7

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_lightgray' for metadata 8

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_cyan' for metadata 9

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_purple' for metadata 10

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_blue' for metadata 11

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_brown' for metadata 12

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_green' for metadata 13

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_red' for metadata 14

[17:09:49] [Client thread/INFO] [Coal Age]: Loading model in 'coalage:colored_coal_black' for metadata 15

 

 

 

I'd think that if "coalage:coal_piece" is OK, then "coalage:colored_coal_black" hould work, but it doesn't.

And getUnlocalizedName method is overloaded and works as I want it to. That's proved by the log

Link to comment
Share on other sites

The ModelBakery.addVariants works great

 

However to load the models I had to use this method:

 

 

for(int i=metastart;i<=metaend;i++)

        {

            Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, i, new ModelResourceLocation(item.getUnlocalizedName(new ItemStack(item, 1, i)).substring(5), "inventory"));

        }

 

 

 

Because the one I fount to be said correct:

 

 

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item,

                    new ItemMeshDefinition()

                    {

                        public ModelResourceLocation getModelLocation(ItemStack stack)

                        {

                            return new ModelResourceLocation(item.getUnlocalizedName(stack).substring(5), "inventory");

                        }

                    });

 

 

was being called all the time and made a giant mess in the log

Link to comment
Share on other sites

The ModelBakery.addVariants works great

 

However to load the models I had to use this method:

 

 

for(int i=metastart;i<=metaend;i++)

        {

            Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, i, new ModelResourceLocation(item.getUnlocalizedName(new ItemStack(item, 1, i)).substring(5), "inventory"));

        }

 

 

 

Because the one I fount to be said correct:

 

 

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item,

                    new ItemMeshDefinition()

                    {

                        public ModelResourceLocation getModelLocation(ItemStack stack)

                        {

                            return new ModelResourceLocation(item.getUnlocalizedName(stack).substring(5), "inventory");

                        }

                    });

 

 

was being called all the time and made a giant mess in the log

yeah, that's how it is supposed to work, it's a technique called a 'function object'.  Every time minecraft wants to know what ModelResourceLocation to use for your itemstack, it calls the getModelLocation() you have given it.  So if you put a println in there, it will print every time it's called, which is a lot.  The solution is not to put a println in there.  Or, adding every single variant (like you have done) works too, since there aren't very many.

 

-TGG

 

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.