Jump to content

Recommended Posts

Posted

Yes, getIconIndex has a metadata sensitive version.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

I believe its something like this though i havn't tested it.

 

        public int getIconFromDamage(int i)
        {
                switch(i){
                                case 1: return 0;
                                case 2: return 1;
                                default: return 2;         
        }
   }

 

where the case is the damage value and the return value is corresponding place on the sprite sheet.

EDIT:

Ok yes that does work I have just tested it. If you can't get it to work here is the rest of the code.

 

mod_XXX.java

package net.minecraft.src;

import net.minecraft.src.forge.*;



public class mod_McMod extends BaseMod {
public static final Item  itemTest = new ItemTest(130);


public mod_McMod(){

}


@Override
public String getVersion() {
	// TODO Auto-generated method stub
	return "0.0.1";
}

@Override
public void load() {
           //new ItemStack(itemTest, 1, 0)
           //itemTest is your item, 1 is stack size for init don't think this matters and 0 is damage value
           ModLoader.addName(new ItemStack(itemTest, 1, 0), "Item 1 Name");
           ModLoader.addName(new ItemStack(itemTest, 1, 1), "Item 2 Name");
           ModLoader.addName(new ItemStack(itemTest, 1, 2), "Item 2 Name");
           
           
           ModLoader.addRecipe(new ItemStack(itemTest, 3, 0), new Object[] {"###", '#', Block.dirt});
           ModLoader.addRecipe(new ItemStack(itemTest, 3, 1), new Object[] {"##", '#', Block.dirt});
           ModLoader.addRecipe(new ItemStack(itemTest, 3, 2), new Object[] {"#", '#', Block.dirt});
           
           MinecraftForgeClient.preloadTexture("items.png");

}

}

 

ItemTest.java

package net.minecraft.src;

public class McItemTest extends Item {

public McItemTest(int par1) {
	super(par1);
	setHasSubtypes(true);
                setMaxDamage(0);
}

    private String[] names = new String[]{"item1", "item2" , "item3"};
    
    @Override
    public String getItemNameIS(ItemStack itemstack)
    {
            return names[itemstack.getItemDamage()];
    }
    
    @Override
    public int getIconFromDamage(int i)
    {
        switch(i){
        case 1: return 1;
        case 2: return 2;
        default: return 3;     
        }
            
    }
    
    public String getTextureFile()
    {
            return "items.png";
    }

}

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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