Jump to content

Custom food


SwankLion

Recommended Posts

I want to create a mod. I have eclipse and everything set up for forge already.

Could someone send me a template code for a food item? i've tried looking for tutorials on youtube but they are all 1.5.2 or not comprehensive enough for me to understand. I also want the items to have a potion effect when consumed, setPotionEffect.

Link to comment
Share on other sites

MySparkFish = (new ItemSparkFish(BaseBlockID + OreSpawnConstants.SparkFishBlockID, 1, 0.2F, false).setUnlocalizedName("sparkfish"));

 

 

 

 

public class ItemSparkFish extends ItemFood

{

 

    public ItemSparkFish(int par1, int par2, float par3, boolean par4)

    {

        super(par1, par2, par3, par4);

        this.setAlwaysEdible();

    }

 

   

    public void onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

    {

        super.onFoodEaten(par1ItemStack, par2World, par3EntityPlayer);

        if (!par2World.isRemote)

        {

            par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 100, 0));

        }

 

    }

    @Override

    @SideOnly(Side.CLIENT)

    public void registerIcons(IconRegister iconRegister) {

        this.itemIcon = iconRegister.registerIcon("OreSpawn:" + (this.getUnlocalizedName().substring(5)));

    }

   

}

 

 

 

Please note that "OreSpawn" is the name of my mod, and you should replace it with yours.

The unlocalized name, "sparkfish", is actually short for the icon filename, sparkfish.png.

There is a good beginner tutorial for 1.6.2 hidden here somewhere on the forge wiki.

It is invaluable for a newbie. I suggest you search around until you find it!

 

 

 

Odds are good I've been programming since before you were born. Yeah. I'm OLD school.

Link to comment
Share on other sites

I am tired of writing tuts or explain something. xD nope little joke.

But in this case you did a good start and i think you get it from yourself.

But here is a little help. You can use the class if you want but let the @author inside.

I hope this class helps:

 

package minecraftwero.baconMod.common.items;

import minecraftwero.baconMod.Bacon;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/**
* 
* @author Speiger
*
*/
public class ItemBaconFood extends ItemFood 
{
private String name;
public String texture;
private PotionEffect[] potion;

public ItemBaconFood(int par1, int par2, boolean par3, String par4, String par5,  PotionEffect...par7) 
{
	super(par1, par2, par3);
	this.setCreativeTab(Bacon.baconMod);
	name = par4;
	texture = par5;
	potion = par7;
	this.func_111206_d(par5);
}

public ItemBaconFood(int par1, int par2, boolean par3, String par4, String par5)
{
	this(par1, par2, par3, par4, par5, new PotionEffect(0, 0, 0));
}




public String getItemDisplayName(ItemStack par1)
{
	return name;
}


@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister par1IconRegister)
{
	this.itemIcon = par1IconRegister.registerIcon(texture);
}

@Override
public ItemStack onEaten(ItemStack par1, World par2, EntityPlayer par3) 
{
        --par1.stackSize;
        par3.getFoodStats().addStats(this);
        par2.playSoundAtEntity(par3, "random.burp", 0.5F, par2.rand.nextFloat() * 0.1F + 0.9F);
        addPotions(par1, par2, par3);
	return par1;
}

public void addPotions(ItemStack par1, World par2, EntityPlayer par3)
{
	for(int i = 0; i<potion.length;i++)
	{
		if(potion[i] != null && potion[i].getPotionID() > 0 && !par2.isRemote)
		{
			par3.addPotionEffect(new PotionEffect(potion[i]));
		}
	}
}



}

 

xD change it like every you want. This class do not need a .setUnlokalizedName(); or something like that: but you have to add the texture manually^^

Also i have a craftable foodclass (craftdamage, Eatdamage).

Hope it helps

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.



×
×
  • Create New...

Important Information

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