Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Can you give items different textures based on the metadata/damage of the item? and if so how is that possible?

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

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.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.