Jump to content

Recommended Posts

Posted

I tried to make a food item with 7 metadata states. Each one should have a own potion effect. They should have the same texture and label. I want to implement the addInformation() Method so that the effect is displayed under the Item! My code so far:

 

package VoidCatz.Basic;

import java.util.List;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemFoodBasic extends ItemFood{
private String filename = "Basic:basicitem"; //icon filename
private int effectID = getEffectID(??); //What do you put here?

public ItemFoodBasic(int id, int food, float saturation, boolean wolf) {
	super(id, food, saturation, wolf);
	this.setMaxStackSize(16);
	this.setHasSubtypes(true);
	this.setMaxDamage(0);
	this.setCreativeTab(CreativeTabs.tabFood);
	this.setPotionEffect(effectID, 60, 2, 1.0F);
}

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister reg){
	this.itemIcon = reg.registerIcon(filename);
}

public int getEffectID(ItemStack is){ //checks the metadata and returns the effect id
	int damage = getItemDamageFromStack(is);
	switch(damage){
	case 0: return 1;
	case 1: return 3;
	case 2: return 5;
	case 3: return 8;
	case 4: return 11;
	case 5: return 12;
	case 6: return 13;
	default: return 1;
	}

}

public void setIcon(String IconLoc){
	filename = IconLoc;
}

@Override
public void addInformation(ItemStack is, EntityPlayer player, List l, boolean B){ //Additional info (eg. the names of music discs)
	int damage = getItemDamageFromStack(is);
	switch(damage){
	case 0: l.add("Speed");
	case 1: l.add("Haste");
	case 2: l.add("Strength");
	case 3: l.add("Jump Boost");
	case 4: l.add("Resistance");
	case 5: l.add("Fire Protection");
	case 6: l.add("Water Breathing");
	default: l.add("Speed");
}

}
}

 

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.