Jump to content

[Solved]Texture loading help for a newbie.


bullzeye24

Recommended Posts

Hello, I'm new to minecraft modding, and am relatively new to java as well. I have been working on adding a new item, and the item shows up fine. Its when i get to the texture that i have problems. I've checked the case on all of it and still no luck, so I'm posting here hoping one of you can help me out with this hurdle.

My file directory to the texture

 

Desktop\Gunfactory\src\main\resources\assets\gunfactory\textures\items\sulfur.png

 

My main item class.

 

package com.bullzeye.Gunfactory.Items;

import com.bullzeye.Gunfactory.reference.reference;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class item extends Item {
    public item() {
        super();
    }
    @Override
    public String getUnlocalizedName()
    {
        return String.format("item.%s%s", reference.MOD_ID.toLowerCase()+":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));

    }
    @Override
    public String getUnlocalizedName(ItemStack itemStack)
    {
        return String.format("item.%s%s", reference.MOD_ID.toLowerCase()+":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
    }
    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister iconRegister)
    {
        itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(":")+1));
    }
    protected String getUnwrappedUnlocalizedName(String unlocalizedName)
    {
        return unlocalizedName.substring(unlocalizedName.indexOf('.')+1);
    }
    }

 

 

My sulfur class

 

package com.bullzeye.Gunfactory.Items;

import com.bullzeye.Gunfactory.reference.reference;

public class Itemsulfur extends item {
    public Itemsulfur() {
        super();
        this.setUnlocalizedName("sulfur");
    }
}

 

My item registry class

 

package com.bullzeye.Gunfactory.init;

import com.bullzeye.Gunfactory.Items.Itemsulfur;
import com.bullzeye.Gunfactory.Items.item;
import cpw.mods.fml.common.registry.GameRegistry;

public class moditems {
    public static final item Sulfur = new Itemsulfur();
    public static void init(){
        GameRegistry.registerItem(Sulfur,"Sulfur");
    }
}

 

My error

 

[Client thread/ERROR]: Using missing texture, unable to load minecraft:textures/items/sulfur.png

java.io.FileNotFoundException: minecraft:textures/items/sulfur.png

 

 

Any and all help is appreciated. Thanks in advance :)

Link to comment
Share on other sites

Oh god.  I've seen this code before.

 

And it's a terrible, terrible way to do it.

 

Long story short: you're stripping your mod ID from your item's unlocalized name in order to register the texture name, which needs your mod ID.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thanks, i knew something was off. I"ve been following along with Pahimar's lets mod tutorials on youtube, since I'm new to all this. So if i add in the modid to the unlocalized name, it should register the texture?

edit...

Went back and tried it, man your a life saver. it was alot simpler than I thought. I guess I kept over complicating the issue. Thanks again.

Link to comment
Share on other sites

I guess I kept over complicating the issue.

 

No, Pahimar overcomplicated it in an attempt to use two strings for fuckeverything.  Rather than doing it in a straightforward way that was easy to understand.

 

setUnlocalizedName("myThing");
setTextureName("myThingsTexture");

 

But no, he had to override getUnlocalizedName so that it would strip out the extra copy of the modID, then add it back in differently for texture registration...

 

It's so bad that nearly all the veterans around here recognize his work on sight.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Wow, here i was thinking that it was the right way.. lol . Thanks for opening my eyes to this. I wish i would have seen it sooner. Seems pointless to do all that when you can do it much simpler. I'm going to rewrite it, and get rid of all the excess garbage.

Link to comment
Share on other sites

Wow, here i was thinking that it was the right way.. lol . Thanks for opening my eyes to this. I wish i would have seen it sooner. Seems pointless to do all that when you can do it much simpler. I'm going to rewrite it, and get rid of all the excess garbage.

 

Its not pointless.  It's so that he can change a single string instance and have it update across all usage.  Just that for unlocalized names and file references...you'd then have to update your lang file and file name.  If you really want to rename the block...its not that difficult.

 

The problem is that the way he does it is not newbie friendly.  A fresh hand at modding will see the line and go "ooh magic code..." and not understand what it does so when things go unexpected, they don't understand why.

 

"I told it to use texture name 'sulfur,' it's looking for minecraft:sulfur and can't find it" is a lot easier to solve when you realize you didn't specify your mod-ID.  There's a cause-effect relationship rather than four lines of gibberish.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.